• Advertisement
Sign in to follow this  

PhysX beginer

This topic is 3823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy, i want to cook a .X file mesh in order to simulate phisics on it on my scene. I folow a beginer tutorial from a site and phisics worked for simple objects like sphere/cube etc.. Now..

	 LPD3DXMESH myMesh;	

	 NxTriangleMeshDesc bunnyDesc;


	 Vertex *pVertices = NULL;
	 pTempVertexBuffer->Lock(0, 0, (void**)&pVertices, 0);

	 bunnyDesc.numVertices =         myMesh->GetNumVertices();  
 	 bunnyDesc.numTriangles =        myMesh->GetNumFaces();    
 	 bunnyDesc.pointStrideBytes =    myMesh->GetNumBytesPerVertex(); 
 	 bunnyDesc.triangleStrideBytes = 3*sizeof(float);
 	 bunnyDesc.points = pVertices;  //?
// 	 bunnyDesc.triangles =          //?
// 	 bunnyDesc.flags = 0;           //?

Do i need to clone the mesh to get vertices ? But about the triangles parameter ? And the rest of parameters. Are just the faces ? Please point me in the right direction..

Share this post

Link to post
Share on other sites
there is no need to clone the verts, just itterate through them and take out what you need

vert *ver = NULL;
WORD* Indices;

numOfVerts = (float)mesh->GetNumVertices();
numOfFaces = (float)mesh->GetNumFaces();

mesh->LockVertexBuffer(D3DLOCK_READONLY ,(void**)&ver);
mesh->LockIndexBuffer(D3DLOCK_READONLY ,(LPVOID*)&Indices);

for(DWORD i = 0; i < numOfVerts; i++)

vertices.push_back(v.x );
vertices.push_back(v.y );

all im doing here is adding the x,y,z component to a std:vector


and with the faces, there are 3 verts to a face, so you just obtain them like so

D3DXVECTOR3 *face;
for(DWORD i = 0; i < numOfFaces; i++)
face = new D3DXVECTOR3[3];

face[0] = ver[Indices[3*i+0]].pos;
face[1] = ver[Indices[3*i+1]].pos;
face[2] = ver[Indices[3*i+2]].pos;



this isnt physx specific by the way, i use this method for Newton physics engine

Share this post

Link to post
Share on other sites
Well it seems would not work what i did with PhysX.
I cooked the mesh file, then i loaded it as an actor in the scene:

1. The mesh that is assigned to the actor doesn move at all in the physcs scene (mesh moves ok with other transformation from PhysX, like a cube for example, but not with my cooked data)

2.It seems i have an invisible actor in the scene but actually much larger than the mesh i cooked.
I dont understand why the mesh isnt moving at all. I mean it should at least move in a wrong way if the cooked data is not correct.

The code


NxArray<NxVec3> vertices;
NxArray<NxU32> indice;

int numOfVerts;
int numOfFaces;

NxTriangleMeshDesc bunnyDesc;

//number of faces and vertices
numOfVerts = myMesh->GetNumVertices();
numOfFaces = myMesh->GetNumFaces();

//faces and vertices:
WORD* Indices;

ver = new D3DXVECTOR3[numOfFaces];
Indices = new WORD[numOfFaces];

myMesh->LockVertexBuffer(D3DLOCK_READONLY ,(void**)&ver);
myMesh->LockIndexBuffer(D3DLOCK_READONLY , (LPVOID*)&Indices);

// NxVec3 DXVec3_To_NxVec3(D3DXVECTOR3 DxVector) {
// return NxVec3(DxVector.x, DxVector.y, DxVector.z);
// }

for(DWORD i = 0; i < numOfVerts; i++)



for(DWORD i = 0; i < numOfFaces; i++) {



bunnyDesc.numVertices = vertices.size();
bunnyDesc.numTriangles = indice.size()/3;
bunnyDesc.pointStrideBytes = sizeof(NxVec3);
bunnyDesc.triangleStrideBytes = 3*sizeof(NxU32);

bunnyDesc.points = &vertices[0].x;
bunnyDesc.triangles = &indice[0];
bunnyDesc.flags = 0;

MemoryWriteBuffer buf;
gCooking->NxCookTriangleMesh(bunnyDesc, buf);

NxTriangleMesh* terrainMesh =

NxTriangleMeshShapeDesc terrainMeshDesc;
terrainMeshDesc.meshData = terrainMesh;

NxActorDesc actorDesc;
//a is an actor pointer
a = gScene->createActor(actorDesc);

The mesh is ok, the physcs scene is ok too as far as I have other objects like spheres/cubes etc that works.

Share this post

Link to post
Share on other sites
Later Edit:

I managed to get the cooked data but:
The colission is verry weird for my teapot model. It tryes to colide corecttly but some objects sometimes penetrate it without coliding. Also if Im making a cube it doesnt respond at all at phisics. It just fall thro wall.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement