Jump to content

stranger error when importing a scene from Blender


nomadic_aviator
 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

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();    }
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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