Access to MAYA's WORLD space of an object

Hi there,

For our project, we need to put a camera in a position and make it look to an object.

In order to do this, we need to know the world coordinates of that object.

My colleage @paleRider uses a code to access that information, but the resulting numbers are quite not the real ones.

Talking to eachother, I found out that the numbers Babylon throws are, indeed, the resulting of substracting MAYA’s local space from the world space. I know MAYA’s pivots are quite strange to understand, but they are in fact one of its strengths.

So, at least inside MAYA, you can access the real world space coordinates of an object, independently of the pivot’s position or if you have frozen transformations, and even if the object is inside a group with own transforms.

I guess that information is somewhere when in babylonJS. But where?
Please see this picture:

As you can see, there is a local space, a world space, and the “channel box” coordinates (the column at the very right of the screen). The “channel box” ones are the ones thrown by BabylonJS when querying, but those are NOT the real ones.

Can we throw some light into this?
Thanks in advance.

It is really hard for me to get exactly what information you seek. Let me add @PatrickRyan to the thread.

@joie, the thing that Maya is doing is separating the data into chunks that are easier for the user to digest. Typically, you will see this data stored in the local and world space pivots when you freeze a transform. For example, you move an object 10 units in positive X and then freeze the transform. The channel box will show a value of 0 on X, but the 10 units in X is pushed to the world pivot. This extra transformation is applied by Maya, but allows the user to do things like animate the node with cleaner values that always needing the base world pivot baked into the data.

This is also where we get into issues with our exporter and the glTF format. Our exporter has no way to represent the pivot data in a glTF, so what you end up with is baking the pivot data into the pivot itself. To illustrate this, here is a simple scene that you can load into the sandbox to follow along:

freezeTest.zip (1.6 KB)

The grey cube sits at the world origin for reference. The red cube is 3 units in X from the world origin and has it’s transform frozen in Maya. The green cube sits -3 units in X from the world origin, but is not frozen. You will notice when selecting the green cube, that the units are represented as authored:

image

When selecting the red cube, you will also see that the frozen transform from Maya is respected:

image

What this translates to in reality, is that the local pivot in Maya which has a world space pivot offset saved to it is baked to the pivot in glTF. So when you select the red cube and enable the transform tool, we see where the pivot for the red cube sits:

While the green cube retains the pivot as you would see it in Maya:

This is similar to a parented node where the transform of the node is based off of the parent location. The blue cube sits at 2 units in Y, and is the parent of the teal cube. The teal cube is 3 units in X from its parent so you will see the transform of the teal cube as:

image

It does not have any translation in Y, even though it sits 2 units in Y above the origin because that transform is on the parent node.

So what this means for determining a coordinate to look at is that when authoring in Maya that transforms should not be frozen as this will change the pivot of the mesh to put the world pivot offset back into the object pivot, and you will lose some data. If you need to zero out data similar to freezing a transform, but need to know what the offset is, use a parent node like a locator. This is a transform with no mesh. Using a locator to set the zeroed location of your mesh will do the same thing as freezing the transform without losing the data converting to glTF. Otherwise, you can just not freeze transforms and always take the world offset into account when animating, etc.

If you go with the parenting route, you can always walk the hierarchy of a node to get the full offset so you know exactly where it is in world space. You will just add up all of the offsets from the targeted node and all parent nodes and you will have the exact position in world space.

Hope this makes sense and unblocks you a bit. I know that reworking the scene may be inconvenient. If it’s a major rework, you could drop a locator in the scene in the position of your mesh and use that as your target position. You can easily do this by creating a locator and then adding a point constraint from the locator to your target mesh. The point constraint will move the locator to the position of the target’s pivot automatically. Then simply delete the point constraint and you have a transform that is exactly in the same position as the mesh without the frozen transform. You can then target the locator in your code rather than the mesh, which will shortcut some rework if needed.

Thank you for the explanation. I normally go the parent route because it’s the way to go when you don’t know if what you are doing is final or not and depends on client’s supervision. So if the object changes, it will keep animations and everything because all that is applied to the parent and not the object itself.
But we need to know the word position of the parented object and that’s what is causing problems because it doesn’t throw the real world coordinates.
For some reason, the command used to know world coordinates doesn’t show the real ones.
In order to check this I just create a locator and put it where the object is, so I get world position data. And that one is not the data Babylon is giving.
If that’s not clear enough I’ll create a sample glTF to illustrate the problem.

@joie a small repro would be very helpful. Also, if you could include your sample Maya file so I can look at both sides of the equation would be excellent. Thanks!