Jump to content

generic animations


eboo
 Share

Recommended Posts

Have you a way to use "generic" animations?

I ve a few elements (with same skeleton and skeleton names inside^^) I d like to use the same "way" to animate them.

is it possible?

my objective is to simplify my .bablylons and save few time in blender ^^.

 

Link to comment
Share on other sites

How about 3 .babylons?  The 4.2+ exporters are set up to do that with multiple actions & friendly with inverse kinematics skeletons.

In .babylon / blend 1: first mesh wt skeleton, but no animation.

In .babylon / blend 2: second mesh wt same skeleton, but no animation.

In .babylon / blend 3: a skeleton (with optional bones ending in .ik that do not get exported).  As many named actions as you wish.

loading:

var scene = new BABYLON.Scene(engine);
var lights = ...
var camera = ...

var url = ...      
BABYLON.SceneLoader.Append(url, "mesh1.babylon", scene);
BABYLON.SceneLoader.Append(url, "mesh2.babylon", scene);
BABYLON.SceneLoader.Append(url, "skeleton_library.babylon", scene);
scene.executeWhenReady(function () {
     // Attach camera to canvas inputs
     scene.activeCamera.attachControl(canvas);

     // Once the scene is loaded, register a render loop
     engine.runRenderLoop(function() {
         scene.render();
     });
     var skeleton1 = scene.getSkeletonByName("skeleton1");
     var skeleton2 = scene.getSkeletonByName("skeleton2");
     var library   = scene.getSkeletonByName("library");

     skeleton1.copyAnimationRange(library, "myaction1", true);
     skeleton1.beginAnimation("myaction1");
            
     skeleton2.copyAnimationRange(library, "myaction2", true);
     skeleton2.beginAnimation("myaction2");
            
});

 

Link to comment
Share on other sites

No.  The point of an AnimationRange is to use names not magic numbers.  This becomes really important once you have multiple actions.  Did you give the name of your action "myaction1"?  That is what I used in my sample.  Even imported .bvh files have an action associated with them.  Think you may need to up your Blender game.

To find the name of an action, switch your layout to 'Animation'.  Change your Dope sheet panel to 'Action Editor' mode.  The name(s) of your actions are just to the right.  Showing action, base08_11x94.

Selection_166.thumb.png.d2df6d53b19e83d8

Link to comment
Share on other sites

Line 21916 indicates there is not animation.  Looked at your files.  Is your load script lik:

BABYLON.SceneLoader.Append(url, "nain.babylon", scene);
BABYLON.SceneLoader.Append(url, "walk.babylon", scene);
scene.executeWhenReady(function () {
     // Attach camera to canvas inputs
     scene.activeCamera.attachControl(canvas);

     // Once the scene is loaded, register a render loop
     engine.runRenderLoop(function() {
         scene.render();
     });
     var skeleton1 = scene.getSkeletonByName("Armature");
     var library   = scene.getSkeletonByName("marcher");

     skeleton1.copyAnimationRange(library, "marcher", true);
     skeleton1.beginAnimation("marcher");         
});
Link to comment
Share on other sites

initiated with

BABYLON.SceneLoader.ImportMesh("", "bb/nain/", "nain.babylon",  scene, function (newMeshes, particleSystems, skeletons)
    { few thinks }

skeleton1 = scene.getSkeletonByName("Armature");

and a listener on "x" touch

        BABYLON.SceneLoader.Append("bb/nain/", "walk.babylon", scene);
        library   = scene.getSkeletonByName("marcher");
        skeleton1.copyAnimationRange(library, "marcher", true);
        skeleton1.beginAnimation("marcher");

 

if il look library with firebug i found animations

i will give a try with easier animation and skeleton

Link to comment
Share on other sites

I used my append way.  I get a different error, and in copyAnimationRange() instead.  There is a bug:angry:.  When I did my testing, my destination bones already had some animation, because I wanted to test deleteRange() too.  So I did not get an error.  There needs to be a test added to check if there is no animation[0] to push an empty.

Will not get to this today. My "Gulp"er needs some TLC too.

Link to comment
Share on other sites

Here, is mine showing error.  I do 2 appends, then copy in executeWhenReady.  Thing he gets a different error cause not waiting to do copy.

I have a fix, but cannot gulp.  I was checking if there was no animations & adding in that case, but an Animation has no keys until setKeys().  Here is a changed Bone.copyAnimationRange with 1 line added to setKeys().

        public copyAnimationRange(source: Bone, rangeName: string, frameOffset: number, rescaleAsRequired = false): boolean {
            // all animation may be coming from a library skeleton, so may need to create animation
            if (this.animations.length === 0) {
                this.animations.push(new Animation(this.name, "_matrix", source.animations[0].framePerSecond, Animation.ANIMATIONTYPE_MATRIX, 0));
                this.animations[0].setKeys([{}]);
            }

            // get animation info / verify there is such a range from the source bone
            var sourceRange = source.animations[0].getRange(rangeName);
            if (!sourceRange) {
                return false;
            }
            var from = sourceRange.from;
            var to = sourceRange.to;
            var sourceKeys = source.animations[0].getKeys();
            
            // rescaling prep
            var sourceBoneLength = source.length;
            var scalingReqd = rescaleAsRequired && sourceBoneLength && this.length && sourceBoneLength !== this.length;
            var ratio = scalingReqd ? this.length / sourceBoneLength : null;

            var destKeys = this.animations[0].getKeys();
            
            // loop vars declaration / initialization
            var orig: { frame: number, value: Matrix };
            var origScale = scalingReqd ? BABYLON.Vector3.Zero() : null;
            var origRotation = scalingReqd ? new BABYLON.Quaternion() : null;
            var origTranslation = scalingReqd ? BABYLON.Vector3.Zero() : null;
            var mat: Matrix;

            for (var key = 0, nKeys = sourceKeys.length; key < nKeys; key++) {
                orig = sourceKeys[key];
                if (orig.frame >= from && orig.frame <= to) {
                    if (scalingReqd) {
                        orig.value.decompose(origScale, origRotation, origTranslation);
                        origTranslation.scaleInPlace(ratio);
                        mat = Matrix.Compose(origScale, origRotation, origTranslation);
                    } else {
                        mat = orig.value;
                    }
                    destKeys.push({ frame: orig.frame + frameOffset, value: mat });
                }
            }
            this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
            return true;
        }

 

Link to comment
Share on other sites

eboo,

Having a black screen is because the lights & camera in the nain.babylon file are wrong.

I created my own light & arc rotate camera in the html of my example.  It displays now.  With 2.4 alpha, the animation range copies but errors on playing.

I need to drop back and see that my own test scenes work with the newest of everything.  If not, work back to final 2.3 & earlier Blender exporters.

No offense eboo, gryff, & dad72 (sort of but I do not know 3dMax), but no point in even trying to debug or get your stuff to run.  I know my tests ran, even if slightly flawed in that I already had some animation in the destination skeleton to test range deletion.  Depending on my retesting, I will then proceed accordingly.

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