Constraints#

Constraint definitions and utilities.

Constraint sets for conditioning motion generation (root 2D, full body, end-effectors).

kimodo.constraints.create_pairs(tensor_A, tensor_B)[source]#

Form all (a, b) pairs from two 1D tensors; output shape (len(A)*len(B), 2).

kimodo.constraints.compute_global_heading(global_joints_positions, skeleton)[source]#

Compute global root heading (cos, sin) from global joint positions using skeleton.

class kimodo.constraints.Root2DConstraintSet(
skeleton,
frame_indices,
smooth_root_2d,
to_crop=False,
global_root_heading=None,
)[source]#

Bases: object

Constraint set fixing root (x, z) trajectory and optionally global heading on given frames.

name = 'root2d'#
__init__(
skeleton,
frame_indices,
smooth_root_2d,
to_crop=False,
global_root_heading=None,
)[source]#
update_constraints(data_dict, index_dict)[source]#

Append this constraint’s smooth_root_2d (and optional global_root_heading) to data/index dicts.

crop_move(start, end)[source]#

Return a new constraint set for the cropped frame range [start, end).

get_save_info()[source]#

Return a dict suitable for JSON serialization (frame_indices, smooth_root_2d, optional global_root_heading).

to(device=None, dtype=None)[source]#
classmethod from_dict(skeleton, dico)[source]#

Build a Root2DConstraintSet from a dict (e.g. loaded from JSON).

class kimodo.constraints.FullBodyConstraintSet(
skeleton,
frame_indices,
global_joints_positions,
global_joints_rots,
smooth_root_2d=None,
to_crop=False,
)[source]#

Bases: object

Constraint set fixing full-body global positions and rotations on given keyframes.

name = 'fullbody'#
__init__(
skeleton,
frame_indices,
global_joints_positions,
global_joints_rots,
smooth_root_2d=None,
to_crop=False,
)[source]#
update_constraints(data_dict, index_dict)[source]#

Append global positions, smooth root 2D, root y, and global heading to data/index dicts.

crop_move(start, end)[source]#

Return a new FullBodyConstraintSet for the cropped frame range [start, end).

get_save_info()[source]#

Return a dict for JSON save: type, frame_indices, local_joints_rot, root_positions, smooth_root_2d.

to(device=None, dtype=None)[source]#
classmethod from_dict(skeleton, dico)[source]#

Build a FullBodyConstraintSet from a dict (e.g. loaded from JSON).

class kimodo.constraints.EndEffectorConstraintSet(
skeleton,
frame_indices,
global_joints_positions,
global_joints_rots,
smooth_root_2d,
*,
joint_names,
to_crop=False,
)[source]#

Bases: object

Constraint set fixing selected end-effector positions and rotations on given frames.

name = 'end-effector'#
__init__(
skeleton,
frame_indices,
global_joints_positions,
global_joints_rots,
smooth_root_2d,
*,
joint_names,
to_crop=False,
)[source]#
update_constraints(data_dict, index_dict)[source]#

Append constrained joint positions/rots, smooth root 2D, root y, and heading to data/index dicts.

crop_move(start, end)[source]#

Return a new EndEffectorConstraintSet for the cropped frame range [start, end).

get_save_info()[source]#

Return a dict for JSON save: type, frame_indices, local_joints_rot, root_positions, smooth_root_2d, joint_names.

to(device=None, dtype=None)[source]#
classmethod from_dict(skeleton, dico)[source]#

Build an EndEffectorConstraintSet from a dict (e.g. loaded from JSON).

class kimodo.constraints.LeftHandConstraintSet(*args, **kwargs)[source]#

Bases: EndEffectorConstraintSet

End-effector constraint for the left hand only.

name = 'left-hand'#
joint_names = ['LeftHand']#
__init__(*args, **kwargs)[source]#
class kimodo.constraints.RightHandConstraintSet(*args, **kwargs)[source]#

Bases: EndEffectorConstraintSet

End-effector constraint for the right hand only.

name = 'right-hand'#
joint_names = ['RightHand']#
__init__(*args, **kwargs)[source]#
class kimodo.constraints.LeftFootConstraintSet(*args, **kwargs)[source]#

Bases: EndEffectorConstraintSet

End-effector constraint for the left foot only.

name = 'left-foot'#
joint_names = ['LeftFoot']#
__init__(*args, **kwargs)[source]#
class kimodo.constraints.RightFootConstraintSet(*args, **kwargs)[source]#

Bases: EndEffectorConstraintSet

End-effector constraint for the right foot only.

name = 'right-foot'#
joint_names = ['RightFoot']#
__init__(*args, **kwargs)[source]#
kimodo.constraints.load_constraints_lst(path_or_data, skeleton, device=None, dtype=None)[source]#

Load a list of constraints from JSON path or list of dicts.

Parameters:
  • path_or_data – Path to constraints.json or list of constraint dicts.

  • skeleton – Skeleton instance (used for from_dict).

  • device – If set, move all constraint tensors and skeleton to this device.

  • dtype – If set, cast constraint tensors to this dtype.

kimodo.constraints.save_constraints_lst(path, constraints_lst)[source]#

Save a list of constraint sets to a JSON file.

Returns None if list is empty.