Hey,
I've been struggling to get materials work with hkpMoppBvTreeShape / hkpExtendedMeshShape to no avail, I've read all the material related posts here and lot of related stuff in the documentation but still can't get it right, so I'm posting in hope for some help.
This is how I setup the global material variables:
hkpMeshMaterial HavokMaterial[50]; hkString::memSet( HavokMaterial, 0, sizeof(hkpMeshMaterial) * 50 ); // i don't do anything else for these for now hkInt8* materialIndexBuf; materialIndexBuf=new hkInt8[indexBufSize/3]; // these values are all set to 0 for now
And the mesh:
part.m_vertexBase = (float*)pVertices; part.m_vertexStriding = sizeof(CUSTOMVERTEXNORMAL); part.m_numVertices = vertexBufSize; part.m_indexBase = pIndices; part.m_indexStriding = sizeof(WORD) * 3; part.m_numTriangleShapes = indexBufSize/3; part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16; // material part.m_materialIndexBase = materialIndexBuf; part.m_materialIndexStridingType = hkpExtendedMeshShape::MATERIAL_INDICES_INT8; part.m_materialIndexStriding = sizeof(hkInt8); part.m_materialBase = &HavokMaterial[0]; part.m_materialStriding = sizeof(hkpMeshMaterial); part.m_numMaterials = 50; shape->addTrianglesSubpart( part ); (moppcode stuff in between) hkpMoppBvTreeShape* moppShape; moppShape = new hkpMoppBvTreeShape( shape, code );
And finally here's how I'm trying to retrieve the material:
virtual void calcSingleWheelGroundFriction(hkpVehicleInstance* vehicle, hkInt8 wheelInfoNum, const hkpWorldRayCastOutput& worldRayCastOutput, hkReal& frictionOut) const
{
const hkpMoppBvTreeShape* MoppBvTreeShape = static_cast(worldRayCastOutput.m_rootCollidable->getShape());
const hkpExtendedMeshShape* shape = static_cast(MoppBvTreeShape->getChild());
hkpShapeKey key = HK_INVALID_SHAPE_KEY;
for( int i = 0; i < hkpShapeRayCastOutput::MAX_HIERARCHY_DEPTH && worldRayCastOutput.m_shapeKeys[i] != HK_INVALID_SHAPE_KEY; ++i )
{
key = worldRayCastOutput.m_shapeKeys[i];
}
const hkpMeshMaterial* material = static_cast(shape->getMeshMaterial( key ) );
if( material )
{
// this never happens, the material is always null
}
The retrieved shape mesh is ok, data in it is correct. The key numbers are bit odd but then again I don't know what they should look like, here ere examples: 25559040, 25559041, 78774286, 78774293, 78774292, 85, 86 etc. These are from multiple vehicles near each other.
But as I said the material is always null, no errors or anything. Please help.
Thanks and best regards,
Jarno


