標籤: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