From 97040176d60e63f2801085092a506eeec87d5fa3 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sun, 15 Jun 2025 17:53:15 +0800 Subject: [PATCH] =?UTF-8?q?StaticMeshComponent=E6=94=B9=E4=B8=BAMeshCompon?= =?UTF-8?q?ent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Basic/BillboardTest.cpp | 6 +- example/Basic/auto_instance.cpp | 4 +- .../Basic/auto_merge_material_instance.cpp | 4 +- example/Basic/draw_triangle_use_UBO.cpp | 4 +- example/Gizmo/GizmoResource.h | 4 +- example/Gizmo/PlaneGrid3D.cpp | 4 +- example/Gizmo/RayPicking.cpp | 4 +- inc/hgl/component/Component.h | 4 +- inc/hgl/component/MeshComponent.h | 91 +++++++++++++++++++ inc/hgl/component/StaticMeshComponent.h | 91 ------------------- inc/hgl/graph/MaterialRenderList.h | 4 +- inc/hgl/graph/RenderList.h | 2 +- inc/hgl/graph/RenderNode.h | 4 +- inc/hgl/graph/VK.h | 2 +- src/SceneGraph/CMakeLists.txt | 4 +- ...ntManager.cpp => MeshComponentManager.cpp} | 12 +-- src/SceneGraph/render/MaterialRenderList.cpp | 6 +- src/SceneGraph/render/RenderAssignBuffer.cpp | 2 +- src/SceneGraph/render/RenderList.cpp | 8 +- src/SceneGraph/render/RenderNode.cpp | 2 +- 20 files changed, 131 insertions(+), 131 deletions(-) create mode 100644 inc/hgl/component/MeshComponent.h delete mode 100644 inc/hgl/component/StaticMeshComponent.h rename src/SceneGraph/component/{StaticMeshComponentManager.cpp => MeshComponentManager.cpp} (50%) diff --git a/example/Basic/BillboardTest.cpp b/example/Basic/BillboardTest.cpp index a99b537d..21b853d4 100644 --- a/example/Basic/BillboardTest.cpp +++ b/example/Basic/BillboardTest.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include using namespace hgl; using namespace hgl::graph; @@ -152,8 +152,8 @@ private: { SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点 - CreateComponent(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid)); - CreateComponent(scene_root,ro_billboard); + CreateComponent(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid)); + CreateComponent(scene_root,ro_billboard); CameraControl *camera_control=GetCameraControl(); diff --git a/example/Basic/auto_instance.cpp b/example/Basic/auto_instance.cpp index b5e4a841..2295757f 100644 --- a/example/Basic/auto_instance.cpp +++ b/example/Basic/auto_instance.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include using namespace hgl; using namespace hgl::graph; @@ -83,7 +83,7 @@ private: rad=deg2rad((360.0f/double(TRIANGLE_NUMBER))*i); //这里一定要加,否则结果用int保存会出现问题 mat=rotate(rad,Vector3f(0,0,1)); - CreateComponent(mat,scene_root,render_obj); + CreateComponent(mat,scene_root,render_obj); } return(true); diff --git a/example/Basic/auto_merge_material_instance.cpp b/example/Basic/auto_merge_material_instance.cpp index 4c0f6fb0..44b34947 100644 --- a/example/Basic/auto_merge_material_instance.cpp +++ b/example/Basic/auto_merge_material_instance.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include using namespace hgl; using namespace hgl::graph; @@ -94,7 +94,7 @@ private: mat=rotate(deg2rad(TRI_ROTATE_ANGLE*i),AxisVector::Z); - CreateComponent(mat,scene_root,render_obj[i].mesh); + CreateComponent(mat,scene_root,render_obj[i].mesh); } return(true); diff --git a/example/Basic/draw_triangle_use_UBO.cpp b/example/Basic/draw_triangle_use_UBO.cpp index a38fa654..3621f50b 100644 --- a/example/Basic/draw_triangle_use_UBO.cpp +++ b/example/Basic/draw_triangle_use_UBO.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include using namespace hgl; using namespace hgl::graph; @@ -90,7 +90,7 @@ private: if(!mesh_triangle) return(false); - return CreateComponent(GetSceneRoot(),mesh_triangle); //创建一个静态网格组件 + return CreateComponent(GetSceneRoot(),mesh_triangle); //创建一个静态网格组件 } public: diff --git a/example/Gizmo/GizmoResource.h b/example/Gizmo/GizmoResource.h index d9e385d0..8c2c66e1 100644 --- a/example/Gizmo/GizmoResource.h +++ b/example/Gizmo/GizmoResource.h @@ -7,7 +7,7 @@ VK_NAMESPACE_BEGIN class SceneNode; class PrimitiveCreater; -class StaticMeshComponent; +class MeshComponent; constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]= { @@ -38,6 +38,6 @@ constexpr const float GIZMO_TWO_AXIS_OFFSET =5.0F; Mesh *GetGizmoMesh(const GizmoShape &gs,const GizmoColor &); -StaticMeshComponent *CreateGizmoStaticMeshComponent(SceneNode *); +MeshComponent *CreateGizmoMeshComponent(SceneNode *); VK_NAMESPACE_END diff --git a/example/Gizmo/PlaneGrid3D.cpp b/example/Gizmo/PlaneGrid3D.cpp index 4db3d5ee..1edcd63b 100644 --- a/example/Gizmo/PlaneGrid3D.cpp +++ b/example/Gizmo/PlaneGrid3D.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include using namespace hgl; using namespace hgl::graph; @@ -84,7 +84,7 @@ private: if(!ri) return; - CreateComponent(mat,parent_node,ri); + CreateComponent(mat,parent_node,ri); } bool InitScene() diff --git a/example/Gizmo/RayPicking.cpp b/example/Gizmo/RayPicking.cpp index 5fe3af5f..1d862058 100644 --- a/example/Gizmo/RayPicking.cpp +++ b/example/Gizmo/RayPicking.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include using namespace hgl; using namespace hgl::graph; @@ -101,7 +101,7 @@ private: return(nullptr); } - CreateComponent(parent_node,ri); + CreateComponent(parent_node,ri); return ri; } diff --git a/inc/hgl/component/Component.h b/inc/hgl/component/Component.h index 52c145eb..fb9aefcb 100644 --- a/inc/hgl/component/Component.h +++ b/inc/hgl/component/Component.h @@ -19,7 +19,7 @@ * 需要注意的是:同AMD FidelityFX一样,大部分ComponentManager与Scene基本无关。 * 因为同样的数据可能出现在多个World之中。 * 仅有那些与Scene密切相关的Component它对应的Manager才会出现在Scene中,比如CameraManager/LightManager。 -* 而如StaticMeshComponent之类的纯资源型就会是独立存在的。 +* 而如MeshComponent之类的纯资源型就会是独立存在的。 * * Component是组件的基类,所有组件都从这里派生。 * @@ -31,7 +31,7 @@ * RenderComponent是可渲染组件的基类,所有可渲染组件都从这里派生。 * -* StaticMeshComponent是静态网格组件,它是一个具体的RenderComponent实现。 +* MeshComponent是静态网格组件,它是一个具体的RenderComponent实现。 * */ diff --git a/inc/hgl/component/MeshComponent.h b/inc/hgl/component/MeshComponent.h new file mode 100644 index 00000000..2a55bb79 --- /dev/null +++ b/inc/hgl/component/MeshComponent.h @@ -0,0 +1,91 @@ +#pragma once + +#include +#include + +COMPONENT_NAMESPACE_BEGIN + +struct MeshComponentData:public ComponentData +{ + Mesh *mesh; + +public: + + MeshComponentData() + { + mesh=nullptr; + } + + MeshComponentData(Mesh *m) + { + mesh=m; + } + + virtual ~MeshComponentData(); +};//struct MeshComponentData + +class MeshComponent; + +class MeshComponentManager:public ComponentManager +{ +public: + + static MeshComponentManager *GetDefaultManager() + { + return GetComponentManager(true); + } + + static constexpr const size_t StaticHashCode (){return hgl::GetTypeHash();} + static constexpr const size_t StaticComponentHashCode (){return hgl::GetTypeHash();} + + const size_t GetComponentHashCode ()const override{return MeshComponentManager::StaticComponentHashCode();} + const size_t GetHashCode ()const override{return MeshComponentManager::StaticHashCode();} + +public: + + MeshComponentManager()=default; + + MeshComponent *CreateComponent(MeshComponentData *data); + + MeshComponent *CreateComponent(Mesh *m) + { + auto sm_cd=new MeshComponentData(m); + + return CreateComponent(sm_cd); + } + + virtual Component *CreateComponent(ComponentData *data) override; +};//class MeshComponentManager + +class MeshComponent:public RenderComponent +{ + MeshComponentData *sm_data; + +public: + + MeshComponent(MeshComponentData *cd,MeshComponentManager *cm):RenderComponent(cd,cm){sm_data=cd;} + + virtual ~MeshComponent()=default; + + static MeshComponentManager *GetDefaultManager() + { + return MeshComponentManager::GetDefaultManager(); + } + + static constexpr const size_t StaticHashCode() + { + return hgl::GetTypeHash(); + } + + const size_t GetHashCode()const override + { + return MeshComponent::StaticHashCode(); + } + + MeshComponentData &GetData() {return *sm_data;} + const MeshComponentData &GetData()const {return *sm_data;} + + Mesh *GetMesh() const{return sm_data->mesh;} +};//class MeshComponent + +COMPONENT_NAMESPACE_END diff --git a/inc/hgl/component/StaticMeshComponent.h b/inc/hgl/component/StaticMeshComponent.h deleted file mode 100644 index ca3d43cf..00000000 --- a/inc/hgl/component/StaticMeshComponent.h +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include -#include - -COMPONENT_NAMESPACE_BEGIN - -struct StaticMeshComponentData:public ComponentData -{ - Mesh *mesh; - -public: - - StaticMeshComponentData() - { - mesh=nullptr; - } - - StaticMeshComponentData(Mesh *m) - { - mesh=m; - } - - virtual ~StaticMeshComponentData(); -};//struct StaticMeshComponentData - -class StaticMeshComponent; - -class StaticMeshComponentManager:public ComponentManager -{ -public: - - static StaticMeshComponentManager *GetDefaultManager() - { - return GetComponentManager(true); - } - - static constexpr const size_t StaticHashCode (){return hgl::GetTypeHash();} - static constexpr const size_t StaticComponentHashCode (){return hgl::GetTypeHash();} - - const size_t GetComponentHashCode ()const override{return StaticMeshComponentManager::StaticComponentHashCode();} - const size_t GetHashCode ()const override{return StaticMeshComponentManager::StaticHashCode();} - -public: - - StaticMeshComponentManager()=default; - - StaticMeshComponent *CreateComponent(StaticMeshComponentData *data); - - StaticMeshComponent *CreateComponent(Mesh *m) - { - auto sm_cd=new StaticMeshComponentData(m); - - return CreateComponent(sm_cd); - } - - virtual Component *CreateComponent(ComponentData *data) override; -};//class StaticMeshComponentManager - -class StaticMeshComponent:public RenderComponent -{ - StaticMeshComponentData *sm_data; - -public: - - StaticMeshComponent(StaticMeshComponentData *cd,StaticMeshComponentManager *cm):RenderComponent(cd,cm){sm_data=cd;} - - virtual ~StaticMeshComponent()=default; - - static StaticMeshComponentManager *GetDefaultManager() - { - return StaticMeshComponentManager::GetDefaultManager(); - } - - static constexpr const size_t StaticHashCode() - { - return hgl::GetTypeHash(); - } - - const size_t GetHashCode()const override - { - return StaticMeshComponent::StaticHashCode(); - } - - StaticMeshComponentData &GetData() {return *sm_data;} - const StaticMeshComponentData &GetData()const {return *sm_data;} - - Mesh *GetMesh() const{return sm_data->mesh;} -};//class StaticMeshComponent - -COMPONENT_NAMESPACE_END diff --git a/inc/hgl/graph/MaterialRenderList.h b/inc/hgl/graph/MaterialRenderList.h index 8abe9d3c..6ed3b304 100644 --- a/inc/hgl/graph/MaterialRenderList.h +++ b/inc/hgl/graph/MaterialRenderList.h @@ -109,7 +109,7 @@ public: MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi); ~MaterialRenderList(); - void Add(StaticMeshComponent *); + void Add(MeshComponent *); void SetCameraInfo(CameraInfo *ci){camera_info=ci;} @@ -120,6 +120,6 @@ public: void Render(RenderCmdBuffer *); void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵 - void UpdateMaterialInstance(StaticMeshComponent *); + void UpdateMaterialInstance(MeshComponent *); };//class MaterialRenderList VK_NAMESPACE_END diff --git a/inc/hgl/graph/RenderList.h b/inc/hgl/graph/RenderList.h index 8a31121c..0cd75e27 100644 --- a/inc/hgl/graph/RenderList.h +++ b/inc/hgl/graph/RenderList.h @@ -46,7 +46,7 @@ namespace hgl virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象 virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据 - virtual void UpdateMaterialInstance(StaticMeshComponent *); ///<有对象互换了材质实例 + virtual void UpdateMaterialInstance(MeshComponent *); ///<有对象互换了材质实例 virtual void Clear(); ///<彻底清理 };//class RenderList diff --git a/inc/hgl/graph/RenderNode.h b/inc/hgl/graph/RenderNode.h index e6a887b3..b1f37b42 100644 --- a/inc/hgl/graph/RenderNode.h +++ b/inc/hgl/graph/RenderNode.h @@ -9,13 +9,13 @@ namespace hgl { class Mesh; class MaterialInstance; - class StaticMeshComponent; + class MeshComponent; struct RenderNode:public Comparator { uint index; ///<在MaterialRenderList中的索引 - StaticMeshComponent *sm_component; ///<静态网格组件 + MeshComponent *sm_component; ///<静态网格组件 uint32 l2w_version; uint32 l2w_index; diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index aaa542ef..1ead7c27 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -135,7 +135,7 @@ class IndirectDispatchBuffer; class RenderResource; -class StaticMeshComponent; +class MeshComponent; class SceneNode; class Scene; diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index f4fe9cbf..58aabaee 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -301,11 +301,11 @@ SET(COMPONENT_FILES ${COMPONENT_INCLUDE_PATH}/Component.h ${COMPONENT_INCLUDE_PATH}/SceneComponent.h ${COMPONENT_INCLUDE_PATH}/PrimitiveComponent.h ${COMPONENT_INCLUDE_PATH}/RenderComponent.h - ${COMPONENT_INCLUDE_PATH}/StaticMeshComponent.h + ${COMPONENT_INCLUDE_PATH}/MeshComponent.h component/Component.cpp component/ComponentManager.cpp component/SceneComponent.cpp - component/StaticMeshComponentManager.cpp + component/MeshComponentManager.cpp ) SOURCE_GROUP("Component" FILES ${COMPONENT_FILES}) diff --git a/src/SceneGraph/component/StaticMeshComponentManager.cpp b/src/SceneGraph/component/MeshComponentManager.cpp similarity index 50% rename from src/SceneGraph/component/StaticMeshComponentManager.cpp rename to src/SceneGraph/component/MeshComponentManager.cpp index 37c2d554..0ccd83a1 100644 --- a/src/SceneGraph/component/StaticMeshComponentManager.cpp +++ b/src/SceneGraph/component/MeshComponentManager.cpp @@ -1,10 +1,10 @@ -#include +#include #include #include COMPONENT_NAMESPACE_BEGIN -StaticMeshComponentData::~StaticMeshComponentData() +MeshComponentData::~MeshComponentData() { if(mesh) { @@ -13,18 +13,18 @@ StaticMeshComponentData::~StaticMeshComponentData() } } -Component *StaticMeshComponentManager::CreateComponent(ComponentData *data) +Component *MeshComponentManager::CreateComponent(ComponentData *data) { if(!data)return(nullptr); - return CreateComponent(reinterpret_cast(data)); + return CreateComponent(reinterpret_cast(data)); } -StaticMeshComponent *StaticMeshComponentManager::CreateComponent(StaticMeshComponentData *data) +MeshComponent *MeshComponentManager::CreateComponent(MeshComponentData *data) { if(!data)return(nullptr); - return(new StaticMeshComponent(data,this)); + return(new MeshComponent(data,this)); } COMPONENT_NAMESPACE_END diff --git a/src/SceneGraph/render/MaterialRenderList.cpp b/src/SceneGraph/render/MaterialRenderList.cpp index 94821976..bb9c8897 100644 --- a/src/SceneGraph/render/MaterialRenderList.cpp +++ b/src/SceneGraph/render/MaterialRenderList.cpp @@ -8,7 +8,7 @@ #include"RenderAssignBuffer.h" #include #include -#include +#include VK_NAMESPACE_BEGIN MaterialRenderList::MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi) @@ -45,7 +45,7 @@ MaterialRenderList::~MaterialRenderList() SAFE_CLEAR(assign_buffer); } -void MaterialRenderList::Add(StaticMeshComponent *smc) +void MaterialRenderList::Add(MeshComponent *smc) { if(!smc) return; @@ -130,7 +130,7 @@ void MaterialRenderList::UpdateLocalToWorld() } } -void MaterialRenderList::UpdateMaterialInstance(StaticMeshComponent *smc) +void MaterialRenderList::UpdateMaterialInstance(MeshComponent *smc) { if(!smc)return; diff --git a/src/SceneGraph/render/RenderAssignBuffer.cpp b/src/SceneGraph/render/RenderAssignBuffer.cpp index 81ec5614..167b8070 100644 --- a/src/SceneGraph/render/RenderAssignBuffer.cpp +++ b/src/SceneGraph/render/RenderAssignBuffer.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include VK_NAMESPACE_BEGIN RenderAssignBuffer::RenderAssignBuffer(VulkanDevice *dev,Material *mtl) diff --git a/src/SceneGraph/render/RenderList.cpp b/src/SceneGraph/render/RenderList.cpp index a9b7a92e..36d8877b 100644 --- a/src/SceneGraph/render/RenderList.cpp +++ b/src/SceneGraph/render/RenderList.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include namespace hgl { @@ -25,10 +25,10 @@ namespace hgl for(auto component:sn->GetComponents()) { - if(component->GetHashCode()!=StaticMeshComponent::StaticHashCode()) //暂时只支持StaticMeshComponent + if(component->GetHashCode()!=MeshComponent::StaticHashCode()) //暂时只支持MeshComponent continue; - StaticMeshComponent *smc=reinterpret_cast(component); + MeshComponent *smc=reinterpret_cast(component); Mesh *mesh=smc->GetMesh(); @@ -91,7 +91,7 @@ namespace hgl mrl_map.UpdateLocalToWorld(); } - void RenderList::UpdateMaterialInstance(StaticMeshComponent *smc) + void RenderList::UpdateMaterialInstance(MeshComponent *smc) { if(!smc)return; diff --git a/src/SceneGraph/render/RenderNode.cpp b/src/SceneGraph/render/RenderNode.cpp index 7fac47d9..22480ceb 100644 --- a/src/SceneGraph/render/RenderNode.cpp +++ b/src/SceneGraph/render/RenderNode.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include VK_NAMESPACE_BEGIN /**