How to convert 3D bookmarks to GlobeCamera keyframes


This routine converts 3D bookmarks in the current ArcGlobe document to GlobeCamera keyframes. The keyframes are then used to create a Globe Camera animation comprised of a Globe Camera animation track. This animation can then be played using controls provided on the Animation Controls dialog.

How to use

  1. Paste the code into ArcGlobe's Visual Basic Editor.
  2. Make sure that you have some 3D bookmarks in the current ArcGlobe document
  3. Run the calling procedure.
  4. Play the animation using the controls provided on the Animation Controls dialog. (Note: You need to have the Animation toolbar checked on to gain access to Animation Controls.)
[VBA]
Option Explicit

Public Sub ConvertBookmarkToGlobeCameraKeyframe()
    
    Dim pGMxDoc As IGMxDocument
    Set pGMxDoc = ThisDocument
    
    Dim pScene As IScene
    Set pScene = pGMxDoc.Scene
    
    Dim pGlobe As IGlobe
    Set pGlobe = pScene
    
    Dim pGlobeDisp As IGlobeDisplay
    Set pGlobeDisp = pGlobe.GlobeDisplay
    
    Dim pCamera As ICamera
    Set pCamera = pGlobeDisp.ActiveViewer.Camera
    
    Dim pGlobeCamera As IGlobeCamera
    
    ' Set the Animation Type to be of type GlobeCamera
    
    Dim pAnimTypeGlobeCamera As IAnimationType
    Set pAnimTypeGlobeCamera = New AnimationTypeGlobeCamera
    
    ' Create a New animation track:
    
    Dim pAnimTrack As IAnimationTrack
    Set pAnimTrack = New AnimationTrack
    
    ' Set the Animation Track Type to be GlobeCamera
    
    Set pAnimTrack.AnimationType = pAnimTypeGlobeCamera
    
    ' Get the Bookmarks in the current Scene
    
    Dim p3DBookmarks As ISceneBookmarks
    Set p3DBookmarks = pScene
    
    Dim i As Integer
    For i = 0 To p3DBookmarks.BookmarkCount - 1
        
        Dim p3DBookmark As IBookmark3D
        
        ' Find the bookmark specified in the list of bookmarks to be used in the Animation
        
        p3DBookmarks.FindBookmark "Bookmark " & i + 1, p3DBookmark
        
        ' Apply the Bookmark to the current viewer (Camera will actually visit those areas)
        
        p3DBookmark.Apply pGlobeDisp.ActiveViewer, False, 0
        
        ' Capture the Camera Location/Properties of the current Scene/bookmark, so we can re-visit it
        
        Dim pBookmarkLocation As IBookmark3D
        Set pBookmarkLocation = New Bookmark3D
        
        ' Get the camera properties at the current Scene/Bookmark location
        
        pBookmarkLocation.Capture pCamera
        
        ' Create a New Keyframe
        
        Dim pKeyframe As IKeyframe
        Set pKeyframe = New GlobeCameraKeyframe
        
        Dim pXT As Double
        Dim pYT As Double
        Dim pZT As Double
        
        pCamera.Target.QueryCoords pXT, pYT
        pZT = pCamera.Target.Z
        
        If (pXT * pXT + pYT * pYT + pZT * pZT) _
            < 0.000000000001 Then
            Set pGlobeCamera = pCamera
            pGlobeCamera.OrientationMode = esriGlobeCameraOrientationGlobal
        Else
            Set pGlobeCamera = pCamera
            pGlobeCamera.OrientationMode = esriGlobeCameraOrientationLocal
        End If
        
        ' Assign the properties of the 3D Bookmark we just visited to the Keyframe
        
        pKeyframe.CaptureProperties pScene, pGlobeCamera
        
        ' Assign the Keyframe a Name
        
        pKeyframe.Name = "Bookmark " & i
        
        pAnimTrack.InsertKeyframe pKeyframe, i ' Insert the New Keyframe in the Animation Track
        
    Next i
    
    ' Set the animation track name:
    
    pAnimTrack.Name = "Camera Animation"
    
    ' Set binding properties of the Animation Track - Attach the Animation Track to the
    ' GlobeCamera of the Main Viewer
    
    pAnimTrack.AttachObject pGlobeCamera
    
    pAnimTrack.ApplyToAllViewers = True
    
    ' Add the new Animation Track to the Animation Manager
    
    Dim pAnimTracks As IAnimationTracks
    Set pAnimTracks = pScene
    pAnimTracks.AddTrack pAnimTrack
    
    ' Restore the Original location of the before we recorded the Bookmarks
    
    pBookmarkLocation.Apply pGlobeDisp.ActiveViewer, False, 0
    
    pGlobeDisp.RefreshViewers ' Re-Draws everything in the Main Viewer
    
End Sub