在 ActionScript 3 中使用 Papervision 3D 返回 md2 的动画通道?

发布于 2024-07-16 06:29:58 字数 1072 浏览 8 评论 0原文

我目前正在研究 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]

根据我在自己的搜索中看到的情况,这应该返回字符串形式的通道名称数组。 我尝试从 MorphChannel3D 对象中提取属性,但使用 foreach(var p:* in Object); 没有成功。

我哪里出错了,如何获取动画频道的名称以便我可以随意调用它们?

此处的项目示例

谢谢。

I am currently working on a FlarToolkit / Papervision3D / Quake2 model parsing, that I have successfully loaded, textured, and animated. That being said, the animation calls are merely a guess to me and so far all I know is that "jump" and "run" are available. When i use the built in getAnimationChannels() of the MD2 class, it merely returns and array of MorphChannel3D Objects as follows.

//md2 is a model that is already loaded and waiting utilizing the given events for such.

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]

From what I have seen in my own searches, this should be returning an array of the channel names in String form. I attempted to extract properties from the MorphChannel3D Object with no success using for each(var p:* in Object);

Where am I going wrong, and how can I obtain the name of the animation channels so that I may call them at will?

Example of the project here

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2024-07-23 06:29:58

有趣的项目。

我玩了一下 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();
        }

    }

}

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

希望这可以帮助。

Interesting project.

I played with MD2 a bit, but I got confused. Didn't know what classes to use and how. I asked the guys on the papervision mailing list, but no clear answers.

Here is my test

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();
        }

    }

}

This was created a few months ago, so it might be worth while checking for updates. In my test, things are done a bit manually. I remember seeing some nice demos on the ascollada website, but never had the chance to see how they implemented md2 animation.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文