Tokamak TerrainMesh grab Terrain Mesh Buffer

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
MACARRAUM
Posts: 40
Joined: Sun Nov 28, 2004 8:52 pm
Location: Brazil

Tokamak TerrainMesh grab Terrain Mesh Buffer

Post by MACARRAUM »

Hi,
I am making my game using Tokamak for physics and I am with difficulty to do with that the tokamak creates a land starting from his mesh-buffer. Somebody would know how to tell me a solution for this.

Here this my current integration class:

EDITED: This code work 100% correct!!

Code: Select all

// Parte de Terreno ( Irrlicht + Tokamak )

typedef class Criar_Terreno* Terreno;

class Criar_Terreno
{
private:
	
	IAnimatedMesh* mesh;
	
	ISceneNode* node;

	vector3df posicao;

public:

	Criar_Terreno( float x,float y,float z )
	{
		posicao.X = x;
		posicao.Y = y;
		posicao.Z = z;

		mesh = smgr->getMesh("plataforma.ms3d");
		node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
		
		if(node)
		{
		node->setMaterialTexture ( 0, driver->getTexture ( "plataforma.bmp" ) );
		node->setMaterialFlag ( video::EMF_LIGHTING, false );
		node->setMaterialFlag ( video::EMF_WIREFRAME, false );
		node->setPosition( posicao );
		}
	}
	
	virtual void Integrar_Tokamak( void )
	{
		int i, j, ci, cif, cv;
                    ci = 0; cif = 0; cv = 0;
					
					neTriangleMesh triMesh;
                    
                    int indexcount = 0;
                    int vertexcount = 0;
                    int count = mesh->getMesh(0)->getMeshBufferCount();
                    
                    for(i = 0; i < count; i++)
                    {
                          IMeshBuffer * mb = mesh->getMesh(0)->getMeshBuffer(i);
                          indexcount += mb->getIndexCount();
                          vertexcount += mb->getVertexCount();
                    }

					triMesh.vertexCount = vertexcount;
					triMesh.triangleCount = indexcount / 3;
					
					neV3 * vertices = new neV3[vertexcount];
                    int * indices = new int[indexcount];

					neTriangle * tri = new neTriangle[triMesh.triangleCount];
					                  
                    for(i = 0; i < (mesh->getMesh(0)->getMeshBufferCount()); i++)
                    {
                          IMeshBuffer * mb = mesh->getMesh(0)->getMeshBuffer(i);
						  irr::u16 * mb_indices = mb->getIndices();
                                                    
                          if(mb->getVertexType()==EVT_STANDARD)
                          {
                                S3DVertex * mb_vertices = (S3DVertex*)mb->getVertices();
                                for(j=0; j< mb->getVertexCount();j++)
                                {
                                   vertices[cv].v[0] = mb_vertices[j].Pos.X;
                                   vertices[cv].v[1] = mb_vertices[j].Pos.Y;
                                   vertices[cv].v[2] = mb_vertices[j].Pos.Z;
                                   cv++;
                                }
                          }
                          else if(mb->getVertexType()==EVT_2TCOORDS)
                          {
                               S3DVertex2TCoords * mb_vertices = (S3DVertex2TCoords*)mb->getVertices();
                               for(j=0;j<mb->getVertexCount();j++)
                               {
                                   vertices[cv].v[0] = mb_vertices[j].Pos.X;
                                   vertices[cv].v[1] = mb_vertices[j].Pos.Y;
                                   vertices[cv].v[2] = mb_vertices[j].Pos.Z;
                                   cv++;
                               }
                          }

						  for(j = 0; j < mb->getIndexCount(); j+=3)
                          {
							  tri[ci].indices[2] = cif + mb_indices[j + 0];
							  tri[ci].indices[1] = cif + mb_indices[j + 1];
							  tri[ci].indices[0] = cif + mb_indices[j + 2];
							  tri[ci].materialID = 0;
							  tri[ci].flag = neTriangle::NE_TRI_TRIANGLE;
                              ci++;
                          }
						  cif = cif + mb->getVertexCount();
                    }

					triMesh.vertices = vertices;
					triMesh.triangles = tri;
					
					simulador->SetTerrainMesh(&triMesh);

	}
};
Last edited by MACARRAUM on Fri Jul 08, 2005 1:34 am, edited 1 time in total.
Bot_Builder
Posts: 23
Joined: Thu Apr 14, 2005 6:59 pm
Location: Bushland

Post by Bot_Builder »

Well, you're not setting the vertice's position. If the stuff that's comment out doesn't work, ensure its in teh proper format and if not, convert it.
ImageXP SP2, AMD Athlon 64 3500+, 1GB HyperX RAM, Radeon X700 Pro (PCI-e), 120GB SATA drive :)
MACARRAUM
Posts: 40
Joined: Sun Nov 28, 2004 8:52 pm
Location: Brazil

Post by MACARRAUM »

Hi guys, i found solution for TOKAMAK triMesh !!!!!!

Code: Select all

// Parte de Terreno ( Irrlicht + Tokamak )

typedef class Criar_Terreno* Terreno;

class Criar_Terreno
{
private:
	
	IAnimatedMesh* mesh;
	
	ISceneNode* node;

	vector3df posicao;

public:

	Criar_Terreno( float x,float y,float z )
	{
		posicao.X = x;
		posicao.Y = y;
		posicao.Z = z;

		mesh = smgr->getMesh("plataforma.ms3d");
		node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
		
		if(node)
		{
		node->setMaterialTexture ( 0, driver->getTexture ( "plataforma.bmp" ) );
		node->setMaterialFlag ( video::EMF_LIGHTING, false );
		node->setMaterialFlag ( video::EMF_WIREFRAME, false );
		node->setPosition( posicao );
		}
	}
	
	virtual void Integrar_Tokamak( void )
	{
		int i, j, ci, cif, cv;
                    ci = 0; cif = 0; cv = 0;
					
					neTriangleMesh triMesh;
                    
                    int indexcount = 0;
                    int vertexcount = 0;
                    int count = mesh->getMesh(0)->getMeshBufferCount();
                    
                    for(i = 0; i < count; i++)
                    {
                          IMeshBuffer * mb = mesh->getMesh(0)->getMeshBuffer(i);
                          indexcount += mb->getIndexCount();
                          vertexcount += mb->getVertexCount();
                    }

					triMesh.vertexCount = vertexcount;
					triMesh.triangleCount = indexcount / 3;
					
					neV3 * vertices = new neV3[vertexcount];
                    int * indices = new int[indexcount];

					neTriangle * tri = new neTriangle[triMesh.triangleCount];
					                  
                    for(i = 0; i < (mesh->getMesh(0)->getMeshBufferCount()); i++)
                    {
                          IMeshBuffer * mb = mesh->getMesh(0)->getMeshBuffer(i);
						  irr::u16 * mb_indices = mb->getIndices();
                                                    
                          if(mb->getVertexType()==EVT_STANDARD)
                          {
                                S3DVertex * mb_vertices = (S3DVertex*)mb->getVertices();
                                for(j=0; j< mb->getVertexCount();j++)
                                {
                                   vertices[cv].v[0] = mb_vertices[j].Pos.X;
                                   vertices[cv].v[1] = mb_vertices[j].Pos.Y;
                                   vertices[cv].v[2] = mb_vertices[j].Pos.Z;
                                   cv++;
                                }
                          }
                          else if(mb->getVertexType()==EVT_2TCOORDS)
                          {
                               S3DVertex2TCoords * mb_vertices = (S3DVertex2TCoords*)mb->getVertices();
                               for(j=0;j<mb->getVertexCount();j++)
                               {
                                   vertices[cv].v[0] = mb_vertices[j].Pos.X;
                                   vertices[cv].v[1] = mb_vertices[j].Pos.Y;
                                   vertices[cv].v[2] = mb_vertices[j].Pos.Z;
                                   cv++;
                               }
                          }

						  for(j = 0; j < mb->getIndexCount(); j+=3)
                          {
							  tri[ci].indices[2] = cif + mb_indices[j + 0];
							  tri[ci].indices[1] = cif + mb_indices[j + 1];
							  tri[ci].indices[0] = cif + mb_indices[j + 2];
							  tri[ci].materialID = 0;
							  tri[ci].flag = neTriangle::NE_TRI_TRIANGLE;
                              ci++;
                          }
						  cif = cif + mb->getVertexCount();
                    }

					triMesh.vertices = vertices;
					triMesh.triangles = tri;
					
					simulador->SetTerrainMesh(&triMesh);

	}
};
Post Reply