joeBImagine Posted November 8, 2017 Share Posted November 8, 2017 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 ); } Quote Link to comment Share on other sites More sharing options...
mr_pinc Posted November 8, 2017 Share Posted November 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
joeBImagine Posted November 8, 2017 Author Share Posted November 8, 2017 Just for clarity I can take scene.meshes (or in this case newScene.meshes) and get the meshes that are in the scene and wrap them in an array for later use? Also do you know why the debugger doesn't work with this method? Quote Link to comment Share on other sites More sharing options...
joeBImagine Posted November 8, 2017 Author Share Posted November 8, 2017 I actually got the debugger to work (should have been newScene and not just scene). But I am still slightly confused on the scene.meshes part. Quote Link to comment Share on other sites More sharing options...
joeBImagine Posted November 8, 2017 Author Share Posted November 8, 2017 const newMeshes = newScene.meshes; newMeshes[0].scaling = new BABYLON.Vector3(0.1, 0.1, 0.1); newMeshes[0].position.y = 0; Mr_Pinc you were right. newScene.meshes worked, than you for the help!!! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.