コード例 #1
0
ファイル: __init__.py プロジェクト: renaudll/omtk
def build_selected(sel=None):
    with with_preserve_selection():
        rig, modules = _get_modules_from_selection()
        if not rig or not modules:
            return

        is_module_unbuilt = lambda x: not x.is_built()
        modules = filter(is_module_unbuilt, modules)

        def can_build_module(module):
            try:
                module.validate()
                return True
            except Exception, e:
                pymel.warning("Can't build {0}: {1}".format(module.name, str(e)))
                return False

        modules = filter(can_build_module, modules)

        if not modules:
            return

        # Build selected modules
        rig.pre_build()
        for module in modules:
            module.build()
            rig.post_build_module(module)

        # Re-export network
        if hasattr(rig, '_network'):
            pymel.delete(rig._network)
        libSerialization.export_network(rig)
コード例 #2
0
    def test_rig_squeeze_facial_new(self):
        from omtk.modules.rigHead import Head
        from omtk.modules.rigFaceJaw import FaceJaw
        from omtk.modules.rigFaceBrow import FaceBrow
        from omtk.modules.rigFaceSquint import FaceSquint
        from omtk.modules.rigFaceLips import FaceLips
        from omtk.modules.rigFaceEyes import FaceEyes
        from omtk.modules.rigFaceLids import FaceLids
        from omtk.modules.rigFaceNose import FaceNose

        pymel.delete(pymel.ls(type='network'))
        rig = omtk.create()
        rig.add_module(Head([pymel.PyNode('Head_Jnt')]))
        rig.add_module(FaceJaw([pymel.PyNode('Jaw_Jnt')]))
        rig.add_module(FaceBrow(pymel.ls('*_Brow*_Jnt', type='joint')))
        rig.add_module(FaceSquint(pymel.ls('*_Squint*_Jnt', type='joint')))
        rig.add_module(
            FaceLips(
                pymel.ls('*_Lip*_Jnt', type='joint') +
                pymel.ls('*_Mouth*_Jnt', type='joint')))
        rig.add_module(
            FaceEyes([pymel.PyNode('L_Eye_Jnt'),
                      pymel.PyNode('R_Eye_Jnt')]))
        rig.add_module(FaceLids(pymel.ls('*_Lid*_Jnt', type='joint')))
        rig.add_module(FaceNose(pymel.ls('*Nose*_Jnt', type='joint')))
        rig.build(strict=True)
        libSerialization.export_network(rig)
コード例 #3
0
def build_selected(sel=None):
    with with_preserve_selection():
        rig, modules = _get_modules_from_selection()
        if not rig or not modules:
            return

        is_module_unbuilt = lambda x: not x.is_built()
        modules = filter(is_module_unbuilt, modules)

        def can_build_module(module):
            try:
                module.validate()
                return True
            except Exception, e:
                pymel.warning("Can't build {0}: {1}".format(
                    module.name, str(e)))
                return False

        modules = filter(can_build_module, modules)

        if not modules:
            return

        # Build selected modules
        rig.pre_build()
        for module in modules:
            module.build()
            rig.post_build_module(module)

        # Re-export network
        if hasattr(rig, '_network'):
            pymel.delete(rig._network)
        libSerialization.export_network(rig)
コード例 #4
0
ファイル: __init__.py プロジェクト: goujin/omtk
def build_all():
    """
    Build all the rigs embedded in the current maya scene.
    """
    networks = libSerialization.getNetworksByClass('Rig')
    for network in networks:
        rigroot = libSerialization.import_network(network)
        if rigroot.build():
            pymel.delete(network)
            libSerialization.export_network(rigroot)
コード例 #5
0
    def _create_simple_arm_build_and_export(self):
        jnt_1 = pymel.joint(position=[0, 0, 0])
        jnt_2 = pymel.joint(position=[10, 0, 10])
        jnt_3 = pymel.joint(position=[20, 0, 0])

        rig = omtk.create()
        module = Arm([jnt_1, jnt_2, jnt_3])
        rig.add_module(module)
        rig.build()
        libSerialization.export_network(rig)

        return rig, module
コード例 #6
0
    def _create_simple_arm_build_and_export(self):
        jnt_1 = pymel.joint(position=[0,0,0])
        jnt_2 = pymel.joint(position=[10,0,10])
        jnt_3 = pymel.joint(position=[20,0,0])

        rig = omtk.create()
        module = Arm([jnt_1, jnt_2, jnt_3])
        rig.add_module(module)
        rig.build()
        libSerialization.export_network(rig)

        return rig, module
コード例 #7
0
ファイル: __init__.py プロジェクト: renaudll/omtk
def build_all(strict=False):
    """
    Build all the rigs embedded in the current maya scene.
    """
    networks = libSerialization.get_networks_from_class('Rig')
    for network in networks:
        rigroot = libSerialization.import_network(network)
        if not rigroot:
            log.warning("Error importing rig network {0}".format(network))
            continue
        if rigroot.build(strict=strict):
            pymel.delete(network)
            libSerialization.export_network(rigroot)
コード例 #8
0
def build_all(strict=False):
    """
    Build all the rigs embedded in the current maya scene.
    """
    networks = libSerialization.get_networks_from_class('Rig')
    for network in networks:
        rigroot = libSerialization.import_network(network)
        if not rigroot:
            log.warning("Error importing rig network {0}".format(network))
            continue
        if rigroot.build(strict=strict):
            pymel.delete(network)
            libSerialization.export_network(rigroot)
コード例 #9
0
ファイル: uiLogic.py プロジェクト: goujin/omtk
 def _update_network(self, module, item=None):
     if hasattr(module, "_network"):
         pymel.delete(module._network)
     new_network = libSerialization.export_network(module) #TODO : Automatic update
     #If needed, update the network item net property to match the new exported network
     if item:
         item.net = new_network
コード例 #10
0
    def test_export_network(self, epsilon=0.00001):
        pynode_a = pymel.createNode('transform')
        pynode_b = pymel.createNode('transform')

        old_instance = A()
        old_instance.ex_int = 42
        old_instance.ex_float = 3.14159
        old_instance.ex_str = 'Hello World'
        old_instance.ex_None = None
        old_instance.ex_list_pynode = [None, pynode_a, None, pynode_b]

        #
        # Ensure consistency when exporting to network
        #
        n = libSerialization.export_network(old_instance)
        network_ex_int = n.ex_int.get()
        network_ex_float = n.ex_float.get()
        network_ex_str = n.ex_str.get()
        self.assertTrue(network_ex_int == old_instance.ex_int)
        self.assertTrue(
            abs(network_ex_float - old_instance.ex_float) < epsilon)
        self.assertTrue(network_ex_str == old_instance.ex_str)

        # Note: libSerialization will NEVER export a None value since the type cannot be resolved.
        self.assertTrue(not n.hasAttr('ex_None'))

        #
        # Ensure consistency when importing from network
        #
        new_instance = libSerialization.import_network(n)
        self.assertTrue(network_ex_int == new_instance.ex_int)
        self.assertTrue(
            abs(network_ex_float - new_instance.ex_float) < epsilon)
        self.assertTrue(network_ex_str == new_instance.ex_str)
コード例 #11
0
    def test_export_network(self, epsilon=0.00001):
        pynode_a = pymel.createNode('transform')
        pynode_b = pymel.createNode('transform')

        old_instance = A()
        old_instance.ex_int = 42
        old_instance.ex_float = 3.14159
        old_instance.ex_str = 'Hello World'
        old_instance.ex_None = None
        old_instance.ex_list_pynode = [None, pynode_a, None, pynode_b]

        #
        # Ensure consistency when exporting to network
        #
        n = libSerialization.export_network(old_instance)
        network_ex_int = n.ex_int.get()
        network_ex_float = n.ex_float.get()
        network_ex_str = n.ex_str.get()
        self.assertTrue(network_ex_int == old_instance.ex_int)
        self.assertTrue(abs(network_ex_float- old_instance.ex_float) < epsilon)
        self.assertTrue(network_ex_str == old_instance.ex_str)

        # Note: libSerialization will NEVER export a None value since the type cannot be resolved.
        self.assertTrue(not n.hasAttr('ex_None'))

        #
        # Ensure consistency when importing from network
        #
        new_instance = libSerialization.import_network(n)
        self.assertTrue(network_ex_int == new_instance.ex_int)
        self.assertTrue(abs(network_ex_float- new_instance.ex_float) < epsilon)
        self.assertTrue(network_ex_str == new_instance.ex_str)
コード例 #12
0
def unbuild_selected(sel=None):
    with with_preserve_selection():
        rig, modules = _get_modules_from_selection()
        if not rig or not modules:
            return

        is_module_built = lambda x: x.is_built()
        modules = filter(is_module_built, modules)

        # Build selected modules
        for module in modules:
            module.unbuild()

        # Re-export network
        if hasattr(rig, '_network'):
            pymel.delete(rig._network)
        libSerialization.export_network(rig)
コード例 #13
0
    def test_cyclic_reference_network(self):
        parent = A()
        child = A()
        parent.children = [child]
        child.parent = parent

        data = libSerialization.export_network(parent)
        self.assertTrue(isinstance(data, pymel.nodetypes.Network))
コード例 #14
0
    def test_cyclic_reference_network(self):
        parent = A()
        child = A()
        parent.children = [child]
        child.parent = parent

        data = libSerialization.export_network(parent)
        self.assertTrue(isinstance(data, pymel.nodetypes.Network))
コード例 #15
0
ファイル: __init__.py プロジェクト: renaudll/omtk
def unbuild_selected(sel=None):
    with with_preserve_selection():
        rig, modules = _get_modules_from_selection()
        if not rig or not modules:
            return

        is_module_built = lambda x: x.is_built()
        modules = filter(is_module_built, modules)

        # Build selected modules
        for module in modules:
            module.unbuild()

        # Re-export network
        if hasattr(rig, '_network'):
            pymel.delete(rig._network)
        libSerialization.export_network(rig)
コード例 #16
0
def _update_network(module, item=None):
    if hasattr(module, "_network"):
        pymel.delete(module._network)
    new_network = libSerialization.export_network(
        module)  # TODO : Automatic update
    # If needed, update the network item net property to match the new exported network
    if item:
        item.net = new_network
    return new_network
コード例 #17
0
ファイル: __init__.py プロジェクト: goujin/omtk
def unbuild_all():
    networks = libSerialization.getNetworksByClass('Rig')
    for network in networks:
        rigroot = libSerialization.import_network(network)
        rigroot.unbuild()
        pymel.delete(network)
        # Write changes to scene
        network = libSerialization.export_network(rigroot)
        pymel.select(network)
コード例 #18
0
ファイル: uiLogic.py プロジェクト: goujin/omtk
    def on_import(self):
        path, _ = QtGui.QFileDialog.getOpenFileName(caption="File Save (.json)", filter="JSON (*.json)")
        if not path:
            return

        new_rigs = libSerialization.import_json_file_maya(path)
        if not new_rigs:
            return

        # Remove previous rigs
        all_rigs = core.find()
        for rig in all_rigs:
            if rig._network.exists():
                pymel.delete(rig._network)

        for rig in filter(None, new_rigs):
            libSerialization.export_network(rig)

        self.on_update()
コード例 #19
0
ファイル: uiLogic.py プロジェクト: goujin/omtk
    def export_networks(self):
        path = '/home/rlessard/Desktop/test.json'

        try:
            pymel.delete(self.root._network)
        except AttributeError:
            pass

        net = libSerialization.export_network(self.root) # Export part and only part
        return net
コード例 #20
0
    def on_import(self):
        path, _ = QtGui.QFileDialog.getOpenFileName(
            caption="File Save (.json)", filter="JSON (*.json)")
        if not path:
            return

        new_rigs = libSerialization.import_json_file_maya(path)
        if not new_rigs:
            return

        # Remove previous rigs
        all_rigs = core.find()
        for rig in all_rigs:
            if rig._network.exists():
                pymel.delete(rig._network)

        for rig in filter(None, new_rigs):
            libSerialization.export_network(rig)

        self.on_update()
コード例 #21
0
def unbuild_all(strict=False):
    networks = libSerialization.get_networks_from_class('Rig')
    for network in networks:
        rigroot = libSerialization.import_network(network)
        if not rigroot:
            log.warning("Error importing rig network {0}".format(network))
            continue
        rigroot.unbuild(strict=strict)
        pymel.delete(network)
        # Write changes to scene
        network = libSerialization.export_network(rigroot)
        pymel.select(network)
コード例 #22
0
ファイル: old.py プロジェクト: goujin/omtk
    def test_RigCtrl(self):
        from classCtrl import BaseCtrl
        import libSerialization
        log.info("test_RigCtrl")
        foo = BaseCtrl()
        foo.build()
        pymel.setKeyframe(foo.node)
        foo.unbuild()

        network = libSerialization.export_network(foo)
        pymel.select(network)
        foo.build()
コード例 #23
0
ファイル: main_window.py プロジェクト: renaudll/omtk
    def export_networks(self, update=True):
        try:
            pymel.delete(self.root._network)
        except AttributeError:
            pass

        net = libSerialization.export_network(self.root)  # Export part and only part

        if update:
            self.update_ui()

        return net
コード例 #24
0
ファイル: __init__.py プロジェクト: renaudll/omtk
def unbuild_all(strict=False):
    networks = libSerialization.get_networks_from_class('Rig')
    for network in networks:
        rigroot = libSerialization.import_network(network)
        if not rigroot:
            log.warning("Error importing rig network {0}".format(network))
            continue
        rigroot.unbuild(strict=strict)
        pymel.delete(network)
        # Write changes to scene
        network = libSerialization.export_network(rigroot)
        pymel.select(network)
コード例 #25
0
    def export_networks(self, update=True):
        try:
            pymel.delete(self.root._network)
        except AttributeError:
            pass

        net = libSerialization.export_network(
            self.root)  # Export part and only part

        if update:
            self.update_ui()

        return net
コード例 #26
0
    def test_self_dependance(self):
        node = A()
        node.self = node

        data = libSerialization.export_network(node)
        self.assertTrue(isinstance(data, pymel.nodetypes.Network))
コード例 #27
0
    def test_self_dependance(self):
        node = A()
        node.self = node

        data = libSerialization.export_network(node)
        self.assertTrue(isinstance(data, pymel.nodetypes.Network))
コード例 #28
0
ファイル: __init__.py プロジェクト: goujin/omtk
def detect(*args, **kwargs):
    """
    Fully automatic routine that create rig elements by analysing the joints structure.
    This is only meant as a quick way to get started and is in no way production ready.
    It is recommended that the 't-pose' or 45 angle 't-pose' is respected on the character before running this routine.
    """
    jnts = pymel.ls(type='joint')

    # Validate the joints hyerarchy since it is mandatory to autorig.
    roots = []
    for jnt in jnts:
        root = jnt.root()
        if root and root not in roots:
            roots.append(root)

    if len(roots) > 1:
        log.error("There are more than one joint root in the scene. Please clean up.")
        return None

    root = next(iter(roots), None)
    if not root:
        log.error("Found no joint root.")
        return None

    # Get the rig heights and radius
    height = 0
    radius = 0
    for jnt in jnts:
        pos = jnt.getTranslation(space='world')

        pos_x = pos.x
        h = pos.y
        pos_z = pos.z

        r = pow(pow(pos_x, 2) + pow(pos_z, 2), 0.5)

        if h > height:
            height = h

        if r > radius:
            radius = r

    MINIMUM_HEIGHT=0.01
    if height < MINIMUM_HEIGHT:
        log.error("Skeletton height is too small. Expected more than {0}".format(MINIMUM_HEIGHT))
        return None

    MINIMUM_RADIUS = 0.01
    if radius < MINIMUM_RADIUS:
        log.error("Skeletton radius is too small. Expected more than {0}".format(MINIMUM_RADIUS))
        return None

    #
    # Configure Rig
    #
    rig = create()

    def get_arms(jnts):
        chains = []
        for jnt in jnts:
            arm_jnts = get_arm(jnt)
            if arm_jnts:
                chains.append(arm_jnts)
        return chains

    # Detect hands?
    def get_arm(jnt):
        children = jnt.getChildren()

        # Hand have a minimum of three fingers or not fingers at all
        # todo: More robust!
        if len(children) < 2 and len(children) != 0:
            return False

        # At least two parents (upperarm and forearm)
        forearm = jnt.getParent()
        upperarm = forearm.getParent() if isinstance(forearm, pymel.PyNode) else None
        if not upperarm or not forearm:
            return False

        # Arms don't point upward, don't confuse ourself with the spine
        upperarm_dir = get_direction(upperarm, forearm)
        MAX_DIRECTION_Y = 0.75
        if abs(upperarm_dir.y) > MAX_DIRECTION_Y:
            return False

        arm_jnts = [upperarm, forearm, jnt]
        log.debug("Found Arm using {0}".format(arm_jnts))
        return arm_jnts

    def get_legs(jnts):
        chains = []
        for jnt in jnts:
            leg_jnts = get_leg(jnt)
            if leg_jnts:
                chains.append(leg_jnts)
        return chains

    def get_direction(jnt_inn, jnt_out):
        val = jnt_out.getTranslation(space='world') - jnt_inn.getTranslation(space='world')
        val.normalize()
        return val

    def get_leg(jnt):
        # The tip of the leg never have childrens
        if len(jnt.getChildren()) > 0:
            return False

        # A leg have 5 joints from with the first two point to the ground
        parents = []
        parent = jnt
        while parent:
            parent = parent.getParent()
            parents.append(parent)

        if len(parents) < 5:
            return False

        thigh = parents[3]
        calf = parents[2]
        foot = parents[1]
        toe = parents[0]

        # Validate thigh direction
        DIR_MINIMUM = -0.5
        thigh_dir = get_direction(thigh, calf)
        if thigh_dir.y >= DIR_MINIMUM:
            return False

        # Validate calf direction
        calf_dir = get_direction(calf, foot)
        if calf_dir.y >= DIR_MINIMUM:
            return False

        #print jnt, parents[3], parents[2],
        leg_jnts = [thigh, calf, foot, toe, jnt]
        log.debug("Found Leg using {0}".format(leg_jnts))
        return leg_jnts

    #def get_spines(jnts):
    #    chains = []
    #    for jnt in jnts:
    #        spine_jnts = get_spine(jnt)
    #        if spine_jnts:
    #            chains.append(spine_jnts)
    #    return chains

    log.debug("Detected rig layout:")
    log.debug("\tHeight: {0}".format(height))
    log.debug("\tRadius: {0}".format(radius))

    from omtk.modules.rigTwistbone import Twistbone
    from omtk.modules.rigLeg import Leg
    from omtk.modules.rigArm import Arm

    # Detect legs
    legs_jnts = get_legs(jnts)
    for leg_jnts in legs_jnts:
        for leg_jnt in leg_jnts:
            jnts.remove(leg_jnt)
        rig.append(Leg(leg_jnts))
        rig.append(Twistbone([leg_jnts[0], leg_jnts[1]]))
        rig.append(Twistbone([leg_jnts[1], leg_jnts[2]]))

    # Detect arms
    arms_jnts = get_arms(jnts)
    for arm_jnts in arms_jnts:
        for arm_jnt in arm_jnts:
            jnts.remove(arm_jnt)
        rig.append(Arm(arm_jnts))
        rig.append(Twistbone([arm_jnts[0], arm_jnts[1]]))
        rig.append(Twistbone([arm_jnts[1], arm_jnts[2]]))

    print len(jnts)

    rig.build()

    libSerialization.export_network(rig)