fun with as3Mod source
i got the source for the flip effect ready. it uses the folowing projects: PaperVison as3MOD Shadow Casting i also used this base papervision setup from HERE
// These lines make differant 'pieces' available in your code.
-
package {
-
import flash.display.Sprite; // To extend this class
-
import flash.events.Event; // To work out when a frame is entered.
-
import flash.media.Camera;
-
import org.papervision3d.core.proto.CameraObject3D;
-
import org.papervision3d.core.utils.*;
-
import org.papervision3d.view.*; // We need a viewport
-
import org.papervision3d.cameras.*; // Import all types of camera
-
import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
-
import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
-
import org.papervision3d.core.utils.virtualmouse.VirtualMouse;
-
import com.Stats;
-
public class PaperBase extends Sprite { //Must be "extends Sprite"
-
-
public var viewport:Viewport3D; // The Viewport
-
public var renderer:BasicRenderEngine; // Rendering engine
-
// — Scenes — //
-
public var default_scene:Scene3D; // A Scene
-
// — Cameras –//
-
public var default_camera:Camera3D; // A Camera
-
public var current_camera:CameraObject3D; // A Camera
-
-
public function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
-
initPapervision(vpWidth, vpHeight); // Initialise papervision
-
init3d(); // Initialise the 3d stuff..
-
init2d(); // Initialise the interface..
-
initEvents(); // Set up any event listeners..
-
}
-
-
protected function initPapervision(vpWidth:Number, vpHeight:Number):void {
-
// Here is where we initialise everything we need to
-
// render a papervision scene.
-
viewport = new Viewport3D(vpWidth, vpHeight, true, true);
-
viewport.buttonMode = true;
-
// The viewport is the object added to the flash scene.
-
// You 'look at' the papervision scene through the viewport
-
// window, which is placed on the flash stage.
-
addChild(viewport); // Add the viewport to the stage.
-
//viewport.button = true;
-
// Initialise the rendering engine.
-
renderer = new BasicRenderEngine();
-
// — Initialise the Scenes — //
-
default_scene = new Scene3D();
-
// — Initialise the Cameras — //
-
default_camera = new Camera3D(); // The argument passed to the camera
-
// is the object that it should look at. I've passed the scene object
-
// so that the camera is always pointing at the centre of the scene.
-
current_camera = default_camera;
-
default_camera.zoom = 180
-
addChild( new Stats() );
-
}
-
-
protected function init3d():void {
-
// This function should hold all of the stages needed
-
// to initialise everything used for papervision.
-
// Models, materials, cameras etc.
-
}
-
-
protected function init2d():void {
-
// This function should create all of the 2d items
-
// that will be overlayed on your papervision project.
-
// User interfaces, Heads up displays etc.
-
}
-
-
protected function initEvents():void {
-
// This function makes the onFrame function get called for
-
// every frame.
-
addEventListener(Event.ENTER_FRAME, onEnterFrame);
-
// This line of code makes the onEnterFrame function get
-
// called when every frame is entered.
-
}
-
-
protected function processFrame():void {
-
// Process any movement or animation here.
-
}
-
-
protected function onEnterFrame( ThisEvent:Event ):void {
-
//We need to render the scene and update anything here.
-
processFrame();
-
renderer.renderScene(default_scene, current_camera, viewport);
-
}
-
-
}
-
-
}
// These lines make differant 'pieces' available in your code.
-
package {
-
import org.papervision3d.events.InteractiveScene3DEvent
-
import org.papervision3d.objects.primitives.Plane;
-
import org.papervision3d.objects.primitives.Cube;
-
import org.papervision3d.lights.PointLight3D;
-
import org.papervision3d.materials.BitmapColorMaterial;
-
import org.papervision3d.materials.MovieAssetMaterial;
-
import org.papervision3d.materials.MovieMaterial;
-
import org.papervision3d.shadowC.ShadowCaster;
-
import org.papervision3d.materials.shaders.GouraudShader;
-
import org.papervision3d.materials.shaders.ShadedMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.DisplayObject3D;
-
import fl.events.*
-
import flash.display.BlendMode;
-
import flash.display.Sprite;
-
import flash.filters.BlurFilter;
-
import flash.display.MovieClip
-
import com.Stats;
-
import gs.TweenMax;
-
import gs.easing.*;
-
import com.as3dmod.modifiers.Bend;
-
import com.as3dmod.modifiers.Noise;
-
import com.as3dmod.modifiers.Perlin;
-
import com.as3dmod.ModifierStack;
-
import com.as3dmod.plugins.pv3d.LibraryPv3d;
-
import com.as3dmod.util.ModConstant;
-
import com.as3dmod.util.Phase;
-
-
-
-
public class Main extends PaperBase {
-
// main cube//
-
//cube for the movies
-
private var myCube:Cube;
-
public var MovieMat:MovieAssetMaterial;
-
public var light:PointLight3D;
-
public var gouraudShader:GouraudShader;
-
public var gouraudShaderMat:ShadedMaterial;
-
private var spr:Sprite;
-
private var sprMaterial:MovieMaterial;
-
private var shadowCaster:ShadowCaster;
-
private var shadowPlane:Plane;
-
private var modifierStack:ModifierStack;
-
private var bend:Bend;
-
private var bendPhase:Phase;
-
-
-
-
public function Main() {
-
// inits 3d init(width to draw:number,height to draw:number);
-
init(stage.stageWidth,550);
-
}
-
-
override protected function init2d():void {
-
-
-
//addChild(myPC);
-
-
-
-
addChild(slider8);
-
slider8.addEventListener(SliderEvent.THUMB_DRAG,BendForce)
-
function BendForce(e:SliderEvent):void{
-
bend.force =e.value/20
-
-
-
}
-
addChild(slider9);
-
slider9.addEventListener(SliderEvent.THUMB_DRAG,BendAngle)
-
function BendAngle(e:SliderEvent):void{
-
bend.angle =e.value/20
-
-
-
}
-
-
-
-
}
-
-
override protected function init3d():void {
-
-
-
-
//the light PointLight3D(visible:true);
-
light=new PointLight3D(true,false);
-
light.x = -48
-
light.y = 105
-
light.z = -630
-
light.alpha = .5
-
light.rotationX = 180;
-
light.rotationY = 90;
-
-
// front movie asset material
-
// moviclip in the lybrary with the id of "img"
-
MovieMat=new MovieAssetMaterial("img",false,false);
-
MovieMat.doubleSided = false;
-
MovieMat.smooth = true;
-
MovieMat.precise = false;
-
MovieMat.interactive = true;
-
var MovieMat2=new MovieAssetMaterial("BG",false,false);
-
MovieMat2.doubleSided = false;
-
MovieMat2.smooth = true;
-
MovieMat2.animated = false;
-
MovieMat2.interactive = true;
-
-
-
//shader that holds the shade from the light
-
gouraudShader=new GouraudShader(light,0xFFFFFF,0×666666);
-
var gouraudShader2=new GouraudShader(light,0xFFFFFF,0×666666);
-
-
var shadedMat = new ShadedMaterial(MovieMat2, gouraudShader)
-
shadedMat.interactive = true;
-
-
var shadedMat2 = new ShadedMaterial(MovieMat, gouraudShader2)
-
shadedMat2.interactive = true;
-
-
// list om material for the cube
-
var ml:MaterialsList = new MaterialsList();
-
ml.addMaterial(shadedMat2, "front");
-
ml.addMaterial(shadedMat, "back");
-
ml.addMaterial(MovieMat2, "right");
-
ml.addMaterial(MovieMat2, "left");
-
ml.addMaterial(MovieMat2, "top");
-
ml.addMaterial(MovieMat2, "bottom");
-
-
-
myCube = new Cube(ml, MovieMat.movie.width, 0, MovieMat.movie.height, 5, 5)
-
myCube.scale=.3;
-
myCube.y=0;
-
myCube.x=-4;
-
myCube.z=-10;
-
myCube.rotationY=-180;
-
////this is for the Blur
-
myCube.useOwnContainer = true;
-
-
spr=new Sprite ;
-
/// take away the 0 at the end and it wont be transparent
-
spr.graphics.beginFill(0xFFFFFF,0);
-
// if you chane the "400,400" number to a higher amount it will increas the quality of the shadow but this will kill the FPS
-
spr.graphics.drawRect(0,0,400,400);
-
sprMaterial=new MovieMaterial(spr,true,true,true);
-
shadowPlane=new Plane(sprMaterial,2000,2000);
-
-
-
//Instantiate your shadowCaster object
-
//The parameters are as follows
-
//ShadowCaster("name", shadow color, blend mode, shadow alpha, [filters]);
-
shadowCaster = new ShadowCaster("shadow", 0×000000, BlendMode.MULTIPLY, .1, [new BlurFilter(0, 0, 1)]);
-
//Set the light type (options are SPOTLIGHT and DIRECTIONAL)
-
shadowCaster.setType(ShadowCaster.SPOTLIGHT);
-
//Add your shadowPlane and Cylinder to the scene
-
default_scene.addChild(shadowPlane);
-
-
default_scene.addChild(myCube);
-
-
-
// do as3dmod stuff
-
modifierStack = new ModifierStack(new LibraryPv3d(), myCube);
-
bend = new Bend();
-
bend.constraint = ModConstant.NONE;
-
bend.angle =2.4,
-
bendPhase = new Phase();
-
modifierStack.addModifier(bend);
-
-
-
myCube.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPress );
-
myCube.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onRollOver );
-
myCube.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onRollOut );
-
-
function onPress( e:InteractiveScene3DEvent ):void {
-
trace(e.displayObject3D.rotationY);
-
if (e.displayObject3D.rotationY==-180) {
-
flipBack();
-
} else if (e.displayObject3D.rotationY==0) {
-
flipFront();
-
}
-
}
-
function onRollOver( e:InteractiveScene3DEvent ):void {
-
viewport.buttonMode = true;
-
}
-
function onRollOut( e:InteractiveScene3DEvent ):void {
-
viewport.buttonMode = false;
-
}
-
-
-
function flipFront():void{
-
trace(viewport)
-
TweenMax.to(myCube, 1, {z:-10, rotationY:-180, bezier:[{z:-600, rotationY:0}], ease:Quad.easeOut});
-
TweenMax.to(bend, 1, {force:0, angle:1.5,bezier:[{force:-1.85,angle:1.5}], ease:Quad.easeOut});
-
-
}
-
function flipBack():void{
-
TweenMax.to(myCube, 1, {z:-10, rotationY:0, bezier:[{z:-600, rotationY:-180}], ease:Quad.easeOut});
-
TweenMax.to(bend, 1, {force:0, angle:1.5,bezier:[{force:1.85,angle:1.5}], ease:Quad.easeOut});
-
}
-
-
-
-
}
-
override protected function processFrame():void {
-
modifierStack.apply();
-
light.x = (mouseX-400)
-
light.y = -(mouseY-400)
-
myCube.filters = [new BlurFilter((Math.abs(myCube.z)/90+1.15), Math.abs(myCube.z)/90+1.15, 1)];
-
//the invalidate() method basically clears the previously drawn shadow
-
shadowCaster.invalidate();
-
//the castModel method casts the shadow of an object in your scene
-
//castModel parameters are as follows
-
//castModel(object to cast shadow from, light, plane to cast the shadow onto
-
shadowCaster.castModel(myCube,light,shadowPlane);
-
}
-
}
-
}










