diff --git a/example/Basic/draw_triangle_use_UBO.cpp b/example/Basic/draw_triangle_use_UBO.cpp index 3621f50b..9722c61c 100644 --- a/example/Basic/draw_triangle_use_UBO.cpp +++ b/example/Basic/draw_triangle_use_UBO.cpp @@ -70,7 +70,7 @@ private: return pipeline; } - + bool InitVBO() { const auto ext=GetExtent(); diff --git a/example/Gizmo/BlenderAxis.cpp b/example/Gizmo/BlenderAxis.cpp deleted file mode 100644 index c5a53c39..00000000 --- a/example/Gizmo/BlenderAxis.cpp +++ /dev/null @@ -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平移的方块尺寸为1,位置在3-4 -* -*/ - -/** - * 缩放工具 - */ -class GizmoScale -{ -public: - - -};//class GizmoScale diff --git a/example/Gizmo/CMakeLists.txt b/example/Gizmo/CMakeLists.txt index 1cf23bab..a19ada39 100644 --- a/example/Gizmo/CMakeLists.txt +++ b/example/Gizmo/CMakeLists.txt @@ -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) diff --git a/example/Gizmo/Gizmo3DMove.cpp b/example/Gizmo/Gizmo3DMove.cpp index 4b69a269..2878b337 100644 --- a/example/Gizmo/Gizmo3DMove.cpp +++ b/example/Gizmo/Gizmo3DMove.cpp @@ -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(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱 + render_framework->CreateComponent(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱 tm.SetScale(one_scale); tm.SetTranslation(0,0,GIZMO_CONE_OFFSET); render_framework->CreateComponent(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(tm.GetMatrix(),sn_gizmo_move,circle[2]); + render_framework->CreateComponent(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(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(tm.GetMatrix(),sn_gizmo_move,circle[0]); + render_framework->CreateComponent(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(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(tm.GetMatrix(),sn_gizmo_move,circle[1]); + render_framework->CreateComponent(tm.GetMatrix(),sn_gizmo_move,square[1]); } } } diff --git a/example/Gizmo/MetricCellsGrid.cpp b/example/Gizmo/MetricCellsGrid.cpp deleted file mode 100644 index 542ce5b3..00000000 --- a/example/Gizmo/MetricCellsGrid.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Metric Cells Grid - -#include"VulkanAppFramework.h" -#include -#include -#include -#include -#include -#include -#include - -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(1280,720); -} diff --git a/example/Gizmo/SimplestAxis.cpp b/example/Gizmo/SimplestAxis.cpp new file mode 100644 index 00000000..740726d4 --- /dev/null +++ b/example/Gizmo/SimplestAxis.cpp @@ -0,0 +1,100 @@ +// SimplestAxis +// 直接从0,0,0向三个方向画一条直线,用于确认坐标轴方向 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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(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(OS_TEXT("SimplestAxis"),1280,720); +} diff --git a/inc/hgl/WorkObject.h b/inc/hgl/WorkObject.h index 0c404c62..20721c97 100644 --- a/inc/hgl/WorkObject.h +++ b/inc/hgl/WorkObject.h @@ -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) - //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 &vad_list) + { + return render_framework?render_framework->CreateMesh(name,vertices_count,mi,pipeline,vad_list):nullptr; + } + public: //Component 相关 template diff --git a/inc/hgl/graph/mtl/Material3DCreateConfig.h b/inc/hgl/graph/mtl/Material3DCreateConfig.h index a84051ef..d9847ad3 100644 --- a/inc/hgl/graph/mtl/Material3DCreateConfig.h +++ b/inc/hgl/graph/mtl/Material3DCreateConfig.h @@ -19,14 +19,17 @@ struct Material3DCreateConfig:public MaterialCreateConfig,public Comparator