papervision3d light and a flatshadedcube with tweensy
// forked from mash's papervision3d light and a flatshadedcube
// forked from mash's papervision3d simple example (cube)
package {
import flash.display.*;
import flash.events.*;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import com.flashdynamix.motion.Tweensy;
public class PV3D_01 extends Sprite {
private var camera :Camera3D;
private var scene :Scene3D;
private var viewport :Viewport3D;
private var renderer :BasicRenderEngine;
private var cube :Cube;
public function PV3D_01() {
camera = new Camera3D();
camera.x = 0;
camera.y = 0;
camera.z = -1000;
scene = new Scene3D();
viewport = new Viewport3D( stage.stageWidth, stage.stageHeight, false, true );
renderer = new BasicRenderEngine();
addChild( viewport );
var light:PointLight3D = new PointLight3D(false);
light.x = 0;
light.y = 0;
light.z = -1000;
var material :FlatShadeMaterial = new FlatShadeMaterial(light, 0xD7261C );
material.interactive = true;
var materials :MaterialsList = new MaterialsList( { all : material } );
cube = new Cube( materials );
cube.x = 0;
cube.y = 0;
cube.z = 0;
cube.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, function(e :InteractiveScene3DEvent) :void {
Tweensy.to( camera, { z :camera.z+100 }, 0.3, null, 0, null, function() :void {
Tweensy.to( camera, { z: -1000 }, 0.3 );
});
});
scene.addChild( cube );
addEventListener( Event.ENTER_FRAME, onEnterFrame );
}
public function onEnterFrame(e:Event): void {
cube.rotationX += ( mouseX - stage.stageWidth /2 ) / 200;
cube.rotationY += ( mouseY - stage.stageHeight/2 ) / 200;
renderer.renderScene( scene, camera, viewport );
}
}
}