调整好坐标轴方向以及裁剪面,并增加最简易坐标轴绘制范例

This commit is contained in:
hyzboy 2025-06-18 01:55:53 +08:00
parent d1a1437e6f
commit 368056bb96
10 changed files with 139 additions and 202 deletions

View File

@ -70,7 +70,7 @@ private:
return pipeline;
}
bool InitVBO()
{
const auto ext=GetExtent();

View File

@ -1,30 +0,0 @@
// Blender axis
/**
* 0 1 2 3 4 5 6 7
* 0+---------->>>> X
* 1|
* 2|
* 3| +--+
* 4| +--+
* 5|
* 6V
* 7V
*
* Blender设计
*
* 8
* 2
*
* 2D平移的方块尺寸为13-4
*
*/
/**
*
*/
class GizmoScale
{
public:
};//class GizmoScale

View File

@ -10,9 +10,9 @@
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
endmacro()
CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
CreateProject(02_RayPicking RayPicking.cpp)
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
CreateProject(01_SimplestAxis SimplestAxis.cpp)
CreateProject(02_PlaneGrid3D PlaneGrid3D.cpp)
CreateProject(03_RayPicking RayPicking.cpp)
CreateProject(04_Gizmo3DTest GizmoTest.cpp
Gizmo.h
@ -22,5 +22,3 @@ CreateProject(04_Gizmo3DTest GizmoTest.cpp
#Gizmo3DScale.cpp
#Gizmo3DRotate.cpp
)
#CreateProject(03_BlenderAxis BlenderAxis.cpp)

View File

@ -63,11 +63,11 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Blue),
};
Mesh *circle[3]=
Mesh *square[3]=
{
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Blue)
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
};
if(!sphere)
@ -81,7 +81,7 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
if(!cone[i])
return(false);
if(!circle[i])
if(!square[i])
return(false);
}
@ -94,21 +94,21 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
Transform tm;
const Vector3f one_scale(1);
const Vector3f circle_scale(2);
const Vector3f square_scale(2);
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
{
tm.SetScale(cylinder_scale);
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
tm.SetScale(one_scale);
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[2]); //Z 向上圆锥
tm.SetScale(circle_scale);
tm.SetScale(square_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[2]);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[2]);
}
{
@ -121,9 +121,9 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[0]); //X 向右圆锥
tm.SetScale(circle_scale);
tm.SetScale(square_scale);
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[0]);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[0]);
}
{
@ -136,9 +136,9 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[1]); //Y 向前圆锥
tm.SetScale(circle_scale);
tm.SetScale(square_scale);
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[1]);
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[1]);
}
}
}

View File

@ -1,147 +0,0 @@
// Metric Cells Grid
#include"VulkanAppFramework.h"
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/PrimitiveCreater.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
using namespace hgl;
using namespace hgl::graph;
struct MetricCellsGridData
{
Color4f x_color;
Color4f y_color;
Color4f x_axis_color;
Color4f y_axis_color;
Color4f center_color;
Vector2f lum;
Vector2f cell_step;
Vector2f big_cell_step;
Vector2f scale;
float axis_line_width;
float center_radius;
};
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
constexpr const float PLANE_SIZE=1024;
class TestApp:public SceneAppFramework
{
private:
MetricCellsGridData mcg_data;
Material * material =nullptr;
Pipeline * pipeline =nullptr;
Primitive * ro_plane =nullptr;
MaterialInstance * material_instance =nullptr;
private:
bool InitMDP()
{
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"MetricCellsGrid",PrimitiveType::Fan);
cfg.local_to_world=true;
material=db->LoadMaterial("Std3D/MetricCellsGrid",&cfg);
if(!material)return(false);
{
mcg_data.x_color=Color4f(1,1,1,1);
mcg_data.y_color=Color4f(1,1,1,1);
mcg_data.x_axis_color=GetColor4f(COLOR::BlenderAxisRed, 1.0);
mcg_data.y_axis_color=GetColor4f(COLOR::BlenderAxisGreen, 1.0);
mcg_data.center_color=Color4f(1,1,0,1);
mcg_data.lum =Vector2f(0.1,0.2);
mcg_data.cell_step =Vector2f(8,8);
mcg_data.big_cell_step =Vector2f(32,32);
mcg_data.scale =Vector2f(PLANE_SIZE,PLANE_SIZE);
mcg_data.axis_line_width=1.0;
mcg_data.center_radius =4.0;
}
material_instance=db->CreateMaterialInstance(material,nullptr,&mcg_data);
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,PrimitiveType::Fan);
return pipeline;
}
bool CreateRenderObject()
{
PrimitiveCreater pc(device,material->GetDefaultVIL());
ro_plane=inline_geometry::CreatePlaneSqaure(&pc);
if(ro_plane)
db->Add(ro_plane);
return ro_plane;
}
Mesh *Add(MaterialInstance *mi,const Matrix4f &mat)
{
Mesh *ri=db->CreateMesh(ro_plane,mi,pipeline);
if(!ri)
return(nullptr);
render_root.CreateSubNode(mat,ri);
return ri;
}
bool InitScene()
{
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
camera->pos=Vector3f(PLANE_SIZE/4,PLANE_SIZE/2,PLANE_SIZE/4);
camera_control->SetTarget(Vector3f(0,0,0));
camera_control->Refresh();
// camera_control->SetReserveDirection(true,true); //反转x,y
render_root.RefreshMatrix();
render_list->Expend(&render_root);
return(true);
}
public:
bool Init(uint width,uint height) override
{
if(!SceneAppFramework::Init(width,height))
return(false);
if(!InitMDP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
return RunApp<TestApp>(1280,720);
}

View File

@ -0,0 +1,100 @@
// SimplestAxis
// 直接从0,0,0向三个方向画一条直线用于确认坐标轴方向
#include<hgl/WorkManager.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/mtl/Material3DCreateConfig.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/FirstPersonCameraControl.h>
#include<hgl/color/Color.h>
#include<hgl/component/MeshComponent.h>
using namespace hgl;
using namespace hgl::graph;
class TestApp:public WorkObject
{
private:
Material * material =nullptr;
Pipeline * pipeline =nullptr;
Primitive * prim_axis =nullptr;
MaterialInstance * material_instance =nullptr;
private:
bool InitMDP()
{
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
cfg.local_to_world=true;
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor3D,&cfg);
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D);
return pipeline;
}
bool CreateRenderObject()
{
using namespace inline_geometry;
auto pc=GetPrimitiveCreater(material_instance);
inline_geometry::AxisCreateInfo aci;
prim_axis=CreateAxis(pc,&aci);
return prim_axis;
}
bool InitScene()
{
Mesh *ri=db->CreateMesh(prim_axis,material_instance,pipeline);
CreateComponent<MeshComponent>(GetSceneRoot(),ri);
CameraControl *camera_control=GetCameraControl();
camera_control->SetPosition(Vector3f(32,32,32));
camera_control->SetTarget(Vector3f(0,0,0));
// camera_control->SetReserveDirection(true,true); //反转x,y
return(true);
}
public:
using WorkObject::WorkObject;
~TestApp()
{
SAFE_CLEAR(prim_axis);
}
bool Init() override
{
if(!InitMDP())
return(false);
if(!CreateRenderObject())
return(false);
if(!InitScene())
return(false);
return(true);
}
};//class TestApp:public CameraAppFramework
int os_main(int,os_char **)
{
return RunFramework<TestApp>(OS_TEXT("SimplestAxis"),1280,720);
}

View File

@ -83,12 +83,9 @@ namespace hgl
WO_FUNC_FROM_RENDER_FRAMEWORK(CreatePipeline,graph::Pipeline *)
WO_FUNC_FROM_RENDER_FRAMEWORK(CreateMaterialInstance,graph::MaterialInstance *)
WO_FUNC_FROM_RENDER_FRAMEWORK(GetPrimitiveCreater,SharedPtr<graph::PrimitiveCreater>)
//WO_FUNC_FROM_RENDER_FRAMEWORK(CreatePrimitive,graph::Primitive *)
WO_FUNC_FROM_RENDER_FRAMEWORK(CreateMesh,graph::Mesh *)
#undef WO_FUNC_FROM_RENDER_FRAMEWORK
graph::Primitive *CreatePrimitive(const AnsiString &name,
const uint32_t vertices_count,
const graph::VIL *vil,
@ -97,6 +94,15 @@ namespace hgl
return render_framework?render_framework->CreatePrimitive(name,vertices_count,vil,vad_list):nullptr;
}
graph::Mesh *CreateMesh(const AnsiString &name,
const uint32_t vertices_count,
graph::MaterialInstance *mi,
graph::Pipeline *pipeline,
const std::initializer_list<graph::VertexAttribDataPtr> &vad_list)
{
return render_framework?render_framework->CreateMesh(name,vertices_count,mi,pipeline,vad_list):nullptr;
}
public: //Component 相关
template<typename C,typename ...ARGS>

View File

@ -19,14 +19,17 @@ struct Material3DCreateConfig:public MaterialCreateConfig,public Comparator<Mate
public:
Material3DCreateConfig(const PrimitiveType &p):MaterialCreateConfig(p)
Material3DCreateConfig(const PrimitiveType &p,
const WithCamera &wc=WithCamera::With,
const WithLocalToWorld &l2w=WithLocalToWorld::With)
:MaterialCreateConfig(p)
{
rt_output.color=1; //输出一个颜色
rt_output.depth=true; //不输出深度
rt_output.stencil=false; //不输出stencil
camera=true;
local_to_world=false;
camera=(wc==WithCamera::With);
local_to_world=(l2w==WithLocalToWorld::With);
position_format=VAT_VEC3;

View File

@ -23,6 +23,12 @@ namespace hgl::graph
namespace mtl
{
enum class WithCamera:uint8
{
Without=0,
With
};
enum class WithLocalToWorld:uint8
{
Without=0,

View File

@ -2,6 +2,7 @@
SET REPO="hyzgame"
SET BRANCH=master
git pull
call pull.bat CMAssetsManage %REPO% %BRANCH%
call pull.bat CMCMakeModule %REPO% %BRANCH%
call pull.bat CMCore %REPO% %BRANCH%