I have a fairly large 3DS scene with many individual meshes - a couple of thousand. Each mesh should be using a single material only, i.e. all triangles in that mesh use the same material assigned to the mesh. This seems to be case, but we have many cases where there are also several sub-materials assigned to a mesh which are not actually used in that mesh.
That's fine in 3DS but we export our scene for use in a real-time 3D engine and this is messing up the export... so I wondered if I can write a script which acts on either the whole scene, or the currently selected meshes and will remove all [sub]-materials from each mesh that are not used.
I'm not the artist, I hope this made sense and I got all my terminology right.
How do we know what material is the right one from the multisb material? If it's always just the first material you could do something like
-- walk over all geometry find which has multiSub and apply first material
for o in geometry where isKindOf o.material multimaterial do o.material = o.material.material1
Edit1: If we assume face 1 is leading for material ID we can do
-- walk over all geometry find which has multiSub and apply first material
for o in selection where isKindOf o.material multimaterial do
(
-- Get face material ID from face 1
local id = getFaceMatID o.Mesh 1
-- Assign that material
o.material = o.material[id]
)