nomadic_aviator Posted September 11, 2015 Share Posted September 11, 2015 I am trying to test a scene I created in Blender, but I keep getting the following error. "Uncaught TypeError: Cannot read property 'attachControl' of undefined" Here is my code: if (BABYLON.Engine.isSupported()) { var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); BABYLON.SceneLoader.Load("", "realestate.babylon", engine, function (newScene) { // Wait for textures and shaders to be ready newScene.executeWhenReady(function () { // Attach camera to canvas inputs newScene.activeCamera.attachControl(canvas); // Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { newScene.render(); }); }); }, function (progress) { // To do: give progress feedback to user }); }I have been away from Babylon.js for a little while, I figured I may have missed something, but I am not sure. I have searched to see if this has been a problem that has been solved. Any help you can give is much appreciated.Thank you. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 11, 2015 Share Posted September 11, 2015 Hello, I pretty sure there is no camera in your scene Quote Link to comment Share on other sites More sharing options...
nomadic_aviator Posted September 12, 2015 Author Share Posted September 12, 2015 Thank you. Actually I figured this out. Had a duh moment... Quote Link to comment Share on other sites More sharing options...
nomadic_aviator Posted September 12, 2015 Author Share Posted September 12, 2015 So I added a camera and I still get the same error. if (BABYLON.Engine.isSupported()) { var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var createScene = function() { var scene = new BABYLON.Scene(engine); scene.clearColor = new BABYLON.Color3(.25, .181, .240); //Scene lights var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 0, 0), scene); light.intensity = 10; //Scene camera var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 5,-10), scene); var ground = new BABYLON.Mesh.CreateGround('ground1', 6, 6, 2, scene); //Import scene BABYLON.SceneLoader.Load("", "realestate.babylon", engine, function(newScene){ var mesh = newScene; mesh.executeWhenReady(function() { camera.activeCamera.attachControl(canvas); // Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { newScene.render(); }); }); }); // return the created scene return scene; }; // call the createScene function var scene = createScene(); } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 13, 2015 Share Posted September 13, 2015 Your new scene still has no camera Because SceneLoader.Load returns a newScene object, you have to create your camera in this specific scene. Quote Link to comment Share on other sites More sharing options...
nomadic_aviator Posted September 13, 2015 Author Share Posted September 13, 2015 Then I am very confused. The first code block I got from your blog on this link: http://blogs.msdn.com/b/eternalcoding/archive/2013/06/28/babylon-js-how-to-load-a-babylon-file-produced-with-blender.aspx The only thing I changed was the .babylon file i was trying to load. Has this changed? Is there an updated way to do this? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted September 13, 2015 Share Posted September 13, 2015 switch to BABYLON.SceneLoader.Append, and replace the engine with you pre-created scene as an arg. Load is just a pain in the ass. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2015 Share Posted September 14, 2015 Note that in my example (the blog post) I did not create a camera as my scene already has one. I did not create a scene neither because Load will return it for you Code:if (BABYLON.Engine.isSupported()) { var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); //Import scene BABYLON.SceneLoader.Load("", "realestate.babylon", engine, function(newScene){ if (!newScene.activeCamera) { newScene.activeCamera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 5,-10), newScene); } newScene.executeWhenReady(function() { camera.activeCamera.attachControl(canvas); // Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { newScene.render(); }); }); }); } Quote Link to comment Share on other sites More sharing options...
nomadic_aviator Posted September 14, 2015 Author Share Posted September 14, 2015 This worked. Thank you very much. I understand now. 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.