object_animators.py
1 from DreamTalk.animation.abstract_animators import ProtoAnimator 2 import c4d 3 4 5 class SetVisibility(ProtoAnimator): 6 """animates the visibility of objects using a state animation""" 7 8 def __init__(self, *objs, visible=None, **kwargs): 9 self.set_values(visible) 10 return super().__init__(self, *objs, animation_type="state", **kwargs) 11 12 def specify_desc_ids(self): 13 self.desc_ids = { 14 "vis_editor": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_VISIBILITY_EDITOR, c4d.DTYPE_LONG, 0)), 15 "vis_render": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_VISIBILITY_RENDER, c4d.DTYPE_LONG, 0)) 16 } 17 18 def set_values(self, visible): 19 # translate to c4d values 20 if visible: 21 visibility = 0 22 else: 23 visibility = 1 24 # equate render and editor visibility 25 visibility_editor = visibility_render = visibility 26 self.values = [visibility_editor, visibility_render] 27 28 29 class Show(SetVisibility): 30 """enables the visibility of objects""" 31 32 def __init__(self, *objs, **kwargs): 33 return super().__init__(self, *objs, visible=True, **kwargs) 34 35 36 class Hide(SetVisibility): 37 """disables the visiblity of objects""" 38 39 def __init__(self, *objs, **kwargs): 40 return super().__init__(self, *objs, visible=False, **kwargs) 41 42 43 class Move(ProtoAnimator): 44 """animates the position of objects""" 45 46 def __init__(self, *objs, x=None, y=None, z=None, relative=True, **kwargs): 47 self.set_values(x, y, z) 48 return super().__init__(self, *objs, relative=relative, animation_type="vector", **kwargs) 49 50 def specify_desc_ids(self): 51 self.desc_ids = { 52 "pos_x": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), 53 c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0)), 54 "pos_y": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), 55 c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)), 56 "pos_z": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), 57 c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)) 58 } 59 60 def set_values(self, x, y, z): 61 self.values = [x, y, z] 62 63 64 class Rotate(ProtoAnimator): 65 """animates the rotation of objects""" 66 67 def __init__(self, *objs, h=None, p=None, b=None, relative=True, **kwargs): 68 self.set_values(h, p, b) 69 return super().__init__(self, *objs, relative=relative, animation_type="vector", **kwargs) 70 71 def specify_desc_ids(self): 72 self.desc_ids = { 73 "rot_h": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), 74 c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0)), 75 "rot_p": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), 76 c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)), 77 "rot_b": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), 78 c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)) 79 } 80 81 def set_values(self, h, p, b): 82 self.values = [h, p, b] 83 84 85 class Scale(ProtoAnimator): 86 """animates the scale of objects""" 87 88 def __init__(self, *objs, x=None, y=None, z=None, relative=True, multiplicative=True, **kwargs): 89 self.set_values(x, y, z) 90 return super().__init__(self, *objs, relative=relative, multiplicative=multiplicative, animation_type="vector", **kwargs) 91 92 def specify_desc_ids(self): 93 self.desc_ids = { 94 "scale_x": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0), 95 c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0)), 96 "scale_y": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0), 97 c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0)), 98 "scale_z": c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0), 99 c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)) 100 } 101 102 def set_values(self, x, y, z): 103 self.values = [x, y, z]