迁移auto_merge_material_instance,BillboardTest,PlaneGrid3D,RayPicking四个测试范例到新的Component结构

This commit is contained in:
hyzboy 2025-06-15 02:03:38 +08:00
parent cfda1fceb2
commit a180970eb6
5 changed files with 15 additions and 19 deletions

View File

@ -13,6 +13,7 @@
#include<hgl/graph/VKVertexInputConfig.h> #include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/module/TextureManager.h> #include<hgl/graph/module/TextureManager.h>
#include<hgl/graph/FirstPersonCameraControl.h> #include<hgl/graph/FirstPersonCameraControl.h>
#include<hgl/component/StaticMeshComponent.h>
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
@ -112,19 +113,6 @@ private:
return(true); return(true);
} }
SceneNode *CreateSceneNode(Primitive *r,MaterialInstance *mi,Pipeline *p)
{
Mesh *ri=db->CreateMesh(r,mi,p);
if(!ri)
{
LOG_ERROR(OS_TEXT("Create Mesh failed."));
return(nullptr);
}
return(new SceneNode(ri));
}
bool CreateRenderObject() bool CreateRenderObject()
{ {
using namespace inline_geometry; using namespace inline_geometry;
@ -164,9 +152,8 @@ private:
{ {
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点 SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
scene_root->Add(CreateSceneNode(prim_plane_grid,mi_plane_grid,pipeline_plane_grid)); CreateComponent<StaticMeshComponent>(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
CreateComponent<StaticMeshComponent>(scene_root,ro_billboard);
scene_root->Add(new SceneNode(ro_billboard));
CameraControl *camera_control=GetCameraControl(); CameraControl *camera_control=GetCameraControl();

View File

@ -5,6 +5,7 @@
#include<hgl/filesystem/FileSystem.h> #include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h> #include<hgl/graph/mtl/Material2DCreateConfig.h>
#include<hgl/color/Color.h> #include<hgl/color/Color.h>
#include<hgl/component/StaticMeshComponent.h>
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
@ -93,7 +94,7 @@ private:
mat=rotate(deg2rad<double>(TRI_ROTATE_ANGLE*i),AxisVector::Z); mat=rotate(deg2rad<double>(TRI_ROTATE_ANGLE*i),AxisVector::Z);
scene_root->Add(new SceneNode(mat,render_obj[i].mesh)); CreateComponent<StaticMeshComponent>(mat,scene_root,render_obj[i].mesh);
} }
return(true); return(true);

View File

@ -10,6 +10,7 @@
#include<hgl/graph/VKVertexInputConfig.h> #include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/FirstPersonCameraControl.h> #include<hgl/graph/FirstPersonCameraControl.h>
#include<hgl/color/Color.h> #include<hgl/color/Color.h>
#include<hgl/component/StaticMeshComponent.h>
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
@ -83,7 +84,7 @@ private:
if(!ri) if(!ri)
return; return;
parent_node->Add(new SceneNode(mat,ri)); CreateComponent<StaticMeshComponent>(mat,parent_node,ri);
} }
bool InitScene() bool InitScene()

View File

@ -11,6 +11,7 @@
#include<hgl/graph/mtl/Material3DCreateConfig.h> #include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VertexDataManager.h> #include<hgl/graph/VertexDataManager.h>
#include<hgl/graph/VKVertexInputConfig.h> #include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/component/StaticMeshComponent.h>
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
@ -100,7 +101,7 @@ private:
return(nullptr); return(nullptr);
} }
parent_node->Add(new SceneNode(ri)); CreateComponent<StaticMeshComponent>(parent_node,ri);
return ri; return ri;
} }

View File

@ -156,6 +156,9 @@ namespace hgl
return(nullptr); return(nullptr);
} }
/**
* Component头文件
*/
parent_node->AttachComponent(c); //将组件附加到父节点 parent_node->AttachComponent(c); //将组件附加到父节点
return c; return c;
@ -178,6 +181,9 @@ namespace hgl
return(nullptr); return(nullptr);
} }
/**
* Component头文件
*/
parent_node->AttachComponent(c); //将组件附加到父节点 parent_node->AttachComponent(c); //将组件附加到父节点
c->graph::SceneOrient::SetLocalMatrix(mat); c->graph::SceneOrient::SetLocalMatrix(mat);