From ab3f7714553b4658744249df2bfcec676aec7e6a Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 25 Mar 2025 02:18:49 +0800 Subject: [PATCH] =?UTF-8?q?SceneNode=E5=A2=9E=E5=8A=A0Component=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=87=BD=E6=95=B0(=E4=BD=86Component=E7=9A=84?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E8=BF=98=E6=B2=A1=E6=9C=89=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E7=A1=AE=E5=AE=9A)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/SceneNode.h | 11 +++++++++- src/SceneGraph/scene/SceneNode.cpp | 33 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/inc/hgl/graph/SceneNode.h b/inc/hgl/graph/SceneNode.h index 5dde18c7..d4a53e5e 100644 --- a/inc/hgl/graph/SceneNode.h +++ b/inc/hgl/graph/SceneNode.h @@ -69,10 +69,11 @@ namespace hgl LocalBoundingBox.SetZero(); ChildNode.Clear(); + ComponentList.Clear(); render_obj=nullptr; } - const bool IsEmpty()const + const bool ChildNodeIsEmpty()const { if(render_obj)return(false); if(ChildNode.GetCount())return(false); @@ -111,6 +112,14 @@ namespace hgl public: //组件相关方法 + bool ComponentIsEmpty ()const {return ComponentList.GetCount()==0;} ///<是否没有组件 + virtual int GetComponentCount ()const {return ComponentList.GetCount();} ///<取得组件数量 + virtual void AddComponent (Component *comp) {ComponentList.Add(comp);} ///<添加一个组件 + virtual void RemoveComponent (Component *comp) {ComponentList.DeleteByValue(comp);} ///<删除一个组件 + bool Contains (Component *comp) {return ComponentList.Contains(comp);} ///<是否包含指定组件 + + bool HasComponent (const ComponentManager *); ///<是否有指定组件管理器的组件 + virtual int GetComponents (List &comp_list,const ComponentManager *); ///<取得所有组件 };//class SceneNode diff --git a/src/SceneGraph/scene/SceneNode.cpp b/src/SceneGraph/scene/SceneNode.cpp index 02a41dd7..dd5c8993 100644 --- a/src/SceneGraph/scene/SceneNode.cpp +++ b/src/SceneGraph/scene/SceneNode.cpp @@ -88,5 +88,38 @@ namespace hgl LocalBoundingBox=local; } + + int SceneNode::GetComponents(List &comp_list,const ComponentManager *mgr) + { + if(!mgr)return(-1); + if(ComponentIsEmpty())return(0); + + int result=0; + + for(Component *c:ComponentList) + { + if(c->GetManager()==mgr) + { + comp_list.Add(c); + ++result; + } + } + + return result; + } + + bool SceneNode::HasComponent(const ComponentManager *mgr) + { + if(!mgr)return(false); + if(ComponentIsEmpty())return(false); + + for(Component *c:ComponentList) + { + if(c->GetManager()==mgr) + return(true); + } + + return(false); + } }//namespace graph }//namespace hgl