Got it.... TweenLite phase to Math.pi combined with tween rotationX + 180;

Not quite a 100% twist but 50% twist, 50% rotation.





On 25 November 2010 10:31, Darcey Lloyd <[email protected]> wrote:

> Hi
>
> Is is possible to get the twist modifier to do a twist to a max of 180 deg
> on an axis on a plane, to achieve a twist flip effect? Or should I be
> looking at doing this a different way?
>
> Thanks
>
> Darcey
>
>
>
>
> On 24 November 2010 16:33, jens lofberg <[email protected]> wrote:
>
>>  Happy to help... like your articles.
>>
>> jens
>>
>> Le 24/11/2010 17:05, Darcey Lloyd a écrit :
>>
>> Never mind my last response... Was me being dumb lol
>>
>>  I re-created the project as a pure AS3 Project (no mxml) and I get no
>> errors for type conversion and input params on new Twist(). And no error on
>> addModifier(twist). Then I realised I called the project Twist --- lol name
>> conflict. ( self slap lol ).
>>
>>
>>  I will post up articles on my site over the next few days with examples
>> of all the AS3DMod modifiers in use.
>>
>>  Thanks.
>>
>>  Darcey
>>
>>
>>
>>  Here is full working code:
>>
>>  package
>> {
>>  import away3d.cameras.HoverCamera3D;
>>  import away3d.containers.Scene3D;
>>  import away3d.containers.View3D;
>>  import away3d.core.render.BasicRenderer;
>>  import away3d.core.utils.Cast;
>>  import away3d.debug.AwayStats;
>>  import away3d.materials.BitmapMaterial;
>>  import away3d.primitives.Plane;
>>  import away3d.primitives.Trident;
>>   import com.as3dmod.ModifierStack;
>>  import com.as3dmod.core.Vector3;
>>  import com.as3dmod.modifiers.Bend;
>>  import com.as3dmod.modifiers.Twist;
>>  import com.as3dmod.plugins.away3d.LibraryAway3d;
>>  import com.as3dmod.util.Phase;
>>   import flash.display.Sprite;
>>  import flash.display.StageAlign;
>>  import flash.display.StageScaleMode;
>>  import flash.events.Event;
>>  import flash.events.MouseEvent;
>>  import flash.geom.Vector3D;
>>
>>
>>  [SWF(frameRate="31", backgroundColor="#FFFFFF")]
>>  //[SWF(width="800", height="600", frameRate="31"}]
>>  //
>> ------------------------------------------------------------------------------------------------
>>  public class AS3TwistTest extends Sprite
>>  {
>>  //
>> ------------------------------------------------------------------------------------------------
>>  // Embedded asssets
>>  /*
>>  [Embed(source='assets/front.jpg')]
>>  private var page1aAsset:Class;
>>   [Embed(source='assets/back.jpg')]
>>  private var page1bAsset:Class;
>>  */
>>  //
>> ------------------------------------------------------------------------------------------------
>>    //
>> ------------------------------------------------------------------------------------------------
>>  // Var defs
>>  //
>> ------------------------------------------------------------------------------------------------
>>  private var away3DContainer:Sprite;
>>  private var away3DStatsContainer:Sprite;
>>   // Var ini
>>  private var scene:Scene3D;
>>  private var camera:HoverCamera3D;
>>  private var view:View3D;
>>  private var renderer:BasicRenderer;
>>   private var bMove:Boolean = false;
>>  private var lastPanAngle:Number;
>>  private var lastTiltAngle:Number;
>>  private var lastMouseX:Number;
>>  private var lastMouseY:Number;
>>   // Primitives
>>  private var plane:Plane;
>>  private var nSegments:Number = 10;
>>   // Materials
>>  private var bmat1:BitmapMaterial;
>>  private var bmat2:BitmapMaterial;
>>   // Vars AS3DMod
>>  private var bend:Bend;
>>  private var twist:Twist;
>>  private var twistPhase:Phase;
>>  private var modStack:ModifierStack;
>>  //
>> ------------------------------------------------------------------------------------------------
>>    //
>> ------------------------------------------------------------------------------------------------
>>  public function AS3TwistTest()
>>  {
>>  // stage
>>  stage.align = StageAlign.TOP_LEFT;
>>  stage.scaleMode = StageScaleMode.NO_SCALE;
>>   // Containers
>>  away3DContainer = new Sprite();
>>  away3DStatsContainer = new Sprite();
>>  addChild(away3DContainer);
>>  addChild(away3DStatsContainer);
>>   // Setup Away3D
>>  camera = new HoverCamera3D();
>>  renderer = new BasicRenderer();
>>   scene = new Scene3D();
>>  view = new View3D();
>>  view.scene = scene;
>>  view.camera = camera;
>>  view.renderer = renderer;
>>  view.x = stage.stageWidth / 2;
>>  view.y = stage.stageHeight / 2;
>>   // Setup away3d stats (appears to slow the cpu)
>>  var awaystats:AwayStats = new AwayStats(view);
>>  away3DStatsContainer.addChild(awaystats);
>>   var tr:Trident = new Trident(500,true);
>>  scene.addChild(tr);
>>   // Setup camera
>>  camera.minTiltAngle = -80;
>>  camera.maxTiltAngle = 80;
>>  camera.panAngle = 150;
>>  camera.tiltAngle = 20;
>>  camera.zoom = 5;
>>   // Add Away3D to its container UIComponent
>>  away3DContainer.addChild(view);
>>   // Resize handler
>>  this.addEventListener(Event.RESIZE,handleBrowserResize);
>>  handleBrowserResize();
>>   // Enter frame handler (make things move)
>>  stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
>>  stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
>>  stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
>>    // Setup materials
>>  //bmat1 = new BitmapMaterial(  Cast.bitmap( new page1aAsset() )  );
>>  //bmat2 = new BitmapMaterial(  Cast.bitmap( new page1bAsset() )  );
>>   // generate
>>  generateScene();
>>  }
>>  //
>> ------------------------------------------------------------------------------------------------
>>      //
>> ------------------------------------------------------------------------------------------------
>>  private function generateScene():void
>>  {
>>  //plane = new
>> Plane({segmentsW:10,segmentsH:10,width:800,height:800,material:new
>> WireframeMaterial()});
>>  plane = new Plane();
>>  plane.segmentsW = plane.segmentsH = nSegments;
>>  plane.width = 800;
>>  plane.height = 800;
>>  plane.bothsides = true;
>>  //plane.material = bmat1;
>>  //plane.back = bmat2;
>>  scene.addChild(plane);
>>   // AS3DMod Start
>>  modStack = new ModifierStack(new LibraryAway3d(), plane);
>>   twist = new Twist(Math.PI/2);
>>  twist.vector = new Vector3(1,0,0);
>>  twistPhase = new Phase();
>>  modStack.addModifier(twist);
>>  }
>>  //
>> ------------------------------------------------------------------------------------------------
>>
>>     //
>> ------------------------------------------------------------------------------------------------
>>  private function onEnterFrame(event:Event):void
>>  {
>>  // AS3DMod - Animate twist and apply
>>  twistPhase.value += 0.05;
>>  twist.angle = Math.PI / 4 * twistPhase.phasedValue;
>>  trace("twist.angle = " + twist.angle); // Traces anglle from -0.7 to
>> +0.7
>>  this.modStack.apply();
>>     // Camera movement
>>  if (bMove) {
>>  camera.panAngle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle;
>>  camera.tiltAngle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle;
>>  }
>>   // Hover camera
>>  camera.hover();
>>   // Render
>>  view.render();
>>  }
>>  //
>> ------------------------------------------------------------------------------------------------
>>        //
>> ------------------------------------------------------------------------------------------------
>>  private function mouseDownHandler(event:MouseEvent):void
>>  {
>>  lastPanAngle = camera.panAngle;
>>  lastTiltAngle = camera.tiltAngle;
>>  lastMouseX = stage.mouseX;
>>  lastMouseY = stage.mouseY;
>>  bMove = true;
>>   stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
>>  }
>>  //
>> ------------------------------------------------------------------------------------------------
>>  //
>> ------------------------------------------------------------------------------------------------
>>  private function mouseUpHandler(event:MouseEvent):void
>>  {
>>  bMove = false;
>>  stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
>>  }
>>  //
>> ------------------------------------------------------------------------------------------------
>>  //
>> ------------------------------------------------------------------------------------------------
>>  private function onStageMouseLeave(event:Event):void
>>  {
>>  bMove = false;
>>  stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
>>  }
>>  //
>> ------------------------------------------------------------------------------------------------
>>      //
>> ------------------------------------------------------------------------------------------------
>>  // Browser resize handler (simply adjust view3d center x:0 y:0 at
>> browser 1/2 width and height to keep things in the middle
>>  private function handleBrowserResize(e:Event=null):void
>>  {
>>  this.view.x = stage.stageWidth/2;
>>  this.view.y = stage.stageHeight/2;
>>  }
>>  //
>> ------------------------------------------------------------------------------------------------
>>       }
>>  }
>>
>>
>>
>

Reply via email to