Forums Technical subjects Patchwork 3D R&D and Roadmap Patchwork 3D 2022 release 2 – Scripting API improvements Reply To: Patchwork 3D 2022 release 2 – Scripting API improvements

Author Reply

Romaric BOUNY
Keymaster

2 – kinematics & animations

In Patchwork 3D release 2, the kinematics and timeline API have been added too.

With the kinematics API, it is possible to add Nulls, Vectors and Axis in the kinematics tree and associate surfaces to these kinematics elements.

Using the timeline API, it is possible to manage timelines, create and edit animations.

Example : this script combines cameras API, kinematics API and Timeline API to show how to create some kinds of animation : Camera bookmark animation, simple channel animation, advanced channel animation with curve control.

 

def create_bookmark_camera_anim(db: Database) -> CameraBookmarkAnimation :
    anim = db.create_camera_bookmark_animation('bk_anim')
    group: CameraGroup = db.create_camera_group('CameraGroup For Animation')
    camera_1 = db.create_camera(group)
    camera_1.name = 'BKCamera1'
    camera_1.view_to = Vector3(0.0, 0.0, 0.0)
    camera_1.view_from = Vector3(1.0, 1.0, 1.0)
    camera_2 = db.create_camera(group)
    camera_2.name = 'BKCamera2'
    camera_2.view_from = Vector3(2.0, 1.0, 1.0)
    anim.add_camera_from_camera_group_to_animation(group=group)
    return anim

def create_simple_channel_animation(db: Database) -> ChannelsSimpleAnimation:
    anim = db.create_channels_simple_animation('anim_axis')
    axis = db.list_models()[0].create_axis('animated_axis')
    surf = create_surface(db.list_models()[0], 'AxisAnimatedSurface')
    axis.add_surface(surf)
    anim.set_axis_channel_animation(object=axis, start=25, end=35)
    return anim

def create_curve_channel_animation(db: Database, null_obj: Null) -> ChannelsCurveAnimation:
    anim = db.create_channels_curve_animation('anim_vector_null')
    vector = db.list_models()[0].create_vector('animated_vector')
    anim.add_vector_channel_animation(object=vector)

    surf = create_surface(db.list_models()[0], 'NullAnimatedSurface')
    null_obj.add_surface(surf)
    anim.add_null_channel_animation(object=null_obj, channel='Translation/X')
    anim.add_null_channel_animation(object=null_obj, channel='Translation/Y')
    anim.add_null_channel_animation(object=null_obj, channel='Orientation/Z')
    return anim