Jump to content

How to addIndices after added serveral vertex


photo

Recommended Posts

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 by leon.dong
Link to comment

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:

Link to comment

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

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
×
×
  • Create New...