files = getFiles "C:\\Users\\lynn\\Desktop\\*.max"
for f in files do (loadMAXFile f; print objects)
actionMan.executeAction 0 "40021" -- Selection: 全选
$.EditablePoly.weldFlaggedVertices ()
--遍历减面
(
for obj in objects do
(
select obj
optMod = ProOptimizer()
addModifier obj optMod
optMod.Calculate = true
redrawviews()
vertCnt = (getpolygoncount obj)[2]
if vertCnt <= 500 then
(
optMod.VertexPercent = 80
)
else
(
if vertCnt <= 2000 then
(
optMod.VertexPercent = 60
)
else
(
if vertCnt <= 5000 then
(
optMod.VertexPercent = 40
)
else
(
optMod.VertexPercent = 20
)
)
)
ConvertToPoly obj
)
)
--统一转为可编辑多边形,再附加,绑定为一个模型
actionMan.executeAction 0 "40021" -- Selection:
max select all
actionMan.executeAction 0 "40145"
macros.run "Modifier Stack" "Convert_to_Poly"
undo off
(
while selection.count > 1 do
(
selcount = selection.count
for i = selcount to 2 by -2 do
(
polyop.attach selection[i] selection[i-1]
)
)
update selection[1]
)
--坐标轴居中归底,世界坐标归零
for obj in objects do
(
obj.pivot=obj.center
center = obj.center
center.z = obj.min.z
obj.pivot = center
)
for obj in objects do(
obj.pos = [0,0,0]
)
exportFile "C:/Users/lynn/Desktop/test/test.3ds" #noPrompt selectedOnly: (selection.count != 0 ) using: plug
主要懒得写UI界面了,如有直接有模型可以去掉前两句导入,和最后一句的导出。
然后直接CTRL+E跑一下就可以用,也可以按我写的功能直接拆开跑