1use crate::types::{BoundingBox, Color, Vec3};
2use crate::version::WmoVersion;
3use crate::wmo_group_types::WmoGroupFlags;
4use bitflags::bitflags;
5
6#[derive(Debug)]
8pub struct WmoRoot {
9 pub version: WmoVersion,
11
12 pub materials: Vec<WmoMaterial>,
14
15 pub groups: Vec<WmoGroupInfo>,
17
18 pub portals: Vec<WmoPortal>,
20
21 pub portal_references: Vec<WmoPortalReference>,
23
24 pub visible_block_lists: Vec<Vec<u16>>,
26
27 pub lights: Vec<WmoLight>,
29
30 pub doodad_defs: Vec<WmoDoodadDef>,
32
33 pub doodad_sets: Vec<WmoDoodadSet>,
35
36 pub bounding_box: BoundingBox,
38
39 pub textures: Vec<String>,
41
42 pub header: WmoHeader,
44
45 pub skybox: Option<String>,
47}
48
49#[derive(Debug, Clone)]
51pub struct WmoHeader {
52 pub n_materials: u32,
54
55 pub n_groups: u32,
57
58 pub n_portals: u32,
60
61 pub n_lights: u32,
63
64 pub n_doodad_names: u32,
66
67 pub n_doodad_defs: u32,
69
70 pub n_doodad_sets: u32,
72
73 pub flags: WmoFlags,
75
76 pub ambient_color: Color,
78}
79
80bitflags! {
81 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
83 pub struct WmoFlags: u32 {
84 const HAS_VERTEX_COLORS = 0x01;
86 const OUTDOOR = 0x02;
88 const NO_TERRAIN_SHADOWS = 0x04;
90 const HAS_LIQUIDS = 0x08;
92 const INDOOR_MAP = 0x10;
94 const HAS_SKYBOX = 0x20;
96 const SPECIAL_PASS = 0x40;
98 const USE_SCENE_GRAPH = 0x80;
100 const SHOW_MINIMAP_OUTDOOR = 0x100;
102 const MOUNT_ALLOWED = 0x200;
104 }
105}
106
107#[derive(Debug, Clone)]
109pub struct WmoMaterial {
110 pub flags: WmoMaterialFlags,
112
113 pub shader: u32,
115
116 pub blend_mode: u32,
118
119 pub texture1: u32,
121
122 pub emissive_color: Color,
124
125 pub sidn_color: Color,
127
128 pub framebuffer_blend: Color,
130
131 pub texture2: u32,
133
134 pub diffuse_color: Color,
136
137 pub ground_type: u32,
139}
140
141bitflags! {
142 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
144 pub struct WmoMaterialFlags: u32 {
145 const UNLIT = 0x01;
147 const UNFOGGED = 0x02;
149 const TWO_SIDED = 0x04;
151 const EXTERIOR_LIGHT = 0x08;
153 const WINDOW_LIGHT = 0x10;
155 const IGNORE_VERTEX_LIGHT = 0x20;
157 const DISABLE_Z_BUFFER = 0x40;
159 const UNUSED1 = 0x80;
161 const SHADOW_BATCH_1 = 0x100;
163 const SHADOW_BATCH_2 = 0x200;
165 const UNUSED2 = 0x400;
167 const UNUSED3 = 0x800;
169 }
170}
171
172#[derive(Debug, Clone)]
174pub struct WmoGroupInfo {
175 pub flags: WmoGroupFlags,
177
178 pub bounding_box: BoundingBox,
180
181 pub name: String,
183}
184
185#[derive(Debug, Clone)]
187pub struct WmoPortal {
188 pub vertices: Vec<Vec3>,
190
191 pub normal: Vec3,
193}
194
195#[derive(Debug, Clone)]
197pub struct WmoPortalReference {
198 pub portal_index: u16,
200
201 pub group_index: u16,
203
204 pub side: u16,
206}
207
208#[derive(Debug, Clone)]
210pub struct WmoLight {
211 pub light_type: WmoLightType,
213
214 pub position: Vec3,
216
217 pub color: Color,
219
220 pub intensity: f32,
222
223 pub attenuation_start: f32,
225
226 pub attenuation_end: f32,
228
229 pub use_attenuation: bool,
231
232 pub properties: WmoLightProperties,
234}
235
236#[derive(Debug, Clone, Copy, PartialEq, Eq)]
238pub enum WmoLightType {
239 Omni = 0,
241
242 Spot = 1,
244
245 Directional = 2,
247
248 Ambient = 3,
250}
251
252impl WmoLightType {
253 pub fn from_raw(raw: u8) -> Option<Self> {
255 match raw {
256 0 => Some(Self::Omni),
257 1 => Some(Self::Spot),
258 2 => Some(Self::Directional),
259 3 => Some(Self::Ambient),
260 _ => {
262 tracing::warn!("Unknown light type {}, defaulting to Omni", raw);
264 Some(Self::Omni)
265 }
266 }
267 }
268}
269
270#[derive(Debug, Clone)]
272pub enum WmoLightProperties {
273 Omni,
275
276 Spot {
278 direction: Vec3,
280
281 hotspot: f32,
283
284 falloff: f32,
286 },
287
288 Directional {
290 direction: Vec3,
292 },
293
294 Ambient,
296}
297
298#[derive(Debug, Clone)]
300pub struct WmoDoodadDef {
301 pub name_offset: u32,
303
304 pub position: Vec3,
306
307 pub orientation: [f32; 4],
309
310 pub scale: f32,
312
313 pub color: Color,
315
316 pub set_index: u16,
318}
319
320#[derive(Debug, Clone)]
322pub struct WmoDoodadSet {
323 pub name: String,
325
326 pub start_doodad: u32,
328
329 pub n_doodads: u32,
331}