Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon

Away3D 3.6: Applying Animated and Composite materials

Save for later
  • 3 min read
  • 04 Mar 2011

article-image

 

Away3D 3.6 Essentials




away3d-36-applying-animated-and-composite-materials-img-0 Take Flash to the next dimension by creating detailed, animated, and interactive 3D worlds with Away3D




       

Animated materials


As mentioned above a number of materials can be used to display animations on the surface of a 3D object. These animations are usually movies that have been encoded into a SWF file. You can also display an interactive SWF file, like a form, on the surface of a 3D object.

MovieMaterial


The MovieMaterial displays the output of a Sprite object, which can be animated. The sprite usually originates from another SWF file, which in this case we have embedded and referenced via the Bear class. A new instance of the Bear class is then passed to the MovieMaterial constructor.

protected function applyMovieMaterial():void
 {
 initCube();
 materialText.text = "MovieMaterial";
 var newMaterial:MovieMaterial =
 new MovieMaterial(new Bear());
 currentPrimitive.material = newMaterial;
 }

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime

away3d-36-applying-animated-and-composite-materials-img-1


The MovieMaterial class extends the TransformBitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the TransformBitmapMaterial are also valid for the MovieMaterial.

away3d-36-applying-animated-and-composite-materials-img-2


AnimatedBitmapMaterial


The AnimatedBitmapMaterial class displays the frames from a MovieClip object. In order to increase performance, it will first render each frame of the supplied MovieClip into a bitmap. These bitmaps are stored in a cache, which increases playback performance at the cost of using additional memory.

Because of the memory overhead resulting from this cache, the AnimatedBitmapMaterial cannot be used to display movie clips longer than two seconds. If you pass a movie clip longer than two seconds an exception will be thrown.

The MovieClip object, passed to the AnimatedBitmapMaterial constructor, usually originates from another SWF file. This source SWF file needs to be implemented in the ActionScript Virtual Machine 2 (AVM2) format, which is the format used by Flash Player 9 and above. This is an important point, because a large number of video conversion tools will output AVM1 SWF files.

If you need to display a SWF movie in AVM1 format, use MovieMaterial class instead.


If you try to use an AVM1 SWF file with the AnimatedBitmapMaterial class, an exception similar to the following will be thrown:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::
AVM1Movie@51e8e51 to flash.display.MovieClip
.

FFmapeg is a free, cross-platform tool that can be used to convert video files into AVM2 SWF files. It can be downloaded from , and precompiled Windows binaries can be downloaded from http://sourceforge.net/projects/mplayer-win32/files/FFmpeg/. The following command will convert a WMV video into a two second AVM2 SWF file with a resolution of 320 x 240 without any audio.


ffmpeg -i Butterfly.wmv -t 2 -s 320x240 -an -f avm2 Butterfly.SWF


protected function applyAnimatedBitmapMaterial():void
 {
 initCube();
 materialText.text = "AnimatedBitmapMaterial";
 var newMaterial:AnimatedBitmapMaterial =
 new AnimatedBitmapMaterial(new Butterfly());
 currentPrimitive.material = newMaterial;
 }


The AnimatedBitmapMaterial class extends the TransformBitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the TransformBitmapMaterial are also valid for the AnimatedBitmapMaterial.

away3d-36-applying-animated-and-composite-materials-img-3


Interactive MovieMaterial


By setting the interactive parameter to true, a MovieMaterial object can pass mouse events to the Sprite object it is displaying. This allows you to interact with the material as if it were added directly to the Flash stage while it is wrapped around a 3D object.

protected function applyInteractiveMovieMaterial():void
 {
 initCube();
 materialText.text = "MovieMaterial - Interactive";
 var newMaterial:MovieMaterial =
 new MovieMaterial(new InteractiveTexture(),
 {
 interactive: true,
 smooth: true
 }
 );
 currentPrimitive.material = newMaterial;
 }

away3d-36-applying-animated-and-composite-materials-img-4


Refer to the previous table for the MovieMaterial class for the list of constructor parameters.