Versions Compared

Key

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

...

The script is for Z-based axis setups. If you have a Y-based axis setup go to → "Camera Operations (Y-Setup)"

Code Block
languagepy
# Load Python's math module
import math

# Get the camera "SceneCamera01" and a focus object "Cube01"
# Initialize standard values
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

# Make the camera look at the "focusObject" node's position

if (frame == scene.getMinFrame()):
	camera.setParameter("LookAt", objectPosition)

# Clockwise or counter-clockwise?
if (orientation == 0): sign = 1
else                 : sign = -1

# Get the simulation range
simRange    = float(scene.getMaxFrames() - scene.getMinFrame()) - 1.0
 
# Calculate how many degrees the camera covers within a single frame
# Convert the result from degrees to radians
degPerFrame = (360.0 / simRange) * cycles
radians     = (sign * degPerFrame * math.pi / 180.0) * frame

# Calculate the XY coordinates based on the available values
xCoord         = math.cos(radians) * radius + objectPosition.x
yCoord         = math.sin(radians) * radius + objectPosition.y
cameraPosition = Vector.new(xCoord, yCoord, verticalPosition)
 
# Assemble a position vector and apply it to the camera to make it move
camera.setParameter("Position", cameraPosition)