impworks Logo - a grinning imp in flight

Camera Save and Load as CSV Files

  • Save and Load Camera Animation
  • Version: 0.4
  • October 18, 2020
  • 3.2 KB
  • savecamera.zip

Two python scripts for Vue for loading and saving camera information to and from CSV files (comma separated values). savecameradata.py saves camera position, focus and other data into a CSV file. loadcameradata.py loads a CSV file into Vue and applies it to the camera. The two scripts are useful for moving camera animations between scenes.

It also allows a stationary camera to be moved between scenes.

Python Code – Save Camera Animation

  1. #******************************************************
  2. # Save Camera Data to a CSV file
  3. #
  4. # - savecameradata.py
  5. # - By Mark Caldwell
  6. # - Version 0.4
  7. # - 18th October 2020
  8. # - Copyright Mark Caldwell 2006
  9. # - Tested with Vue R5 (2020)
  10. #
  11. # How to use in 4 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Change Path to Saved File
  16. #
  17. # 3. Then run script and wait for it to work
  18. # To run it go to Python -> Run Python Script
  19. # Then locate the file on your computer
  20. #
  21. # 4. Camera path and rotation are now stored in the CSV
  22. # File and can be loaded using loadcameradata.csv
  23. #
  24. #******************************************************
  25. #------------------------------------------------------------------
  26. # Filename to Save Data To - Change as required for your computer
  27. #------------------------------------------------------------------
  28. #filename="C:/Users/foo/Documents/e-on software/camera.csv"
  29. #----------------------------------------------
  30. # Internal Variables Set Up: Don't alter these
  31. #----------------------------------------------
  32. end=0
  33. frames=[]
  34. currentframe=0
  35. oldframe=currentframe+1
  36. SetCurrentFrame (0)
  37. #----------------------------------------------
  38. # Find the camera
  39. #----------------------------------------------
  40. SelectByType(VuePython.VOT_Camera)
  41. camobj = GetSelectedObjectByIndex(0)
  42. cam=camobj.ToCamera()
  43. #----------------------------------------------
  44. # Find the first key frame if it comes before
  45. # frame 0
  46. #----------------------------------------------
  47. SetCurrentFrame(currentframe)
  48. while end==0:
  49. PreviousKeyFrame ()
  50. currentframe=CurrentFrame ()
  51. if currentframe<oldframe:
  52. oldframe=currentframe
  53. else:
  54. end=1
  55. #----------------------------------------------
  56. # Step through key frames and read camera info
  57. #----------------------------------------------
  58. end=0
  59. oldframe=currentframe-2
  60. SetCurrentFrame(currentframe-1)
  61. framecount=0
  62. while end==0:
  63. NextKeyFrame ()
  64. currentframe=CurrentFrame ()
  65. if currentframe>oldframe:
  66. oldframe=currentframe
  67. pos=camobj.Position()
  68. rot=camobj.GetRotationAngles()
  69. dof=cam.DepthOfField()
  70. exp=cam.Exposure ()
  71. foc=cam.Focal ()
  72. focdis=cam.FocusDistance ()
  73. abr=cam.LensAberration ()
  74. hor=cam.HorizontalFilmShift()
  75. ver=cam.VerticalFilmShift ()
  76. frames.append([currentframe,pos[0],pos[1],pos[2],rot[0],rot[1],rot[2],dof,exp,foc,focdis,abr,hor,ver])
  77. framecount=framecount+1
  78. else:
  79. end=1
  80. #----------------------------------------------
  81. # Write out camera data to file
  82. #----------------------------------------------
  83. output=open (filename,'w')
  84. for f in frames:
  85. if framecount==1:
  86. f[0]=0
  87. line=str(f[0])+','+str(f[1])+','
  88. for n in range (2,14):
  89. line=line+str(float(f[n]))
  90. if n<13:
  91. line=line+','
  92. else:
  93. line=line+'\n'
  94. output.write(line)
  95. output.close()
  96. Refresh ()
  97. #----------------------------------------------
  98. # End of Script
  99. #----------------------------------------------

Python Code – Load Camera Animation

  1. #******************************************************
  2. # Loads Camera Data from a CSV file
  3. #
  4. # - loadcameradata.py
  5. # - By Mark Caldwell
  6. # - Version 0.4
  7. # - 18th October 2020
  8. # - Copyright Mark Caldwell 2006
  9. # - Tested with Vue R5 (2020
  10. #
  11. # How to use in 3 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Change Path to Saved File if required and camera to be edited
  16. #
  17. # 3. Then run script and wait for it to work
  18. # To run it go to Python -> Run Python Script
  19. # Then locate the file on your computer
  20. #
  21. #******************************************************
  22. #-------------------------------------------------------------------
  23. # Change yo the same as savecameradata.py
  24. #-------------------------------------------------------------------
  25. #Filename to Load Data From - Change if different on your computer
  26. filename="C:/Users/foo/Documents/e-on software/camera.csv"
  27. #----------------------------------------------
  28. # End of Changeable Parts
  29. #----------------------------------------------
  30. frames=[]
  31. #----------------------------------------------
  32. # Select or create the Camera
  33. #----------------------------------------------
  34. cam=StoreCamera ()
  35. SelectByType(VuePython.VOT_Camera)
  36. camobj = GetSelectedObjectByIndex(0)
  37. cam=camobj.ToCamera()
  38. #----------------------------------------------
  39. # Read Camera Data in from CSV file
  40. #----------------------------------------------
  41. file=open(filename,'r')
  42. while 1:
  43. line = file.readline()
  44. if not(line):
  45. break
  46. b=line.split(',')
  47. frames.append([float(b[0]),float(b[1]),float(b[2]),float(b[3]),float(b[4]),float(b[5]),float(b[6]),
  48. float(b[7]),float(b[8]),float(b[9]),float(b[10]),float(b[11]),float(b[12]),float(b[13])])
  49. file.close()
  50. #----------------------------------------------
  51. # Apply animation
  52. #----------------------------------------------
  53. for data in frames:
  54. SetCurrentFrame (data[0])
  55. camobj.SetPosition(data[1],data[2],data[3])
  56. camobj.SetRotationAngles(data[4],data[5],data[6],True)
  57. cam.SetDepthOfField(data[7])
  58. cam.SetExposure (data[8])
  59. cam.SetFocal (data[9])
  60. cam.SetFocusDistance (data[10])
  61. cam.SetLensAberration (data[11])
  62. cam.SetHorizontalFilmShift(data[12])
  63. cam.SetVerticalFilmShift (data[13])
  64. Refresh ()
  65. #----------------------------------------------
  66. # End of Script
  67. #----------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2021