From 9e74d19220cc3f3f26c4152f12b75ccd4fa7a5c2 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 25 Jun 2025 00:10:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8SceneNode=E4=B8=AD=E6=B7=BB=E5=8A=A0Cr?= =?UTF-8?q?eateNode/Duplication/DuplicationChildNodes/DuplicationComponent?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/SceneNode.h | 31 ++++++++++++++++++++++++++++-- src/SceneGraph/scene/SceneNode.cpp | 20 ------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/inc/hgl/graph/SceneNode.h b/inc/hgl/graph/SceneNode.h index b60aa48f..f31c315c 100644 --- a/inc/hgl/graph/SceneNode.h +++ b/inc/hgl/graph/SceneNode.h @@ -61,6 +61,35 @@ namespace hgl::graph virtual ~SceneNode(); + virtual SceneNode * CreateNode()const{return(new SceneNode);} ///<创建一个同类的节点对象 + + virtual void DuplicationChildNodes(SceneNode *node) const ///<复制子节点到指定节点 + { + for(SceneNode *sn:GetChildNode()) + node->Add(sn->Duplication()); + } + + virtual void DuplicationComponents(SceneNode *node) const ///<复制组件到指定节点 + { + for(Component *c:GetComponents()) + node->AttachComponent(c->Duplication()); + } + + virtual SceneNode * Duplication() const ///<复制一个场景节点 + { + if(!this) + return nullptr; + + SceneNode *node=CreateNode(); + + node->SetSceneMatrix(GetSceneMatrix()); //复制本地矩阵 + + DuplicationChildNodes(node); //复制子节点 + DuplicationComponents(node); //复制组件 + + return node; + } + void Clear() override { SceneOrient::Clear(); @@ -137,6 +166,4 @@ namespace hgl::graph const ComponentSet &GetComponents ()const{return component_set;} };//class SceneNode - - SceneNode *Duplication(SceneNode *); ///<复制一个场景节点 }//namespace hgl::graph diff --git a/src/SceneGraph/scene/SceneNode.cpp b/src/SceneGraph/scene/SceneNode.cpp index 03c9594f..182e750a 100644 --- a/src/SceneGraph/scene/SceneNode.cpp +++ b/src/SceneGraph/scene/SceneNode.cpp @@ -4,26 +4,6 @@ namespace hgl::graph { - SceneNode *Duplication(SceneNode *src_node) - { - if(!src_node) - return nullptr; - - SceneNode *node=new SceneNode(*(SceneOrient *)src_node); - - for(SceneNode *sn:src_node->GetChildNode()) - { - node->Add(Duplication(sn)); - } - - for(Component *c:src_node->GetComponents()) - { - node->AttachComponent(c->Duplication()); - } - - return node; - } - //void SceneNode::SetRenderable(Mesh *ri) //{ // render_obj=ri;