Aligning object to face normal with local rotation

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

Comment viewing options

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

thank you! second one does it

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

jahman's picture

.

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

miauu's picture

.

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's picture

Thanx a lot, miauu!

Thanx a lot, miauu!

Comment viewing options

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