Jump to content

bone/mesh animation from blender into babylon.js


ragamuffin
 Share

Recommended Posts

Hi everybody, noob here. So I have an animation of a walking person created using makehuman and makewalk and exported to a .babylon. I have the keyframe 0 .babylon appearing in my browser window but can't make the animation run. How can I control it?

Here's my code so far (mostly copy/pasted from a tutorial for importing a mesh-only animation from babylon.

I get a TypeError: scene undefined. from the line scene.beginAnimation(cmbrighuman-highpolyeyes, 31, 60, true, 1.0);
 

<code>

var canvas, engine, scene, camera = 0;

document.addEventListener("DOMContentLoaded", function () {
    if (BABYLON.Engine.isSupported()) {
        initscene();
    }
}, false);

function initscene() {
    canvas = document.getElementById("glCanvas");
    engine = new BABYLON.Engine(canvas, true);
    BABYLON.SceneLoader.Load("", "blender/scenes/walk.babylon", engine, function (scene) {
            // Wait for textures and shaders to be ready
            scene.executeWhenReady(function () {
                // Attach camera to canvas inputs

                var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(1,0,1), scene);
                console.log(scene.meshes[0]);
                
                scene.meshes[0].convertToFlatShadedMesh();
                scene.meshes[0].showBoundingBox = true;
                light.groundColor = new BABYLON.Color3(0.2,0,0.3);
                
            
                // Once the scene is loaded, just register a render loop to render it
                engine.runRenderLoop(function() {
                    
                    scene.render();
                });
            });
        }, function (progress) {
            // To do: give progress feedback to user
    }
    );

    scene.beginAnimation(cmbrighuman-highpolyeyes, 31, 60, true, 1.0);
}

</code>

 

Link to comment
Share on other sites

Hiya @ragamuffin, welcome to the forum!  Sorry it has taken so long to get a reply.  Any progress/success?

On 5/28/2016 at 8:22 AM, ragamuffin said:

scene.beginAnimation(cmbrighuman-highpolyeyes, 31, 60, true, 1.0);

The 'scene' variable in that line... is located outside-of the sceneLoader's   [and executeWhenReady()] ... scope.

Could you try moving that line upward?  Make that be the LAST line in the scene.executeWhenReady() function.  That SHOULD work.  Keep us posted, if you would... thanks.

Again, welcome.

Link to comment
Share on other sites

While @Wingnut is probably right, SceneLoader.Load() is obsolete and inferior to SceneLoad.Append().  Append() also solves the scope problem by design.  See this thread for example on how to remove all this spaghetti code callback logic, which Load causes.  If and when you decide to load multiple .babylon files for a scene, callbacks are terrible.  Better to start using scene.executeWhenReady() right from the beginning.

Since this is your first post would recommend your first verify that everything besides the animation exported as expected, using the BJS Sandbox.  Just drag your .babylon & textures in.

FYI, you can specify flat shading when exporting.

You should also think about using the animation ranges which were exported as well instead of scene.beginAnimation()

Good luck.

 

 

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