gryff Posted June 4, 2014 Share Posted June 4, 2014 In my past two experiments with animation I have been using bones/rigs, but Blender is capable of animations without rigs. So we have experiment 3: The Doors A simple scene - a wall and 3 coloured doors. When the scene opens you will see all three doors go through an open/close cycle. The blue and the green doors keep animating, the red door just goes through one cycle. The starting and looping of the animations seems to be controlled by this code in the babylon file"autoAnimate":true,"autoAnimateFrom":0,"autoAnimateTo":60,"autoAnimateLoop":trueIn an effort to stop the red door animating I added this code to the scene loader:theDoor = newScene.getMeshByName("door_l");myAnim[0] = theDoor.animations[0];myAnim[0].autoAnimate = false;myAnim[0].autoAnimateLoop = false;myAnim[0].loopMode = 2;The web console printout shows that "autoAnimate" and "AutoAnimateLoop" are being set to false (see image), but despite this the red door loops once and the only code stopping it from behaving in the same manner as the blue and green door is setting the "loopMode" to 2; Now I can stop all the animations from starting by editing the babylon file and setting "autoAnimate" to false. No problem in this simple scene - but when I have bigger babylon files it gets a little trickier. What am I doing wrong? Any thoughts greatly appreciated. cheers, gryff Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2014 Share Posted June 4, 2014 Hello Gryff, the autoXXX properties are just used by the loader, If you want to stop or start an animation, just call the following code:scene.beginAnimation(mesh, 0, 100)orscene.stopAnimation(mesh) Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 4, 2014 Share Posted June 4, 2014 Gryff... is 'The Doors' link in your post... properly url'd? Also, I suspect that DK has mis-understood the inconsistency you are seeing, but i will leave that adjusting to you, G-man. Quote Link to comment Share on other sites More sharing options...
gryff Posted June 4, 2014 Author Share Posted June 4, 2014 TY Wingy - url is fixed. Yesterday was not a good day. cheers, gryff Quote Link to comment Share on other sites More sharing options...
gryff Posted June 4, 2014 Author Share Posted June 4, 2014 I tried DK's suggestion and changed my loading code to :theDoor = newScene.getMeshByName("door_l");newScene.stopAnimation(theDoor); It works fine. I guess I thought I was being clever trying to access the "AutoAnimate" and "AutoAnimateLoop" parameters - and by doing so, overlooked the obvious. TY DK for pointing out the obvious to me. Now I can experiment some more with the "doors" By the way, One of the benefits of building the "doors" this way in Blender is it allows me to easily set the pivot point - and I see possibilities of a reduction in babylon file size (more to come). cheers, gryff Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2014 Share Posted June 4, 2014 The fault is mine if this kind of things need to be explained Quote Link to comment Share on other sites More sharing options...
gryff Posted June 4, 2014 Author Share Posted June 4, 2014 Nah DK - just me being dumb. I'm trying to understand the possibilities of Blender and .babylon file export. I've chosen to look at animation - beyond bouncing balls and cubes - right now to see what optimizations are possible - and hopefully other people will benefit from my experiments. I will be adding more to this thread. cheers, gryff Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 5, 2014 Share Posted June 5, 2014 So, umm, gryff... those doors were animated within Blender, yes? (and without rigging, but that's not important for what I am about to talk about.) So, then, somewhere in the sceneLoader or sometime before you start the rendering... you do this... (var) theDoor = newScene.getMeshByName("door_l"); Good. And then you could do alert(theDoor) or console.log(theDoor) to make sure you got a handle/ref to the red door. then... you do... (var) myAnim[0] = theDoor.animations[0]; Cool, but it probably should have been... (var) myDoorAnimArray = theDoor.animations; That would make a copy of the door's 'array of Babylon animation objects'. Likely, that is rarely necessary for any reason... but its good demented experimenting... what the hell, eh? One thing that would be interesting... is to see HOW MANY Babylon animation objects are stored inside the door's animation array. I think you can get that number... with console.log(theDoor.animations.length) see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length I think... somemesh.animations array... ONLY stores babylon animation objects... http://doc.babylonjs.com/page.php?p=24666 That is the world famous babylon animation object... with all of its bells and whistles. (knobs) So... if you wanted to go whacking on an object's Blender-built animation... after its been loaded into BJS, but before the scene starts rendering... you would probably want to follow the methods and properties of a babylon animation object (url above). So lets say there IS a babylon animation object STORED in theDoor.animations array... after the load. Prove that to yourself with: var theDoor = newScene.getMeshByName("door_l");console.log(theDoor.animations[0]); It should return [object] if there is a babylon animation object in slot 0 of that array'o'animation objects. Look at that page once more. See the 'constructor' for a babylon animation object up at the top of the list there? new Animation(name, targetProperty, framePerSecond, dataType, loopMode) Look at that... animations have NAMES. So, during the scene loading, the .babylon file parser probably saw an animation present on door_l... and had to 'construct' a babylon animation object and shove it into door_l.animations array. I wonder what it NAMED that object when it constructed it and pushed it into slot [0] of the array. Lets find out. var theDoor = newScene.getMeshByName("door_l");console.log(theDoor.animations[0].name); While we're at it, lets 'peek' its dataType... var theDoor = newScene.getMeshByName("door_l");console.log(theDoor.animations[0].dataType); Let's peek the targetProperty... var theDoor = newScene.getMeshByName("door_l");console.log(theDoor.animations[0].targetProperty); And lets peek its loopMode... var theDoor = newScene.getMeshByName("door_l");console.log(theDoor.animations[0].loopMode); If its a simple number... then let's CHANGE (poke) the loopMode... var theDoor = newScene.getMeshByName("door_l");theDoor.animations[0].loopMode = 1; And lets peek the loopMode again to make sure the poke worked... var theDoor = newScene.getMeshByName("door_l");console.log(theDoor.animations[0].loopMode); Back to the page for babylon animation objects... see the properties that are labeled 'static'? That means that they can be PEEKed (console.log their values) but not POKEd (not changeable) There is a powerful 'method' that can be 'called' (runned). animate(target, delay, from, to, loop, speedRatio) . Click on it in the list, and it will show what kind of values it needs in its args/parameters. Object for the first arg, numbers for the next three args, boolean for the fifth arg, and a number for the sixth arg. var theDoor = newScene.getMeshByName("door_l");theDoor.animations[0].animate(theDoor, 0, 0, 100, true, 5); I'm just guessing at the settings. Its a place for mad sceintist play, that's for sure. Want to know another little fun secret? clone() So, before you start making a mess of an animation, you could clone it for safe keeping. var theDoor = newScene.getMeshByName("door_l");var myOriginalAnimationObj = theDoor.animations[0].clone(); Now be a mad scientist and screw up the animation object in slot 0 by doing a bunch of retarded... theDoor.animations[0].animate(whatever, whatever, whatever, whatever, whatever, whatever); Need to get it back to sanity? var theDoor = newScene.getMeshByName("door_l");theDoor.animations[0] = myOriginalAnimationObj; Ahh, back to the safety of square one. But you would probably just keep reloading the scene. But you can also repeatedly call the animate method right from the console input line. Just type... var theDoor=engine.scenes[0].getMeshByName("door_l");theDoor.animations[0].animate(theDoor, 0, 0, 100, true, 5); (then hit enter) Then watch what happens, then up-cursor, make some adjustments, and hit enter again, and again, and again, never needing to reload the scene. Or... got some buttons with position: fixed; at the top or bottom of the screen... for beginAnimation and stopAnimation and runMyDementedAnimateFunction? Huh? Why not? C'MON! So, there you go. You know how to peek properties on a babylon animation object that was made automatically during a scene loading, and you know how to poke values into non-static properties of it, as well. You know how to 'call' the animate() function on a babylon animation object, and you also know how to call the clone() method to keep your nuts from slipping into a vice. There is a third method... setKeys(values). Visit the animation tutorial if you want to do mad scientist experiments... on that method (to learn what values are expected inside a setKeys call). You have everything you need... in this post... to get totally out of control. Ain't it great? I hope this long miserable post helps you think up some crazy ideas to torture babylon animation objects that might reside in theDoor.animations[0]. Be well... cool experiments, gryffster! Keep us posted. PS: The terms 'peek' and 'poke' are from the OLD days of programming in a language called BASIC. These days, it is called getting and setting... but I like to live in the past. heh Quote Link to comment Share on other sites More sharing options...
gryff Posted June 8, 2014 Author Share Posted June 8, 2014 Thanks for your thoughtful response Wingy - have saved it as a text file into my "Wingnut" directory where I keep a lot of your stuff from the "Chronicals" and "Tutorials". I even played with one of your thoughts, the cloning of animations, and tried it out on another, new, feature - instancing but that is another story. Just so you know, I normally have the page open all the time - in a tab right right next to a tab with this forum and the babylon.js github ;-) As you know, I have experimented a lot with animations and for this "doors" test I have 4 different index pages that I tried all kinds of code on to stop that autoAnimate feature:"autoAnimate":true,"autoAnimateFrom":0,"autoAnimateTo":60,"autoAnimateLoop":true,I did a lot of "Peeking" and "Poking" trying to get a handle on it .About the only thing I did not try was "scene.stopAnimation". "Console.log" is probably my most frequently typed line of code. But, provided the file is not too large, I also look in the babylon file itself - it helps me understand what is going on too. For example, the babylon file for the desk with an armature is 339kb in size, whereas the file for the desk with no armature is 119kb in size. My immeadiate thought was why? Well obvious the armature has to be in the .babylon file, but looking at the two files another major difference shows up: Desk with rig is including every frame: {"frame":1,"values":[0.0091,1.0000,0.0000,0.0000,-1.0000,0.0091,-0.0000,0.0000,-0.0000,-0.0000,1.0000,0.0000,0.9675,0.3945,0.4897,1.0000]},{"frame":2,"values":[0.0091,1.0000,-0.0001,0.0000,-0.9999,0.0091,0.0134,0.0000,0.0134,-0.0000,0.9999,0.0000,0.9675,0.3945,0.4897,1.0000]},{"frame":3,"values":[0.0091,1.0000,-0.0005,0.0000,-0.9985,0.0091,0.0543,0.0000,0.0543,-0.0000,0.9985,0.0000,0.9675,0.3945,0.4897,1.0000]},{"frame":4,"values":[0.0090,1.0000,-0.0011,0.0000,-0.9924,0.0091,0.1230,0.0000,0.1230,-0.0000,0.9924,0.0000,0.9675,0.3945,0.4897,1.0000]},....{"frame":28,"values":[0.0091,1.0000,-0.0004,0.0000,-0.9988,0.0091,0.0472,0.0000,0.0472,-0.0000,0.9989,0.0000,0.9675,0.3945,0.4897,1.0000]},{"frame":29,"values":[0.0091,1.0000,-0.0001,0.0000,-0.9999,0.0091,0.0117,0.0000,0.0117,-0.0000,0.9999,0.0000,0.9675,0.3945,0.4897,1.0000]},{"frame":30,"values":[0.0091,1.0000,0.0000,0.0000,-1.0000,0.0091,-0.0000,0.0000,-0.0000,-0.0000,1.0000,0.0000,0.9675,0.3945,0.4897,1.0000]},But desk with no rig includes only frames that I set (plus a couple of extras!). No rig Desk"keys":[{"frame":0,"values":[-0.0000,-0.0041,-0.0000]},{"frame":1.0,"values":[-0.0000,-0.0041,-0.0000]},{"frame":30.0,"values":[-0.0000,-1.5670,-0.0000]},{"frame":60.0,"values":[-0.0000,-0.0000,-0.0000]},{"frame":60,"values":[-0.0000,-0.0000,-0.0000]}]Curiously the export from Blender added a frame0 and a duplicate of frame60. And the name I gave a particular animation in Blender like "open_lc" (to open left cupboard) does not show up in the .babylon file. Anyway, I will continue to experiment - keeping my local copy of your post open while I work. cheers, gryff Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 9, 2014 Share Posted June 9, 2014 Cool, gryff, thanks for that info. Interesting! Nico is working on a .babylon file parser... and talking about it in another thread. And our sceneLoader is really a .babylon file parser, as well (duh?). Eventually, I would love to get Nico's heavily-commented code/results, and then I can use my almost-tolerable skills with dynamic html... to make a HTML viewer for .babylon files. You know, something happy, with tutti fruitie colors that makes looking inside .babylon files... an enjoyable experience. Them .json-based .babylon files can get a little large, though. And once a guy wraps html tags around a bunch of data contained in those files, that can make for one friggin' huge web page... maybe much too large for a browser... especially if the scene is full of complex models. That might cause my idea to be null and void. Thanks for the kind words and informative post, gryffenheim! You are getting to be a God of the Exporter, yes sir. 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.