[Closed] Wrong rotation according the viewport
Hi all.
In a modifier that I’m working on, I have “gravity”.
So, when I apply that, every node should goes down.
For instance, if I create a ball (or any object) in perspective viewport, everything if fine and go down, but, if I create it in front view, the initial transform matrix points to wrong direction, because the front viewports’ Z axis is different than perspective’s Z axis, you know?
What can I do to get the correct rotation as soon as I apply the modifier?
Thank you all.
Hi, MattRennie.
Thank you for your answer.
I’m pretty new in 3dsmax SDK (C++) and I wonder how can I use world space.
I’ve already tried to read the doc, but I couldn’t find exactly how to use it.
I also tried to set nodeTransf.setRotate but it didn’t work properly.
In addition, if the object is created in perspective viewport, it shouldn’t rotate at all, because that’s is already in the right orientation. So, how do I do that? I should create a conditional function? “If the object is created in left view or front view, do that…”?
Can you give me a clue?
Thank you.
If you multiply a local point by its parent node matrix, you get a world space point. If you multiply a world space point by the inverse of a node matrix, you get a local point in the coordinate system of that node.
So if you have an object that is rotated, and you want to transform its points downward (and you’re given its points in local space), you’ll want to do this:
- multiply the points by the transform of their node
- transform the points downward
- multiply the points by the inverse transform of their node
In the SDK you can get any INode’s transformation matrix with ‘[node]->GetObjectTM(t)’. There is also a built in function to invert any TM: ‘Inverse™’.
So in your modifier you’ll want to get the node the modifier is applied to (usually using a DependentEnumProc…you can find plenty of examples in the SDK sample files), then get that node’s TM and do what I listed above.
Hi, ivanisavich.
Thank you so much for your deep explanation.
Unfortunately, I couldn’t do that yet, because I don’t understand everything yet.
When you say ‘point’, you mean ‘node’ of the object?
About 1), why should I multiply the node by its transformation? How do I do that?
And 2), how can I transform them downward? Maybe something with Point3(0,0,-1) ?
Look what I’ve done:
// Code from MyModifier::Data::Apply
auto nodeTM = node->GetNodeTM(time);
auto parent = node->GetParentNode();
auto parentTM = parent->GetNodeTM(time);
// WORKED but its a little bit rotated in its base axis
//::Matrix3 matrixFix = nodeTM; // I tried this too
::Matrix3 matrixFix = nodeTM * parentTM; // It’s the same than the line above. Nothing different
matrixFix.SetRotate(0, 0, 0); // Can I do this manually or should get yaw, pitch and roll from somewhere?
matrixFix.Invert();
matrixFix.Translate(nodeTM.GetTrans()); // align the modifier according the object
node->SetNodeTM(time, matrixFix);
Oh sorry, I thought that you meant you were transforming vertices of a node downward, like in a modifier. That’s what I meant by ‘point’ (the vertices of the node). In a geo modifier vertices will be piped down into your ModifyObject function and you would transform them in the way I described.
Could you be more specific about what your plugin does? You wouldn’t want to directly affect the transform of your node in a modifier, so are you affecting the transforms of other nodes in your modifier? Or is this some kind of transform controller or utility plugin?
The modifier plugin works this way, por example:
- Create a sphere (or any object in the scene)
- When I apply the plugin, it creates hair (lots of strands) around the sphere.
- So, now I have the sphere and another “object” with lot of strands.
- When I apply gravity (of this plugin), every strand in hair should goes down.
Actually, with the code I showed the last answer, all the strands go down, but it seems it’s not correct, because when I try to rotate gravity in perspective is ok, but in the left and front viewport, the axis are changed or inverted.
The problem is when I create the sphere in the left or front viewport, if I apply hair and gravity, they have a wrong rotation, you see?
So your plugin is a geometry plugin that creates geometry (hair strands) around a separate geometry object? Or is it creating new INodes around that geometry object?
In other words, is the hair you’re creating a mesh of your plugin, or separate objects that your plugin is just positioning?
Yes, it is a Geometry Plugin. It creates a “new object” with lots of strands and align it to the object (i.e. sphere). I can separate both objects, but the hair is stuck on the sphere.
So after your plugin runs there are 3 nodes:
-
Your geometry plugin node which does the work
-
The hair node which was created by your plugin
-
The target geometry node which the hair is position on
And you simply want to align the hair node to the target node? Is that correct?