TerrainSceneNode - get triangles

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
zielin
Posts: 20
Joined: Thu Aug 02, 2012 5:45 am
Location: Poland

TerrainSceneNode - get triangles

Post by zielin »

Hello,

I see that terrain scene node generated via heightmap differs from other nodes because indices are empty. I try to get all triangles used in terrain to pass them into bullet mesh shape, but I can't find any proper way to do it. I'll be grateful if somoene tell me how to generate triangles for terrain scene node. Here is fragment of code I wrote, but it doesn't work. Second loop never runs, because indice count is zero.

Code: Select all

 
btCollisionShape * createShape(const irr::scene::ISceneNode * pNode)
{
    scene::ITerrainSceneNode* pTerrain = (scene::ITerrainSceneNode*) pNode;
    scene::IMesh* mesh = pTerrain->getMesh();
    btTriangleMesh* btMesh = new btTriangleMesh();
 
    for (int bIndex = 0; bIndex < mesh->getMeshBufferCount(); ++bIndex)
    {
        // Extracting all meshes from TerrainNode
        scene::IMeshBuffer* irrMesh = mesh->getMeshBuffer(bIndex);
        
        auto mb_vertices = (video::S3DVertex2TCoords*) irrMesh->getVertices();
        
        // now irrMesh->getIndexCount() returns 0
        // mb_vertices is filled properly, but nothing is known about triangles
        
        // nullptr
        u16* indices = (u16*) irrMesh->getIndices();
 
        for (int i = 0; i < irrMesh->getIndexCount(); i += 3)
        {
            s32 index = indices[i];
            btMesh->addTriangle(bulletVector(mb_vertices[index].Pos), bulletVector(mb_vertices[index + 1].Pos), bulletVector(mb_vertices[index + 2].Pos));
        }
    }
 
    pShape = new btBvhTriangleMeshShape(btMesh, true);
}
}
zielin
Posts: 20
Joined: Thu Aug 02, 2012 5:45 am
Location: Poland

Re: TerrainSceneNode - get triangles

Post by zielin »

Thanks, I'll check it.
Post Reply