amorgan Posted January 9, 2015 Share Posted January 9, 2015 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 9, 2015 Share Posted January 9, 2015 Good idea! How do you think the code would look like from an user point of view? (dream it and I'm gonna code it ) amorgan 1 Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 9, 2015 Author Share Posted January 9, 2015 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? Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 9, 2015 Author Share Posted January 9, 2015 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 9, 2015 Share Posted January 9, 2015 Ok let me think a bit about how to do that without losing performance amorgan 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted January 11, 2015 Share Posted January 11, 2015 Hi amorgan, If you declare your variable as global, then it should work the way you want. I'm not certain I understand the problem. Cheers, Dbawel Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 12, 2015 Author Share Posted January 12, 2015 I thought I tried this before and was having issue. I will have to try it again, but I thought there was an issue with propogating references through the function? In addition it would be nice to keep this out of the global space, imo. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 12, 2015 Share Posted January 12, 2015 Guess what? I found a satisfactory way to do this.So now you can do this:http://www.babylonjs-playground.com/#1OCNMPvar keys = []; //At the animation key 0, the value of scaling is "1" keys.push({ frame: 0, value: function() { return -10; } }); Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 13, 2015 Author Share Posted January 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
iiceman Posted January 13, 2015 Share Posted January 13, 2015 http://www.babylonjs-playground.com/#1OCNMP#2 You mean like that? But that's what you already posted above, isn't it? Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 13, 2015 Author Share Posted January 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 13, 2015 Author Share Posted January 13, 2015 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 13, 2015 Share Posted January 13, 2015 This should work:http://www.babylonjs-playground.com/#1OCNMP#5 Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 13, 2015 Author Share Posted January 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 14, 2015 Share Posted January 14, 2015 Perhaps like this ? http://www.babylonjs-playground.com/#1OCNMP#7 Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 14, 2015 Author Share Posted January 14, 2015 but then you get behavior like this http://www.babylonjs-playground.com/#1OCNMP#8 (press the fpsLabel haha) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 14, 2015 Share Posted January 14, 2015 And this one?http://www.babylonjs-playground.com/#1OCNMP#9 Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 14, 2015 Author Share Posted January 14, 2015 At that point I feel like it's just as clean then to do this: http://www.babylonjs-playground.com/#1OCNMP#10 Edit: Marking this as solved in reference to this solution and Detlakosh's example: http://www.babylonjs...d.com/#1OCNMP#9 . Either seem suitable, depending on preference. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 14, 2015 Share Posted January 14, 2015 Both work:) amorgan 1 Quote Link to comment Share on other sites More sharing options...
amorgan Posted January 16, 2015 Author Share Posted January 16, 2015 Unless you see a need or a performance advantage of babylon handling this, I will stick with the method above. Thanks for the help, it allowed me to eliminate some overhead on my animations. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 16, 2015 Share Posted January 16, 2015 Performance wise they should produce same outcome amorgan 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.