Versions Compared

Key

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

...

The script is for Y-based axis setups. If you have a Z-based axis setup go to → "Animation Keys (Z-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()
	zCoord = math.sin(radians) * radius + objectPosition.getZ()
 
	positionCache.append(Vector.new(xCoord, verticalPosition, zCoord))
 
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

...