自制3DSMAX 自动减面脚本

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跑一下就可以用,也可以按我写的功能直接拆开跑
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值