TerraForge3D  2.3.1
3D Terrain And Landscape Generator
ClearMeshGenerator.cpp
1#include "Generators/ClearMeshGenerator.h"
2#include "Utils/Utils.h"
3#include "Data/ApplicationState.h"
4#include "Profiler.h"
5
6ClearMeshGenerator::ClearMeshGenerator(ApplicationState *as, ComputeKernel *kernels)
7{
8 bool tmp = false;
9 appState = as;
10}
11
12void ClearMeshGenerator::Generate(ComputeKernel *kernels)
13{
14 START_PROFILER();
15
16 if(useGPU)
17 {
18 if (appState->mode == ApplicationMode::TERRAIN)
19 {
20 kernels->SetKernelArg("clear_mesh_terrain", 0, "mesh");
21 kernels->ExecuteKernel("clear_mesh_terrain", cl::NDRange(1), cl::NDRange(appState->models.coreTerrain->mesh->vertexCount));
22 }
23
24 else if (appState->mode == ApplicationMode::CUSTOM_BASE)
25 {
26 kernels->SetKernelArg("clear_mesh_custom_base", 0, "mesh");
27 kernels->SetKernelArg("clear_mesh_custom_base", 1, "mesh_copy");
28 kernels->ExecuteKernel("clear_mesh_custom_base", cl::NDRange(1), cl::NDRange(appState->models.customBase->mesh->vertexCount));
29 }
30 }
31
32 else
33 {
34 if (appState->mode == ApplicationMode::TERRAIN)
35 {
36 Mesh *mes = appState->models.coreTerrain->mesh;
37 int vc = mes->vertexCount;
38
39 for(int i=0; i<vc; i++)
40 {
41 mes->vert[i].normal.x = mes->vert[i].normal.y = mes->vert[i].normal.z = mes->vert[i].position.y = 0.0f;
42 mes->vert[i].extras1.x = 0.0f;
43 mes->vert[i].extras1.y = 0.0f;
44 mes->vert[i].extras1.z = 0.0f;
45 }
46 }
47
48 else if (appState->mode == ApplicationMode::CUSTOM_BASE)
49 {
50 Mesh *mes = appState->models.customBase->mesh;
51 Mesh *mesC = appState->models.customBaseCopy->mesh;
52 int vc = mesC->vertexCount;
53
54 for(int i=0; i<vc; i++)
55 {
56 mes->vert[i].normal.x = mes->vert[i].normal.y = mes->vert[i].normal.z = 0.0f;
57 mes->vert[i].position = mesC->vert[i].position;
58 mes->vert[i].extras1.x = 0.0f;
59 mes->vert[i].extras1.y = 0.0f;
60 mes->vert[i].extras1.z = 0.0f;
61 }
62 }
63 }
64
65 END_PROFILER(time);
66}
67
68nlohmann::json ClearMeshGenerator::Save()
69{
70 nlohmann::json data;
71 data["uiActive"] = uiActive;
72 data["useGPU"] = useGPU;
73 return data;
74}
75
76void ClearMeshGenerator::Load(nlohmann::json data)
77{
78 uiActive = data["uiActive"];
79 useGPU = data["useGPU"];
80}
81
82void ClearMeshGenerator::ShowSettings()
83{
84 if(ImGui::Checkbox("Use GPU##CMG", &useGPU))
85 {
86 }
87
88 ImGui::Checkbox("Use GPU For Normals(Flat Shading)##CMG", &appState->states.useGPUForNormals);
89 ImGui::Text("Time : %lf ms", time);
90}
Definition: Mesh.h:21
a class to store JSON values
Definition: json.hpp:17860