Jump to content

Actions, Animations, and Callbacks


Recommended Posts

I'm having a little trouble with actions, animations, and callbacks. It looks like there isn't a native way to accomplish what I'm after, but I wanted to check with the experts before I continue.


What I'm trying to accomplish:


  • I want to execute an action which fires a function (callback) before and after the animation.


I can accomplish the "before" callback by creating using CombineAction, but it appears the onAnimationEnd is out of my scope.. Specifically in this 1st case I've encountered, I'm using the InterpolateValueAction - which appears to create an Animation for me (while giving me no option to inject the onAnimationEnd callback).


I looked around in Animatable but it doesn't seem like it is what I need either. I thought maybe I could access the animations array of the mesh but alas, it's empty until the action is invoked. Is there a native way I'm missing?

Link to comment
Share on other sites

Hey Hazardus,


a playground would be nice so that everbyody know what and how exactly you want to do it. InterpolateValueAction doesn't seem to have a callback function for animation end, but I know scene.beginAnimation has it:





Maybe there is another way to achieve what you want while using beginAnimation (maybe with the ExecuteCodeAction)? Anyhow, a playground that shows what you have so far might greatly help :)

Link to comment
Share on other sites

Okay, you could do something like that: http://www.babylonjs-playground.com/#2JO9B#1


This uses the ExecuteCodeAction and is some more code than you had before, but seems to work. Maybe somebody else has a better idea or knows how to do the same with less code (maybe with using the InterpolateValueAction).


Let me know if that helped :)

Link to comment
Share on other sites

Hmm.. I like it! I suppose InterpolateValueAction is the only one that has duration (except maybe playSoundAction), and the rest are instant (start/stop = same point in time).


It gives more control over the Animation itself, which is also a plus. Being able to pass a callback would be nice, but this is much better than what I was (reluctantly) considering: modifying the native function or using a Timeout.


Thanks, iiceman!

Link to comment
Share on other sites

You are welcome :) Don't forget to show us what you created when you are done!


By the way: if it answers your question you can flag the thread as answered, too.


Sure - it will be a while longer before I can, but I'll definitely share this neat little project when it's done!


By the way.. the "Animatable" page in the docs leads to a 404 (which I love - "working on my machine" hehehe). From what I gather it's rarely used and just happens to be in the source code, but I'd love to know for sure when/how/why to use this. ( the link: http://doc.babylonjs.com/tutorials/page.php?p=25171 )

Link to comment
Share on other sites

I just realized that the interpolateValueAction uses beginDirectAnimation wich is pretty much the same as beginAnimation (they both can have that needed callback). So it would be easy to add a callback parameter to the interpolateValueAction, right? Or is there a reason that the interpolateValueAction didn't get that callback parameter?


(note to myself: learn typescript to be able to create pull requests for those simple things that even I could do to get my name on the contributor list :D )

Link to comment
Share on other sites

is there a reason that the interpolateValueAction didn't get that callback parameter?


I wondered that myself. The same goes for BABYLON.Animation.CreateAndStartAnimation - why not 1 more parameter for simplicity? Getting to that much needed onAnimationEnd is a bit of a hassle, though as Ice pointed out it can be done.


As for where I found the link, it's actually on the http://doc.babylonjs.com/tutorials/07._Animations page under ( Parameters for scene.beginAnimation ). I couldn't seem to find a way to edit the docs and fix it myself.


I was really hoping the link would be a doc page. I've checked out Animatable in the classes section and the source code, but it's still a bit of a mystery to me. I haven't had a chance to mess around with it just yet.

Link to comment
Share on other sites

And BOOOM :)

New constructor for InterpolateAction:

constructor(triggerOptions: any, target: any, public propertyPath: string, public value: any, public duration: number = 1000, condition?: Condition, public stopOtherAnimations?: boolean, public onInterpolationDone?: () => void) {


new signature for CreateAndStartAnimation:

public static CreateAndStartAnimation(name: string, mesh: AbstractMesh, targetProperty: string,  framePerSecond: number, totalFrame: number, from: any, to: any, loopMode?: number, easingFunction?: EasingFunction, onAnimationEnd?: () => void)
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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...