Gizmo资源管理中改为保存MeshComponentData/ComponentDataPtr
This commit is contained in:
parent
5ee42c2ae2
commit
19aee81063
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
|
#include<hgl/component/Component.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ enum class GizmoShape:uint
|
|||||||
bool InitGizmoResource(RenderFramework *);
|
bool InitGizmoResource(RenderFramework *);
|
||||||
void FreeGizmoResource();
|
void FreeGizmoResource();
|
||||||
|
|
||||||
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color);
|
ComponentDataPtr GetGizmoMeshComponentDataPtr(const GizmoShape &shape,const GizmoColor &color);
|
||||||
|
|
||||||
SceneNode *GetGizmoMoveNode();
|
SceneNode *GetGizmoMoveNode();
|
||||||
//SceneNode *GetGizmoScaleMesh();
|
//SceneNode *GetGizmoScaleMesh();
|
||||||
|
@ -32,24 +32,41 @@ VK_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/**
|
///**
|
||||||
* 移动 Gizmo 节点
|
//* 移动 Gizmo 节点
|
||||||
*/
|
//*/
|
||||||
class GizmoMoveNode:public SceneNode
|
//class GizmoMoveNode:public SceneNode
|
||||||
{
|
//{
|
||||||
MeshComponent *sphere=nullptr;
|
// struct GizmoMoveAxis
|
||||||
|
// {
|
||||||
|
// MeshComponent *cylinder =nullptr; //圆柱
|
||||||
|
// MeshComponent *cone =nullptr; //圆锥
|
||||||
|
// MeshComponent *square =nullptr; //双轴调节正方形
|
||||||
|
// };
|
||||||
|
|
||||||
struct GizmoMoveAxis
|
// MeshComponent *sphere=nullptr;
|
||||||
{
|
// GizmoMoveAxis axis[3]; //X,Y,Z 三个轴
|
||||||
MeshComponent *cylinder =nullptr; //圆柱
|
|
||||||
MeshComponent *cone =nullptr; //圆锥
|
|
||||||
MeshComponent *square =nullptr; //双轴调节正方形
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
//public:
|
||||||
|
|
||||||
|
// GizmoMoveNode(RenderFramework *rf)
|
||||||
|
// {
|
||||||
|
// //SetName("GizmoMoveNode");
|
||||||
|
|
||||||
|
// Mesh *sphere=GetGizmoMesh(GizmoShape::Sphere,GizmoColor::White);
|
||||||
|
|
||||||
|
// sn_gizmo_move->AttachComponent(rf->CreateComponent<MeshComponent>(sphere));
|
||||||
|
|
||||||
|
// for(int i=0;i<3;i++)
|
||||||
|
// {
|
||||||
|
// axis[i].cylinder=nullptr;
|
||||||
|
// axis[i].cone=nullptr;
|
||||||
|
// axis[i].square=nullptr;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
};//class GizmoMoveNode:public SceneNode
|
//};//class GizmoMoveNode:public SceneNode
|
||||||
|
|
||||||
static SceneNode *sn_gizmo_move=nullptr;
|
static SceneNode *sn_gizmo_move=nullptr;
|
||||||
}//namespace
|
}//namespace
|
||||||
@ -66,26 +83,27 @@ void ClearGizmoMoveNode()
|
|||||||
|
|
||||||
bool InitGizmoMoveNode(RenderFramework *render_framework)
|
bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||||
{
|
{
|
||||||
Mesh *sphere=GetGizmoMesh(GizmoShape::Sphere,GizmoColor::White);
|
ComponentDataPtr sphere=GetGizmoMeshComponentDataPtr(GizmoShape::Sphere,GizmoColor::White);
|
||||||
Mesh *cylinder[3]
|
|
||||||
|
ComponentDataPtr cylinder[3]
|
||||||
{
|
{
|
||||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Cylinder,GizmoColor::Red),
|
||||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Cylinder,GizmoColor::Green),
|
||||||
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||||
};
|
};
|
||||||
|
|
||||||
Mesh *cone[3]
|
ComponentDataPtr cone[3]
|
||||||
{
|
{
|
||||||
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Red),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Cone,GizmoColor::Red),
|
||||||
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Green),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Cone,GizmoColor::Green),
|
||||||
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Blue),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Cone,GizmoColor::Blue),
|
||||||
};
|
};
|
||||||
|
|
||||||
Mesh *square[3]=
|
ComponentDataPtr square[3]=
|
||||||
{
|
{
|
||||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Square,GizmoColor::Red),
|
||||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
|
GetGizmoMeshComponentDataPtr(GizmoShape::Square,GizmoColor::Green),
|
||||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
|
GetGizmoMeshComponentDataPtr(GizmoShape::Square,GizmoColor::Blue)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!sphere)
|
if(!sphere)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include<hgl/graph/InlineGeometry.h>
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
#include<hgl/graph/SceneNode.h>
|
#include<hgl/graph/SceneNode.h>
|
||||||
#include<hgl/graph/RenderFramework.h>
|
#include<hgl/graph/RenderFramework.h>
|
||||||
|
#include<hgl/component/MeshComponent.h>
|
||||||
#include"GizmoResource.h"
|
#include"GizmoResource.h"
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
@ -45,22 +46,52 @@ namespace
|
|||||||
{
|
{
|
||||||
Primitive *prim;
|
Primitive *prim;
|
||||||
|
|
||||||
Mesh *mesh[size_t(GizmoColor::RANGE_SIZE)];
|
struct
|
||||||
};
|
{
|
||||||
|
Mesh *mesh;
|
||||||
|
MeshComponentData *mcd;
|
||||||
|
ComponentDataPtr cdp;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void Create(Primitive *prim,MaterialInstance *mi,Pipeline *ppl)
|
||||||
|
{
|
||||||
|
mesh=CreateMesh(prim,mi,ppl);
|
||||||
|
mcd=new MeshComponentData(mesh);
|
||||||
|
cdp=mcd;
|
||||||
|
}
|
||||||
|
}mesh_data[size_t(GizmoColor::RANGE_SIZE)];
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void Create(Primitive *p)
|
||||||
|
{
|
||||||
|
prim=p;
|
||||||
|
|
||||||
|
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
||||||
|
mesh_data[i].Create(prim,gizmo_triangle.mi[i],gizmo_triangle.pipeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
SAFE_CLEAR(prim)
|
||||||
|
|
||||||
|
for(auto &md:mesh_data)
|
||||||
|
{
|
||||||
|
md.cdp.unref();
|
||||||
|
SAFE_CLEAR(md.mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};//class GizmoMesh
|
||||||
|
|
||||||
GizmoMesh gizmo_mesh[size_t(GizmoShape::RANGE_SIZE)]{};
|
GizmoMesh gizmo_mesh[size_t(GizmoShape::RANGE_SIZE)]{};
|
||||||
|
|
||||||
void InitGizmoMesh(const GizmoShape &gs,Primitive *prim,Pipeline *p)
|
void InitGizmoMesh(const GizmoShape &gs,Primitive *prim)
|
||||||
{
|
{
|
||||||
if(!prim)
|
if(!prim)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GizmoMesh *gr=gizmo_mesh+size_t(gs);
|
gizmo_mesh[size_t(gs)].Create(prim);
|
||||||
|
|
||||||
gr->prim=prim;
|
|
||||||
|
|
||||||
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
|
||||||
gr->mesh[i]=CreateMesh(prim,gizmo_triangle.mi[i],p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitMI(GizmoResource *gr)
|
bool InitMI(GizmoResource *gr)
|
||||||
@ -196,7 +227,7 @@ namespace
|
|||||||
using namespace inline_geometry;
|
using namespace inline_geometry;
|
||||||
|
|
||||||
{
|
{
|
||||||
InitGizmoMesh(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
|
InitGizmoMesh(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -207,7 +238,7 @@ namespace
|
|||||||
cci.field_count=16;
|
cci.field_count=16;
|
||||||
cci.has_center=false;
|
cci.has_center=false;
|
||||||
|
|
||||||
InitGizmoMesh(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
InitGizmoMesh(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -217,11 +248,11 @@ namespace
|
|||||||
cci.tangent=false;
|
cci.tangent=false;
|
||||||
cci.tex_coord=false;
|
cci.tex_coord=false;
|
||||||
|
|
||||||
InitGizmoMesh(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
InitGizmoMesh(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
InitGizmoMesh(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
|
InitGizmoMesh(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -232,7 +263,7 @@ namespace
|
|||||||
cci.numberSlices=16; //圆锥底部分割数
|
cci.numberSlices=16; //圆锥底部分割数
|
||||||
cci.numberStacks=3; //圆锥高度分割数
|
cci.numberStacks=3; //圆锥高度分割数
|
||||||
|
|
||||||
InitGizmoMesh(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
InitGizmoMesh(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -242,7 +273,7 @@ namespace
|
|||||||
cci.numberSlices=16; //圆柱底部分割数
|
cci.numberSlices=16; //圆柱底部分割数
|
||||||
cci.radius =1; //圆柱半径
|
cci.radius =1; //圆柱半径
|
||||||
|
|
||||||
InitGizmoMesh(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
InitGizmoMesh(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -253,7 +284,7 @@ namespace
|
|||||||
tci.numberSlices=64;
|
tci.numberSlices=64;
|
||||||
tci.numberStacks=8;
|
tci.numberStacks=8;
|
||||||
|
|
||||||
InitGizmoMesh(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
|
InitGizmoMesh(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci));
|
||||||
}
|
}
|
||||||
|
|
||||||
ENUM_CLASS_FOR(GizmoShape,int,i)
|
ENUM_CLASS_FOR(GizmoShape,int,i)
|
||||||
@ -298,10 +329,7 @@ void FreeGizmoResource()
|
|||||||
ClearGizmoMoveNode();
|
ClearGizmoMoveNode();
|
||||||
|
|
||||||
for(GizmoMesh &gr:gizmo_mesh)
|
for(GizmoMesh &gr:gizmo_mesh)
|
||||||
{
|
gr.Clear();
|
||||||
SAFE_CLEAR(gr.prim)
|
|
||||||
SAFE_CLEAR_OBJECT_ARRAY(gr.mesh)
|
|
||||||
}
|
|
||||||
|
|
||||||
SAFE_CLEAR(gizmo_triangle.prim_creater);
|
SAFE_CLEAR(gizmo_triangle.prim_creater);
|
||||||
SAFE_CLEAR(gizmo_triangle.vdm);
|
SAFE_CLEAR(gizmo_triangle.vdm);
|
||||||
@ -310,7 +338,7 @@ void FreeGizmoResource()
|
|||||||
SAFE_CLEAR(gizmo_line.vdm);
|
SAFE_CLEAR(gizmo_line.vdm);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color)
|
ComponentDataPtr GetGizmoMeshComponentDataPtr(const GizmoShape &shape,const GizmoColor &color)
|
||||||
{
|
{
|
||||||
if(!gizmo_rr)
|
if(!gizmo_rr)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
@ -318,7 +346,7 @@ Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color)
|
|||||||
RANGE_CHECK_RETURN_NULLPTR(shape)
|
RANGE_CHECK_RETURN_NULLPTR(shape)
|
||||||
RANGE_CHECK_RETURN_NULLPTR(color)
|
RANGE_CHECK_RETURN_NULLPTR(color)
|
||||||
|
|
||||||
return gizmo_mesh[size_t(shape)].mesh[size_t(color)];
|
return gizmo_mesh[size_t(shape)].mesh_data[size_t(color)].cdp;
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user