Away3D 3.6: Applying Animated and Composite materials

0
89
3 min read

 

Away3D 3.6 Essentials

Away3D 3.6 Essentials

Take Flash to the next dimension by creating detailed, animated, and interactive 3D worlds with Away3D

        Read more about this book      

(For more resources on 3D, see here.)

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;
}

Away3D 3.6: Applying Animated and Composite materials

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 3.6: Applying Animated and Composite materials

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 3.6: Applying Animated and Composite materials

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 3.6: Applying Animated and Composite materials

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here