wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
material.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <array>
9#include <cstdint>
10#include <string>
11
12#include <welder/vocabulary.hpp>
13
14#include <wowlib/core/lang.hpp>
18
24 struct [[
25 =welder::weld,
26 =welder::weld_as("M2Color"),
28 =welder::doc(R"(
29 One color + alpha animation pair. Abstract over the client version; construct a concrete
30 version with M2Color.ForVersion / for_version.)")
31 ]] M2ColorBase {
32 // The concretes default operator== — the base must be comparable too.
33 bool operator==(const M2ColorBase&) const = default;
34 };
35
36 /** The version-agnostic base of every M2TextureWeight<V> (welded as "M2TextureWeight").
37 Bindings-only, like every *Base: it gives the per-version classes a
38 common welded supertype, so the family surface hoists their shared
39 members and containers of them carry a base-typed live view. */
40 struct [[
41 =welder::weld,
42 =welder::weld_as("M2TextureWeight"),
44 =welder::doc(R"(
45 One texture weight (transparency) track. Abstract over the client version; construct a concrete
46 version with M2TextureWeight.ForVersion / for_version.)")
48 // The concretes default operator== — the base must be comparable too.
49 bool operator==(const M2TextureWeightBase&) const = default;
50 };
51
55
56 struct [[
57 =welder::weld,
58 =welder::weld_as("M2TextureFlipbook"),
60 =welder::doc(R"(
61 One texture flipbook animation. Abstract over the client version; construct a concrete
62 version with M2TextureFlipbook.ForVersion / for_version.)")
64 // The concretes default operator== — the base must be comparable too.
65 bool operator==(const M2TextureFlipbookBase&) const = default;
66 };
67
69 Bindings-only, like every *Base: it gives the per-version classes a
70 common welded supertype, so the family surface hoists their shared
71 members and containers of them carry a base-typed live view. */
72 struct [[
73 =welder::weld,
74 =welder::weld_as("M2TextureTransform"),
76 =welder::doc(R"(
77 One texture UV transform animation. Abstract over the client version; construct a concrete
78 version with M2TextureTransform.ForVersion / for_version.)")
80 // The concretes default operator== — the base must be comparable too.
81 bool operator==(const M2TextureTransformBase&) const = default;
82 };
83
84 struct [[
85 =welder::weld,
86 =welder::doc("An M2 vertex: position, 4-bone weights/indices, normal and "
87 "two texture coordinate sets.")
89 [[=welder::doc("Position in model space.")]]
90 C3Vector pos{};
91 [[=welder::doc("Influence weights of the four bones; they sum to 255.")]]
92 std::array<std::uint8_t, 4> boneWeights{};
93 [[=welder::doc("The four influencing bone indices.")]]
94 std::array<std::uint8_t, 4> boneIndices{};
95 [[=welder::doc("Normal in model space.")]]
96 C3Vector normal{};
97 [[=welder::doc("Two UV sets; the shader picks which are used.")]]
98 std::array<C2Vector, 2> texCoords{};
100 bool operator==(const M2Vertex&) const = default;
101 };
102
103 static_assert(sizeof(M2Vertex) == 48);
104
105 enum class [[
106 =welder::weld,
107 =welder::flags,
108 =welder::doc("M2Material render flags.")
109 ]] MaterialFlags : std::uint16_t {
110 Unlit [[=welder::doc("No lighting.")]] = 0x1,
111 Unfogged [[=welder::doc("No fog.")]] = 0x2,
112 TwoSided [[=welder::doc("No backface culling.")]] = 0x4,
113 DepthTest [[=welder::doc("Depth test enabled.")]] = 0x8,
114 DepthWrite [[=welder::doc("Depth write enabled.")]] = 0x10,
115 NoCustomAlpha [[=welder::doc("MoP+: force fully opaque/transparent for "
116 "custom elements.")]] = 0x800
117 };
118
119 struct [[
120 =welder::weld,
121 =welder::doc("An M2 material: render flags (see MaterialFlags) and the "
122 "blending mode (see M2/Rendering M2BLEND).")
123 ]] M2Material {
124 [[=welder::doc("See MaterialFlags.")]]
126 [[=welder::doc("M2BLEND blending mode (see M2/Rendering).")]]
127 std::uint16_t blendingMode = 0;
128
129 bool operator==(const M2Material&) const = default;
130 };
132 static_assert(sizeof(M2Material) == 4);
133
134 struct [[
135 =welder::weld,
136 =welder::doc("A texture definition: type 0 references the filename (TXID "
137 "FileDataIDs replace it in 8.0+); non-zero types are runtime component "
138 "slots (skin, hair, monster skins, ...).")
139 ]] M2Texture {
140 [[=welder::doc("0 = filename-referenced, else a component slot.")]]
141 std::uint32_t type = 0;
142 [[=welder::doc("0x1 wrap X, 0x2 wrap Y.")]]
143 std::uint32_t flags = 0;
144 [[=welder::doc(
145 "For type 0; the serializer writes the NUL inside the count.")]]
146 std::string filename;
148 bool operator==(const M2Texture&) const = default;
149 };
150
151 namespace detail {
152 // The annotated era layouts; instantiate through the canonicalizing
153 // aliases below, never directly.
154 template <ClientVersion V>
155 struct [[
156 =welder::weld,
157 =welder::doc(
158 "A vertex color + alpha animation pair, referenced from skin batches "
159 "by color index.")
161 [[=welder::doc("RGB vertex color.")]]
163 [[=welder::doc("0 transparent .. 0x7FFF opaque.")]]
165
166 bool operator==(const M2Color&) const = default;
167 };
168
169 template <ClientVersion V>
170 struct [[
171 =welder::weld,
172 =welder::doc("A global texture weight (transparency) track.")
174 [[=welder::doc("0 transparent .. 0x7FFF opaque; multiplies the color "
175 "block's alpha.")]]
177
178 bool operator==(const M2TextureWeight&) const = default;
179 };
180
181 template <ClientVersion V>
182 struct [[
183 =welder::weld,
184 =welder::doc(
185 "A pre-WotLK texture flipbook slot; never observed engaged in files.")
186 ]] M2TextureFlipbook : M2TextureFlipbookBase {
187 [[=welder::doc("Frame index keyframes.")]]
189
190 bool operator==(const M2TextureFlipbook&) const = default;
191 };
192
193 template <ClientVersion V>
194 struct [[
195 =welder::weld,
196 =welder::doc(
197 "A UV animation: translation/rotation/scaling keyframes for the "
198 "texture matrix (rotation pivots at texture center 0.5, 0.5).")
199 ]] M2TextureTransform : M2TextureTransformBase {
200 [[=welder::doc("UV translation keyframes.")]]
201 record::M2Track<C3Vector, V> translation{};
202 [[=welder::doc("UV rotation keyframes, pivoting at the texture center.")]]
204 [[=welder::doc("UV scaling keyframes.")]]
206
207 bool operator==(const M2TextureTransform&) const = default;
208 };
209 }
210
211 // The canonicalizing faces: these records' only version axis is the track
212 // era of the animations they embed (M2TrackPivots).
213 template <ClientVersion V>
215 template <ClientVersion V>
217 template <ClientVersion V>
219 template <ClientVersion V>
221}
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
Binding-language identities welder's core does not name.
#define WOWLIB_CS_FAMILY_SURFACE
The C# rod's family-surface opt-in, spellable in every build.
Definition lang.hpp:44
The M2 version vocabulary: the layout pivots record/entity partial specializations key on,...
M2 body record structs (sequences, bones, tracks, textures, cameras, emitters) and their flag enums.
Definition bone.hpp:17
detail::M2Track< T, canonicalVersion(V, M2TrackPivots, M2Versions)> M2Track
An animation track for value type T — the canonicalizing face of detail::M2Track: every client versio...
Definition track.hpp:498
detail::M2TextureTransform< canonicalVersion(V, M2TrackPivots, M2Versions)> M2TextureTransform
Definition material.hpp:175
detail::M2Color< canonicalVersion(V, M2TrackPivots, M2Versions)> M2Color
Definition material.hpp:169
MaterialFlags
M2Material render flags.
Definition material.hpp:87
@ NoCustomAlpha
MoP+: force fully opaque/transparent for custom elements.
Definition material.hpp:93
detail::M2TextureWeight< canonicalVersion(V, M2TrackPivots, M2Versions)> M2TextureWeight
Definition material.hpp:171
detail::M2TextureFlipbook< canonicalVersion(V, M2TrackPivots, M2Versions)> M2TextureFlipbook
Definition material.hpp:173
constexpr std::array M2TrackPivots
Track-shaped records (M2Track, M2TrackBase, and every record whose only version axis is the tracks it...
constexpr std::array M2Versions
The versions M2 is instantiated (and welded) for: every targeted last-minor-of-major release,...
constexpr ClientVersion canonicalVersion(ClientVersion v, std::span< const ClientVersion > pivots, std::span< const ClientVersion > grid)
The canonical version v collapses to: the FIRST grid version in v's range.
A 3D float vector — the workhorse: positions, normals, rotations-as-Euler-degrees in placements.
Definition types.hpp:49
The version-agnostic base of every M2Color<V> (welded as "M2Color").
Definition material.hpp:27
bool operator==(const M2ColorBase &) const =default
An M2 material: render flags (see MaterialFlags) and the blending mode (see M2/Rendering M2BLEND).
Definition material.hpp:97
bool operator==(const M2Material &) const =default
MaterialFlags flags
See MaterialFlags.
Definition material.hpp:99
std::uint16_t blendingMode
M2BLEND blending mode (see M2/Rendering).
Definition material.hpp:101
The version-agnostic base of every M2TextureFlipbook<V> (welded as "M2TextureFlipbook").
Definition material.hpp:51
bool operator==(const M2TextureFlipbookBase &) const =default
The version-agnostic base of every M2TextureTransform<V> (welded as "M2TextureTransform").
Definition material.hpp:63
bool operator==(const M2TextureTransformBase &) const =default
The version-agnostic base of every M2TextureWeight<V> (welded as "M2TextureWeight").
Definition material.hpp:39
bool operator==(const M2TextureWeightBase &) const =default
A texture definition: type 0 references the filename (TXID FileDataIDs replace it in 8....
Definition material.hpp:109
std::uint32_t type
0 = filename-referenced, else a component slot.
Definition material.hpp:111
std::string filename
For type 0; the serializer writes the NUL inside the count.
Definition material.hpp:115
std::uint32_t flags
0x1 wrap X, 0x2 wrap Y.
Definition material.hpp:113
bool operator==(const M2Texture &) const =default
An M2 vertex: position, 4-bone weights/indices, normal and two texture coordinate sets.
Definition material.hpp:69
C3Vector pos
Position in model space.
Definition material.hpp:71
std::array< std::uint8_t, 4 > boneIndices
The four influencing bone indices.
Definition material.hpp:75
std::array< std::uint8_t, 4 > boneWeights
Influence weights of the four bones; they sum to 255.
Definition material.hpp:73
C3Vector normal
Normal in model space.
Definition material.hpp:77
bool operator==(const M2Vertex &) const =default
std::array< C2Vector, 2 > texCoords
Two UV sets; the shader picks which are used.
Definition material.hpp:79
A vertex color + alpha animation pair, referenced from skin batches by color index.
Definition material.hpp:125
bool operator==(const M2Color &) const =default
A pre-WotLK texture flipbook slot; never observed engaged in files.
Definition material.hpp:145
bool operator==(const M2TextureFlipbook &) const =default
A UV animation: translation/rotation/scaling keyframes for the texture matrix (rotation pivots at tex...
Definition material.hpp:154
bool operator==(const M2TextureTransform &) const =default
A global texture weight (transparency) track.
Definition material.hpp:136
bool operator==(const M2TextureWeight &) const =default
The M2 animation vocabulary (namespace wowlib::formats::m2::root::record): the small fixed-size primi...