Page 1 of 1

Tokamak TerrainMesh grab Terrain Mesh Buffer

Posted: Wed May 18, 2005 2:17 pm
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);

	}
};

Posted: Fri May 20, 2005 11:31 pm
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.

Posted: Thu Jul 07, 2005 6:56 pm
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);

	}
};