StaticMeshComponent改为MeshComponent
This commit is contained in:
parent
ec4125776a
commit
97040176d6
@ -13,7 +13,7 @@
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -152,8 +152,8 @@ private:
|
||||
{
|
||||
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
||||
|
||||
CreateComponent<StaticMeshComponent>(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
|
||||
CreateComponent<StaticMeshComponent>(scene_root,ro_billboard);
|
||||
CreateComponent<MeshComponent>(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
|
||||
CreateComponent<MeshComponent>(scene_root,ro_billboard);
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -83,7 +83,7 @@ private:
|
||||
rad=deg2rad<double>((360.0f/double(TRIANGLE_NUMBER))*i); //这里一定要加<double>或<float>,否则结果用int保存会出现问题
|
||||
mat=rotate(rad,Vector3f(0,0,1));
|
||||
|
||||
CreateComponent<StaticMeshComponent>(mat,scene_root,render_obj);
|
||||
CreateComponent<MeshComponent>(mat,scene_root,render_obj);
|
||||
}
|
||||
|
||||
return(true);
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -94,7 +94,7 @@ private:
|
||||
|
||||
mat=rotate(deg2rad<double>(TRI_ROTATE_ANGLE*i),AxisVector::Z);
|
||||
|
||||
CreateComponent<StaticMeshComponent>(mat,scene_root,render_obj[i].mesh);
|
||||
CreateComponent<MeshComponent>(mat,scene_root,render_obj[i].mesh);
|
||||
}
|
||||
|
||||
return(true);
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -90,7 +90,7 @@ private:
|
||||
if(!mesh_triangle)
|
||||
return(false);
|
||||
|
||||
return CreateComponent<StaticMeshComponent>(GetSceneRoot(),mesh_triangle); //创建一个静态网格组件
|
||||
return CreateComponent<MeshComponent>(GetSceneRoot(),mesh_triangle); //创建一个静态网格组件
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -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
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -84,7 +84,7 @@ private:
|
||||
if(!ri)
|
||||
return;
|
||||
|
||||
CreateComponent<StaticMeshComponent>(mat,parent_node,ri);
|
||||
CreateComponent<MeshComponent>(mat,parent_node,ri);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -101,7 +101,7 @@ private:
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
CreateComponent<StaticMeshComponent>(parent_node,ri);
|
||||
CreateComponent<MeshComponent>(parent_node,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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})
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
|
||||
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<StaticMeshComponentData *>(data));
|
||||
return CreateComponent(reinterpret_cast<MeshComponentData *>(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
|
@ -8,7 +8,7 @@
|
||||
#include"RenderAssignBuffer.h"
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
#include<hgl/graph/CameraInfo.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
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;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/graph/VKRenderAssign.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderAssignBuffer::RenderAssignBuffer(VulkanDevice *dev,Material *mtl)
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/Mesh.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
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<StaticMeshComponent *>(component);
|
||||
MeshComponent *smc=reinterpret_cast<MeshComponent *>(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;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include<hgl/graph/RenderNode.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/component/StaticMeshComponent.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user