leon.dong Posted December 6, 2023 Share Posted December 6, 2023 (edited) My code is like below. Unigine::MeshPtr myUnigineMesh = Unigine::Mesh::create(); for(int i=0;i<100;i++) { myUnigineMesh->addVertex(Unigine::Math::vec3(pos.x, pos.y, pos.z), surfaceIndex); } The vertex info have been added successfully. My question is how to add Index like sample code which in your offical doc. myUnigineMesh->addIndex(0, surfaceIndex); myUnigineMesh->addIndex(1, surfaceIndex); myUnigineMesh->addIndex(2, surfaceIndex); myUnigineMesh->addIndex(3, surfaceIndex); myUnigineMesh->addIndex(2, surfaceIndex); myUnigineMesh->addIndex(1, surfaceIndex); I can run the sample code successfully. Since the sample code only have 4 vertex , however my scenario has more than 10 vertex , is there any easy way to automatically calculate the index or indices info? Simply searched doc no useful, so looking forward to help from forum. Thanks for any advice. Edited December 6, 2023 by leon.dong Link to comment
leon.dong Posted December 6, 2023 Author Share Posted December 6, 2023 Or does Unigine has some methods to auto generte the index info depend on these vertext info ? Link to comment
silent Posted December 7, 2023 Share Posted December 7, 2023 You can call Mesh::createIndices() to generate indices automatically. Something like that: Unigine::MeshPtr m = Unigine::Mesh::create(); int s = m->addSurface("surface"); m->addVertex(Unigine::Math::vec3(0.0f, 0.0f, 0.0f), s); m->addVertex(Unigine::Math::vec3(1.0f, 1.0f, 0.0f), s); m->addVertex(Unigine::Math::vec3(0.0f, 1.0f, 0.0f), s); m->addVertex(Unigine::Math::vec3(0.0f, 0.0f, 0.0f), s); m->addVertex(Unigine::Math::vec3(1.0f, 0.0f, 0.0f), s); m->addVertex(Unigine::Math::vec3(1.0f, 1.0f, 0.0f), s); m->createIndices(); m->createTangents(); m->createBounds(); How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
leon.dong Posted December 7, 2023 Author Share Posted December 7, 2023 Thanks silent. very helpful. I checked my codes and data. the difference is , your sample code can run since the vertext info is the pattern of forming triangles However my vertex information is a geometry edge vertex information , so call createIndices will crash. Is there any solution for that kind of vertex ? Thanks again. Link to comment
silent Posted December 8, 2023 Share Posted December 8, 2023 Unfortunately, createIndices()can only create them if you provide vertices in a specific format (as shown in previous message). How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
leon.dong Posted December 11, 2023 Author Share Posted December 11, 2023 I tried below method, it could help a lot . void A::GetNewVertices(std::vector<Unigine::Math::vec3> inVertex, std::vector<Unigine::Math::vec3>& outVertex) { //input pos std::vector<KernelTest::Point_3> points; for (size_t i = 0; i < inVertex.size(); i++) { points.push_back(KernelTest::Point_3(inVertex[i].x, inVertex[i].y, inVertex[i].z)); } // Delaunay3D deTriangles(points.begin(), points.end()); //// for (Delaunay3D::Finite_facets_iterator fit = deTriangles.finite_facets_begin(); fit != deTriangles.finite_facets_end(); ++fit) { Delaunay3D::Facet face = *fit; std::cout << deTriangles.triangle(face) << std::endl; // KernelTest::Point_3 p1 = face.first->vertex((face.second + 1) % 4)->point(); KernelTest::Point_3 p2 = face.first->vertex((face.second + 2) % 4)->point(); KernelTest::Point_3 p3 = face.first->vertex((face.second + 3) % 4)->point(); //output outVertex.push_back(Unigine::Math::vec3(p1.x(), p1.y(), p1.z())); outVertex.push_back(Unigine::Math::vec3(p2.x(), p2.y(), p2.z())); outVertex.push_back(Unigine::Math::vec3(p3.x(), p3.y(), p3.z())); } } Link to comment
leon.dong Posted December 11, 2023 Author Share Posted December 11, 2023 Is Unigine clockwise or anti-clockwise when add vertex to surface ? Link to comment
silent Posted December 11, 2023 Share Posted December 11, 2023 Yes, counter-clockwise is expected vertex order in surfaces of the mesh. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
leon.dong Posted December 11, 2023 Author Share Posted December 11, 2023 (edited) Thanks silent. very efficient. Edited December 11, 2023 by leon.dong Link to comment
Recommended Posts