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.
  1.  package  {
  2. import flash.display.Sprite; // To extend this class
  3.  import flash.events.Event; // To work out when a frame is entered.
  4.  import flash.media.Camera;
  5.  import org.papervision3d.core.proto.CameraObject3D;
  6.  import org.papervision3d.core.utils.*;
  7.  import org.papervision3d.view.*; // We need a viewport
  8.  import org.papervision3d.cameras.*; // Import all types of camera
  9.  import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
  10.  import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
  11.  import org.papervision3d.core.utils.virtualmouse.VirtualMouse;
  12.  import com.Stats;
  13.  public class PaperBase extends Sprite { //Must be "extends Sprite"
  14.  
  15.   public var viewport:Viewport3D; // The Viewport
  16.   public var renderer:BasicRenderEngine; // Rendering engine
  17.   // — Scenes — //
  18.   public var default_scene:Scene3D; // A Scene
  19.   // — Cameras –//
  20.   public var default_camera:Camera3D; // A Camera
  21.   public var current_camera:CameraObject3D; // A Camera
  22.  
  23.   public function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
  24.    initPapervision(vpWidth, vpHeight); // Initialise papervision
  25.    init3d(); // Initialise the 3d stuff..
  26.    init2d(); // Initialise the interface..
  27.    initEvents(); // Set up any event listeners..
  28.   }
  29.  
  30.   protected function initPapervision(vpWidth:Number, vpHeight:Number):void {
  31.    // Here is where we initialise everything we need to
  32.    // render a papervision scene.
  33.    viewport = new Viewport3D(vpWidth, vpHeight, true, true);
  34.    viewport.buttonMode = true;
  35.    // The viewport is the object added to the flash scene.
  36.    // You 'look at' the papervision scene through the viewport
  37.    // window, which is placed on the flash stage.
  38.    addChild(viewport); // Add the viewport to the stage.
  39.    //viewport.button = true;
  40.    // Initialise the rendering engine.
  41.    renderer = new BasicRenderEngine();
  42.    // — Initialise the Scenes — //
  43.    default_scene = new Scene3D();
  44.    // — Initialise the Cameras — //
  45.    default_camera = new Camera3D(); // The argument passed to the camera
  46.    // is the object that it should look at. I've passed the scene object
  47.    // so that the camera is always pointing at the centre of the scene.
  48.    current_camera = default_camera;
  49.    default_camera.zoom = 180
  50.    addChild( new Stats() );
  51.   }
  52.  
  53.   protected function init3d():void {
  54.    // This function should hold all of the stages needed
  55.    // to initialise everything used for papervision.
  56.    // Models, materials, cameras etc.
  57.   }
  58.  
  59.   protected function init2d():void {
  60.    // This function should create all of the 2d items
  61.    // that will be overlayed on your papervision project.
  62.    // User interfaces, Heads up displays etc.
  63.   }
  64.  
  65.   protected function initEvents():void {
  66.    // This function makes the onFrame function get called for
  67.    // every frame.
  68.    addEventListener(Event.ENTER_FRAME, onEnterFrame);
  69.    // This line of code makes the onEnterFrame function get
  70.    // called when every frame is entered.
  71.   }
  72.  
  73.   protected function processFrame():void {
  74.    // Process any movement or animation here.
  75.   }
  76.  
  77.   protected function onEnterFrame( ThisEvent:Event ):void {
  78.    //We need to render the scene and update anything here.
  79.    processFrame();
  80.    renderer.renderScene(default_scene, current_camera, viewport);
  81.   }
  82.  
  83.  }
  84.  
  85. }
// These lines make differant 'pieces' available in your code.
  1. package {
  2.  import org.papervision3d.events.InteractiveScene3DEvent
  3.  import org.papervision3d.objects.primitives.Plane;
  4.  import org.papervision3d.objects.primitives.Cube;
  5.  import org.papervision3d.lights.PointLight3D;
  6.  import org.papervision3d.materials.BitmapColorMaterial;
  7.  import org.papervision3d.materials.MovieAssetMaterial;
  8.  import org.papervision3d.materials.MovieMaterial;
  9.  import org.papervision3d.shadowC.ShadowCaster;
  10.  import org.papervision3d.materials.shaders.GouraudShader;
  11.  import org.papervision3d.materials.shaders.ShadedMaterial;
  12.  import org.papervision3d.materials.utils.MaterialsList;
  13.  import org.papervision3d.objects.DisplayObject3D;
  14.  import fl.events.*
  15.  import flash.display.BlendMode;
  16.  import flash.display.Sprite;
  17.  import flash.filters.BlurFilter;
  18.  import flash.display.MovieClip
  19.  import com.Stats;
  20.  import gs.TweenMax;
  21.  import gs.easing.*;
  22.  import com.as3dmod.modifiers.Bend;
  23.  import com.as3dmod.modifiers.Noise;
  24.  import com.as3dmod.modifiers.Perlin;
  25.  import com.as3dmod.ModifierStack;
  26.  import com.as3dmod.plugins.pv3d.LibraryPv3d;
  27.  import com.as3dmod.util.ModConstant;
  28.  import com.as3dmod.util.Phase;
  29.  
  30.  
  31.  
  32.  public class Main extends PaperBase {
  33.   // main cube//
  34.   //cube for the movies
  35.   private var myCube:Cube;
  36.   public var MovieMat:MovieAssetMaterial;
  37.   public var light:PointLight3D;
  38.   public var gouraudShader:GouraudShader;
  39.   public var gouraudShaderMat:ShadedMaterial;
  40.   private var spr:Sprite;
  41.   private var sprMaterial:MovieMaterial;
  42.   private var shadowCaster:ShadowCaster;
  43.   private var shadowPlane:Plane;
  44.   private var modifierStack:ModifierStack;
  45.   private var bend:Bend;
  46.   private var bendPhase:Phase;
  47.  
  48.  
  49.  
  50.   public function Main() {
  51.    // inits 3d init(width to draw:number,height to draw:number);
  52.    init(stage.stageWidth,550);
  53.   }
  54.  
  55.   override protected function init2d():void {
  56.    
  57.    
  58.    //addChild(myPC);
  59.    
  60.    
  61.    
  62.    addChild(slider8);
  63.    slider8.addEventListener(SliderEvent.THUMB_DRAG,BendForce)
  64.    function BendForce(e:SliderEvent):void{
  65.     bend.force =e.value/20
  66.    
  67.    
  68.    }
  69.    addChild(slider9);
  70.    slider9.addEventListener(SliderEvent.THUMB_DRAG,BendAngle)
  71.    function BendAngle(e:SliderEvent):void{
  72.     bend.angle =e.value/20
  73.    
  74.    
  75.    }  
  76.    
  77.  
  78.  
  79.   }
  80.  
  81.   override protected function init3d():void {
  82.    
  83.    
  84.    
  85.    //the light PointLight3D(visible:true);
  86.    light=new PointLight3D(true,false);
  87.    light.x = -48  
  88.    light.y = 105
  89.    light.z = -630
  90.    light.alpha = .5
  91.    light.rotationX = 180;
  92.    light.rotationY = 90;
  93.    
  94.    // front movie asset material
  95.    // moviclip in the lybrary with the id of "img"
  96.    MovieMat=new MovieAssetMaterial("img",false,false);
  97.    MovieMat.doubleSided = false;
  98.    MovieMat.smooth = true;
  99.    MovieMat.precise = false;
  100.    MovieMat.interactive = true;
  101.    var MovieMat2=new MovieAssetMaterial("BG",false,false);
  102.    MovieMat2.doubleSided = false;
  103.    MovieMat2.smooth = true;
  104.    MovieMat2.animated = false;
  105.    MovieMat2.interactive = true;
  106.    
  107.    
  108.    //shader that holds the shade from the light
  109.    gouraudShader=new GouraudShader(light,0xFFFFFF,0×666666);
  110.    var gouraudShader2=new GouraudShader(light,0xFFFFFF,0×666666);
  111.    
  112.    var shadedMat = new ShadedMaterial(MovieMat2, gouraudShader)
  113.    shadedMat.interactive = true;
  114.    
  115.    var shadedMat2 = new ShadedMaterial(MovieMat, gouraudShader2)
  116.    shadedMat2.interactive = true;
  117.    
  118.    // list om material for the cube
  119.    var ml:MaterialsList = new MaterialsList();
  120.    ml.addMaterial(shadedMat2, "front");
  121.    ml.addMaterial(shadedMat, "back");
  122.    ml.addMaterial(MovieMat2, "right");
  123.    ml.addMaterial(MovieMat2, "left");
  124.    ml.addMaterial(MovieMat2, "top");
  125.    ml.addMaterial(MovieMat2, "bottom");
  126.    
  127.    
  128.    myCube = new Cube(ml, MovieMat.movie.width, 0, MovieMat.movie.height, 5, 5)
  129.    myCube.scale=.3;
  130.    myCube.y=0;
  131.    myCube.x=-4;
  132.    myCube.z=-10;
  133.    myCube.rotationY=-180;
  134.    ////this is for the Blur
  135.    myCube.useOwnContainer = true;
  136.  
  137.    spr=new Sprite  ;
  138.    /// take away the 0 at the end and it wont be transparent
  139.    spr.graphics.beginFill(0xFFFFFF,0);
  140.    // 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
  141.    spr.graphics.drawRect(0,0,400,400);
  142.    sprMaterial=new MovieMaterial(spr,true,true,true);
  143.    shadowPlane=new Plane(sprMaterial,2000,2000);
  144.    
  145.    
  146.    //Instantiate your shadowCaster object
  147.    //The parameters are as follows
  148.    //ShadowCaster("name", shadow color, blend mode, shadow alpha, [filters]);
  149.    shadowCaster = new ShadowCaster("shadow", 0×000000, BlendMode.MULTIPLY, .1, [new BlurFilter(0, 0, 1)]);
  150.    //Set the light type (options are SPOTLIGHT and DIRECTIONAL)
  151.    shadowCaster.setType(ShadowCaster.SPOTLIGHT);
  152.    //Add your shadowPlane and Cylinder to the scene
  153.    default_scene.addChild(shadowPlane);
  154.  
  155.    default_scene.addChild(myCube);
  156.    
  157.  
  158.    // do as3dmod stuff
  159.    modifierStack = new ModifierStack(new LibraryPv3d(), myCube);
  160.    bend = new Bend();
  161.    bend.constraint = ModConstant.NONE;
  162.    bend.angle =2.4,
  163.    bendPhase = new Phase();
  164.    modifierStack.addModifier(bend);
  165.    
  166.    
  167.    myCube.addEventListener( InteractiveScene3DEvent.OBJECT_PRESS, onPress );
  168.    myCube.addEventListener( InteractiveScene3DEvent.OBJECT_OVER, onRollOver );
  169.    myCube.addEventListener( InteractiveScene3DEvent.OBJECT_OUT, onRollOut );
  170.    
  171.    function onPress( e:InteractiveScene3DEvent ):void {
  172.     trace(e.displayObject3D.rotationY);
  173.     if (e.displayObject3D.rotationY==-180) {
  174.      flipBack();
  175.     } else if (e.displayObject3D.rotationY==0) {
  176.      flipFront();
  177.     }
  178.    }
  179.    function onRollOver( e:InteractiveScene3DEvent ):void {
  180.     viewport.buttonMode = true;
  181.    }
  182.    function onRollOut( e:InteractiveScene3DEvent ):void {
  183.     viewport.buttonMode = false;
  184.    }
  185.    
  186.    
  187.    function flipFront():void{
  188.     trace(viewport)
  189.     TweenMax.to(myCube, 1, {z:-10, rotationY:-180, bezier:[{z:-600, rotationY:0}], ease:Quad.easeOut});
  190.    TweenMax.to(bend, 1, {force:0, angle:1.5,bezier:[{force:-1.85,angle:1.5}], ease:Quad.easeOut});
  191.    
  192.    }
  193.    function flipBack():void{
  194.     TweenMax.to(myCube, 1, {z:-10, rotationY:0, bezier:[{z:-600, rotationY:-180}], ease:Quad.easeOut});
  195.    TweenMax.to(bend, 1, {force:0, angle:1.5,bezier:[{force:1.85,angle:1.5}], ease:Quad.easeOut});
  196.    }
  197.    
  198.    
  199.    
  200.   }
  201.   override protected function processFrame():void {
  202.    modifierStack.apply();
  203.    light.x = (mouseX-400)
  204.    light.y = -(mouseY-400)
  205.    myCube.filters = [new BlurFilter((Math.abs(myCube.z)/90+1.15), Math.abs(myCube.z)/90+1.15, 1)];
  206.    //the invalidate() method basically clears the previously drawn shadow
  207.    shadowCaster.invalidate();
  208.    //the castModel method casts the shadow of an object in your scene
  209.    //castModel parameters are as follows
  210.    //castModel(object to cast shadow from, light, plane to cast the shadow onto
  211.    shadowCaster.castModel(myCube,light,shadowPlane);
  212.   }
  213.  }
  214. }
Share and Enjoy:
  • Facebook
  • LinkedIn
  • TwitThis
  • Google
  • del.icio.us
  • Digg
  • Sphinn
  • Mixx
  • MySpace
  • StumbleUpon

Reply

You must be logged in to post a comment.