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

[codesyntax lang=”python”]

#******************************************************
# Save Camera Data to a CSV file
#
# – savecameradata.py
# – By Mark Caldwell
# – Version 0.4
# – 18th October 2020
# – Copyright Mark Caldwell 2006
# – Tested with Vue R5 (2020)
#
# How to use in 4 easy steps
#
# 1. Download this file onto your computer
#
# 2. Change Path to Saved File
#
# 3. Then run script and wait for it to work
# To run it go to Python -> Run Python Script
# Then locate the file on your computer
#
# 4. Camera path and rotation are now stored in the CSV
# File and can be loaded using loadcameradata.csv
#
#******************************************************

#——————————————————————
# Filename to Save Data To – Change as required for your computer
#——————————————————————

#filename=”C:/Users/foo/Documents/e-on software/camera.csv”

#———————————————-
# Internal Variables Set Up: Don’t alter these
#———————————————-

end=0
frames=[]
currentframe=0
oldframe=currentframe+1
SetCurrentFrame (0)

#———————————————-
# Find the camera
#———————————————-

SelectByType(VuePython.VOT_Camera)
camobj = GetSelectedObjectByIndex(0)
cam=camobj.ToCamera()

#———————————————-
# Find the first key frame if it comes before
# frame 0
#———————————————-

SetCurrentFrame(currentframe)

while end==0:
PreviousKeyFrame ()
currentframe=CurrentFrame ()
if currentframe<oldframe:
oldframe=currentframe
else:
end=1

#———————————————-
# Step through key frames and read camera info
#———————————————-

end=0
oldframe=currentframe-2
SetCurrentFrame(currentframe-1)
framecount=0

while end==0:
NextKeyFrame ()
currentframe=CurrentFrame ()

if currentframe>oldframe:
oldframe=currentframe
pos=camobj.Position()
rot=camobj.GetRotationAngles()
dof=cam.DepthOfField()
exp=cam.Exposure ()
foc=cam.Focal ()
focdis=cam.FocusDistance ()
abr=cam.LensAberration ()
hor=cam.HorizontalFilmShift()
ver=cam.VerticalFilmShift ()
frames.append([currentframe,pos[0],pos[1],pos[2],rot[0],rot[1],rot[2],dof,exp,foc,focdis,abr,hor,ver])
framecount=framecount+1
else:
end=1

#———————————————-
# Write out camera data to file
#———————————————-

output=open (filename,’w’)
for f in frames:
if framecount==1:
f[0]=0
line=str(f[0])+’,’+str(f[1])+’,’
for n in range (2,14):
line=line+str(float(f[n]))
if n<13:
line=line+’,’
else:
line=line+’\n’
output.write(line)
output.close()

Refresh ()

#———————————————-
# End of Script
#———————————————-

[/codesyntax]

Python Code – Load Camera Animation

[codesyntax lang=”python”]

#******************************************************
# Loads Camera Data from a CSV file
#
# – loadcameradata.py
# – By Mark Caldwell
# – Version 0.4
# – 18th October 2020
# – Copyright Mark Caldwell 2006
# – Tested with Vue R5 (2020
#
# How to use in 3 easy steps
#
# 1. Download this file onto your computer
#
# 2. Change Path to Saved File if required and camera to be edited
#
# 3. Then run script and wait for it to work
# To run it go to Python -> Run Python Script
# Then locate the file on your computer
#
#******************************************************

#——————————————————————-
# Change yo the same as savecameradata.py
#——————————————————————-

#Filename to Load Data From – Change if different on your computer
filename=”C:/Users/foo/Documents/e-on software/camera.csv”

#———————————————-
# End of Changeable Parts
#———————————————-

frames=[]

#———————————————-
# Select or create the Camera
#———————————————-

cam=StoreCamera ()
SelectByType(VuePython.VOT_Camera)
camobj = GetSelectedObjectByIndex(0)
cam=camobj.ToCamera()

#———————————————-
# Read Camera Data in from CSV file
#———————————————-

file=open(filename,’r’)

while 1:
line = file.readline()
if not(line):
break

b=line.split(‘,’)
frames.append([float(b[0]),float(b[1]),float(b[2]),float(b[3]),float(b[4]),float(b[5]),float(b[6]),
float(b[7]),float(b[8]),float(b[9]),float(b[10]),float(b[11]),float(b[12]),float(b[13])])

file.close()

#———————————————-
# Apply animation
#———————————————-

for data in frames:
SetCurrentFrame (data[0])
camobj.SetPosition(data[1],data[2],data[3])
camobj.SetRotationAngles(data[4],data[5],data[6],True)
cam.SetDepthOfField(data[7])
cam.SetExposure (data[8])
cam.SetFocal (data[9])
cam.SetFocusDistance (data[10])
cam.SetLensAberration (data[11])
cam.SetHorizontalFilmShift(data[12])
cam.SetVerticalFilmShift (data[13])

Refresh ()

#———————————————-
# End of Script
#———————————————-

[/codesyntax]

impworks © Copyright Mark Caldwell 1996 - 2024