Hi people,
I have 2 heavy things in my scene, a 3D model and an image. First the smaller images load and then the heavier models load. Is there a way to assign a preloader so that the app only loads when everything else has been loaded?
<!DOCTYPE html>
<title>Babylon.js</title>
<!-- Babylon.js -->
<script src="https://code.jquery.com/pep/0.4.2/pep.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.2/dat.gui.min.js"></script>
<script src="https://preview.babylonjs.com/ammo.js"></script>
<script src="https://preview.babylonjs.com/cannon.js"></script>
<script src="https://preview.babylonjs.com/Oimo.js"></script>
<script src="https://preview.babylonjs.com/libktx.js"></script>
<script src="https://preview.babylonjs.com/earcut.min.js"></script>
<script src="https://preview.babylonjs.com/babylon.js"></script>
<script src="https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js"></script>
<script src="https://preview.babylonjs.com/materialsLibrary/babylonjs.materials.min.js"></script>
<script src="https://preview.babylonjs.com/proceduralTexturesLibrary/babylonjs.proceduralTextures.min.js"></script>
<script src="https://preview.babylonjs.com/postProcessesLibrary/babylonjs.postProcess.min.js"></script>
<script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.js"></script>
<script src="https://preview.babylonjs.com/serializers/babylonjs.serializers.min.js"></script>
<script src="https://preview.babylonjs.com/gui/babylon.gui.min.js"></script>
<script src="https://cdn.babylonjs.com/loaders/"></script>
<style>
html,
body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
}
</style>
</head>
<body>
<canvas id="renderCanvas"></canvas>
<script>
var canvas = document.getElementById("renderCanvas");
var engine = null;
var scene = null;
var sceneToRender = null;
var createDefaultEngine = function () { return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true }); };
class Playground
{
static CreateScene(engine, canvas)
{
BABYLON.SceneLoader.ImportMesh("", "Models/", "scene.gltf", scene, function (vpMesh) {
}, undefined, undefined, '.gltf');
var Lamp = new BABYLON.SpriteManager("Lamp", "RoomTexture/Lampe.png", 51, 98, scene);
var spriteLamp = new BABYLON.Sprite("spriteLamp", Lamp);
spriteLamp.position.x = 900;
spriteLamp.position.y = -60;
spriteLamp.position.z = -1200;
spriteLamp.size = 220;
spriteLamp.renderingGroupId = 3;
Lamp.renderingGroupId = 3;
return scene;
}
}
createScene = function () { return Playground.CreateScene(engine, engine.getRenderingCanvas()); }
var engine;
try
{
engine = createDefaultEngine();
} catch (e)
{
console.log("the available createEngine function failed. Creating the default engine instead");
engine = createDefaultEngine();
}
if (!engine) throw 'engine should not be null.';
scene = createScene();
sceneToRender = scene
engine.runRenderLoop(function ()
{
if (sceneToRender)
{
sceneToRender.render();
}
});
// Resize
window.addEventListener("resize", function ()
{
engine.resize();
});
</script>
`Preformatted text`