Timeline Example ====================== This example depicts how to create animations and integrate into a newly created timeline. To use this script, open a new database, create a plane and a cube, then execute the script : the script will create automatically kinematics parent for the cube so that it can be animated. .. literalinclude:: TimelineExample.py :linenos: :download:`Download example ` .. only:: html .. image:: TimelineExample.gif :width: 1200 :alt: Executing script and playing the created timeline .. image:: timelineUI.png :width: 1200 :alt: Created timeline .. rubric:: ChannelsCurveAnimation A :python:`"ChannelsCurveAnimation"` is created to animate the translation of the newly created kinematic object :python:`"Null"`. First, the animation is created using :py:meth:`create_channels_curve_animation() ` and the total duration of the animation is set to 3 seconds using the :py:attr:`duration ` attribute. Then, the channels to animate the translation along the X axis is added to the previously created animation using :py:meth:`add_null_channel_animation() ` with the channel set as 'Translation/X'. Then the translated X position is defined for each keyframe using :py:meth:`insert_key_frame() `. Finally, the translation along the Y axis is created and defined similarly using :py:meth:`add_null_channel_animation() ` with the channel set as 'Translation/Y' and the translated Y position for each keyframe. In this example, the null will translate in the following way : (X=0.3, Y=0.3) → (X=0.3, Y=-0.3) → (X=0.0, Y=0.0). .. rubric:: ChannelsSimpleAnimation A :python:`"ChannelsSimpleAnimation"` is created to animate the rotation of the newly created kinematic object :python:`"Axis"`. First, the animation is created using :py:meth:`create_channels_simple_animation() `. Then, the animation channel setting the start/end angle and duration for axis rotation is added to the previously created animation using :py:meth:`set_axis_channel_animation() `. In this example, the axis will rotate from 0° to 360° during 2 seconds. .. rubric:: CameraBezierPathAnimation A :python:`"CameraBezierPathAnimation"` is created to animate the :python:`"Camera"` position and target. First, the animation is created using :py:meth:`create_camera_bezier_path_animation() ` and the total duration of the animation is set to 3 seconds using the :py:attr:`duration ` attribute. Then, in order to make the camera's position move along a :python:`"BezierPath"`, the :py:attr:`position_type ` attribute is set to :python:`"CameraBezierPathAnimationPositionType.FOLLOW_BEZIER_PATH"`, the py:attr:`bezier_path_used_for_position ` attribute is set to the desired :python:`"BezierPath"` and the the py:attr:`position_bezier_path_inverted ` attribute is set to True to make the camera move the inverted curve. Finally, to set the camera's target to the :python:`"Null"` object, he :py:attr:`target_type ` attribute is set to :python:`"CameraBezierPathAnimationTargetType.FOLLOW_NULL"`, the py:attr:`target_null ` attribute is set to the desired :python:`"Null"`. .. rubric:: CameraBookmarkAnimation A :python:`"CameraBookmarkAnimation"` is created to animate the :python:`"Camera"` position. First, the animation is created using :py:meth:`create_camera_bookmark_animation() `, here the total duration of the animation is set implicitely by computing the total sum of each :python:`"CameraBookmark"`'s duration. In this example, the list of :python:`"CameraBookmark"` is defined by creating a :python:`"CameraGroup"` containing as much as :python:`"Camera"` as the animation need bookmarks. Each camera's position will be used to define each bookmark's position. Then, by using :py:meth:`add_camera_from_camera_group_to_animation() ` with the previously created :python:`"CameraGroup"`, an animation containing as many bookmarks as the cameras in the group is created. Finally, a for loop is used to define each bookmarj's duration, thus defining the total duration of the whole animation. .. rubric:: Insert to timeline To insert the created animation into the timeline, the corresponding :python:`"TimelineTrack"` needs to be found : :python:`"ChannelsCurveAnimation"` and :python:`"ChannelsSimpleAnimation"` will be inserted in :py:meth:`empty_channels_track() `, :python:`"CameraBezierPathAnimation"` and :python:`"CameraBookmarkAnimation"` will be inserted in :py:meth:`camera_animation_track() `, :python:`"ConfigurationKeyAnimation"` will be inserted in :py:meth:`configurationAnimationTrack() `, :python:`"TextureAnimation"` will be inserted in :py:meth:`textureAnimationTracks() `, :python:`"ProductKeyAnimation"` will be inserted in :py:meth:`list_product_key_animations() `. Then the animation is inserted to the :python:`"TimelineTrack"` as a clip by using :py:meth:`insert_animation() ` with the starting time in milliseconds. In the example a :python:`"Product"` is inserted in py:meth:`product_animation_track() ` to show how it can be done simply : the animation does not need to be created as :py:meth:`list_product_key_animations() ` contains every existing product. .. rubric:: Clean empty Timelines At the end of the script, timelines are looped through to check for empty tracks : is a timeline does not have a track with animation inserted, it is deleted.