Instances of materials, or object instances?
Best regards,
Daniel
Best regards,
Daniel
[size=9] ( mtlindex = 0 mtllist = #() mtlname = #() mtlcount = #() allsel = selection as array mat = multimaterial numsubs:10 -- scan for unique objects and create an array with them for obj in allsel do ( instances = #() instanceObjs = #() inst = false instancemgr.getinstances obj &instances if instances.count == 1 then inst = false else ( --append sel instances[1] obj = instances[1] inst = true for j = 2 to instances.count do ( found = finditem allsel instances[j] if found != 0 then ( deleteItem allsel found h = point pos:(instances[j].pos) scale:(instances[j].scale) rotation:(instances[j].rotation) name:("point_"+instances[j].name) append instanceObjs h delete instances[j] ) ) ) if (classof obj.material) == multimaterial then ( selmtlcount = 0 selindex = #() tindex = mtlindex md = edit_mesh() md.name = "MultMat" addmodifier obj md collapsestack obj --maxOps.CollapseNodeTo sel[i] (sel[i].modifiers.count) off --if sel[i].modifiers.count > 0 then (format "Cannot handle modifiers.\n";break) --if (classof sel[i])==Editable_Mesh then (format "Not editable mesh.\n";break) for j=1 to obj.numfaces do ( facindex = getFaceMatID obj j found = finditem selindex facindex if found != 0 then (setFaceMatID obj j (tindex + found)) else ( mtlindex += 1 append selindex facindex setFaceMatID obj j mtlindex ) ) append mtlcount (selindex.count) for j=1 to selindex.count do ( found = finditem (obj.material.materialIDList) selindex[j] if found == 0 then append mtllist (NoMaterial()) else append mtllist (obj.material.materialList[found]) append mtlname (obj.name + "_" + (j as string)) ) ) else ( mtlindex += 1 append mtllist (obj.material) append mtlcount 1 md = materialmodifier() md.name = "MultMat" md.materialID = mtlindex addmodifier obj md append mtlname (obj.name) ) obj.material = mat if inst then ( for i in instanceObjs do ( o = instance obj o.name = substring (i.name) 7 (i.name.count-7) o.rotation = i.rotation o.scale = i.scale o.pos = i.pos delete i ) ) ) mat.numsubs = (mtllist.count) -- second pass for i=1 to mtllist.count do ( mat.names[i] = mtlname[i] mat.materialIDList[i] = i mat.materialList[i] = mtllist[i] ) ) [/size]
Comment