Jump to content
  • Advertisement
Sign in to follow this  
Azzazelus_13

PhysX beginer

This topic is 4010 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;


	

	 LPDIRECT3DVERTEXBUFFER9 pTempVertexBuffer;
	 myMesh->GetVertexBuffer(&pTempVertexBuffer);
 
	 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
Advertisement
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 );
vertices.push_back(v.z);
}

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

edit:

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;


faces.push_back(face);

}

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

D3DXLoadMeshFromX(L"C:\\bila.X",
D3DXMESH_SYSTEMMEM|D3DXMESH_32BIT,
D3DDevice,
NULL,
NULL,
NULL,
NULL,
&myMesh);




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:
D3DXVECTOR3 *ver = NULL;
WORD* Indices;

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


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



// THE FUNCTION FOR D3DXVECTOR TO NXVECTOR3
// NxVec3 DXVec3_To_NxVec3(D3DXVECTOR3 DxVector) {
// return NxVec3(DxVector.x, DxVector.y, DxVector.z);
// }


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

{
vertices.push_back(DXVec3_To_NxVec3(ver));

}




for(DWORD i = 0; i < numOfFaces; i++) {
indice.push_back(Indices);

}

myMesh->UnlockVertexBuffer();


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 =
gScene->getPhysicsSDK().createTriangleMesh(MemoryReadBuffer(buf.data));



NxTriangleMeshShapeDesc terrainMeshDesc;
terrainMeshDesc.meshData = terrainMesh;


NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&terrainMeshDesc);
//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.
http://img216.imageshack.us/img216/420/wtqs0.jpg

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!