def create_ctrls(self, i, cv_loc): pmc.select(cl=1) ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=3, d=3, s=8, n="{0}_{1}_fk_CTRL_shape".format( self.model.module_name, (i + 1)), ch=0)[0] ctrl = rig_lib.create_jnttype_ctrl(name="{0}_{1}_fk_CTRL".format( self.model.module_name, (i + 1)), shape=ctrl_shape, drawstyle=2, rotateorder=2) inv_ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=2.5, d=3, s=8, n="{0}_{1}_inv_fk_CTRL_shape".format( self.model.module_name, (i + 1)), ch=0)[0] inv_ctrl = rig_lib.create_jnttype_ctrl( name="{0}_{1}_inv_fk_CTRL".format(self.model.module_name, (i + 1)), shape=inv_ctrl_shape, drawstyle=2, rotateorder=2) nearest_point_on_curve = pmc.createNode("nearestPointOnCurve", n="temp_NPOC") self.guides[1].worldSpace >> nearest_point_on_curve.inputCurve cv_loc.getShape().worldPosition >> nearest_point_on_curve.inPosition ctrl.setAttr("translate", nearest_point_on_curve.getAttr("position")) inv_ctrl.setAttr("translate", nearest_point_on_curve.getAttr("position")) pmc.delete(nearest_point_on_curve) pmc.parent(inv_ctrl, self.ctrl_input_grp, r=0) if i == 0: pmc.parent(ctrl, self.ctrl_input_grp, r=0) else: pmc.parent(ctrl, "{0}_{1}_fk_CTRL".format(self.model.module_name, i), r=0) pmc.reorder(ctrl, front=1) pmc.parent(self.created_inv_fk_ctrls[i - 1], inv_ctrl) pmc.reorder(self.created_inv_fk_ctrls[i - 1], front=1) self.created_fk_ctrls.append(ctrl) self.created_inv_fk_ctrls.append(inv_ctrl)
def create_ik(self): start_shape = rig_lib.z_box_curve("{0}_start_ik_CTRL_shape".format(self.model.module_name)) start_ctrl = rig_lib.create_jnttype_ctrl(name="{0}_start_ik_CTRL".format(self.model.module_name), shape=start_shape, drawstyle=2, rotateorder=2) end_shape = rig_lib.z_box_curve("{0}_end_ik_CTRL_shape".format(self.model.module_name)) end_ctrl = rig_lib.create_jnttype_ctrl(name="{0}_end_ik_CTRL".format(self.model.module_name), shape=end_shape, drawstyle=2, rotateorder=2) start_ofs = pmc.group(start_ctrl, n="{0}_start_ik_ctrl_OFS".format(self.model.module_name)) start_ofs.setAttr("rotateOrder", 2) end_ofs = pmc.group(end_ctrl, n="{0}_end_ik_ctrl_OFS".format(self.model.module_name)) end_ofs.setAttr("rotateOrder", 2) start_ofs.setAttr("translate", pmc.xform(self.created_fk_ctrls[0], q=1, ws=1, translation=1)) start_ofs.setAttr("rotate", pmc.xform(self.created_fk_ctrls[0], q=1, ws=1, rotation=1)) end_ofs.setAttr("translate", pmc.xform(self.created_fk_ctrls[-1], q=1, ws=1, translation=1)) end_ofs.setAttr("rotate", pmc.xform(self.created_fk_ctrls[-1], q=1, ws=1, rotation=1)) pmc.parent(start_ofs, self.ctrl_input_grp, r=0) pmc.parent(end_ofs, self.created_fk_ctrls[-2], r=0) pmc.parent(self.created_fk_ctrls[-1], end_ctrl, r=0) pmc.parent(self.created_locs[0], start_ctrl, r=0) self.created_fk_ctrls[-1].setAttr("visibility", 0) self.created_ik_ctrls = [start_ctrl, end_ctrl] if not self.model.how_many_ctrls == 2: center_ctrl = (self.model.how_many_ctrls / 2.0) - 0.5 for i, loc in enumerate(self.created_locs): if i == center_ctrl: const = pmc.parentConstraint(start_ctrl, end_ctrl, loc, maintainOffset=1, skipRotate=["x", "y", "z"]) const.setAttr("{0}W0".format(start_ctrl), 1) const.setAttr("{0}W1".format(end_ctrl), 1) elif i < center_ctrl: const = pmc.parentConstraint(start_ctrl, end_ctrl, loc, maintainOffset=1, skipRotate=["x", "y", "z"]) const.setAttr("{0}W0".format(start_ctrl), 1) const.setAttr("{0}W1".format(end_ctrl), ((1 / (self.model.how_many_ctrls / 2.0)) * (i / 2.0))) elif i > center_ctrl: const = pmc.parentConstraint(start_ctrl, end_ctrl, loc, maintainOffset=1, skipRotate=["x", "y", "z"]) const.setAttr("{0}W0".format(start_ctrl), ((1 / (self.model.how_many_ctrls / 2.0)) * (((len(self.created_locs)-1) - i) / 2.0))) const.setAttr("{0}W1".format(end_ctrl), 1) pmc.parent(self.created_pelvis_ctrl, start_ctrl) pmc.parentConstraint(end_ctrl, self.created_spine_jnts[-1], maintainOffset=1, skipTranslate=["x", "y", "z"])
def create_fk(self): ik_spline_cv_list = [] ik_spline_controlpoints_list = [] for i, cv in enumerate(self.guides[1].cv): ik_spline_cv_list.append(cv) for i, cp in enumerate(self.ik_spline.controlPoints): ik_spline_controlpoints_list.append(cp) for i, cv in enumerate(ik_spline_cv_list): self.created_locs.append(self.create_locators(i, cv, ik_spline_controlpoints_list)) self.create_ctrls(i, self.created_locs[i]) # for i, cv in enumerate(self.ik_spline.cv): # ik_spline_cv_list.append(cv) # # for i, cp in enumerate(self.ik_spline.controlPoints): # ik_spline_controlpoints_list.append(cp) # # if not self.model.ik_creation_switch: # for i, cv in enumerate(ik_spline_cv_list): # cv_loc = self.create_locators(i, cv, ik_spline_controlpoints_list) # self.create_ctrls(i, cv_loc) # self.created_locs.append(cv_loc) # else: # ik_spline_none_tangent_cv_list = [cv for cv in ik_spline_cv_list if cv != ik_spline_cv_list[1] and cv != ik_spline_cv_list[-2]] # # ik_spline_none_tangent_controlpoints_list = [cp for cp in ik_spline_controlpoints_list if cp != ik_spline_controlpoints_list[1] and cp != ik_spline_controlpoints_list[-2]] # # for i, cv in enumerate(ik_spline_none_tangent_cv_list): # cv_loc = self.create_locators(i, cv, ik_spline_none_tangent_controlpoints_list) # self.create_ctrls(i, cv_loc) # self.created_locs.append(cv_loc) # # start_tangent_loc = self.create_locators(i=1, cv=ik_spline_cv_list[1], # ik_spline_controlpoints=ik_spline_controlpoints_list) # end_tangent_loc = self.create_locators(i=-2, cv=ik_spline_cv_list[-2], # ik_spline_controlpoints=ik_spline_controlpoints_list) # start_tangent_loc.rename("{0}_start_tangent_pos".format(self.model.module_name)) # end_tangent_loc.rename("{0}_end_tangent_pos".format(self.model.module_name)) # self.tangent_locs = [start_tangent_loc, end_tangent_loc] self.ik_spline.setAttr("translate", (0, 0, 0)) self.ik_spline.setAttr("rotate", (0, 0, 0)) self.ik_spline.setAttr("scale", (1, 1, 1)) # pmc.parentConstraint(self.created_fk_ctrls[-1], self.created_spine_jnts[-1], maintainOffset=1, skipTranslate=("x", "y", "z")) pmc.select(cl=1) pelvis_ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 1, 0), sw=360, r=2.5, d=3, s=8, n="{0}_pelvis_CTRL_shape".format(self.model.module_name), ch=0)[0] self.created_pelvis_ctrl = rig_lib.create_jnttype_ctrl(name="{0}_pelvis_CTRL".format(self.model.module_name), shape=pelvis_ctrl_shape, drawstyle=2, rotateorder=2) self.created_pelvis_ctrl.setAttr("translate", pmc.xform(self.created_pelvis_jnt, q=1, ws=1, translation=1)) pmc.parent(self.created_pelvis_ctrl, self.ctrl_input_grp) # pmc.pointConstraint(self.created_pelvis_ctrl, self.created_pelvis_jnt, maintainOffset=1) # self.created_pelvis_ctrl.rotate >> self.created_pelvis_jnt.rotate pmc.parentConstraint(self.created_pelvis_ctrl, self.created_pelvis_jnt, maintainOffset=1) self.created_pelvis_ctrl.scale >> self.created_pelvis_jnt.scale
def create_fk(self): toes_shape = pmc.circle(c=(0, 0, 0), nr=(0, 1, 0), sw=360, r=1, d=3, s=8, n="{0}_toes_fk_CTRL_shape".format( self.model.module_name), ch=0)[0] self.toes_ctrl = rig_lib.create_jnttype_ctrl("{0}_toes_fk_CTRL".format( self.model.module_name), toes_shape, drawstyle=2, rotateorder=4) self.toes_ctrl.setAttr( "translate", pmc.xform(self.created_fk_jnts[1], q=1, ws=1, translation=1)) self.toes_ctrl.setAttr("jointOrient", (90, 90 * (1 - self.side_coef), 90 * (1 + self.side_coef))) pmc.parent(self.toes_ctrl, self.ctrl_input_grp, r=0) self.toes_ctrl.addAttr( "jntRotateOffsetX", attributeType="float", defaultValue=self.created_fk_jnts[1].getAttr("rotateX"), hidden=0, keyable=0) self.toes_ctrl.addAttr( "jntRotateOffsetY", attributeType="float", defaultValue=self.created_fk_jnts[1].getAttr("rotateY"), hidden=0, keyable=0) self.toes_ctrl.addAttr( "jntRotateOffsetZ", attributeType="float", defaultValue=self.created_fk_jnts[1].getAttr("rotateZ"), hidden=0, keyable=0) jnt_offset = pmc.createNode("plusMinusAverage", n="{0}_ball_jnt_offset_PMA".format( self.created_fk_jnts[1])) jnt_offset.setAttr("operation", 1) self.toes_ctrl.rotate >> jnt_offset.input3D[0] self.toes_ctrl.jntRotateOffsetX >> jnt_offset.input3D[1].input3Dx self.toes_ctrl.jntRotateOffsetY >> jnt_offset.input3D[1].input3Dy self.toes_ctrl.jntRotateOffsetZ >> jnt_offset.input3D[1].input3Dz jnt_offset.output3D >> self.created_fk_jnts[1].rotate
def execute(self): self.prebuild() for obj in self.selection: if pmc.objExists("{0}_ctrl_OFS".format(obj)): pmc.delete("{0}_ctrl_OFS".format(obj)) pmc.select(cl=1) ctrl_shape = pmc.circle(c=(0, 0, 0), nr=self.orientation, sw=360, r=self.model.size, d=3, s=8, n="{0}_CTRLShape".format(obj), ch=0)[0] ctrl = rig_lib.create_jnttype_ctrl("{0}_CTRL".format(obj), ctrl_shape, drawstyle=2, rotateorder=self.rotate_order) pmc.select(cl=1) ctrl_ofs = pmc.joint(p=(0, 0, 0), n="{0}_ctrl_OFS".format(obj)) ctrl_ofs.setAttr("rotateOrder", self.rotate_order) ctrl_ofs.setAttr("drawStyle", 2) pmc.parent(ctrl, ctrl_ofs) if pmc.objectType(obj) == "joint" or pmc.xform( obj, q=1, rotatePivot=1) == [0, 0, 0]: pmc.xform(ctrl_ofs, ws=1, matrix=pmc.xform(obj, q=1, ws=1, matrix=1)) else: pmc.xform(ctrl_ofs, ws=1, translation=pmc.xform(obj, q=1, ws=1, rotatePivot=1)) pmc.xform(ctrl_ofs, ws=1, rotation=pmc.xform(obj, q=1, ws=1, rotation=1)) pmc.select(self.selection)
def execute(self): self.prebuild() self.delete_existing_objects() self.connect_to_parent() cog_shape = rig_lib.large_box_curve("{0}_CTRL_shape".format(self.model.module_name)) cog_ctrl = rig_lib.create_jnttype_ctrl(name="{0}_CTRL".format(self.model.module_name), shape=cog_shape, drawstyle=2) cog_ofs = pmc.group(cog_ctrl, n="{0}_ctrl_OFS".format(self.model.module_name)) cog_ofs.setAttr("translate", pmc.xform(self.guide, q=1, ws=1, translation=1)) pmc.parent(cog_ofs, self.ctrl_input_grp) rig_lib.create_output(name="{0}_OUTPUT".format(self.model.module_name), parent=cog_ctrl) rig_lib.clean_ctrl(cog_ctrl, 20, trs="s") self.jnt_input_grp.setAttr("visibility", 0) self.parts_grp.setAttr("visibility", 0) self.guides_grp.setAttr("visibility", 0) info_crv = rig_lib.signature_shape_curve("{0}_INFO".format(self.model.module_name)) info_crv.getShape().setAttr("visibility", 0) info_crv.setAttr("hiddenInOutliner", 1) info_crv.setAttr("translateX", lock=True, keyable=False, channelBox=False) info_crv.setAttr("translateY", lock=True, keyable=False, channelBox=False) info_crv.setAttr("translateZ", lock=True, keyable=False, channelBox=False) info_crv.setAttr("rotateX", lock=True, keyable=False, channelBox=False) info_crv.setAttr("rotateY", lock=True, keyable=False, channelBox=False) info_crv.setAttr("rotateZ", lock=True, keyable=False, channelBox=False) info_crv.setAttr("scaleX", lock=True, keyable=False, channelBox=False) info_crv.setAttr("scaleY", lock=True, keyable=False, channelBox=False) info_crv.setAttr("scaleZ", lock=True, keyable=False, channelBox=False) info_crv.setAttr("visibility", lock=True, keyable=False, channelBox=False) info_crv.setAttr("overrideEnabled", 1) info_crv.setAttr("overrideDisplayType", 2) pmc.parent(info_crv, self.parts_grp) rig_lib.add_parameter_as_extra_attr(info_crv, "Module", "cog") rig_lib.add_parameter_as_extra_attr(info_crv, "parent_Module", self.model.selected_module) rig_lib.add_parameter_as_extra_attr(info_crv, "parent_output", self.model.selected_output) pmc.select(cl=1)
def create_option_ctrl(self): option_ctrl_shape = rig_lib.jnt_shape_curve( name="{0}_option_ctrl_shape".format(self.model.module_name)) self.option_ctrl = rig_lib.create_jnttype_ctrl( name="{0}_option_CTRL".format(self.model.module_name), shape=option_ctrl_shape) self.option_ctrl.setAttr( "translate", pmc.xform(self.created_spine_jnts[0], q=1, ws=1, translation=1)) heigh = 0 if pmc.objExists("mod_hd"): mod_hd_grp = pmc.ls("mod_hd")[0] mod_hd_bbox = mod_hd_grp.getBoundingBox() mod_hd_bbox_low_corner = mod_hd_bbox[0] mod_hd_bbox_hi_corner = mod_hd_bbox[1] mod_hd_bbox_heigh = mod_hd_bbox_hi_corner[ 1] - mod_hd_bbox_low_corner[1] if mod_hd_bbox_heigh > heigh: heigh = mod_hd_bbox_heigh if pmc.objExists("mod_proxy"): mod_proxy_grp = pmc.ls("mod_proxy")[0] mod_proxy_bbox = mod_proxy_grp.getBoundingBox() mod_proxy_bbox_low_corner = mod_proxy_bbox[0] mod_proxy_bbox_hi_corner = mod_proxy_bbox[1] mod_proxy_bbox_heigh = mod_proxy_bbox_hi_corner[ 1] - mod_proxy_bbox_low_corner[1] if mod_proxy_bbox_heigh > heigh: heigh = mod_proxy_bbox_heigh if pmc.objExists("mod_sliced"): mod_sliced_grp = pmc.ls("mod_sliced")[0] mod_sliced_bbox = mod_sliced_grp.getBoundingBox() mod_sliced_bbox_low_corner = mod_sliced_bbox[0] mod_sliced_bbox_hi_corner = mod_sliced_bbox[1] mod_sliced_bbox_heigh = mod_sliced_bbox_hi_corner[ 1] - mod_sliced_bbox_low_corner[1] if mod_sliced_bbox_heigh > heigh: heigh = mod_sliced_bbox_heigh ctrl_cvs = self.option_ctrl.cv[:] for i, cv in enumerate(ctrl_cvs): pmc.xform(self.option_ctrl.getShape().controlPoints[i], ws=1, translation=(pmc.xform(cv, q=1, ws=1, translation=1)[0], pmc.xform(cv, q=1, ws=1, translation=1)[1] + heigh, pmc.xform(cv, q=1, ws=1, translation=1)[2])) self.option_ctrl.addAttr("ctrlsPrincipaux", attributeType="bool", defaultValue=1, hidden=0, keyable=1) self.option_ctrl.addAttr("ctrlsSecondaires", attributeType="bool", defaultValue=0, hidden=0, keyable=1) self.option_ctrl.addAttr("autoSwim", attributeType="float", defaultValue=0, hidden=0, keyable=1, hasMaxValue=1, hasMinValue=1, maxValue=1, minValue=0) self.option_ctrl.addAttr("amplitude", attributeType="float", defaultValue=2, hidden=0, keyable=1, hasMaxValue=0, hasMinValue=1, minValue=0) self.option_ctrl.addAttr("speed", attributeType="float", defaultValue=2, hidden=0, keyable=1, hasMaxValue=0, hasMinValue=1, minValue=0.1) self.option_ctrl.addAttr("delay", attributeType="float", defaultValue=-0.5, hidden=0, keyable=1, hasMaxValue=0, hasMinValue=0) i = 1 while i <= self.model.how_many_levels: if i == self.model.how_many_levels: name = "caudalfin" else: name = "level{0}".format(i) self.option_ctrl.addAttr("{0}Attributes".format(name), attributeType="enum", enumName="_________", hidden=0, keyable=0) self.option_ctrl.setAttr("{0}Attributes".format(name), lock=1, channelBox=1) self.option_ctrl.addAttr("{0}Offset".format(name), attributeType="float", defaultValue=0, hidden=0, keyable=1, hasMinValue=1, minValue=0, hasMaxValue=1, maxValue=self.model.how_many_jnts + 2) self.option_ctrl.addAttr("{0}Amplitude".format(name), attributeType="float", defaultValue=1, hidden=0, keyable=1, hasMaxValue=0, hasMinValue=1, minValue=0) self.option_ctrl.addAttr("{0}Frequence".format(name), attributeType="float", defaultValue=1, hidden=0, keyable=1, hasMaxValue=0, hasMinValue=0) self.option_ctrl.addAttr("{0}Delay".format(name), attributeType="float", defaultValue=1, hidden=0, keyable=1, hasMaxValue=0, hasMinValue=0) i += 1 option_ctrl_offset = pmc.group(em=1, n="{0}_option_ctrl_OFS".format( self.model.module_name)) option_ctrl_offset.setAttr( "translate", pmc.xform(self.option_ctrl, q=1, ws=1, translation=1)) option_ctrl_offset.setAttr( "rotate", pmc.xform(self.option_ctrl, q=1, ws=1, rotation=1)) pmc.parent(self.option_ctrl, option_ctrl_offset, r=0) pmc.parent(option_ctrl_offset, self.ctrl_input_grp, r=0)
def execute(self): self.prebuild() check_list = [ "{0}_RIG".format(self.model.character_name), "GEO_GRP", "CTRL_GRP", "JNT_GRP", "MESH_GRP", "PARTS_GRP", "global_CTRL", "{0}_global_OUTPUT".format(self.model.module_name), "{0}_local_INPUT".format(self.model.module_name), "{0}_local_ctrl_OFS".format(self.model.module_name), "{0}_local_CTRL".format(self.model.module_name), "{0}_local_ctrl_OUTPUT".format(self.model.module_name), "{0}_global_scale_MDL".format(self.model.module_name) ] if rig_lib.exists_check(check_list): pmc.select(cl=1) return if rig_lib.exists_check("{0}_RIG".format(self.model.character_name)): pmc.delete("{0}_RIG".format(self.model.character_name)) main_grp = pmc.group(em=1, n="{0}_RIG".format(self.model.character_name)) geo_grp = pmc.group(em=1, n="GEO_GRP") ctrl_grp = pmc.group(em=1, n="CTRL_GRP") jnt_grp = pmc.group(em=1, n="JNT_GRP") mesh_grp = pmc.group(em=1, n="MESH_GRP") parts_grp = pmc.group(em=1, n="PARTS_GRP") global_shape = rig_lib.square_arrow_curve( "{0}_global_CTRL_shape".format(self.model.module_name)) global_ctrl = rig_lib.create_jnttype_ctrl(name="global_CTRL", shape=global_shape, drawstyle=2) global_output = pmc.spaceLocator(p=(0, 0, 0), n="{0}_global_OUTPUT".format( self.model.module_name)) global_output.visibility.set(0) pmc.parent(geo_grp, ctrl_grp, jnt_grp, mesh_grp, parts_grp, global_ctrl, main_grp) pmc.parent(global_output, global_ctrl, r=1) local_input = pmc.group(em=1, n="{0}_local_ctrl_INPUT".format( self.model.module_name)) pmc.parent(local_input, ctrl_grp, r=1) rig_lib.matrix_constraint(global_output, local_input, srt="trs") local_shape = pmc.circle(c=(0, 0, 0), nr=(0, 1, 0), sw=360, r=5, d=3, s=8, n="{0}_local_CTRL_shape".format( self.model.module_name), ch=0)[0] local_ctrl = rig_lib.create_jnttype_ctrl(name="{0}_local_CTRL".format( self.model.module_name), shape=local_shape, drawstyle=2) pmc.parent(local_ctrl, local_input, r=1) rig_lib.create_output(name="{0}_local_ctrl_OUTPUT".format( self.model.module_name), parent=local_ctrl) global_scale_mult_node = pmc.createNode( "multDoubleLinear", n="{0}_global_mult_local_scale_MDL".format(self.model.module_name)) global_ctrl.scaleY >> global_ctrl.scaleX global_ctrl.scaleY >> global_ctrl.scaleZ local_ctrl.scaleY >> local_ctrl.scaleX local_ctrl.scaleY >> local_ctrl.scaleZ global_ctrl.scaleY >> global_scale_mult_node.input1 local_ctrl.scaleY >> global_scale_mult_node.input2 pmc.aliasAttr("global_scale", global_ctrl.scaleY) pmc.aliasAttr("local_scale", local_ctrl.scaleY) global_ctrl.setAttr("scaleX", lock=True, keyable=False, channelBox=False) global_ctrl.setAttr("scaleY", keyable=False, channelBox=True) global_ctrl.setAttr("scaleZ", lock=True, keyable=False, channelBox=False) local_ctrl.setAttr("scaleX", lock=True, keyable=False, channelBox=False) local_ctrl.setAttr("scaleY", keyable=False, channelBox=True) local_ctrl.setAttr("scaleZ", lock=True, keyable=False, channelBox=False) rig_lib.clean_ctrl(global_ctrl, 3, trs="") rig_lib.clean_ctrl(local_ctrl, 17, trs="") info_crv = rig_lib.signature_shape_curve("{0}_INFO".format( self.model.module_name)) info_crv.getShape().setAttr("visibility", 0) info_crv.setAttr("hiddenInOutliner", 1) info_crv.setAttr("translateX", lock=True, keyable=False, channelBox=False) info_crv.setAttr("translateY", lock=True, keyable=False, channelBox=False) info_crv.setAttr("translateZ", lock=True, keyable=False, channelBox=False) info_crv.setAttr("rotateX", lock=True, keyable=False, channelBox=False) info_crv.setAttr("rotateY", lock=True, keyable=False, channelBox=False) info_crv.setAttr("rotateZ", lock=True, keyable=False, channelBox=False) info_crv.setAttr("scaleX", lock=True, keyable=False, channelBox=False) info_crv.setAttr("scaleY", lock=True, keyable=False, channelBox=False) info_crv.setAttr("scaleZ", lock=True, keyable=False, channelBox=False) info_crv.setAttr("visibility", lock=True, keyable=False, channelBox=False) info_crv.setAttr("overrideEnabled", 1) info_crv.setAttr("overrideDisplayType", 2) pmc.parent(info_crv, parts_grp) rig_lib.add_parameter_as_extra_attr(info_crv, "Module", "mandatory_base") rig_lib.add_parameter_as_extra_attr(info_crv, "character_name", self.model.character_name) pmc.select(cl=1)
def create_ctrls(self): self.ctrls = [] for fol in self.follicles: pmc.select(clear=1) ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=1, d=3, s=8, n=str(fol).replace("_FOL", "_ctrl_Shape"), ch=0)[0] ctrl = rig_lib.create_jnttype_ctrl(name=str(fol).replace( "_FOL", "_CTRL"), shape=ctrl_shape) pmc.select(clear=1) ctrl_ofs = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_OFS")) ctrl_ofs.setAttr("drawStyle", 2) ctrl_fix_r = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_rotate_FIX")) ctrl_fix_r.setAttr("drawStyle", 2) ctrl_fix_r.setAttr("rotateOrder", 5) ctrl_fix_t = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_translate_FIX")) ctrl_fix_t.setAttr("drawStyle", 2) pmc.parent(ctrl, ctrl_fix_t) pmc.parent(ctrl_ofs, fol) ctrl_ofs.setAttr("translate", (0, 0, 0)) ctrl_ofs.setAttr("rotate", (0, 0, 0)) ctrl_ofs.setAttr("jointOrient", (0, 0, 0)) invert_ctrl_translate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_translate_MDL") invert_ctrl_rotate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_rotate_MDL") ctrl.translate >> invert_ctrl_translate.input1 invert_ctrl_translate.setAttr("input2", (-1, -1, -1)) invert_ctrl_translate.output >> ctrl_fix_t.translate ctrl.rotate >> invert_ctrl_rotate.input1 invert_ctrl_rotate.setAttr("input2", (-1, -1, -1)) invert_ctrl_rotate.output >> ctrl_fix_r.rotate ctrl_cvs = ctrl.cv[:] for i, cv in enumerate(ctrl_cvs): pmc.xform(ctrl.getShape().controlPoints[i], translation=(pmc.xform(cv, q=1, translation=1)[0], pmc.xform(cv, q=1, translation=1)[1], pmc.xform(cv, q=1, translation=1)[2] + 1)) self.ctrls.append(ctrl)
def create_ctrls(self): jaw_shape = pmc.circle(c=(0, 0, 0), nr=(0, 1, 0), sw=360, r=3, d=3, s=8, n="{0}_jaw_CTRL_shape".format( self.model.module_name), ch=0)[0] jaw_ctrl = rig_lib.create_jnttype_ctrl(name="{0}_jaw_CTRL".format( self.model.module_name), shape=jaw_shape, drawstyle=2) # jaw_ofs = pmc.group(jaw_ctrl, n="{0}_jaw_ctrl_OFS".format(self.model.module_name)) jaw_cvs = jaw_ctrl.getShape().cv[:] for cv in jaw_cvs: pmc.xform(cv, ws=1, translation=(pmc.xform(cv, q=1, ws=1, translation=1)[0], pmc.xform(cv, q=1, ws=1, translation=1)[1], pmc.xform(cv, q=1, ws=1, translation=1)[2] + 2)) pmc.select(cl=1) jaw_ofs = pmc.joint(p=(0, 0, 0), n="{0}__jaw_ctrl_OFS".format( self.model.module_name)) jaw_ofs.setAttr("drawStyle", 2) pmc.parent(jaw_ctrl, jaw_ofs) jaw_ofs.setAttr( "translate", pmc.xform(self.created_skn_jnts[2], q=1, ws=1, translation=1)) jaw_ofs.setAttr( "jointOrient", pmc.xform(self.created_skn_jnts[2], q=1, ws=1, rotation=1)) pmc.parent(jaw_ofs, self.ctrl_input_grp) jaw_ctrl.rotate >> self.created_skn_jnts[2].rotate jaw_ctrl.translate >> self.created_skn_jnts[2].translate l_eye_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=1, d=3, s=8, n="{0}_left_eye_CTRL_shape".format( self.model.module_name), ch=0)[0] l_eye_ctrl = rig_lib.create_jnttype_ctrl( name="{0}_left_eye_CTRL".format(self.model.module_name), shape=l_eye_shape, drawstyle=2) # l_eye_ofs = pmc.group(l_eye_ctrl, n="{0}_left_eye_ctrl_OFS".format(self.model.module_name)) l_eye_cvs = l_eye_ctrl.getShape().cv[:] for cv in l_eye_cvs: pmc.xform(cv, ws=1, translation=(pmc.xform(cv, q=1, ws=1, translation=1)[0], pmc.xform(cv, q=1, ws=1, translation=1)[1], pmc.xform(cv, q=1, ws=1, translation=1)[2] + 2)) l_eye_ctrl.setAttr( "translate", pmc.xform(self.created_skn_jnts[4], q=1, ws=1, translation=1)) pmc.parent(l_eye_ctrl, self.ctrl_input_grp) l_eye_ctrl.rotate >> self.created_skn_jnts[4].rotate r_eye_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=1, d=3, s=8, n="{0}_right_eye_CTRL_shape".format( self.model.module_name), ch=0)[0] # r_eye_ofs = pmc.group(r_eye_ctrl, n="{0}_right_eye_ctrl_OFS".format(self.model.module_name)) r_eye_ctrl = rig_lib.create_jnttype_ctrl( name="{0}_right_eye_CTRL".format(self.model.module_name), shape=r_eye_shape, drawstyle=2) r_eye_cvs = r_eye_ctrl.getShape().cv[:] for cv in r_eye_cvs: pmc.xform(cv, ws=1, translation=(pmc.xform(cv, q=1, ws=1, translation=1)[0], pmc.xform(cv, q=1, ws=1, translation=1)[1], pmc.xform(cv, q=1, ws=1, translation=1)[2] + 2)) r_eye_ctrl.setAttr( "translate", pmc.xform(self.created_skn_jnts[5], q=1, ws=1, translation=1)) pmc.parent(r_eye_ctrl, self.ctrl_input_grp) r_eye_ctrl.rotate >> self.created_skn_jnts[5].rotate self.created_ctrls = [jaw_ctrl, l_eye_ctrl, r_eye_ctrl]
def create_fk(self): ik_spline_cv_list = [] ik_spline_controlpoints_list = [] for i, cv in enumerate(self.guides[1].cv): ik_spline_cv_list.append(cv) for i, cp in enumerate(self.ik_spline.controlPoints): ik_spline_controlpoints_list.append(cp) self.created_locs = [] for i, cv in enumerate(ik_spline_cv_list): self.created_locs.append( self.create_locators(i, cv, ik_spline_controlpoints_list)) self.create_ctrls(i, self.created_locs[i]) pmc.parent(self.created_locs[0], self.created_inv_fk_ctrls[0]) pmc.parent(self.created_locs[-1], self.created_fk_ctrls[-1]) center_ctrl = (self.model.how_many_ctrls / 2.0) - 1.5 for i, loc in enumerate(self.created_locs[1:-1]): pmc.select(cl=1) ctrl_ofs = pmc.joint(p=(0, 0, 0), n="{0}".format( str(loc).replace("_pos", "_bend_ctrl_OFS"))) ctrl_ofs.setAttr("drawStyle", 2) ctrl_shape = pmc.circle( c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=1.5, d=3, s=8, n="{0}".format(str(loc).replace("_pos", "_bend_CTRL_Shape")), ch=0)[0] ctrl = rig_lib.create_jnttype_ctrl(name=str(loc).replace( "_pos", "_bend_CTRL"), shape=ctrl_shape) pmc.parent(ctrl, ctrl_ofs) nearest_point_on_curve = pmc.createNode("nearestPointOnCurve", n="temp_NPOC") self.guides[1].worldSpace >> nearest_point_on_curve.inputCurve loc.getShape().worldPosition >> nearest_point_on_curve.inPosition ctrl_ofs.setAttr("translate", nearest_point_on_curve.getAttr("position")) pmc.delete(nearest_point_on_curve) pmc.parent(ctrl_ofs, self.ctrl_input_grp) pmc.parent(loc, ctrl) if i == center_ctrl: const = pmc.parentConstraint(self.created_inv_fk_ctrls[0], self.created_fk_ctrls[-1], ctrl_ofs, maintainOffset=1, skipRotate=["x", "y", "z"]) const.setAttr("{0}W0".format(self.created_inv_fk_ctrls[0]), 1) const.setAttr("{0}W1".format(self.created_fk_ctrls[-1]), 1) elif i < center_ctrl: const = pmc.parentConstraint(self.created_inv_fk_ctrls[0], self.created_fk_ctrls[-1], ctrl_ofs, maintainOffset=1, skipRotate=["x", "y", "z"]) const.setAttr("{0}W0".format(self.created_inv_fk_ctrls[0]), 1) const.setAttr("{0}W1".format(self.created_fk_ctrls[-1]), ((1 / (self.model.how_many_ctrls / 2.0)) * ((i + 1) / 2.0))) elif i > center_ctrl: const = pmc.parentConstraint(self.created_inv_fk_ctrls[0], self.created_fk_ctrls[-1], ctrl_ofs, maintainOffset=1, skipRotate=["x", "y", "z"]) const.setAttr("{0}W0".format(self.created_inv_fk_ctrls[0]), ((1 / (self.model.how_many_ctrls / 2.0)) * (((len(self.created_locs) - 1) - (i + 1)) / 2.0))) const.setAttr("{0}W1".format(self.created_fk_ctrls[-1]), 1) self.bend_ctrls.append(ctrl) self.ik_spline.setAttr("translate", (0, 0, 0)) self.ik_spline.setAttr("rotate", (0, 0, 0)) self.ik_spline.setAttr("scale", (1, 1, 1)) # pmc.parentConstraint(self.created_fk_ctrls[-1], self.created_spine_jnts[-1], maintainOffset=1, skipTranslate=("x", "y", "z")) pmc.select(d=1) pelvis_ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 1, 0), sw=360, r=2.5, d=3, s=8, n="{0}_pelvis_CTRL_shape".format( self.model.module_name), ch=0)[0] self.created_pelvis_ctrl = rig_lib.create_jnttype_ctrl( name="{0}_pelvis_CTRL".format(self.model.module_name), shape=pelvis_ctrl_shape, drawstyle=2, rotateorder=2) self.created_pelvis_ctrl.setAttr( "translate", pmc.xform(self.created_pelvis_jnt, q=1, ws=1, translation=1)) pmc.parent(self.created_pelvis_ctrl, self.ctrl_input_grp) # pmc.pointConstraint(self.created_pelvis_ctrl, self.created_pelvis_jnt, maintainOffset=1) # self.created_pelvis_ctrl.rotate >> self.created_pelvis_jnt.rotate pmc.parentConstraint(self.created_pelvis_ctrl, self.created_pelvis_jnt, maintainOffset=1) self.created_pelvis_ctrl.scale >> self.created_pelvis_jnt.scale
def create_corner_ctrls(self): distance = pmc.createNode("distanceBetween") self.top_ctrls_jnt[0].getParent().translate >> distance.point1 self.bot_ctrls_jnt[0].getParent().translate >> distance.point2 topstart_botstart_dist = distance.getAttr("distance") self.bot_ctrls_jnt[0].getParent().translate // distance.point2 self.bot_ctrls_jnt[-1].getParent().translate >> distance.point2 topstart_botend_dist = distance.getAttr("distance") pmc.delete(distance) if topstart_botstart_dist < topstart_botend_dist: side1_jnts = [self.top_ctrls_jnt[0], self.bot_ctrls_jnt[0]] side1_ctrls = [self.top_ctrls[0], self.bot_ctrls[0]] side2_jnts = [self.top_ctrls_jnt[-1], self.bot_ctrls_jnt[-1]] side2_ctrls = [self.top_ctrls[-1], self.bot_ctrls[-1]] else: side1_jnts = [self.top_ctrls_jnt[0], self.bot_ctrls_jnt[-1]] side1_ctrls = [self.top_ctrls[0], self.bot_ctrls[-1]] side2_jnts = [self.top_ctrls_jnt[-1], self.bot_ctrls_jnt[0]] side2_ctrls = [self.top_ctrls[-1], self.bot_ctrls[0]] pmc.select(cl=1) side1_master_ofs = pmc.joint(p=(0, 0, 0), n="{0}_corner_01_jnt_OFS".format(self.model.module_name)) side1_master_jnt = pmc.joint(p=(0, 0, 0), n="{0}_corner_01_JNT".format(self.model.module_name)) pmc.select(cl=1) side2_master_ofs = pmc.joint(p=(0, 0, 0), n="{0}_corner_02_jnt_OFS".format(self.model.module_name)) side2_master_jnt = pmc.joint(p=(0, 0, 0), n="{0}_corner_02_JNT".format(self.model.module_name)) side1_master_ofs.setAttr("drawStyle", 2) side2_master_ofs.setAttr("drawStyle", 2) side1_master_jnt.setAttr("radius", 0.5) side2_master_jnt.setAttr("radius", 0.5) side1_master_ofs.setAttr("translate", ((side1_jnts[0].getParent().getAttr("translateX") + side1_jnts[-1].getParent().getAttr("translateX")) / 2, (side1_jnts[0].getParent().getAttr("translateY") + side1_jnts[-1].getParent().getAttr("translateY")) / 2, (side1_jnts[0].getParent().getAttr("translateZ") + side1_jnts[-1].getParent().getAttr("translateZ")) / 2,)) side2_master_ofs.setAttr("translate", ((side2_jnts[0].getParent().getAttr("translateX") + side2_jnts[-1].getParent().getAttr("translateX")) / 2, (side2_jnts[0].getParent().getAttr("translateY") + side2_jnts[-1].getParent().getAttr("translateY")) / 2, (side2_jnts[0].getParent().getAttr("translateZ") + side2_jnts[-1].getParent().getAttr("translateZ")) / 2,)) if side1_master_ofs.getAttr("translateX") < -0.05: side1_master_ofs.setAttr("jointOrientY", 180) elif side2_master_ofs.getAttr("translateX") < -0.05: side2_master_ofs.setAttr("jointOrientY", 180) pmc.parent(side1_jnts[0].getParent(), side1_master_jnt) pmc.parent(side1_jnts[-1].getParent(), side1_master_jnt) pmc.parent(side2_jnts[0].getParent(), side2_master_jnt) pmc.parent(side2_jnts[-1].getParent(), side2_master_jnt) self.sides_master_jnts = [side1_master_jnt, side2_master_jnt] self.sides_ctrls = [] self.sides_ctrls_fol = [] for jnt in self.sides_master_jnts: follicle_shape = pmc.createNode("follicle", n=str(jnt).replace("_JNT", "_FOLShape")) follicle = follicle_shape.getParent() follicle.rename(str(jnt).replace("_JNT", "_FOL")) follicle_shape.outTranslate >> follicle.translate follicle_shape.outRotate >> follicle.rotate self.mesh_to_follow.getShape().outMesh >> follicle_shape.inputMesh self.mesh_to_follow.getShape().worldMatrix[0] >> follicle_shape.inputWorldMatrix point_on_mesh = pmc.createNode("closestPointOnMesh", n=str(jnt) + "CPM") self.mesh_to_follow.getShape().outMesh >> point_on_mesh.inMesh point_on_mesh.setAttr("inPosition", pmc.xform(jnt, q=1, ws=1, translation=1)) follicle_shape.setAttr("parameterU", point_on_mesh.getAttr("parameterU")) follicle_shape.setAttr("parameterV", point_on_mesh.getAttr("parameterV")) pmc.delete(point_on_mesh) self.sides_ctrls_fol.append(follicle) pmc.select(clear=1) ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=0.8, d=3, s=8, n=str(jnt).replace("_JNT", "_ctrl_Shape"), ch=0)[0] ctrl = rig_lib.create_jnttype_ctrl(name=str(jnt).replace("_JNT", "_CTRL"), shape=ctrl_shape) pmc.select(clear=1) ctrl_ofs = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_OFS")) ctrl_ofs.setAttr("drawStyle", 2) ctrl_fix_r = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_rotate_FIX")) ctrl_fix_r.setAttr("drawStyle", 2) ctrl_fix_r.setAttr("rotateOrder", 5) ctrl_fix_t = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_translate_FIX")) ctrl_fix_t.setAttr("drawStyle", 2) pmc.parent(ctrl, ctrl_fix_t) pmc.parent(ctrl_ofs, follicle) ctrl_ofs.setAttr("translate", (0, 0, 0)) ctrl_ofs.setAttr("rotate", (0, 0, 0)) ctrl_ofs.setAttr("jointOrient", (0, 0, 0)) ctrl_ofs_orientation_loc = pmc.spaceLocator(p=(0, 0, 0), n="{0}_orientation_LOC".format(ctrl_ofs)) pmc.parent(ctrl_ofs_orientation_loc, jnt, r=1) pmc.parent(ctrl_ofs_orientation_loc, follicle, r=0) ctrl_ofs.setAttr("jointOrient", ctrl_ofs_orientation_loc.getAttr("rotate")) pmc.delete(ctrl_ofs_orientation_loc) invert_ctrl_translate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_translate_MDL") invert_ctrl_rotate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_rotate_MDL") ctrl.translate >> invert_ctrl_translate.input1 invert_ctrl_translate.setAttr("input2", (-1, -1, -1)) invert_ctrl_translate.output >> ctrl_fix_t.translate ctrl.rotate >> invert_ctrl_rotate.input1 invert_ctrl_rotate.setAttr("input2", (-1, -1, -1)) invert_ctrl_rotate.output >> ctrl_fix_r.rotate ctrl_cvs = ctrl.cv[:] for cv in ctrl_cvs: pmc.move(cv, 0.5, moveZ=1, ws=1, wd=1, r=1) ctrl.translate >> jnt.translate ctrl.rotate >> jnt.rotate ctrl.scale >> jnt.scale self.sides_ctrls.append(ctrl) ctrl.addAttr("cornerSecondaryCtrls", attributeType="bool", defaultValue=0, hidden=0, keyable=1) pmc.parent(jnt.getParent(), self.parts_grp) pmc.parent(follicle, self.ctrl_input_grp) self.sides_ctrls[0].cornerSecondaryCtrls >> side1_ctrls[0].visibility self.sides_ctrls[0].cornerSecondaryCtrls >> side1_ctrls[-1].visibility self.sides_ctrls[-1].cornerSecondaryCtrls >> side2_ctrls[0].visibility self.sides_ctrls[-1].cornerSecondaryCtrls >> side2_ctrls[-1].visibility
def create_ribbons(self, side, components_type, selection, how_many_ctrls): if components_type != "face": if components_type == "edge": vertices_from_selection = pmc.polyListComponentConversion(selection, fromEdge=1, toVertex=1) vertices = pmc.ls(vertices_from_selection, flatten=1) vertices_from_first_edge = pmc.ls(pmc.polyListComponentConversion(selection[0], fromEdge=1, toVertex=1), flatten=1) edges_from_point = pmc.ls(pmc.polyListComponentConversion(vertices_from_first_edge[0], fromVertex=1, toEdge=1), flatten=1) vertices_from_edges = pmc.ls(pmc.polyListComponentConversion(edges_from_point, toVertex=1, fromEdge=1, border=1), flatten=1) next_vertex = [vertex for vertex in vertices_from_edges if vertex in vertices] if len(next_vertex) == 1: first_vertex = pmc.ls(vertices_from_first_edge[0])[0] else: first_vertex = pmc.ls(vertices_from_first_edge[1])[0] vertices.remove(first_vertex) vertices.insert(0, first_vertex) else: vertices = selection ordered_vertices = rig_lib.continuous_check_and_reorder_vertex_list(vertices, self.model.module_name) vertices_world_pos = [] skn_jnts = [] for i, vertex in enumerate(ordered_vertices): vertices_world_pos.append(pmc.xform(vertex, q=1, ws=1, translation=1)) pmc.select(cl=1) jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_{2}_SKN".format(self.model.module_name, side, i)) jnt.setAttr("translate", vertices_world_pos[i]) jnt.setAttr("radius", 0.1) skn_jnts.append(jnt) front_curve = pmc.curve(d=3, p=vertices_world_pos, n="{0}_{1}_nurbsSurface_guide_01".format(self.model.module_name, side)) back_curve = pmc.duplicate(front_curve, n="{0}_{1}_nurbsSurface_guide_02".format(self.model.module_name, side))[0] if self.model.loft_axis == "X": front_curve.setAttr("translateX", 0.1) back_curve.setAttr("translateX", -0.1) elif self.model.loft_axis == "Y": front_curve.setAttr("translateY", 0.1) back_curve.setAttr("translateY", -0.1) else: front_curve.setAttr("translateZ", 0.1) back_curve.setAttr("translateZ", -0.1) surface = pmc.loft(back_curve, front_curve, ar=1, ch=0, d=1, uniform=0, n="{0}_{1}_ribbons_NURBSSURFACE".format(self.model.module_name, side))[0] surface = pmc.rebuildSurface(surface, ch=0, du=1, dv=3, dir=2, kcp=1, kr=0, rt=0, rpo=1)[0] pmc.delete(front_curve) pmc.delete(back_curve) pmc.parent(surface, self.parts_grp) self.jnts_to_skin.append(skn_jnts) follicles = [] for i, jnt in enumerate(skn_jnts): follicle_shape = pmc.createNode("follicle", n="{0}_{1}_{2}_FOLShape".format(self.model.module_name, side, i)) follicle = follicle_shape.getParent() follicle.rename("{0}_{1}_{2}_FOL".format(self.model.module_name, side, i)) follicle_shape.outTranslate >> follicle.translate follicle_shape.outRotate >> follicle.rotate surface.getShape().local >> follicle_shape.inputSurface surface.getShape().worldMatrix[0] >> follicle_shape.inputWorldMatrix point_on_surface = pmc.createNode("closestPointOnSurface", n=str(jnt) + "CPS") surface.getShape().local >> point_on_surface.inputSurface point_on_surface.setAttr("inPosition", pmc.xform(jnt, q=1, ws=1, translation=1)) follicle_shape.setAttr("parameterU", point_on_surface.getAttr("parameterU")) follicle_shape.setAttr("parameterV", point_on_surface.getAttr("parameterV")) pmc.delete(point_on_surface) pmc.parent(jnt, follicle, r=0) follicles.append(follicle) pmc.parent(follicle, self.jnt_input_grp) pmc.select(cl=1) start_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_start_JNT".format(self.model.module_name, side)) start_jnt.setAttr("radius", 0.2) pmc.select(cl=1) end_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_end_JNT".format(self.model.module_name, side)) end_jnt.setAttr("radius", 0.2) pmc.select(cl=1) mid_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_mid_JNT".format(self.model.module_name, side)) mid_jnt.setAttr("radius", 0.2) pmc.select(cl=1) start_mid_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_start_mid_JNT".format(self.model.module_name, side)) start_mid_jnt.setAttr("radius", 0.2) pmc.select(cl=1) mid_end_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_mid_end_JNT".format(self.model.module_name, side)) mid_end_jnt.setAttr("radius", 0.2) ctrl_jnts_pos = pmc.createNode("pointOnSurfaceInfo", n="{0}_{1}_PSI".format(self.model.module_name, side)) surface.getShape().local >> ctrl_jnts_pos.inputSurface ctrl_jnts_pos.setAttr("parameterU", 0.5) ctrl_jnts_pos.setAttr("parameterV", 0.0) pmc.refresh() start_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) if how_many_ctrls == "7": ctrl_jnts_pos.setAttr("parameterV", 0.3) else: ctrl_jnts_pos.setAttr("parameterV", 0.25) pmc.refresh() start_mid_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrl_jnts_pos.setAttr("parameterV", 0.5) pmc.refresh() mid_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) if how_many_ctrls == "7": ctrl_jnts_pos.setAttr("parameterV", 0.7) else: ctrl_jnts_pos.setAttr("parameterV", 0.75) pmc.refresh() mid_end_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrl_jnts_pos.setAttr("parameterV", 1.0) pmc.refresh() end_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) if how_many_ctrls == "7": pmc.select(cl=1) start_quarter_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_start_quarter_JNT".format(self.model.module_name, side)) start_quarter_jnt.setAttr("radius", 0.2) pmc.select(cl=1) quarter_end_jnt = pmc.joint(p=(0, 0, 0), n="{0}_{1}_quarter_end_JNT".format(self.model.module_name, side)) quarter_end_jnt.setAttr("radius", 0.2) ctrl_jnts_pos.setAttr("parameterV", 0.15) pmc.refresh() start_quarter_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrl_jnts_pos.setAttr("parameterV", 0.85) pmc.refresh() quarter_end_jnt.setAttr("translate", ctrl_jnts_pos.getAttr("position")) ctrls_jnt = [start_jnt, start_quarter_jnt, start_mid_jnt, mid_jnt, mid_end_jnt, quarter_end_jnt, end_jnt] else: ctrls_jnt = [start_jnt, start_mid_jnt, mid_jnt, mid_end_jnt, end_jnt] pmc.delete(ctrl_jnts_pos) ctrls = [] ctrls_fol = [] for jnt in ctrls_jnt: if side == "bot": jnt.setAttr("jointOrientX", 180) if jnt.getAttr("translateX") < -0.05: jnt.setAttr("jointOrientY", 180) follicle_shape = pmc.createNode("follicle", n=str(jnt).replace("_JNT", "_FOLShape")) follicle = follicle_shape.getParent() follicle.rename(str(jnt).replace("_JNT", "_FOL")) follicle_shape.outTranslate >> follicle.translate follicle_shape.outRotate >> follicle.rotate self.mesh_to_follow.getShape().outMesh >> follicle_shape.inputMesh self.mesh_to_follow.getShape().worldMatrix[0] >> follicle_shape.inputWorldMatrix point_on_mesh = pmc.createNode("closestPointOnMesh", n=str(jnt) + "CPM") self.mesh_to_follow.getShape().outMesh >> point_on_mesh.inMesh point_on_mesh.setAttr("inPosition", pmc.xform(jnt, q=1, ws=1, translation=1)) follicle_shape.setAttr("parameterU", point_on_mesh.getAttr("parameterU")) follicle_shape.setAttr("parameterV", point_on_mesh.getAttr("parameterV")) pmc.delete(point_on_mesh) ctrls_fol.append(follicle) pmc.select(clear=1) ctrl_shape = pmc.circle(c=(0, 0, 0), nr=(0, 0, 1), sw=360, r=0.5, d=3, s=8, n=str(jnt).replace("_JNT", "_ctrl_Shape"), ch=0)[0] ctrl = rig_lib.create_jnttype_ctrl(name=str(jnt).replace("_JNT", "_CTRL"), shape=ctrl_shape) pmc.select(clear=1) ctrl_ofs = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_OFS")) ctrl_ofs.setAttr("drawStyle", 2) ctrl_fix_r = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_rotate_FIX")) ctrl_fix_r.setAttr("drawStyle", 2) ctrl_fix_r.setAttr("rotateOrder", 5) ctrl_fix_t = pmc.joint(p=(0, 0, 0), n=str(ctrl).replace("_CTRL", "_ctrl_translate_FIX")) ctrl_fix_t.setAttr("drawStyle", 2) pmc.parent(ctrl, ctrl_fix_t) pmc.parent(ctrl_ofs, follicle) ctrl_ofs.setAttr("translate", (0, 0, 0)) ctrl_ofs.setAttr("rotate", (0, 0, 0)) ctrl_ofs.setAttr("jointOrient", (0, 0, 0)) ctrl_ofs_orientation_loc = pmc.spaceLocator(p=(0, 0, 0), n="{0}_orientation_LOC".format(ctrl_ofs)) pmc.parent(ctrl_ofs_orientation_loc, jnt, r=1) pmc.parent(ctrl_ofs_orientation_loc, follicle, r=0) ctrl_ofs.setAttr("jointOrient", ctrl_ofs_orientation_loc.getAttr("rotate")) pmc.delete(ctrl_ofs_orientation_loc) invert_ctrl_translate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_translate_MDL") invert_ctrl_rotate = pmc.createNode("multiplyDivide", n=str(ctrl) + "invert_rotate_MDL") ctrl.translate >> invert_ctrl_translate.input1 invert_ctrl_translate.setAttr("input2", (-1, -1, -1)) invert_ctrl_translate.output >> ctrl_fix_t.translate ctrl.rotate >> invert_ctrl_rotate.input1 invert_ctrl_rotate.setAttr("input2", (-1, -1, -1)) invert_ctrl_rotate.output >> ctrl_fix_r.rotate ctrl_cvs = ctrl.cv[:] for cv in ctrl_cvs: pmc.move(cv, 0.5, moveZ=1, ws=1, wd=1, r=1) pmc.move(cv, 0.1, moveY=1, ls=1, wd=1, r=1) jnt_ofs = pmc.duplicate(jnt, n=str(jnt).replace("_JNT", "_jnt_OFS"))[0] jnt_ofs.setAttr("drawStyle", 2) pmc.parent(jnt, jnt_ofs) ctrl.translate >> jnt.translate ctrl.rotate >> jnt.rotate ctrl.scale >> jnt.scale ctrls.append(ctrl) pmc.parent(jnt_ofs, self.parts_grp) pmc.parent(follicle, self.ctrl_input_grp) pmc.select(cl=1) pmc.skinCluster(ctrls_jnt, surface, bm=0, dr=4.0, mi=2, nw=1, sm=0, tsb=1, wd=0) return skn_jnts, surface, follicles, ctrls_jnt, ctrls_fol, ctrls else: pmc.error("faces aren't support yet")