Hi All,
I have been a regular viewer of this forum when encountering issues with my ventures into Havok Physics, and usually find the solution, however I'm having issues with something that I just can't seem so resolve.
I'm working on a project that is using Havok Physics and Direct3D9, and have got a number of things working, but now I am trying to import models and reached a snag. I don't have 3dsmax or Maya meaning I can't create .hkx files, so what I'm attempting to do is convert the 3D model that I can import with Direct3D into a hkpExtendedMeshShape so that the physical world will match the real world.
(Click for fullimage)
As you can see in the above image, the cube I'm rendering does not look the same when imported into Havok, and I can't think why. I've been spending ages on this and only just managed to get this far. I tried the same on the terrain, but that had even more issues (but that's perhaps down to it not having triangulated surfaces, which the cube does). Here is the code:
MeshVertex* verts = 0;
meshBlock->LockVertexBuffer(0, (void**)&verts);
int numVertices = meshBlock->GetNumVertices();
float* vertices = new float[numVertices * 3];
for(int i = 0; i < numVertices; i++)
{
int vertex = i * 3;
vertices[vertex + 0] = verts[i].position.x;
vertices[vertex + 1] = verts[i].position.y;
vertices[vertex + 2] = verts[i].position.z;
}
void* indices = 0;
meshBlock->LockIndexBuffer(0, (void**)&indices);
int numTriangles = meshBlock->GetNumFaces();
hkpExtendedMeshShape* m_mesh = new hkpExtendedMeshShape();
{
hkpExtendedMeshShape::TrianglesSubpart part;
part.m_vertexBase = vertices;
part.m_vertexStriding = sizeof(float) * 3;
part.m_numVertices = numVertices;
part.m_indexBase = indices;
part.m_indexStriding = sizeof(unsigned short) * 3;
part.m_numTriangleShapes = numTriangles;
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
m_mesh->addTrianglesSubpart(part);
}
meshBlock->UnlockIndexBuffer();
meshBlock->UnlockVertexBuffer();
hkpRigidBodyCinfo blockInfo;
hkVector4 blockPosition(0.0f, 5.0f, 0.0f);
hkReal blockMass = 100.0f;
blockInfo.m_shape = m_mesh;
blockInfo.m_position = blockPosition;
blockInfo.m_mass = blockMass;
blockInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
blockInfo.m_qualityType = HK_COLLIDABLE_QUALITY_MOVING;
hkpInertiaTensorComputer::setShapeVolumeMassProperties(m_mesh, blockMass, blockInfo);
pRigidBody = new hkpRigidBody(blockInfo);
physics->getWorld()->addEntity(pRigidBody);
pRigidBody->removeReference();
m_mesh->removeReference();I could potentially remove the first for loop and just cast the MeshVertex (custom FVF), but for now that doesn't seem to be the issue. So using the LPD3DXMesh I'm attempting to extract the vertices and indexes and then apply it to the extended mesh. I get the impression that the indices are getting messed up during the process, but can't figure out how to resolve the issue.
Any help in this matter would be greatly appreciated.


