Chrislistens

Problem with babylon.sceneloader

Recommended Posts

Hello everybody,

I created a very simple scene (1 simple sphere) with Clara.io, then exported it in .babylon format. This file is named "scene2.babylon"

In my folder named "babylontest", I have 2 files :

- scene2.babylon

- babylon.html  (code below)

Would anyone know why the code below doesn't work (nothing appears when I load "babylon.html")? Is there a problem with the line "BABYLON.SceneLoader.Load("", "scene2.babylon", engine, function (newScene)" ?

 

Thank you in advance if you can help !!!

Cheers,

Chris

------------------

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Using babylon.js - How to load a scene</title>
    <script src="https://cdn.babylonjs.com/babylon.max.js"></script>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
            overflow: hidden;
        }

        #renderCanvas {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <canvas id="renderCanvas"></canvas>
    <script>
    if (BABYLON.Engine.isSupported()) {
        var canvas = document.getElementById("renderCanvas");
        var engine = new BABYLON.Engine(canvas, true);

        BABYLON.SceneLoader.Load("", "scene2.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
        });
    }
</script>
 </body>
</html>

babylon.html

Share this post


Link to post
Share on other sites

@Chrislistens Hi and welcome to the forum :)

I tested your HTML code with a simple sphere and plane I created with Blender and it worked fine - just changed the script for BJS to one I have on my local server.

3 hours ago, Chrislistens said:

I created a very simple scene (1 simple sphere) with Clara.io

Did you include a camera and light? If I remove the camera from my Blender scene then it hangs at the line below when I try to load that with your script:

 newScene.activeCamera.attachControl(canvas); 

cheers, gryff :)

Share this post


Link to post
Share on other sites

Hi Gryff,

Thank you very much for your answer and the time spent !

yes I included a camera and light, and I precise the .babylon file works when I test it in Sandbox. So I still don't understand what the problem is...

Thank you again!

Cheers,

Chris

 

Share this post


Link to post
Share on other sites
13 hours ago, gryff said:

@Chrislistens Hi and welcome to the forum :)

I tested your HTML code with a simple sphere and plane I created with Blender and it worked fine - just changed the script for BJS to one I have on my local server.

Did you include a camera and light? If I remove the camera from my Blender scene then it hangs at the line below when I try to load that with your script:


 newScene.activeCamera.attachControl(canvas); 

cheers, gryff :)

Hi Gryff,

Thank you very much for your answer and the time spent !

yes I included a camera and light, and I precise the .babylon file works when I test it in Sandbox. So I still don't understand what the problem is...

Thank you again!

Cheers,

Chris

Share this post


Link to post
Share on other sites

@Chrislistens  : I  gather you still are having problems.

Can you post your .babylon file, and if you created the scene at .clara.io  can you export it as a .blend file and post that too (if it does not cost you money)

cheers, gryff :)

Share this post


Link to post
Share on other sites

Just a guess because you wrote "In my folder..." : Did you open babylon.html with your browser from your disk ?

Because the way scene data is loaded requires the files to be hosted by a webserver. If open the file from disk this part is going to be missing.

Share this post


Link to post
Share on other sites
On 12/08/2017 at 11:55 AM, Chrislistens said:

Thanks a lot to you all for your replies!

- Christoph, indeed I open the babylon.html from my disk: I'm going to try to host by a webserver, even if by now I don't know how to do it.

- Deltakosh, you can find my 2 files attached.

Thanks in advance!!

Cheers,

Chris

babylon.html

scene2.babylon

If you use an IDE, it's likely to have a webserver pluggin available.

Otherwise, if you're running on Windows (I don't know for others OS), I think Firefox is fine with the use of your local directory as a webserver (ie : you may open index.html with Firefox, and request other files from the same directory with Javascript), it can be a workaround.

Edit : I just tried your file on my Mac. Indeed, it fails to load with Chrome and Safari, but it loads with Firefox.

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.