Tip:
Highlight text to annotate it
X
In this movie, we'll show how to use Python in MotionBuilder to constrain a camera's aim from one object to another.
Start by selecting 'Window > Python Editor'.
To create a cube, we'll use the FBCreateObject() function.
The first argument is the Asset Browser path to the Primitives section.
This path begins with 'Browsing', and is followed by 'Templates', 'Elements', and 'Primitives'.
The second argument is the Asset Browser name of the object we want to create. We'll want to create a cube.
In the case of primitives, the third argument has to be the same as the second argument.
For other object types however, this can be an arbitrary name.
If we look in the Scene Browser, our cube is nested under the scene's root node, but it isn't visible in the viewport.
Set its Show property to True to make it visible.
To translate the cube up by 50 units, set its Translation property to FBVector3d( 0, 50, 0 ).
Rotate the cube around the Z-axis by 15 degrees by setting its Rotation property to ( 0, 0, 15 )
Scale the cube by 3 units along each axis by setting its Scaling property to ( 3, 3, 3 )
Now that we have a basic idea of how to create primitives, and how to modify their properties, we can start working on our script
In the scripting tab, import the pyfbsdk module.
We'll want to test our script on a new scene every time.
To clear the scene, type FBApplication().FileNew()
Create a cube, in the same way we had created it in the interactive tab.
Set the cube's name to 'myCube'
Translate the cube 100 units along the positive x axis, and give it a y-value of 50 units.
Rotate the cube by 35 degrees in the Y and Z axes.
Remember to set the cube's Show property to True to see it in the viewport.
Save the script as constrainCamera.py.
Run the script by pressing the execute button.
Notice that the scene is cleared, and that the new cube is positioned and rotated according to the values set in the script.
Create a sphere primitive, again using FBCreateObject().
Instead of 'Cube', use 'Sphere' as the Asset Browser name.
Set its name to 'mySphere'
Position the sphere away from the cubeā¦
and make the sphere visible in the viewport.
To create a camera, there are two alternatives.
The first way would be to use the FBCreateObject() function, similarly to how we had created the cube and the sphere.
The other way is to use the FBCamera class.
Create the camera by calling camera = FBCamera( 'myCamera' ).
The 'myCamera' string is the custom name of the camera.
Move it 100 units along the y Axis.
Set its Rotation property to 0, 0, 0 to point it along the positive x axis.
Make the camera visible in the viewport via its Show property.
When we run the script, we now have a sphere, a camera, and a cube in our scene.
In the next part, we'll show how to use constraints to animate the camera's aim from the cube to the sphere.