Example #1
0
    def get_head_length(self, jnt_head):
        """
        Resolve a head influence height using raycasts.
        This is in the Rig class to increase performance using the caching mechanism.
        :param jnt_head: The head influence to mesure.
        :return: A float representing the head length. None if unsuccessful.
        """
        ref_tm = jnt_head.getMatrix(worldSpace=True)

        geometries = libHistory.get_affected_shapes(jnt_head)

        # Resolve the top of the head location
        bot = pymel.datatypes.Point(ref_tm.translate)
        # dir = pymel.datatypes.Point(1,0,0) * ref_tm
        # dir = dir.normal()
        # This is strange but not pointing to the world sometime don't work...
        # TODO: FIX ME
        dir = pymel.datatypes.Point(0, 1, 0)

        top = libRigging.ray_cast_farthest(bot, dir, geometries)
        if not top:
            self.warning("Can't resolve head top location using raycasts using {0} {1}!".format(
                bot, dir
            ))
            return None

        return libPymel.distance_between_vectors(bot, top)
Example #2
0
    def get_head_length(self):
        jnt_head = self.get_head_jnt()
        if not jnt_head:
            self.warning("Can't resolve head length!")

        ref_tm = jnt_head.getMatrix(worldSpace=True)

        geometries = libRigging.get_affected_geometries(jnt_head)

        # Resolve the top of the head location
        bot = pymel.datatypes.Point(ref_tm.translate)
        #dir = pymel.datatypes.Point(1,0,0) * ref_tm
        #dir = dir.normal()
        # This is strange but not pointing to the world sometime don't work...
        # TODO: FIX ME
        dir = pymel.datatypes.Point(0,1,0)

        top = libRigging.ray_cast_farthest(bot, dir, geometries)
        if not top:
            self.warning("Can't resolve head top location using raycasts using {0} {1}!".format(
                bot, dir
            ))
            return None

        return libPymel.distance_between_vectors(bot, top)
Example #3
0
    def get_head_length(self):
        jnt_head = self.get_head_jnt()
        if not jnt_head:
            self.warning("Can't resolve head length!")

        ref_tm = jnt_head.getMatrix(worldSpace=True)

        geometries = libRigging.get_affected_geometries(jnt_head)

        # Resolve the top of the head location
        bot = pymel.datatypes.Point(ref_tm.translate)
        #dir = pymel.datatypes.Point(1,0,0) * ref_tm
        #dir = dir.normal()
        # This is strange but not pointing to the world sometime don't work...
        # TODO: FIX ME
        dir = pymel.datatypes.Point(0, 1, 0)

        top = libRigging.ray_cast_farthest(bot, dir, geometries)
        if not top:
            self.warning(
                "Can't resolve head top location using raycasts using {0} {1}!"
                .format(bot, dir))
            return None

        return libPymel.distance_between_vectors(bot, top)
Example #4
0
    def raycast_farthest(self, pos, dir):
        """
        Return the farest point on any of the rig registered geometries using provided position and direction.
        """
        geos = self.get_meshes()
        if not geos:
            return None

        result = libRigging.ray_cast_farthest(pos, dir, geos)
        if not result:
            return None

        return result
Example #5
0
    def raycast_farthest(self, pos, dir):
        """
        Return the farest point on any of the rig registered geometries using provided position and direction.
        """
        geos = self.get_meshes()
        if not geos:
            return None

        result = libRigging.ray_cast_farthest(pos, dir, geos)
        if not result:
            return None

        return result
Example #6
0
    def _get_recommended_pivot_back(self, geometries, tm_ref, tm_ref_dir, pos_toes):
        """
        Determine recommended position using ray-cast from the toes.
        If the ray-cast fail, use the toes position.
        return: The recommended position as a world pymel.datatypes.Vector
        """
        dir = pymel.datatypes.Point(0,0,-1) * tm_ref_dir
        pos = libRigging.ray_cast_farthest(pos_toes, dir, geometries)
        if not pos:
            cmds.warning("Can't automatically solve FootRoll back pivot.")
            pos = pos_toes

        # Ensure we are aligned with the reference matrix.
        pos_relative = pos * tm_ref.inverse()
        pos_relative.x = 0
        pos_relative.y = 0
        pos = pos_relative * tm_ref
        pos.y = 0

        #HACK : Ensure that the point is size 3 and not 4
        return pymel.datatypes.Point(pos.x,pos.y,pos.z)
Example #7
0
    def _get_recommended_pivot_front(self, geometries, tm_ref, tm_ref_dir, pos_toes, pos_tip):
        """
        Determine recommended position using ray-cast from the toes.
        If the ray-cast fail, use the last joint position.
        return: The recommended position as a world pymel.datatypes.Vector
        """
        dir = pymel.datatypes.Point(0, 0, 1) * tm_ref_dir
        pos = libRigging.ray_cast_farthest(pos_toes, dir, geometries)
        if not pos:
            cmds.warning("Can't automatically solve FootRoll front pivot, using last joint as reference.")
            pos = pos_tip
        else:
            # Compare our result with the last joint position and take the longuest.
            pos.z = max(pos.z, pos_tip.z)

        # Ensure we are aligned with the reference matrix.
        pos_relative = pos * tm_ref.inverse()
        pos_relative.x = 0
        pos_relative.y = 0
        pos = pos_relative * tm_ref
        pos.y = 0

        #HACK : Ensure that the point is size 3 and not 4
        return pymel.datatypes.Point(pos.x,pos.y,pos.z)