//Run a mesher command int TriangleMesher::RunMesherCommand(MesherCommand* mc) { int ret = false; //Figure out which command to execute and run it if(mc->command_type == MesherCommand::GENERATE_RANDOM_GRID) ret = GenerateRandomGrid(mc->xmin, mc->xmax, mc->ymin, mc->ymax, mc->vertex_count); else if(mc->command_type == MesherCommand::GENERATE_UNIFORM_GRID) ret = GenerateUniformGrid(mc->xmin, mc->xmax, mc->ymin, mc->ymax, mc->xcount, mc->ycount); else if(mc->command_type == MesherCommand::GENERATE_HEX_GRID) ret = GenerateHexGrid(mc->xmin, mc->xmax, mc->ymin, mc->ymax, mc->xcount, mc->ycount); else if(mc->command_type == MesherCommand::RUN_TRIANGLE_MESHER) ret = RunTriangleMesher(mc->use_kd_tree); else if(mc->command_type == MesherCommand::LOAD_MESH_FROM_FILE) ret = LoadMeshFromFile(mc->filename, mc->load_save_triangles); else if(mc->command_type == MesherCommand::SAVE_MESH_TO_FILE) ret = SaveMeshToFile(mc->filename, mc->load_save_triangles); else if(mc->command_type == MesherCommand::WRITE_SVG) ret = WriteSVG(mc->svg_filename, mc->svg_width, mc->svg_height); else if(mc->command_type == MesherCommand::SUBDIVIDE_TRIANGLE) ret = SubdivideTriangle(mc->subdivide_vindex, mc->subdivide_triangle_local_index); else if(mc->command_type == MesherCommand::BARYCENTRIC_SUBDIVIDE) ret = BarycentricSubdivide(mc->subdivide_triangle_local_index); else if(mc->command_type == MesherCommand::BASIC_TRIANGLE_MESHER) ret = BasicTriangleMesher(); else if(mc->command_type == MesherCommand::STRETCHED_GRID) ret = StretchedGrid(mc->stretched_grid_iterations, mc->stretched_grid_alpha); else if(mc->command_type == MesherCommand::REFINE_MESH) ret = RefineMesh(mc->desired_edge_length); else if(mc->command_type == MesherCommand::DO_NOTHING) ret = true; //Update the mesher command result if(ret == false) { mc->mesher_command_result = MesherCommand::FAILURE_RESULT; return false; } else { mc->mesher_command_result = MesherCommand::SUCCESS_RESULT; return true; } return true; }
void Rendering::VisualBodyFactory::CreateSphereProps() { const float X = .525731112119133606f; const float Z = .850650808352039932f; const int divisionDepth = 4; std::vector<glm::vec3> icoVerts = { glm::vec3(-X, 0, Z), glm::vec3(X, 0, Z), glm::vec3(-X, 0, -Z), glm::vec3(X, 0, -Z), glm::vec3(0, Z, X), glm::vec3(0, Z, -X), glm::vec3(0, -Z, X), glm::vec3(0, -Z, -X), glm::vec3(Z, X, 0), glm::vec3(-Z, X, 0), glm::vec3(Z, -X, 0), glm::vec3(-Z, -X, 0) }; std::vector<unsigned int> icoIndices = { 0, 4, 1, 0, 9, 4, 9, 5, 4, 4, 5, 8, 4, 8, 1, 8, 10, 1, 8, 3, 10, 5, 3, 8, 5, 2, 3, 2, 7, 3, 7, 10, 3, 7, 6, 10, 7, 11, 6, 11, 0, 6, 0, 1, 6, 6, 1, 10, 9, 0, 11, 9, 11 ,2, 9, 2, 5, 7, 2, 11 }; for (int i = 0; i < divisionDepth; ++i) { std::vector<glm::vec3> newVerts; std::vector<unsigned int> newIndices; for (int j = 0; j < icoIndices.size(); j += 3) { SubdivideTriangle(icoVerts[icoIndices[j]], icoVerts[icoIndices[j + 1]], icoVerts[icoIndices[j + 2]], newVerts, newIndices); } icoVerts = newVerts; icoIndices = newIndices; if (i == 0) { ToNFG(icoVerts, icoIndices, "DebugSphere.nfg"); } } for (auto vert : icoVerts) { m_sphereVerts.push_back(Rendering::VertexFormat(vert, Core::DEFAULT_OBJECT_COLOR)); } m_sphereIndices = icoIndices; }