Add button in world space

Hello,
Is there a way to create the AdvancedDynamicTexture for world space? I am trying to add a button in a scene and the only way I came across online for a world space is to define it as such:

var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateForMesh(mesh);

But what if my scene does not have a mesh. So is there a way to add a button to the scene and I can move with position node?

var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateForMesh(meshName);
    var panel = new BABYLON.GUI.StackPanel();
    panel.isVertical = false;
    panel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;
    advancedTexture.addControl(panel);

    var addButton = function (text, callback) {
        var button = BABYLON.GUI.Button.CreateSimpleButton("button", text);
        button.width = "140px";
        button.height = "40px";
        button.color = "white";
        button.background = "green";
        button.paddingLeft = "10px";
        button.paddingRight = "10px";
        button.onPointerUpObservable.add(function () {
            callback();
        });
        panel.addControl(button);
    }

Hi. Simply add mesh like plane and hide this mesh or try use transformNode Transform Node | Babylon.js Documentation but I don’t know if you can attach gui element to transform node… But you can try.

I’m not sure what you mean by this. If you are trying to make a 2D button move with a world space coordinate, you can use linkWithMesh to link it to a transform node. Is this what you mean?

4 Likes