2025-06-15 17:53:15 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include<hgl/component/RenderComponent.h>
|
|
|
|
#include<hgl/graph/Mesh.h>
|
|
|
|
|
2025-06-17 00:34:42 +08:00
|
|
|
//#include<hgl/log/LogInfo.h>
|
|
|
|
|
2025-06-15 17:53:15 +08:00
|
|
|
COMPONENT_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
struct MeshComponentData:public ComponentData
|
|
|
|
{
|
2025-06-17 00:34:42 +08:00
|
|
|
//static uint unique_id_count;
|
|
|
|
|
|
|
|
//uint unique_id;
|
|
|
|
|
2025-06-15 17:53:15 +08:00
|
|
|
Mesh *mesh;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
MeshComponentData()
|
|
|
|
{
|
|
|
|
mesh=nullptr;
|
2025-06-17 00:34:42 +08:00
|
|
|
|
|
|
|
// unique_id=++unique_id_count;
|
|
|
|
// LOG_INFO(AnsiString("MeshComponentData():")+AnsiString::numberOf(unique_id));
|
2025-06-15 17:53:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MeshComponentData(Mesh *m)
|
|
|
|
{
|
|
|
|
mesh=m;
|
2025-06-17 00:34:42 +08:00
|
|
|
|
|
|
|
// unique_id=++unique_id_count;
|
|
|
|
// LOG_INFO(AnsiString("MeshComponentData(Mesh *):")+AnsiString::numberOf(unique_id));
|
2025-06-15 17:53:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~MeshComponentData();
|
|
|
|
};//struct MeshComponentData
|
|
|
|
|
|
|
|
class MeshComponent;
|
|
|
|
|
|
|
|
class MeshComponentManager:public ComponentManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2025-06-17 00:34:42 +08:00
|
|
|
COMPONENT_MANAGER_CLASS_BODY(Mesh)
|
2025-06-15 17:53:15 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
MeshComponentManager()=default;
|
|
|
|
|
2025-06-17 00:34:42 +08:00
|
|
|
Component *CreateComponent(ComponentDataPtr cdp) override;
|
2025-06-15 17:53:15 +08:00
|
|
|
|
2025-06-17 00:34:42 +08:00
|
|
|
MeshComponent *CreateComponent(Mesh *);
|
2025-06-15 17:53:15 +08:00
|
|
|
};//class MeshComponentManager
|
|
|
|
|
|
|
|
class MeshComponent:public RenderComponent
|
|
|
|
{
|
2025-06-17 00:34:42 +08:00
|
|
|
WeakPtr<ComponentData> sm_data;
|
2025-06-15 17:53:15 +08:00
|
|
|
|
2025-06-16 00:02:07 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
COMPONENT_CLASS_BODY(Mesh)
|
|
|
|
|
2025-06-15 17:53:15 +08:00
|
|
|
public:
|
|
|
|
|
2025-06-17 00:34:42 +08:00
|
|
|
MeshComponent(ComponentDataPtr cdp,MeshComponentManager *cm):RenderComponent(cdp,cm)
|
|
|
|
{
|
|
|
|
sm_data=cdp;
|
|
|
|
}
|
2025-06-15 17:53:15 +08:00
|
|
|
|
|
|
|
virtual ~MeshComponent()=default;
|
|
|
|
|
2025-06-17 00:34:42 +08:00
|
|
|
MeshComponentData *GetData() {return dynamic_cast< MeshComponentData *>(sm_data.get());}
|
|
|
|
const MeshComponentData *GetData()const {return dynamic_cast<const MeshComponentData *>(sm_data.const_get());}
|
2025-06-15 17:53:15 +08:00
|
|
|
|
2025-06-17 00:34:42 +08:00
|
|
|
Mesh *GetMesh()const
|
|
|
|
{
|
|
|
|
if(!sm_data.valid())
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
const MeshComponentData *mcd=dynamic_cast<const MeshComponentData *>(sm_data.const_get());
|
|
|
|
|
|
|
|
if(!mcd)
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
return mcd->mesh;
|
|
|
|
}
|
2025-06-15 17:53:15 +08:00
|
|
|
};//class MeshComponent
|
|
|
|
|
|
|
|
COMPONENT_NAMESPACE_END
|