• Advertisement
Sign in to follow this  

problems with cooking a triangle mesh

This topic is 3493 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

ok This was working in a previous project that I had, and I copied the code to my new project and now its broken. I have seached all over and read the docs but I cant get it to work again. It seems like its just giving me all null numbers. anyways, the code is this. NxActor* GenerateTriangleMeshFromDXMesh(ID3DXMesh* Mesh, NxVec3 pos, int group) { 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; NxInitCooking(); NxTriangleMeshShapeDesc ShapeDesc; if(0) { // Cooking from file bool status = NxCookTriangleMesh(TriMeshDesc, UserStream("c:\\tmp.bin", false)); ShapeDesc.meshData = gPhysicsSDK->createTriangleMesh(UserStream("c:\\tmp.bin", true)); } else { // Cooking from memory MemoryWriteBuffer buf; bool status = NxCookTriangleMesh(TriMeshDesc, buf); ShapeDesc.meshData = gPhysicsSDK->createTriangleMesh(MemoryReadBuffer(buf.data)); } NxActorDesc actorDesc; actorDesc.shapes.pushBack(&ShapeDesc); actorDesc.globalPose.t = pos; // PhysXActor->userData = (void*)1; delete[] verts; delete[] tris; NxActor* NewActor = gScene->createActor(actorDesc); //add one and record the total object count CountNewObject = TOTAL_OBJECTS [ 0 ]; TOTAL_OBJECTS [ 0 ] = CountNewObject + 1; //set the group for the new object if(group == 1) SetActorCollisionGroup( NewActor , groupA); if(group == 2) SetActorCollisionGroup( NewActor , groupB); if(group == 3) SetActorCollisionGroup( NewActor , groupC); return NewActor; } I am by no means a pro at this, but I am trying so I really need some help thanks.

Share this post


Link to post
Share on other sites
Advertisement
The only reason I can think for the above code failing is- the model is large (32k-64k indices). If so, try unsigned short in your IndexBufferStruct.

Share this post


Link to post
Share on other sites
That is not the problem, I've already tried that and It didnt work out. I tried to put in a low poly object and it also fails. Im gonna try to re-build the entire project and cut and paste stuff out and figure out why this will work in one project but not this one...LOL, oh well thats the way it goes lol....thanks.

Share this post


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

  • Advertisement