Erain 3D
advert here

Level: Beginner Version : 2.0 Author : Thomas PFEIFFER Date : October 09 2007


Starting with Sandy 2.0 for AS2

Sandy 2.0 application is completely different than the previous 1.x one.

Conceptually, it is very similar. Better, it is a lot simpler now ;-) Many of you have been afraid by the previous version. Sure it required a kind of learning. Now the learning phasis becomes a lot shorter.

Ok let's go, see how to build a basic Sandy 2.0 application. First we need to have a container.

var myContainer:MovieClip = _root.createEmptyMovieClip("sandyScene", 0 );
World3D.getInstance().container = myContainer;

After that, we need to initialize our application. Mainly the World3D object which must have some properties correctly set : camera, root node and container.

// Initialize the world
function init( Void ):Void
{
	World3D.getInstance().root = _createScene();
        // we create the camera. It is very important to pass correct values as viewport dimension. Usually your swf dimension for a simple demo.
	var myCamera:Camera3D = new Camera3D( 500, 500 );
	World3D.getInstance().camera = myCamera;
	World3D.getInstance().root.addChild( myCamera );		
        // we need to call ourself now the render method.
        // Here we use the enterframe event, using a Delegate command.
	myContainer.onEnterFrame = Delegate.create( this, onRender );
}

As you have seen, this time we do not use an event system to render the world3D. The way to render the 3D scene is up to you. Use a setInterval, an onEnterFrame handler, something more complex which fits the client CPU capacity, it is up to you.

Ok, now the most important part, the creation of your scene. Once again, it is very simple. In this case, we have a box, with a basic Color material.

// Create the object tree
function createScene( Void ):Group
{
	var g:Group = new Group("root");
	// we create the box
	var myBox:Box = new Box( "myBox", 100, 100, 100 );
        // we set its position, lot simpler isn't it? 
	myBox.x = 10;
	myBox.y = -20;
	myBox.z = 300;
	// we apply the bitmap appearance
	myBox.appearance = new Appearance( new ColorMaterial( 0xFF0000, 0 ) );
	// link the object to the group to make it displayable.
	g.addChild( myBox );
	return g;
}

Ok, we have correctly initialized our scene, we have an object inside, let's render !!

// we render the world
function _onRender( Void ):Void
{
	World3D.getInstance().render();
}

That's all. You finally have your box displayed on the screen.

A Sandy3D 2.0 AS2 application is that simple now 8-)