Jump to content

Loading animations on the fly


Dad72
 Share

Recommended Posts

@Dad72 : I looked at your .babylon files to find something like this - a definition of the "ranges" :

Quote

"ranges":[{"name":"base06_02x30","from":1,"to":179}]

That code snippet is from a blender export, using BE4.4.1,  of a file containing a single animation. I could not find any "ranges" in your files. So is the code line :

skeletonsPerso[0].copyAnimationRange(BipWalk, "walk", true);// add walk

just failing quietly?

Also, I am getting four of these lines in my console"

Quote

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.babylon.actifgames.com/anim/walk.babylon.manifest?1457100183077. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Not sure if any of that helps

cheers, gryff :)

 

Link to comment
Share on other sites

Just create your own range on the skeleton, not bones.  Call it "everything", and give it a from of 1 and a to of whatever the last frame is.

Copy the "everything" animation range using the skeleton version of copyAnimationRange, not a the [0] bone.  Bone has a copyAnimationRange() method, but it is not meant to be called in user code.  Sorry, do not have time to edit your playground .  For future searching, better to explain here anyway.

whenReady{
   var srcSkeleton = scene.getS...
   var destSkeleton = scene.getS...
   srcSkeleton.createAnimationRange("everything", 1, 666);
   destSkeleton.copyAnimationRange(srcSkeleton, "everything");
   destSkeleton.beginAnimation("everything");
}
Link to comment
Share on other sites

@dad72 - take a look in your file "walk.babylon" and search for "Bip01 Spine1". You will see that there are two property animations for that bone - position and scaling

Here is the scaling data:

{"name":"scaling animation","property":"scaling","dataType":1,"loopBehavior":1,"framePerSecond":30,

"keys":[{"frame":0,"values":[1.1025,0.9798,1.1493]},{"frame":13,"values":[1.075,1.0057,1.1484]},{"frame":14,"values":[1.1486,1.0074,1.073]},{"frame":17,"values":[1.1494,1.01,1.0694]},{"frame":26,"values":[1.1478,1.0072,1.0739]},{"frame":27,"values":[1.0764,1.0053,1.1474]},{"frame":40,"values":[1.1025,0.9798,1.1493]}]

No other other bone I looked at had animation for this property.

A number of the other bones also have a scaling animation - but I'm not sure how significant the animation values are. The "Bip01 Neck" does not have a scaling animation.

Hope that helps.

cheers, gryff :)

Link to comment
Share on other sites

Ok, I understood why. for the character I was using a heightpoly model with 57 bones and for animated, I used a lowpoly model with 34 bones that had a different number of bones. This explains the previous problem.

Here it works correctly: 

http://www.babylonjs-playground.com/#GA8XI#12

Thank you for your help everyone.

 

Link to comment
Share on other sites

Good.  While my test scene worked under 2.4-alpha.  I managed to break it when I got rid of all animation in the meshes skeleton.  Got the "spaghetti monster". Have managed to fix that.  Am coming out with a PR hopefully by Monday with fixes, and with logging in SceneLoader.  It will be turned on by default.  It will show summary stats like # of bones, so anyone looking at the logs could see that mis-match.  Also thinking about more messages in copyAnimationRange to alert to issue.  Have also added a producer tag for the .babylon file, which will always be on the console.

Playgrounds are fine, but logs are pretty important if BJS is to be taken serious.  You cannot always share proprietary geometry.  This makes BJS unsuitable be used by consultants.  I have been out of the consulting business longer than many here have been programming.  Having to ask the client permission to show your actual work to determine a problem would make you look like a complete light weight.

Not looking for work right now, but that new format, g something, would probably what the client wanted.  Doubt it logs. Will worry about that later.

TOB is being refactored to be multi file source.  Though it is very OO, being 1 gigantic file is a limiting factor.  The architecture would actually support JS / JSON / and the G thing.  Not going to do that right now, but probably not going to add new stuff to the JSON format single source file for much longer. 

Link to comment
Share on other sites

I was talking about TOB being a glTF producer.  Not really seriously considering yet, just saying it could handled with the 2 pass architecture.

Logging wise, I have put most of the logging in each major class, just like the parse is.  In the form of a toString.  Here is skeletons example:

/**
 * @param {boolean} fullDetails - support for multiple levels of logging within scene loading
 */
public toString(fullDetails? : boolean) : string {
    var ret = "Name: " + this.name + ", nBones: " + this.bones.length;
    ret += ", nAnimationRanges: " + (this._ranges ? Object.keys(this._ranges).length : "none");
    if (fullDetails){
        ret += ", Ranges: {" 
        var first = true;
        for (var name in this._ranges) {
            if (!first){
                ret + ", ";
                first = false; 
            }
            ret += name; 
        }
        ret += "}";
    }
    return ret;
} 

I have put in trapping in the loader methods.  Have so many major classes checked out.  My dog is sick & needs attention, so going to do a commit PR with what I got so far.  You just cannot keep this many files checked out at once.

Link to comment
Share on other sites

  • 2 years later...

Hi all, 

I realise its been a couple years since this was posted - just wondering what the current state of play is in regards to the original post?  I am researching whether babylon.js will allow me to load my character model and apply different animations to it based on user interaction.. 

Cheers.. 

 

Link to comment
Share on other sites

I did it on 2 projects that are day under development.

To do that :

1) You load your dummy model that contains the animations with ImportMesh, then you create animations skeleton.createAnimationRange ('walk', keyStart, KeyEnd). This dummy model can be disposed afterwards.

2) You load the other models without animations which contains the same number of bones as the dummy model and you copy the animations there with skeleton.copyAnimationRange (skeleton, 'walk', true);

3) You play the animations following the user interaction by calling the animation you need by name with skeleton.beginAnimation ('' walk ', true, 1.0);

4) If later you want to add animation, you do it on the dummy model only and in the code, you add the animations with createAnimationRange () and copyAnimationRange (). You can have a class that will allow you to easily add your animations. The goal is to use a single dummy character with new animations and load them on all the other characters and following the interactions of the user call the appropriate animation by are name contained in copyAnimationRange ()

Here is a small PG example:

http://www.babylonjs-playground.com/#GA8XI#111

 

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