Hello Babylon.js Fellas!
How are you?
Guys, could you help me?
I’m trying to change the position of a button. It would be nice if the button could apper on one of the corners of a given screen. At the moment it is appering over the airplane model.
Here is the playground in question:
var createScene = function () {
// Low Poly Character with Blender Tutorial of Grant Abbitt: https://www.youtube.com/user/mediagabbitt
engine.enableOfflineSupport = false;
// Scene and Camera
var scene = new BABYLON.Scene(engine);
var camera1 = new BABYLON.ArcRotateCamera("camera1", Math.PI / 2, Math.PI / 4, 10, new BABYLON.Vector3(0, -5, 0), scene);
scene.activeCamera = camera1;
scene.activeCamera.attachControl(canvas, true);
camera1.lowerRadiusLimit = 2;
camera1.upperRadiusLimit = 10;
camera1.wheelDeltaPercentage = 0.01;
camera1.pinchPrecision=100
// Lights
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 3, -3), scene);
light.intensity = 2.5;
light.specular = BABYLON.Color3.Black();
var light2 = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -0.5, -1.0), scene);
light2.position = new BABYLON.Vector3(0, 5, 5);
// Skybox
var skybox = BABYLON.MeshBuilder.CreateBox("skyBox", { size: 1000.0 }, scene);
var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
skyboxMaterial.backFaceCulling = false;
//skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/skybox2", scene);
//skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
//skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
skybox.material = skyboxMaterial;
// Ground
//var ground = BABYLON.MeshBuilder.CreateGround("ground", { height: 50, width: 50, subdivisions: 4 }, scene);
//var groundMaterial = new BABYLON.StandardMaterial("groundMaterial", scene);
//groundMaterial.diffuseTexture = new BABYLON.Texture("textures/wood.jpg", scene);
//groundMaterial.diffuseTexture.uScale = 30;
//groundMaterial.diffuseTexture.vScale = 30;
//groundMaterial.specularColor = new BABYLON.Color3(.1, .1, .1);
//ground.material = groundMaterial;
// Load hero character and play animation
BABYLON.SceneLoader.ImportMesh("", "https://raw.githubusercontent.com/chicortiz/glb/main/", "demoi12.glb", scene, function (newMeshes, particleSystems, skeletons, animationGroups) {
var hero = newMeshes[0];
//Scale the model down
hero.scaling.scaleInPlace(0.1);
//Lock camera on the character
camera1.target = hero;
//Get the Samba animation Group
//const sambaAnim = scene.getAnimationGroupByName("Samba");
//Play the Samba animation
//sambaAnim.start(true, 1.0, sambaAnim.from, sambaAnim.to, false);
// GUI
var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
var button = BABYLON.GUI.Button.CreateImageButton("but", "", "https://raw.githubusercontent.com/chicortiz/svg/main/sd.svg");
// ("but", "Click Me",
button.width = 0.2;
button.height = "40px";
button.color = "transparent";
button.background = "transparent";
advancedTexture.addControl(button);
advancedTexture.addControl(target);
target.linkWithMesh(demoi);
demoi.linkOffsetY = -150;
});
return scene;
};
Here is the result: https://prototipe.com.br/html_3d/demoibabylon.html
Maybe mix my actual playground with this other one?
→ https://playground.babylonjs.com/#XCPP9Y#39
I mean something like this:
advancedTexture.addControl(button);
advancedTexture.addControl(target);
target.linkWithMesh(demoi);
demoi.linkOffsetY = -150;
I also don’t know if I’m accessing the console in the right way to check what is going wrong. Any help is appreciated.
Thank you very much for your time,
Greetings,
Ortiz