Tweens into an external file

Software: Away3D 3.x

Bertie, Newbie
Posted: 13 December 2011 03:18 PM   Total Posts: 8

Hi everybody,

I have made a 3D model of a cube and imported it into Flash Builder with preFab and away3d as follows:


package
{
    import away3d.cameras.HoverCamera3D;
    import away3d.containers.*;
    import away3d.events.MouseEvent3D;
   
    import com.greensock.TweenLite;
   
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.utils.*;
   
    import models.cube;
   
    [SWF(width=“600”, height=“600”, frameRate=“60”, backgroundColor=”#000000”)]
   
    public class model extends Sprite
    {
      public var view:View3D;
      private var cam:HoverCamera3D;
      private var move:Boolean = false;
      private var lastPanAngle:Number;
      private var lastTiltAngle:Number;
      private var lastMouseX:Number;
      private var lastMouseY:Number;
     
      public var model_cube:cube = new cube;
      public var side:cube; //?
     
      public function model()
      {
          start();
          view.scene.addChild(model_cube);
          turn(); //?
      }
     
      public function start(): void
      {
          cam = new HoverCamera3D({zoom:1, focus:7});
          cam.panAngle = cam.panAngle = 25;
          cam.tiltAngle = cam.tiltAngle = 25;
          cam.hover(true);
         
          view = new View3D({x:300,y:300,camera:cam});
          addChild(view);
          view.camera.y = 300;
          view.camera.zoom = 50;
         
          this.addEventListener(Event.ENTER_FRAME,update);
          stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);
          stage.addEventListener(MouseEvent.MOUSE_UP, MouseUp);
      }
     
      public function turn():void
      {
          // ?        TweenLite.to(side.Obj_000002_Bitmap_Bitmap, 1, {rotationZ:90, timeScale:0.5, scaleX:1, scaleY:1});
      }
     
      public function update(e:Event):void
      {
          var cameraSpeed:Number = 0.5;
          if (move)
          {
              cam.panAngle = cameraSpeed*( stage.mouseX - lastMouseX) + lastPanAngle;
              cam.tiltAngle = cameraSpeed*(- stage.mouseY + lastMouseY) + lastTiltAngle;
          }
          cam.hover();
          view.render();
      }
     
      private function MouseDown(event:MouseEvent):void
      {
          lastPanAngle = cam.panAngle;
          lastTiltAngle = cam.tiltAngle;
          lastMouseX = stage.mouseX;
          lastMouseY = stage.mouseY;
          move = true;
      }
     
      private function MouseUp(event:MouseEvent):void
      {
          move = false;
      }
    }
}


The 3D model of the cube consists of 6 sides with each their own texture (jpg). You can find the script of the cube in the attachment.

Is it possible to turn around one of the 6 sides of the cube with a tween from the script above?
So is it possible to do tweens into an external file (attached file) from another file?

 

File Attachments
cube.as  (File Size: 11KB - Downloads: 290)
   

Avatar
Fabrice Closier, Administrator
Posted: 13 December 2011 03:50 PM   Total Posts: 1265   [ # 1 ]

Yes, but as you use hover camera, you will have locks on poles, and/or get weird rotations.
So If I was you, I would here rotate the cube instead, or let camera and cube do 1/2 of the tween.

 

   

Bertie, Newbie
Posted: 13 December 2011 04:14 PM   Total Posts: 8   [ # 2 ]

Thanks for the quick reply.

I think I understand what you mean.
But isn’t it possible to rotate only the texture of one side? So not the real side but only the jpg picture that is “projected” on the side?

 

   

Bertie, Newbie
Posted: 13 December 2011 09:12 PM   Total Posts: 8   [ # 3 ]

Below you can see a part of the code of the cube which is made by preFab.
The complete code is attached.

I have added some code (in red) and I know that it doesn’t work. But I don’t know why it’s not working.

package model
{
import away3d.containers.ObjectContainer3D;
import away3d.containers.Scene3D;
import away3d.materials.*;
import away3d.core.base.*;
import away3d.loaders.utils.*;
import away3d.loaders.data.*;
import flash.utils.Dictionary;
import away3d.primitives.*;
import flash.display.Bitmap;
import flash.display.BitmapData;

import away3d.events.MouseEvent3D;

import com.greensock.TweenLite;

import flash.geom.*;

public class cube extends ObjectContainer3D
{
  [Embed(source=“images/Obj_000001.jpg”)]
  public var Obj_000001_Bitmap_Bitmap:Class;

  [Embed(source=“images/Obj_000002.jpg”)]
  private var Obj_000002_Bitmap_Bitmap:Class;

  [Embed(source=“images/Obj_000003.jpg”)]
  private var Obj_000003_Bitmap_Bitmap:Class;

  [Embed(source=“images/Obj_000004.jpg”)]
  private var Obj_000004_Bitmap_Bitmap:Class;

  [Embed(source=“images/Obj_000005.jpg”)]
  private var Obj_000005_Bitmap_Bitmap:Class;

  [Embed(source=“images/Obj_000006.jpg”)]
  private var Obj_000006_Bitmap_Bitmap:Class;

  private var objs:Object = {};
  private var geos:Array = [];
  private var oList:Array =[];
  private var aC:Array;
  private var aV:Array;
  private var aU:Array;
  private var _scale:Number;

  public function cube(scale:Number = 1)
  {
  _scale = scale;
  setSource();
  addContainers();
  buildMeshes();
  buildMaterials();
  cleanUp();
 
  Obj_000002_Bitmap_Bitmap.addOnMouseDown(rotate);
  }
 
  public function rotate():void
  {
  TweenLite.to(Obj_000002_Bitmap_Bitmap, 1, {rotationZ:90, timeScale:0.5, scaleX:1, scaleY:1});
  }

 
  private function buildMeshes():void
  {
  var m0:Matrix3D = new Matrix3D();
  m0.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0*_scale,0*_scale,-2535*_scale,1]);
  transform = m0;

  objs.obj0 = {name:“Obj_000001”,  transform:m0, pivotPoint:new Vector3D(0,0,0), container:0, bothsides:false, material:null, ownCanvas:false, pushfront:false, pushback:false};
  objs.obj0.geo=geos[0];
  var m1:Matrix3D = new Matrix3D();
  m1.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0*_scale,0*_scale,2535*_scale,1]);
  transform = m1;

  objs.obj1 = {name:“Obj_000002”,  transform:m1, pivotPoint:new Vector3D(0,0,0), container:0, bothsides:false, material:null, ownCanvas:false, pushfront:false, pushback:false};
  objs.obj1.geo=geos[1];
  var m2:Matrix3D = new Matrix3D();
  m2.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,2575*_scale,0*_scale,0*_scale,1]);
  transform = m2;

  objs.obj2 = {name:“Obj_000003”,  transform:m2, pivotPoint:new Vector3D(0,0,0), container:0, bothsides:false, material:null, ownCanvas:false, pushfront:false, pushback:false};
  objs.obj2.geo=geos[2];
  var m3:Matrix3D = new Matrix3D();
  m3.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0*_scale,2475*_scale,0*_scale,1]);
  transform = m3;

  objs.obj3 = {name:“Obj_000004”,  transform:m3, pivotPoint:new Vector3D(0,0,0), container:0, bothsides:false, material:null, ownCanvas:false, pushfront:false, pushback:false};
  objs.obj3.geo=geos[3];
  var m4:Matrix3D = new Matrix3D();
  m4.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,-2575*_scale,0*_scale,0*_scale,1]);
  transform = m4;

  objs.obj4 = {name:“Obj_000005”,  transform:m4, pivotPoint:new Vector3D(0,0,0), container:0, bothsides:false, material:null, ownCanvas:false, pushfront:false, pushback:false};
  objs.obj4.geo=geos[4];
  var m5:Matrix3D = new Matrix3D();
  m5.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0*_scale,-2475*_scale,0*_scale,1]);
  transform = m5;

  objs.obj5 = {name:“Obj_000006”,  transform:m5, pivotPoint:new Vector3D(0,0,0), container:0, bothsides:false, material:null, ownCanvas:false, pushfront:false, pushback:false};
  objs.obj5.geo=geos[5];

  var ref:Object;
  var mesh:Mesh;
  var j:int;
  var av:Array;
  var au:Array;
  var v0:Vertex;
  var v1:Vertex;
  var v2:Vertex;
  var u0:UV;
  var u1:UV;
  var u2:UV;
  var aRef:Vector.<Face>;
  for(var i:int = 0;i

 

File Attachments
cube.zip  (File Size: 3KB - Downloads: 148)
   

Bertie, Newbie
Posted: 15 December 2011 01:43 PM   Total Posts: 8   [ # 4 ]

Actually the next error appears:

TypeError: Error #1006: addOnMouseDown is not a function.

I don’t understand why this error appears. I have used this addOnMouseDown before without problems.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X