Temporary repository for tutorial code ported to Sandy 1.2 ( AS2 ) The tutorial pages could be extended to include these 1.2 code versions, while keeping the 1.1 versions. The changes are not very complicated and has to do only with the new camera definition and the projection screen. ( I have made some changes to the Stage size and the camera position, just to get closer to the Box ). Here are the codes.
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200 ); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -200); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { ;// make you implementation here } // We lauch the animation creation. init();
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200 ); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -200); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { // We create our object. It is a cube of 50 pixels var o:Object3D = new Box( 50, 50, 50 ); // Now we simply link the Object leaf to the root node, and finish the tree creation bg.addChild( o); } // We lauch the animation creation. init();
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -200); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { // We create our object. It is a cube of 50 pixels var o:Object3D = new Box( 50, 50, 50 ); // We create the skin to change the box's appearance. // Here we are using the SimpleColor skin, which requires a fill color, an alpha, and a thickness. // I choose to make it a little bit transparent and red var skin:Skin = new SimpleColorSkin (0xFF0000, 80, 2); // Now we just have to apply the skin to the object. // The skin will be applied to all faces of the object o.setSkin (skin); // Now we simply add the Object to the root node, to finish the tree creation bg.addChild( o); } // We lauch the animation creation. init();
import sandy.core.light.*; import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -100); // we add the camera to the world World3D.getInstance().setCamera( cam ); //We create the Light coming from the left with a low intensity (20) var l:Light3D = new Light3D (new Vector (1, 0, 0), 20); // set the world light World3D.getInstance ().setLight (l); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene (bg:Group):Void { // We create our object. It is a cube of 50 pixels, and with the quad mode, so here four points per face. var o:Object3D = new Box (50, 50, 50, 'quad'); // we create a skin to "dress up " the object a bit, and make it visually better. // SimpleColor skin is used here, it needs the fill color, alpha, and thickness var skin:Skin = new MixedSkin (0x00FF00, 100, 0, 1); // We enable the light skin.setLightingEnable(true); // We apply the skin to the object o.setSkin (skin); // We create two TransformGroup instances. Each one corresponds to a node of the tree we are going to create. var tg1:TransformGroup = new TransformGroup (); var tg2:TransformGroup = new TransformGroup (); // We also create two instances of Translation objects. // Give them an appropriate name, this becomes important very rapidly. var translation:Transform3D = new Transform3D (); // We create an interpolator to make it rotate linearly for a while var ease:Ease = new Ease (); ease.linear (); var rotint:RotationInterpolator = new RotationInterpolator (ease.create (), 300); // we translate the object by 500 pixels on the Z axis. translation.translate (0, 0, 200); // We apply those transformations to the nodes. tg1.setTransform (translation); tg2.setTransform (rotint); // We add the rotation tansformation to the node which represents the rotation,by setting it as a child. // The rotation will be applied first, translation later (higher in the tree) tg2.addChild (o); // Now we link the two nodes // The order here is very important. tg1.addChild (tg2); // Now we simply link the translation node to the root node, thus completing the tree creation bg.addChild (tg1); } // We launch the animation creation. init ();
import sandy.core.data.*; import sandy.core.group.*; import sandy.primitive.*; import sandy.view.*; import sandy.core.*; import sandy.skin.*; import sandy.util.*; import sandy.core.transform.*; import sandy.events.*; function init( Void ):Void { // we create our camera var cam:Camera3D = new Camera3D( 200, 200); // we move the camera backward to be able to see the object placed at 0,0,0 cam.setPosition(0, 0, -100); // we add the camera to the world World3D.getInstance().setCamera( cam ); // we create the root node. var bg:Group = new Group(); // and set it as the root node of the world. World3D.getInstance().setRootGroup( bg ); // and we lauch the scene creation createScene( bg ); // and now that everything is created, we can launch the world rendering. World3D.getInstance().render(); } function createScene( bg:Group ):Void { // nous créons notre objet. Pour cela nous utilisons ici la primitive box. // cela créé une boite qui, dans le cas où les dimensions d'hauteur, profondeur, largeur, sont les memes // genère un cube. Ici nous crééons donc un cube de 50 pixels. var o:Object3D = new Box( 50, 50, 50 , 'quad'); // on créé un skin qui va permettre d'habiller un peu mieux notre objet 3D. // ici le skin SimpleColor qui demande une couleur de replissage, la valeur de l'alpha et l'épaisseur du trait. var skin:Skin = new MixedSkin( 0x00FF00, 100, 0, 100 ); // on applique le skin sur l'objet. o.setSkin( skin ); // Nous crééons deux transform Group différents. Chacun correspondant à un noeud de la branche de transformations // que nous voulons creer. var tg1:TransformGroup = new TransformGroup(); var tg2:TransformGroup = new TransformGroup(); // Nous créeons de même deux instances de la classe Transform3D. // Profitons-en d'ailleurs pour commencer à nommer nos variables correctement. Vous le verrez ceci // deviens vite très important var translation:Transform3D = new Transform3D(); var rotation:Transform3D = new Transform3D(); // translation de 200 pixels dans l'axe des Z. translation.translate( 0, 0, 200 ); // Rotation de 30 degrés autours de l'axe defini par le vector 1, 1, 1 //( ce qui correspond à une rotation équivalente dans les 3 dimensions ) rotation.rotAxis( new Vector(1,1,1), 30); // Nous appliquons ces transformations aux noeuds tg1.setTransform( translation ); tg2.setTransform( rotation ); // nous ajoutons notre objet comme enfant du noeud correspondant à la rotation. // l'opération de rotation lui sera donc appliquée avant celle de translation tg2.addChild( o ); // Maintenant nous relions nos deux noeuds, en mettant la translation en opération parent à celle de rotation. // Cet ordre est très imporant selon le résultat voulu! tg1.addChild( tg2 ); // nous ajoutons le transformGroup comme filds du BranchGroup afin de créer l'arborescence //et rendre l'object affichable. bg.addChild( tg1 ); } // Nous lançons la création du monde 3D init();