2024-06-25 01:17:47 +08:00
|
|
|
|
/*
|
|
|
|
|
Gizmo move
|
2023-11-01 18:37:10 +08:00
|
|
|
|
|
2024-06-25 01:17:47 +08:00
|
|
|
|
ref: Blender 4
|
2023-11-01 18:37:10 +08:00
|
|
|
|
|
2024-06-25 01:17:47 +08:00
|
|
|
|
|
|
|
|
|
0 9-10
|
|
|
|
|
*----------------->>>>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5+
|
|
|
|
|
| +6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v
|
2023-11-01 18:37:10 +08:00
|
|
|
|
|
2024-06-25 01:17:47 +08:00
|
|
|
|
假设轴尺寸为10
|
|
|
|
|
箭头长度为2,直径为2
|
|
|
|
|
双轴调节正方形,长宽为1,位置为5,5
|
2023-11-01 18:37:10 +08:00
|
|
|
|
|
2024-06-25 01:17:47 +08:00
|
|
|
|
中心球半径为1
|
|
|
|
|
*/
|
2023-11-01 18:37:10 +08:00
|
|
|
|
|
2024-07-15 01:23:13 +08:00
|
|
|
|
#include"GizmoResource.h"
|
2025-01-15 02:42:04 +08:00
|
|
|
|
#include<hgl/graph/SceneNode.h>
|
2024-07-28 23:34:04 +08:00
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
2025-06-15 23:25:08 +08:00
|
|
|
|
#include<hgl/graph/RenderFramework.h>
|
|
|
|
|
#include<hgl/component/MeshComponent.h>
|
2024-07-15 01:23:13 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
|
2024-07-28 23:34:04 +08:00
|
|
|
|
namespace
|
2024-07-15 01:23:13 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
|
|
|
|
|
static SceneNode *sn_gizmo_move=nullptr;
|
2024-07-29 14:01:10 +08:00
|
|
|
|
}//namespace
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
SceneNode *GetGizmoMoveNode()
|
2024-07-29 14:01:10 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
return sn_gizmo_move;
|
2024-07-29 14:01:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
void ClearGizmoMoveNode()
|
2024-07-29 14:01:10 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
SAFE_CLEAR(sn_gizmo_move);
|
2024-07-29 14:01:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
bool InitGizmoMoveNode(RenderFramework *render_framework)
|
2024-07-29 14:01:10 +08:00
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
Mesh *sphere=GetGizmoMesh(GizmoShape::Sphere,GizmoColor::White);
|
2025-05-18 02:03:16 +08:00
|
|
|
|
Mesh *cylinder[3]
|
2024-07-29 14:01:10 +08:00
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Red),
|
|
|
|
|
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Green),
|
|
|
|
|
GetGizmoMesh(GizmoShape::Cylinder,GizmoColor::Blue),
|
2024-07-29 14:01:10 +08:00
|
|
|
|
};
|
2024-07-15 01:23:13 +08:00
|
|
|
|
|
2025-05-18 02:03:16 +08:00
|
|
|
|
Mesh *cone[3]
|
2024-07-28 23:34:04 +08:00
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Red),
|
|
|
|
|
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Green),
|
|
|
|
|
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Blue),
|
2024-07-29 14:01:10 +08:00
|
|
|
|
};
|
2024-07-15 01:23:13 +08:00
|
|
|
|
|
2025-05-18 02:03:16 +08:00
|
|
|
|
Mesh *circle[3]=
|
2024-07-30 13:55:44 +08:00
|
|
|
|
{
|
2025-06-15 07:43:13 +08:00
|
|
|
|
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Red),
|
|
|
|
|
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Green),
|
|
|
|
|
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Blue)
|
2024-07-30 13:55:44 +08:00
|
|
|
|
};
|
|
|
|
|
|
2024-07-29 14:01:10 +08:00
|
|
|
|
if(!sphere)
|
|
|
|
|
return(false);
|
2024-07-28 23:34:04 +08:00
|
|
|
|
|
2024-07-29 14:01:10 +08:00
|
|
|
|
for(int i=0;i<3;i++)
|
|
|
|
|
{
|
|
|
|
|
if(!cylinder[i])
|
2024-07-28 23:34:04 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2024-07-29 14:01:10 +08:00
|
|
|
|
if(!cone[i])
|
|
|
|
|
return(false);
|
2024-07-30 23:54:25 +08:00
|
|
|
|
|
2024-08-30 01:29:20 +08:00
|
|
|
|
if(!circle[i])
|
2024-07-30 23:54:25 +08:00
|
|
|
|
return(false);
|
2024-07-29 14:01:10 +08:00
|
|
|
|
}
|
2024-07-28 23:34:04 +08:00
|
|
|
|
|
2024-07-29 14:01:10 +08:00
|
|
|
|
{
|
2025-06-15 23:25:08 +08:00
|
|
|
|
sn_gizmo_move=new SceneNode();
|
2024-08-29 13:07:02 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
sn_gizmo_move->AttachComponent(render_framework->CreateComponent<MeshComponent>(sphere));
|
2024-07-29 14:01:10 +08:00
|
|
|
|
|
2024-07-28 23:34:04 +08:00
|
|
|
|
{
|
2024-07-29 14:01:10 +08:00
|
|
|
|
Transform tm;
|
2024-07-28 23:34:04 +08:00
|
|
|
|
|
2024-08-05 01:25:49 +08:00
|
|
|
|
const Vector3f one_scale(1);
|
2024-08-30 01:29:20 +08:00
|
|
|
|
const Vector3f circle_scale(2);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
|
2024-07-30 01:01:29 +08:00
|
|
|
|
|
2024-07-30 13:55:44 +08:00
|
|
|
|
{
|
|
|
|
|
tm.SetScale(cylinder_scale);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
|
2024-07-30 13:55:44 +08:00
|
|
|
|
|
|
|
|
|
tm.SetScale(one_scale);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[2]); //Z 向上圆锥
|
2024-07-30 13:55:44 +08:00
|
|
|
|
|
2024-08-30 01:29:20 +08:00
|
|
|
|
tm.SetScale(circle_scale);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[2]);
|
2024-07-30 13:55:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tm.SetScale(cylinder_scale);
|
|
|
|
|
tm.SetRotation(AxisVector::Y,90);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(GIZMO_CYLINDER_OFFSET,0,0);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[0]); //X 向右圆柱
|
2024-07-30 13:55:44 +08:00
|
|
|
|
|
|
|
|
|
tm.SetScale(one_scale);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[0]); //X 向右圆锥
|
2024-07-30 13:55:44 +08:00
|
|
|
|
|
2024-08-30 01:29:20 +08:00
|
|
|
|
tm.SetScale(circle_scale);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[0]);
|
2024-07-30 13:55:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tm.SetScale(cylinder_scale);
|
|
|
|
|
tm.SetRotation(AxisVector::X,-90);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
tm.SetTranslation(0,GIZMO_CYLINDER_OFFSET,0);
|
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[1]); //Y 向前圆柱
|
2024-07-30 13:55:44 +08:00
|
|
|
|
|
|
|
|
|
tm.SetScale(one_scale);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[1]); //Y 向前圆锥
|
2024-07-28 23:34:04 +08:00
|
|
|
|
|
2024-08-30 01:29:20 +08:00
|
|
|
|
tm.SetScale(circle_scale);
|
2024-08-30 00:30:06 +08:00
|
|
|
|
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
|
2025-06-15 23:25:08 +08:00
|
|
|
|
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[1]);
|
2024-07-30 13:55:44 +08:00
|
|
|
|
}
|
2024-07-29 14:01:10 +08:00
|
|
|
|
}
|
2024-07-28 23:34:04 +08:00
|
|
|
|
}
|
2024-07-29 14:01:10 +08:00
|
|
|
|
|
2025-06-15 23:25:08 +08:00
|
|
|
|
if(!sn_gizmo_move)
|
2024-07-29 14:01:10 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2024-07-15 01:23:13 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_END
|