| 506 | } |
| 507 | |
| 508 | pub fn extend(&mut self, collection: impl IntoNodeCollection, parent: Option<usize>) -> usize { |
| 509 | let mut collection = collection.into_node_collection(); |
| 510 | let entry_offset = self.entries.len(); |
| 511 | let spec_offset = self.specs.len(); |
| 512 | let scene_offset = self.scenes.len(); |
| 513 | let mut root = collection.root.map(|root| entry_offset + root); |
| 514 | for spec in &mut collection.specs { |
| 515 | spec.parent = spec.parent.map(|parent| entry_offset + parent).or(parent); |
| 516 | } |
| 517 | for scene in &mut collection.scenes { |
| 518 | scene.parent = scene.parent.map(|parent| entry_offset + parent).or(parent); |
| 519 | } |
| 520 | for entry in collection.entries { |
| 521 | let entry_parent = match entry { |
| 522 | NodeCollectionEntry::Node(index) => collection.specs[index].parent, |
| 523 | NodeCollectionEntry::Scene(index) => collection.scenes[index].parent, |
| 524 | }; |
| 525 | if root.is_none() && entry_parent == parent { |
| 526 | root = Some(self.entries.len()); |
| 527 | } |
| 528 | match entry { |
| 529 | NodeCollectionEntry::Node(index) => { |
| 530 | self.specs.push(collection.specs[index].clone()); |
| 531 | self.entries |
| 532 | .push(NodeCollectionEntry::Node(spec_offset + index)); |
| 533 | } |
| 534 | NodeCollectionEntry::Scene(index) => { |
| 535 | self.scenes.push(collection.scenes[index].clone()); |
| 536 | self.entries |
| 537 | .push(NodeCollectionEntry::Scene(scene_offset + index)); |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | root.unwrap_or(entry_offset) |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | pub trait IntoNodeCollection { |