[WIP] StaticMesh and GizmoMove
This commit is contained in:
@@ -22,17 +22,74 @@
|
||||
*/
|
||||
|
||||
#include"GizmoResource.h"
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct StaticMesh
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
static StaticMesh *sm_gizmo_move=nullptr;
|
||||
|
||||
bool InitGizmoMoveStaticMesh()
|
||||
{
|
||||
Renderable *sphere=GetGizmoRenderable(GizmoShape::Sphere,GizmoColor::White);
|
||||
Renderable *cylinder[3]
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Renderable *cone[3]
|
||||
{
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Red),
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Green),
|
||||
GetGizmoRenderable(GizmoShape::Cone,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
if(!sphere)
|
||||
return(false);
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
if(!cylinder[i])
|
||||
return(false);
|
||||
|
||||
if(!cone[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
{
|
||||
SceneNode *root_node=new SceneNode(scale(1),sphere);
|
||||
|
||||
root_node->CreateSubNode(scale(9,1,1),cylinder[0]);
|
||||
|
||||
{
|
||||
TransformMatrix4f tm;
|
||||
|
||||
tm.SetTranslation(Vector3f(0,0,4.5f));
|
||||
root_node->CreateSubNode(tm.GetMatrix(),cylinder[2]); //Z 向上
|
||||
|
||||
tm.SetRotation(Vector3f(0,0,1),90);
|
||||
tm.SetTranslation(Vector3f(4.5f,0,0));
|
||||
|
||||
root_node->CreateSubNode(tm.GetMatrix(),cylinder[0]); //X 向右
|
||||
|
||||
tm.SetRotation(Vector3f(1,0,0),90);
|
||||
tm.SetTranslation(Vector3f(0,4.5f,0));
|
||||
|
||||
root_node->CreateSubNode(tm.GetMatrix(),cylinder[1]); //Y 向前
|
||||
}
|
||||
|
||||
sm_gizmo_move=CreateGizmoStaticMesh(root_node);
|
||||
}
|
||||
|
||||
if(!sm_gizmo_move)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
}//namespace
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -14,6 +14,43 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
namespace
|
||||
{
|
||||
static RenderResource * gizmo_rr=nullptr;
|
||||
|
||||
struct GizmoResource
|
||||
{
|
||||
Material * mtl;
|
||||
MaterialInstance * mi[size_t(GizmoColor::RANGE_SIZE)];
|
||||
Pipeline * pipeline;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
PrimitiveCreater * prim_creater;
|
||||
};
|
||||
|
||||
static GizmoResource gizmo_line{};
|
||||
static GizmoResource gizmo_triangle{};
|
||||
|
||||
struct GizmoRenderable
|
||||
{
|
||||
Primitive *prim;
|
||||
|
||||
Renderable *renderable[size_t(GizmoColor::RANGE_SIZE)];
|
||||
};
|
||||
|
||||
GizmoRenderable gizmo_rederable[size_t(GizmoShape::RANGE_SIZE)]{};
|
||||
|
||||
void InitGizmoRenderable(const GizmoShape &gs,Primitive *prim,Pipeline *p)
|
||||
{
|
||||
if(!prim)
|
||||
return;
|
||||
|
||||
GizmoRenderable *gr=gizmo_rederable+size_t(gs);
|
||||
|
||||
gr->prim=prim;
|
||||
|
||||
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
||||
gr->renderable[i]=CreateRenderable(prim,gizmo_triangle.mi[i],p);
|
||||
}
|
||||
|
||||
bool InitMI(GizmoResource *gr)
|
||||
{
|
||||
if(!gr||!gr->mtl)
|
||||
@@ -122,9 +159,9 @@ namespace
|
||||
if(!gizmo_triangle.vdm)
|
||||
return(false);
|
||||
|
||||
if(!gizmo_triangle.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
||||
HGL_SIZE_1MB, //最大索引数量
|
||||
IndexType::U16)) //索引类型
|
||||
if(!gizmo_triangle.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
||||
HGL_SIZE_1MB, //最大索引数量
|
||||
IndexType::U16)) //索引类型
|
||||
return(false);
|
||||
}
|
||||
|
||||
@@ -139,7 +176,7 @@ namespace
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
gizmo_prim[size_t(GizmoShape::Plane)]=CreatePlane(gizmo_triangle.prim_creater);
|
||||
InitGizmoRenderable(GizmoShape::Plane,CreatePlane(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -149,11 +186,11 @@ namespace
|
||||
cci.tangent=false;
|
||||
cci.tex_coord=false;
|
||||
|
||||
gizmo_prim[size_t(GizmoShape::Cube)]=CreateCube(gizmo_triangle.prim_creater,&cci);
|
||||
InitGizmoRenderable(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
gizmo_prim[size_t(GizmoShape::Sphere)]=CreateSphere(gizmo_triangle.prim_creater,8);
|
||||
InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,8),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -164,7 +201,7 @@ namespace
|
||||
cci.numberSlices=8; //圆锥底部分割数
|
||||
cci.numberStacks=1; //圆锥高度分割数
|
||||
|
||||
gizmo_prim[size_t(GizmoShape::Cone)]=CreateCone(gizmo_triangle.prim_creater,&cci);
|
||||
InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -174,12 +211,12 @@ namespace
|
||||
cci.numberSlices=8; //圆柱底部分割数
|
||||
cci.radius =1; //圆柱半径
|
||||
|
||||
gizmo_prim[size_t(GizmoShape::Cylinder)]=CreateCylinder(gizmo_triangle.prim_creater,&cci);
|
||||
InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||
}
|
||||
|
||||
ENUM_CLASS_FOR(GizmoShape,int,i)
|
||||
{
|
||||
if(!gizmo_prim[i])
|
||||
if(!gizmo_rederable[i].prim)
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
@@ -206,7 +243,12 @@ bool InitGizmoResource(GPUDevice *device)
|
||||
|
||||
void FreeGizmoResource()
|
||||
{
|
||||
SAFE_CLEAR_OBJECT_ARRAY(gizmo_prim)
|
||||
for(GizmoRenderable &gr:gizmo_rederable)
|
||||
{
|
||||
SAFE_CLEAR(gr.prim)
|
||||
SAFE_CLEAR_OBJECT_ARRAY(gr.renderable)
|
||||
}
|
||||
|
||||
SAFE_CLEAR(gizmo_triangle.prim_creater);
|
||||
SAFE_CLEAR(gizmo_triangle.vdm);
|
||||
// SAFE_CLEAR(gizmo_pipeline_triangles);
|
||||
@@ -215,4 +257,26 @@ void FreeGizmoResource()
|
||||
SAFE_CLEAR(gizmo_rr);
|
||||
}
|
||||
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color)
|
||||
{
|
||||
if(!gizmo_rr)
|
||||
return(nullptr);
|
||||
|
||||
RANGE_CHECK_RETURN_NULLPTR(shape)
|
||||
RANGE_CHECK_RETURN_NULLPTR(color)
|
||||
|
||||
return gizmo_rederable[size_t(shape)].renderable[size_t(color)];
|
||||
}
|
||||
|
||||
StaticMesh *CreateGizmoStaticMesh(SceneNode *root_node)
|
||||
{
|
||||
if(!root_node)
|
||||
return(nullptr);
|
||||
|
||||
if(root_node->IsEmpty())
|
||||
return(nullptr);
|
||||
|
||||
return CreateRRObject<StaticMesh>(gizmo_rr,root_node);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -1,7 +1,13 @@
|
||||
#pragma once
|
||||
#include"Gizmo.h"
|
||||
#include<hgl/color/Color.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class SceneNode;
|
||||
class PrimitiveCreater;
|
||||
class StaticMesh;
|
||||
|
||||
constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]=
|
||||
{
|
||||
COLOR::MozillaCharcoal,
|
||||
@@ -14,20 +20,8 @@ constexpr const COLOR gizmo_color[size_t(GizmoColor::RANGE_SIZE)]=
|
||||
COLOR::BlenderYellow,
|
||||
};
|
||||
|
||||
static RenderResource * gizmo_rr=nullptr;
|
||||
Renderable *GetGizmoRenderable(const GizmoShape &gs,const GizmoColor &);
|
||||
|
||||
struct GizmoResource
|
||||
{
|
||||
Material * mtl;
|
||||
MaterialInstance * mi[size_t(GizmoColor::RANGE_SIZE)];
|
||||
Pipeline * pipeline;
|
||||
VertexDataManager * vdm;
|
||||
StaticMesh *CreateGizmoStaticMesh(SceneNode *);
|
||||
|
||||
PrimitiveCreater * prim_creater;
|
||||
};
|
||||
|
||||
static GizmoResource gizmo_line{};
|
||||
static GizmoResource gizmo_triangle{};
|
||||
|
||||
static Primitive * gizmo_prim[size_t(GizmoShape::RANGE_SIZE)]{};
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
@@ -83,7 +83,12 @@ private:
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
ro_plane=inline_geometry::CreatePlane(db,material->GetDefaultVIL());
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
ro_plane=inline_geometry::CreatePlane(&pc);
|
||||
|
||||
if(ro_plane)
|
||||
db->Add(ro_plane);
|
||||
|
||||
return ro_plane;
|
||||
}
|
||||
|
@@ -0,0 +1,30 @@
|
||||
#include<hgl/graph/StaticMesh.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
StaticMesh *StaticMesh::CreateNewObject(RenderResource *rr,SceneNode *node)
|
||||
{
|
||||
if(!node)
|
||||
return(nullptr);
|
||||
|
||||
if(node->IsEmpty())
|
||||
return(nullptr);
|
||||
|
||||
return(new StaticMesh(rr,node));
|
||||
}
|
||||
|
||||
StaticMesh::StaticMesh(RenderResource *r,SceneNode *sn)
|
||||
{
|
||||
rr=r;
|
||||
root_node=sn;
|
||||
}
|
||||
|
||||
StaticMesh::~StaticMesh()
|
||||
{
|
||||
rr->Release(this);
|
||||
|
||||
SAFE_CLEAR(root_node);
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/graph/SceneNode.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class StaticMesh
|
||||
{
|
||||
RenderResource *rr;
|
||||
|
||||
SortedSets<Primitive *> prim_set;
|
||||
SortedSets<MaterialInstance *> mi_set;
|
||||
SortedSets<Pipeline *> pipeline_set;
|
||||
|
||||
protected:
|
||||
|
||||
SceneNode *root_node
|
||||
|
||||
public:
|
||||
|
||||
|
||||
};
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -233,7 +233,7 @@ private:
|
||||
{
|
||||
struct CylinderCreateInfo cci;
|
||||
|
||||
cci.halfExtend =1.25; //圆柱一半高度
|
||||
cci.halfExtend =1.25; //圆柱一半高度
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =1.25f; //圆柱半径
|
||||
|
||||
@@ -256,7 +256,7 @@ private:
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(U8_TEXT("Create Renderable failed! Primitive: ")+r->GetName());
|
||||
LOG_ERROR("Create Renderable failed! Primitive: "+r->GetName());
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user