Update:
Well I tried the 3 float vector thing, and here are the results, they're kinda closer to what I need:
Code: Select all
static hkpRigidBody* createTriangleMesh(hkpWorld* pWorld, Ogre::Mesh* mesh, const Vector3& scale)
{
hkpExtendedMeshShape* meshShape = new hkpExtendedMeshShape(0.0f);
Vector3* vertices;
size_t vertex_count,index_count;
unsigned int* indices;
getMeshInformation(mesh, vertex_count, vertices, index_count, indices);
hkVector4* hkVertices;
hkReal* vertexBuffer;
int tmpCounter = 0;
for (int j = 0; j < vertex_count; j+=1 )
{
vertexBuffer[tmpCounter] = vertices[j].x * scale.x;
vertexBuffer[tmpCounter+1] = vertices[j].y * scale.y;
vertexBuffer[tmpCounter+2] = vertices[j].z * scale.z;
tmpCounter += 3;
}
for (int i = 0; i < index_count; i++)
{
//indices[i] = i;
std::cout << indices[i] << "\n";
}
hkpExtendedMeshShape::TrianglesSubpart part;
part.m_vertexBase = vertexBuffer;
part.m_vertexStriding = sizeof(float) * 3;
part.m_numVertices = vertex_count;
part.m_indexBase = indices;
part.m_indexStriding = sizeof(unsigned int);
part.m_numTriangleShapes = index_count;
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
meshShape->addTrianglesSubpart(part);
hkpMoppCompilerInput* cmi = new hkpMoppCompilerInput();
hkpMoppCode* code = hkpMoppUtility::buildCode(meshShape, *cmi);
hkpMoppBvTreeShape* moppBvShape = new hkpMoppBvTreeShape(meshShape, code);
hkpRigidBodyCinfo info;
info.m_shape = moppBvShape;
info.m_motionType = hkpMotion::MOTION_FIXED;
hkpRigidBody* r = new hkpRigidBody(info);
pWorld->addEntity(r);
return r;
}
^^^ Updated Code ^^^
Now the indices seem to be a problem... I have no idea how to order them or fix the code at
-------------------------------------------------------
Here's the original Irrlicht source, if anyone can convert it to OGRE more properly than me:
Code: Select all
hkpRigidBody* createTriangleMesh(hkpWorld* pWorld, irr::scene::IMesh* mesh, irr::core::vector3df scale)
{
hkpExtendedMeshShape* meshShape = new hkpExtendedMeshShape(0.0f);
for (irr::u32 i = 0; i < mesh->getMeshBufferCount(); i++)
{
irr::scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
irr::video::S3DVertex2TCoords* vertices = (irr::video::S3DVertex2TCoords*)mb->getVertices();
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++)
{
vertexBuffer[tmpCounter] = vertices[x].Pos.X * scale.X;
vertexBuffer[tmpCounter+1] = vertices[x].Pos.Y * scale.Y;
vertexBuffer[tmpCounter+2] = vertices[x].Pos.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);
}
hkpMoppCompilerInput* cmi = new hkpMoppCompilerInput();
hkpMoppCode* code = hkpMoppUtility::buildCode(meshShape, *cmi);
hkpMoppBvTreeShape* moppBvShape = new hkpMoppBvTreeShape(meshShape, code);
hkpRigidBodyCinfo info;
info.m_shape = moppBvShape;
info.m_motionType = hkpMotion::MOTION_FIXED;
hkpRigidBody* r = new hkpRigidBody(info);
pWorld->addEntity(r);
return r;
}
Wolfmanfx wrote:Where did you allocate the memory for you vertices?
Code: Select all
hkVector4* hkVertices; // <-- no alloc here --> = new hkVector4[n];
for (int j = 0; j < vertex_count; j+=1 )
{
hkVertices[j] = hkVector4(vertices[j].x, vertices[j].y, vertices[j].z, 0);
}
And why do you use a vector 4 for position vector3 should be enough. (i just checked the first few lines)
Because Havok doesn't have a Vector3 data type, the 4th value is optional - defaults to 0, and for some reason I copied the wrong code.
I changed the code to the one above, so it doesn't matter.