Notifications
Clear all

[Closed] Rotate modifier gizmo in world space

Is there some universal way of rotating modifier gizmos in world space? I’ve tried this:

modgizmo= $.uvwmap.gizmo
oldModMatrix = modgizmo.transform
--this moves gizmo to object's origin
modgizmo.transform = modgizmo.transform * (inverse (transMatrix(oldModMatrix.position)))
--rotates by 90 degree around Y axis
modgizmo.rotation = modgizmo.rotation + (((eulerangles 0 90 0) as quat) * (inverse ($.objecttransform)))
--this moves gizmo to saved position
modgizmo.transform = modgizmo.transform * ((transMatrix(oldModMatrix.position)))


It works in simple cases, but with rotated objects/gizmos it mixes up the axis.

11 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

what do you mean by rotate a gizmo in the world space? do you need a function that set a modifier’s gizmo using world space transform matrix? or in two words: align a gizmo to an object world transform?

 JHN

Take a look at Martin Breidt’s gizmo control. You should find the code idea’s you need.

http://scripts.breidt.net/#gizmoControl

-Johan

Thank you, Johan!

I’ve already dived into the code Will post here if I’ll come to some way of rotating gizmos without expression controllers (hopefully).

and there is another question… around what point do you want to rotate?

I have some simple script to quickly rotate uvw gizmo around local axis at 90 degrees.

mod_obj = modPanel.getCurrentObject()
gizmo_rotation = mod_obj.gizmo.rotation
mod_obj.gizmo.rotation = gizmo_rotation * ((eulerangles 0 0 -90) as quat)

It rotates only in local space, no matter what coordsys in choosen in max, so I’ve decided to improve it a little, to rotate gizmo around it’s center in View space when I work in top/front/left/etc viewports, and in World space when I work in User/Perspective viewport. Ultimately I’d like to rotate it in current coordsys.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

ok… i can give a formula but it’s not interesting. here is a theory and everyone has a chance to do it himself…
to rotate a gizmo in some space we need the transition matrix to this space and rotation matrix to rotate…
in case of transition in world space the transition matrix is:


 wt_tm = (inverse (getModContextTM node modi)) * node.objecttransform
 

where node is our node, and modi is our modifier

the rotation matrix in world space is:


 wr_tm = (angle as quat) as matrix3
 

where angle is an angle of rotation (eulerangles, angleaxis or quat)

now we have to find the rotation matrix in gizmo space (gr_tm):


 --we know that:
 gizmo_tm * wt_tm * wr_tm = gizmo_tm * gr_tm * wt_tm
 -- so
 gr_tm = wt_tm * wr_tm * (inverse wt_tm)
 

as we have gr_tm the final rotated matrix in gizmo space is:


 final_tm = gizmo_tm * gr_tm
 

if we need to rotate gizmo around center we have to rebuild the final matrix as:


 matrix3 final_tm[1] final_tm[2] final_tm[3] gizmo_tm[4]
 

hopefully i didn’t forget anything…

oh… i forgot to say… the transition matrix that i shown is correct for UVWMAP modifier only.
for a simple modifier the transition matrix is different. but it’s easy to find it in the mxs help.

That’s cool Thank you Denis, I should do some research now to catch all these matrices

One more question please, may be offtopic – why getModContextTM node modi matrix is almost always equals to identity matrix?

if you translate(rotate, scale) gizmo it will be not…

if you translate(rotate, scale) gizmo it will be not…

This is why I’m asking – I did move and rotate gizmo, gizmo.transform reflects all that transformations but not the getModContextTM. Have to check one more time…

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

it was rubbish what i said … ModContextTM is coordinate space defined by developer where the modifier works. The gizmo transform is in this space. Usually most of modifiers use Object space, so the ModContextTM is an identity matrix. but as i said it might be any and defined by developer.