I want cook .x file to NxTriangleMesh,my function is following:
void GenerateTriangleMeshFromDXMesh(ID3DXMesh* Mesh, NxActor* &PhysXActor, NxVec3 pos)
{
typedef struct {
D3DXVECTOR3 VertexPos;
D3DXVECTOR3 Normal;
D3DXVECTOR2 TexCoord;
} Mesh_FVF;
//Used to copy indices
typedef struct {
short IBNumber[3];
} IndexBufferStruct;
int NumVerticies = Mesh->GetNumVertices();
int NumTriangles = Mesh->GetNumFaces();
DWORD FVFSize = D3DXGetFVFVertexSize(Mesh->GetFVF());
//Create pointer for vertices
NxVec3* verts = new NxVec3[NumVerticies];
char *DXMeshPtr;
Mesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&DXMeshPtr);
for(int i = 0; i < NumVerticies; i++)
{
Mesh_FVF *DXMeshFVF = (Mesh_FVF*)DXMeshPtr;
verts = NxVec3(DXMeshFVF->VertexPos.x, DXMeshFVF->VertexPos.y, DXMeshFVF->VertexPos.z);
DXMeshPtr += FVFSize;
}
Mesh->UnlockVertexBuffer();
//Create pointer for indices
IndexBufferStruct *tris = new IndexBufferStruct[NumTriangles];
IndexBufferStruct *DXMeshIBPtr;
Mesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&DXMeshIBPtr);
for(int NumInd = 0; NumInd < NumTriangles; NumInd++)
{
tris[NumInd].IBNumber[0] = DXMeshIBPtr[NumInd].IBNumber[0];
tris[NumInd].IBNumber[1] = DXMeshIBPtr[NumInd].IBNumber[1];
tris[NumInd].IBNumber[2] = DXMeshIBPtr[NumInd].IBNumber[2];
}
Mesh->UnlockIndexBuffer();
// Build physical model
NxTriangleMeshDesc TriMeshDesc;
TriMeshDesc.numVertices = NumVerticies;
TriMeshDesc.numTriangles = NumTriangles;
TriMeshDesc.pointStrideBytes = sizeof(NxVec3);
TriMeshDesc.triangleStrideBytes = 3*sizeof(short);
TriMeshDesc.points = verts;
TriMeshDesc.triangles = tris;
TriMeshDesc.flags = NX_MF_16_BIT_INDICES;
NxTriangleMeshShapeDesc ShapeDesc;
{
// Cooking from memory
MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(TriMeshDesc, buf); //it return true;
ShapeDesc.meshData = gPhysicsSDK->createTriangleMesh(MemoryReadBuffer(buf.data));//it return 0,ShapeDesc.meshData == 0x00000000,why?
}
NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&ShapeDesc);
actorDesc.globalPose.t = pos;
PhysXActor = gScene->createActor(actorDesc);
PhysXActor->userData = (void*)1;
delete[] verts;
delete[] tris;
}
I try another means:
Then I create a triangle and set the vertex data,set the index data ,I want cook the triangle into NxTriangleMesh,the codes are following:
//set the vertex data
NxReal* verts = new NxReal[9];
for(int i=0; i<9;i++)
{
verts = i;
}
//set the index data
DWORD* index = new DWORD[3];
index[0] = 0;
index[1] = 1;
index[2] = 2;
// Build physical model
NxTriangleMeshDesc TriMeshDesc;
TriMeshDesc.numVertices = 3;
TriMeshDesc.numTriangles = 1;
TriMeshDesc.pointStrideBytes = sizeof(NxVec3);
TriMeshDesc.triangleStrideBytes = 3*sizeof(DWORD);
TriMeshDesc.points = verts;
TriMeshDesc.triangles = index;
TriMeshDesc.flags = 0ï¼›
if(!TriMeshDesc.isValid())
{
return;
}
NxTriangleMeshShapeDesc ShapeDesc;
// Cooking from memory
NxInitCooking();
MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(TriMeshDesc, buf);//return false,why?
MemoryReadBuffer readBuffer(buf.data);
ShapeDesc.meshData = gPhysicsSDK->createTriangleMesh(readBuffer);
help: How to cook .x file to NxTriangleMesh by physX engine?
-
pyhmail
- Gnoblar
- Posts: 6
- Joined: Mon Mar 17, 2008 6:39 am
- jacmoe
- OGRE Retired Moderator

- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Not related to Ogre at all. /* moving */
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- betajaen
- OGRE Moderator

- Posts: 3447
- Joined: Mon Jul 18, 2005 4:15 pm
- Location: Wales, UK
- x 58
- Contact:
- sinbad
- OGRE Retired Team Member

- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 67
- Contact:
