WPF特效-鱼游动动画3

原文: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,帧,游动效果很赞):

??

? ?

原文地址:https://www.cnblogs.com/lonelyxmas/p/9472668.html

时间: 2024-08-04 04:11:49

WPF特效-鱼游动动画3的相关文章

WPF特效-鱼游动动画

原文:WPF特效-鱼游动动画 ? 实现思路: ? ? ? ? ? 通过VisualBrush Binding方式获取鱼局部图像,在Viewport3D中创建ModelVisual3D块并把获取到的局部图通过VisualBrush Binding方式赋值.然后对ModelVisual3D块写3D 动画. ? ? ? ? ? 我的鱼原始图: 实现的效果: ? ? ? ? ? ? ? ? ? ? ? ?其他套路: ? ? ? 序列图动画帧循环加载. ? ? ? ?查阅资源,几乎都是在3DMax 或者U

基于css3小船水面游动动画特效

基于css3小船水面游动动画特效,这是一款色彩鲜艳扁平风格的css3动画特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="land"> <div class="land_01"></div> <div class="land_02"></div> <div class="land_03"></div&g

WPF特效-实现3D足球效果

原文:WPF特效-实现3D足球效果 WPF 实现 3D足球效果,效果图如下: ?每个面加载不同贴图. <UserControl x:Class="MediaBalll.Model3Ds.BuckyBall"? ? ? ? ? ? ?xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"? ? ? ? ? ? ?xmlns:x="http://schemas.microsoft

WPF特效-绘制实时2D激光雷达图

原文:WPF特效-绘制实时2D激光雷达图 接前两篇: https://blog.csdn.net/u013224722/article/details/80738619 https://blog.csdn.net/u013224722/article/details/80738995 除了c# GDI .Opencv(c++). c# Emgu绘图外,其实c#? WPF绘图功能也很强大.上文中之所以最终使用了Emgu绘图 ,只是因为在踩坑过程中尝试使用了Emgu的图像处理函数. 即首先将List

WPF特效-拼图游戏

原文:WPF特效-拼图游戏 此文主要描述我实现碎片化的便捷过程. 步骤1: ? ?选取参考图如下(百度图库搜的): 步骤2: ? ?根据效果图或者模型构建贝塞尔曲线,为了方便查看效果,可以设置控制点,Console.WriteLine或直接UI上显示的方式记录最终坐标,效果图如: ? ?上图中的红线,为两条贝塞尔曲线,左侧的位置我已经通过控制点的方式调好. 上图Gif为我调整上方第二条贝塞尔的示意. 步骤3: ?当上方右侧的第二条贝塞尔曲线也调整好后,就已经相当于调整好了所有的四条边. ? 具体

WPF 3D 平移模型+动画(桥梁检测系统)

原文:WPF 3D 平移模型+动画(桥梁检测系统) 关于WPF 3D,网上有很多旋转的例子,但是关于平移的例子并不是太多.本文并非WPF 3D扫盲篇,因此需要对WPF 3D有一定了解,至少知道Viewport, PerspectiveCamera, ModelVisual3D等数据结构.需要了解WPF 3D的基础知识,可以参考MSDN:?http://msdn.microsoft.com/zh-cn/library/ms747437.aspx. ? 1. 摄像机平移OR物体平移: WPF场景主要

WPF 精修篇 路径动画

原文:WPF 精修篇 路径动画 路径动画 是让一个对象围绕指定Path 的运动路径 进行移动的动画 举栗子 路径动画 使用 Blend 来设置 是十分简单的 首先用工具 笔  点出一条线 新建一个圆形对象 然后右键笔画出的路径 设置为运动路径 效果 可以把storyboard 设置成 Forever 这样就一直在循环运动 <Storyboard x:Key="Storyboard1" RepeatBehavior="Forever"> 原文地址:http

WPF 精修篇 属性动画

原文:WPF 精修篇 属性动画 属性动画 是通过 Storyboard 来改变属性值 <Rectangle x:Name="rect" Width="200" Height="200" > <Rectangle.Fill> <SolidColorBrush Color="Beige" x:Name="color"></SolidColorBrush> <

代码创建 WPF 旋转、翻转动画(汇总)

原文:代码创建 WPF 旋转.翻转动画(汇总) 先建立一个button <Button Width="80" Height="60" Content="旋转" Name="trans" Click="trans_Click" Style="{x:Null}"/> 方法一:绕左上角旋转 public void Transform1() { RotateTransform rtf