سؤال

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]
)

نصائح أخرى

Give this a try:

for i in 1 to meditMaterials.count where (MeditUtilities.isMaterialInUse meditMaterials[i] == false) do meditMaterials[i] = Standard()
ATSOps.Refresh()
freeSceneBitmaps()

Or you can also detect textures on modifiers like this:

modTexMaps = #()
for obj in geometry where obj.modifiers.count != 0 do
(
for m = 1 to obj.modifiers.count do
(
    for p in (getpropnames obj.modifiers[m]) \
    where isKindOf (tex = getproperty obj.modifiers[m] p) texturemap do 
    (
        append modTexMaps tex
    )
)
)
modTexMaps
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top