Havok integration question.
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Havok integration question.
Does anyone have a function that converts an IMesh into a Havok hkpExtendedMeshShape? I've been trying to write one for a while now, and I've gotten nowhere.
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
I don't use Havok, but here is the code we use to convert an IMesh to a btTriangleMesh for Bullet. It might be able to point you in the general direction:
amesh is defined as "irr::scene::IAnimatedMesh* amesh;" and was loaded in an earlier step "amesh = smgr->getMesh(worldmodel);"
Code: Select all
irr::scene::IMeshBuffer* mesh = amesh->getMesh(0)->getMeshBuffer(0);
btTriangleMesh* btmesh = new btTriangleMesh();
irr::video::S3DVertex* verticies = (irr::video::S3DVertex*)mesh->getVertices();
irr::u16* indicies = mesh->getIndices();
for(irr::u32 i=0;i < mesh->getIndexCount();i+=3)
{
btmesh->addTriangle(
btVector3(
verticies[indicies[i]].Pos.X,
verticies[indicies[i]].Pos.Y,
verticies[indicies[i]].Pos.Z
),
btVector3(
verticies[indicies[i+1]].Pos.X,
verticies[indicies[i+1]].Pos.Y,
verticies[indicies[i+1]].Pos.Z
),
btVector3(
verticies[indicies[i+2]].Pos.X,
verticies[indicies[i+2]].Pos.Y,
verticies[indicies[i+2]].Pos.Z
)
);
}
btBvhTriangleMeshShape* btshape = new btBvhTriangleMeshShape(btmesh,false);
//...
This is the function I am using to convert an IMesh to a havok rigid body. I modified the code a bit that someone else had posted to this forum a while back.
Code: Select all
hkpRigidBody* createTriangleMesh(hkpWorld* pWorld, IMesh* mesh, vector3df scale,
hkpMotion::MotionType motionType)
{
hkpExtendedMeshShape* meshShape = new hkpExtendedMeshShape(0.0f);
for (irr::u32 i = 0; i < mesh->getMeshBufferCount(); i++)
{
irr::scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
irr::f32* vertexBuffer = new irr::f32[mb->getVertexCount() * 3];
irr::u16* indexBuffer = mb->getIndices();
int tmpCounter = 0;
for (irr::u32 x = 0; x < mb->getVertexCount(); x++)
{
vector3df tmp = mb->getPosition(x);
vertexBuffer[tmpCounter] = tmp.X * scale.X;
vertexBuffer[tmpCounter+1] = tmp.Y * scale.Y;
vertexBuffer[tmpCounter+2] = tmp.Z * scale.Z;
tmpCounter += 3;
}
hkpExtendedMeshShape::TrianglesSubpart part;
part.m_vertexBase = vertexBuffer;
part.m_vertexStriding = sizeof(float) * 3;
part.m_numVertices = mb->getVertexCount();
part.m_indexBase = indexBuffer;
part.m_indexStriding = sizeof(unsigned short)*3;
part.m_numTriangleShapes = mb->getIndexCount()/3;
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
meshShape->addTrianglesSubpart(part);
}
hkpRigidBodyCinfo rbCi;
rbCi.m_shape = meshShape;
rbCi.m_motionType = motionType;
hkpRigidBody* r = new hkpRigidBody(rbCi);
pWorld->addEntity(r);
//r->removeReference();
return r;
}