2023-10-05 00:50:31 +08:00
|
|
|
|
// PlaneGrid3D
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
#include"VulkanAppFramework.h"
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
2020-10-21 12:39:22 +08:00
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
2019-05-27 22:48:01 +08:00
|
|
|
|
#include<hgl/graph/RenderList.h>
|
2020-11-19 22:12:31 +08:00
|
|
|
|
#include<hgl/graph/Camera.h>
|
2023-09-28 17:44:47 +08:00
|
|
|
|
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
2023-10-07 20:59:44 +08:00
|
|
|
|
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
2023-10-11 18:49:29 +08:00
|
|
|
|
class TestApp:public SceneAppFramework
|
2019-05-27 22:48:01 +08:00
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
Material * material =nullptr;
|
|
|
|
|
Pipeline * pipeline =nullptr;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
Primitive * ro_plane_grid =nullptr;
|
|
|
|
|
MaterialInstance * material_instance[3]{};
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
bool InitMDP()
|
2019-07-11 11:18:34 +08:00
|
|
|
|
{
|
2023-09-28 18:13:51 +08:00
|
|
|
|
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2023-09-28 17:44:47 +08:00
|
|
|
|
cfg.local_to_world=true;
|
|
|
|
|
|
2023-10-11 19:02:17 +08:00
|
|
|
|
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
2023-09-28 18:13:51 +08:00
|
|
|
|
if(!material)return(false);
|
2023-09-28 17:44:47 +08:00
|
|
|
|
|
2023-10-05 00:50:31 +08:00
|
|
|
|
Color4f GridColor;
|
|
|
|
|
COLOR ce=COLOR::BlenderAxisRed;
|
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
for(uint i=0;i<3;i++)
|
|
|
|
|
{
|
2023-10-05 00:50:31 +08:00
|
|
|
|
GridColor=GetColor4f(ce,1.0);
|
|
|
|
|
|
2023-10-11 19:14:24 +08:00
|
|
|
|
material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor);
|
2023-10-05 00:50:31 +08:00
|
|
|
|
|
|
|
|
|
ce=COLOR((int)ce+1);
|
2023-09-28 18:13:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
2021-09-15 19:17:56 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
return pipeline;
|
2019-07-11 11:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
bool CreateRenderObject()
|
2019-05-27 22:48:01 +08:00
|
|
|
|
{
|
2022-06-24 21:36:24 +08:00
|
|
|
|
using namespace inline_geometry;
|
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
struct PlaneGridCreateInfo pgci;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2023-09-29 02:59:10 +08:00
|
|
|
|
pgci.grid_size.width =32;
|
|
|
|
|
pgci.grid_size.height=32;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2023-09-29 02:59:10 +08:00
|
|
|
|
pgci.sub_count.width =8;
|
|
|
|
|
pgci.sub_count.height=8;
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
pgci.lum=0.5;
|
2023-09-29 02:59:10 +08:00
|
|
|
|
pgci.sub_lum=1.0;
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
ro_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
|
2021-11-30 15:01:55 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
return ro_plane_grid;
|
|
|
|
|
}
|
2023-10-13 19:22:11 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
|
|
|
|
{
|
|
|
|
|
Renderable *ri=db->CreateRenderable(ro_plane_grid,mi,pipeline);
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
if(!ri)
|
|
|
|
|
return(nullptr);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
render_root.CreateSubNode(mat,ri);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
return ri;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
bool InitScene()
|
|
|
|
|
{
|
2023-09-28 18:13:51 +08:00
|
|
|
|
Add(material_instance[0],Matrix4f(1.0f));
|
|
|
|
|
Add(material_instance[1],rotate(HGL_RAD_90,0,1,0));
|
|
|
|
|
Add(material_instance[2],rotate(HGL_RAD_90,1,0,0));
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
2023-09-29 02:59:10 +08:00
|
|
|
|
camera->pos=Vector3f(32,32,32);
|
2022-01-27 10:20:49 +08:00
|
|
|
|
camera_control->SetTarget(Vector3f(0,0,0));
|
|
|
|
|
camera_control->Refresh();
|
2022-01-18 12:10:02 +08:00
|
|
|
|
|
2023-10-12 02:24:58 +08:00
|
|
|
|
// camera_control->SetReserveDirection(true,true); //反转x,y
|
2023-10-11 19:38:12 +08:00
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
render_root.RefreshMatrix();
|
2023-09-28 17:44:47 +08:00
|
|
|
|
render_list->Expend(&render_root);
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2023-10-11 18:49:29 +08:00
|
|
|
|
bool Init(uint width,uint height) override
|
2019-05-27 22:48:01 +08:00
|
|
|
|
{
|
2023-10-11 18:49:29 +08:00
|
|
|
|
if(!SceneAppFramework::Init(width,height))
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
if(!InitMDP())
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2023-09-28 18:13:51 +08:00
|
|
|
|
if(!CreateRenderObject())
|
|
|
|
|
return(false);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
if(!InitScene())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-06-15 18:07:20 +08:00
|
|
|
|
};//class TestApp:public CameraAppFramework
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
int main(int,char **)
|
|
|
|
|
{
|
2023-10-11 18:49:29 +08:00
|
|
|
|
return RunApp<TestApp>(1280,720);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
}
|