WPF effects-Fish Swim Animation 3

Source: Internet
Author: User

Original: WPF effects-Fish Swim Animation 3

WPF does not support bones, so use 3DMax to export the sequence model file (. MTL;. obj).

Method 1:

Use blend 2013 to open all obj files, drag and arrange to display in UserControl, use RenderTargetBitmap to generate PNG sequence diagrams, and use a timer to play sequence diagrams.


Method 2:

? WPF has many class libraries that dynamically load obj model files, and dynamically loads all of the obj files using the loop method to dynamically generate a sequence diagram for each obj. (not yet tried, theory is no problem).


Method 3:

? Using Unity3d to open the exported skeleton model file, the resulting PNG sequence diagram is loaded in WPF (not yet tried).


Method One detailed:

1. Blend open obj sequence and arrange (blend project can be opened with VS, effect rendered in VS, 5 obj file used for testing)


2. Using RenderTargetBitmap to generate a PNG sequence diagram

 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();            }
? The PNG generated after the run is as follows:

3. Use the timer to play the sequence diagram

  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*In            Dex, 0, 300, 180)); This.        Imgmainzm.source = Osource; }

4. Final effect Demonstration

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??


5. Only 5 obj files are used for testing, the number of sequence frames is too small, so the fish action is more rigid, enough to avoid, for example, before I started to download the WinForm version of the demo:

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


? The code friend uses the sequence diagram as follows (about 20, frame, swimming effect is great):

??

? ?

WPF effects-Fish Swim Animation 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.