Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mycomp.Test01 {
- import flash.ui.Keyboard;
- import flash.events.KeyboardEvent;
- import away3d.animators.AnimationStateBase;
- import away3d.animators.SkeletonAnimationState;
- import away3d.animators.data.Skeleton;
- import away3d.containers.ObjectContainer3D;
- import away3d.controllers.LookAtController;
- import away3d.animators.SkeletonAnimator;
- import away3d.animators.SkeletonAnimationSet;
- import away3d.entities.Mesh;
- import away3d.containers.Scene3D;
- import away3d.library.assets.AssetType;
- import away3d.cameras.Camera3D;
- import away3d.events.AssetEvent;
- import away3d.library.AssetLibrary;
- import flash.system.Security;
- import flash.net.URLRequest;
- import away3d.loaders.parsers.Parsers;
- import flash.events.Event;
- import away3d.containers.View3D;
- import flash.display.Sprite;
- public class Test01 extends Sprite {
- private var _view:View3D;
- private var _scene:Scene3D;
- private var _camera:Camera3D;
- private var _mesh:Mesh;
- private var animationSet:SkeletonAnimationSet;
- private var animator:SkeletonAnimator;
- private var cameraController:LookAtController;
- public function Test01() {
- Security.allowDomain("*");
- this._view = new View3D();
- this._view.backgroundColor= 0x666666;
- this._view.antiAlias=4;
- this.addChild(this._view);
- this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
- Parsers.enableAllBundled();
- AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
- AssetLibrary.load(new URLRequest('http://127.0.0.1/box.awd'));
- this._camera = new Camera3D();
- this._camera.lens.far = 5000;
- this._camera.lens.near = 20;
- this._camera.y = 500;
- this._camera.z = 0;
- this._scene = new Scene3D();
- this._view.camera=this._camera;
- this._view.scene=this._scene;
- var placeHolder:ObjectContainer3D = new ObjectContainer3D();
- placeHolder.z = 1000;
- cameraController = new LookAtController(this._camera, placeHolder);
- stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
- }
- private function onKeyUp(event:KeyboardEvent):void {
- }
- private function onKeyDown(event:KeyboardEvent):void {
- trace("key down");
- switch (event.keyCode) {
- case (Keyboard.X):
- this._camera.rotationX+=0.5;
- break;
- case (Keyboard.Y):
- this._camera.rotationY+=0.5;
- break;
- case (Keyboard.Z):
- this._camera.rotationZ+=0.5;
- break;
- }
- }
- private function onAssetComplete(event:AssetEvent):void {
- if (event.asset.assetType == AssetType.SKELETON) {
- trace("## SKELETON ASSET");
- var skeleton:Skeleton = event.asset as Skeleton;
- //create a new skeleton animation set
- animationSet = new SkeletonAnimationSet();
- //wrap our skeleton animation set in an animator object and add our sequence objects
- animator = new SkeletonAnimator(animationSet, skeleton, false);
- } else if (event.asset.assetType == AssetType.ANIMATION_STATE) {
- var animationState:SkeletonAnimationState = event.asset as SkeletonAnimationState;
- trace("## ANIMATION STATE ASSET name - " + animationState.name);
- animationSet.addState(animationState.name, animationState);
- } else if (event.asset.assetType == AssetType.MESH) {
- trace("## MESH ASSET");
- this._mesh = event.asset as Mesh;
- this._mesh.castsShadows = true;
- this._mesh.scale(10);
- this._mesh.z = 1000;
- this._mesh.rotationY = -45;
- // this._mesh.animator=this.animator;
- this._scene.addChild(this._mesh);
- cameraController.lookAtObject = this._mesh;
- }
- }
- private function onEnterFrame(ev : Event) : void
- {
- _view.render();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment