joeBImagine

Issue with BABYLON.SceneLoader.Load

Recommended Posts

Hello!  I am having an issue with BABYLON.SceneLoader.Load.  I am able to initialize a file from a local directory no problem.  However, unlike BABYLON.SceneLoader.ImportMesh, which puts the imported meshes into an array, I have no clue what the mesh names would be or how to access them.  I am also for some reason, unable to initialize the debug layer (It works fine when I create the scene using ImportMesh).

The reason I am using SceneLoader.Load instead of SceneLoader.ImportMesh, is because I want each time someone clicks on "New Scene" in the html Navigation, it creates a new scene.  

if (BABYLON.Engine.isSupported()) {
	const canvas = document.getElementById('renderCanvas');
	const engine = new BABYLON.Engine(canvas, true);

	const inputElement = document.getElementById('fileUpload');
	inputElement.addEventListener(
		'change',
		function handleFiles(event) {
			const fileList = this.files[0];
			const reader = new FileReader();

			reader.addEventListener('loadend', () => {
				let data = reader.result;
				BABYLON.SceneLoader.Load(
					'',
					'data:' + data,
					engine,
					function(newScene) {
						// Wait for textures and shaders to be ready
						newScene.executeWhenReady(function() {
							var camera = new BABYLON.ArcRotateCamera(
								'ArcRotateCamera',
								0,
								0,
								0,
								BABYLON.Vector3.Zero(),
								newScene
							);
							camera.setPosition(new BABYLON.Vector3(0, 0, -3));
							newScene.activeCamera = camera;
							newScene.activeCamera.attachControl(canvas);
							newScene.clearColor = new BABYLON.Color3(1, 1, 1);

							let light0 = new BABYLON.HemisphericLight('Hemi0', new BABYLON.Vector3(0, 1, 0), newScene);
							light0.intensity = 0.7;
							light0.diffuse = new BABYLON.Color3(1, 1, 1);
							light0.specular = new BABYLON.Color3(0, 0, 0);
							light0.groundColor = new BABYLON.Color3(0, 0, 0);

							let light1 = new BABYLON.HemisphericLight('Hemi1', new BABYLON.Vector3(0, -1, 0), newScene);
							light1.intensity = 0.7;
							light1.diffuse = new BABYLON.Color3(1, 1, 1);
							light1.specular = new BABYLON.Color3(0, 0, 0);
							light1.groundColor = new BABYLON.Color3(0, 0, 0);

							// Once the scene is loaded, just register a render loop to render it
							engine.runRenderLoop(function() {
								newScene.render();
							});
							window.addEventListener('resize', () => {
								engine.resize();
							});
						});
					},
					function(progress) {}
				);
			});
			reader.readAsText(fileList);
		},
		false
	);
}

 

Share this post


Link to post
Share on other sites

That method does not return a list of loaded meshes.  Once it's done you can checl all the meshes in the scene - scene.meshes - I'm going to make an assumption that scene.load overwrites all the objects in the scene so you should be safe to use that.  Scene.append - does not discard the existing scene and like the name implies appends the contents to the existing scene.  It might be helpful for that methods - on success callback to return a list of all the items it loaded. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.