Sets by cube
Display sets by cubes.
package {
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.*;
import flash.text.*;
import org.papervision3d.view.BasicView;
import org.papervision3d.materials.special.Letter3DMaterial;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.typography.Text3D;
import org.papervision3d.typography.fonts.HelveticaBold;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.stats.StatsView;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.core.render.filter.FogFilter;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.special.FogMaterial;
import org.papervision3d.core.effects.view.ReflectionView;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.PhongMaterial;
import org.papervision3d.view.layer.ViewportLayer;
import caurina.transitions.Tweener;
[SWF(frameRate='60', backgroundColor='#333333')]
public class FlashTest extends ReflectionView {
private var prod : Boolean = false;
protected var do3d:DisplayObject3D;
protected var cubes:Array = [];
protected var titles:Array = [];
protected var numItems:Number = 5;
protected var currentItem:Number = 3;
protected var angle:Number = 25;
protected var mat:PhongMaterial;
protected var materials:MaterialsList;
protected var light:PointLight3D;
public function FlashTest() {
if(!prod) initStats();
super(640, 480, true, true);
init();
}
protected function init():void
{
createChildren();
animate();
startRendering();
}
protected function createChildren():void
{
light = new PointLight3D();
light.x = 10;
light.y = 10;
mat = new PhongMaterial(light, 0x336699, 0x000000, 15);
mat.smooth = true;
mat.interactive = true;
materials = new MaterialsList();
materials.addMaterial(mat, "all");
do3d = new DisplayObject3D();
for (var i:int = 0; i < numItems; i++)
{
var cube:Cube = new Cube(materials, 200, 200, 200, 20, 20, 20);
cube.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, onCubeClick);
cube.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleOut);
cube.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleOver);
var textMaterial : Letter3DMaterial = new Letter3DMaterial(0xffffff);
textMaterial.doubleSided = true;
var title: Text3D = new Text3D("Set " + (i+1), new HelveticaBold(), textMaterial);
title.id = i;
cube.id = i;
titles.push(title);
cubes.push(cube);
do3d.addChild(title);
do3d.addChild(cube);
scene.addChild(do3d);
}
var plane:Plane = new Plane(new ColorMaterial(0x333333), 250, 250, 1, 1);
plane.y = 250;
plane.z = -1;
scene.addChild(plane);
//camera.zoom = 150;
}
protected function onCubeClick(evt:InteractiveScene3DEvent):void
{
currentItem = evt.target.id;
animate();
}
protected function animate():void
{
for(var n:uint = 0; n < titles.length; n++){
if(n == currentItem){
Tweener.addTween(titles[n], {y:-250, time:2, onStart:function():void{ titles[n].visible=true; }});
} else {
Tweener.addTween(titles[n], {y:250, time:1, onComplete:function():void{ titles[n].visible=false; }});
}
}
for (var i:int = 0; i < cubes.length; i++)
{
var cube:Cube = cubes[i];
var cubeX:Number = i*500;
var cubeZ:Number = i*1000;
//var cubeRotationY:Number = 0
/*
if (i == currentItem)
{
cubeZ = -300
Tweener.addTween(cube, {rotationY:cubeRotationY, x:cubeX, z:cubeZ, time:2});
}
if(i > currentItem)
{
cubeX = (i - currentItem + 1) * 180;
//cubeRotationY = angle + 10 * (i - currentItem);
Tweener.addTween(cube, {rotationY:cubeRotationY, x:cubeX, z:cubeZ, time:2});
}
if (i < currentItem)
{
cubeX = (currentItem - i + 1) * -180;
//cubeRotationY = -angle - 10 * (currentItem - i);
Tweener.addTween(cube, {rotationY:cubeRotationY, x:cubeX, z:cubeZ, time:2});
}
*/
//Tweener.addTween(do3d, {x:(i*100), time:2});
Tweener.addTween(cube, {x:cubeX, z:cubeZ, time:2});
if (i == currentItem)
{
//Tweener.addTween(viewport, {x:-cubeX, time:2});
}
}
}
private function handleOut(event : MouseEvent) : void
{
event.currentTarget.filters = null;
event.currentTarget.z -= 5;
}
private function handleOver(event : MouseEvent) : void
{
var filter:GlowFilter = new GlowFilter(0x336699, 0.5, 50, 50, 2, 1, false, false);
event.currentTarget.filters = [filter];
event.currentTarget.z += 5;
}
private function initStats() : void
{
var statsView : StatsView = new StatsView(renderer);
addChild(statsView);
}
}
}