Skip to content

Instantly share code, notes, and snippets.

@jaymzcd
Created February 26, 2010 10:39
Show Gist options
  • Save jaymzcd/315617 to your computer and use it in GitHub Desktop.
Save jaymzcd/315617 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onInit(event);" backgroundColor='0xFFFFFF' width="1100" height="800">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.materials.*;
import org.papervision3d.objects.primitives.Plane;
import nl.demonsters.debugger.MonsterDebugger;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.display.MovieClip;
import com.greensock.TweenLite
import com.greensock.easing.FastEase;
private var renderer:BasicRenderEngine = new BasicRenderEngine();
private var scene:Scene3D = new Scene3D();
private var camera:Camera3D = new Camera3D;
private var viewport:Viewport3D;
private var planes:Array = new Array();
private var angle:int = 0;
private var scale:Number = 1;
private var infoMat:ColorMaterial = new ColorMaterial(0x000000, 0.3);
private var main_plane:Plane;
private var prev_x:Number;
private var prev_y:Number;
private var txt:TextField = new TextField();
private var p:Plane;
private var debugger:MonsterDebugger;
private function slidePlane(p:Plane):void {
TweenLite.to(p, .666, {
x:-200
});
}
private function planeOver(e:InteractiveScene3DEvent) : void {
if(e.currentTarget.z == 0) {
e.currentTarget.z = -20; // drag it out a bit to stop it rotating
e.currentTarget.rotationZ = 0;
e.currentTarget.rotationY = 0;
e.currentTarget.scale = 1.5;
}
}
private function planeOut(e:InteractiveScene3DEvent) : void {
if(e.currentTarget.z == -20) {
e.currentTarget.z = 0;
e.currentTarget.scale = 1;
}
}
private function planePress(e:InteractiveScene3DEvent) : void {
planes.forEach(resetPlanes);
if(e.currentTarget.z == -300) {
TweenLite.to(e.currentTarget, .666, {
z:0,
rotationZ : 0,
rotationY : 0,
scale : 1,
x: prev_x,
y: prev_y
});
} else {
prev_x = e.currentTarget.x;
prev_y = e.currentTarget.y;
TweenLite.to(e.currentTarget, .666, {
z:-300,
rotationZ : 0,
rotationY : 0,
scale : 1,
x: 0,
y: 0,
onComplete: slidePlane,
onCompleteParams : [e.currentTarget]
});
}
}
private function LoadXML(e:Event):void {
var xmlData:XML = new XML(e.target.data);
var x_offset:int = -(stage.stageWidth/2);
var y_offset:int = (stage.stageHeight/4);
var cnt:int = 0;
for each(var shoe:XML in xmlData.shoe) {
var mat:BitmapFileMaterial = new BitmapFileMaterial(shoe.image.text());
mat.doubleSided = true;
mat.interactive = true;
var plane:Plane = new Plane(mat, 100, 100, 4, 4);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, planePress);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, planeOver);
plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, planeOut);
planes.push(plane);
plane.x = x_offset;
plane.y = y_offset;
scene.addChild(plane);
x_offset += 110;
cnt++;
if(cnt%10==0) {
y_offset -= 110;
x_offset = -(stage.stageWidth/2);
}
}
}
protected function onInit( event:Event ) : void {
debugger = new MonsterDebugger(this);
MonsterDebugger.trace(this, "starting up");
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("data.xml"));
viewport = new Viewport3D(canvasPv3D.width, canvasPv3D.height, true, true);
var uicomp:UIComponent = new UIComponent();
canvasPv3D.addChild( uicomp );
uicomp.addChild( viewport );
camera.z = -500;
main_plane = new Plane(infoMat, 3000, 3000);
main_plane.z = -100;
//scene.addChild(main_plane);
var tf:TextFormat = new TextFormat();
tf.size = 48;
tf.font = "Arial Black";
createTextPlane(680, 170, "NEW NIKE STOCK<br>CROOKEDTONGUES.COM", tf, AntiAliasType.NORMAL, true, true);
center_text.text = "NEW NIKE STOCK<br>CROOKEDTONGUES.COM";
text_size.value = 48;
canvasPv3D.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function createTextPlane(width:Number=100, height:Number=100, message:String="Text goes here", format:TextFormat=null, alias:String = AntiAliasType.NORMAL , transparent:Boolean = false, smooth:Boolean = false):void {
scene.removeChild(p);
var mc:MovieClip = new MovieClip();
txt.wordWrap = true;
txt.width = width;
txt.height = height;
txt.multiline = true;
txt.htmlText= message;
txt.autoSize = TextFieldAutoSize.CENTER;
if(format)
txt.setTextFormat(format);
txt.antiAliasType = alias;
mc.graphics.beginFill(0xFFFFFF, 0.333);
mc.graphics.drawRoundRect(0,0,width,height, 25, 25);
mc.graphics.endFill();
mc.addChild(txt);
var mat:MovieMaterial = new MovieMaterial(mc, transparent, false, true);
mat.doubleSided = true;
mat.smooth = smooth;
mat.tiled = true;
p = new Plane(mat, width/2, height/2);
p.z = -250;
scene.addChild(p);
}
private function onEnterFrame( event : Event ):void {
angle = (angle+5)%360;
planes.forEach(rotatePlane);
camera.rotationY = ( (mouseX-(stage.stageHeight /2) ) * 60 ) / (stage.stageHeight*10) ;
camera.rotationX = ( (mouseY-(stage.stageWidth/2) ) * 60 ) / (stage.stageWidth*10);
renderer.renderScene(scene,camera,viewport);
}
private function rotatePlane(element:*, index:int, arr:Array):void {
if (element.z == 0) {
element.rotationY = angle;
element.rotationZ = angle;
}
}
private function resetPlanes(element:*, index:int, arr:Array):void {
if(element.z < 0) {
TweenLite.to(element, 0.333, {
z : 0,
x: prev_x,
y: prev_y
});
}
}
private function changeText(event:Event):void {
var tf:TextFormat = new TextFormat();
tf.size = text_size.value;
tf.font = "Arial Black";
createTextPlane(680, 170, center_text.text, tf, AntiAliasType.NORMAL, true, true);
}
]]>
</mx:Script>
<mx:Box direction="vertical">
<mx:Box direction="horizontal" paddingTop="5" paddingLeft="5" width="100%">
<mx:TextInput id="center_text" width="300" />
<mx:HSlider id="text_size" width="200" maximum="72" minimum="8" snapInterval="1" tickInterval="6" labels="['8','72']" />
<mx:Button id="btn1" label="Update" click="changeText(event);" />
</mx:Box>
<mx:Canvas id="canvasPv3D" width="100%" height="100%"/>
</mx:Box>
</mx:Application>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment