在动作脚本3中使用Papervision 3D返回md2的动画频道?

时间:2009-03-30 18:04:15

标签: actionscript-3 papervision3d

我目前正在进行FlarToolkit / Papervision3D / Quake2模型解析,我已成功加载,纹理化和动画化。话虽这么说,动画调用仅仅是对我的一种猜测,到目前为止我所知道的是“跳跃”和“运行”是可用的。当我使用MD2类的内置getAnimationChannels()时,它只返回MorphChannel3D对象和数组,如下所示。

// md2是一个已经加载并等待使用给定事件的模型。

trace(_md2.getAnimationChannels()); //returns [object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D],[object MorphChannel3D]

从我在自己的搜索中看到的,这应该是以String形式返回一个通道名称数组。我尝试从MorphChannel3D对象中提取属性,但没有成功使用每个属性(对象中的var p:*);

我哪里出错了,如何获取动画频道的名称,以便我可以随意拨打电话?

Example of the project here

感谢。

1 个答案:

答案 0 :(得分:0)

有趣的项目。

我玩了MD2,但我感到很困惑。不知道使用什么类以及如何使用。我在papervision邮件列表上询问了这些人,但没有明确的答案。

这是我的测试

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import org.papervision3d.core.animation.channel.AbstractChannel3D;
    import org.papervision3d.core.animation.channel.MorphChannel3D;

    import org.papervision3d.events.AnimationEvent;
    import org.ascollada.utils.FPS;
    import org.papervision3d.cameras.*;
    import org.papervision3d.core.geom.*;
    import org.papervision3d.core.geom.renderables.*;
    import org.papervision3d.events.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.special.*;
    import org.papervision3d.materials.utils.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.parsers.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.render.*;
    import org.papervision3d.scenes.*;
    import org.papervision3d.view.*;
    import org.papervision3d.view.layer.*;

    /**
    * Basic MD2Test Class
    * @author George Profenza
    */
    public class MD2Test extends Sprite
    {

        private var viewport:BasicView;
        private var timer:Timer;
        private var fps:FPS;
        private var container:DisplayObject3D;
        private var box:MD2;
        private var isPlaying:Boolean = true;
        private var _channels:Array;
        private var _numFrames:int;
        private var _currentFrame:int;
        private var frameCount:int = 1;

        public function MD2Test() 
        {
            init();
        }

        private function init():void {

            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.SHOW_ALL;

            viewport = new BasicView(0, 0, true, true, CameraType.FREE);
            addChild(viewport);

            container = new DisplayObject3D();
            viewport.scene.addChild(container);

            fps = new FPS();
            addChild(fps);

            var mat:WireframeMaterial = new WireframeMaterial(0x990000);
            mat.doubleSided = true;

            box = new MD2(false);
            box.rotationX = -90;
            box.load("animations/box_wrap_anim.md2", mat, 6, 10);
            box.addEventListener(FileLoadEvent.LOAD_COMPLETE, boxLoaded);
            box.addEventListener(AnimationEvent.ANIMATION_NEXT_FRAME, boxAnimationComplete);
            container.addChild(box);

            //var channel:AnimationCha = new MorphChannel3D(box);

            var btnPlay:Sprite = new Sprite();
            btnPlay.graphics.beginFill(0x990000);
            btnPlay.graphics.drawRect(0, 0, 60, 20);
            btnPlay.graphics.endFill();
            addChild(btnPlay);
            btnPlay.y = 100;
            btnPlay.addEventListener(MouseEvent.CLICK, playMD2);

            var btnNextFrame:Sprite = new Sprite();
            btnNextFrame.graphics.beginFill(0x990000);
            btnNextFrame.graphics.drawRect(0, 0, 60, 20);
            btnNextFrame.graphics.endFill();
            addChild(btnNextFrame);
            btnNextFrame.y = 200;
            btnNextFrame.addEventListener(MouseEvent.CLICK, playNextFrame);

            addEventListener(Event.ENTER_FRAME, render);
        }

        private function boxAnimationComplete(e:AnimationEvent):void 
        {
            trace('box animation complete');
        }

        private function playNextFrame(e:MouseEvent):void 
        {
            if (frameCount < _numFrames) frameCount++;
            else frameCount = frameCount;
            gotoFrame(frameCount);
        }

        private function boxLoaded(e:FileLoadEvent):void 
        {
            _channels = box.getAnimationChannels();

           trace("channel count", _channels.length);
           rewind();

           _numFrames = 0;
           _currentFrame = 1;

           for each(var channel:AbstractChannel3D in _channels)
           {
               _numFrames = Math.max(_numFrames, channel.keyFrames.length);
               channel.updateToFrame(_currentFrame);
           }
        }

        public function rewind():void
       {
           trace("channels length: " + box.getAnimationChannels().length);
           for each(var channel:AbstractChannel3D in _channels)
           {
               channel.updateToFrame(1);
           }
       }

       public function gotoFrame(frame:Number):void
       {
           for each(var channel:AbstractChannel3D in _channels)
               channel.updateToFrame(frame);
       }


        private function playMD2(e:MouseEvent):void 
        {
            isPlaying = !isPlaying;
            isPlaying ? box.stop() : box.play();
        }

        private function render(e:Event):void 
        {
            viewport.camera.orbit(mouseY * .5, mouseX * .5);
            viewport.singleRender();
        }

    }

}

这是几个月前创建的,所以在检查更新时可能是值得的。在我的测试中,事情是手动完成的。我记得在the ascollada website看过一些不错的演示,但从未有机会看到他们如何实现md2动画。

希望这有帮助。