Holomatix

Log In / Register


Blaze & ActionScript
From a Flash developer's perspective, Blaze brings realtime-rendered photo-realistic 3D into Flash through an extension to the MovieClip paradigm.

From an ActionScripter's perspective, the Blaze ActionScript extensions provide a set of additional classes and methods that allow programmatic control over the 3D elements in a scene.

Overview

It is not necessary to learn any Blaze ActionScript to view 3D content into an existing Flash presentation. A 3D model is loaded into a Flash presentation using the loadMovie() method of a MovieClip.

However, a mastery of the Blaze ActionScript Extensions will give you the ultimate in control of each and every aspect of a 3D scene, for example controlling the position of a 3D object, playing animations et cetera.

The basic component of a 3D scene is called a SceneObject. This is an instance of a 3D Model. SceneObjects can be attached to MovieClips (and to each other) to form a hierarchy. The instance objects can be referenced through ActionScript in just the same way as MovieClips.

Example

An example of a mobile phone will be used to illustrate Blaze 3D concepts. The main part of the phone is called the body. The body has a flip and an aerial attached to it. In the scene called "phone" there is the following hierarchy:

  body
  |      |
   flip    aerial

Loading a model

Having lit the 3D model and published from Blaze 3D Studio, you will have a 3D file named myProject.swf, according to the name of your 3D project. In Flash, this 3D .swf file can be loaded into a movieclip like a normal .swf file. In our example, if the movieclip were called mc1, then you would write:

mc1.loadMovie("phone.swf")

Any flash shapes which were previously inside the MovieClip will be replaced by a table with a lamp on it. The origin of the MovieClip in its parent MovieClip becomes the centre of projection for the 3d.

Referencing a 3d object

Once loaded, SceneObjects can be referenced through the MovieClip into which they were loaded. To store the aerial as a temporary variable, write:

aerialObject = mc1.body.flip;

Manipulating a 3d object

All SceneObjects have a property called matrix of class Matrix3d. This can be altered to move a 3d object around the scene. The full list of methods of Matrix3d is given in the Blaze ActionScript dictionary. As an example, to position the aerial relative to the body, you might use:

aerialObject.matrix.setTranslation(10, 0, 0);

The standard way of updating the view of the 3D object is to move the camera. The camera is returned by the method getCamera(), called on the MovieClip:

cameraObject = mc1.getCamera();

The camera is just another SceneObject:

cameraMatrix = cameraObject.matrix;
cameraMatrix.rotate(0, 90, 0);

The camera will move and the view will update. The default camera is put into the scene when the 3D is published from Blaze 3D Studio, but any SceneObject can be used as the camera position (see MovieClip.setCamera() in the ActionScript dictionary).

Changing the appearance of a 3d object

If a SceneObject represents a physical object (as opposed to a camera) then it has a property called model. A Model is split into parts known as triangle sets. These are not actionscript objects but can be passed as Strings to certain methods. The names of the triangle sets can be found in the 'Explorer' section of Blaze 3D Studio. Model has a method called getMaterial(String) which will return the material in use by the triangle set part of the model passed to it.

For example, the flip may have two triangle sets, called "buttonsTriangleSet" and "surroundTriangleSet". To access the material used by the buttons you would write:

flipObject = mc1.body.flip;
buttonsMaterial = flipObject.model.getMaterial("buttonsTriangleSet");

buttonsMaterial is a Material. A Material has one generic method called setData() which can be passed various parameters to alter the appearance of those triangle sets which use it. A full list is given in the Blaze ActionScript dictionary, but to change the texture map of the buttons (say, from "greenButtons.jpg" to "blueButtons.jpg") you would write:

buttonsMaterial.setData("texture", 1, "name", "blueShade.jpg");

The buttons will change from green to blue.

Playing an animation

A SceneObject may have animations defined for it. These will usually be set up in a package such as Maya or 3DS Max and imported into Blaze 3D Studio. They are instances of the class HAnim. They can be played and stopped from ActionScript and are defined from time 0 to time 1.

The aerial has an animation defined called extend:

extendAnim = aerialObject.extend;
extendAnim.play(0, 0);
extendAnim.play(1, 20);

The animation here is played to its 0 position over 0 frames (moves immediately) and then to its 1 position over 20 frames.

 
< Prev   Next >


© Copyright 2000-2010 Holomatix Ltd. All rights reserved.