ScriptSpot

Forum topic · General Scripting

Aligning object to face normal with local rotation

By Vadim Vdovenko · 2018-07-04

Description

Hello!

My script aligns object to face like this:
https://i.imgur.com/SggAqvx.png

But i need to get this:
https://i.imgur.com/gmuYhav.png

there is a code i used:


faces = (polyOp.getFaceSelection $Box001) as array
face = faces[1]
theMatrix = matrixFromNormal(polyOp.getFaceNormal $Box001 face)
theMatrix.row4 = polyOp.getFaceCenter $Box001 face
$object.transform = theMatrix

Help me, friends :)

Comments (5)

Vadim Vdovenko · 2018-07-07

thank you!
second one does it right, but it too complicated for me to understand
i write simple script that creates and aligns helper grid on selected face and i can't rotate it right way. So can you please fix my code if you know how

.

miauu · 2018-07-08

The best way is to try to learn something from the code that works for you.
But(not the best solution):


(
	tmpMesh = snapShotAsMesh $Box001
	faces = (getFaceSelection tmpMesh) as array
	face = faces[1]
	faceNormal = getFaceNormal tmpMesh face
	faceCenter = meshop.getFaceCenter tmpMesh face
	
	vv = getFace tmpMesh face
	dir = normalize ((getVert tmpMesh vv[2]) - (getVert tmpMesh vv[1]))
	side = normalize (cross dir faceNormal)
	front = normalize (cross faceNormal side)
	theMatrix = matrix3 front side faceNormal faceCenter
	delete tmpMesh
	
	$Box002.transform = theMatrix	
)

Vadim Vdovenko · 2018-07-08

Thanx a lot, miauu!

.

jahman · 2018-07-08

align to normal
там все понятно должно быть