# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Show the usage of CameraSwitcher
#
# Topic:FBCameraSwitcher, FBCamera, FBTime, FBRenderer, FBVector3d, FBPlayerControl, FBSystem 
#

from pyfbsdk import FBTime, FBModel, FBModelCube, FBCamera, FBCameraSwitcher, FBRenderer, FBScene, FBSystem, FBVector3d, FBPlayerControl

# Create a Model for camera's LookAt
lModel1 = FBModelCube("My Cube")
lModel1.Scaling = FBVector3d(20, 20, 20)    #enlarge 
lModel1.Show = True
lModel1.Visible = True

# Once created, the camera needs to be made visible
lCamera1 = FBCamera("Camera 1")
lCamera1.Show = True
lCamera1.SetVector( FBVector3d( 300, 100, 000 ) )
lCamera1.LookAt = lModel1

lCamera2 = FBCamera("Camera 2")
lCamera2.Show = True
lCamera2.SetVector( FBVector3d( 0, 100, 300 ) )
lCamera2.LookAt = lModel1

lCamera3 = FBCamera("Camera 3")
lCamera3.Show = True
lCamera3.SetVector( FBVector3d( -300, 100, 0 ) )
lCamera3.LookAt = lModel1

lCamera4 = FBCamera("Camera 4")
lCamera4.Show = True
lCamera4.SetVector( FBVector3d( 0, 200, -500 ) )
lCamera4.LookAt = lModel1

# Turn on CameraSwitcher for the main model view.
FBSystem().Scene.Renderer.UseCameraSwitcher = True

# Get the system camera switcher instance.
lCameraSwitcher = FBCameraSwitcher()

# Get Current Camera
lCurCamera = lCameraSwitcher.CurrentCamera
print lCurCamera.Name

# Set Current Camera & turn on manual switch mode
lCameraSwitcher.CurrentCamera = lCamera2

# Get Current Camera Index
lCurCameraIndex = lCameraSwitcher.CurrentCameraIndex
print lCurCameraIndex

# Set Current Camera Index
lCameraSwitcher.CurrentCameraIndex = 3

# Get CameraIndex property's AnimationNode 
lCameraIndexProp = lCameraSwitcher.PropertyList.Find("Camera Index")
lCameraIndexPropAnimationNode = lCameraIndexProp.GetAnimationNode()

# Work with FCurve directly
lCameraIndexPropAnimationNode.KeyAdd(FBTime(0,0,0), 1)
lCameraIndexPropAnimationNode.KeyAdd(FBTime(0,0,1), 2)
lCameraIndexPropAnimationNode.KeyAdd(FBTime(0,0,2), 3)
lCameraIndexPropAnimationNode.KeyAdd(FBTime(0,0,3), 4)

# Use FCurve evaluate mode instead of manual mode for camera switching
lCameraSwitcher.UseEvaluateSwitch()

# Playback
lPlayer = FBPlayerControl()
lPlayer.GotoStart()
lPlayer.Play()

# Cleanup
#del( FBTime, FBModel, FBModelCube, FBCamera, FBCameraSwitcher, FBRenderer, FBScene, FBSystem, FBVector3d, FBPlayerControl )