You are Here:Home>>Old Posts>>Tutorial | Working with Class Mirror in Away3D

Tutorial | Working with Class Mirror in Away3D

Carlos Pinho
By | 2008-06-09T22:39:55+00:00 Jun 9, 2008|Old Posts|

mirror2

After the some work on animation, I came back to the extrusions classes. The next one to be added to the growing collection is Mirror. This class allows you to mirror the geometry of a given object3D, that it’s an ObjectContainer with more Object3D nested inside of it or just one Object3D, the class will Mirror it! The Object3d is affected, no duplicated objects here.

It supports 3 options per axe: “x”, “x-“, “x+”, “y”, “y-“, “y+”, “z”, “z-“, “z+”;
The “axe” option mirrors according to 0 world on the given axe, the “-” mirrors on negative direction and “+” on positive direction.

The code is pretty easy to implement:

import away3d.extrusions.Mirror;
[..]
var sphere:Sphere = new Sphere({material:mat, segmentsH:6, segmentsW:6, radius:600});
Mirror.apply(sphere, "x");

There is even a third optional parameter if you want to recenter the pivot of the object.

mirror
Warning: this demo needs some CPU time to init!!!

The code of the swf above:

//bee is an AS3 model;
	bee = new Bee({scaling:.8, material:mat});
	var cont:ObjectContainer3D = new ObjectContainer3D(bee);
	this.scene.addChild(cont);
	Mirror.apply(cont, "x");
	Mirror.apply(cont, "y");
	Mirror.apply(cont, "z");
	Mirror.apply(cont, "z+");
	Mirror.apply(cont, "y+");
	Mirror.apply(cont, "x+", true);

However watch out the face count, the code is easy, those few lines are good for almost 36000 triangles in this case! Totally useless but I wanted to see if the code could handle it! Even if nested in groups.
This is a very bad example because the base model has already too much faces! Choose/build a base geometry according to idea/design.

I can imagine some cases where it can also save data… say you model half a human face, this feature is in many 3D app, you would need only to load half the face data and ask Away to mirror when loaded…

This class will land in the Away3D svn with the next update.

About the Author

Fabrice Closier is a Flash Developer, and belongs to the Away3D team. He run’s also a blog where you can view more tips and tutorials about this awesome Flash 3D Engine.

About the Author:

Carlos Pinho
A father, a husband and a geek... Carlos was the founder of projects like The Tech Labs and Flash Enabled Blog. He is the founder of TekTuts He is passionate about technologies. Their main skills are in analytics, transport & logistics, business administration. He also writes about programming resources, trends, strategy and web development.