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 the script to Simulation Flow (Ctrl/Cmd + F2) > FramesPre.

The script makes a camera ("Camera01") spinning around a cube object ("Cube01"). During the motion the camera will look at the cube. 

It is possible to specify the distance between camera and object, and the number of revolutions around the object during the simulation. With "orientation" the camera's rotation can be clockwise or counter-clockwise.

The script is for Y-based axis setups. If you have a Z-based axis setup go to "Camera Operations (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

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

if (orientation == 0): sign = 1
else                 : sign = -1

simRange    = float(scene.getMaxFrames() - scene.getMinFrame()) - 1.0
degPerFrame = (360.0 / simRange) * cycles
radians     = (sign * degPerFrame * math.pi / 180.0) * frame

xCoord         = math.cos(radians) * radius + objectPosition.x
zCoord         = math.sin(radians) * radius + objectPosition.z
cameraPosition = Vector.new(xCoord, verticalPosition, zCoord)
 
camera.setParameter("Position", cameraPosition)
  • No labels