A helper object for scripting reusable keyframe-based animations.
animator | A helper object for scripting reusable keyframe-based animations. |
Preference Dialog | None. |
Comments | The animator assists you in scripting a reusable keyframe-based animation. |
Properties | |
interpolationType | const, ( r, w ) |
length | float, ( r, w ) |
keyType | const, ( r, w ) |
align | bool, ( r, w ) |
timeScale | float, ( r, w ) |
dim | object, ( r, w ) |
rpos | float [0, 1], ( r, w ) |
rori | float [0, 1], ( r, w ) |
rscl | float [0, 1], ( r, w ) |
keys | array, ( r ) |
Functions | |
addKey | |
apply | |
remove |
The animator assists you in scripting a reusable keyframe-based animation. Once complete, you can apply the resulting animation to any 3D entity OR object with numerical properties.
Here is an annotated example code that uses both animator and replicator to animate a swarm of cubes.
var r = new animator(); r.interpolationType = animator.LINEAR;
// not specifying rot and scl means they will stay // the same as previous values, in this case, the initial valus. var k = r.addKey(); k.time = 0.5; k.position = {x:0,y:300,z:0};
k = r.addKey(); k.time = 1.5; k.position = {x:200,y:300,z:0}; k.scale = {x:0.2,y:0.2,z:0.2};
k = r.addKey(); k.time = 2.0; k.position = {x:200,y:300,z:500}; k.rotation = {x:0,y:90,z:0};
// leaving the last pos, scl, rot undefined // means it will loop back to settings at time 0.0 k = r.addKey(); k.time = 2.5;
// add large randomenss to its movement including // position, rotation, and scale in all 3 dimensions. r.dim = {x:350,y:350,z:350}; r.rpos = {x:0.9,y:0.9,z:0.9}; r.rori = {x:0.9,y:0.9,z:0.9}; r.rscl = {x:0.9,y:0.9,z:0.9};
// now replicate a cube manualobject molecule. // first hide the original cube. // The replication works as follows: // a grid of 7x7 with 49 cells is introduced // on the xz plane with origin at (0, 200, 0). // Each cell has dimension (300, 300, 300). // the cube is randomly placed in the cell // with amount of randomness (0.2, 0.6, 0.2). // Finally call run() to start the replication.
var rp = new replicator(this.cube); this.cube.hide(); rp.origin = {x:0,y:200,z:0}; rp.mul = {x:7,y:1,z:7}; rp.dim = {x:300, y:300, z:300}; rp.rpos = {x:0.2,y:0.6,z:0.2}; rp.run();
// Apply the animation to each of the 49 cubes. // Use replicator.access() to get to each cube by index. // and animator.apply() to obtain its animation track. // finally call track.play(true) to play the animation in a loop.
for (var i=0; i<49; i++) { var a = r.apply(rp.access(i)); a.play(true); }
bool, ( r, w )
Align object’s direction to the animation path. If object’s direction is not defined, use local z-dir instead.(see Mesh Molecule.direction.)
array, ( r )
Returns an array of keyframes for this animation.
apply(entity);
Apply this animation to either a mesh, manualobject, light, or particle molecule or any javascript object containing animatable numerical properties.
entity | (object) a mesh, manualobject, light, or particle molecule or object with animatable properties. (e.g. {strength: 0.2}.) |
(object) | an animation track. |