PhysX and IrrLicht

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
Serg88
Posts: 30
Joined: Mon Oct 19, 2009 5:52 pm
Location: Moscow/Russia

PhysX and IrrLicht

Post by Serg88 »

I write same code for converting terrain to NxActor, all whas perfect, but when i trying convert mash of model, my programm crashed
data format is like the same, but why it`s happens?

Code: Select all

NxActor* Convert(scene::IMeshBuffer *mb)
{
	NxBodyDesc  bodyDesc;
	NxActorDesc actorDesc;
	NxTriangleMeshDesc* concaveDesc = NULL;

	video::S3DVertex *irrverts = (video::S3DVertex*)mb->getVertices();
	NxVec3 *verts = new NxVec3[mb->getVertexCount()];
		//={	NxVec3(-boxDim.x, -boxDim.y, -boxDim.z)	}; // data format

	for(u32 i=0;i<mb->getVertexCount();i++)
		verts[i] = NxVec3(irrverts[i].Pos.X,irrverts[i].Pos.Y,irrverts[i].Pos.Z);
	
	NxU32 *indices = (NxU32*)mb->getIndices();
		//={ 1,2,3,}; by 3 // data format

	// Create descriptor for triangle mesh
	if (!concaveDesc)
	{
		concaveDesc		= new NxTriangleMeshDesc();
		assert(concaveDesc);
	}	
	
	concaveDesc->numVertices			= 16;
	concaveDesc->pointStrideBytes		= sizeof(NxVec3);
	concaveDesc->points					= verts;
	concaveDesc->numTriangles			= mb->getVertexCount();
	concaveDesc->triangles				= indices;
	concaveDesc->triangleStrideBytes	= 3 * sizeof(NxU32);
	concaveDesc->flags					= 0;
	assert(concaveDesc->isValid());

	// The actor has one shape, a triangle mesh
	NxTriangleMeshShapeDesc concaveShapeDesc;
	concaveShapeDesc.localPose.t = NxVec3(0,0,0);//h.y
	concaveShapeDesc.userData	 = concaveDesc;
	
	NxInitCooking();
	MemoryWriteBuffer buf;
	NxTriangleMesh * pMesh = NULL;
	
	printf("before_ln181\n");
	bool status = NxCookTriangleMesh(*concaveDesc, buf); // at this line my programm is crash
	printf("after_ln183\n");

	assert(status);
	pMesh = gps->createTriangleMesh(MemoryReadBuffer(buf.data));
	assert(pMesh);
	concaveShapeDesc.meshData = pMesh;
	NxCloseCooking();

	if (pMesh)
	{
		// Save mesh in userData for drawing
		pMesh->saveToDesc(*concaveDesc);
		//

		assert(concaveShapeDesc.isValid());
		actorDesc.shapes.pushBack(&concaveShapeDesc);
		//Dynamic triangle mesh don't be supported anymore. So body = NULL
		actorDesc.body			= NULL;
		actorDesc.globalPose.t	= NxVec3(-6.0f, 0.0f, 0.0f);
		assert(actorDesc.isValid());
		NxActor *pActor = scn->createActor(actorDesc);
		assert(pActor);
		return pActor;	
	}
	return NULL;
}
Incidental question:
At picture my mesh buffer is red, why?
when function was started, all been correct

Image

PS this code was based on Lesson102_Mesh_Shapes.doc from PhysX Training Programm
from Russia with love :))))
Serg88
Posts: 30
Joined: Mon Oct 19, 2009 5:52 pm
Location: Moscow/Russia

Post by Serg88 »

P.S. Problem Solved.
from Russia with love :))))
Post Reply