编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

Maxscript实现沿着线阵列杆件

wxchong 2024-12-13 16:39:54 开源技术 32 ℃ 0 评论

在max中通常需要给玻璃体添加杆件的情况,所以一般原始方法就是3dmax本身自带的阵列实现,就是下面的SpacingTool工具



但是很麻烦不是?所以可以使用脚本去快捷实现,下面是实现效果。


主要思路是 在线上插入很多相等距离的点,然后获得这些点的坐标并赋予给每一个杆件

其他具体细节有:

1每个杆件需要按照线的走势顺势转动角度,

2杆件间隔设置的1.5m一根

3每一根杆件都是关联的

4不管是一条线还是多条线,只要选中时就可以一起生成杆件,速度快

5适配不同系统单位下杆件大小保持真实尺寸

下面是相关代码。可以复制保存为后缀为".ms"的格式的文件这里保存的是ArrayBar.ms

--单位换算
fn displaymetertosysunit oldcount=(
    case units.SystemType of (
        #centimeters:(oldcount=oldcount*100)
        #millimeters:(oldcount=oldcount*1000)
        #inches:(oldcount=oldcount*39.37)
        #feet:(oldcount=oldcount*3.2808)
        #miles:(oldcount=oldcount*0.0006214)
        #meters:(oldcount=oldcount)
        #kilometers:(oldcount=oldcount*0.001)
        default:(oldcount)
    )
 	return oldcount
)---end fn

--核心代码区,主要是在线上插入很多等比例距离的点,然后获得这些点的坐标给每一个杆件
 fn ArrayBar =( 
    --append all selected shapes into array
	sel=getcurrentselection ()
	shapeNumbers=#()
	for a in sel do (
		if (iskindof a shape) do (
			
			append shapeNumbers a
		)
	)--end for1
    --create a  bar
    oringBar=Box name:#bar width:(displaymetertosysunit (0.05)) length:(displaymetertosysunit (0.05)) height:(displaymetertosysunit (15))
	converttoPoly oringBar
 	for k=1 to shapeNumbers.count do (
		
        -- get interplation from every line
		if classof shapeNumbers[k]==SplineShape then(
			splineNums=numsplines shapeNumbers[k]
			
			for j=1 to splineNums do(			 
					per=(displaymetertosysunit (1.5))/(curveLength shapeNumbers[k] j)            
					for i=0 to 1 by per do(
						interPlationPos=(lengthInterp shapeNumbers[k] j i)
						Tanangle=pathTangent shapeNumbers[k] j i
						newBar=instance oringBar  pos:interPlationPos 
						rotate newBar (eulerangles 0 0 (acos(dot [1,0,0] Tanangle)))                   
					)
			 )
		)else(
				  newLine=ConverttoSplineshape(copy shapeNumbers[k])
				  per=(displaymetertosysunit (1.5))/(curveLength newLine)
				  for i=0 to 1 by per do(
							interPlationPos=(lengthInterp shapeNumbers[k] 1 i)
							Tanangle=pathTangent shapeNumbers[k] 1 i
							newBar=instance oringBar pos:interPlationPos
							rotate newBar (eulerangles 0 0 (acos(dot [1,0,0] Tanangle)))                   
					)
					delete newLine
 
		)
		 
	) 
    delete oringBar
	resetLengthInterp () 
    
)---end fn
ArrayBar()
 

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表