Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The script is an extension of  "Camera Operations (Y-Setup)" and works as a batch script instead of a simulation script. The camera positions are cached, translated into animation keys, and added to the  "Curve Editor". The script is for Z-based axis setups. If you have a Z-based axis setup go to → "Animation Keys (Y-Setup)".

 

Code Block
languagepy
import math
 
camera           = scene.getCamera("SceneCamera01")
focusObject      = scene.getObject("Cube01")
objectPosition   = focusObject.getParameter("Position")
frame            = scene.getCurrentFrame()
radius           = 1.5
cycles           = 3.0
verticalPosition = 0.5
orientation      = 0
positionCache    = []
indexCounter     = 0
 
curvePosX = camera.getParameterCurve("Position.X")
curvePosY = camera.getParameterCurve("Position.Y")
curvePosZ = camera.getParameterCurve("Position.Z")
 
camera.setParameter("LookAt", objectPosition)
 
if (orientation == 0): sign = 1
else : sign = -1
 
simRange    = scene.getMaxFrames() - scene.getMinFrame()
degPerFrame = (360.0 / simRange) * cycles
 
for i in range(0, simRange -+ 1):
	radians = (sign * degPerFrame * math.pi / 180.0) * float(i)
	xCoord = math.cos(radians) * radius + objectPosition.getX()
	yCoord = math.sin(radians) * radius + objectPosition.getY()
 
	positionCache.append(Vector.new(xCoord, yCoord, verticalPosition))
 
for entry in positionCache:
	currentTime = float(indexCounter) / scene.getFps()
 
	keyX = Key.new()
	keyY = Key.new()
	keyZ = Key.new()
 
	keyX.time = currentTime
	keyX.value = entry.x
	keyX.type = KEY_TYPE_TCB
 
	curvePosX.addKey(keyX)

	keyY.time = currentTime
	keyY.value = entry.y
	keyY.type = KEY_TYPE_TCB
 
	curvePosY.addKey(keyY)
	keyZ.time = currentTime
	keyZ.value = entry.z
	keyZ.type = KEY_TYPE_TCB
 
	curvePosZ.addKey(keyZ)
 
	indexCounter += 1

...