Hi, gyus. Here is a animated material for away 4. May be somebody would need it. Or maybe you can improve performance of code, let me know.
package core
{
import flash.display.MovieClip;
import away3d.materials.TextureMaterial;
import flash.display3D.textures.Texture;
import flash.display.BitmapData;
import away3d.utils.Cast;
import flash.events.Event;
import flash.filters.BitmapFilter;
import away3d.textures.BitmapTexture;
import flash.display.Bitmap;
import away3d.tools.utils.TextureUtils;
import flash.geom.Matrix;
public class AnimMaterial extends TextureMaterial
{
private var isPlay:Boolean = true;
public function AnimMaterial(animationArg:MovieClip)
{
var totFrames:int = animationArg.totalFrames;
var textures:Vector.<BitmapTexture> = new Vector.<BitmapTexture>();
for(var i:int = 0; i < totFrames; i++)
{
alphaThreshold = .5;
animationArg.gotoAndStop(i);
var textureData:BitmapData = new BitmapData(256,256,true,.5);
textureData = Cast.bitmapData(animationArg);
var tempTex:BitmapTexture = Cast.bitmapTexture(resizeBitmapData(textureData,512,512));
textures.push(tempTex);
}
animationArg.addEventListener(Event.ENTER_FRAME, updateMaterial);
var cnt:int = 0;
function updateMaterial(event:Event) :void
{
if(cnt < textures.length - 1) cnt++;
else cnt = 0;
texture = textures[cnt];
}
}
private function resizeBitmapData(bmData:BitmapData, bmdWidth:Number, bmdHeight:Number):BitmapData
{
var mat:Matrix = new Matrix();
mat.scale(bmdHeight/bmData.width, bmdHeight/bmData.height);
var bmd:BitmapData = new BitmapData(bmdWidth, bmdHeight,true,.5);
bmd.draw(bmData, mat, null, null, null, true);
return bmd;
}
public function stop() :void
{
isPlay = false;
}
public function play() :void
{
isPlay = true;
}
}
}