Actually, the alignment is already correct, but there is a bug about the different viewports.
You know the front viewport has different axis than perspective viewport.
The Z and Y are different.
So, if I create a sphere in the perspective and I try to rotate the gravity in the front viewport, it rotates wrongly. For example, when I rotate X, it rotates Y, when I do it in Z, rotates another axis… Was I clear? My english is not very good.
What do you mean rotate the gravity? Do you mean a gravity spacewarp node? Or do you mean your geometry plugin node? Why would rotating your geometry/gravity node affect your hair if your hair is being aligned to the target object?
In the plugin I’m working on, in the Gravity Modifier, I can rotate it.
For instance, I can set the gravity down-up or left-right, or any direction I want, you see?
But it doesn’t rotate correctly in front and left viewport. The axis are wrong and I dont know how to fix that.
Did you picture that?
I think I should give the geometry the viewport axis… not the node axis… I don’t know. It’s very confuse to me yet.
What do you mean by “gravity modifier”? Do you mean that your plugin has a sub-object gizmo that you can rotate around?
You should never, ever do any viewport-dependent calculations on nodes (except under very special circumstances). There’s no bug in the viewports that causes them to treat each axis differently…what you’re experiencing is the fact that the object creation plane will be different depending on what viewport a node is created in, and you’re probably having issues since objects created in viewports other than top and perspective will not be world-axis aligned.
Exactly. There is a gizmo for gravity.
“and you’re probably having issues since objects created in viewports other than top and perspective will not be world-axis aligned.”
That is it! But can yougive me a clue to fix that?
I’m trying to fix that along two weeks, but it’s still too hard to me.
Thank you for your help.
I haven’t used gizmos with the SDK much, but my guess is that it’s operating in local coordinates relative to its node. So the first thing you want to do is multiply the transform of the gizmo, with the transform of the node. This will give you a world-space transform of the gizmo.
From there, you just do your gravity calculations as normal. My guess is that since you’re not doing that first world-space conversion of the gizmo’s transform, the calculations you’re doing with the gizmo are being affected by the orientation of your node (which will be different depending on which viewport you create it in).
Thank you very much.
I’ve tried a lot of things, but nothing yet.
I think the problem is here:
matrixFix.Translate(nodeTM.GetTrans());
I also tried:
matrixFix.Translate(nodeTM.GetTrans() * parentTM.GetTrans());
From:
//::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);
mod->pblock->SetValue(pb_sg_grav_dir, 0, node);
So, the parameter pb_sg_grav_dir is apply to strands, gizmo and all things which use gravity. That is the gravity’s direction.
I guess I’d have to see more of your code, as well as screenshots of your node setup in order to fully understand the problem. None of the code you posted really makes sense.
If you need a gravity vector from a subobject gizmo, it should be as simple as taking your subobject gizmo transform, multiplying it by the gizmo’s parent node transform, and then getting row#2 from that resulting matrix (row 2 is the ‘up’ direction of the matrix). That will give you a world-space gravity vector which you can use to offset your strands.
Unfortunately, I can’t tell you much about the code because it’s confidential, you know? It’s not a plugin of mine, I’m just working for the company.
Look at these steps:
Well, I can’t really help without seeing more of the code and your screenshots don’t clear anything up.
I guess the advice I’ll leave you with is: don’t over complicate things by manually trying to compensate for positions/rotations/scale of your nodes individually. Just multiply transforms until you get to your desired coordinate system. Point3 x TM = world coordinates. Point3 x Inverse™ = local coordinates. Same goes for TMs themselves.