Tuesday, January 26, 2010

Run Multiple Collada Animations at once

I tweaked the Away3d SkinAnimation class to allow me to run multiple animations at once(as long as they don't effect the same bones). So for instance you could have a walking animation with the legs moving, while you animate a hand waving animation. Here is the code you will need to replace in your SkinAnimation class*:

*Note, you will need to update the IMeshAnimation Interface class, to change the update definition to:
function update(time:Number, interpolate:Boolean = true, onlyChannels:Array = null):void;

* Updates all channels in the animation with the given time in seconds.
* @param time Defines the time in seconds of the playhead of the animation.
* @param interpolate [optional] Defines whether the animation interpolates between channel points Defaults to true.
* @param onlyChannels [optional] Will only update the channels whose name contain part of the strings in this array. If this value is null, all channels will be updated
public function update(time:Number, interpolate:Boolean = true, onlyChannels:Array = null ):void
if (time > start + length ) {
if (loop) {
time = start + (time - start) % length;
time = start + length;
} else if (time < time =" start" time =" start;" onlychannels ="="" uint =" 0;">= 0)
return true;
return false;

Friday, November 13, 2009

Speed Up an Unchanged Away3d Scene

Have you have ever noticed your Away3d scene eating up the clock cycles even though the scene has not changed? There may be a very good reason for this... well an annoying reason for this might be a more accurate.

Say you are updating an objects orientation on every update:
plane.rotationX = 240;

Because of the in-preciseness of floating point numbers, this object's rotationX might be set to something very close, but not quite the same as the value before, such as 239.99999999999997. Then on the next update you are setting it to 240 again, and because this is ever so slightly different than the last number, Away3d will re-render the whole part of the that scene. This is unnecessary work, and can cause problems in a mixed flash/html site, where the rest of the site will run more slowly when the flash piece is not even moving or being interacted with.

Here is a way to check if you do indeed need to update a object's value:
 function setIfChanged( target, variable:String, value:Number, precision:Number = 0.001 ) {  
// checks if the new value is within a certain precision "distance" from the other
if ((Math.abs(target[variable - value) < Math.abs(precision)) == false)
target[variable] = value;
// use the above function to check if it is really a new value
setIfChanged(plane, "rotationX", 240);

If you use this method to check items you are updating on often (like on every Enter Frame), it will only re-render what it needs to, and when it doesn't it will run much faster and not slow down the rest of the site.

Wednesday, January 7, 2009

Away3d - Tween Filters

I had read that there was no way to tween filters in Away3d using one of the convenient Tweening Engines like TweenLite. It is true that you cannot Tween the filters using the tweening engines built-in filter tweening, but I have found an easy way around this. All you have to do is tween the properties in the Filters array.

For example:

// cube can be any Object3D object
cube.filters = [ new GlowFilter(0xFFFFFF, 1, 12, 12, 0), new GlowFilter(0x00FFFF, 1, 21, 21, 0) ];

TweenLite.to( cube.filters[0], 1, { strength:2.4 } );
TweenLite.to( cube.filters[1], 1, { strength:1.3 } );

Friday, August 22, 2008

Create Custom Tween's for TweenLite

I wanted an easy way to create custom tweens with a visual guide, much like you can with LMC Tween and Fuse. Since I couldn't find anything out there that provided this I decided to create my own.

Here is the link http://rokkan.com/testing/tween/rokkan_bezierdefiner.swf .

To use this program I recommend downloading the accompanying class ZigoTween.as .

Example of creating a custom tween:

var zt:ZigoTween = new ZigoTween([{Mx:0,Nx:0,Ny:-1000,My:0,Px:500,Py:500},{Mx:500,My:-500}] );

This example assumes you have imported the ZigoTween.as class.

If anybody can help me make this a custom Flash Panel I would appreciate the help.