Camera Transition Animation

A guide for adding animated camera transitions to your configuration setup

Camera Animation Example

Overview

This guide will walk you through the steps involved in adding smooth camera transitions between camera positions.

The Threekit platform does not currently offer an animation toolset through the UI to achieve this effect. Instead, the approach we need to take is to leverage the power of the Player API to build our own camera animation setup.

This guide provides you with a ready-to-use script that can be added to your scene asset, and a set of instructions for how to control the animation.

Configuration Setup

Step by Step Setup
1

Camera Attribute Setup

The script expects a camera name attribute of type String, on the scene asset where the script is added. This attribute should store the name of the target camera where you want to animate.

If your camera angle attribute is of type Asset/Part Reference, storing Items as options, then you will need to create a separate string attribute that stores the name of the camera nodes from the scene. These string names could be stored as metadata on the items representing each camera option. You would then have to create an additional rule to read that metadata from the camera item and set its value to the camera string attribute.

You will then need to set the constant named cameraAttributeName in the script to hold the name of your string camera name attribute, as shown below.

Ensure that your scene contains a set of cameras corresponding to each of the options on this string attribute, and that their names correspond with the string values.

For example, for a CamAngle attribute with options of "Main", "Front", and "Back" you will need to create a set of three cameras in the scene named "Main", "Front", and "Back".

2

Camera Setup

The camera settings are important, as the script is currently designed to animate only between position and rotations of the cameras. Other parameters like lens focal length, control mode, or constraints won't get considered.

The player camera will be set to the same settings as the scene camera corresponding to the default camera option. Ensure that all your cameras are essentially the same as far as focal length, control mode and constraints as the default starting camera, so that there is no confusion.

3

Camera Orbit Target Node

Another important element in the animation is the focal point of the camera. When transitioning from one camera angle to another we generally want to ensure that we keep the camera facing at the product. This can be done with the aid of a Null node in the scene, which we can use as our orbit target.

Position the Null node where you want the camera to focus during the transition, and then edit the script to provide the name of the null node to the orbitTargetNodeName constant listed at the top of the script.

4

Animation Time Attribute

The third important element in the animation is the duration. This determines how fast the transition takes place from one camera angle to another.

The script provides control for this through the use of an attribute on the asset where you have the script added. It expects that you create a number attribute with the name CamAnimationTime, and that you give it a value that represents the number of seconds. This can be a floating point value as well, such as 1.25, which would represent a duration of one and a quarter seconds (a total of 1250 milliseconds).

If you wish to use a different name for your attribute, then you can edit the script at the top, to set your own custom attribute name on the cameraAnimationTime constant.

5

Debugging

For issues with the above steps, and other animation issues, the script offers the option to display helpful messages in the browser console, that may help you debug the issues.

By default the script below has set the debug feature to OFF. To enable it, change the logDebug constant to true at the top of the script.

6

Player Camera

You can leave the scene player camera empty, as the script will automatically make a copy at runtime of the camera corresponding to the default value for your cameraAttributeNameattribute, and set it as the active camera upon player initialization.

Script Setup

Once the required steps listed above have been completed, the script below will need to be added to the scene asset.

The script needs to be copied and pasted in a custom code action, inside a rule on your scene asset.

Once you have pasted it, and every time you make a change, you need to save the changes using the little Disk icon below the script window, in addition to saving the changes to your asset.

Limitations

  • The animation curve cannot be controlled without editing the script, but this requires some understanding of the math involved in the easing function. This can be done by editing the following line of code:

  • Only the position and rotation of the cameras will be used during the animation transition. This means that if you have different cameras with different focal lengths, different orbit modes, or different constraints, this information will not currently get applied.

    • For constraints, you can use the relative mode instead of world mode for Longitude constraints in particular, which would be more general regardless of the camera orientation, but feel free to experiement with different settings to see what works best.

Last updated

Was this helpful?