Hello!
I have created two asset managers, each populated with either .stl meshes with materials assigned or bespoke .babylon js files from Blender. I can call these from within my createScene function using the .load() command and everything works as expected.
I am now trying to attach these load() commands to a gui with little success. Basically I want one checkbox on and its linked assets loaded at startup and the other checkbox off and its assets not loaded. the checkboxes should then function as one would expect, loading and unloading the contents of the assetmangers depending on their state.
My first issue is that even if I create an advanceddyanmictexture and nothing else, this single line of code causes the .html not to load. I have placed it within my createScene function as the playground example suggets but I just get a white screen on navigating to the page.
This is pretty fundamental as I canât test any of the rest of the code without being able to call this first part of the gui. Secondly, Iâm not sure of the correct syntax to load / unload assetmanagers using a checkBox. I assume I need a function driven by the checkedchangeobservable watch which in turn gets itâs value from checkbox.ishchecked but again until I can even get the GUI to load I canât progress.
Fullcode for the createScene function below for reference.
// Add your code here matching the playground format
var createScene = function () {
//Create Scene
var scene = new BABYLON.Scene(engine);
//Material Definition
var wakeInner = new BABYLON.StandardMaterial("myMaterial", scene);
wakeInner.diffuseColor = new BABYLON.Color3(0.7, 0.7, 0.7);
wakeInner.alpha = 0.25;
var wakeMid = new BABYLON.StandardMaterial("myMaterial", scene);
wakeMid.diffuseColor = new BABYLON.Color3(0.8, 0.8, 0.8);
wakeMid.alpha = 0.175;
var wakeOuter = new BABYLON.StandardMaterial("myMaterial", scene);
wakeOuter.diffuseColor = new BABYLON.Color3(0.9, 0.9, 0.9);
wakeOuter.alpha = 0.1;
// Create the Asset Managers
var wakeAssets = new BABYLON.AssetsManager(scene);
var carAssets = new BABYLON.AssetsManager(scene);
// Add Meshes to Asset Managers
var meshTask1 = wakeAssets.addMeshTask("", "", "", "isosurfaces_CpT0pt0Trimmed-20per-rot.stl");
meshTask1.onSuccess = function (task) {
task.loadedMeshes[0].material = wakeInner;
}
var meshTask2 = wakeAssets.addMeshTask("", "", "", "isosurfaces_CpT0pt4Trimmed-20per-rot.stl");
meshTask2.onSuccess = function (task) {
task.loadedMeshes[0].material = wakeMid;
}
var meshTask3 = wakeAssets.addMeshTask("", "", "", "isosurfaces_CpT0pt8Trimmed-20per-rot.stl");
meshTask3.onSuccess = function (task) {
task.loadedMeshes[0].material = wakeOuter;
}
var meshTask4 = carAssets.addMeshTask("", "", "", "F12022.babylon");
// Camera Controls
var camera = new BABYLON.ArcRotateCamera("camera", 0, 0, 10, new BABYLON.Vector3(), scene);
camera.setPosition(new BABYLON.Vector3(2, 2, 2));
camera.attachControl(canvas, true);
camera.wheelPrecision = 30;
camera.useAutoRotationBehavior = true;
camera.autoRotationBehavior.idleRotationSpeed = 0.25;
// Light Control
const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0));
// GUI
var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
var panel = new BABYLON.GUI.StackPanel();
panel.width = "200px";
panel.isVertical = false;
panel.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_RIGHT;
panel.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
advancedTexture.addControl(panel);
var wakeCheckbox = new BABYLON.GUI.Checkbox();
wakeCheckbox.width = "20px";
wakeCheckbox.height = "20px";
wakeCheckbox.isChecked = false;
wakecheckbox.onIsCheckedChangedObservable.add(function(value) {
//Code to Load wakeAssets depdning on state
//wakeAssets.load();
});
panel.addControl(wakeCheckbox);
var carCheckbox = new BABYLON.GUI.Checkbox();
wakeCheckbox.width = "20px";
wakeCheckbox.height = "20px";
wakeCheckbox.isChecked = true;
wakecheckbox.onIsCheckedChangedObservable.add(function(value) {
//Code to load carAssets
//carAssets.load();
});
panel.addControl(wakeCheckbox);
// Sound Control
const sound = new BABYLON.Sound("f1-theme", "Formula 1 Theme Live in Concert by Brian Tyler.mp3", scene, null, { loop: true, autoplay: true });
return scene;
};