void Node::RemoveChild(Node* node) { int idx = 0; for (auto& child : children_) { if (child.get() == node) { children_.erase(children_.begin() + idx); auto range = childrenHash_.equal_range(node->name_); auto it = range.first; while (it != range.second) { PNode child = it->second.lock(); if (!child) it = childrenHash_.erase(it); else if (child.get() == node) it = childrenHash_.erase(it); else ++it; } break; } ++idx; } }
void Node::AddChild(PNode node) { CHECK_ASSERT(node && node.get() != this); children_.push_back(node); childrenHash_.insert(std::make_pair(node->name_, node)); PNode thisNode = SharedFromPointerNode(this); node->parent_ = thisNode; PScene scene = scene_.lock(); if (!scene) scene = std::dynamic_pointer_cast<Scene>(thisNode); node->scene_ = scene; if (scene) { PLight light = std::dynamic_pointer_cast<Light>(node); if (light) scene->AddLight(light.get()); else { PCamera camera = std::dynamic_pointer_cast<Camera>(node); if (camera) scene->AddCamera(camera.get()); else { auto ps = std::dynamic_pointer_cast<ParticleSystem>(node); if (ps) scene->AddParticleSystem(ps.get()); } } } node->MarkAsDirty(); }