MeshBuffer help

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Blade
Posts: 9
Joined: Wed Sep 05, 2007 4:07 pm

MeshBuffer help

Post by Blade »

Hi guys, i think i need some help from you. I would like to get alle Vertices and Indices out of a Mesh because i need them for building a physics object:

Code: Select all

ISceneNode* node = smgr->addMeshSceneNode( mesh1, 0, -1, vector3df(0,-5,15), vector3df(0,0,0), vector3df(0.01f,0.01f,0.01f) );
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialTexture( 0, driver->getTexture("media/house/fw12b.jpg") );
IMeshBuffer *buffer = mesh1->getMeshBuffer(0);

int nv = buffer->getVertexCount ();		
int ni = buffer->getIndexCount 	();		
float *pVerts = new float[3*nv];
int *pInds = new int[ni];

if(buffer->getVertexType() == video::EVT_2TCOORDS)
{
irr::video::S3DVertex2TCoords* pv1 = (irr::video::S3DVertex2TCoords*) buffer->getVertices();
irr::u16* pi = (irr::u16*)buffer->getIndices();
int loop;

for (loop=0;i<nv;loop++) {
		pVerts[loop*3+0]=0.01*pv1[loop].Pos.X + 0;
		pVerts[loop*3+1]=0.01*pv1[loop].Pos.Y - 5;
		pVerts[loop*3+2]=0.01*pv1[loop].Pos.Z + 15;
	}
	
	for (loop=0;loop<ni;loop++) {
		pInds[loop]=pi[loop];
	}
}
The Problem is that I cannot access all the Vertices I get from getVertexCount(). My Programm always crashes when I run through more than 7 loops. That means there seem to be not more than 7 Vertices included in my mesh although getVertexCount() says there are more than 900!

Furthermore I don't understand why my Mesh has 23 different MeshBuffers. So does my Mesh have 23 Materials and for every Material 1 MeshBuffer?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

My Programm always crashes when...
I'm pretty sure you want the loop condition to be loop < nv. That could be a problem.
Furthermore I don't understand why my Mesh has 23 different MeshBuffers.
Probably because you have 23 distinct materials or meshes. Either that or you have some submeshes that have to many vertices to fit into the 65536 vertex limit imposed by Irrlicht.
So does my Mesh have 23 Materials and for every Material 1 MeshBuffer?
Yes. If you have 23 materials, there are actually 23 mesh buffers, each with one material. At least this is the norm. There is nothing that stops someone from creating a mesh buffer that shares its material settings with another mesh buffer.
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

vitek wrote:
My Programm always crashes when...
I'm pretty sure you want the loop condition to be loop < nv. That could be a problem.
Oh man! Unbelievable how long I looked at this piece of code and thought "hmm everything looks right" and then I missed something this trivial. ^^

Blade, what kind of mesh is this? 23 distinct mesh buffers is unwanted in most cases and a potential performance hog. This sort of problem can occur when you use a file format that is poorly supported by your modelling tool or you do something funny in the modeller or, of course, you really use this many distinct materials. Better double check your export format and settings.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

However, any proper compiler will warn about this code, if not error. i is not defined anywhere, and I doubt that it is allowed within a comparison.
Blade
Posts: 9
Joined: Wed Sep 05, 2007 4:07 pm

Post by Blade »

Saturn wrote: Oh man! Unbelievable how long I looked at this piece of code and thought "hmm everything looks right" and then I missed something this trivial. ^^
You're right. Perhaps i should have looked through it this morning again before i postet this thread in the forum here. I'm sorry of disturbing your time.
Saturn wrote: Blade, what kind of mesh is this? 23 distinct mesh buffers is unwanted in most cases and a potential performance hog. This sort of problem can occur when you use a file format that is poorly supported by your modelling tool or you do something funny in the modeller or, of course, you really use this many distinct materials. Better double check your export format and settings.
i simply tried the house.3ds mesh example that comes with irrEdit
Post Reply