Jump to content

Manually Looping Animations


MackeyK24
 Share

Recommended Posts

Hi guys ... I am creating transitions and blend trees for BabylonJS toolkit... The very nature of the transition system in unity DOES NOT ALLOW traditional looping...

 

EVERYTHING is a transition condition check... if NO conditions are meet after ANY animation is play it is stopped... the have various of way they id to LOOP back on itself with ANOTHER transition set state.... So basically they ALWAYS play one iteration of an animation and check it transition condition (which may be itself) and plays that animation clip...

 

Now I am wonder what the performance impact of babylonJS of doing ANOTHER scene.beginAnimation in the OnAnimationEnd end event in the same frame as the on animationEnd Event (so its not choppy) VS playing it with a loop cycle... I won't know if cam to loop back onto itself until AFTER the animation has been played and its conditions are check... So I gotta 'Manually Loop Animations' even small few frame animations:

 

Yo @Deltakosh ... Pinging you in too :)

Here is an example of some of my state machine update logic, tell me why you think the impact performance of manually looping animations this way will be:

private setCurrentMachineState(name:string):void {
    if (this._state == null || this._state.name !== name) {
        this._state = this.getMachineStateInfo(name);
    }
    if (this._state != null) {
        this._state.interupted = false;
        this._state.sts = BABYLON.MachineStatus.None;
        if (this._state.motion != null && this._state.motion !== "" && this._state.type === BABYLON.MotionType.Clip) {
            var local:BABYLON.MachineState = this._state;
            var blend:number = BABYLON.Constants.NoBlending;
            var speed:number = local.speed;
            local.sts = BABYLON.MachineStatus.Playing;
            this._animataions = this.manager.playAnimationClip(local.motion, this.owned, false, speed, blend, true, ()=>{ 
                local.sts = BABYLON.MachineStatus.Finished;
                this.updateStateMachine();
            });
        }
    }
}

 

NOTE: this.manager.playAnimationClip basically calls scene.beginAnimation on all required components as well... then on this.updateStateMachine will cause the

component to call this.setCurrentMachineState on WHATEVER the first transition CHECK says... including it might be itself again...

Hope I explained that good enough :)

 

Link to comment
Share on other sites

I extensively start animations in onAnimationEnd!  I'm using cps from redux-saga for my state machine, but even manually with nearly zero issues.  i have had instances where i manually needed to clear the animations array, but those were really nested and waiting on a series of animations to complete (in loops).  So, I have some code that looks like this to work and is maybe a timing issue elsewhere in my code:

animationTarget.animations = []
animationTarget.animations.push(animationRotation)

If I could create a PG it would take hours and not be easy to follow.  I would just say that if you run into something crazy that doesn't make sense to just check/log the animations array before starting a new animation to make sure it only has what you want on it.  In my case I was expecting the animations array to be empty (as onAnimationEnd had fired) and it wasn't empty :)  It's easy to notice, because a previous animation will start, too! I am very impressed with the animations and how easy they are to work with.

Link to comment
Share on other sites

2 hours ago, brianzinn said:

I extensively start animations in onAnimationEnd!  I'm using cps from redux-saga for my state machine, but even manually with nearly zero issues.  i have had instances where i manually needed to clear the animations array, but those were really nested and waiting on a series of animations to complete (in loops).  So, I have some code that looks like this to work and is maybe a timing issue elsewhere in my code:


animationTarget.animations = []
animationTarget.animations.push(animationRotation)

If I could create a PG it would take hours and not be easy to follow.  I would just say that if you run into something crazy that doesn't make sense to just check/log the animations array before starting a new animation to make sure it only has what you want on it.  In my case I was expecting the animations array to be empty (as onAnimationEnd had fired) and it wasn't empty :)  It's easy to notice, because a previous animation will start, too! I am very impressed with the animations and how easy they are to work with.

I keep 1 long animation track with all the animation clips from the unity Animator Control baked into 1 single BabylonAnimation... I keep a TOC of all the animation clip ranges (kinda like _ranges for skeleton... but for much more the skeletons... I can use all animations from unity)...

So basically I am call scene.beginAnimation on the SAME animation track with different start and end values...

Idle 0 - 20

Walk 20 - 50

Run 50 = 100

and so on... So if I can FREELY jump around in that same animation OVER AND OVER with different ranges each time I'm Kool...

BTW ... @Deltakosh said this is something like the built-in cycle does anyways :)

 

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