1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
//! High-level WMO editing API
//!
//! This module provides a user-friendly interface for modifying WMO files,
//! including materials, groups, transformations, and doodad management.
use crate::converter::WmoConverter;
use crate::error::{Result, WmoError};
use crate::types::{BoundingBox, Vec3};
use crate::version::WmoVersion;
use crate::wmo_group_types::{WmoGroup, WmoGroupHeader};
use crate::wmo_types::{WmoDoodadDef, WmoDoodadSet, WmoGroupInfo, WmoMaterial, WmoRoot};
use crate::writer::WmoWriter;
// Use WmoGroupFlags from wmo_group_types since that's where WmoGroupHeader uses it
use crate::wmo_group_types::WmoGroupFlags;
/// WMO editor for modifying WMO files
pub struct WmoEditor {
/// Root WMO data
root: WmoRoot,
/// Group WMO data
groups: Vec<WmoGroup>,
/// Modified flag for root
root_modified: bool,
/// Modified flags for groups
group_modified: Vec<bool>,
/// Original version
original_version: WmoVersion,
}
impl WmoEditor {
/// Create a new WMO editor from a root WMO file
pub fn new(root: WmoRoot) -> Self {
let original_version = root.version;
let group_count = root.groups.len();
Self {
root,
groups: Vec::with_capacity(group_count),
root_modified: false,
group_modified: vec![false; group_count],
original_version,
}
}
/// Add a group to the editor
pub fn add_group(&mut self, group: WmoGroup) -> Result<()> {
// Verify group index
let group_index = group.header.group_index as usize;
if group_index >= self.root.groups.len() {
return Err(WmoError::InvalidReference {
field: "group_index".to_string(),
value: group_index as u32,
max: self.root.groups.len() as u32 - 1,
});
}
// Ensure groups vector has enough capacity
if self.groups.len() <= group_index {
self.groups.resize_with(group_index + 1, || WmoGroup {
header: WmoGroupHeader {
flags: WmoGroupFlags::empty(),
bounding_box: BoundingBox {
min: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
max: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
},
name_offset: 0,
group_index: 0,
},
materials: Vec::new(),
vertices: Vec::new(),
normals: Vec::new(),
tex_coords: Vec::new(),
batches: Vec::new(),
indices: Vec::new(),
vertex_colors: None,
bsp_nodes: None,
liquid: None,
doodad_refs: None,
});
}
// Store the group
self.groups[group_index] = group;
self.group_modified[group_index] = true;
Ok(())
}
/// Get a reference to the root WMO
pub fn root(&self) -> &WmoRoot {
&self.root
}
/// Get a mutable reference to the root WMO
pub fn root_mut(&mut self) -> &mut WmoRoot {
self.root_modified = true;
&mut self.root
}
/// Get a reference to a specific group
pub fn group(&self, index: usize) -> Option<&WmoGroup> {
self.groups.get(index)
}
/// Get a mutable reference to a specific group
pub fn group_mut(&mut self, index: usize) -> Option<&mut WmoGroup> {
if index < self.group_modified.len() {
self.group_modified[index] = true;
}
self.groups.get_mut(index)
}
/// Get the number of groups
pub fn group_count(&self) -> usize {
self.root.groups.len()
}
/// Check if a specific group has been loaded
pub fn is_group_loaded(&self, index: usize) -> bool {
index < self.groups.len() && self.group(index).is_some()
}
/// Check if a specific group has been modified
pub fn is_group_modified(&self, index: usize) -> bool {
index < self.group_modified.len() && self.group_modified[index]
}
/// Check if the root has been modified
pub fn is_root_modified(&self) -> bool {
self.root_modified
}
/// Convert to a specific version
pub fn convert_to_version(&mut self, target_version: WmoVersion) -> Result<()> {
// Only convert if necessary
if self.root.version == target_version {
return Ok(());
}
// Convert root
let converter = WmoConverter::new();
converter.convert_root(&mut self.root, target_version)?;
self.root_modified = true;
// Convert all loaded groups
for (i, group) in self.groups.iter_mut().enumerate() {
converter.convert_group(group, target_version, self.original_version)?;
if i < self.group_modified.len() {
self.group_modified[i] = true;
}
}
Ok(())
}
/// Get the original version of the WMO
pub fn original_version(&self) -> WmoVersion {
self.original_version
}
/// Get the current version of the WMO
pub fn current_version(&self) -> WmoVersion {
self.root.version
}
/// Save the root WMO to a writer
pub fn save_root<W: std::io::Write + std::io::Seek>(&self, writer: &mut W) -> Result<()> {
// Write the root WMO
let writer_obj = WmoWriter::new();
writer_obj.write_root(writer, &self.root, self.root.version)?;
Ok(())
}
/// Save a specific group to a writer
pub fn save_group<W: std::io::Write + std::io::Seek>(
&self,
writer: &mut W,
index: usize,
) -> Result<()> {
// Check if group exists
let group = self
.group(index)
.ok_or_else(|| WmoError::InvalidReference {
field: "group_index".to_string(),
value: index as u32,
max: self.groups.len() as u32 - 1,
})?;
// Write the group
let writer_obj = WmoWriter::new();
writer_obj.write_group(writer, group, self.root.version)?;
Ok(())
}
// Material editing methods
/// Add a new material
pub fn add_material(&mut self, material: WmoMaterial) -> usize {
self.root_modified = true;
self.root.materials.push(material);
self.root.header.n_materials += 1;
self.root.materials.len() - 1
}
/// Remove a material
pub fn remove_material(&mut self, index: usize) -> Result<WmoMaterial> {
if index >= self.root.materials.len() {
return Err(WmoError::InvalidReference {
field: "material_index".to_string(),
value: index as u32,
max: self.root.materials.len() as u32 - 1,
});
}
self.root_modified = true;
let material = self.root.materials.remove(index);
self.root.header.n_materials -= 1;
// Now we need to update all references to this material in groups
for (i, group) in self.groups.iter_mut().enumerate() {
let mut modified = false;
// Update materials list
for mat_idx in &mut group.materials {
match (*mat_idx as usize).cmp(&index) {
std::cmp::Ordering::Equal => {
// This material has been removed, use a default one instead
*mat_idx = 0;
modified = true;
}
std::cmp::Ordering::Greater => {
// This material has been shifted down by one
*mat_idx -= 1;
modified = true;
}
std::cmp::Ordering::Less => {}
}
}
// Update batches
for batch in &mut group.batches {
match (batch.material_id as usize).cmp(&index) {
std::cmp::Ordering::Equal => {
// This material has been removed, use a default one instead
batch.material_id = 0;
modified = true;
}
std::cmp::Ordering::Greater => {
// This material has been shifted down by one
batch.material_id -= 1;
modified = true;
}
std::cmp::Ordering::Less => {}
}
}
if modified && i < self.group_modified.len() {
self.group_modified[i] = true;
}
}
Ok(material)
}
/// Get a reference to a material
pub fn material(&self, index: usize) -> Option<&WmoMaterial> {
self.root.materials.get(index)
}
/// Get a mutable reference to a material
pub fn material_mut(&mut self, index: usize) -> Option<&mut WmoMaterial> {
self.root_modified = true;
self.root.materials.get_mut(index)
}
// Texture editing methods
/// Add a new texture
pub fn add_texture(&mut self, texture: String) -> usize {
self.root_modified = true;
self.root.textures.push(texture);
self.root.textures.len() - 1
}
/// Remove a texture
pub fn remove_texture(&mut self, index: usize) -> Result<String> {
if index >= self.root.textures.len() {
return Err(WmoError::InvalidReference {
field: "texture_index".to_string(),
value: index as u32,
max: self.root.textures.len() as u32 - 1,
});
}
self.root_modified = true;
let texture = self.root.textures.remove(index);
// Now we need to update all references to this texture in materials
for material in &mut self.root.materials {
match (material.texture1 as usize).cmp(&index) {
std::cmp::Ordering::Equal => {
// This texture has been removed, use a default one instead
material.texture1 = 0;
}
std::cmp::Ordering::Greater => {
// This texture has been shifted down by one
material.texture1 -= 1;
}
std::cmp::Ordering::Less => {}
}
match (material.texture2 as usize).cmp(&index) {
std::cmp::Ordering::Equal => {
// This texture has been removed, use a default one instead
material.texture2 = 0;
}
std::cmp::Ordering::Greater => {
// This texture has been shifted down by one
material.texture2 -= 1;
}
std::cmp::Ordering::Less => {}
}
}
Ok(texture)
}
/// Get a reference to a texture
pub fn texture(&self, index: usize) -> Option<&String> {
self.root.textures.get(index)
}
/// Get a mutable reference to a texture
pub fn texture_mut(&mut self, index: usize) -> Option<&mut String> {
self.root_modified = true;
self.root.textures.get_mut(index)
}
// Group editing methods
/// Create a new group
pub fn create_group(&mut self, name: String) -> usize {
self.root_modified = true;
// Create a new group info entry
let group_info = WmoGroupInfo {
flags: WmoGroupFlags::empty(),
bounding_box: BoundingBox {
min: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
max: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
},
name,
};
// Add to root
self.root.groups.push(group_info);
self.root.header.n_groups += 1;
// Create placeholder group data
let group_index = self.root.groups.len() - 1;
let header = WmoGroupHeader {
flags: WmoGroupFlags::empty(),
bounding_box: BoundingBox {
min: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
max: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
},
name_offset: 0, // Will be calculated when saving
group_index: group_index as u32,
};
let group = WmoGroup {
header,
materials: Vec::new(),
vertices: Vec::new(),
normals: Vec::new(),
tex_coords: Vec::new(),
batches: Vec::new(),
indices: Vec::new(),
vertex_colors: None,
bsp_nodes: None,
liquid: None,
doodad_refs: None,
};
// Add to groups
if self.groups.len() <= group_index {
self.groups.resize_with(group_index + 1, || WmoGroup {
header: WmoGroupHeader {
flags: WmoGroupFlags::empty(),
bounding_box: BoundingBox {
min: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
max: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
},
name_offset: 0,
group_index: 0,
},
materials: Vec::new(),
vertices: Vec::new(),
normals: Vec::new(),
tex_coords: Vec::new(),
batches: Vec::new(),
indices: Vec::new(),
vertex_colors: None,
bsp_nodes: None,
liquid: None,
doodad_refs: None,
});
}
self.groups.push(group);
self.group_modified.push(true);
group_index
}
/// Remove a group
pub fn remove_group(&mut self, index: usize) -> Result<WmoGroupInfo> {
if index >= self.root.groups.len() {
return Err(WmoError::InvalidReference {
field: "group_index".to_string(),
value: index as u32,
max: self.root.groups.len() as u32 - 1,
});
}
self.root_modified = true;
let group_info = self.root.groups.remove(index);
self.root.header.n_groups -= 1;
// Update group indices
for (i, _group) in self.root.groups.iter_mut().enumerate() {
if i >= index {
// This group has been shifted down by one
let group_idx = i as u32;
if let Some(loaded_group) = self.groups.get_mut(i) {
loaded_group.header.group_index = group_idx;
if i < self.group_modified.len() {
self.group_modified[i] = true;
}
}
}
}
// Remove group data if loaded
if index < self.groups.len() {
self.groups.remove(index);
}
if index < self.group_modified.len() {
self.group_modified.remove(index);
}
// Update portal references
for portal_ref in &mut self.root.portal_references {
match (portal_ref.group_index as usize).cmp(&index) {
std::cmp::Ordering::Equal => {
// This portal reference now points to a non-existent group
// Setting to 0 is probably the safest option
portal_ref.group_index = 0;
}
std::cmp::Ordering::Greater => {
// This group has been shifted down by one
portal_ref.group_index -= 1;
}
std::cmp::Ordering::Less => {}
}
}
Ok(group_info)
}
// Vertex manipulation methods
/// Add a vertex to a group
pub fn add_vertex(&mut self, group_index: usize, vertex: Vec3) -> Result<usize> {
// Validate group index
if group_index >= self.groups.len() {
return Err(WmoError::InvalidReference {
field: "group_index".to_string(),
value: group_index as u32,
max: self.groups.len() as u32 - 1,
});
}
// Work with the group
let vertex_index = {
let group = &mut self.groups[group_index];
// Add vertex
group.vertices.push(vertex);
// Update bounding box
let min = &mut group.header.bounding_box.min;
let max = &mut group.header.bounding_box.max;
min.x = min.x.min(vertex.x);
min.y = min.y.min(vertex.y);
min.z = min.z.min(vertex.z);
max.x = max.x.max(vertex.x);
max.y = max.y.max(vertex.y);
max.z = max.z.max(vertex.z);
group.vertices.len() - 1
};
// Also update root group info
if let Some(group_info) = self.root.groups.get_mut(group_index) {
let info_min = &mut group_info.bounding_box.min;
let info_max = &mut group_info.bounding_box.max;
info_min.x = info_min.x.min(vertex.x);
info_min.y = info_min.y.min(vertex.y);
info_min.z = info_min.z.min(vertex.z);
info_max.x = info_max.x.max(vertex.x);
info_max.y = info_max.y.max(vertex.y);
info_max.z = info_max.z.max(vertex.z);
self.root_modified = true;
}
Ok(vertex_index)
}
/// Remove a vertex from a group
pub fn remove_vertex(&mut self, group_index: usize, vertex_index: usize) -> Result<Vec3> {
// Validate group index
if group_index >= self.groups.len() {
return Err(WmoError::InvalidReference {
field: "group_index".to_string(),
value: group_index as u32,
max: self.groups.len() as u32 - 1,
});
}
let group = &mut self.groups[group_index];
if vertex_index >= group.vertices.len() {
return Err(WmoError::InvalidReference {
field: "vertex_index".to_string(),
value: vertex_index as u32,
max: group.vertices.len() as u32 - 1,
});
}
// Remove vertex
let vertex = group.vertices.remove(vertex_index);
// Remove corresponding normal if present
if vertex_index < group.normals.len() {
group.normals.remove(vertex_index);
}
// Remove corresponding texture coordinate if present
if vertex_index < group.tex_coords.len() {
group.tex_coords.remove(vertex_index);
}
// Remove corresponding vertex color if present
if let Some(colors) = &mut group.vertex_colors
&& vertex_index < colors.len()
{
colors.remove(vertex_index);
}
// Update indices
for idx in &mut group.indices {
match (*idx as usize).cmp(&vertex_index) {
std::cmp::Ordering::Equal => {
// This index now points to a non-existent vertex
// Setting to 0 is probably the safest option
*idx = 0;
}
std::cmp::Ordering::Greater => {
// This index has been shifted down by one
*idx -= 1;
}
std::cmp::Ordering::Less => {}
}
}
// Recalculate bounding box
self.recalculate_group_bounding_box(group_index)?;
Ok(vertex)
}
/// Recalculate the bounding box for a group
pub fn recalculate_group_bounding_box(&mut self, group_index: usize) -> Result<()> {
// Validate group index
if group_index >= self.groups.len() {
return Err(WmoError::InvalidReference {
field: "group_index".to_string(),
value: group_index as u32,
max: self.groups.len() as u32 - 1,
});
}
// Calculate the new bounding box
let new_bounding_box = {
let group = &mut self.groups[group_index];
if group.vertices.is_empty() {
// No vertices, use a default bounding box
BoundingBox {
min: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
max: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
}
} else {
// Calculate from vertices
let mut min_x = f32::MAX;
let mut min_y = f32::MAX;
let mut min_z = f32::MAX;
let mut max_x = f32::MIN;
let mut max_y = f32::MIN;
let mut max_z = f32::MIN;
for vertex in &group.vertices {
min_x = min_x.min(vertex.x);
min_y = min_y.min(vertex.y);
min_z = min_z.min(vertex.z);
max_x = max_x.max(vertex.x);
max_y = max_y.max(vertex.y);
max_z = max_z.max(vertex.z);
}
BoundingBox {
min: Vec3 {
x: min_x,
y: min_y,
z: min_z,
},
max: Vec3 {
x: max_x,
y: max_y,
z: max_z,
},
}
}
};
// Update the group's bounding box
self.groups[group_index].header.bounding_box = new_bounding_box;
// Also update root group info
if let Some(group_info) = self.root.groups.get_mut(group_index) {
group_info.bounding_box = new_bounding_box;
self.root_modified = true;
}
Ok(())
}
/// Recalculate the global bounding box
pub fn recalculate_global_bounding_box(&mut self) -> Result<()> {
if self.root.groups.is_empty() {
// No groups, use a default bounding box
self.root.bounding_box = BoundingBox {
min: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
max: Vec3 {
x: 0.0,
y: 0.0,
z: 0.0,
},
};
} else {
// Calculate from group bounding boxes
let mut min_x = f32::MAX;
let mut min_y = f32::MAX;
let mut min_z = f32::MAX;
let mut max_x = f32::MIN;
let mut max_y = f32::MIN;
let mut max_z = f32::MIN;
for group_info in &self.root.groups {
min_x = min_x.min(group_info.bounding_box.min.x);
min_y = min_y.min(group_info.bounding_box.min.y);
min_z = min_z.min(group_info.bounding_box.min.z);
max_x = max_x.max(group_info.bounding_box.max.x);
max_y = max_y.max(group_info.bounding_box.max.y);
max_z = max_z.max(group_info.bounding_box.max.z);
}
self.root.bounding_box = BoundingBox {
min: Vec3 {
x: min_x,
y: min_y,
z: min_z,
},
max: Vec3 {
x: max_x,
y: max_y,
z: max_z,
},
};
}
self.root_modified = true;
Ok(())
}
// Doodad manipulation methods
/// Add a doodad definition
pub fn add_doodad(&mut self, doodad: WmoDoodadDef) -> usize {
self.root_modified = true;
self.root.doodad_defs.push(doodad);
self.root.header.n_doodad_defs += 1;
self.root.header.n_doodad_names += 1; // Assuming name is also added
self.root.doodad_defs.len() - 1
}
/// Remove a doodad definition
pub fn remove_doodad(&mut self, index: usize) -> Result<WmoDoodadDef> {
if index >= self.root.doodad_defs.len() {
return Err(WmoError::InvalidReference {
field: "doodad_index".to_string(),
value: index as u32,
max: self.root.doodad_defs.len() as u32 - 1,
});
}
self.root_modified = true;
let doodad = self.root.doodad_defs.remove(index);
self.root.header.n_doodad_defs -= 1;
// Update doodad references in sets
for set in &mut self.root.doodad_sets {
if set.start_doodad as usize <= index
&& index < (set.start_doodad + set.n_doodads) as usize
{
// This doodad was part of the set
set.n_doodads -= 1;
}
if set.start_doodad as usize > index {
// Doodads after the removed one have shifted down
set.start_doodad -= 1;
}
}
// Update doodad references in groups
for (i, group) in self.groups.iter_mut().enumerate() {
if let Some(refs) = &mut group.doodad_refs {
let mut modified = false;
for doodad_ref in refs.iter_mut() {
match (*doodad_ref as usize).cmp(&index) {
std::cmp::Ordering::Equal => {
// This reference now points to a non-existent doodad
// Remove this reference
*doodad_ref = 0;
modified = true;
}
std::cmp::Ordering::Greater => {
// This reference has been shifted down by one
*doodad_ref -= 1;
modified = true;
}
std::cmp::Ordering::Less => {
// No change needed
}
}
}
if modified && i < self.group_modified.len() {
self.group_modified[i] = true;
}
}
}
Ok(doodad)
}
/// Doodad set manipulation methods
/// Add a doodad set
pub fn add_doodad_set(&mut self, set: WmoDoodadSet) -> usize {
self.root_modified = true;
self.root.doodad_sets.push(set);
self.root.header.n_doodad_sets += 1;
self.root.doodad_sets.len() - 1
}
/// Remove a doodad set
pub fn remove_doodad_set(&mut self, index: usize) -> Result<WmoDoodadSet> {
if index >= self.root.doodad_sets.len() {
return Err(WmoError::InvalidReference {
field: "doodad_set_index".to_string(),
value: index as u32,
max: self.root.doodad_sets.len() as u32 - 1,
});
}
self.root_modified = true;
let set = self.root.doodad_sets.remove(index);
self.root.header.n_doodad_sets -= 1;
Ok(set)
}
}