Used Transform instead of Matrix4f in SceneOrient, MaterialRenderList/RenderAssignBuffer supports updating the L2WMatrix of only the changed objects
This commit is contained in:
@@ -23,6 +23,8 @@ class MaterialRenderList
|
||||
|
||||
RenderNodeList rn_list;
|
||||
|
||||
RenderNodePointerList rn_update_l2w_list;
|
||||
|
||||
private:
|
||||
|
||||
RenderAssignBuffer *assign_buffer;
|
||||
@@ -92,5 +94,7 @@ public:
|
||||
void End();
|
||||
|
||||
void Render(RenderCmdBuffer *);
|
||||
|
||||
void UpdateTransform(); //刷新所有对象的LocalToWorld矩阵
|
||||
};//class MaterialRenderList
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -31,5 +31,11 @@ public:
|
||||
for(auto *it:data_list)
|
||||
it->value->Render(rcb);
|
||||
}
|
||||
|
||||
void UpdateTransform()
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
it->value->UpdateTransform();
|
||||
}
|
||||
};//class MaterialRenderMap
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -39,6 +39,8 @@ namespace hgl
|
||||
|
||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||
|
||||
virtual void UpdateTransform(); ///<更新所有对象的变换数据
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
};//class RenderList
|
||||
}//namespace graph
|
||||
|
@@ -15,11 +15,15 @@ namespace hgl
|
||||
{
|
||||
SceneNode *scene_node;
|
||||
|
||||
uint32 l2w_transform_version;
|
||||
uint32 l2w_index;
|
||||
|
||||
Vector3f world_position;
|
||||
float to_camera_distance;
|
||||
};
|
||||
|
||||
using RenderNodeList=List<RenderNode>;
|
||||
using RenderNodePointerList=List<RenderNode *>;
|
||||
|
||||
using MaterialInstanceSets=SortedSets<MaterialInstance *>; ///<材质实例集合
|
||||
}//namespace graph
|
||||
|
@@ -33,8 +33,8 @@ namespace hgl
|
||||
SceneNode()=default;
|
||||
SceneNode(SceneNode *);
|
||||
SceneNode( Renderable *ri ) {render_obj=ri;}
|
||||
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
||||
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
||||
SceneNode(const Transform &tf ):SceneOrient(tf) {}
|
||||
SceneNode(const Transform &tf, Renderable *ri ):SceneOrient(tf) {render_obj=ri;}
|
||||
|
||||
virtual ~SceneNode()=default;
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace hgl
|
||||
|
||||
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
|
||||
|
||||
virtual void RefreshMatrix (const Matrix4f *mat=nullptr); ///<刷新世界变换矩阵
|
||||
virtual bool RefreshTransform (const Transform &tf=IdentityTransform) override; ///<刷新世界变换
|
||||
virtual void RefreshBoundingBox (); ///<刷新绑定盒
|
||||
|
||||
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
|
||||
|
@@ -4,7 +4,6 @@
|
||||
//#include<hgl/type/List.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
//#include<hgl/graph/Transform.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@@ -12,54 +11,48 @@ namespace hgl
|
||||
/**
|
||||
* 方向定位数据基类
|
||||
*/
|
||||
class SceneOrient ///场景定位类
|
||||
class SceneOrient ///场景定位类
|
||||
{
|
||||
protected:
|
||||
|
||||
//ObjectList<Transform> TransformList;
|
||||
Vector3f Position; ///<坐标
|
||||
Vector3f Direction; ///<方向
|
||||
|
||||
Vector3f Position; ///<坐标
|
||||
Vector3f Direction; ///<方向
|
||||
Transform LocalTransform; ///<当前变换(指相对上一级的变换)
|
||||
Transform WorldTransform; ///<当前到世界变换
|
||||
|
||||
bool IdentityLocalMatrix; ///<是否为空矩阵
|
||||
protected:
|
||||
|
||||
Matrix4f LocalMatrix; ///<当前矩阵(指相对上一级的变换矩阵)
|
||||
Matrix4f LocalToWorldMatrix; ///<当前到世界矩阵
|
||||
|
||||
Matrix4f InverseLocalMatrix; ///<反向当前矩阵
|
||||
Matrix4f InverseLocalToWorldMatrix; ///<反向当前到世界矩阵
|
||||
void SetWorldTransform (const Transform &); ///<设定当前节点到世界矩阵
|
||||
|
||||
public:
|
||||
|
||||
SceneOrient();
|
||||
SceneOrient(const SceneOrient &);
|
||||
SceneOrient(const Matrix4f &mat);
|
||||
SceneOrient(const Transform &);
|
||||
virtual ~SceneOrient()=default;
|
||||
|
||||
void SetPosition (const Vector3f &pos){Position=pos;}
|
||||
void SetDirection (const Vector3f &dir){Direction=dir;}
|
||||
|
||||
const Vector3f & GetLocalPosition ()const{return Position;}
|
||||
const Vector3f & GetLocalDirection ()const{return Direction;}
|
||||
const Vector3f & GetWorldPosition ()const{return TransformPosition(LocalToWorldMatrix,Position);}
|
||||
const Vector3f & GetWorldDirection ()const{return TransformDirection(LocalToWorldMatrix,Direction);}
|
||||
const Vector3f & GetLocalPosition ()const {return Position;}
|
||||
const Vector3f & GetLocalDirection ()const {return Direction;}
|
||||
const Vector3f GetWorldPosition () {return WorldTransform.TransformPosition(Position);}
|
||||
const Vector3f GetWorldDirection () {return WorldTransform.TransformDirection(Direction);}
|
||||
|
||||
public:
|
||||
|
||||
const bool IsIdentityLocalMatrix ()const{return IdentityLocalMatrix;} ///<是否为空矩阵(相对上一级没变化)
|
||||
void SetLocalTransform (const Transform &); ///<设定当前节点矩阵
|
||||
|
||||
Matrix4f & SetLocalMatrix (const Matrix4f &); ///<设定当前节点矩阵
|
||||
Matrix4f & SetLocalToWorldMatrix (const Matrix4f &); ///<设定当前节点到世界矩阵
|
||||
|
||||
const Matrix4f & GetLocalMatrix ()const {return LocalMatrix;}
|
||||
const Matrix4f & GetLocalToWorldMatrix ()const {return LocalToWorldMatrix;}
|
||||
|
||||
const Matrix4f & GetInverseLocalMatrix ()const {return InverseLocalMatrix;}
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix()const {return InverseLocalToWorldMatrix;}
|
||||
const Transform & GetLocalTransform ()const {return LocalTransform;} ///<取得当前节点矩阵
|
||||
const Transform & GetWorldTransform ()const {return WorldTransform;} ///<取得当前节点到世界矩阵
|
||||
|
||||
Transform & GetLocalTransform () {LocalTransform.UpdateMatrix();return LocalTransform;} ///<取得当前节点矩阵
|
||||
Transform & GetWorldTransform () {WorldTransform.UpdateMatrix();return WorldTransform;} ///<取得当前节点到世界矩阵
|
||||
|
||||
public:
|
||||
|
||||
virtual void RefreshLocalToWorldMatrix (const Matrix4f *); ///<刷新到世界空间矩阵
|
||||
virtual bool RefreshTransform (const Transform &); ///<刷新到世界空间变换
|
||||
};//class SceneOrient
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
Reference in New Issue
Block a user