diff --git a/CMCore b/CMCore index 7f39d773..7165984d 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 7f39d7731845b3592cab7b5267eac88f7b13573b +Subproject commit 7165984d2270c61f19653a3a256c05786ec478fa diff --git a/example/Gizmo/CMakeLists.txt b/example/Gizmo/CMakeLists.txt index 6e62ac07..0b6970c6 100644 --- a/example/Gizmo/CMakeLists.txt +++ b/example/Gizmo/CMakeLists.txt @@ -14,6 +14,12 @@ CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp) CreateProject(02_RayPicking RayPicking.cpp) CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp) -CreateProject(04_Gizmo3DTest GizmoTest.cpp Gizmo3DMove.cpp Gizmo.h GizmoResource.h GizmoResource.cpp) +CreateProject(04_Gizmo3DTest GizmoTest.cpp + Gizmo.h + GizmoResource.h + GizmoResource.cpp + Gizmo3DMove.cpp + Gizmo3DScale.cpp + Gizmo3DRotate.cpp) #CreateProject(03_BlenderAxis BlenderAxis.cpp) diff --git a/example/Gizmo/Gizmo.h b/example/Gizmo/Gizmo.h index 3e177160..115fa88d 100644 --- a/example/Gizmo/Gizmo.h +++ b/example/Gizmo/Gizmo.h @@ -25,14 +25,16 @@ enum class GizmoShape:uint Sphere, //球 Cone, //圆锥 Cylinder, //圆柱 + Torus, //圆环 - ENUM_CLASS_RANGE(Plane,Cylinder) + ENUM_CLASS_RANGE(Plane,Torus) }; bool InitGizmoResource(RenderResource *); void FreeGizmoResource(); - StaticMesh *GetGizmoMoveStaticMesh(); +StaticMesh *GetGizmoScaleStaticMesh(); +StaticMesh *GetGizmoRotateStaticMesh(); VK_NAMESPACE_END diff --git a/example/Gizmo/Gizmo3DMove.cpp b/example/Gizmo/Gizmo3DMove.cpp index 02f155f7..7a5dcefe 100644 --- a/example/Gizmo/Gizmo3DMove.cpp +++ b/example/Gizmo/Gizmo3DMove.cpp @@ -76,17 +76,20 @@ bool InitGizmoMoveStaticMesh() if(!cone[i]) return(false); + + if(!plane[i]) + return(false); } { - SceneNode *root_node=new SceneNode(sphere); + SceneNode *root_node=new SceneNode(scale(0.5f),sphere); { Transform tm; constexpr const Vector3f one_scale(1); constexpr const Vector3f plane_scale(2); - constexpr const Vector3f cylinder_scale(0.35f,0.35f,4.5f); + constexpr const Vector3f cylinder_scale(0.35f,0.35f,4.0f); { tm.SetScale(cylinder_scale); diff --git a/example/Gizmo/Gizmo3DRotate.cpp b/example/Gizmo/Gizmo3DRotate.cpp new file mode 100644 index 00000000..51babf8f --- /dev/null +++ b/example/Gizmo/Gizmo3DRotate.cpp @@ -0,0 +1,66 @@ +#include"GizmoResource.h" +#include +#include + +VK_NAMESPACE_BEGIN + +namespace +{ + static StaticMesh *sm_gizmo_rotate=nullptr; +}//namespace + +StaticMesh *GetGizmoRotateStaticMesh() +{ + return sm_gizmo_rotate; +} + +void ClearGizmoRotateStaticMesh() +{ + SAFE_CLEAR(sm_gizmo_rotate); +} + +bool InitGizmoRotateStaticMesh() +{ + Renderable *torus[4] + { + GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Red), + GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Green), + GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Blue), + + GetGizmoRenderable(GizmoShape::Torus,GizmoColor::White), + }; + + for(int i=0;i<4;i++) + { + if(!torus[i]) + return(false); + } + + { + SceneNode *root_node=new SceneNode(); + + { + Transform tm; + + tm.SetScale(10.0f); + + tm.SetRotation(AXIS::Z,90); + root_node->CreateSubNode(tm,torus[0]); + + tm.ClearRotation(); + root_node->CreateSubNode(tm,torus[1]); + + tm.SetRotation(AXIS::X,90); + root_node->CreateSubNode(tm,torus[2]); + } + + sm_gizmo_rotate=CreateGizmoStaticMesh(root_node); + } + + if(!sm_gizmo_rotate) + return(false); + + return(true); +} + +VK_NAMESPACE_END diff --git a/example/Gizmo/Gizmo3DScale.cpp b/example/Gizmo/Gizmo3DScale.cpp new file mode 100644 index 00000000..d33fb773 --- /dev/null +++ b/example/Gizmo/Gizmo3DScale.cpp @@ -0,0 +1,149 @@ +/* + Gizmo move + + ref: Blender 4 + + + 0 9-10 + *----------------->>>> + | + | + | 5+ + | +6 + | + | + v + + 假设轴尺寸为10 + 箭头长度为2,直径为2 + 双轴调节正方形,长宽为1,位置为5,5 + + 中心球半径为1 +*/ + +#include"GizmoResource.h" +#include +#include + +VK_NAMESPACE_BEGIN + +namespace +{ + static StaticMesh *sm_gizmo_scale=nullptr; +}//namespace + +StaticMesh *GetGizmoScaleStaticMesh() +{ + return sm_gizmo_scale; +} + +void ClearGizmoScaleStaticMesh() +{ + SAFE_CLEAR(sm_gizmo_scale); +} + +bool InitGizmoScaleStaticMesh() +{ + 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 *cube[3] + { + GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Red), + GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Green), + GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Blue), + }; + + Renderable *plane[3]= + { + GetGizmoRenderable(GizmoShape::Plane,GizmoColor::Red), + GetGizmoRenderable(GizmoShape::Plane,GizmoColor::Green), + GetGizmoRenderable(GizmoShape::Plane,GizmoColor::Blue) + }; + + if(!sphere) + return(false); + + for(int i=0;i<3;i++) + { + if(!cylinder[i]) + return(false); + + if(!cube[i]) + return(false); + + if(!plane[i]) + return(false); + } + + { + SceneNode *root_node=new SceneNode(scale(0.5f),sphere); + + { + Transform tm; + + constexpr const Vector3f one_scale(2); + constexpr const Vector3f plane_scale(2); + constexpr const Vector3f cylinder_scale(0.35f,0.35f,4.0f); + + { + tm.SetScale(cylinder_scale); + tm.SetTranslation(0,0,4.5f); + root_node->CreateSubNode(tm,cylinder[2]); //Z 向上圆柱 + + tm.SetScale(one_scale); + tm.SetTranslation(0,0,9.5f); + root_node->CreateSubNode(tm,cube[2]); //Z 向上圆锥 + + tm.SetScale(plane_scale); + tm.SetTranslation(5,5,0); + root_node->CreateSubNode(tm,plane[2]); + } + + { + tm.SetScale(cylinder_scale); + tm.SetRotation(AxisVector::Y,90); + tm.SetTranslation(4.5f,0,0); + root_node->CreateSubNode(tm,cylinder[0]); //X 向右圆柱 + + tm.SetScale(one_scale); + tm.SetTranslation(9.5f,0,0); + root_node->CreateSubNode(tm,cube[0]); //X 向右圆锥 + + tm.SetScale(plane_scale); + tm.SetTranslation(0,5,5); + root_node->CreateSubNode(tm,plane[0]); + } + + { + tm.SetScale(cylinder_scale); + tm.SetRotation(AxisVector::X,-90); + tm.SetTranslation(0,4.5f,0); + + root_node->CreateSubNode(tm,cylinder[1]); //Y 向前圆柱 + + tm.SetScale(one_scale); + tm.SetTranslation(0,9.5f,0); + root_node->CreateSubNode(tm,cube[1]); //Y 向前圆锥 + + tm.SetScale(plane_scale); + tm.SetTranslation(5,0,5); + root_node->CreateSubNode(tm,plane[1]); + } + } + + sm_gizmo_scale=CreateGizmoStaticMesh(root_node); + } + + if(!sm_gizmo_scale) + return(false); + + return(true); +} + +VK_NAMESPACE_END diff --git a/example/Gizmo/GizmoResource.cpp b/example/Gizmo/GizmoResource.cpp index e2da9f25..4125f5cc 100644 --- a/example/Gizmo/GizmoResource.cpp +++ b/example/Gizmo/GizmoResource.cpp @@ -15,6 +15,12 @@ VK_NAMESPACE_BEGIN bool InitGizmoMoveStaticMesh(); void ClearGizmoMoveStaticMesh(); +bool InitGizmoScaleStaticMesh(); +void ClearGizmoScaleStaticMesh(); + +bool InitGizmoRotateStaticMesh(); +void ClearGizmoRotateStaticMesh(); + namespace { static RenderResource * gizmo_rr=nullptr; @@ -198,7 +204,7 @@ namespace } { - InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,32),gizmo_triangle.pipeline); + InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,8),gizmo_triangle.pipeline); } { @@ -206,8 +212,8 @@ namespace cci.radius =1; //圆锥半径 cci.halfExtend =1; //圆锤一半高度 - cci.numberSlices=32; //圆锥底部分割数 - cci.numberStacks=8; //圆锥高度分割数 + cci.numberSlices=16; //圆锥底部分割数 + cci.numberStacks=3; //圆锥高度分割数 InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline); } @@ -216,12 +222,23 @@ namespace struct CylinderCreateInfo cci; cci.halfExtend =1; //圆柱一半高度 - cci.numberSlices=32; //圆柱底部分割数 + cci.numberSlices=16; //圆柱底部分割数 cci.radius =1; //圆柱半径 InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline); } + { + struct TorusCreateInfo tci; + + tci.innerRadius=0.975; + tci.outerRadius=1.0; + tci.numberSlices=64; + tci.numberStacks=32; + + InitGizmoRenderable(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline); + } + ENUM_CLASS_FOR(GizmoShape,int,i) { if(!gizmo_rederable[i].prim) @@ -252,12 +269,16 @@ bool InitGizmoResource(RenderResource *rr) return(false); InitGizmoMoveStaticMesh(); + InitGizmoScaleStaticMesh(); + InitGizmoRotateStaticMesh(); return(true); } void FreeGizmoResource() { + ClearGizmoRotateStaticMesh(); + ClearGizmoScaleStaticMesh(); ClearGizmoMoveStaticMesh(); for(GizmoRenderable &gr:gizmo_rederable) @@ -295,4 +316,4 @@ StaticMesh *CreateGizmoStaticMesh(SceneNode *root_node) return(new StaticMesh(root_node)); } -VK_NAMESPACE_END \ No newline at end of file +VK_NAMESPACE_END diff --git a/example/Gizmo/GizmoTest.cpp b/example/Gizmo/GizmoTest.cpp index e0e2afef..2b973dc2 100644 --- a/example/Gizmo/GizmoTest.cpp +++ b/example/Gizmo/GizmoTest.cpp @@ -6,7 +6,8 @@ using namespace hgl::graph; class TestApp:public SceneAppFramework { - StaticMesh *sm=nullptr; + StaticMesh *sm_move=nullptr; + StaticMesh *sm_rotate=nullptr; private: @@ -15,7 +16,8 @@ private: if(!InitGizmoResource(db)) return(false); - sm=GetGizmoMoveStaticMesh(); + sm_move =GetGizmoMoveStaticMesh(); + sm_rotate =GetGizmoRotateStaticMesh(); return(true); } @@ -34,7 +36,7 @@ public: camera_control->SetTarget(Vector3f(0,0,0)); camera_control->Refresh(); - SceneNode *sn=sm->GetScene(); + SceneNode *sn=sm_rotate->GetScene(); sn->RefreshMatrix(); diff --git a/res b/res index 475d8ad4..e1a36d78 160000 --- a/res +++ b/res @@ -1 +1 @@ -Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd +Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index ecfaaabb..155044f5 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -802,9 +802,9 @@ namespace hgl // generate normal and stores it in the right position // NOTE: cos (2PIx) = cos (x) and sin (2PIx) = sin (x) so, we can use this formula // normal = {cos(2PIs)cos(2PIt) , sin(2PIs)cos(2PIt) ,sin(2PIt)} - *np = +cos2PIs * cos2PIt; ++np; - *np = +sin2PIt; ++np; - *np = +sin2PIs * cos2PIt; ++np; + *np = cos2PIs * cos2PIt; ++np; + *np = sin2PIt; ++np; + *np = sin2PIs * cos2PIt; ++np; } if(tcp) diff --git a/src/ShaderGen/3d/M_Gizmo3D.cpp b/src/ShaderGen/3d/M_Gizmo3D.cpp index b0d67f55..ff62fa95 100644 --- a/src/ShaderGen/3d/M_Gizmo3D.cpp +++ b/src/ShaderGen/3d/M_Gizmo3D.cpp @@ -47,7 +47,7 @@ void main() float specular=max(dot(half_vector,Input.Normal),0.0); - spec_color=specular*pow(specular,64)*SUN_COLOR; + spec_color=specular*pow(specular,16)*SUN_COLOR; } FragColor=vec4(direct_color+spec_color,1.0);