diff --git a/CMCore b/CMCore index 7feefc65..1a61053e 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 7feefc65c96d704f05b43f266b30e628fad5e539 +Subproject commit 1a61053e33ba573fb80a3775200e3db83dafd6bd diff --git a/example/Gizmo/Gizmo.h b/example/Gizmo/Gizmo.h index 914a5525..b64a080d 100644 --- a/example/Gizmo/Gizmo.h +++ b/example/Gizmo/Gizmo.h @@ -32,4 +32,6 @@ enum class GizmoShape:uint bool InitGizmoResource(GPUDevice *); void FreeGizmoResource(); +StaticMesh *GetGizmoMoveStaticMesh(); + VK_NAMESPACE_END diff --git a/example/Gizmo/Gizmo3DMove.cpp b/example/Gizmo/Gizmo3DMove.cpp index fb54098d..7a1f3dd2 100644 --- a/example/Gizmo/Gizmo3DMove.cpp +++ b/example/Gizmo/Gizmo3DMove.cpp @@ -30,66 +30,85 @@ VK_NAMESPACE_BEGIN 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]); - - { - Transform 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 +StaticMesh *GetGizmoMoveStaticMesh() +{ + return sm_gizmo_move; +} + +void ClearGizmoMoveStaticMesh() +{ + SAFE_CLEAR(sm_gizmo_move); +} + +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(sphere); + + root_node->CreateSubNode(scale(9,1,1),cylinder[0]); + + { + Transform tm; + + tm.SetTranslation(Vector3f(0,0,4.5f)); + root_node->CreateSubNode(tm.GetMatrix(),cylinder[2]); //Z 向上圆柱 + + tm.SetTranslation(Vector3f(0,0,9.5f)); + root_node->CreateSubNode(tm.GetMatrix(),cone[2]); //Z 向上圆锥 + + tm.SetRotation(AxisVector::Y,90); + tm.SetTranslation(Vector3f(4.5f,0,0)); + + root_node->CreateSubNode(tm.GetMatrix(),cylinder[0]); //X 向右圆柱 + + tm.SetTranslation(Vector3f(9.5f,0,0)); + root_node->CreateSubNode(tm.GetMatrix(),cone[0]); //X 向右圆锥 + + tm.SetRotation(AxisVector::X,90); + tm.SetTranslation(Vector3f(0,4.5f,0)); + + root_node->CreateSubNode(tm.GetMatrix(),cylinder[1]); //Y 向前圆柱 + + tm.SetTranslation(Vector3f(0,9.5f,0)); + root_node->CreateSubNode(tm.GetMatrix(),cone[1]); //Y 向前圆锥 + } + + sm_gizmo_move=CreateGizmoStaticMesh(root_node); + } + + if(!sm_gizmo_move) + return(false); + + return(true); +} + VK_NAMESPACE_END diff --git a/example/Gizmo/GizmoResource.cpp b/example/Gizmo/GizmoResource.cpp index ffdd5366..73c45263 100644 --- a/example/Gizmo/GizmoResource.cpp +++ b/example/Gizmo/GizmoResource.cpp @@ -12,6 +12,9 @@ VK_NAMESPACE_BEGIN +bool InitGizmoMoveStaticMesh(); +void ClearGizmoMoveStaticMesh(); + namespace { static RenderResource * gizmo_rr=nullptr; @@ -109,9 +112,9 @@ namespace if(!gizmo_line.vdm) return(false); - if(!gizmo_line.vdm->Init( HGL_SIZE_1MB, //最大顶点数量 - HGL_SIZE_1MB, //最大索引数量 - IndexType::U16)) //索引类型 + if(!gizmo_line.vdm->Init( HGL_SIZE_1MB, //最大顶点数量 + HGL_SIZE_1MB, //最大索引数量 + IndexType::U16)) //索引类型 return(false); } @@ -238,11 +241,15 @@ bool InitGizmoResource(GPUDevice *device) if(!InitGizmoResource2D(device)) return(false); + InitGizmoMoveStaticMesh(); + return(true); } void FreeGizmoResource() { + ClearGizmoMoveStaticMesh(); + for(GizmoRenderable &gr:gizmo_rederable) { SAFE_CLEAR(gr.prim) diff --git a/example/Gizmo/GizmoTest.cpp b/example/Gizmo/GizmoTest.cpp index 01fea2d4..4ca0b56e 100644 --- a/example/Gizmo/GizmoTest.cpp +++ b/example/Gizmo/GizmoTest.cpp @@ -6,6 +6,8 @@ using namespace hgl::graph; class TestApp:public SceneAppFramework { + StaticMesh *sm=nullptr; + private: bool InitGizmo() @@ -13,6 +15,8 @@ private: if(!InitGizmoResource(device)) return(false); + sm=GetGizmoMoveStaticMesh(); + return(true); } @@ -25,6 +29,13 @@ public: if(!InitGizmo()) return(false); + + camera->pos=Vector3f(32,32,32); + camera_control->SetTarget(Vector3f(0,0,0)); + camera_control->Refresh(); + + render_root.RefreshMatrix(); + render_list->Expend(sm->GetScene()); return(true); } diff --git a/inc/hgl/graph/StaticMesh.h b/inc/hgl/graph/StaticMesh.h index df216ea6..95b7c4e6 100644 --- a/inc/hgl/graph/StaticMesh.h +++ b/inc/hgl/graph/StaticMesh.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -22,5 +22,9 @@ public: virtual ~StaticMesh(); static StaticMesh *CreateNewObject(RenderResource *,SceneNode *); + +public: + + SceneNode *GetScene(){return root_node;} };//class StaticMesh VK_NAMESPACE_END diff --git a/inc/hgl/graph/VK.h b/inc/hgl/graph/VK.h index 9e4cf817..469297a7 100644 --- a/inc/hgl/graph/VK.h +++ b/inc/hgl/graph/VK.h @@ -115,6 +115,8 @@ class IndirectDispatchBuffer; class RenderResource; +class StaticMesh; + enum class SharingMode { Exclusive = 0,