Rotate object so as to make specific face horizontal.

Hi all ! Help wanted !
Is the following logic correct ? New in scripting!!!

1. Let's say we have an object with many faces and random rotation
2. And we want to rotate the object so as to make one selected face be on the horizontal level (like align to horizontal).
3. We get the facenormal for that face and get the matrix3 for it
4. We rotate the main object by using matrix3 according to the matrix3 of the face

Does it make any sense ? Is there a better way to try this ? Can anyone help ?

Question: Is it better to connect matrix3 data of the whole object with plain object rotation, angle and one vector? Is it possible ?

That's it for now !
Thank you all

Comments

Comment viewing options

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

Just for info...

...you can do it without scripting in, like, 12 seconds.
Make a plane or whatever primitive - with autogrid turned on - on the face of your model, link the model to the plane, reset the plane's rotation values to zero, delete the plane, done.

As for scripting it, get the normal vector with getFaceNormal(), make a matrix3 out of it with matrixFromNormal(), then multiply the object's transform by the invert of that matrix.

f = 16  --  face index
norm = getFaceNormal obj f
tm = matrixFromNormal norm
obj.transform *= inverse tm

That's for an editable mesh. For an editable poly, use the polyOp methods.

Iga's picture

Hi ! I know I can do it

Hi ! I know I can do it without scripting !
I 'm studying to make a script for multiple objects !
So, thank you very much ! I'll get down to it !

Comment viewing options

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