ULRE/inc/hgl/component/MeshComponent.h

86 lines
1.9 KiB
C
Raw Normal View History

2025-06-15 17:53:15 +08:00
#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();
ComponentData *Duplication() override
{
return(new MeshComponentData(mesh));
}
2025-06-15 17:53:15 +08:00
};//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:
COMPONENT_CLASS_BODY(Mesh)
2025-06-15 17:53:15 +08:00
public:
MeshComponent(MeshComponentData *cd,MeshComponentManager *cm):RenderComponent(cd,cm){sm_data=cd;}
virtual ~MeshComponent()=default;
MeshComponentData &GetData() {return *sm_data;}
const MeshComponentData &GetData()const {return *sm_data;}
2025-06-15 17:53:15 +08:00
Mesh *GetMesh() const{return sm_data->mesh;}
2025-06-15 17:53:15 +08:00
};//class MeshComponent
COMPONENT_NAMESPACE_END