WPF特效-鱼游动动画3

WPF不支持骨骼,故使用3DMax导出了序列模型文件(.mtl;.obj)。

方法1:

使用Blend 2013打开所有obj文件,拖动排列一下即可在usercontrol中显示,使用RenderTargetBitmap生成png的序列图,使用Timer播放序列图即可。


方法2:

 WPF有很多动态加载obj模型文件的类库,使用循环方法,动态加载所有obj文件,动态生成每个obj对应的序列图。(尚未尝试,理论毫无问题)。


方法3:

  使用Unity3D 打开导出的带骨骼的模型文件,生成png序列图在WPF中加载(尚未尝试)。


方法一详细:

1、Blend打开obj序列并排列(blend项目可以用vs打开,下图为VS中呈现的效果,使用了5个Obj文件,用于测试)


2、使用RenderTargetBitmap生成png序列图

 string sTargetFile = AppDomain.CurrentDomain.BaseDirectory + "Fish1.png";

            RenderTargetBitmap oRenderTargetBitmap = new RenderTargetBitmap((int)this.GdMainZm.Width,
                (int)this.GdMainZm.Height, 96, 96, PixelFormats.Pbgra32);
            oRenderTargetBitmap.Render(this.GdMainZm);

            PngBitmapEncoder oPngEncoder = new PngBitmapEncoder();
            oPngEncoder.Frames.Add(BitmapFrame.Create(oRenderTargetBitmap));
            using (Stream stm = File.Create(sTargetFile))
            {
                oPngEncoder.Save(stm);
                stm.Close();
            }
 运行后生成的png效果图如下:

3、使用Timer播放序列图

   private ImageSource ImageSrc;
        private DispatcherTimer TimerPlay;
        private int Index = -1;

        private void FishItem8_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= FishItem8_Loaded;

            AsynchUtils.AsynchDelayExecuteFunc(() => {
                this.TimerPlay = new DispatcherTimer(DispatcherPriority.SystemIdle);
                this.TimerPlay.Interval = TimeSpan.FromSeconds(0.3);
                this.TimerPlay.Tick += TimerPlay_Tick;
                this.TimerPlay.Start();
            }, Utilitys.GetRandomSeed().NextDouble());
        }

        private void TimerPlay_Tick(object sender, EventArgs e)
        {
            Index++;
            if (Index >= 5)
                Index = 0;

            BitmapSource oSource = new CroppedBitmap(BitmapFrame.Create((BitmapSource)ImageSrc),
                  new Int32Rect(300*Index, 0, 300, 180));
            this.ImgMainZm.Source = oSource;
        }

4、最终效果演示

                                            


5、只使用了5个obj文件用于测试,序列帧数量过少,所以鱼动作比较呆板,足够多时可避免,例如在我开始之前下载的Winform版的Demo:

http://download.csdn.net/download/staricqxyz/1433772


  该码友采用的序列图如下(约20,帧,游动效果很赞):

  

   

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DuelCode

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值