StaticMeshComponent改为MeshComponent
This commit is contained in:
@@ -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实现。
|
||||
*
|
||||
*/
|
||||
|
||||
|
91
inc/hgl/component/MeshComponent.h
Normal file
91
inc/hgl/component/MeshComponent.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/RenderComponent.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
|
||||
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<MeshComponentManager>(true);
|
||||
}
|
||||
|
||||
static constexpr const size_t StaticHashCode (){return hgl::GetTypeHash<MeshComponentManager>();}
|
||||
static constexpr const size_t StaticComponentHashCode (){return hgl::GetTypeHash<MeshComponent>();}
|
||||
|
||||
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<MeshComponent>();
|
||||
}
|
||||
|
||||
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
|
@@ -1,91 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/component/RenderComponent.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
|
||||
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<StaticMeshComponentManager>(true);
|
||||
}
|
||||
|
||||
static constexpr const size_t StaticHashCode (){return hgl::GetTypeHash<StaticMeshComponentManager>();}
|
||||
static constexpr const size_t StaticComponentHashCode (){return hgl::GetTypeHash<StaticMeshComponent>();}
|
||||
|
||||
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<StaticMeshComponent>();
|
||||
}
|
||||
|
||||
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
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -9,13 +9,13 @@ namespace hgl
|
||||
{
|
||||
class Mesh;
|
||||
class MaterialInstance;
|
||||
class StaticMeshComponent;
|
||||
class MeshComponent;
|
||||
|
||||
struct RenderNode:public Comparator<RenderNode>
|
||||
{
|
||||
uint index; ///<在MaterialRenderList中的索引
|
||||
|
||||
StaticMeshComponent *sm_component; ///<静态网格组件
|
||||
MeshComponent *sm_component; ///<静态网格组件
|
||||
|
||||
uint32 l2w_version;
|
||||
uint32 l2w_index;
|
||||
|
@@ -135,7 +135,7 @@ class IndirectDispatchBuffer;
|
||||
|
||||
class RenderResource;
|
||||
|
||||
class StaticMeshComponent;
|
||||
class MeshComponent;
|
||||
|
||||
class SceneNode;
|
||||
class Scene;
|
||||
|
Reference in New Issue
Block a user