Game Development Community

TSMaterialList

by Erik Madison · in Torque Game Engine · 03/27/2004 (6:15 am) · 2 replies

I'm so confused here, I don't know if I can even explain my query...

How does an object know which material to use?
object being mShape->meshes[num], a part of a segmented model. TSShapeInstance holds the master material list, but I can find no correlation to the individual meshes. I did find a matIndex within the primitive structure, but that seemed to not be related.

#1
03/27/2004 (5:28 pm)
Have you tried looking at the code which sets up OpenGL for rendering?
#2
03/27/2004 (9:01 pm)
Thats it. Took a bit to understand it.
Short answer:
TSMesh * mesh = mMeshObjects[i].getMesh(od);
if (mesh)
{
U32 material = mesh->primitives[0].matIndex & TSDrawPrimitive::MaterialMask;
if (mesh->primitives[0].matIndex & TSDrawPrimitive::NoMaterial)
Con::errorf("No material on this mesh");
else {
TSMaterialList * materials = mShape->materialList;
const char* matname = materials->getMaterialName(material);
Con::errorf("Mesh %s uses texture %s", skinName, matname);
}
}
I'll probably post a practical app for this in a few days.