def create_locators(self, suffix='ctrl'): euler_filter_attrs = "rx", "ry", "rz" time = timeline.get() self.locators = [] constraints = [] for index, node in enumerate(self.selection): locator = cmds.spaceLocator( name="{}_{}_{}".format(node, suffix, index))[0] parent = cmds.parentConstraint(node, locator) scale = cmds.scaleConstraint(node, locator) constraints.append(parent[0]) constraints.append(scale[0]) self.locators.append(locator) cmds.bakeResults(self.locators, time=time) for locator in self.locators: for attr in euler_filter_attrs: cmds.filterCurve("{}.{}".format(locator, attr)) cmds.delete(constraints) self.add_to_set(self.locators, self.bakery_elements_set)
def test_get(self): start = cmds.playbackOptions(query=True, min=True) end = cmds.playbackOptions(query=True, max=True) timelineRange = timeline.get() self.assertEqual(start, timelineRange[0]) self.assertEqual(end, timelineRange[1])
def create_ctrls(self): ctrls = [] constraints = [] for index, locator in enumerate(self.aim_locators): ctrl_locator = cmds.spaceLocator(name="aim_ctrl_{}".format(index)) ctrls.append(ctrl_locator[0]) constraints.append(cmds.parentConstraint(locator, ctrl_locator)[0]) cmds.bakeResults(ctrls, time=timeline.get()) attrs = [] for ctrl in ctrls: for attr in "rx", "ry", "rz": attrs.append("{}.{}".format(ctrl, attr)) cmds.filterCurve(attrs) cmds.delete(constraints) for ctrl, locator, spin_locator in zip(ctrls, self.aim_locators, self.spin_locators): cmds.pointConstraint(ctrl, locator, mo=True) cmds.parentConstraint(ctrl, spin_locator, mo=True) self.add_to_set(ctrls, self.bakery_elements_set)
def rig_setup(self, constraint="parent"): cmds.currentTime(timeline.get()[0]) for index in range(len(self.aim_locators)): try: cmds.aimConstraint(self.aim_locators[index + 1], self.aim_locators[index], mo=True, aim=(0, 1, 0), u=(1, 0, 0), worldUpType="object", wuo=self.spin_locators[index]) except: cmds.aimConstraint(self.aim_locators[index - 1], self.aim_locators[index], mo=True, aim=(0, -1, 0), u=(-1, 0, 0), worldUpType="object", wuo=self.spin_locators[index]) for locator, transform in zip(self.aim_locators, self.selection): if constraint == "orient": cmds.orientConstraint(locator, transform, mo=True) else: cmds.parentConstraint(locator, transform, mo=True)
def __init__(self, constraint="parent"): super(AimRig, self).__init__() cmds.currentTime(timeline.get()[0]) self.check_attributes(constraint) self.create_selection_set() self.create_bakery_elements_set() self.build(constraint)
def bake_elements(self): bake_elements = [] time = timeline.get() for s in self.get_sets(self.selection_set_attr): bake_elements.extend(cmds.sets(s, q=True)) bake_elements = list(set(bake_elements)) cmds.bakeResults(bake_elements, time=time)
def rig(selection): cmds.currentTime(timeline.get()[0]) parents = [] for node in selection: parents.extend(cmds.listRelatives(node, parent=True)) n_locator_offsets, n_particles, nucleus, setup_group, n_locators = ( nparticle_locators(parents)) for node, n_locator in zip(selection, n_locators): cmds.pointConstraint(n_locator, node)
def bake(selection): cmds.currentTime(timeline.get()[0]) locators = baker.create_locators(selection) n_locator_offsets, n_particles, nucleus, setup_group, n_locators = ( nparticle_locators(locators)) for locator, node in zip(n_locators, selection): cmds.pointConstraint(locator, node) physics_group = cmds.createNode('transform', name='physics_group') cmds.parent(setup_group, locators, physics_group)
def bake_locators(self): constraints = [] bake_transforms = [] bake_transforms.extend(self.aim_locators) bake_transforms.extend(self.spin_locators) for transform, locator, spin_locator in zip(self.selection, self.aim_locators, self.spin_locators): constraints.append( cmds.parentConstraint(transform, locator, mo=True)[0]) constraints.append( cmds.parentConstraint(transform, spin_locator, mo=True)[0]) cmds.bakeResults(bake_transforms, at=["tx", "ty", "tz"], time=timeline.get()) cmds.delete(constraints)
def test_set(self): timeline.set(start=0, end=10) timelineRange = timeline.get() self.assertEqual(timelineRange, (0, 10))