转自:http://hi.baidu.com/ych1219553/blog/item/a4efbb245ce69c034d088d06.html#send
关于ArcGIS的三维解决方案,用过ArcScene的朋友,应该是深有体会的了。。。当然我们也看到很多朋友在网上发布了很多三维处理效果图,真是让人兴奋不已呀。。。在这里我也把自己的所做的一些基于ArcGIS Engine的三维场景的动画轨迹的录制解决方法,跟大家共享!希望我的心血能为大家提供一点帮助!
在ArcGIS的接口里,提供了IAnimationTracks,通过它我们可以实现三维动画轨迹的创建,删除或在播放当前轨迹的三维场景效果,进而可以生成三维场景的录像输出处理方法(这个我在下一篇再给大家介绍),还是看看具体实现代码吧--
/// <summary> /// 创建动画轨迹 /// </summary> public void CreateAnimationTrack( string trackName ) { IAnimationTrack pAnimationTrack = new AnimationTrackClass(); IAnimationType pAnimationType = new AnimationTypeCameraClass(); pAnimationTrack.AnimationType = pAnimationType;
pAnimationTrack.Name = trackName; pAnimationTrack.AttachObject( pSceneGraph.ActiveViewer.Camera ); pAnimationTrack.ApplyToAllViewers = true; pAnimationTrack.EvenTimeStamps = false;
pAnimationTracks.AddTrack( pAnimationTrack ); }
/// <summary> /// 删除动画轨迹 /// </summary> public void RemoveAnimationTrack( string trackName ) { IAnimationTrack pAnimationTrack; pAnimationTracks.FindTrack( trackName, out pAnimationTrack ); pAnimationTracks.RemoveTrack( pAnimationTrack ); } /// <summary> /// 播放当前动画轨迹 /// </summary> public void PlayAnimationTrack( string trackName ) { Hashtable htKeyTime = null;
bool[] TracksEnable = new Boolean[pAnimationTracks.TrackCount]; IAnimationTrack pAnimationTrack; for( int index = 0; index < pAnimationTracks.TrackCount; index++ ) { pAnimationTrack = pAnimationTracks.Tracks.get_Element( index ) as IAnimationTrack; TracksEnable[index] = pAnimationTrack.IsEnabled; if( pAnimationTrack.Name == trackName ) { pAnimationTrack.IsEnabled = true; htKeyTime = ClsAnimationTracks.GetKeyTimeTable( pAnimationTrack.Name ); } else pAnimationTrack.IsEnabled = false;
}
int sumTime = 0; foreach( object obj in htKeyTime.Values ) { sumTime += Convert.ToInt32( obj ); }
double duration = (double)sumTime / 1000;
TimeSpan timeSpan; double elapsedTime;
DateTime startTime = DateTime.Now; int j = 0; do { timeSpan = (DateTime.Now).Subtract(startTime); elapsedTime = timeSpan.TotalSeconds; if (elapsedTime > duration) elapsedTime = duration; pAnimationTracks.ApplyTracks(pSceneGraph.ActiveViewer, elapsedTime, duration); pSceneGraph.RefreshViewers(); j = j + 1; }
for( int index = 0; index < pAnimationTracks.TrackCount; index++ ) { pAnimationTrack = pAnimationTracks.Tracks.get_Element( index ) as IAnimationTrack; pAnimationTrack.IsEnabled = TracksEnable[index]; } }
是不是很简单呢?记住哟,在播放轨迹的时候,有个时间的处理方法,具体在程序调试时,多试几次就知道是怎么回事了,我就不多说了。。。
当然,还有动画帧的处理方法,ArcGIS也提供了一个很方便的接口IKeyframe来实现的,再通过动画轨迹接口IAnimationTrack来实现动画帧的创建,删除等功能,代码实现如下:
/// <summary> /// 创建动画帧 /// </summary> public void CreateKeyFrame( IAnimationTrack pAnimationTrack, string keyName, int timeSpan ) { IKeyframe pKeyframe = new Bookmark3DClass(); pKeyframe.Name = keyName; pKeyframe.CaptureProperties( pScene, pSceneGraph.ActiveViewer.Camera );
pAnimationTrack.InsertKeyframe( pKeyframe, pAnimationTrack.KeyframeCount );
Hashtable htKeyTime = ClsAnimationTracks.GetKeyTimeTable( pAnimationTrack.Name ); int sumTime = 0; foreach( object obj in htKeyTime.Values ) { sumTime += Convert.ToInt32( obj ); }
double dblTime = 0; for( int index = 0; index < pAnimationTrack.KeyframeCount; index++ ) { pKeyframe = pAnimationTrack.get_Keyframe( index ); dblTime += Convert.ToDouble( htKeyTime[pKeyframe.Name] ) / sumTime; pKeyframe.TimeStamp = dblTime; } }
/// <summary> /// 删除动画帧 /// </summary> public void RemoveKeyFrame( IAnimationTrack pAnimationTrack, string keyName ) { for( int index = 0; index < pAnimationTrack.KeyframeCount; index++ ) { if( pAnimationTrack.get_Keyframe( index ).Name == keyName ) { pAnimationTrack.RemoveKeyframe( index ); break; } } }
/// <summary> /// 删除当前轨迹的所有帧 /// </summary> public void RemoveAllKeyFrame( IAnimationTrack pAnimationTrack ) { pAnimationTrack.RemoveAllKeyframes(); }
不知道大家对这些实现方法了解得多少?多多提意见哟。。。
转载于:https://www.cnblogs.com/willwayer/archive/2009/10/23/1588419.html
相关资源:ArcGIS Engine开发实例教程