diff --git a/CMCore b/CMCore index a82810d5..538d1978 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit a82810d58aa2dab60360a278038aa31ab7bcb116 +Subproject commit 538d19781a7818e1333d9ee5a8c165dcff072a25 diff --git a/CMSceneGraph b/CMSceneGraph index 3bc0658d..3e2f129a 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 3bc0658d28e30457907003d85151b3b46083af53 +Subproject commit 3e2f129abf1b0480133010830b97f6eb902f960b diff --git a/example/Gizmo/CMakeLists.txt b/example/Gizmo/CMakeLists.txt index 36803e1a..8208e083 100644 --- a/example/Gizmo/CMakeLists.txt +++ b/example/Gizmo/CMakeLists.txt @@ -14,6 +14,6 @@ CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp) CreateProject(02_RayPicking RayPicking.cpp) CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp) -CreateProject(04_Gizmo3DMove Gizmo3DMove.cpp Gizmo.h Gizmo.cpp) +CreateProject(04_Gizmo3DMove Gizmo3DMove.cpp Gizmo.h GizmoResource.cpp) #CreateProject(03_BlenderAxis BlenderAxis.cpp) diff --git a/example/Gizmo/GizmoResource.cpp b/example/Gizmo/GizmoResource.cpp index 667fffd4..c82e6afe 100644 --- a/example/Gizmo/GizmoResource.cpp +++ b/example/Gizmo/GizmoResource.cpp @@ -7,6 +7,7 @@ #include #include #include +#include VK_NAMESPACE_BEGIN @@ -130,10 +131,25 @@ bool InitGizmoResource(RenderResource *rr) if(!prim_creater) return(false); - - } + { + using namespace inline_geometry; + + { + struct PlaneGridCreateInfo pgci; + + pgci.grid_size.Set(32,32); + pgci.sub_count.Set(8,8); + + pgci.lum=0.75; + pgci.sub_lum=1.0; + + PrimitiveCreater pc(device,material->GetDefaultVIL()); + + prim[size_t(GizmoShape::Plane)]=CreatePlaneGrid(prim_creater,&pgci); + } + } return(true); } diff --git a/example/Gizmo/PlaneGrid3D.cpp b/example/Gizmo/PlaneGrid3D.cpp index af9cb0f3..23d86683 100644 --- a/example/Gizmo/PlaneGrid3D.cpp +++ b/example/Gizmo/PlaneGrid3D.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace hgl; using namespace hgl::graph; @@ -33,6 +34,10 @@ private: material=db->LoadMaterial("Std3D/VertexLum3D",&cfg); if(!material)return(false); + VILConfig vil_config; + + vil_config.Add(VAN::Luminance,VF_V1UN8); + Color4f GridColor; COLOR ce=COLOR::BlenderAxisRed; @@ -40,12 +45,12 @@ private: { GridColor=GetColor4f(ce,1.0); - material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor); + material_instance[i]=db->CreateMaterialInstance(material,&vil_config,&GridColor); ce=COLOR((int)ce+1); } - pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines); + pipeline=CreatePipeline(material_instance[0],InlinePipeline::Solid3D,Prim::Lines); return pipeline; } @@ -59,12 +64,12 @@ private: pgci.grid_size.Set(32,32); pgci.sub_count.Set(8,8); - pgci.lum=0.75; - pgci.sub_lum=1.0; + pgci.lum=180; + pgci.sub_lum=255; - PrimitiveCreater pc(device,material->GetDefaultVIL()); + PrimitiveCreater pc(device,material_instance[0]->GetVIL()); - prim_plane_grid=CreatePlaneGrid(&pc,&pgci); + prim_plane_grid=CreatePlaneGrid2D(&pc,&pgci); return prim_plane_grid; } diff --git a/inc/hgl/graph/InlineGeometry.h b/inc/hgl/graph/InlineGeometry.h index a371ba44..201be5f1 100644 --- a/inc/hgl/graph/InlineGeometry.h +++ b/inc/hgl/graph/InlineGeometry.h @@ -71,14 +71,16 @@ namespace hgl Size2u sub_count; ///<细分格子数量 - float lum; ///<一般线条颜色 - float sub_lum; ///<细分及边界线条颜色 + uint8 lum; ///<一般线条亮度 + uint8 sub_lum; ///<细分及边界线条亮度 };//struct PlaneGridCreateInfo /** * 创建一个平面网格(线条) */ - Primitive *CreatePlaneGrid(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci); + Primitive *CreatePlaneGrid2D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci); //创建一个平面网格(线条) + + Primitive *CreatePlaneGrid3D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci); /** * 创建一个平面(三角形) diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index c0997718..da2a720c 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -163,8 +163,8 @@ namespace hgl return pc->Create(); } - - Primitive *CreatePlaneGrid(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci) + + Primitive *CreatePlaneGrid2D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci) { if(!pc->Init("PlaneGrid",((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0)) return(nullptr); @@ -192,7 +192,59 @@ namespace hgl Vector2f(left+col,bottom)); } - VABMap1f lum(pc->GetVABMap(VAN::Luminance)); + VABMap1uf8 lum(pc->GetVABMap(VAN::Luminance)); + + if(lum.IsValid()) + { + for(uint row=0;row<=pgci->grid_size.Height();row++) + { + if((row%pgci->sub_count.Height())==0) + lum->RepeatWrite(pgci->sub_lum,2); + else + lum->RepeatWrite(pgci->lum,2); + } + + for(uint col=0;col<=pgci->grid_size.Width();col++) + { + if((col%pgci->sub_count.Width())==0) + lum->RepeatWrite(pgci->sub_lum,2); + else + lum->RepeatWrite(pgci->lum,2); + } + } + + return pc->Create(); + } + + Primitive *CreatePlaneGrid3D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci) + { + if(!pc->Init("PlaneGrid",((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0)) + return(nullptr); + + VABMap3f vertex(pc->GetVABMap(VAN::Position)); + + if(!vertex.IsValid()) + return(nullptr); + + const float right=float(pgci->grid_size.Width())/2.0f; + const float left =-right; + + const float bottom=float(pgci->grid_size.Height())/2.0f; + const float top =-bottom; + + for(uint row=0;row<=pgci->grid_size.Height();row++) + { + vertex->WriteLine( Vector3f(left ,top+row,0), + Vector3f(right,top+row,0)); + } + + for(uint col=0;col<=pgci->grid_size.Width();col++) + { + vertex->WriteLine(Vector3f(left+col,top ,0), + Vector3f(left+col,bottom,0)); + } + + VABMap1uf8 lum(pc->GetVABMap(VAN::Luminance)); if(lum.IsValid()) {