Jump to content

Animations based off of Calculations


amorgan
 Share

Recommended Posts

Right now I am following a similar method to Temechon's for updating animations found here, http://pixelcodr.com/tutos/toad_attack/toad_attack-2.html RE: Basic Animations. This is the only way I have seen to be able to dynamically create animations based of off current position,rotation, etc. It would be nice if instead of taking a value for the Keys, they could take a function, so that the animation would not have to be recreated on every iteration. Would this be possible to do?

 

Thanks

Link to comment
Share on other sites

Awesome! This is my first pass at would it could look like, still referencing Temechons example:

function animateEnding (ending) {    // Create the Animation object    var animateEnding = new BABYLON.Animation("animateEnding", "position.y", 60, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE);    // Add these keys to the animation    animateEnding.setKeys(function () {		var keys = [];		//Get the initial position of our mesh		var posY = ending.position.y;				keys.push({			frame: 0,			value: posY		},{			frame: 5,			value: posY+0.5		},{			frame: 10,			value: posY		});				return keys;	});    // Link the animation to the mesh    ending.animations.push(animateEnding);    // Run the animation !    scene.beginAnimation(ending, 0, 10, false, 1);}

Then at the beginning of the animation, the function is called each time (internally to the animation function). Therefore when you call beginAnimation(), restart(), or if it is a looping animation that function gets called to recalculate the keys. Might be able to keep the existing use of the function if the parameter is determined to be an arrary or a function.

 

Also would calling beginAnimation(), restart the animatin? Or does restart() work even after the animation has stopped?

Link to comment
Share on other sites

You know though reading back through the animation wiki sections. It seems like BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE could have been used for this? Or am I missing something...

 

Edit: Unless, Relative means since the last animation and not the current position at the beginning haha

Link to comment
Share on other sites

So I don't think this does what I would have expected: http://www.babylonjs-playground.com/#1OCNMP#1 I would have expected it to be finish back at 1 (the initial starting point), but instead grows.

 

I would assume it is calculating this value every time the animation function is trying to interpolate the frames? Whereas the goal would be to only calculate it at the beginning. I still haven't tried the global variable method, I will get back in regards to that, though I would still prefer it not be global.

Link to comment
Share on other sites

No they do not behave the same. If you look at this: http://www.babylonjs-playground.com/#1OCNMP#3 You will notice that if you click on the fpsLabel, it will increase the y scaling by 1, but the animation does not change, because the value only get's calculated on creation. Whereas I am looking to calculate the value at the beginning of each loop/start of the animation.

Link to comment
Share on other sites

So I can achieve what I want by eleminating some steps from Temechons example and not entirely recreate the animation, but just recalculate the keys and set them again before calling the animation. http://www.babylonjs-playground.com/#1OCNMP#4 (press the fpsLabel). This isn't as clean as just being able to pass in a function for the keys, then just starting and/or restarting the animation. Maybe it is, since I can just use the function I would have used to calculate the keys anyways. Guess it depends on if we want Babylon to handle it or not.

 

Note: I'm being generic with my examples, of course, since I am trying to do other animations also that would benefit from the behavior I am suggesting, at least for me :)

Link to comment
Share on other sites

Unfortunately that is still not solving the problem I see. If I were to change scaling.x before calling that animation, only the first key will "update", the other keys will stay as they were. Though I tried to show that, but for some reason when I do this: http://www.babylonjs-playground.com/#1OCNMP#6 I can't change the scaling.x, once the animation has began, even if it is set to CONSTANT?

 

If you look back at http://www.babylonjs-playground.com/#1OCNMP#1 I would want to be able to calculate those keys at the beginning of the animation, but this method instead makes it infinitely grow instead of returning back to the initial value. The desired result would be how this example executes, I use the scaling.y as example to show that it is indeed being recalcuated before each call. This specific example might be hiding the issue, though.

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