迁移到StaticMeshComponent渲染

This commit is contained in:
2025-06-14 21:05:36 +08:00
parent 92f612f675
commit f9675fc1e5
15 changed files with 140 additions and 141 deletions

View File

@@ -82,7 +82,7 @@ public:
public: //事件
virtual void OnAttach(SceneNode *node){if(node)OwnerNode=node;} ///<附加到节点事件
virtual void OnDetach(){OwnerNode=nullptr;} ///<从节点分离事件
virtual void OnDetach(SceneNode *node){OwnerNode=nullptr;} ///<从节点分离事件
virtual void OnFocusLost(){} ///<焦点丢失事件
virtual void OnFocusGained(){} ///<焦点获得事件

View File

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

View File

@@ -1,17 +1,17 @@
#pragma once
#include<hgl/component/Component.h>
#include<hgl/component/PrimitiveComponent.h>
COMPONENT_NAMESPACE_BEGIN
/**
* 可渲染组件
*/
class RenderComponent: public Component
class RenderComponent:public PrimitiveComponent
{
public:
using Component::Component;
using PrimitiveComponent::PrimitiveComponent;
virtual ~RenderComponent()=default;
};//class RenderComponent

View File

@@ -0,0 +1,20 @@
#pragma once
#include<hgl/component/Component.h>
COMPONENT_NAMESPACE_BEGIN
/**
* 场景组件<br>
* 场景组件中的元素必须是针对场景起作用的,并不一定需要自己绘出来,但也对场景产生影响。比如太阳光、全局风场
*/
class SceneComponent:public Component
{
public:
using Component::Component;
virtual ~SceneComponent()=default;
};//class SceneComponent
COMPONENT_NAMESPACE_END

View File

@@ -1,6 +1,6 @@
#pragma once
#include<hgl/component/PrimitiveComponent.h>
#include<hgl/component/RenderComponent.h>
#include<hgl/graph/Mesh.h>
COMPONENT_NAMESPACE_BEGIN
@@ -57,14 +57,14 @@ public:
virtual Component *CreateComponent(ComponentData *data) override;
};//class StaticMeshComponentManager
class StaticMeshComponent:public PrimitiveComponent
class StaticMeshComponent:public RenderComponent
{
StaticMeshComponentData *sm_data;
public:
StaticMeshComponent(StaticMeshComponentData *cd,StaticMeshComponentManager *cm)
:PrimitiveComponent(cd,cm)
:RenderComponent(cd,cm)
{
sm_data=cd;
}

View File

@@ -109,7 +109,7 @@ public:
MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi);
~MaterialRenderList();
void Add(SceneNode *);
void Add(StaticMeshComponent *);
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
@@ -120,6 +120,6 @@ public:
void Render(RenderCmdBuffer *);
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
void UpdateMaterialInstance(SceneNode *);
void UpdateMaterialInstance(StaticMeshComponent *);
};//class MaterialRenderList
VK_NAMESPACE_END

View File

@@ -46,7 +46,7 @@ namespace hgl
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
virtual void UpdateMaterialInstance(SceneNode *); ///<有对象互换了材质实例
virtual void UpdateMaterialInstance(StaticMeshComponent *); ///<有对象互换了材质实例
virtual void Clear(); ///<彻底清理
};//class RenderList

View File

@@ -9,13 +9,13 @@ namespace hgl
{
class Mesh;
class MaterialInstance;
class SceneNode;
class StaticMeshComponent;
struct RenderNode:public Comparator<RenderNode>
{
uint index; ///<在MaterialRenderList中的索引
SceneNode * scene_node;
StaticMeshComponent *sm_component; ///<静态网格组件
uint32 l2w_version;
uint32 l2w_index;
@@ -27,6 +27,11 @@ namespace hgl
//该函数位于MaterialRenderList.cpp
const int compare(const RenderNode &)const override;
public:
Mesh *GetMesh()const;
MaterialInstance *GetMaterialInstance()const;
};
using RenderNodeList=ArrayList<RenderNode>;

View File

@@ -30,8 +30,6 @@ namespace hgl::graph
AABB LocalBoundingBox; ///<本地坐标绑定盒
//AABB WorldBoundingBox; ///<世界坐标绑定盒
Mesh *render_obj=nullptr; ///<可渲染实例
protected:
ObjectList<SceneNode> ChildNode; ///<子节点
@@ -55,9 +53,7 @@ namespace hgl::graph
SceneNode(const SceneNode &)=delete;
SceneNode(const SceneNode *)=delete;
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
SceneNode( Mesh *ri ) {render_obj=ri;}
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
SceneNode(const Matrix4f &mat, Mesh *ri ):SceneOrient(mat) {render_obj=ri;}
public:
@@ -74,12 +70,10 @@ namespace hgl::graph
ChildNode.Clear();
ComponentSet.Clear();
render_obj=nullptr;
}
const bool ChildNodeIsEmpty()const
{
if(render_obj)return(false);
if(ChildNode.GetCount())return(false);
return(true);
@@ -89,10 +83,6 @@ namespace hgl::graph
SceneNode * GetParent() noexcept{return ParentNode;}
const SceneNode * GetParent()const noexcept{return ParentNode;}
void SetRenderable(Mesh *);
Mesh * GetRenderable() noexcept{return render_obj;}
const Mesh * GetRenderable()const noexcept{return render_obj;}
SceneNode *Add(SceneNode *sn)
{
if(!sn)
@@ -118,13 +108,32 @@ namespace hgl::graph
bool ComponentIsEmpty ()const{return ComponentSet.GetCount()==0;} ///<是否没有组件
virtual int GetComponentCount ()const{return ComponentSet.GetCount();} ///<取得组件数量
virtual void AttachComponent (Component *comp){ComponentSet.Add(comp);} ///<添加一个组件
virtual void DetachComponent (Component *comp){ComponentSet.Delete(comp);} ///<删除一个组件
virtual bool AttachComponent (Component *comp) ///<添加一个组件
{
if(!comp)return(false);
if(ComponentSet.Add(comp)<0)
return(false);
comp->OnAttach(this); //调用组件的OnAttach方法
return(true);
}
virtual void DetachComponent (Component *comp) ///<删除一个组件
{
if (!comp)return;
ComponentSet.Delete(comp);
comp->OnDetach(this); //调用组件的OnDetach方法
}
bool Contains (Component *comp){return ComponentSet.Contains(comp);} ///<是否包含指定组件
bool HasComponent (const ComponentManager *); ///<是否有指定组件管理器的组件
virtual int GetComponents (ArrayList<Component *> &comp_list,const ComponentManager *); ///<取得所有组件
const SortedSet<Component *> & GetComponents ()const{return ComponentSet;}
};//class SceneNode
SceneNode *Duplication(SceneNode *); ///<复制一个场景节点