Вот пример. В объекте используется всего два материала, остальные идут в виде бороды от старых сцен:
Есть несколько способов сделать это ручками стандартными средствами макса, но скриптом проще и быстрее:
-------------------------------------------------------------
-- work olny selection geometry
-- collapse modifier stack
fn GetOriginObj ar = (
arrAL = #()
arComp = #()
for i in ar do(
if findItem arComp i == 0 do(
if classOf i.baseobject == Editable_Poly or classOf i.baseobject == Editable_mesh do(
arPart = #()
InstanceMgr.GetInstances i &allObjInst
join arPart allObjInst
join arComp arPart
append arrAL arPart
)
)
)
arFin = #()
aC = arrAL.count
for i = 1 to aC do append arFin arrAL[i][1]
arFin
)
fn getArID obj =(
arID = #()
maxOps.CollapseNodeTo obj 1 true
case classOf obj of (
(Editable_Poly):(
nf = obj.numfaces
arID = makeUniqueArray(for f=1 to nf collect polyop.getFaceMatId obj f)
)
(Editable_Mesh):(
nf = obj.numfaces
arID = makeUniqueArray(for f=1 to nf collect getFaceMatID obj f)
)
default: (false)
)
)
fn setID obj arMat =(
case classOf obj of (
(Editable_Poly):(
nf = obj.numfaces
for f=1 to nf do(
_id = polyop.getFaceMatId obj f
for m in arMat do if _id == m[3] do polyOp.setFaceMatID obj f m[4]
)
)
(Editable_Mesh):(
nf = obj.numfaces
for f=1 to nf do(
_id = getFaceMatId obj f
for m in arMat do if _id == m[3] do setFaceMatID obj f m[4]
)
)
default: (false)
)
)
arrObj = GetOriginObj (selection as array)
select arrObj
progressstart "Optimization ID-materials..."
arNum = arrObj.count
num = 1
for o in arrObj do(
m = o.material
arMat = #()
if m != undefined and classOf m == Multimaterial do(
arID = getArID o
ac = arID.count
if m.numsubs > ac do(
if arID != false and ac > 1 do for i = 1 to ac do append arMat #(m[arID[i]], m.names[arID[i]], m.materialIDList[arID[i]], i)
setID o arMat
if setID != false do(
nMat = Multimaterial numsubs:arMat.count name:("m-" + o.name)
for i = 1 to arMat.count do(
nMat.materialList[i] = arMat[i][1]
nMat.names[i] = arMat[i][2]
nMat.materialIDList[i] = arMat[i][4]
)
update o
--get instances obj
InstanceMgr.GetInstances o &allObjInst
for i in allObjInst do i.material = nMat
format "%, %" o.name allObjInst.count
)
progressupdate (num*100.0/arNum)
num +=1
) -- end if m.numsubs > ac
) -- end if m != undefined and classOf m == Multimaterial
) -- end for o in arrObj
progressend ()
-------------------------------------------------------------
Есть несколько способов сделать это ручками стандартными средствами макса, но скриптом проще и быстрее:
-------------------------------------------------------------
-- work olny selection geometry
-- collapse modifier stack
fn GetOriginObj ar = (
arrAL = #()
arComp = #()
for i in ar do(
if findItem arComp i == 0 do(
if classOf i.baseobject == Editable_Poly or classOf i.baseobject == Editable_mesh do(
arPart = #()
InstanceMgr.GetInstances i &allObjInst
join arPart allObjInst
join arComp arPart
append arrAL arPart
)
)
)
arFin = #()
aC = arrAL.count
for i = 1 to aC do append arFin arrAL[i][1]
arFin
)
fn getArID obj =(
arID = #()
maxOps.CollapseNodeTo obj 1 true
case classOf obj of (
(Editable_Poly):(
nf = obj.numfaces
arID = makeUniqueArray(for f=1 to nf collect polyop.getFaceMatId obj f)
)
(Editable_Mesh):(
nf = obj.numfaces
arID = makeUniqueArray(for f=1 to nf collect getFaceMatID obj f)
)
default: (false)
)
)
fn setID obj arMat =(
case classOf obj of (
(Editable_Poly):(
nf = obj.numfaces
for f=1 to nf do(
_id = polyop.getFaceMatId obj f
for m in arMat do if _id == m[3] do polyOp.setFaceMatID obj f m[4]
)
)
(Editable_Mesh):(
nf = obj.numfaces
for f=1 to nf do(
_id = getFaceMatId obj f
for m in arMat do if _id == m[3] do setFaceMatID obj f m[4]
)
)
default: (false)
)
)
arrObj = GetOriginObj (selection as array)
select arrObj
progressstart "Optimization ID-materials..."
arNum = arrObj.count
num = 1
for o in arrObj do(
m = o.material
arMat = #()
if m != undefined and classOf m == Multimaterial do(
arID = getArID o
ac = arID.count
if m.numsubs > ac do(
if arID != false and ac > 1 do for i = 1 to ac do append arMat #(m[arID[i]], m.names[arID[i]], m.materialIDList[arID[i]], i)
setID o arMat
if setID != false do(
nMat = Multimaterial numsubs:arMat.count name:("m-" + o.name)
for i = 1 to arMat.count do(
nMat.materialList[i] = arMat[i][1]
nMat.names[i] = arMat[i][2]
nMat.materialIDList[i] = arMat[i][4]
)
update o
--get instances obj
InstanceMgr.GetInstances o &allObjInst
for i in allObjInst do i.material = nMat
format "%, %" o.name allObjInst.count
)
progressupdate (num*100.0/arNum)
num +=1
) -- end if m.numsubs > ac
) -- end if m != undefined and classOf m == Multimaterial
) -- end for o in arrObj
progressend ()
-------------------------------------------------------------
Комментариев нет:
Отправить комментарий