Hi everyone !
I tried to load a model to a scene using this code :
const canvas = document.getElementById('canvas');
var engine = new BABYLON.Engine(canvas, true);
function createScene() {
var scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera(
'camera',
Math.PI / 2,
Math.PI / 2,
250,
BABYLON.Vector3.Zero(),
scene,
);
camera.attachControl(canvas, true);
var light = new BABYLON.HemisphericLight(
'light1',
new BABYLON.Vector3(0, 1, 0),
scene,
);
light.intensity = 0.7;
BABYLON.SceneLoader.Append(
'https://rawgit.com/KhronosGroup/glTF-Sample-Models/master/2.0/Buggy/glTF-Binary/Buggy.glb',
'',
scene,
(newScene) => {
console.log('callback mesh count: ' + newScene.meshes.length);
},
);
return scene;
}
var scene = createScene();
engine.runRenderLoop(() => {
scene.render();
});
It does not work if I use the npm packages (4.0.1) :
import * as BABYLON from 'babylonjs';
import 'babylonjs-loaders';
I get issues like :
babylonjs-loaders.js:4 Uncaught TypeError: Cannot read property 'SceneLoader' of undefined
but it works if I use the cdn version:
<script src="https://cdn.babylonjs.com/babylon.js"></script>
<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
It is maybe related to the packages uploaded to npm, as the code is also working on the playground.
Thanks for your help and suggestions !