增加新的StaticMeshComponent,并添加关于各Component关系的注释

This commit is contained in:
2025-03-25 23:15:38 +08:00
parent 87989a8e42
commit 964c17cf94
3 changed files with 79 additions and 3 deletions

View File

@@ -4,6 +4,30 @@
#include<hgl/type/SortedSet.h>
#include<hgl/type/List.h>
/**
* Component/Data/Manager 体系设计简要说明
*
* 本体系参考AMD FidelityFX但并不完全一致。
*
* AMD FidelityFX中Component存放于Entity下而我方中与其类似的定义为SceneNode。
* 不管是Entity还是SceneNode它们都提供空间变换以及子节点、Component的管理。
*
* ComponentData是每个Component的数据用于向Component或是其它模块提供数据。
* ComponentManager是Component的管理器用于管理Component的创建、销毁、更新等。
*
* Component是组件的基类所有组件都从这里派生。
*
*
* RenderComponent是可渲染组件的基类所有可渲染组件都从这里派生。它继承于Component。
*
* PrimitiveComponent是图元组件的基类所有图元组件都从这里派生。它继承于RenderComponent。
* 它再度派生出的任何Component都必须是一个有3D空间的几何图元。
* 引擎中的空间、物理、等都由PrimitiveComponent提供数据进行计算。
*
* StaticMeshComponent是静态网格组件它是一个具体的PrimitiveComponent实现。
*
*/
#define COMPONENT_NAMESPACE hgl::graph
#define COMPONENT_NAMESPACE_BEGIN namespace COMPONENT_NAMESPACE {
#define COMPONENT_NAMESPACE_END }

View File

@@ -1,18 +1,19 @@
#pragma once
#include<hgl/component/RenderComponent.h>
#include<hgl/graph/VKRenderable.h>
COMPONENT_NAMESPACE_BEGIN
/**
* 图元组件<br>
* 组件中的元素必须是一个可以明确描述的几何体,可以被明确标记尺寸、参与空间、物理计算等。
*/
class PrimitiveComponent:public RenderComponent
{
public:
PrimitiveComponent()=default;
virtual ~PrimitiveComponent()=default;
Renderable *GetRenderable();
};//class PrimitiveComponent
COMPONENT_NAMESPACE_END

View File

@@ -0,0 +1,51 @@
#pragma once
#include<hgl/component/PrimitiveComponent.h>
#include<hgl/graph/VKRenderable.h>
COMPONENT_NAMESPACE_BEGIN
struct StaticMeshComponentData:public ComponentData
{
Renderable *renderable;
};//struct StaticMeshComponentData
class StaticMeshComponent:public PrimitiveComponent;
class StaticMeshComponentManager:public ComponentManager
{
public:
StaticMeshComponentManager()=default;
StaticMeshComponent *CreateStaticMeshComponent(SceneNode *psn,StaticMeshComponentData *data);
virtual Component *CreateComponent(SceneNode *psn,ComponentData *data) override
{
return CreateStaticMeshComponent(psn,reinterpret_cast<StaticMeshComponentData *>(data));
}
};//class StaticMeshComponentManager
class StaticMeshComponent:public PrimitiveComponent
{
StaticMeshComponentData *sm_data;
public:
StaticMeshComponent(SceneNode *psn,ComponentData *cd,ComponentManager *cm)
:PrimitiveComponent(psn,cd,cm)
{
sm_data=reinterpret_cast<StaticMeshComponentData *>(cd);
}
virtual ~StaticMeshComponent()
{
SAFE_CLEAR(sm_Data);
}
StaticMeshComponentData &GetData() {return *sm_data;}
const StaticMeshComponentData &GetData()const {return *sm_data;}
};//class StaticMeshComponent
COMPONENT_NAMESPACE_END