Jump to content

Issue with BABYLON.SceneLoader.Load


joeBImagine
 Share

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
	);
}

 

Link to comment
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. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...