Exemplo n.º 1
0
    def process_component_parenting_data(self, component_parenting_data=None):
        """
        Process the correct parenting data based on the rig and operator meta
        data. It will store the data in the "self.parenting_data_dic" variable.

        Args:
            component_parenting_data(List): List filled with dict to pass.

        Example:
            >>>import build
            >>>build_instance = build.MainBuild()
            >>>build_instance.process_component_parenting_data()
            [{'root_meta_nd_uuid':
            u'cc4064e3-f3b0-4512-8e44-b914b3df3c1e-rig_container',
            'rig_components_uuid':
            [u'f0bc993e-38e5-4210-816c-3dac633b6ee0-comp_container']},
            {'root_meta_nd_uuid':
            u'd16fe8f1-0d50-4a20-9b61-79a2f2f817bd-rig_container',
            'rig_components_uuid': [
            u'62c00a43-269b-4b19-b275-2bc7d9b28162-comp_container']}]

        """
        logger.log(
            level="info",
            message="### Processing component parenting data dictionary. "
            "###",
            logger=_LOGGER,
        )
        result = []
        self.parenting_data_dic = component_parenting_data
        if not component_parenting_data:
            for op_meta_data in self.operators_meta_data:
                data_dic = {}
                for rig_meta_data in self.rig_meta_data:
                    if op_meta_data.get(constants.META_DATA_DIC_ITEM_0
                                        ) == rig_meta_data.get(
                                            constants.META_DATA_DIC_ITEM_0):
                        rig_components_list = []
                        for rig_components in op_meta_data.get(
                                constants.META_DATA_DIC_ITEM_1):
                            comp_container_uuid = strings.search_and_replace(
                                rig_components.get(constants.UUID_ATTR_NAME),
                                constants.MAIN_OP_ND_UUID_SUFFIX,
                                constants.COMP_CONTAINER_UUID_SUFFIX,
                            )
                            rig_components_list.append(comp_container_uuid)
                        data_dic[
                            constants.
                            RIG_CONTAINER_UUID_DIC_KEY] = strings.search_and_replace(
                                rig_meta_data.get(
                                    constants.META_DATA_DIC_ITEM_1).get(
                                        constants.UUID_ATTR_NAME),
                                constants.OP_ROOT_ND_UUID_SUFFIX,
                                constants.RIG_CONTAINER_UUID_SUFFIX,
                            )
                        data_dic[
                            constants.
                            COMP_CONTAINER_UUID_DIC_KEY] = rig_components_list
                result.append(data_dic)
            self.parenting_data_dic = result
Exemplo n.º 2
0
 def build_component_logic(self):
     """
     Build Component logic. It is derivative method from parent class.
     """
     # Name reformatting.
     control_name = constants.DEFAULT_CONTROL_NAME_PATTERN
     control_name = strings.search_and_replace(
         control_name,
         "M_",
         "{}_".format(
             self.operator_meta_data.get(constants.META_MAIN_COMP_SIDE)),
     )
     control_name = strings.search_and_replace(
         control_name,
         "name",
         self.operator_meta_data.get(constants.META_MAIN_COMP_NAME),
     )
     control_name = strings.search_and_replace(
         control_name,
         "index",
         str(self.operator_meta_data.get(constants.META_MAIN_COMP_INDEX)),
     )
     # Create offset grp.
     offset_grp = pmc.createNode("transform",
                                 n="{}_offset_GRP".format(control_name))
     # Find correct control shape based on meta data.
     for index, shape_instance in enumerate(self.CONTROL_SHAPES):
         if index is self.operator_meta_data["control_shape"]:
             curve_instance = shape_instance.get("instance")
     # Create control curve and match it with main_op_nd.
     match_matrix = self.operator_meta_data.get(
         constants.META_MAIN_OP_ND_WS_MATRIX_STR)
     scale_normalized_matrix = mayautils.matrix_normalize_scale(
         match_matrix)
     curve = curve_instance.create_curve(
         name=control_name,
         match=scale_normalized_matrix,
         scale=match_matrix.scale,
     )
     # At control to offset group.
     offset_grp.addChild(curve[0])
     self.controls.append(curve[1])
     self.component_rig_list.append(offset_grp)
     self.input_matrix_offset_grp.append(offset_grp)
     self.output_matrix_nd_list.append(curve[1])
     self.bnd_output_matrix.append(curve[1])
     logger.log(
         level="info",
         message="Component logic created "
         "for: {} Component".format(
             self.operator_meta_data[constants.META_MAIN_COMP_NAME]),
         logger=_LOGGER,
     )
Exemplo n.º 3
0
    def get_component_container_from_main_op_nd_uuid(self, main_op_uuid):
        """
        Gives back the component_container node form main_op_nd_uuid.

        Args:
            main_op_uuid(str): The main op nd uuid.

        Returns:
            pmc.PyNode() if successful. False if not.

        """
        # reformat the main_op_nd_uuid to comp_container_uuid
        comp_container_uuid = strings.search_and_replace(
            main_op_uuid,
            constants.MAIN_OP_ND_UUID_SUFFIX,
            constants.COMP_CONTAINER_UUID_SUFFIX,
        )
        # Get the component container from reformatted uuid.
        comp_container = self.get_container_node_from_uuid(comp_container_uuid)
        if not comp_container:
            logger.log(
                level="error",
                message="Component container "
                "with {} uuid "
                "not exist.".format(comp_container_uuid),
            )
            return False
        return comp_container
Exemplo n.º 4
0
 def create_component_container(self):
     """
     Init rig component container its contents..
     """
     self.component_root = CompContainer(
         self.operator_meta_data.get(constants.META_MAIN_COMP_NAME),
         self.operator_meta_data.get(constants.META_MAIN_COMP_SIDE),
         self.operator_meta_data.get(constants.META_MAIN_COMP_INDEX),
     )
     self.component_root.create_comp_container()
     # Refactor Main op uuid to comp uuid
     uuid_ = self.operator_meta_data.get(constants.UUID_ATTR_NAME)
     uuid_ = strings.search_and_replace(
         uuid_,
         constants.MAIN_OP_ND_UUID_SUFFIX,
         constants.COMP_CONTAINER_UUID_SUFFIX,
     )
     self.component_root.set_uuid(uuid_)
     logger.log(
         level="info",
         message="Component hierarchy setted up "
         "for: {} Component".format(
             self.operator_meta_data[constants.META_MAIN_COMP_NAME]
         ),
         logger=_LOGGER,
     )
Exemplo n.º 5
0
 def connect_components(self):
     """
     Will connect all input and outputs of each component.
     """
     if not self.operators_meta_data:
         logger.log(level="error",
                    message="No operators meta data "
                    "accessible")
         return False
     logger.log(
         level="info",
         message="### Connect component inputs and outputs. "
         "###",
         logger=_LOGGER,
     )
     # loop trough the operators_meta_data.
     for dic in self.operators_meta_data:
         # get the meta data form dic.
         meta_data = dic.get(constants.META_DATA_DIC_ITEM_1)
         for data in meta_data:
             # try to get the parent meta data node.
             parent_meta_nd = data.get(constants.META_MAIN_PARENT_ND)
             # if parent meta data node exist go further.
             if parent_meta_nd:
                 # check if the parent_meta_nd is a meta node.
                 # If  not i guess it is already JoMRS uuid string.
                 if isinstance(parent_meta_nd, meta.MainOpMetaNode):
                     # get the parent meta uuid data.
                     parent_meta_nd_ui = parent_meta_nd.get_uuid()
                 else:
                     # guess the instance is JoMRS uuid string.
                     parent_meta_nd_ui = parent_meta_nd
                 # refactor the parent meta nd uuid to component meta nd
                 # uuid.
                 parent_component_container_uuid = strings.search_and_replace(
                     parent_meta_nd_ui,
                     constants.MAIN_OP_ND_UUID_SUFFIX,
                     constants.COMP_CONTAINER_UUID_SUFFIX,
                 )
                 # get the parent component container nd based on the
                 # refactored parent meta nd uuid.
                 parent_component_container_nd = self.get_container_node_from_uuid(
                     parent_component_container_uuid)
                 # refactor the child meta nd uuid to component meta nd
                 # uuid.
                 child_component_container_uuid = strings.search_and_replace(
                     data.get(constants.UUID_ATTR_NAME),
                     constants.MAIN_OP_ND_UUID_SUFFIX,
                     constants.COMP_CONTAINER_UUID_SUFFIX,
                 )
                 # get the child component container nd based on the
                 # refactored child meta nd uuid.
                 child_component_container_nd = self.get_container_node_from_uuid(
                     child_component_container_uuid)
                 # parent component instance to get output node.
                 parent_component_instance = components.main.CompContainer(
                     component_container=parent_component_container_nd)
                 # get container content to set container content dic.
                 parent_component_instance.get_container_content()
                 # get the output node from container dic.
                 parent_component_container_nd_output = parent_component_instance.container_content.get(
                     "output")
                 # child component instance to get output node.
                 child_component_container_instance = components.main.CompContainer(
                     component_container=child_component_container_nd)
                 # get container content to set container content dic.
                 child_component_container_instance.get_container_content()
                 # get the input node from container dic.
                 child_component_container_nd_input = child_component_container_instance.container_content.get(
                     "input")
                 # connect the output and input node.
                 parent_component_container_nd_output.attr("{}[{}]".format(
                     constants.OUTPUT_WS_PORT_NAME,
                     data.get(constants.PARENT_OUTPUT_WS_PORT_INDEX),
                 )).connect(
                     child_component_container_nd_input.attr("{}[0]".format(
                         constants.INPUT_WS_PORT_NAME)))
Exemplo n.º 6
0
 def build_component_logic(self):
     """
     Build Component logic. It is derivative method from parent class.
     """
     # Name reformatting.
     component_side = self.operator_meta_data.get(
         constants.META_MAIN_COMP_SIDE)
     control_name = constants.DEFAULT_CONTROL_NAME_PATTERN
     control_name = strings.search_and_replace(control_name, "M_",
                                               "{}_".format(component_side))
     control_name = strings.search_and_replace(
         control_name,
         "name",
         self.operator_meta_data.get(constants.META_MAIN_COMP_NAME),
     )
     control_name = strings.search_and_replace(
         control_name,
         "index",
         str(self.operator_meta_data.get(constants.META_MAIN_COMP_INDEX)),
     )
     # Find correct control shape based on meta data.
     for index, shape_instance in enumerate(self.CONTROL_SHAPES):
         if index is self.operator_meta_data.get(
                 self.CONTROL_SHAPE_ATTR_NAME):
             curve_instance = shape_instance.get("instance")
     # Get match matrix from meta data.
     orig_match_matrix = self.operator_meta_data.get(
         constants.META_MAIN_OP_ND_WS_MATRIX_STR)
     # Get world space bool in meta data.
     worldspace_orientation = self.operator_meta_data.get(
         self.WS_ORIENTATION_ATTR_NAME)
     # Get bnd jnt creation bool in meta data.
     bnd_jnt_creation = self.operator_meta_data.get(self.BND_JNT_ATTR_NAME)
     # normalize the match matrix in scale.
     tweaked_matrix = mayautils.matrix_normalize_scale(orig_match_matrix)
     # Reset the matrix in rotation.
     if worldspace_orientation:
         tweaked_matrix = mayautils.matrix_reset_rotation(tweaked_matrix)
     # Get control curve color from rig meta data.
     control_curve_color = self.get_control_curve_color_from_rig_meta_data(
         component_side, "control")
     # Create the control curve.
     control_curve = curve_instance.create_curve(
         name=control_name,
         match=tweaked_matrix,
         scale=orig_match_matrix.scale,
         color_index=control_curve_color,
         lock_visibility=True,
     )
     # Create offset grp.
     offset_grp = pmc.createNode("transform",
                                 n="{}_offset_GRP".format(control_name))
     # At control to offset group.
     offset_grp.addChild(control_curve[0])
     self.controls.append(control_curve[1])
     self.component_rig_list.append(offset_grp)
     self.input_matrix_offset_grp.append(offset_grp)
     self.output_matrix_nd_list.append(control_curve[1])
     # lock and hide transform attributes if it is defined in the meta data.
     for lock_attr in self.LOCK_TRANSFORMATION_ATTRIBUTES:
         if self.operator_meta_data.get(lock_attr):
             attribute_string = lock_attr.split("_")[1]
             attributes.lock_and_hide_attributes(
                 control_curve[1], attributes=attribute_string)
     if bnd_jnt_creation:
         self.bnd_output_matrix.append(control_curve[1])
     logger.log(
         level="info",
         message="Component logic created "
         "for: {} Component".format(
             self.operator_meta_data[constants.META_MAIN_COMP_NAME]),
         logger=_LOGGER,
     )
Exemplo n.º 7
0
 def create_BND_joints(self):
     """
     Create the component bind joints.
     """
     output_nd = self.component_root.container_content.get("output")
     connected_bnd_outputs = output_nd.attr(
         constants.BND_OUTPUT_WS_PORT_NAME
     ).get()
     if not connected_bnd_outputs:
         return False
     main_op_ws_scale = self.operator_meta_data.get(
         constants.META_MAIN_OP_ND_WS_MATRIX_STR
     ).scale
     # calculate the scale average for the correct joint radius.
     scale_x, scale_y, scale_z = main_op_ws_scale
     main_op_ws_scale_avg = (scale_x + scale_y + scale_z) / 3
     temp = []
     for count in range(len(connected_bnd_outputs)):
         # Bind joint name creation.
         bnd_joint_name = strings.search_and_replace(
             constants.BND_JNT_DEFAULT_NAME,
             "side",
             self.operator_meta_data.get(constants.META_MAIN_COMP_SIDE),
         )
         bnd_joint_name = strings.search_and_replace(
             bnd_joint_name,
             "name",
             self.operator_meta_data.get(constants.META_MAIN_COMP_NAME),
         )
         bnd_joint_name = strings.search_and_replace(
             bnd_joint_name,
             "index",
             str(
                 self.operator_meta_data.get(constants.META_MAIN_COMP_INDEX)
             ),
         )
         bnd_joint_name = strings.search_and_replace(
             bnd_joint_name, "count", str(count)
         )
         bnd_joint = mayautils.create_joint(bnd_joint_name, typ="BND")
         bnd_joint.radius.set(main_op_ws_scale_avg)
         mul_ma_nd = mayautils.create_matrix_constraint(
             source=bnd_joint,
             target=output_nd,
             target_plug="{}[{}]".format(
                 constants.BND_OUTPUT_WS_PORT_NAME, str(count)
             ),
         )
         # get the matrix constraint nodes and add them to the component
         # container.
         offset_matrix_nd = mul_ma_nd.matrixIn[0].connections()
         decomp_nd = mul_ma_nd.matrixSum.connections()
         for node in [offset_matrix_nd, decomp_nd, mul_ma_nd]:
             self.component_root.container.addNode(node)
         # The part below will check if the component is a mirrored
         # component. If it will get the negative scale value in the
         # bnd joints and make it positive! This is important for a correct
         # rig hierarchy without buffer transforms.
         negate_axe = []
         if bnd_joint.scaleX.get() < 0:
             negate_axe.append("X")
         elif bnd_joint.scaleY.get() < 0:
             negate_axe.append("Y")
         elif bnd_joint.scaleZ.get() < 0:
             negate_axe.append("Z")
         if negate_axe:
             for axe in negate_axe:
                 mult_nd_name = strings.search_and_replace(
                     decomp_nd.name(),
                     "_DEMAND",
                     "_scale_{}_MULDOLINND".format(axe),
                 )
                 mult_nd = pmc.createNode("multDoubleLinear", n=mult_nd_name)
                 mult_nd.input2.set(-1)
                 decomp_nd.attr("outputScale{}".format(axe)).connect(
                     mult_nd.input1
                 )
                 mult_nd.output.connect(
                     bnd_joint.attr(
                         bnd_joint.attr("scale{}".format(axe)), force=True
                     )
                 )
         temp.append(bnd_joint)
     # If it is more then one joint it will create a hierarchy.
     if len(temp) > 1:
         mayautils.create_hierarchy(temp, True)
     # set joint orient to zero because this would mess up the matrix
     # constraint setup.
     for jnt in temp:
         jnt.jointOrient.set(0, 0, 0)
     self.component_root.set_bnd_root_nd(temp[-1])
     # Step feedback
     logger.log(
         level="info",
         message="BND joint hierarchy build "
         "for: {} Component".format(
             self.operator_meta_data[constants.META_MAIN_COMP_NAME]
         ),
         logger=_LOGGER,
     )