hkpMeshMaterial problem

hkpMeshMaterial problem

vfgdfg's picture

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

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
sean.thurston's picture

Hi jarno,

The key values are a function of a lot of different information. They should look very strange.

Have you taken a look at the MeshMaterialDemo? It pretty much does exactly what you are trying to do. It sets up a mesh in code and then grabs the mesh value out at runtime. From just a quick look at the code I don't really see anything that stands out at me.

From looking at the getMeshMaterialFunction() there are only two paths that can return an HK_NULL. If either the materialIndexBase is null or if the actual mesh material is null. I don't see it in your code but are you actually setting up the hkpMeshMaterials?

Cheers,
Sean

Developer Support Engineer Havok www.havok.com
vfgdfg's picture

Hi,

I don't know anything else than hkString::memSet( HavokMaterial, 0, sizeof(hkpMeshMaterial) * 50 );

I also tried to set values to m_filterInfo. Does setting up the materials require something else?

Best Regards,

Jarno

sean.thurston's picture

Hi vfgdfg,

I did some quick tests and it looks like the m_materialIndexBase is null when I put your code in. Double check that value in the calculate friction method. Make sure it is being referenced correctly.

Also, double check the MeshMaterialDemo.

Thanks,
Sean

Developer Support Engineer Havok www.havok.com
vfgdfg's picture

Ooh crap, you were right. Turns out I wasn't setting up the m_materialIndexBase when loading the map data, only when creating/updating it which doesn't happen in the actual game, doh. But anyway now it works, yay! Thanks a lot!

Best Regards,

Jarno

Login to leave a comment.