MovieClip Material

Software: Away3D 4.x

sadmonster, Newbie
Posted: 19 January 2016 12:48 PM   Total Posts: 2

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 0totFramesi++)
   
{
    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_FRAMEupdateMaterial);
   
   var 
cnt:int 0;
   
   function 
updateMaterial(event:Event) :void
   {
     
if(cnt textures.length 1cnt++;
     else 
cnt 0;
     
texture textures[cnt];
   
}
  }
  
  
private function resizeBitmapData(bmData:BitmapDatabmdWidth:NumberbmdHeight:Number):BitmapData 
  {
    
var mat:Matrix = new Matrix();
    
mat.scale(bmdHeight/bmData.widthbmdHeight/bmData.height);
    var 
bmd:BitmapData = new BitmapData(bmdWidthbmdHeight,true,.5);
    
bmd.draw(bmDatamatnullnullnulltrue);
    return 
bmd;
  
}
  
  
public function stop() :void
  {
   isPlay 
false;
  
}
  
  
public function play() :void
  {
   isPlay 
true;
  
}
 }
 
   
   
‹‹ MovieClip Material

X

Away3D Forum

Member Login

Username

Password

Remember_me



X