AS3: DistortionTweener Done Easier In Papervision3D
View Example
Get Papervision3D [Tutorial]
Get TweenMax
Download Source
Well, the first thing I have done in Papervision3D is a replica of what I essentially did with the DistortionTweener (or actually the reason I made the DistortionTweener). It is much easier to do and takes a lot less to do (the original DistortionTweener, with research, took me about a week to do while this took me about an hour). Keep in mind the code is probably not super optimized as this is THE first thing I've done with PV3D.
-
/**
-
* @author Matt Przybylski [http://www.reintroducing.com]
-
* @version 1.0
-
*/
-
-
package com.reintroducing
-
{
-
import flash.display.Sprite;
-
import flash.events.Event;
-
-
import org.papervision3d.cameras.Camera3D;
-
import org.papervision3d.core.proto.MaterialObject3D;
-
import org.papervision3d.events.InteractiveScene3DEvent;
-
import org.papervision3d.materials.MovieAssetMaterial;
-
import org.papervision3d.objects.DisplayObject3D;
-
import org.papervision3d.objects.primitives.Plane;
-
import org.papervision3d.render.BasicRenderEngine;
-
import org.papervision3d.scenes.Scene3D;
-
import org.papervision3d.view.Viewport3D;
-
-
import gs.TweenMax;
-
-
public class Main extends Sprite
-
{
-
//- PRIVATE & PROTECTED VARIABLES -------------------------------------------------------------------------
-
-
private var _viewport:Viewport3D;
-
private var _scene:Scene3D;
-
private var _camera:Camera3D;
-
private var _renderer:BasicRenderEngine;
-
private var _front:Plane;
-
private var _back:Plane;
-
-
//- PUBLIC & INTERNAL VARIABLES ---------------------------------------------------------------------------
-
-
-
-
//- CONSTRUCTOR -------------------------------------------------------------------------------------------
-
-
public function Main():void
-
{
-
this.init();
-
}
-
-
//- PRIVATE & PROTECTED METHODS ---------------------------------------------------------------------------
-
-
/**
-
*
-
*/
-
private function init():void
-
{
-
this.initPapervision();
-
this.initObjects();
-
this.initListeners();
-
}
-
-
/**
-
*
-
*/
-
private function initPapervision():void
-
{
-
this._viewport = new Viewport3D(stage.stageWidth, stage.stageHeight, true, true);
-
this._scene = new Scene3D();
-
this._camera = new Camera3D(null, 11);
-
this._renderer = new BasicRenderEngine();
-
-
this.addChild(this._viewport);
-
}
-
-
/**
-
*
-
*/
-
private function initObjects():void
-
{
-
var frontMat:MovieAssetMaterial = new MovieAssetMaterial("front", true);
-
frontMat.interactive = true;
-
-
this._front = new Plane(frontMat, 300, 150, 10, 10);
-
-
var backMat:MovieAssetMaterial = new MovieAssetMaterial("back", true);
-
backMat.interactive = true;
-
-
this._back = new Plane(backMat, 300, 150, 10, 10);
-
this._back.yaw(180);
-
-
var holder:DisplayObject3D = new DisplayObject3D("holder");
-
holder.addChild(this._front);
-
holder.addChild(this._back);
-
-
this._scene.addChild(holder);
-
}
-
-
/**
-
*
-
*/
-
private function initListeners():void
-
{
-
this._front.addEventListener(InteractiveScene3DEvent.OBJECT_RELEASE, onPlaneClicked);
-
this._back.addEventListener(InteractiveScene3DEvent.OBJECT_RELEASE, onPlaneClicked);
-
-
this.addEventListener(Event.ENTER_FRAME, render);
-
}
-
-
//- PUBLIC & INTERNAL METHODS -----------------------------------------------------------------------------
-
-
-
-
//- EVENT HANDLERS ----------------------------------------------------------------------------------------
-
-
/**
-
*
-
*/
-
private function render($evt:Event):void
-
{
-
this._renderer.renderScene(this._scene, this._camera, this._viewport);
-
}
-
-
/**
-
*
-
*/
-
private function onPlaneClicked($evt:InteractiveScene3DEvent):void
-
{
-
var mam:MovieAssetMaterial = MovieAssetMaterial($evt.target.material);
-
-
if (mam.texture == "front")
-
{
-
TweenMax.to(this._front, 1, {rotationY: -180});
-
TweenMax.to(this._back, 1, {rotationY: 0});
-
}
-
else
-
{
-
TweenMax.to(this._front, 1, {rotationY: 0});
-
TweenMax.to(this._back, 1, {rotationY: 180});
-
}
-
}
-
-
//- GETTERS & SETTERS -------------------------------------------------------------------------------------
-
-
-
-
//- HELPERS -----------------------------------------------------------------------------------------------
-
-
override public function toString():String
-
{
-
return "com.reintroducing.Main";
-
}
-
-
//- END CLASS ---------------------------------------------------------------------------------------------
-
}
-
}
In the example, click on the plane to see the other side and click again to flip back to the front.











How can you stop the distortion when you move the plane left or right?
I'm not sure I understand what you are asking. Can you elaborate a bit?