Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MirrorController.get_opposite_control method Bug #392

Open
thirstydevil opened this issue Feb 27, 2024 · 0 comments
Open

MirrorController.get_opposite_control method Bug #392

thirstydevil opened this issue Feb 27, 2024 · 0 comments

Comments

@thirstydevil
Copy link

thirstydevil commented Feb 27, 2024

The method to replace the side string isn't very safe and produces bugs.

target_name = node.name().replace(side_l, side_r)

For example, input node of "fore_quad_leg_l_fk1" will produce "fore_quad_reg_r_fk1" where the name "leg" has been changed to "reg"

I have a more robust fix at the cost of speed, but it could be cached.

    @staticmethod
    def get_opposite_control_fallback(node):
        import difflib
        mgear.log(f"Using : MirrorController.get_opposite_control_fallback method for node : {node}")

        root = node.longName().split("|")[0]
        # This guard may be overkill but the guide might be in the scene or some straggling shapes
        controls = [n for n in pm.ls(type="transform") if
                    n.longName().startswith(root) and hasattr(n, "side_label")]

        side = node.attr("side_label").get()

        filtered_controls = []
        if side == "L":
            filtered_controls = [n.shortName() for n in controls if n.attr("side_label").get() == "R"]

        elif side == "R":
            filtered_controls = [n.shortName() for n in controls if n.attr("side_label").get() == "L"]

        closest = difflib.get_close_matches(node.shortName(), filtered_controls)
        if closest:
            return pm.PyNode(closest[0])

    @staticmethod
    def get_opposite_control(node):
        side_l = node.attr("L_custom_side_label").get()
        side_r = node.attr("R_custom_side_label").get()
        side = node.attr("side_label").get()

        target_name = None
        if side == "L":
            target_name = node.name().replace(side_l, side_r)
        elif side == "R":
            target_name = node.name().replace(side_r, side_l)

        if target_name and pm.objExists(target_name):
            return pm.PyNode(target_name)
        else:
            return MirrorController.get_opposite_control_fallback(node)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant