Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Add this script to a "Batch Script" editor (F10) and execute it with Script > Run.

The script is an extension of  "Camera Operations" 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 Y-based axis setups. If you have a Z-based axis setup go to → "Animation Keys (Z-Setup)".

 

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

 


  • No labels