wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
liquid.hpp
Go to the documentation of this file.
1#pragma once
2
10
11#include <bit>
12#include <cstdint>
13
14#include <welder/vocabulary.hpp>
15
17
19 enum class [[
20 =welder::weld,
21 =welder::doc(R"(
22 The MH2O per-instance vertex layout (LiquidVertexFormat). Which arrays a
23 liquid instance stores — heights, depths, texture coordinates — and thus
24 how wowlib decodes and re-lays its vertex data.)")
25 ]] LiquidVertexFormat : std::uint16_t {
26 HeightDepth [[=welder::doc(
27 "Case 0: a float height map and a byte depth map "
28 "(the pre-WoD go-to).")]] = 0,
29 HeightUv [[=welder::doc(
30 "Case 1: a float height map and a UV texture-coordinate "
31 "map.")]] = 1,
32 DepthOnly [[=welder::doc(
33 "Case 2: a byte depth map only; the surface is flat at "
34 "0.0 (ocean).")]] = 2,
35 HeightUvDepth [[=welder::doc(
36 "Case 3: a float height map, a UV map and a byte depth "
37 "map.")]] = 3
38 };
39
41 struct [[
42 =welder::weld,
43 =welder::doc(
44 "An MH2O liquid UV coordinate (case 1/3): x and y, each divided by 8 "
45 "for shaders.")
47 [[=welder::doc("The u coordinate (divided by 8 in shaders).")]]
48 std::uint16_t x = 0;
49 [[=welder::doc("The v coordinate.")]]
50 std::uint16_t y = 0;
51
52 bool operator==(const UVMapEntry&) const = default;
53 };
54
55 static_assert(sizeof(UVMapEntry) == 4);
56
57 // --- legacy MCLQ (pre-WotLK) ------------------------------------------------
58
60 the shared height. Obtain one with SLVert.asMagma(). */
61 struct [[
62 =welder::weld,
63 =welder::doc(
64 "The magma/slime reading of a legacy liquid vertex (MCLQ): u16 texture "
65 "coordinates s, t and the shared height. See SLVert.as_magma().")
66 ]] SMVert {
67 [[=welder::doc("Texture coordinate s.")]]
68 std::uint16_t s = 0;
69 [[=welder::doc("Texture coordinate t.")]]
70 std::uint16_t t = 0;
71 [[=welder::doc("Liquid surface height (shared with the water reading).")]]
72 float height = 0;
73
74 bool operator==(const SMVert&) const = default;
75 };
76
77 static_assert(sizeof(SMVert) == 8);
78
82 struct [[
83 =welder::weld,
84 =welder::doc(R"(
85 A legacy liquid vertex (MCLQ, 8 bytes). The first four bytes are flow /
86 depth data for water and ocean or two u16 texture coordinates for magma /
87 slime — the cell's liquid-type flags choose the reading (use as_magma()).
88 The trailing float is the surface height in all readings.)")
89 ]] SLVert {
90 [[=welder::doc("Water: depth. Ocean: depth. Magma/slime: low byte of s.")]]
91 std::uint8_t depth = 0;
92 [[=welder::doc(
93 "Water: flow0 percent. Ocean: foam. Magma/slime: high byte of s.")]]
94 std::uint8_t flow0 = 0;
95 [[=welder::doc(
96 "Water: flow1 percent. Ocean: wet. Magma/slime: low byte of t.")]]
97 std::uint8_t flow1 = 0;
98 [[=welder::doc("Filler. Magma/slime: high byte of t.")]]
99 std::uint8_t filler = 0;
100 [[=welder::doc("Liquid surface height at this vertex.")]]
101 float height = 0;
102
103 [[nodiscard]]
104 [[=welder::doc(
105 "Reinterpret this vertex under the magma/slime reading (u16 s, t). A "
106 "pure byte reinterpretation; use it only for magma/slime cells.")]]
107 SMVert asMagma() const { return std::bit_cast<SMVert>(*this); }
108
109 [[=welder::doc("Overwrite this vertex's bytes from a magma/slime reading.")]
110 ]
111 void setMagma(const SMVert& magma) {
112 *this = std::bit_cast<SLVert>(magma);
113 }
114
115 bool operator==(const SLVert&) const = default;
116 };
117
118 static_assert(sizeof(SLVert) == 8);
119
121 struct [[
122 =welder::weld,
123 =welder::doc(
124 "A legacy liquid flow vector (MCLQ, 40 bytes): a sphere of influence, a "
125 "direction and velocity/amplitude/frequency.")
126 ]] SWFlowv {
127 [[=welder::doc("The sphere of influence.")]]
128 CAaSphere sphere{};
129 [[=welder::doc("The flow direction.")]]
130 C3Vector direction{};
131 [[=welder::doc("The flow velocity.")]]
132 float velocity = 0;
133 [[=welder::doc("The flow amplitude.")]]
134 float amplitude = 0;
135 [[=welder::doc("The flow frequency.")]]
136 float frequency = 0;
137
138 bool operator==(const SWFlowv&) const = default;
139 };
140
141 static_assert(sizeof(SWFlowv) == 40);
142}
ADT chunk binary structs (the MCNK cell header, texture layers, liquid records, flying bounds) and th...
Definition header.hpp:22
@ HeightUv
Case 1: a float height map and a UV texture-coordinate map.
Definition liquid.hpp:21
@ HeightUvDepth
Case 3: a float height map, a UV map and a byte depth map.
Definition liquid.hpp:23
@ HeightDepth
Case 0: a float height map and a byte depth map (the pre-WoD go-to).
Definition liquid.hpp:20
@ DepthOnly
Case 2: a byte depth map only; the surface is flat at 0.0 (ocean).
Definition liquid.hpp:22
One legacy liquid vertex (MCLQ, 8 bytes).
Definition liquid.hpp:60
std::uint8_t flow0
Water: flow0 percent.
Definition liquid.hpp:64
float height
Liquid surface height at this vertex.
Definition liquid.hpp:70
std::uint8_t flow1
Water: flow1 percent.
Definition liquid.hpp:66
SMVert asMagma() const
Reinterpret this vertex under the magma/slime reading (u16 s, t).
Definition liquid.hpp:74
std::uint8_t depth
Water: depth.
Definition liquid.hpp:62
The magma/slime reading of an MCLQ vertex (8 bytes): two u16 texcoords and the shared height.
Definition liquid.hpp:44
bool operator==(const SMVert &) const =default
std::uint16_t s
Texture coordinate s.
Definition liquid.hpp:46
std::uint16_t t
Texture coordinate t.
Definition liquid.hpp:48
float height
Liquid surface height (shared with the water reading).
Definition liquid.hpp:50
One legacy liquid flow vector (MCLQ SWFlowv, 40 bytes).
Definition liquid.hpp:93
bool operator==(const SWFlowv &) const =default
One MH2O UV texture-coordinate entry (two u16, divided by 8 in shaders).
Definition liquid.hpp:28
std::uint16_t y
The v coordinate.
Definition liquid.hpp:32
bool operator==(const UVMapEntry &) const =default
std::uint16_t x
The u coordinate (divided by 8 in shaders).
Definition liquid.hpp:30
A 3D float vector — the workhorse: positions, normals, rotations-as-Euler-degrees in placements.
Definition types.hpp:49
An axis-aligned sphere: position and radius.
Definition types.hpp:144
The binary-level math and color primitives shared across WoW file formats (wowdev....