/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
// _______________________________________________________________________ HelloWorld
// This example creates a basic scene with
// a plane primitive and a loaded sphere.
package
{
import flash.display.Sprite;
import flash.display.LoaderInfo;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;
// Import Papervision3D
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.Ase;
import org.papervision3d.objects.Cube;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.MaterialsList;
public class main extends Sprite
{
// ___________________________________________________________________ vars3D
var container :Sprite;
var scene :Scene3D;
var camera :Camera3D;
var sphere :Ase;
var plane :DisplayObject3D;
var mousePressStatus :String;
var shiftKeyIsPressed :String;
var params:Object = LoaderInfo(loaderInfo).parameters;
// index.html?imageFileFront=images/metall.jpg&imageFileBack=images/rot2.JPG&imageFileTop=images/null.png&imageFileBottom=images/metall.jpg&imageFileLeft=images/rot3.JPG&imageFileRight=images/rot4.JPG&width=440&depth=220&height=560
for (var prop in params) {
trace("params."+prop+" = "+params[prop]);
}
// ___________________________________________________________________ main
function main()
{
init3D();
// onEnterFrame
this.addEventListener( Event.ENTER_FRAME, loop3D );
stage.addEventListener( MouseEvent.MOUSE_UP,toogleMouseUp );
stage.addEventListener( MouseEvent.MOUSE_DOWN,toogleMouseDown );
stage.addEventListener( MouseEvent.MOUSE_WHEEL,mouseWheelHandler );
stage.addEventListener( KeyboardEvent.KEY_DOWN, switchZoomMode);
stage.addEventListener( KeyboardEvent.KEY_UP, switchZoomMode);
}
// ___________________________________________________________________ init3D
function toogleMouseUp(e:MouseEvent):void
{
mousePressStatus = "false";
}
function toogleMouseDown(e:MouseEvent):void
{
mousePressStatus = "true";
}
function switchZoomMode(e:KeyboardEvent):void
{
if (e.shiftKey){
shiftKeyIsPressed = "true";
} else {
shiftKeyIsPressed = "null";
}
}
function mouseWheelHandler(e:MouseEvent):void {
trace("mouseWheelHandler delta: " + e.delta);
camera.z=(camera.z+(e.delta*10));
}
function init3D():void
{
// Create container sprite and center it in the stage
container = new Sprite();
addChild( container );
container.x = stage.stageWidth*.5;
container.y = stage.stageHeight*.5;
// Create scene
scene = new Scene3D( container );
// Create camera
camera = new Camera3D();
camera.x=0;
camera.y=0;
camera.z=1000;
// Add Earth sphere
//addEarth();
// Add space plane
addBox();
}
// ___________________________________________________________________ loop
function addBox():void
{
var size :Number = 500;
var quality :Number = 5;
// Materials
/*
var materials:MaterialsList = new MaterialsList(
{
front: new BitmapFileMaterial( "images/rot1.JPG" ),
back: new BitmapFileMaterial( "images/rot2.JPG" ),
right: new BitmapFileMaterial( "images/rot3.JPG" ),
left: new BitmapFileMaterial( "images/rot4.JPG" ),
top: new BitmapFileMaterial( "images/null.png" ),
bottom: new BitmapFileMaterial( "images/metall.jpg" )
} );
*/
var materials:MaterialsList = new MaterialsList(
{
front: new BitmapFileMaterial( params.picturePath+params.imageFileFront ),
back: new BitmapFileMaterial( params.picturePath+params.imageFileBack ),
right: new BitmapFileMaterial( params.picturePath+params.imageFileRight ),
left: new BitmapFileMaterial( params.picturePath+params.imageFileLeft ),
top: new BitmapFileMaterial( params.picturePath+params.imageFileTop ),
bottom: new BitmapFileMaterial( params.picturePath+params.imageFileBottom )
} );
// Cube face settings
// You can add or sustract faces to your selection. For examples: Cube.FRONT+Cube.BACK or Cube.ALL-Cube.Top.
// On single sided materials, all faces will be visible from the inside.
var insideFaces :int = Cube.ALL-Cube.Top;
// Front and back cube faces will not be created.
//var excludeFaces :int = Cube.TOP;
// Create the cube.
cube = new Cube( materials, params.width, params.depth, params.height, quality, quality, quality, insideFaces);
cube.x=0;
cube.y=0;
cube.z=0;
scene.addChild( cube, "Cube" );
var materials2:MaterialsList = new MaterialsList(
{
front: new BitmapFileMaterial( "images/paper1.jpg" ),
back: new BitmapFileMaterial( "images/paper2.jpg" ),
right: new BitmapFileMaterial( "images/paper3.jpg" ),
left: new BitmapFileMaterial( "images/paper4.jpg" ),
top: new BitmapFileMaterial( "images/null.png" ),
bottom: new BitmapFileMaterial( "images/paper5.jpg" )
} );
var insideFaces2 :int = Cube.ALL;
// Front and back cube faces will not be created.
//var excludeFaces :int = Cube.TOP;
// Create the cube.
cube2 = new Cube( materials2, params.width, params.depth, params.height, quality, quality, quality, insideFaces2);
cube2.x=0;
cube2.y=0;
cube2.z=0;
scene.addChild( cube2, "Cube" );
cube.yaw(-30);
cube2.yaw(-30);
}
// ___________________________________________________________________ loop
function loop3D(event:Event):void
{
// Move camera with the mouse
//camera.x = -container.mouseX/0.2;
//camera.y = container.mouseY/0.2;
if((mousePressStatus == "true") && (shiftKeyIsPressed != "true")){
trace("standard press - shitkeyValue : " + shiftKeyIsPressed);
cube.rotationY = container.mouseX / -1.2;
cube.rotationX = container.mouseY / -1.2;
cube2.rotationY = container.mouseX / -1.2;
cube2.rotationX = container.mouseY / -1.2;
}else if((mousePressStatus == "true") && (shiftKeyIsPressed == "true")){
camera.z=(1000+(-(container.mouseY*2)));
trace("move camera x axis : " + camera.z);
}else{
// Rotate sphere around its own vertical axis
cube.yaw( 2 );
cube2.yaw( 2 );
}
scene.renderCamera( camera );
}
}
}