Rotate pivot to align with edge of line

for i in selection do

(p1 =getKnotPoint i 1 1

p2 =getKnotPoint i 1 2

dir = normalize (p2 - p1)

vec = case axis of

(

#x: obj.transform[1] 

#y: obj.transform[2] 

#z: obj.transform[3] 

)

tm = i.transform

vec = normalize vec

 

 

rtm = angleaxis (acos (dot vec dir)) (normalize (cross dir vec))

i.transform = translate (rotate (scalematrix tm.scale) (tm.rotation*rtm)) tm.pos

(if pos == true do obj.pos = p1

)

AttachmentSize
max.jpg66.7 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

(
	selObjsArr = selection as array
	for obj in selObjsArr do
	(
		p1 = getKnotPoint obj 1 1
		p2 = getKnotPoint obj 1 2
		dir = normalize (p2 - p1)
		vec = obj.transform[1] 
		tm = obj.transform
		vec = normalize vec
		dir = normalize dir
		rtm = angleaxis (acos (dot vec dir)) (normalize (cross dir vec))
		tempObjTM = translate (rotate (scalematrix tm.scale) (tm.rotation*rtm)) tm.pos
		--
		worldAlignPivot obj
		rotation = inverse tempObjTM.rotation
		in coordsys local obj.rotation *= rotation
		obj.objectoffsetrot *= rotation
		obj.objectoffsetpos *= rotation	
		obj.pivot = p1		
	)
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.