示例#1
0
    def perform_connections(self):
        """
        performs the connections between the modules
        :return: <bool> True for success. <bool> False for failure.
        """
        if not self.information:
            return False

        # make relationships by connecting to other nodes in the scene
        if isinstance(self.controller_data, (list, tuple)):
            control_data = self.controller_data[0]
        if isinstance(self.controller_data, dict):
            control_data = self.controller_data

        # we want to deliberately raise an error when the object is not found
        if "constrainTo" in self.information:
            constrain_to = self.information['constrainTo']
            if constrain_to:
                if not object_utils.is_exists(constrain_to):
                    ctrl_obj = control_utils.get_control_name(constrain_to)
                    if object_utils.is_exists(ctrl_obj):
                        object_utils.do_parent_constraint(ctrl_obj, control_data['controller'])
                else:
                    object_utils.do_parent_constraint(constrain_to, control_data['controller'])

        if "parentTo" in self.information:
            parent_to = self.information['parentTo']
            if parent_to:
                if not object_utils.is_exists(parent_to):
                    ctrl_obj = control_utils.get_control_name(parent_to)
                    if object_utils.is_exists(ctrl_obj):
                        object_utils.do_parent(control_data['group_names'][-1], ctrl_obj)
                else:
                    object_utils.do_parent(control_data['group_names'][-1], parent_to)
        return True
示例#2
0
    def replace_guides(self):
        """
        replaces the guide joints with the actual bound joints.
        :return: <tuple> bound joint array.
        """
        if self.if_guides_exist():
            positions = self.get_guide_positions()
            self.finished_joints = ()

            for name, jnt_array, pos_array in zip(self.names,
                                                  self.guide_joints,
                                                  positions):
                # remove the existing guides
                object_utils.remove_node(jnt_array)

                # set the positions gathered from the guide joints
                self.finished_joints += joint_utils.create_joint(
                    name,
                    num_joints=len(pos_array),
                    prefix_name=self.prefix_name,
                    use_position=pos_array,
                    bound_joint=True,
                    as_strings=True),

                # parent the replaced joints
                if len(self.finished_joints) > 1:
                    object_utils.do_parent(self.finished_joints[-1],
                                           self.finished_joints[-2])

            # set the guide joints to zero
            self.guide_joints = []
示例#3
0
    def create_guides(self):
        """
        creates a guide joint object.
        :return: <str> bool.
        """
        self.guide_joints = ()

        # get the positions for the middle joint
        positions = ([0.0, 0.0, 0.0], [2.0, 0.0, -1.0], [4.0, 0.0, 0.0])

        # create the hand joint
        idx = 0
        for name, pos in zip(self.names, positions):
            # create the guide joints
            self.guide_joints += joint_utils.create_joint(
                num_joints=1,
                name=name,
                guide_joint=True,
                prefix_name=self.prefix_name,
                as_strings=True,
                use_position=pos)[0],

            if len(self.guide_joints) > 1:
                # parent the guide joints
                object_utils.do_parent(self.guide_joints[idx],
                                       self.guide_joints[idx - 1])
            idx += 1
        joint_utils.orient_joints(self.guide_joints,
                                  primary_axis=self.forward_axis)
        joint_utils.zero_joint_orient(self.guide_joints[-1])
示例#4
0
    def create_joints(self, positions, suffix="bnd"):
        """
        create bind joints at positions.
        :param positions: <tuple> positions array.
        :param suffix: <str> suffix name.
        :return: <tuple> bind joints
        """
        bind_joints = ()
        # create the arm joint
        idx = 0
        for name, pos in zip(self.names, positions):
            bind_joints += joint_utils.create_joint(
                num_joints=1,
                name=name,
                suffix_name=suffix,
                prefix_name=self.prefix_name,
                as_strings=True,
                use_position=pos)[0],

            if len(bind_joints) > 1:
                # parent the guide joints
                object_utils.do_parent(bind_joints[idx], bind_joints[idx - 1])

            # we must freeze the rotational transformations for the ik handle to work properly.
            joint_utils.freeze_transformations(bind_joints[idx],
                                               rotate=True,
                                               translate=False,
                                               scale=False)
            # if len(positions) - 1 == idx:
            #     joint_utils.zero_joint_orient(bind_joints[-1])
            idx += 1
        return bind_joints
示例#5
0
    def create_guides(self):
        """
        creates a guide joint object.
        :return: <str> joint object name.
        """
        self.guide_joints = ()

        # get the positions for the middle joint
        hand_position = joint_utils.get_joint_positions(self.number_of_joints)
        mid_positions = joint_utils.get_joint_positions(self.number_of_joints, z=1.0)
        indx_positions = joint_utils.get_joint_positions(self.number_of_joints, x=1.0, z=1.0)
        thumb_positions = joint_utils.get_joint_positions(self.number_of_joints, x=2.0, z=1.0)
        ring_positions = joint_utils.get_joint_positions(self.number_of_joints, x=-1.0, z=1.0)
        pinky_positions = joint_utils.get_joint_positions(self.number_of_joints, x=-2.0, z=1.0)

        positions = (hand_position, mid_positions, indx_positions, thumb_positions, ring_positions, pinky_positions)

        # create the hand joint
        for name, jnt_num, pos in zip(self.names, self.joints_num, positions):
            self.guide_joints += joint_utils.create_joint(
                num_joints=jnt_num, name=name, guide_joint=True,
                prefix_name=self.prefix_name, as_strings=True, use_position=pos),

        for idx in xrange(1, len(self.guide_joints)):
            object_utils.do_parent(self.guide_joints[idx][0], self.guide_joints[0][0])
示例#6
0
    def create_controllers(self):
        """
        creates a controller object over the joint object.
        :return: <str> group name.
        """
        ctrl_data = ()
        for name, obj_array in zip(self.names, self.finished_joints):
            data = control_utils.create_controllers_with_standard_constraints(
                name, objects_array=obj_array, shape_name=self.control_shape)

            if "_" not in name:
                self.controller_data = data

            # parent everything else to the hand controller
            if name == self.name:
                par_obj = data[0]["controller"]
            else:
                object_utils.do_parent(data[0]["group_names"][0], par_obj)

            # perform the FK parenting
            self.perform_parenting(data)

            # return data
            ctrl_data += data,
        return ctrl_data
示例#7
0
 def perform_parenting(self):
     """
     now parent the groups to their controllers.
     :return: <bool> True for success. <bool> False for failure.
     """
     for structure in self.parent_structure:
         object_utils.do_parent(structure[1], structure[0])
     return True
示例#8
0
 def perform_parenting(self, controller_data):
     """
     now parent the groups to their controllers.
     :return: <bool> True for success. <bool> False for failure.
     """
     max_len = len(controller_data) - 1
     for idx in xrange(max_len):
         if idx + 1 <= max_len:
             c_data = controller_data[max_len - idx]
             next_data = controller_data[(max_len - idx) - 1]
             object_utils.do_parent(c_data["group_names"][0], next_data["controller"])
     return True
示例#9
0
 def perform_parenting(self):
     """
     now parent the groups to their controllers.
     :return: <bool> True for success. <bool> False for failure.
     """
     max_len = len(self.controller_data) - 1
     for idx in xrange(max_len):
         # data = {'controller': u'FkChain_0_0_ctrl', 'group_names': ('FkChain_0_0_ctrl_grp', 'FkChain_0_0_ctrl_cnst')
         if idx + 1 <= max_len:
             c_data = self.controller_data[max_len - idx]
             next_data = self.controller_data[(max_len - idx) - 1]
             object_utils.do_parent(c_data["group_names"][0],
                                    next_data["controller"])
     return True
示例#10
0
    def create_guides(self):
        """
        creates a guide joint object.
        :return: <str> joint object name.
        """
        self.guide_joints = ()

        # get the positions for the middle joint
        positions = ([0.0, 1.0, 0.0], [0.0, 0.0, 2.0], [0.0, 0.0, 3.0])

        # create the hand joint
        for name, pos in zip(self.names, positions):
            self.guide_joints += joint_utils.create_joint(
                num_joints=1,
                name=name,
                guide_joint=True,
                prefix_name=self.prefix_name,
                as_strings=True,
                use_position=pos),

        for idx in xrange(1, len(self.guide_joints)):
            object_utils.do_parent(self.guide_joints[idx],
                                   self.guide_joints[idx - 1])
示例#11
0
    def create_arm_system(self, bind_joints, fk_joints, ik_joints):
        """
        creates the ik fk blending system.
        :param bind_joints: <tuple> bind joints array.
        :param fk_joints: <tuple> fk joints array.
        :param ik_joints: <tuple> ik joints array.
        :return: <dict> controller date information.
        """
        controller_data = {}

        # creates the ik system for the ik joints
        # print ik_joints
        ik_handle = joint_utils.create_ik_handle(ik_joints,
                                                 name=self.name + '_ik')
        self.built_groups.append(ik_handle[0])

        controller_data[
            'pole_vector_ctrl'] = self.create_pole_vector_controller(
                ik_joints, ik_handle[0])

        # create the controller to manage the ik_fk switching
        ik_fk_ctrl = control_utils.create_control(shape_name='locator',
                                                  name=self.name + '_ikfk')
        ik_fk_ctrl_attr = object_utils.attr_add_float(ik_fk_ctrl['controller'],
                                                      'ikfk',
                                                      min_value=0.0,
                                                      max_value=1.0)
        transform_utils.match_position_transform(
            self.get_control_top_group(ik_fk_ctrl), ik_joints[-1])

        blend_node = object_utils.create_node(node_type='blendColors',
                                              node_name=self.name + "_blend")
        self.built_groups.append(blend_node)
        object_utils.do_connections(ik_fk_ctrl_attr, blend_node + '.blender')
        object_utils.do_set_attr(blend_node + '.color2R', 0.0)
        object_utils.do_set_attr(blend_node + '.color1R', 1.0)
        object_utils.do_set_attr(blend_node + '.color1G', 0.0)
        object_utils.do_set_attr(blend_node + '.color2G', 1.0)
        controller_data["ikfk_controller"] = ik_fk_ctrl

        # creates the parent constraints and setup the switching system
        for bnd_jnt, fk_jnt, ik_jnt in zip(bind_joints, fk_joints, ik_joints):
            # connect the blend color controller to the constraint group
            parent_cnst = object_utils.do_parent_constraint((ik_jnt, fk_jnt),
                                                            bnd_jnt)
            attrs = self.get_ikfk_attrs(parent_cnst)
            status = object_utils.do_connections(blend_node + '.outputR',
                                                 attrs["ik"])
            if not status:
                raise RuntimeError(
                    "[Arm] :: Connection failure: {}.".format(blend_node))
            status = object_utils.do_connections(blend_node + '.outputG',
                                                 attrs["fk"])
            if not status:
                raise RuntimeError(
                    "[Arm] :: Connection failure: {}.".format(blend_node))

        # constrain the control node, the ik and fk joints are stored as the last ones in list
        control_cnst = object_utils.do_parent_constraint(
            (ik_jnt, fk_jnt),
            ik_fk_ctrl["group_names"][0],
            maintain_offset=False)
        attrs = self.get_ikfk_attrs(control_cnst)
        status = object_utils.do_connections(blend_node + '.outputR',
                                             attrs["ik"])
        if not status:
            raise RuntimeError(
                "[Arm] :: Connection failure: {}.".format(blend_node))
        status = object_utils.do_connections(blend_node + '.outputG',
                                             attrs["fk"])
        if not status:
            raise RuntimeError(
                "[Arm] :: Connection failure: {}.".format(blend_node))

        # create the controllers for the Ik system
        wrist_ik_ctrl = control_utils.create_control(shape_name='sphere',
                                                     name=self.name +
                                                     '_wrist_ik')
        transform_utils.match_matrix_transform(
            self.get_control_top_group(wrist_ik_ctrl), ik_joints[-1])
        object_utils.do_point_constraint(wrist_ik_ctrl['controller'],
                                         ik_handle[0])
        controller_data["ik_wrist_controller"] = wrist_ik_ctrl

        upper_ik_ctrl = control_utils.create_control(shape_name='sphere',
                                                     name=self.name +
                                                     '_upper_ik')
        transform_utils.match_matrix_transform(
            self.get_control_top_group(upper_ik_ctrl), ik_joints[0])
        object_utils.do_point_constraint(upper_ik_ctrl['controller'],
                                         ik_joints[0])
        controller_data["ik_upper_controller"] = upper_ik_ctrl

        # create the controllers for the Fk system
        controller_data["fk_controller"] = self.create_controllers(fk_joints)

        # organize the control systems
        control_grp = object_utils.create_node('transform',
                                               node_name=self.name +
                                               '_controllers_grp')
        for k_name in controller_data:
            top_grp = self.get_control_top_group(controller_data[k_name])
            object_utils.do_parent(top_grp, control_grp)

        # organize the systems nodes
        systems_grp = object_utils.create_node('transform',
                                               node_name=self.name +
                                               '_systems_grp')
        object_utils.do_parent(ik_handle[0], systems_grp)
        object_utils.do_parent(bind_joints[0], systems_grp)
        object_utils.do_parent(fk_joints[0], systems_grp)
        object_utils.do_parent(ik_joints[0], systems_grp)

        # now create a master controller for this arm system
        master_ctrl = control_utils.create_control(shape_name='locator',
                                                   name=self.name + '_plug')
        object_utils.do_parent_constraint(master_ctrl["controller"],
                                          systems_grp,
                                          maintain_offset=True)
        object_utils.do_scale_constraint(master_ctrl["controller"],
                                         systems_grp,
                                         maintain_offset=True)
        object_utils.do_parent_constraint(master_ctrl["controller"],
                                          control_grp,
                                          maintain_offset=True)
        object_utils.do_scale_constraint(master_ctrl["controller"],
                                         control_grp,
                                         maintain_offset=True)

        # now make the arm stretchy
        self.make_arm_stretchy()

        # store the master controller as part of the main controller data
        self.controller_data = master_ctrl
        self.built_groups.append(controller_data)
        return controller_data