optimized SceneNode class.
This commit is contained in:
parent
9450d92784
commit
4614562929
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/math/Math.h>
|
#include<hgl/math/Math.h>
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
|
||||||
#include<hgl/graph/PrimitiveCreater.h>
|
#include<hgl/graph/PrimitiveCreater.h>
|
||||||
#include<hgl/graph/VKVertexInputConfig.h>
|
#include<hgl/graph/VKVertexInputConfig.h>
|
||||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||||
@ -94,7 +93,7 @@ private:
|
|||||||
rad=deg2rad<double>((360/TRIANGLE_NUMBER)*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
rad=deg2rad<double>((360/TRIANGLE_NUMBER)*i); //这里一定要加<float>或<float>,否则结果用int保存会出现问题
|
||||||
mat=rotate(rad,Vector3f(0,0,1));
|
mat=rotate(rad,Vector3f(0,0,1));
|
||||||
|
|
||||||
render_root.CreateSubNode(mat,render_obj);
|
render_root.Add(new SceneNode(mat,render_obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
render_root.RefreshMatrix();
|
render_root.RefreshMatrix();
|
||||||
@ -111,9 +110,9 @@ public:
|
|||||||
SAFE_CLEAR(render_list);
|
SAFE_CLEAR(render_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Init()
|
bool Init(uint w,uint h)
|
||||||
{
|
{
|
||||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
if(!VulkanApplicationFramework::Init(w,h))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
render_list=new RenderList(device);
|
render_list=new RenderList(device);
|
||||||
@ -139,12 +138,5 @@ public:
|
|||||||
|
|
||||||
int main(int,char **)
|
int main(int,char **)
|
||||||
{
|
{
|
||||||
TestApp app;
|
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||||
|
|
||||||
if(!app.Init())
|
|
||||||
return(-1);
|
|
||||||
|
|
||||||
while(app.Run());
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/math/Math.h>
|
|
||||||
#include<hgl/math/HalfFloat.h>
|
#include<hgl/math/HalfFloat.h>
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
|
||||||
#include<hgl/graph/SceneInfo.h>
|
|
||||||
#include<hgl/graph/VKVertexInputConfig.h>
|
#include<hgl/graph/VKVertexInputConfig.h>
|
||||||
#include<hgl/graph/PrimitiveCreater.h>
|
#include<hgl/graph/PrimitiveCreater.h>
|
||||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||||
@ -125,9 +122,9 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool Init()
|
bool Init(uint w,uint h)
|
||||||
{
|
{
|
||||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
if(!VulkanApplicationFramework::Init(w,h))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
InitVIL();
|
InitVIL();
|
||||||
@ -157,12 +154,5 @@ public:
|
|||||||
|
|
||||||
int main(int,char **)
|
int main(int,char **)
|
||||||
{
|
{
|
||||||
TestApp app;
|
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
|
||||||
|
|
||||||
if(!app.Init())
|
|
||||||
return(-1);
|
|
||||||
|
|
||||||
while(app.Run());
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形,使用UBO传递Viewport信息
|
||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/math/Math.h>
|
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
|
||||||
#include<hgl/graph/SceneInfo.h>
|
|
||||||
#include<hgl/graph/VKVertexInputConfig.h>
|
#include<hgl/graph/VKVertexInputConfig.h>
|
||||||
#include<hgl/graph/PrimitiveCreater.h>
|
#include<hgl/graph/PrimitiveCreater.h>
|
||||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||||
@ -132,5 +129,5 @@ public:
|
|||||||
|
|
||||||
int main(int,char **)
|
int main(int,char **)
|
||||||
{
|
{
|
||||||
RunApp<TestApp>(1280,720);
|
return RunApp<TestApp>(1280,720);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ bool InitGizmoRotateStaticMesh()
|
|||||||
|
|
||||||
white_torus->GetTransform().AddTransform(rotate_white_torus_tfc);
|
white_torus->GetTransform().AddTransform(rotate_white_torus_tfc);
|
||||||
|
|
||||||
root_node->AddSubNode(white_torus);
|
root_node->Add(white_torus);
|
||||||
}
|
}
|
||||||
|
|
||||||
sm_gizmo_rotate=CreateGizmoStaticMesh(root_node);
|
sm_gizmo_rotate=CreateGizmoStaticMesh(root_node);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include<hgl/graph/RenderNode.h>
|
#include<hgl/graph/RenderNode.h>
|
||||||
#include<hgl/graph/VKVABList.h>
|
#include<hgl/graph/VKVABList.h>
|
||||||
#include<hgl/type/SortedSets.h>
|
|
||||||
#include<hgl/graph/VKIndirectCommandBuffer.h>
|
#include<hgl/graph/VKIndirectCommandBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
@ -10,7 +10,7 @@ namespace hgl
|
|||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
using SceneNodeID =uint64;
|
using SceneNodeID =uint64;
|
||||||
using SceneNodeName =AnsiIDName;
|
using SceneNodeName =UTF16IDName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 场景节点数据类<br>
|
* 场景节点数据类<br>
|
||||||
@ -30,7 +30,7 @@ namespace hgl
|
|||||||
|
|
||||||
Renderable *render_obj=nullptr; ///<可渲染实例
|
Renderable *render_obj=nullptr; ///<可渲染实例
|
||||||
|
|
||||||
public:
|
protected:
|
||||||
|
|
||||||
ObjectList<SceneNode> SubNode; ///<子节点
|
ObjectList<SceneNode> SubNode; ///<子节点
|
||||||
|
|
||||||
@ -39,16 +39,18 @@ namespace hgl
|
|||||||
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
|
const SceneNodeID & GetNodeID ()const { return NodeID; } ///<取得节点ID
|
||||||
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
|
const SceneNodeName & GetNodeName ()const { return NodeName; } ///<取得节点名称
|
||||||
|
|
||||||
private:
|
const ObjectList<SceneNode> &GetSubNode()const { return SubNode; } ///<取得子节点列表
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
SceneNode()=default;
|
SceneNode()=default;
|
||||||
SceneNode(SceneNode *);
|
SceneNode(const SceneNode &)=delete;
|
||||||
|
SceneNode(const SceneNode *)=delete;
|
||||||
|
SceneNode(const SceneOrient &so ):SceneOrient(so) {}
|
||||||
SceneNode( Renderable *ri ) {render_obj=ri;}
|
SceneNode( Renderable *ri ) {render_obj=ri;}
|
||||||
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
||||||
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
||||||
|
|
||||||
friend SceneNode *CreateSceneNode(const SceneNodeName &);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~SceneNode()=default;
|
virtual ~SceneNode()=default;
|
||||||
@ -75,7 +77,7 @@ namespace hgl
|
|||||||
Renderable *GetRenderable(){return render_obj;}
|
Renderable *GetRenderable(){return render_obj;}
|
||||||
void SetRenderable(Renderable *);
|
void SetRenderable(Renderable *);
|
||||||
|
|
||||||
SceneNode *AddSubNode(SceneNode *sn)
|
SceneNode *Add(SceneNode *sn)
|
||||||
{
|
{
|
||||||
if(!sn)
|
if(!sn)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
@ -84,67 +86,6 @@ namespace hgl
|
|||||||
return sn;
|
return sn;
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneNode *CreateSubNode()
|
|
||||||
{
|
|
||||||
SceneNode *sn=new SceneNode();
|
|
||||||
|
|
||||||
SubNode.Add(sn);
|
|
||||||
return sn;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneNode *CreateSubNode(Renderable *ri)
|
|
||||||
{
|
|
||||||
if(!ri)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
SceneNode *sn=new SceneNode(ri);
|
|
||||||
|
|
||||||
SubNode.Add(sn);
|
|
||||||
return sn;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneNode *CreateSubNode(const Matrix4f &mat)
|
|
||||||
{
|
|
||||||
SceneNode *sn=new SceneNode(mat);
|
|
||||||
|
|
||||||
SubNode.Add(sn);
|
|
||||||
return sn;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneNode *CreateSubNode(const Matrix4f &mat,Renderable *ri)
|
|
||||||
{
|
|
||||||
if(!ri)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
SceneNode *sn=new SceneNode(mat,ri);
|
|
||||||
|
|
||||||
SubNode.Add(sn);
|
|
||||||
return sn;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneNode *CreateSubNode(SceneNode *node)
|
|
||||||
{
|
|
||||||
if(!node)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
SceneNode *sn=new SceneNode(node);
|
|
||||||
|
|
||||||
SubNode.Add(sn);
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneNode *CreateSubNode(const Matrix4f &mat,SceneNode *node)
|
|
||||||
{
|
|
||||||
if(!node)
|
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
SceneNode *sn=new SceneNode(mat);
|
|
||||||
sn->CreateSubNode(node);
|
|
||||||
|
|
||||||
SubNode.Add(sn);
|
|
||||||
return sn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public: //坐标相关方法
|
public: //坐标相关方法
|
||||||
|
|
||||||
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
|
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
|
||||||
@ -157,7 +98,7 @@ namespace hgl
|
|||||||
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||||
};//class SceneNode
|
};//class SceneNode
|
||||||
|
|
||||||
SceneNode *CreateSceneNode(const SceneNodeName &);
|
SceneNode *Duplication(const SceneNode *); ///<复制一个场景节点
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE
|
#endif//HGL_GRAPH_SCENE_NODE_INCLUDE
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/MaterialRenderList.h>
|
||||||
|
#include<hgl/graph/RenderList.h>
|
||||||
#include<hgl/graph/SceneNode.h>
|
#include<hgl/graph/SceneNode.h>
|
||||||
#include<hgl/graph/VKBuffer.h>
|
#include<hgl/graph/VK.h>
|
||||||
#include<hgl/graph/VKPrimitive.h>
|
|
||||||
#include<hgl/graph/VKCommandBuffer.h>
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
#include<hgl/graph/VKMaterial.h>
|
||||||
#include<hgl/graph/VKMaterialParameters.h>
|
|
||||||
#include<hgl/graph/VKRenderable.h>
|
#include<hgl/graph/VKRenderable.h>
|
||||||
#include<hgl/util/sort/Sort.h>
|
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -43,7 +41,7 @@ namespace hgl
|
|||||||
++renderable_count;
|
++renderable_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(SceneNode *sub:sn->SubNode)
|
for(SceneNode *sub:sn->GetSubNode())
|
||||||
ExpendNode(sub);
|
ExpendNode(sub);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
@ -4,22 +4,21 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
SceneNode::SceneNode(SceneNode *node):SceneOrient(*node)
|
SceneNode *Duplication(SceneNode *src_node)
|
||||||
{
|
{
|
||||||
if(!node)
|
if(!src_node)
|
||||||
return;
|
return nullptr;
|
||||||
|
|
||||||
BoundingBox=node->BoundingBox;
|
SceneNode *node=new SceneNode(*(SceneOrient *)src_node);
|
||||||
LocalBoundingBox=node->LocalBoundingBox;
|
|
||||||
|
|
||||||
render_obj=node->render_obj;
|
node->SetRenderable(src_node->GetRenderable());
|
||||||
|
|
||||||
for(SceneNode *sn:node->SubNode)
|
for(SceneNode *sn:src_node->GetSubNode())
|
||||||
{
|
{
|
||||||
SceneNode *new_sn=new SceneNode(sn);
|
node->Add(Duplication(sn));
|
||||||
|
|
||||||
SubNode.Add(new_sn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneNode::SetRenderable(Renderable *ri)
|
void SceneNode::SetRenderable(Renderable *ri)
|
||||||
@ -89,62 +88,5 @@ namespace hgl
|
|||||||
|
|
||||||
LocalBoundingBox=local;
|
LocalBoundingBox=local;
|
||||||
}
|
}
|
||||||
|
|
||||||
///**
|
|
||||||
//* 从当前节点展开输出到一个渲染列表
|
|
||||||
//* @param rl 渲染列表
|
|
||||||
//* @param func 过滤函数
|
|
||||||
//* @param func_data 过滤函数用辅助数据
|
|
||||||
//* @return 成功与否
|
|
||||||
//*/
|
|
||||||
//bool SceneNode::ExpendToList(RenderList *rl,FilterSceneNodeFunc func,void *func_data)
|
|
||||||
//{
|
|
||||||
// if(!rl)return(false);
|
|
||||||
|
|
||||||
// if(func)
|
|
||||||
// if(!func(this,func_data))
|
|
||||||
// return(false);
|
|
||||||
|
|
||||||
// {
|
|
||||||
// int count=renderable_instances.GetCount();
|
|
||||||
|
|
||||||
// if(count>0)
|
|
||||||
// rl->Add(this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// {
|
|
||||||
// int count=SubNode.GetCount();
|
|
||||||
// SceneNode **sub=SubNode.GetData();
|
|
||||||
|
|
||||||
// for(int i=0;i<count;i++)
|
|
||||||
// {
|
|
||||||
// (*sub)->ExpendToList(rl,func,func_data); //展开子节点
|
|
||||||
|
|
||||||
// ++sub;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return(true);
|
|
||||||
//}
|
|
||||||
|
|
||||||
///**
|
|
||||||
//* 从当前节点展开输出到一个渲染列表
|
|
||||||
//* @param rl 渲染列表
|
|
||||||
//* @param cam 摄像机
|
|
||||||
//* @param comp_func 渲染列表远近比较函数
|
|
||||||
//*/
|
|
||||||
//bool SceneNode::ExpendToList(RenderList *rl,Camera *cam,RenderListCompFunc comp_func)
|
|
||||||
//{
|
|
||||||
// if(!rl||!cam)return(false);
|
|
||||||
|
|
||||||
// if(!ExpendToList(rl))
|
|
||||||
// return(false);
|
|
||||||
|
|
||||||
// if(comp_func)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return(true);
|
|
||||||
//}
|
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user