2D Position of a locator

Is there a way to get the 2D position for a locator comming from maya.
I have no idea where to search for.

What is a locator ? :slight_smile:

An object in maya without a mesh. A null.
The maya exporter is able to export it.

Ok so you should be able to get it through his name:

scene.getNodeByName("name")

That will return a TransformNode

Isnt the transform node a 3D transform.
I would need the pixel position on screen.

I would like to link a 2D text image to that position.

Here an babylong file with a cube and a locator.cube_and_locator.zip (1.7 KB)

Yes it is

You can then use GUI to add label to it:
https://doc.babylonjs.com/how_to/gui#tracking-positions

1 Like

Thanks great info!

1 Like

I wan to do something very similar to this, but instead of attaching to a mesh, I want to attach to another 2D GUI control. Is there any way to do this? I am currently walking up the parent hierarchy adding up the left and top properties, but its complicated significantly by the horizontal and vertical alignment properties.

1 Like

I do not think it is possible but maybe @Evgeni_Popov has an idea ?

I think you can use the _currentMeasure.left / _currentMeasure.top properties of the control.

The _currentMeasure property is public but hidden (hence the underscore). If you don’t want to use it directly, you can use control.centerX - control.widthInPixels / 2 and control.centerY - control.heightInPixels / 2 to get those values.

1 Like

This is the function I ended up writing. It works.

    const findWorldCoords = function (alignWith){
        var left = 0;
        var top = 0;
        while (alignWith && alignWith !== parentContainer) {
            if (alignWith.parent) {
                switch (alignWith.verticalAlignment) {
                    case BABYLON.GUI.Control.VERTICAL_ALIGNMENT_TOP:
                        top += alignWith.topInPixels;
                        break;
                    case BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM:
                        top += alignWith.parent.heightInPixels - alignWith.heightInPixels + alignWith.topInPixels;
                        break;
                    case BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER:
                        top += (alignWith.parent.heightInPixels - alignWith.heightInPixels) / 2 + alignWith.topInPixels;
                        break;
                }
                switch (alignWith.horizontalAlignment) {
                    case BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT:
                        left += alignWith.leftInPixels;
                        break;
                    case BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT:
                        left += alignWith.parent.widthInPixels - alignWith.widthInPixels + alignWith.leftInPixels;
                        break;
                    case BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER:
                        left += (alignWith.parent.widthInPixels - alignWith.widthInPixels) / 2 + alignWith.leftInPixels;
                        break;
                }
            }
            alignWith = alignWith.parent;
        }
        return { left: left, top: top };
    }


1 Like