topical media & game development
script-sandy-steve-Materials.ax
script-sandy-steve-Materials.ax
(swf
)
[ flash
]
package
{
//import flash.display.Sprite;
import flash.display.*;
import flash.events.*;
import flash.ui.*;
import flash.net.URLRequest;
import flash.text.*;
import sandy.core.data.*;
import sandy.core.Scene3D;
import sandy.core.scenegraph.*;
import sandy.materials.*;
import sandy.materials.attributes.*;
import sandy.primitive.*;
import sandy.util.*;
import sandy.events.*;
public class script-sandy-steve-Materials extends Sprite
{
private var scene:Scene3D;
private var camera:Camera3D;
private var object:Max;
private var plane:Plane3D;
private var text:TextField = new TextField();
private var app1:Appearance;
private var app2:Appearance;
private var app3:Appearance;
private var app4:Appearance;
private var app5:Appearance;
private var app6:Appearance;
private var app7:Appearance;
private var app8:Appearance;
private var active:Boolean = true;
private var destroy:Boolean = false;
public function script-sandy-steve-Materials() : void
{
// We create the camera
camera = new Camera3D( 400, 400 );
camera.x = 100;
camera.y = 50;
camera.z = -300;
camera.lookAt(0,0,0);
text.width = 200;
text.x = 15;
text.y = 15;
// We create the "group" that is the tree of all the visible objects
var root:Group = createScene();
// We create a Scene and we add the camera and the objects tree
scene = new Scene3D( "scene", this, camera, root );
Key.initialize(stage);
// Listen to the heart beat and render the scene
addEventListener( Event.ENTER_FRAME, loop3D );
}
// Create the scene graph based on the root Group of the scene
private function createScene():Group
{
// Create the root Group
var g:Group = new Group();
// the test object
object = new Max ("object");
plane = new Plane3D ("textPlane", 150, 150, 1, 1);
plane.rotateZ = 90;
plane.rotateY = 30;
plane.x = -220;
plane.y = 75;
plane.z = 200;
materials();
importTextures();
object.appearance = app1;
object.container.buttonMode = true;
g.addChild (object);
g.addChild (plane);
return g;
}
private function materials () : void
{
// define materials
var mat:MaterialAttributes = new MaterialAttributes (new LightAttributes (false, 0.3));
var matGouraurd:MaterialAttributes = new MaterialAttributes (new GouraudAttributes(false, 0.3), new LightAttributes (false, 3.0));
var matOutline:MaterialAttributes = new MaterialAttributes (new OutlineAttributes (1, 0xFF11FF, 1));
var material1:Material = new ColorMaterial(0x3344CC, 1, mat);
material1.lightingEnable = true;
app1 = new Appearance(material1);
var material2:WireFrameMaterial = new WireFrameMaterial(1, 0xCC0011, 1);
material2.lightingEnable = true;
app2 = new Appearance(material2);
var material3:OutlineMaterial = new OutlineMaterial(1, 0xFFFF00, 1);
material3.lightingEnable = true;
app3 = new Appearance(material3);
var material4:CelShadeMaterial = new CelShadeMaterial(0x00EE33, 1, 2, 0xFFFFFF,1);
material4.lightingEnable = true;
app4 = new Appearance(material4);
var material5:ZShaderMaterial = new ZShaderMaterial ();
material5.lightingEnable = true;
app5 = new Appearance(material5);
var material6:Material = new ColorMaterial (0xFFEE33, 1, matGouraurd);
material6.lightingEnable = true;
app6 = new Appearance(material6);
var material7:Material = new ColorMaterial (0x00AA33, 1, matOutline);
material7.lightingEnable = true;
app7 = new Appearance(material7);
}
public function importTextures() : void
{
var importer:Loader = new Loader();
importer.contentLoaderInfo.addEventListener(Event.COMPLETE, importCompleted);
importer.load(new URLRequest("../assets/student/steve/selection.png"));
}
public function importCompleted (event:Event) : void
{
var target = event.target;
var texture = target.loader.content.bitmapData;
app8 = new Appearance(new BitmapMaterial (texture));
plane.appearance = app8;
}
private function switchMat (event:KeyboardEvent) : void
{
switch(event.keyCode)
{
case Keyboard.F1:
object.appearance= app1;
break;
case Keyboard.F2:
object.appearance = app2;
break;
case Keyboard.F3:
object.appearance = app3;
break;
case Keyboard.F4:
object.appearance = app4;
break;
case Keyboard.F5:
object.appearance = app5;
break;
case Keyboard.F6:
object.appearance = app6;
break;
case Keyboard.F7:
object.appearance = app7;
break;
}
}
private function animate (event:Event) : void
{
if (active)
{
object.rotateX += 2;
object.rotateY += 2;
}
}
private function activate (event:KeyboardEvent) : void
{
if(Key.isDown(Keyboard.SPACE))
{
active = !active;
}
}
// The Event.ENTER_FRAME event handler tells the world to render
private function loop3D (event:Event) : void
{
object.container.addEventListener(KeyboardEvent.KEY_DOWN, switchMat);
stage.addEventListener(Event.ENTER_FRAME, animate);
stage.addEventListener(KeyboardEvent.KEY_DOWN, activate);
scene.render();
}
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.