ufk

away3d testing

ufk
Jul 22nd, 2012
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.mycomp.Test01 {
  2.     import flash.ui.Keyboard;
  3.     import flash.events.KeyboardEvent;
  4.     import away3d.animators.AnimationStateBase;
  5.     import away3d.animators.SkeletonAnimationState;
  6.     import away3d.animators.data.Skeleton;
  7.     import away3d.containers.ObjectContainer3D;
  8.     import away3d.controllers.LookAtController;
  9.     import away3d.animators.SkeletonAnimator;
  10.     import away3d.animators.SkeletonAnimationSet;
  11.     import away3d.entities.Mesh;
  12.     import away3d.containers.Scene3D;
  13.     import away3d.library.assets.AssetType;
  14.     import away3d.cameras.Camera3D;
  15.     import away3d.events.AssetEvent;
  16.     import away3d.library.AssetLibrary;
  17.     import flash.system.Security;
  18.     import flash.net.URLRequest;
  19.     import away3d.loaders.parsers.Parsers;
  20.     import flash.events.Event;
  21.     import away3d.containers.View3D;
  22.     import flash.display.Sprite;
  23.  
  24.     public class Test01 extends Sprite {
  25.        
  26.         private var _view:View3D;
  27.         private var _scene:Scene3D;
  28.         private var _camera:Camera3D;
  29.         private var _mesh:Mesh;
  30.         private var animationSet:SkeletonAnimationSet;
  31.         private var animator:SkeletonAnimator;
  32.         private var cameraController:LookAtController;
  33.        
  34.        
  35.         public function Test01() {
  36.             Security.allowDomain("*");
  37.             this._view = new View3D();
  38.             this._view.backgroundColor= 0x666666;
  39.             this._view.antiAlias=4;
  40.            
  41.             this.addChild(this._view);
  42.             this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  43.            
  44.             Parsers.enableAllBundled();
  45.            
  46.             AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
  47.             AssetLibrary.load(new URLRequest('http://127.0.0.1/box.awd'));
  48.  
  49.             this._camera = new Camera3D();
  50.             this._camera.lens.far = 5000;
  51.             this._camera.lens.near = 20;
  52.             this._camera.y = 500;
  53.             this._camera.z = 0;
  54.            
  55.             this._scene = new Scene3D();
  56.            
  57.             this._view.camera=this._camera;
  58.             this._view.scene=this._scene;
  59.            
  60.             var placeHolder:ObjectContainer3D = new ObjectContainer3D();
  61.             placeHolder.z = 1000;
  62.             cameraController = new LookAtController(this._camera, placeHolder);
  63.            
  64.                 stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
  65.                 stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  66.            
  67.         }
  68.        
  69.         private function onKeyUp(event:KeyboardEvent):void {
  70.            
  71.         }
  72.        
  73.         private function onKeyDown(event:KeyboardEvent):void {
  74.             trace("key down");
  75.             switch (event.keyCode) {
  76.                 case (Keyboard.X):
  77.                     this._camera.rotationX+=0.5;                   
  78.                     break;
  79.                 case (Keyboard.Y):
  80.                     this._camera.rotationY+=0.5;                   
  81.                     break;
  82.                 case (Keyboard.Z):
  83.                     this._camera.rotationZ+=0.5;                   
  84.                     break;             
  85.             }
  86.            
  87.            
  88.         }
  89.        
  90.         private function onAssetComplete(event:AssetEvent):void {
  91.            
  92.             if (event.asset.assetType == AssetType.SKELETON) {
  93.                 trace("## SKELETON ASSET");
  94.                 var skeleton:Skeleton = event.asset as Skeleton;
  95.                 //create a new skeleton animation set
  96.                 animationSet = new SkeletonAnimationSet();
  97.                
  98.                 //wrap our skeleton animation set in an animator object and add our sequence objects
  99.                 animator = new SkeletonAnimator(animationSet, skeleton, false);
  100.                
  101.                
  102.                
  103.             }   else if (event.asset.assetType == AssetType.ANIMATION_STATE) {
  104.                 var animationState:SkeletonAnimationState = event.asset as SkeletonAnimationState;
  105.                 trace("## ANIMATION STATE ASSET name - " + animationState.name);
  106.                 animationSet.addState(animationState.name, animationState);
  107.                
  108.             } else if (event.asset.assetType == AssetType.MESH) {
  109.                 trace("## MESH ASSET");
  110.                 this._mesh = event.asset as Mesh;
  111.                 this._mesh.castsShadows = true;
  112.                 this._mesh.scale(10);
  113.                 this._mesh.z = 1000;
  114.                 this._mesh.rotationY = -45;    
  115.             //  this._mesh.animator=this.animator;
  116.                 this._scene.addChild(this._mesh);
  117.                 cameraController.lookAtObject = this._mesh;
  118.             }
  119.            
  120.         }
  121.        
  122.         private function onEnterFrame(ev : Event) : void
  123.         {
  124.                 _view.render();
  125.         }      
  126.        
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment