package {
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.utils.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.*;
import org.papervision3d.cameras.*;
import org.papervision3d.lights.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.*;
import caurina.transitions.Tweener;
[SWF(width = "720", height = "480", frameRate = "60", backgroundColor="#FFFFFF")];
public class shadowex extends BasicView {
static private const CUBE_ROUND :uint = 2500;
static private const CUBE_SIZE :uint = 600;
static private const CUBE_SEGMENT :uint = 1;
static private const CUBE_AMOUNT :uint = 10;
static private const CAMERA_POSITION :uint = 4500;
static private const LIGHT_POSITION :uint = 2000;
static private const PLANE_SIZE :uint = 8000;
private var rotXValue:Number;
private var rotZValue:Number;
private var rotYValue:Number;
private var light :PointLight3D = new PointLight3D();
private var shadowCaster :ShadowCaster = new ShadowCaster("shadow", 0, BlendMode.NORMAL, .25, [new BlurFilter(16, 16, 3)]); ;
private var plane :Plane;
private var cube :DisplayObject3D;
private var lightModel :DisplayObject3D;
private var materials:MaterialsList;
private var flatShaderMat:FlatShadeMaterial;
public function shadowex() {
super(0, 0, true, false, CameraType.TARGET);
// shadow caster and movie material
shadowCaster.setType(ShadowCaster.SPOTLIGHT);
var sprite : Sprite = new Sprite();
sprite.graphics.beginFill(0xEEEEEE, 1);
sprite.graphics.drawRect(0, 0, 128, 128);
sprite.graphics.endFill();
var movieMat : MovieMaterial = new MovieMaterial(sprite, false, true, true);
// add movieMaterial to plane
plane = new Plane(movieMat, PLANE_SIZE, PLANE_SIZE, 4, 4);
plane.pitch(90);
plane.y = - CUBE_ROUND;
scene.addChild(plane);
/*
cubes = scene.addChild(new DisplayObject3D());
var i:int = CUBE_AMOUNT;
while(i--)
{
var cube:Cube = new Cube(
new MaterialsList( { all:new FlatShadeMaterial(light, 0xCCCCCC) } ),
CUBE_SIZE, CUBE_SIZE, CUBE_SIZE,
CUBE_SEGMENT, CUBE_SEGMENT, CUBE_SEGMENT);
cube.x = CUBE_ROUND * Math.random() - CUBE_ROUND / 2;
cube.y = CUBE_ROUND * Math.random() - CUBE_ROUND / 2;
cube.z = CUBE_ROUND * Math.random() - CUBE_ROUND / 2;
cube.scale = .8 * Math.random() + .2;
cube.rotationX = 360 * Math.random();
cube.rotationY = 360 * Math.random();
cube.rotationZ = 360 * Math.random();
cubes.addChild(cube);
}
*/
flatShaderMat = new FlatShadeMaterial (light, 0x000000, 0x333333);
materials = new MaterialsList ();
materials.addMaterial(flatShaderMat, "all");
cube = new Cube(materials, 500, 500, 500, 3, 3, 3);
///
lightModel = new Sphere(new WireframeMaterial(0xFFFF00), 100, 1, 1);
scene.addChild(lightModel);
scene.addChild(light);
scene.addChild(cube);
recalcValues();
startRendering();
}
private function recalcValues():void {
rotXValue = randomize (0, 360);
rotYValue = randomize (0, 360);
rotZValue = randomize (0, 360);
Tweener.addTween(cube, {rotationX:rotXValue, rotationY:rotYValue, rotationZ: rotZValue, onUpdate:startRendering, onComplete:recalcValues, transition:"easeInOutElastic", time:3});
}
private function randomize(min:Number, max:Number):Number {
return Math.random() * max - min + min;
}
override protected function onRenderTick(e:Event = null):void {
shadowCaster.invalidate();
shadowCaster.castModel(cube, light, plane);
camera.x += (CAMERA_POSITION * Math.sin(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.x) * .1;
camera.z += (CAMERA_POSITION * Math.cos(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.z) * .1;
camera.y += (CAMERA_POSITION * mouseY / stage.stageHeight - CAMERA_POSITION / 2 - camera.y) * .1;
light.x = LIGHT_POSITION * Math.sin(getTimer() / 2000);
light.z = LIGHT_POSITION * Math.cos(getTimer() / 2000);
light.y = LIGHT_POSITION * 1;
lightModel.transform = light.transform
;
super.onRenderTick(e);
}
}
}
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.utils.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.*;
import org.papervision3d.cameras.*;
import org.papervision3d.lights.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.*;
import caurina.transitions.Tweener;
[SWF(width = "720", height = "480", frameRate = "60", backgroundColor="#FFFFFF")];
public class shadowex extends BasicView {
static private const CUBE_ROUND :uint = 2500;
static private const CUBE_SIZE :uint = 600;
static private const CUBE_SEGMENT :uint = 1;
static private const CUBE_AMOUNT :uint = 10;
static private const CAMERA_POSITION :uint = 4500;
static private const LIGHT_POSITION :uint = 2000;
static private const PLANE_SIZE :uint = 8000;
private var rotXValue:Number;
private var rotZValue:Number;
private var rotYValue:Number;
private var light :PointLight3D = new PointLight3D();
private var shadowCaster :ShadowCaster = new ShadowCaster("shadow", 0, BlendMode.NORMAL, .25, [new BlurFilter(16, 16, 3)]); ;
private var plane :Plane;
private var cube :DisplayObject3D;
private var lightModel :DisplayObject3D;
private var materials:MaterialsList;
private var flatShaderMat:FlatShadeMaterial;
public function shadowex() {
super(0, 0, true, false, CameraType.TARGET);
// shadow caster and movie material
shadowCaster.setType(ShadowCaster.SPOTLIGHT);
var sprite : Sprite = new Sprite();
sprite.graphics.beginFill(0xEEEEEE, 1);
sprite.graphics.drawRect(0, 0, 128, 128);
sprite.graphics.endFill();
var movieMat : MovieMaterial = new MovieMaterial(sprite, false, true, true);
// add movieMaterial to plane
plane = new Plane(movieMat, PLANE_SIZE, PLANE_SIZE, 4, 4);
plane.pitch(90);
plane.y = - CUBE_ROUND;
scene.addChild(plane);
/*
cubes = scene.addChild(new DisplayObject3D());
var i:int = CUBE_AMOUNT;
while(i--)
{
var cube:Cube = new Cube(
new MaterialsList( { all:new FlatShadeMaterial(light, 0xCCCCCC) } ),
CUBE_SIZE, CUBE_SIZE, CUBE_SIZE,
CUBE_SEGMENT, CUBE_SEGMENT, CUBE_SEGMENT);
cube.x = CUBE_ROUND * Math.random() - CUBE_ROUND / 2;
cube.y = CUBE_ROUND * Math.random() - CUBE_ROUND / 2;
cube.z = CUBE_ROUND * Math.random() - CUBE_ROUND / 2;
cube.scale = .8 * Math.random() + .2;
cube.rotationX = 360 * Math.random();
cube.rotationY = 360 * Math.random();
cube.rotationZ = 360 * Math.random();
cubes.addChild(cube);
}
*/
flatShaderMat = new FlatShadeMaterial (light, 0x000000, 0x333333);
materials = new MaterialsList ();
materials.addMaterial(flatShaderMat, "all");
cube = new Cube(materials, 500, 500, 500, 3, 3, 3);
///
lightModel = new Sphere(new WireframeMaterial(0xFFFF00), 100, 1, 1);
scene.addChild(lightModel);
scene.addChild(light);
scene.addChild(cube);
recalcValues();
startRendering();
}
private function recalcValues():void {
rotXValue = randomize (0, 360);
rotYValue = randomize (0, 360);
rotZValue = randomize (0, 360);
Tweener.addTween(cube, {rotationX:rotXValue, rotationY:rotYValue, rotationZ: rotZValue, onUpdate:startRendering, onComplete:recalcValues, transition:"easeInOutElastic", time:3});
}
private function randomize(min:Number, max:Number):Number {
return Math.random() * max - min + min;
}
override protected function onRenderTick(e:Event = null):void {
shadowCaster.invalidate();
shadowCaster.castModel(cube, light, plane);
camera.x += (CAMERA_POSITION * Math.sin(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.x) * .1;
camera.z += (CAMERA_POSITION * Math.cos(mouseX / stage.stageWidth * 360 * Math.PI / 180) - camera.z) * .1;
camera.y += (CAMERA_POSITION * mouseY / stage.stageHeight - CAMERA_POSITION / 2 - camera.y) * .1;
light.x = LIGHT_POSITION * Math.sin(getTimer() / 2000);
light.z = LIGHT_POSITION * Math.cos(getTimer() / 2000);
light.y = LIGHT_POSITION * 1;
lightModel.transform = light.transform
;
super.onRenderTick(e);
}
}
}








