getting information about the verices of a mesh

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
hansmbakker
Posts: 41
Joined: Mon Feb 16, 2004 7:37 pm

getting information about the verices of a mesh

Post by hansmbakker »

Hi,

for a newton script (NewtonCreateConvexHull) I'd like to know how to write a script that does the following:

-put all the vertices of a mesh in an array
-put the amount of vertices of the mesh in an float

there is something about in in the newton tutorial but i don't exactly understand it.

Thank you!!
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Code: Select all

bool AddMeshToNewtonCollision ( newton::NewtonCollision* collision, scene::IMesh* mesh )
{
	int						bufferCount		= 0;
	int						i				= 0;
	int						j				= 0;
	int						v1i				= 0;
	int						v2i				= 0;
	int						v3i				= 0;
	float					mag				= 0.0f;
	scene::IMeshBuffer*		mb				= NULL;
	video::S3DVertex*		mb_vertices		= NULL;
	u16*					mb_indices		= NULL;
	core::vector3df			vArray[3], e0, e1, area;

	newton::NewtonTreeCollisionBeginBuild ( collision );

	bufferCount = mesh->getMeshBufferCount ( );

	for ( i = 0; i < bufferCount; i++ )
	{
		mb = mesh->getMeshBuffer ( i );
		mb_vertices = (video::S3DVertex*)mb->getVertices ( );
		mb_indices = mb->getIndices ( );

		// add each triangle from the mesh
		for ( j = 0; j < mb->getIndexCount ( ); j += 3 )
		{
			v1i = mb_indices[j];
			v2i = mb_indices[j + 1];
			v3i = mb_indices[j + 2];

			vArray[0] = mb_vertices[v1i].Pos;
			vArray[1] = mb_vertices[v2i].Pos;
			vArray[2] = mb_vertices[v3i].Pos;

			e0 = vArray[1] - vArray[0];
			e1 = vArray[2] - vArray[0];

			area = e0.crossProduct ( e1 );
			mag = area.dotProduct ( area );

			if ( mag > -0.00001 )
				newton::NewtonTreeCollisionAddFace ( collision, 3, &vArray[0].X, 12, 1 );
		}
	}

	newton::NewtonTreeCollisionEndBuild ( collision, 1 );

	return true;
}
hansmbakker
Posts: 41
Joined: Mon Feb 16, 2004 7:37 pm

Post by hansmbakker »

thank you!

but actionally i need each vertex only one time -> i do not neet triangles but vertices

i need them for NewtonCreateConvexHull

there you need an array of the vertices and in this way you get each vertex three times, i think

i'm not so good at working at this low-level working with vertices...
Post Reply