2024-07-14 23:49:05 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialInstance.h>
|
2024-06-26 01:51:13 +08:00
|
|
|
|
#include<hgl/graph/VKPipeline.h>
|
|
|
|
|
#include<hgl/graph/VKPrimitive.h>
|
|
|
|
|
#include<hgl/graph/VertexDataManager.h>
|
|
|
|
|
#include<hgl/graph/PrimitiveCreater.h>
|
|
|
|
|
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
|
|
|
|
#include<hgl/color/Color.h>
|
2024-07-01 02:57:33 +08:00
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
2025-01-15 02:42:04 +08:00
|
|
|
|
#include<hgl/graph/SceneNode.h>
|
2025-06-15 23:25:08 +08:00
|
|
|
|
#include<hgl/graph/RenderFramework.h>
|
2024-07-14 23:49:05 +08:00
|
|
|
|
#include"GizmoResource.h"
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
bool InitGizmoMoveNode(RenderFramework *);
|
|
|
|
|
void ClearGizmoMoveNode();
|
2024-07-29 14:01:10 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
//bool InitGizmoScaleMesh();
|
|
|
|
|
//void ClearGizmoScaleMesh();
|
|
|
|
|
//
|
|
|
|
|
//bool InitGizmoRotateMesh();
|
|
|
|
|
//void ClearGizmoRotateMesh();
|
2024-07-30 23:54:25 +08:00
|
|
|
|
|
2024-06-26 01:51:13 +08:00
|
|
|
|
namespace
|
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
static RenderFramework *render_framework=nullptr;
|
|
|
|
|
static RenderResource * gizmo_rr=nullptr;
|
2024-07-28 23:34:04 +08:00
|
|
|
|
|
|
|
|
|
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{};
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
struct GizmoMesh
|
2024-07-28 23:34:04 +08:00
|
|
|
|
{
|
|
|
|
|
Primitive *prim;
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
Mesh *mesh[size_t(GizmoColor::RANGE_SIZE)];
|
2024-07-28 23:34:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
GizmoMesh gizmo_mesh[size_t(GizmoShape::RANGE_SIZE)]{};
|
2024-07-28 23:34:04 +08:00
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
void InitGizmoMesh(const GizmoShape &gs,Primitive *prim,Pipeline *p)
|
2024-07-28 23:34:04 +08:00
|
|
|
|
{
|
|
|
|
|
if(!prim)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
GizmoMesh *gr=gizmo_mesh+size_t(gs);
|
2024-07-28 23:34:04 +08:00
|
|
|
|
|
|
|
|
|
gr->prim=prim;
|
|
|
|
|
|
|
|
|
|
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
2025-06-15 07:43:13 +08:00
|
|
|
|
gr->mesh[i]=CreateMesh(prim,gizmo_triangle.mi[i],p);
|
2024-07-28 23:34:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
bool InitMI(GizmoResource *gr)
|
|
|
|
|
{
|
|
|
|
|
if(!gr||!gr->mtl)
|
2024-06-26 01:51:13 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
Color4f color;
|
|
|
|
|
|
|
|
|
|
for(uint i=0;i<uint(GizmoColor::RANGE_SIZE);i++)
|
|
|
|
|
{
|
|
|
|
|
color=GetColor4f(gizmo_color[i],1.0);
|
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
gr->mi[i]=gizmo_rr->CreateMaterialInstance(gr->mtl,nullptr,&color);
|
|
|
|
|
if(!gr->mi[i])
|
2024-06-26 01:51:13 +08:00
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
bool InitGizmoResource2D()
|
2024-07-10 01:14:54 +08:00
|
|
|
|
{
|
|
|
|
|
if(!gizmo_rr)
|
|
|
|
|
return(false);
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
VulkanDevice *device=render_framework->GetDevice();
|
|
|
|
|
VulkanDevAttr *dev_attr=device->GetDevAttr();
|
|
|
|
|
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
|
2024-07-10 01:14:54 +08:00
|
|
|
|
|
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-30 00:47:28 +08:00
|
|
|
|
cfg.local_to_world=true;
|
2024-07-10 01:14:54 +08:00
|
|
|
|
cfg.position_format=VAT_VEC3;
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
mtl::MaterialCreateInfo *mci=CreateVertexLuminance3D(dev_attr,&cfg);
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
if(!mci)
|
|
|
|
|
return(false);
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
gizmo_line.mtl=gizmo_rr->CreateMaterial("GizmoLine",mci);
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!gizmo_line.mtl)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-07-30 00:47:28 +08:00
|
|
|
|
|
|
|
|
|
gizmo_line.mtl->Update();
|
2024-07-10 01:14:54 +08:00
|
|
|
|
}
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
gizmo_line.pipeline=render_pass->CreatePipeline(gizmo_line.mtl,InlinePipeline::Solid3D);
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!gizmo_line.pipeline)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
|
|
|
|
}
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!InitMI(&gizmo_line))
|
2024-06-26 01:51:13 +08:00
|
|
|
|
return(false);
|
2024-07-10 01:14:54 +08:00
|
|
|
|
|
|
|
|
|
{
|
2024-07-14 23:49:05 +08:00
|
|
|
|
gizmo_line.vdm=new VertexDataManager(device,gizmo_line.mtl->GetDefaultVIL());
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!gizmo_line.vdm)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-29 14:01:10 +08:00
|
|
|
|
if(!gizmo_line.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
|
|
|
|
HGL_SIZE_1MB, //最大索引数量
|
|
|
|
|
IndexType::U16)) //索引类型
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
|
|
|
|
}
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(true);
|
2024-06-26 01:51:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
bool InitGizmoResource3D()
|
2024-06-26 01:51:13 +08:00
|
|
|
|
{
|
2024-07-10 01:14:54 +08:00
|
|
|
|
if(!gizmo_rr)
|
2024-06-26 01:51:13 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
VulkanDevice *device=render_framework->GetDevice();
|
|
|
|
|
VulkanDevAttr *dev_attr=device->GetDevAttr();
|
|
|
|
|
RenderPass *render_pass=render_framework->GetDefaultRenderPass();
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-01 02:57:33 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
mtl::Material3DCreateConfig cfg(PrimitiveType::Triangles);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
cfg.local_to_world=true;
|
|
|
|
|
cfg.material_instance=true;
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
mtl::MaterialCreateInfo *mci=CreateGizmo3D(dev_attr,&cfg);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
if(!mci)
|
|
|
|
|
return(false);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
gizmo_triangle.mtl=gizmo_rr->CreateMaterial("GizmoTriangle",mci);
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!gizmo_triangle.mtl)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-07-30 00:47:28 +08:00
|
|
|
|
|
|
|
|
|
gizmo_triangle.mtl->Update();
|
2024-07-01 13:37:47 +08:00
|
|
|
|
}
|
2024-07-01 02:57:33 +08:00
|
|
|
|
|
2024-07-01 13:37:47 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
gizmo_triangle.pipeline=render_pass->CreatePipeline(gizmo_triangle.mtl,InlinePipeline::Solid3D);
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!gizmo_triangle.pipeline)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
}
|
2024-06-26 01:51:13 +08:00
|
|
|
|
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!InitMI(&gizmo_triangle))
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2024-07-01 13:37:47 +08:00
|
|
|
|
{
|
2024-07-14 23:49:05 +08:00
|
|
|
|
gizmo_triangle.vdm=new VertexDataManager(device,gizmo_triangle.mtl->GetDefaultVIL());
|
2024-07-01 02:57:33 +08:00
|
|
|
|
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!gizmo_triangle.vdm)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-07-01 02:57:33 +08:00
|
|
|
|
|
2024-07-28 23:34:04 +08:00
|
|
|
|
if(!gizmo_triangle.vdm->Init( HGL_SIZE_1MB, //最大顶点数量
|
|
|
|
|
HGL_SIZE_1MB, //最大索引数量
|
|
|
|
|
IndexType::U16)) //索引类型
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2024-07-14 23:49:05 +08:00
|
|
|
|
gizmo_triangle.prim_creater=new PrimitiveCreater(gizmo_triangle.vdm);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
|
2024-07-14 23:49:05 +08:00
|
|
|
|
if(!gizmo_triangle.prim_creater)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2024-07-10 01:14:54 +08:00
|
|
|
|
using namespace inline_geometry;
|
|
|
|
|
|
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
InitGizmoMesh(GizmoShape::Square,CreatePlaneSqaure(gizmo_triangle.prim_creater),gizmo_triangle.pipeline);
|
2024-07-10 01:14:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 01:29:20 +08:00
|
|
|
|
{
|
|
|
|
|
CircleCreateInfo cci;
|
|
|
|
|
|
|
|
|
|
cci.center=Vector2f(0,0);
|
|
|
|
|
cci.radius=Vector2f(0.5,0.5);
|
|
|
|
|
cci.field_count=16;
|
|
|
|
|
cci.has_center=false;
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
InitGizmoMesh(GizmoShape::Circle,CreateCircle3DByIndexTriangles(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
2024-08-30 01:29:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
{
|
|
|
|
|
CubeCreateInfo cci;
|
|
|
|
|
|
|
|
|
|
cci.normal=true;
|
|
|
|
|
cci.tangent=false;
|
|
|
|
|
cci.tex_coord=false;
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
InitGizmoMesh(GizmoShape::Cube,CreateCube(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
2024-07-10 01:14:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
InitGizmoMesh(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,16),gizmo_triangle.pipeline);
|
2024-07-10 01:14:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ConeCreateInfo cci;
|
|
|
|
|
|
2024-08-30 00:30:06 +08:00
|
|
|
|
cci.radius =GIZMO_CONE_RADIUS; //圆锥半径
|
|
|
|
|
cci.halfExtend =1; //圆锤一半高度
|
2024-07-30 23:54:25 +08:00
|
|
|
|
cci.numberSlices=16; //圆锥底部分割数
|
|
|
|
|
cci.numberStacks=3; //圆锥高度分割数
|
2024-07-10 01:14:54 +08:00
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
InitGizmoMesh(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
2024-07-10 01:14:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct CylinderCreateInfo cci;
|
|
|
|
|
|
|
|
|
|
cci.halfExtend =1; //圆柱一半高度
|
2024-07-30 23:54:25 +08:00
|
|
|
|
cci.numberSlices=16; //圆柱底部分割数
|
2024-07-10 01:14:54 +08:00
|
|
|
|
cci.radius =1; //圆柱半径
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
InitGizmoMesh(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
2024-07-10 01:14:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-30 23:54:25 +08:00
|
|
|
|
{
|
|
|
|
|
struct TorusCreateInfo tci;
|
|
|
|
|
|
|
|
|
|
tci.innerRadius=0.975;
|
|
|
|
|
tci.outerRadius=1.0;
|
|
|
|
|
tci.numberSlices=64;
|
2024-07-31 00:11:24 +08:00
|
|
|
|
tci.numberStacks=8;
|
2024-07-30 23:54:25 +08:00
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
InitGizmoMesh(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
|
2024-07-30 23:54:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 01:14:54 +08:00
|
|
|
|
ENUM_CLASS_FOR(GizmoShape,int,i)
|
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
if(!gizmo_mesh[i].prim)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
|
|
|
|
}
|
2024-07-01 02:57:33 +08:00
|
|
|
|
}
|
2024-07-10 01:14:54 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
2024-07-01 02:57:33 +08:00
|
|
|
|
}
|
2024-07-10 01:14:54 +08:00
|
|
|
|
}//namespace
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
bool InitGizmoResource(RenderFramework *rf)
|
2024-07-10 01:14:54 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
if(!rf)
|
2024-07-30 00:47:28 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework=rf;
|
2024-07-10 01:14:54 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
gizmo_rr=render_framework->GetRenderResource();
|
2024-07-30 00:47:28 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
VulkanDevice *device=render_framework->GetDevice();
|
2024-07-10 01:14:54 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
if(!InitGizmoResource3D())
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
if(!InitGizmoResource2D())
|
2024-07-10 01:14:54 +08:00
|
|
|
|
return(false);
|
2024-07-01 13:37:47 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
InitGizmoMoveNode(rf);
|
2025-06-15 07:43:13 +08:00
|
|
|
|
//InitGizmoScaleMesh();
|
|
|
|
|
//InitGizmoRotateMesh();
|
2024-07-29 14:01:10 +08:00
|
|
|
|
|
2024-06-26 01:51:13 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 23:31:18 +08:00
|
|
|
|
void FreeGizmoResource()
|
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
//ClearGizmoRotateMesh();
|
|
|
|
|
//ClearGizmoScaleMesh();
|
2025-06-15 23:25:08 +08:00
|
|
|
|
ClearGizmoMoveNode();
|
2024-07-29 14:01:10 +08:00
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
for(GizmoMesh &gr:gizmo_mesh)
|
2024-07-28 23:34:04 +08:00
|
|
|
|
{
|
|
|
|
|
SAFE_CLEAR(gr.prim)
|
2025-06-15 07:43:13 +08:00
|
|
|
|
SAFE_CLEAR_OBJECT_ARRAY(gr.mesh)
|
2024-07-28 23:34:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-14 23:49:05 +08:00
|
|
|
|
SAFE_CLEAR(gizmo_triangle.prim_creater);
|
|
|
|
|
SAFE_CLEAR(gizmo_triangle.vdm);
|
2024-07-30 00:47:28 +08:00
|
|
|
|
|
|
|
|
|
SAFE_CLEAR(gizmo_line.prim_creater);
|
|
|
|
|
SAFE_CLEAR(gizmo_line.vdm);
|
2024-07-01 23:31:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
Mesh *GetGizmoMesh(const GizmoShape &shape,const GizmoColor &color)
|
2024-07-28 23:34:04 +08:00
|
|
|
|
{
|
|
|
|
|
if(!gizmo_rr)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
|
|
RANGE_CHECK_RETURN_NULLPTR(shape)
|
|
|
|
|
RANGE_CHECK_RETURN_NULLPTR(color)
|
|
|
|
|
|
2025-06-15 07:43:13 +08:00
|
|
|
|
return gizmo_mesh[size_t(shape)].mesh[size_t(color)];
|
2024-07-28 23:34:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-30 23:54:25 +08:00
|
|
|
|
VK_NAMESPACE_END
|