Jump to content

Problem with babylon.sceneloader


Chrislistens
 Share

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

Link to comment
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 :)

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

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

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

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...