• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Directx Mesh into PhysX Mesh

6 posts in this topic

Yes I know there is a similar topic but this one is different. I have managed to load a mesh into PhysX. I know the mesh is fine, because i render it with directx at the same time, and yes it's triangulated, and dead simple (well my most recent one is). I have tried altering some of the code to change the order the vertices are in putted, i.e. shifting them forward and backward by one in the vector. This for some reason created an identical mesh in PhysX (checked with remote debugger). Here is the code i use.
std::vector<float> GetVertices(LPD3DXMESH g_pMesh)
std::vector<float> vertices;
DWORD stride =  D3DXGetFVFVertexSize(g_pMesh->GetFVF());
BYTE* vbptr = NULL;
g_pMesh->LockVertexBuffer(0, (LPVOID*)&vbptr);
int ii = -1;
for(unsigned int i = 0; i < g_pMesh->GetNumVertices(); i++)
D3DXVECTOR3* pos = (D3DXVECTOR3*)vbptr;
vbptr += stride;
return vertices;

std::vector<short> GetIndices(LPD3DXMESH     g_pMesh)
//LPVOID* ppData;
DWORD stride = sizeof(short);
BYTE* ibptr = NULL;
short* indices = new short[(g_pMesh)->GetNumFaces() * 3];
std::vector<short> copy;
(g_pMesh)->LockIndexBuffer(0, (LPVOID*)&indices);
for(unsigned int i = 0; i < (g_pMesh)->GetNumFaces() * 3; i++)
return copy;

NxActor* GenTriangleMesh(NxVec3 pos, std::vector<short> indices, std::vector<float> vertices )
int NumVerticies = vertices.size() / 3;
int NumTriangles = indices.size() / 3;
//Create pointer for vertices
NxVec3* verts = new NxVec3[NumVerticies];
int ii = -1;
for(int i = 0; i < NumVerticies; i++)

verts[i].x = vertices[ii];
verts[i].y = vertices[++ii];
verts[i].z = vertices[++ii];
//Create pointer for indices
NxU16 *tris = new NxU16[indices.size()];
for(int i = indices.size() - 1; i >= 0; --i)
tris[i] = i;
// Build physical model
NxTriangleMeshDesc TriMeshDesc;
TriMeshDesc.numVertices = NumVerticies;
TriMeshDesc.numTriangles = NumTriangles;
TriMeshDesc.pointStrideBytes = sizeof(NxVec3);
TriMeshDesc.triangleStrideBytes = 3*sizeof(NxU16);
TriMeshDesc.points = verts;
TriMeshDesc.triangles = tris;
TriMeshDesc.flags = NX_MF_16_BIT_INDICES ;//| NX_MF_FLIPNORMALS  ;
NxTriangleMeshShapeDesc ShapeDesc;
// Cooking from memory
MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(TriMeshDesc, buf);
ShapeDesc.meshData = gPhysicsSDK->createTriangleMesh(MemoryReadBuffer(buf.data));
NxActorDesc actorDesc;
actorDesc.globalPose.t = pos;

NxActor* act = gScene->createActor(actorDesc);
delete[] verts;
delete[] tris;
return act;

Here are the images of the problem: The direct x ones show what it is like at render time and how the meshes should be, the PhysX remote Debugger shows otherwise. As you can see triangles are missing top and bottom, it seems systematic but i don't know how to fix it. Please provide me with some code to fix this or some examples as i have no idea what to do or where to start. Thanks JamesCobras

Share this post

Link to post
Share on other sites
Hi, As far i can see, your box are wrong from the source, remember, to draw
the primitives directx uses triangles, not quads or some, so, check on your
3d modeling software that, make the mesh only with triangles, no quads, no
five sides polys, maybe your model have some of those, then when directx
triangulates the mesh screw all. Maybe could be that,

Share this post

Link to post
Share on other sites
Sorry i obviously wasn't clear.
The direct x model renders perfectly in my app when rendered but the collision mesh is not generated properly from the .x mesh file.

It is in this forum because this is similar to parse an .x file. it seems that it is missing some of the faces, but i'm not sure how to code it to fix it.

The mesh is fine and renders well just it is not parsed correctly into PhysX, that is where i need the help, i'm nearly there but not quite.

Share this post

Link to post
Share on other sites
Oh, well, my code to obtain the mesh info:

BYTE *ptr = NULL;
int numIndices;
DWORD numVerts;
DWORD numFaces;
DWORD fvf;
DWORD vertSize;
int count;

LM = D3DXLoadMeshFromX(ThisMeshDesc.meshfile,D3DXMESH_MANAGED,pDevice,NULL,NULL,NULL,NULL,&mesh);

if(LM != D3D_OK)
MessageBox(0,ThisMeshDesc.meshfile,"Can't Find:",0);

count = 0;
mesh->LockVertexBuffer(0, (LPVOID*)&ptr);
numvertex = numVerts = mesh->GetNumVertices();
numfaces = numFaces = mesh->GetNumFaces();
fvf = mesh->GetFVF();
vertSize = D3DXGetFVFVertexSize(fvf);
verts = new NxVec3[numVerts];

for(DWORD i=0;i<numVerts;i++)
NxVec3 *vPtr=(NxVec3 *) ptr;
verts[i].x = vPtr->x;
verts[i].y = vPtr->y;
verts[i].z = vPtr->z;

mesh->LockIndexBuffer ( D3DLOCK_READONLY, (VOID**)&lpIB);
mesh->GetIndexBuffer( &lpIndexBuffer );
lpIndexBuffer->GetDesc( &ibdesc );

if(ibdesc.Format == D3DFMT_INDEX32)
{numIndices = ibdesc.Size / sizeof(DWORD);
tri32 = new NxU32[numFaces*3];
b_32 = true; }
else{numIndices = ibdesc.Size / sizeof(WORD);
tri16 = new NxU16[numFaces*3];
b_32 = false;}

for(int i=0; i<numIndices; i += 3 )
if (ibdesc.Format == D3DFMT_INDEX32 )
{ tri32[count] = ((DWORD*)lpIB)[ i ];
tri32[count] = ((DWORD*)lpIB)[ i+1 ];
tri32[count] = ((DWORD*)lpIB)[ i+2 ];
{ tri16[count] = ((WORD*)lpIB)[ i ];
tri16[count] = ((WORD*)lpIB)[ i+1 ];
tri16[count] = ((WORD*)lpIB)[ i+2 ];


I hope that can help a bit

Share this post

Link to post
Share on other sites
unfortunately that didn't work, maybe i integrated it wrong do you have the rest of the code?

Just that it looked like nothing was passed to PhysX.

Grrrr, this is starting to irritate me. i thought i know how to do this, but it just is too cryptic and the api really isn't much help...

Maybe i should export to a different format to cook file and just render with .x files but a better solution is preferred.

Help please, i'm really getting disparate, has anyone gone about this a different way?


Share this post

Link to post
Share on other sites
For cook the mesh:

NxBodyDesc bodyDesc;
NxConvexMeshDesc temp_convexDesc;
temp_convexDesc.numVertices = Mesh->numvertex;
temp_convexDesc.pointStrideBytes = sizeof(NxVec3);
temp_convexDesc.points = Mesh->verts;
temp_convexDesc.flags = NX_CF_COMPUTE_CONVEX;
bodyDesc.solverIterationCount = 5;

NxConvexShapeDesc convexShapeDesc;
convexShapeDesc.localPose.t = NxVec3(0,0,0);
convexShapeDesc.mass = m_mass;
convexShapeDesc.density = .001;

MemoryWriteBuffer buf;
bool status = NxCookConvexMesh(temp_convexDesc,buf);

MemoryReadBuffer readBuffer(buf.data);
convexShapeDesc.meshData = PhysicsSDK->createConvexMesh(readBuffer);

NxActorDesc actorDesc;

bodyDesc.linearVelocity = m_InitialVelocity;
actorDesc.body = &bodyDesc;
actorDesc.density = 1.0;

actorDesc.globalPose.t = m_InitialPosition;
actorDesc.group = m_group;
actorDesc.userData = obj;
actorDesc.contactReportFlags = NX_NOTIFY_ALL;

PhysXActor = Scene->createActor(actorDesc);

I hope that can help, if you still have the problem, send me MP.

Share this post

Link to post
Share on other sites
Thanks Mate i had it close to that, just passed the wrong stuff in the wrong places, i think it was the stride amount that i got wrong, but thanks mate, collision, working perfectly.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0