WPF特效-魚遊動動畫3

來源:互聯網
上載者:User

標籤:png   exec   from   圖片   link   ++   save   director   dev   

原文: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,幀,遊動效果很贊):

??

? ?

WPF特效-魚遊動動畫3

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.