标题: Away3D中MD5动画加载和互动实例 [打印本页] 作者: 铁锹 时间: 2012-12-21 13:37 标题: Away3D中MD5动画加载和互动实例 本文分享的是Away3D中MD5动画加载和互动实例,全文摘录如下:全屏演示请点击3D动画效果截图进入: /* MD5 animation loading and interaction example in Away3d Demonstrates: How to load MD5 mesh and anim files with bones animation from embedded resources.How to map animation data after loading in order to playback an animation sequence.How to control the movement of a game character using keys. Code by Rob Bateman & David Lenaertsrob@infiniteturtles.co.ukhttp://www.infiniteturtles.co.ukdavid.lenaerts@gmail.comhttp://www.derschmale.com This code is distributed under the MIT License Copyright (c) Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the “Software”), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so,subject to the following conditions: The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE. */
//setup controller to be used on the camera
placeHolder = new Mesh();
placeHolder.y = 50;
cameraController = new LookAtController(camera, placeHolder);
/** * Initialise the lights */privatefunction initLights():void{//create a light for shadows that mimics the sun's position in the skybox
redLight = new PointLight();
redLight.x = -1000;
redLight.y = 200;
redLight.z = -1400;
redLight.color = 0xff1111;
scene.addChild(redLight);
//create a snowy ground plane
ground = new Mesh(new PlaneGeometry(50000, 50000, 1, 1), groundMaterial);
ground.geometry.scaleUV(200, 200);
ground.castsShadows = false;
scene.addChild(ground);
//create a skybox
cubeTexture = new BitmapCubeTexture(new EnvPosX().bitmapData, new EnvNegX().bitmapData, new EnvPosY().bitmapData, new EnvNegY().bitmapData, new EnvPosZ().bitmapData, new EnvNegZ().bitmapData);
skyBox = new SkyBox(cubeTexture);
scene.addChild(skyBox);
}
/** * Initialise the hellknight mesh */privatefunction initMesh():void{//parse hellknight mesh
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
AssetLibrary.loadData(new HellKnight_Mesh(), null, null, new MD5MeshParser());
}
/** * Initialise the hellknight animations */privatefunction initAnimations():void{
animator = new SmoothSkeletonAnimator(mesh.animationState as SkeletonAnimationState);
for(var i:uint = 0; i < ANIM_NAMES.length; ++i)
AssetLibrary.loadData(new ANIM_CLASSES(), null, ANIM_NAMES, new MD5AnimParser());
/** * Listener function for asset complete event on loader */privatefunction onAssetComplete(event:AssetEvent):void{if(event.asset.assetType == AssetType.ANIMATION){
var seq:SkeletonAnimationSequence = event.asset as SkeletonAnimationSequence;
seq.name = event.asset.assetNamespace;
animator.addSequence(seq);
/** * Key down listener for animation */privatefunctiononKeyDown(event:KeyboardEvent):void{switch(event.keyCode){case Keyboard.SHIFT:
isRunning = ***e;
if(isMoving)
updateMovement(movementDirection);
break;
case Keyboard.UP:
case Keyboard.W:
updateMovement(movementDirection = 1);
break;
case Keyboard.DOWN:
case Keyboard.S:
updateMovement(movementDirection = -1);
break;
case Keyboard.LEFT:
case Keyboard.A:
currentRotationInc = -ROTATION_SPEED;
break;
case Keyboard.RIGHT:
case Keyboard.D:
currentRotationInc = ROTATION_SPEED;
break;
case Keyboard.NUMBER_1:
playAction(1);
break;
case Keyboard.NUMBER_2:
playAction(2);
break;
case Keyboard.NUMBER_3:
playAction(3);
break;
case Keyboard.NUMBER_4:
playAction(4);
break;
case Keyboard.NUMBER_5:
playAction(5);
break;
case Keyboard.NUMBER_6:
playAction(6);
break;
case Keyboard.NUMBER_7:
playAction(7);
break;
case Keyboard.NUMBER_8:
playAction(8);
break;
case Keyboard.NUMBER_9:
playAction(9);
break;
}}
privatefunctiononKeyUp(event:KeyboardEvent):void{switch(event.keyCode){case Keyboard.SHIFT:
isRunning = false;
if(isMoving)
updateMovement(movementDirection);
break;
case Keyboard.UP:
case Keyboard.W:
case Keyboard.DOWN:
case Keyboard.S:
stop();
break;
case Keyboard.LEFT:
case Keyboard.A:
case Keyboard.RIGHT:
case Keyboard.D:
currentRotationInc = 0;
break;
}}