前面的几篇博文提高了3D符号化以及根据路径创建动画方面的内容,先来看下效果图:
那么创建的动画应该怎么保存呢?通过查找帮助文档以及OMD,可以知道Globe实现了IBasicScene接口和IBasicScene2接口,通过其LoadAnimation和SaveAnimation方法就可以加载和保存动画文件。如下图:
代码如下:
//加载动画文件 .aga private void button_loadAnimation_Click (object sender,EventArgs e) { try { OpenFileDialog openDlgAnimation = new OpenFileDialog(); openDlgAnimation.Title = "加载动画文件(.aga)"; openDlgAnimation.Filter = "动画文件(*.aga)|*.aga"; string strAnimationName = ""; DialogResult Dr = openDlgAnimation.ShowDialog(); if (Dr==DialogResult.OK) { strAnimationName = openDlgAnimation.FileName; IGlobe globe = m_globeControl.Globe; IBasicScene basicscene = globe as IBasicScene; basicscene.LoadAnimation(strAnimationName); } } catch (System.Exception ex) { MyMessagebox pMyMessagebox=new MyMessagebox(ex.Message); pMyMessagebox.Show(); } } //保存动画文件 private void button_SaveAnimation_Click (object sender,EventArgs e) { IGlobe globe = m_globeControl.Globe; int tracksCount = (globe as IAGAnimationTracks).AGTracks.Count; if (tracksCount>0) { IBasicScene2 basicscene = globe as IBasicScene2; OpenFileDialog openSaveAnimationDlg = new OpenFileDialog(); openSaveAnimationDlg.Title = "选择动画存放路径"; openSaveAnimationDlg.Filter = "动画文件(*.aga)|*.aga"; openSaveAnimationDlg.FileName = "输电线路动画.aga"; DialogResult DR = openSaveAnimationDlg.ShowDialog(); if (DR==DialogResult.OK) { basicscene.SaveAnimation(openSaveAnimationDlg.FileName); } else { MyMessagebox pMymessagebox = new MyMessagebox("动画未保存!"); pMymessagebox.Show(); } } else { MyMessagebox mymessagebox = new MyMessagebox("当前视图不包含动画文件!"); mymessagebox.Show(); } }
下面一片博文将介绍如何在globeControl下播放动画,敬请关注!