[Closed] Aligning a modifier Gizmo to World Space?
I’m in the middle of writing a fairly involved maxscript tool and have hit a brick wall in regards to the following problem:
This is what I want to do:
- Apply a slice modifier to a single object
- Set the slice modifier’s slice-plane gizmo to be aligned to WORLD space.
The reason for the second step is that I want to have buttons control the slice plane’s angle. In order to change this angle, and have it consistent with any object in the scene(for later uses), I have to be able to set this angle based on world rotation.
The problem here, is that I cannot figure out how to align it to anything other than the rotation local to the object the modifier is applied to.
Utilizing the Maxscript Help file, I have been learning about transformation matrices and how sub-object gizmos are computed. This area is still a bit fuzzy to me, but I’ve endeavored to make a silly sample script(that doesn’t work properly) so that you might have something to play with:
undo on
foo = selection as array
if foo.count == 1 then
(
macros.run "Modifier Stack" "Convert_to_Poly"
modPanel.addModToSelection (SliceModifier ()) ui:on
fooRot = foo[1].rotation
FooTM = foo[1].objecttransform
modTM = getModContextTM foo[1] foo[1].Slice
foo[1].slice.slice_plane.rotation = fooRot*modTM*(fooTM)
)
else
(
messagebox "Please select a single object"
)
At this point, the slice gizmo will simply be aligned to the object’s rotation, not the world. Any help in this matter would be very appreciated. I hope that I have been clear, but I applogize if I have ommited any important information.
I look forward to your response(s).
-Dave
Hey Dave,
I got it to move with the following code:
obj = selection[1]
objTM = obj.objectTransform
modTM = getModContextTM obj obj.slice
WPos = [0,50,-10]
obj.slice.slice_plane.position = WPos * modTM * (inverse objTM)
Shouldn’t be much different for rotations.
Hope this helps for you,
- Rens
Thanks Rens, but no luck. If you look at the rotation value of the slice gizmo, you will see that it still thinks “world” is the object it’s applied to, not the actual world rotation. I too could get it to move VIA world coords, but not by “world rotation”.
If we simply substitute position for rotation, like this:
obj = selection[1]
objTM = obj.objectTransform
modTM = getModContextTM obj obj.slice
WRot = (quat 0 0 0 1)
obj.slice.slice_plane.rotation = WRot * modTM * (inverse objTM)
The effect is identical to the code I posted in my first post. If you try rotating the original object, and then apply this code, you will see that the slice plane does not in fact line-up with the world grid.
Very perplexing.
Thanks again, for the help. Perhaps I’m still missing something.
-Dave
Sorry, I should’ve checked the rotation before I posted.
Somehow this works:
obj = selection[1]
objTM = obj.objectTransform
modTM = getModContextTM obj obj.slice
WRot = (eulerangles 0 90 0) as quat
obj.slice.slice_plane.rotation = WRot * modTM - (inverse (objTM as quat))
It makes sense somewhere in the back of my brain, probably in the same area as where I stowed away my maths from highschool, but it’s rather late here. I’ll let caffeine enlighten me in the morning.
Good luck,
- Rens
P.S. Oh, the ((eulerangles 0 90 0) as quat) is just for making it easier for me to see the rotation.
Here is the short answer;)
tm=(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
$.modifiers[1].slicePlane.transform = inverse $.objectTransform *tm
Assumes the top modifier is the slice of the selected object. Set tm to be any work matrix values you need.
You guys are just the best. Rens, Paul and Martijn, I can’t thank you enough. I was leaning towards Paul’s solution but it was not as simple as his. Martijn, thanks for taking the time to write me that code. I’ll be going over it a good bit while I move forward with my little project. And last but not least, Rens, I wanted to thank you for your efforts and quick replies. Your method actually helped me get close to Paul’s solution.
Aren’t maxscript rotations fun? Hehe.
Thanks again everyone. If any of you are modelers, you’re probably going to like what I’m cooking up here…
And to think Paul started all this ridiculousness. I asked a question about wheel rotation a month ago and now am learning maxscript…
-Dave