Updated to support Newly SceneOrient,compiled all OK! but Non test..next step is test samples.
This commit is contained in:
parent
410b94a127
commit
a9526ce956
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 529ad6b4037865b871f3406fa528ef1ec80d56a8
|
||||
Subproject commit 45e02b7c7206ac459692d693c1b840f8378906d3
|
@ -150,7 +150,7 @@ public:
|
||||
//}
|
||||
|
||||
root.RefreshTransform();
|
||||
render_list->UpdateTransform();
|
||||
render_list->UpdateLocalToWorld();
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
|
@ -95,6 +95,6 @@ public:
|
||||
|
||||
void Render(RenderCmdBuffer *);
|
||||
|
||||
void UpdateTransform(); //刷新所有对象的LocalToWorld矩阵
|
||||
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
|
||||
};//class MaterialRenderList
|
||||
VK_NAMESPACE_END
|
||||
|
@ -32,10 +32,10 @@ public:
|
||||
it->value->Render(rcb);
|
||||
}
|
||||
|
||||
void UpdateTransform()
|
||||
void UpdateLocalToWorld()
|
||||
{
|
||||
for(auto *it:data_list)
|
||||
it->value->UpdateTransform();
|
||||
it->value->UpdateLocalToWorld();
|
||||
}
|
||||
};//class MaterialRenderMap
|
||||
VK_NAMESPACE_END
|
||||
|
@ -39,7 +39,7 @@ namespace hgl
|
||||
|
||||
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
|
||||
|
||||
virtual void UpdateTransform(); ///<更新所有对象的变换数据
|
||||
virtual void UpdateLocalToWorld(); ///<更新所有对象的变换数据
|
||||
|
||||
virtual void Clear(); ///<彻底清理
|
||||
};//class RenderList
|
||||
|
@ -15,7 +15,7 @@ namespace hgl
|
||||
{
|
||||
SceneNode *scene_node;
|
||||
|
||||
uint32 l2w_transform_version;
|
||||
uint32 l2w_version;
|
||||
uint32 l2w_index;
|
||||
|
||||
Vector3f world_position;
|
||||
|
@ -32,8 +32,8 @@ namespace hgl
|
||||
SceneNode()=default;
|
||||
SceneNode(SceneNode *);
|
||||
SceneNode( Renderable *ri ) {render_obj=ri;}
|
||||
SceneNode(const Transform &tf ):SceneOrient(tf) {}
|
||||
SceneNode(const Transform &tf, Renderable *ri ):SceneOrient(tf) {render_obj=ri;}
|
||||
SceneNode(const Matrix4f &mat ):SceneOrient(mat) {}
|
||||
SceneNode(const Matrix4f &mat, Renderable *ri ):SceneOrient(mat) {render_obj=ri;}
|
||||
|
||||
virtual ~SceneNode()=default;
|
||||
|
||||
@ -128,7 +128,7 @@ namespace hgl
|
||||
|
||||
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒
|
||||
|
||||
virtual bool RefreshTransform (const Transform &tf=IdentityTransform) override; ///<刷新世界变换
|
||||
virtual void RefreshMatrix () override; ///<刷新世界变换
|
||||
virtual void RefreshBoundingBox (); ///<刷新绑定盒
|
||||
|
||||
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
|
||||
|
@ -7,53 +7,135 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class SceneMatrix :public VersionData<Matrix4f>
|
||||
{
|
||||
protected:
|
||||
|
||||
Matrix4f parent_matrix;
|
||||
Matrix4f local_matrix;
|
||||
TransformManager transform_manager;
|
||||
Matrix4f transform_matrix;
|
||||
|
||||
protected:
|
||||
|
||||
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
|
||||
Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵
|
||||
|
||||
void MakeNewestData(Matrix4f &local_to_world_matrix) override ///<生成最新的数据(需要派生类重载)
|
||||
{
|
||||
transform_manager.GetMatrix(transform_matrix);
|
||||
|
||||
local_to_world_matrix=parent_matrix*local_matrix*transform_matrix;
|
||||
|
||||
inverse_local_to_world_matrix =inverse(local_to_world_matrix);
|
||||
inverse_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
const Matrix4f &GetLocalMatrix()const{return local_matrix;} ///<取得本地矩阵
|
||||
|
||||
const Matrix4f &GetLocalToWorldMatrix(){return GetNewestVersionData();} ///<取得本地到世界矩阵
|
||||
const Matrix4f &GetInverseLocalToWorldMatrix(){UpdateNewestData();return inverse_local_to_world_matrix;} ///<取得世界到本地矩阵
|
||||
const Matrix4f &GetInverseTransposeLocalToWorldMatrix() ///<取得世界到本地矩阵的转置矩阵
|
||||
{
|
||||
UpdateNewestData();
|
||||
return inverse_transpose_local_to_world_matrix;
|
||||
}
|
||||
|
||||
TransformManager &GetTransform() { return transform_manager; } ///<取得变换管理器
|
||||
|
||||
public:
|
||||
|
||||
SceneMatrix():VersionData(Identity4f)
|
||||
{
|
||||
parent_matrix=Identity4f;
|
||||
local_matrix=Identity4f;
|
||||
transform_matrix=Identity4f;
|
||||
}
|
||||
|
||||
SceneMatrix(SceneMatrix &so):VersionData(so.GetLocalToWorldMatrix())
|
||||
{
|
||||
parent_matrix=so.parent_matrix;
|
||||
local_matrix=so.local_matrix;
|
||||
transform_manager=so.transform_manager;
|
||||
transform_matrix=so.transform_matrix;
|
||||
|
||||
inverse_local_to_world_matrix=so.inverse_local_to_world_matrix;
|
||||
inverse_transpose_local_to_world_matrix=so.inverse_transpose_local_to_world_matrix;
|
||||
}
|
||||
|
||||
SceneMatrix(const Matrix4f &mat):VersionData(Identity4f)
|
||||
{
|
||||
SetLocalMatrix(mat);
|
||||
}
|
||||
|
||||
void SetLocalMatrix(const Matrix4f &mat)
|
||||
{
|
||||
if (IsNearlyEqual(local_matrix,mat))
|
||||
return;
|
||||
|
||||
local_matrix=mat;
|
||||
UpdateVersion();
|
||||
}
|
||||
|
||||
void SetParentMatrix(const Matrix4f &pm)
|
||||
{
|
||||
if (IsNearlyEqual(parent_matrix,pm))
|
||||
return;
|
||||
|
||||
parent_matrix=pm;
|
||||
UpdateVersion();
|
||||
}
|
||||
};//class SceneMatrix
|
||||
|
||||
/**
|
||||
* 方向定位数据基类
|
||||
* 方向定位数据基类<br>
|
||||
* 用于描述一个物体在3D空间中的位置、旋转、缩放等信息。<br>
|
||||
* 构成说明:<br>
|
||||
* <ul> *
|
||||
* <li>LocalMatrix 一般用于描述当前节点相对上一级的变换矩阵</li>
|
||||
* <li>LocalToWorldMatrix 最终用于描述当前节点相对于世界的变换矩阵,在渲染时使用</li>
|
||||
*
|
||||
* <li>transform_manager 用于管理当前节点所有的变换情况,如果本节点不存在额外变换,数量为0。</li>
|
||||
* </ul>
|
||||
*
|
||||
* LocalToWorldMatrix=ParnetMatrix * LocalMatrix * TraansformMatrix<br>
|
||||
*/
|
||||
class SceneOrient ///场景定位类
|
||||
{
|
||||
protected:
|
||||
|
||||
Matrix4f parent_matrix;
|
||||
bool parent_matrix_dirty;
|
||||
SceneMatrix scene_matrix;
|
||||
|
||||
Matrix4f local_matrix;
|
||||
bool local_matrix_dirty;
|
||||
|
||||
TransformManager transform_manager;
|
||||
uint32 transform_version;
|
||||
|
||||
uint32 local_to_world_matrix_version;
|
||||
|
||||
// LocalToWorld = ParentMatrix * LocalMatrix * TransformMatrix
|
||||
|
||||
Matrix4f local_to_world_matrix; ///<本地到世界矩阵
|
||||
Matrix4f inverse_local_to_world_matrix; ///<世界到本地矩阵
|
||||
Matrix4f inverse_transpose_local_to_world_matrix; ///<世界到本地矩阵的转置矩阵
|
||||
|
||||
virtual void SetWorldMatrix(const Matrix4f &);
|
||||
Vector3f WorldPosition;
|
||||
|
||||
public:
|
||||
|
||||
SceneOrient();
|
||||
SceneOrient()=default;
|
||||
SceneOrient(const SceneOrient &);
|
||||
SceneOrient(const Matrix4f &);
|
||||
virtual ~SceneOrient()=default;
|
||||
|
||||
void SetLocalMatrix(const Matrix4f &); ///<设置本地矩阵
|
||||
|
||||
public:
|
||||
const Matrix4f & GetLocalMatrix ()const{return local_matrix;}
|
||||
|
||||
TransformManager & GetTransform () {return transform_manager;} ///<取得变换管理器
|
||||
|
||||
const Matrix4f & GetLocalToWorldMatrix ()const{return local_to_world_matrix;}
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix ()const{return inverse_local_to_world_matrix;}
|
||||
const Matrix4f & GetInverseTransposeLocalToWorldMatrix ()const{return inverse_transpose_local_to_world_matrix;}
|
||||
void SetLocalMatrix (const Matrix4f &mat){scene_matrix.SetLocalMatrix(mat);} ///<设置本地矩阵
|
||||
void SetParentMatrix (const Matrix4f &mat){scene_matrix.SetParentMatrix(mat);} ///<设置上级到世界空间变换矩阵
|
||||
|
||||
public:
|
||||
|
||||
virtual bool RefreshMatrix (const Matrix4f &); ///<刷新到世界空间变换
|
||||
const uint32 GetLocalToWorldMatrixVersion()const { return scene_matrix.GetNewestVersion(); } ///<取得版本号
|
||||
|
||||
const Vector3f & GetWorldPosition() const { return WorldPosition; } ///<取得世界坐标
|
||||
const Matrix4f & GetLocalMatrix ()const {return scene_matrix.GetLocalMatrix();} ///<取得本地矩阵
|
||||
|
||||
TransformManager & GetTransform () {return scene_matrix.GetTransform();} ///<取得变换管理器
|
||||
|
||||
const Matrix4f & GetLocalToWorldMatrix () {return scene_matrix.GetLocalToWorldMatrix();} ///<取得本地到世界矩阵
|
||||
const Matrix4f & GetInverseLocalToWorldMatrix () {return scene_matrix.GetInverseLocalToWorldMatrix();}
|
||||
const Matrix4f & GetInverseTransposeLocalToWorldMatrix () {return scene_matrix.GetInverseTransposeLocalToWorldMatrix();}
|
||||
|
||||
public:
|
||||
|
||||
virtual void RefreshMatrix();
|
||||
};//class SceneOrient
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -113,7 +113,7 @@ void MaterialRenderList::Add(SceneNode *sn)
|
||||
|
||||
rn.scene_node =sn;
|
||||
|
||||
rn.l2w_transform_version=sn->GetWorldTransform().GetVersion();
|
||||
rn.l2w_version=sn->GetLocalToWorldMatrixVersion();
|
||||
rn.l2w_index=0;
|
||||
|
||||
rn.world_position =sn->GetWorldPosition();
|
||||
@ -141,7 +141,7 @@ void MaterialRenderList::End()
|
||||
assign_buffer->WriteNode(rn_list);
|
||||
}
|
||||
|
||||
void MaterialRenderList::UpdateTransform()
|
||||
void MaterialRenderList::UpdateLocalToWorld()
|
||||
{
|
||||
if(!assign_buffer)
|
||||
return;
|
||||
@ -154,13 +154,14 @@ void MaterialRenderList::UpdateTransform()
|
||||
|
||||
int first=-1,last=-1;
|
||||
int update_count=0;
|
||||
uint32 l2w_version=0;
|
||||
RenderNode *rn=rn_list.GetData();
|
||||
|
||||
for(int i=0;i<node_count;i++)
|
||||
{
|
||||
Transform &tf=rn->scene_node->GetWorldTransform();
|
||||
l2w_version=rn->scene_node->GetLocalToWorldMatrixVersion();
|
||||
|
||||
if(rn->l2w_transform_version!=tf.GetVersion()) //版本不对,需要更新
|
||||
if(rn->l2w_version!=l2w_version) //版本不对,需要更新
|
||||
{
|
||||
if(first==-1)
|
||||
{
|
||||
@ -169,7 +170,7 @@ void MaterialRenderList::UpdateTransform()
|
||||
|
||||
last=rn->l2w_index;
|
||||
|
||||
rn->l2w_transform_version=tf.GetVersion();
|
||||
rn->l2w_version=l2w_version;
|
||||
|
||||
rn_update_l2w_list.Add(rn);
|
||||
|
||||
@ -181,7 +182,7 @@ void MaterialRenderList::UpdateTransform()
|
||||
|
||||
if(update_count>0)
|
||||
{
|
||||
assign_buffer->UpdateTransform(rn_update_l2w_list,first,last);
|
||||
assign_buffer->UpdateLocalToWorld(rn_update_l2w_list,first,last);
|
||||
rn_update_l2w_list.Clear();
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ void RenderAssignBuffer::StatL2W(const RenderNodeList &rn_list)
|
||||
|
||||
for(uint i=0;i<rn_list.GetCount();i++)
|
||||
{
|
||||
*l2wp=rn->scene_node->GetWorldTransform().GetMatrix();
|
||||
*l2wp=rn->scene_node->GetLocalToWorldMatrix();
|
||||
++l2wp;
|
||||
++rn;
|
||||
}
|
||||
@ -81,7 +81,7 @@ void RenderAssignBuffer::StatL2W(const RenderNodeList &rn_list)
|
||||
l2w_buffer->Unmap();
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::UpdateTransform(const RenderNodePointerList &rnp_list,const int first,const int last)
|
||||
void RenderAssignBuffer::UpdateLocalToWorld(const RenderNodePointerList &rnp_list,const int first,const int last)
|
||||
{
|
||||
if(!l2w_buffer)
|
||||
return;
|
||||
@ -97,7 +97,7 @@ void RenderAssignBuffer::UpdateTransform(const RenderNodePointerList &rnp_list,c
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
l2wp[(*rn)->l2w_index-first]=(*rn)->scene_node->GetWorldTransform().GetMatrix();
|
||||
l2wp[(*rn)->l2w_index-first]=(*rn)->scene_node->GetLocalToWorldMatrix();
|
||||
|
||||
++rn;
|
||||
}
|
||||
|
@ -92,6 +92,6 @@ public:
|
||||
|
||||
void WriteNode(const RenderNodeList &);
|
||||
|
||||
void UpdateTransform(const RenderNodePointerList &,const int first,const int last);
|
||||
void UpdateLocalToWorld(const RenderNodePointerList &,const int first,const int last);
|
||||
};//struct RenderAssignBuffer
|
||||
VK_NAMESPACE_END
|
||||
|
@ -78,12 +78,12 @@ namespace hgl
|
||||
mrl_map.Clear();
|
||||
}
|
||||
|
||||
void RenderList::UpdateTransform()
|
||||
void RenderList::UpdateLocalToWorld()
|
||||
{
|
||||
if(renderable_count<=0)
|
||||
return;
|
||||
|
||||
mrl_map.UpdateTransform();
|
||||
mrl_map.UpdateLocalToWorld();
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -40,18 +40,14 @@ namespace hgl
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新变换
|
||||
* @param parent_transform 上级节点变换
|
||||
* 刷新矩阵变换
|
||||
*/
|
||||
bool SceneNode::RefreshTransform(const Transform &parent_transform)
|
||||
void SceneNode::RefreshMatrix()
|
||||
{
|
||||
if(!parent_transform.IsLastVersion())
|
||||
return(false);
|
||||
if (scene_matrix.IsNewestVersion())
|
||||
return;
|
||||
|
||||
if(!parent_transform.IsIdentity())
|
||||
SceneOrient::RefreshTransform(parent_transform);
|
||||
else
|
||||
SetWorldTransform(LocalTransform);
|
||||
const Matrix2f &l2w=scene_matrix.GetLocalToWorldMatrix();
|
||||
|
||||
const int count=SubNode.GetCount();
|
||||
|
||||
@ -59,13 +55,11 @@ namespace hgl
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
if(!(*sub)->RefreshTransform(WorldTransform))
|
||||
return(false);
|
||||
(*sub)->SetParentMatrix(l2w);
|
||||
(*sub)->RefreshMatrix();
|
||||
|
||||
sub++;
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,92 +3,30 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
SceneOrient::SceneOrient()
|
||||
{
|
||||
parent_matrix=Identity4f;
|
||||
local_matrix=Identity4f;
|
||||
|
||||
SetWorldMatrix(Identity4f);
|
||||
|
||||
parent_matrix_dirty=false;
|
||||
local_matrix_dirty=false;
|
||||
transform_version=transform_manager.GetCurrentVersion();
|
||||
}
|
||||
|
||||
SceneOrient::SceneOrient(const SceneOrient &so)
|
||||
{
|
||||
#define SO_COPY(value) value=so.value;
|
||||
|
||||
SO_COPY(parent_matrix)
|
||||
SO_COPY(parent_matrix_dirty)
|
||||
|
||||
SO_COPY(local_matrix)
|
||||
SO_COPY(local_matrix_dirty)
|
||||
|
||||
SO_COPY(transform_manager)
|
||||
SO_COPY(transform_version)
|
||||
|
||||
SO_COPY(local_to_world_matrix)
|
||||
SO_COPY(inverse_local_to_world_matrix)
|
||||
SO_COPY(inverse_transpose_local_to_world_matrix)
|
||||
|
||||
#undef SO_COPY
|
||||
scene_matrix=so.scene_matrix;
|
||||
WorldPosition=so.WorldPosition;
|
||||
}
|
||||
|
||||
SceneOrient::SceneOrient(const Matrix4f &mat):SceneOrient()
|
||||
{
|
||||
SetLocalMatrix(mat);
|
||||
scene_matrix.SetLocalMatrix(mat);
|
||||
|
||||
WorldPosition=TransformPosition(mat,ZeroVector3f);
|
||||
}
|
||||
|
||||
void SceneOrient::SetLocalMatrix(const Matrix4f &mat)
|
||||
void SceneOrient::RefreshMatrix()
|
||||
{
|
||||
if(IsNearlyEqual(local_matrix,mat))
|
||||
if (scene_matrix.IsNewestVersion())
|
||||
{
|
||||
//是最新版本,证明没有更新,那不用刷新了
|
||||
return;
|
||||
|
||||
local_matrix=mat;
|
||||
}
|
||||
|
||||
void SceneOrient::SetWorldMatrix(const Matrix4f &wm)
|
||||
{
|
||||
local_to_world_matrix =wm;
|
||||
inverse_local_to_world_matrix =inverse(local_to_world_matrix);
|
||||
inverse_transpose_local_to_world_matrix=transpose(inverse_local_to_world_matrix);
|
||||
}
|
||||
const Matrix4f &l2w=scene_matrix.GetNewestVersionData();
|
||||
|
||||
/**
|
||||
* 刷新世界变换矩阵
|
||||
* @param parent_matrix 上一级LocalToWorld变换矩阵
|
||||
*/
|
||||
bool SceneOrient::RefreshMatrix(const Matrix4f &pm)
|
||||
{
|
||||
if(hgl_cmp(pm,parent_matrix)==0) //如果上一级到这一级没变,自然是可以用memcmp比较的
|
||||
return(true);
|
||||
|
||||
parent_matrix=pm;
|
||||
|
||||
Matrix4f tm;
|
||||
|
||||
transform_manager.GetMatrix(tm);
|
||||
|
||||
SetWorldMatrix(parent_matrix*local_matrix*tm);
|
||||
|
||||
//if(IsIdentityMatrix(LocalMatrix))
|
||||
//{
|
||||
// SetWorldMatrix(parent_matrix);
|
||||
// return(true);
|
||||
//}
|
||||
//
|
||||
|
||||
//if(IsIdentityMatrix(parent_matrix))
|
||||
//{
|
||||
// SetWorldMatrix(LocalMatrix);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// SetWorldMatrix(parent_matrix*LocalMatrix);
|
||||
//}
|
||||
|
||||
return(true);
|
||||
WorldPosition=TransformPosition(l2w,ZeroVector3f);
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
Loading…
x
Reference in New Issue
Block a user