Class KeyframesManager

java.lang.Object
gaiasky.util.camera.rec.KeyframesManager
All Implemented Interfaces:
IObserver

public class KeyframesManager extends Object implements IObserver
Manages the camera keyframes in Gaia Sky, providing functionality for creating, loading, saving, and exporting camera paths. This class acts as a central hub for camera recording and playback operations, coordinating between the user interface, the camera system, and external processing scripts.

Key responsibilities include:

  • Keyframe Management: Maintaining a synchronized list of Keyframe objects that define camera position, orientation, and timing.
  • Persistence: Loading from and saving to .gkf (Gaia Sky Keyframes) files.
  • Path Generation: Converting keyframes into smooth camera paths using different interpolation methods such as Linear, Catmull-Rom Spline, or B-Spline.
  • Playback Control: Managing the Camcorder.RecorderState (IDLE, PLAYING, STEPPING) and advancing the camera along the path frame by frame.
  • External Integration: Providing an interface to run the OptFlowCam Python script for advanced camera path optimization and conversion.
  • Event Handling: Implementing IObserver to respond to system-wide events like saving, exporting, or frame updates.

This class follows the Singleton pattern, accessible via the instance field.

  • Field Details

  • Constructor Details

    • KeyframesManager

      public KeyframesManager()
  • Method Details

    • initialize

      public static void initialize()
    • regenerateCameraPath

      public void regenerateCameraPath()
      Re-generates the camera path object from the current keyframes list.
    • clean

      public void clean()
      Cleans the current configuration of keyframes.
    • getFrameNumber

      public long getFrameNumber(Keyframe kf)
      Gets the frame number of the given keyframe using the current target frame rate setting.
      Parameters:
      kf - The keyframe.
      Returns:
      The frame number corresponding to exactly this keyframe if the keyframe is valid and in the keyframes list, otherwise -1. The frame number is in [0,n-1].
    • loadKeyframesFile

      public List<Keyframe> loadKeyframesFile(Path file) throws RuntimeException
      Throws:
      RuntimeException
    • saveKeyframesFile

      public void saveKeyframesFile(List<Keyframe> keyframes, String fileName, boolean overwrite, boolean notification)
    • samplePaths

      public double[] samplePaths(com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<Vector3D>> pointsSep, double[] points, int samplesPerSegment, KeyframesManager.PathType pathType)
    • exportKeyframesFile

      public void exportKeyframesFile(List<Keyframe> keyframes, String fileName, boolean overwrite)
    • play

      public void play()
      Sets the manager in play mode.
    • isPlaying

      public boolean isPlaying()
    • pause

      public void pause()
      Sets the manager in pause mode.
    • isIdle

      public boolean isIdle()
    • stepping

      public void stepping()
      Sets the manager in stepping mode.
    • isStepping

      public boolean isStepping()
    • skip

      public void skip(long frame)
      Skips to the given frame.
      Parameters:
      frame - The frame number.
    • checkKeyframeTimings

      public boolean checkKeyframeTimings()
      Checks that all keyframe timings fall perfectly on a frame, so that t(kf) * FPS % 1 = 0 holds.
      Returns:
      True if the keyframe timings are consistent with the camcorder FPS setting.
    • runOptFlowCamScript

      public void runOptFlowCamScript(Path scriptLocation, Path outputFile, boolean overwrite)
      Runs the OptFlowCam script at the given location with the current keyframes, with the given output file. This version checks for Python/Pipenv, installs dependencies, and then runs the script.
      Parameters:
      scriptLocation - The location of the OptFlowCam script. This location must contain a optflowcam_convert.py file.
      outputFile - Path to the output camera path (.gsc) file.
      overwrite - Whether to overwrite the output file if it exists. If false, a new file name will be created from the provided one.
    • notify

      public void notify(Event event, Object source, Object... data)
      Description copied from interface: IObserver
      Event notification call.
      Specified by:
      notify in interface IObserver
      Parameters:
      event - The event type.
      source - The source object, if any.
      data - The data associated with this event.