Python源码示例:pymel.core.duplicate()

示例1
def hold_ctrl_shapes(ctrl, parent=None):
    """
    Make a snapshot of all shapes of a specific ctrls.
    """
    shapes = filter(lambda x: isinstance(x, pymel.nodetypes.CurveShape), ctrl.getShapes())
    snapshot_transform = pymel.duplicate(ctrl, parentOnly=True, returnRootsOnly=True)[0]
    for shape in shapes:
        shape_snapshot = _duplicate_shape(shape)
        tmp_transform = shape_snapshot.getParent()
        shape_snapshot.setParent(snapshot_transform, s=True, r=True)
        pymel.delete(tmp_transform)
    if parent:
        snapshot_transform.setParent(parent)
    else:
        snapshot_transform.setParent(world=True)
    snapshot_transform.rename('{0}Snapshot'.format(ctrl.name()))
    return snapshot_transform 
示例2
def duplicate(self, class_=None, prefix="", suffix=""):
        """duplicates itself and returns a new joint hierarchy

        :param class_: The class of the created JointHierarchy. Default value
          is JointHierarchy
        :param prefix: Prefix for newly created joints
        :param suffix: Suffix for newly created joints
        """
        if class_ is None:
            class_ = self.__class__

        new_start_joint = pm.duplicate(self.start_joint)[0]
        all_hierarchy = list(reversed(new_start_joint.listRelatives(ad=1, type=pm.nt.Joint)))
        new_end_joint = all_hierarchy[len(self.joints) - 2]

        # delete anything below
        pm.delete(new_end_joint.listRelatives(ad=1))

        new_hierarchy = class_(start_joint=new_start_joint, end_joint=new_end_joint)
        for j, nj in zip(self.joints, new_hierarchy.joints):
            nj.rename("{prefix}{joint}{suffix}".format(prefix=prefix, suffix=suffix, joint=j.name()))

        return new_hierarchy 
示例3
def readIkKwargs(cls, card, isMirroredSide, sideAlteration=lambda **kwargs: kwargs, kinematicType='ik'):
        '''
        Overriden to handle if a custom curve was given, which then needs to be duplicated, mirrored and
        fed directly into the splineTwist.
        '''

        kwargs = cls.readKwargs(card, isMirroredSide, sideAlteration, kinematicType='ik')
        if isMirroredSide:
            if 'controlCountOrCrv' in kwargs and not isinstance( kwargs['controlCountOrCrv'], int ):
                crv = kwargs['controlCountOrCrv']
                crv = duplicate(crv)[0]
                kwargs['controlCountOrCrv'] = crv
                move( crv.sp, [0, 0, 0], a=True )
                move( crv.rp, [0, 0, 0], a=True )
                crv.sx.set(-1)
                
                kwargs['duplicateCurve'] = False
                
        return kwargs 
示例4
def duplicate_with_skin(nodes, parentNode=None):
    #親子付けがあってもエラーはかないように修正
    print nodes
    # リストタイプじゃなかったらリストに変換する
    if not isinstance(nodes, list):
        nodes = [nodes]
    dupObjs = []
    for node in nodes:
        #子供のノード退避用ダミーペアレントを用意
        dummy = common.TemporaryReparent().main(mode='create')
        common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut')
        #複製
        dup = cmds.duplicate(node)[0]
        #ウェイト転送メソッドをSimpleWeightコピペに変更
        weight.SimpleWeightCopyPaste().main(node, mode='copy', saveName=__name__, weightFile=node)
        weight.SimpleWeightCopyPaste().main(dup, mode='paste', saveName=__name__, weightFile=node)
        #親子付けを戻す
        common.TemporaryReparent().main(node,dummyParent=dummy, mode='parent')
        #ダミーペアレントを削除
        common.TemporaryReparent().main(dummyParent=dummy, mode='delete')
        if parentNode is not None:
            cmds.parent(dup, parentNode)
        dupObjs.append(dup)
    return dupObjs
    
#シーン内、もしくは入力メッシュ内にゼロポリゴンオブジェクトがあるかどうか調べる関数 
示例5
def instance(self, source_transform_node):
        """instances the given nodes hierarchy
        """

        # duplicate the given node
        # then replace the instanceable nodes with instances

        # find instanceable nodes in the node and dupNode
        source_hierarchy = self.walk_hierarchy(source_transform_node)

        # if there is no node in the sourceHierarchy just return
        # the instance of the given node
        if len(source_hierarchy) < 1:
            dup_node = pm.duplicate(source_transform_node, ilf=1, rc=True)[0]
            pm.select(dup_node)
            return

        dup_node = pm.duplicate(source_transform_node, rc=True)[0]
        dup_hierarchy = self.walk_hierarchy(dup_node)

        for i, node in enumerate(dup_hierarchy):

            shape = node.getShape()
            if shape is not None and isinstance(shape,
                                                tuple(self._instanceables)):
                # instance the corresponding sourceNode
                source_node = source_hierarchy[i]
                new_instance_node = pm.duplicate(source_node, ilf=True)[0]

                pm.parent(new_instance_node, node.getParent(), r=False)
                pm.delete(node)

        pm.select(dup_node)
        return dup_node 
示例6
def create_ik_hierarchy(self):
        """Creates the ik hierarchy
        """
        self.ik_hierarchy = self.base_hierarchy.duplicate(class_=JointHierarchy, suffix="_ik") 
示例7
def create_fk_hierarchy(self):
        """Creates the fk hierarchy
        """
        self.fk_hierarchy = self.base_hierarchy.duplicate(class_=JointHierarchy, suffix="_fk") 
示例8
def create_ik_hierarchy(self):
        """Creates the ik hierarchy
        """
        self.ik_hierarchy = self.base_hierarchy.duplicate(class_=IKLimbJointHierarchy, suffix="_ik")
        # set joint radius
        base_radius = self.base_hierarchy.joints[0].radius.get()
        for j in self.ik_hierarchy.joints:
            j.radius.set(base_radius * 2)
        assert isinstance(self.ik_hierarchy, IKLimbJointHierarchy)
        self.ik_hierarchy.create_ik_setup() 
示例9
def duplicate_with_connections(cls):
        """duplicates the selected nodes with connections to the network
        """
        return pm.duplicate(ic=1, rr=1) 
示例10
def duplicate_input_graph(cls):
        """duplicates the selected nodes with all their inputs
        """
        return pm.duplicate(un=1, rr=1) 
示例11
def unshape_parent_nodes(cls):
        """Moves the shape node of a mesh to another transform node as a
        children if the mesh node has other meshes under it. Essentially
        cleaning the scene.
        """
        mesh_nodes_with_transform_children = []
        all_meshes = pm.ls(dag=1, type='mesh')

        for node in all_meshes:
            parent = node.getParent()
            tra_under_shape = pm.ls(
                parent.listRelatives(),
                type='transform'
            )
            if len(tra_under_shape):
                mesh_nodes_with_transform_children.append(parent)

        for node in mesh_nodes_with_transform_children:
            # duplicate the node
            dup = pm.duplicate(node)[0]

            # remove all descendents
            all_descendents = dup.listRelatives(ad=1)
            # remove the shape from the list
            all_descendents.remove(dup.getShape())

            pm.delete(all_descendents)

            # parent under the original node
            pm.parent(dup, node)

            # remove the shape of the original node
            pm.delete(node.getShape()) 
示例12
def split_camera(cls):
        """splits one camera to multiple cameras
        """
        selection = pm.ls(sl=1, type=pm.nt.Transform)
        if not selection:
            raise RuntimeError("Please select at least one camera")

        new_cameras = []

        from anima.env.mayaEnv import camera_tools
        for cam in selection:
            cut_info = camera_tools.find_cut_info(cam)

            for cut_in, cut_out in cut_info:
                print(cut_in, cut_out)
                # duplicate the original camera with input graph
                dup_cam = pm.duplicate(cam, un=1)[0]

                # remove all keyframes out of the cut range
                # remove befor
                pm.cutKey(dup_cam, time=(-1000, cut_in - 1))
                # # remove after
                pm.cutKey(dup_cam, time=(cut_out + 1, 100000))

                # rename the new cam
                dup_cam.rename("%s_#" % cam.name())

                new_cameras.append(dup_cam)

            # remove original camera
            pm.delete(cam)

        # select all new cameras
        pm.select(new_cameras) 
示例13
def duplicateObject(object):
        #duplicate the object
        dup = pm.duplicate(object)
        return dup[0] 
示例14
def createSurfaceFromJoints(joints, name="surface", ibtCVNum=0, degree=3):
    """
    Create a nurbs surface along the given joints.
    nurbs CV position is defined by joint position.
    :param joints: `list` list of joint nodes
    :param name: `string` name of the built surface
    :param ibtCVNum: `int` number of cv points added inbetween the joint position
    :param degree: `int` nurbs surface degree
    :return: `PyNode` result surface
    """
    # build surface from joints, one span for each joint
    auxCrv = createCurveFromJoint(joints, name+"_crv", ibtCVNum, degree)
    startPos = joints[0].getTranslation(space="world")
    endPos = joints[-1].getTranslation(space="world")

    offDir = (om.MVector(*(startPos-endPos))^om.MVector(0,1,0)).normal()
    if offDir.length() == 0: offDir = om.MVector(0,0,-1)

    print startPos, endPos, offDir[0], offDir[1], offDir[2]
    buildCrv1 = pm.duplicate(auxCrv)
    pm.move(offDir.x*0.5, offDir.y*0.5, offDir.z*0.5, buildCrv1, r=1)
    buildCrv2 = pm.duplicate(auxCrv)
    pm.move(offDir.x*-0.5, offDir.y*-0.5, offDir.z*-0.5, buildCrv2, r=1)
    auxSurf = pm.loft(buildCrv1, buildCrv2, n=name, ch=0, u=1, d=degree)[0]
    pm.rebuildSurface(auxSurf, ch=0, su=1, du=1, dv=degree, sv=0)
    pm.delete(auxCrv, buildCrv1, buildCrv2)
    # auxSurf.setParent(0)
    return auxSurf 
示例15
def duplicateJointChain(rootJoint, replace=None, suffix=None):
    """
    Duplicate the given joint chain.
    :param rootJoint: `PyNode` root joint of the given joint chain
    :param replace: `tuple` or `list` (old string, new string)
                    rename the duplicated joint chain by replacing string in given joint name
    :param suffix: `string` rename the duplicated joint chain by adding suffix to the given joint name
    :return: `list` list of joints in the duplicated joint chain. ordered by hierarchy
    """
    srcJnts = getJointsInChain(rootJoint)
    dupJnts = []
    if not replace and not suffix:
        raise ValueError("Please rename the duplicated joint chain.")
    for i, srcJnt in enumerate(srcJnts):
        newName = srcJnt.name()
        if replace:
            newName = newName.replace(replace[0], replace[1])
        if suffix:
            newName = "{0}_{1}".format(newName, suffix)
        dupJnt = pm.duplicate(srcJnt, n=newName, po=1)[0]
        dupJnts.append(dupJnt)
        for attr in ['t', 'r', 's', 'jointOrient']:
            pm.setAttr("{0}.{1}".format(dupJnt.name(), attr), pm.getAttr("{0}.{1}".format(srcJnt.name(), attr)))
        if i>0:
            dupJnt.setParent(dupJnts[i-1])
    #
    # for i, srcJnt in enumerate(srcJnts):
    #     if i==0: continue
    #     srcPar = pm.listRelatives(srcJnt, p=1)
    #     if srcPar:
    #         dupJnts[i].setParent(srcPar[0].name().replace(replace[0], replace[1]))
    return dupJnts 
示例16
def duplicate_with_skin(nodes, parentNode=None):
    #親子付けがあってもエラーはかないように修正
    #print nodes
    # リストタイプじゃなかったらリストに変換する
    if not isinstance(nodes, list):
        nodes = [nodes]
    dupObjs = []
    for node in nodes:
        #子供のノード退避用ダミーペアレントを用意
        dummy = common.TemporaryReparent().main(mode='create')
        common.TemporaryReparent().main(node,dummyParent=dummy, mode='cut')
        #複製
        dup = cmds.duplicate(node)[0]
        #ウェイト転送メソッドをSimpleWeightコピペに変更
        weight.SimpleWeightCopyPaste().main(node, mode='copy', saveName=__name__, weightFile=node)
        weight.SimpleWeightCopyPaste().main(dup, mode='paste', saveName=__name__, weightFile=node)
        #親子付けを戻す
        common.TemporaryReparent().main(node,dummyParent=dummy, mode='parent')
        #ダミーペアレントを削除
        common.TemporaryReparent().main(dummyParent=dummy, mode='delete')
        if parentNode is not None:
            cmds.parent(dup, parentNode)
        dupObjs.append(dup)
    return dupObjs
    
#シーン内、もしくは入力メッシュ内にゼロポリゴンオブジェクトがあるかどうか調べる関数 
示例17
def duplicateCard(card):
    d = duplicate( card )[0]
    proxy.relink( card, d )
    if card.parentCard:
        d.parentCardLink = card.parentCard
    return d 
示例18
def face_extraction(faces=None, deleteOrg=True, selectDuplicated=True, transferWeight=True):
    '''
    メッシュを選択したフェイスで切り分ける
    deleteOrg 切り分け元のフェイスを削除するかどうかを指定デフォルトTrue
    faces → 外部ツールからフェイスのリストを渡して実行したい場合の引数
    '''
    if faces is None:
        selection = cmds.ls(sl=True)
    else:
        selection = faces
    selObjects = []
    for sel in selection:
        objNameTemp = sel.split('.')
        if not objNameTemp[0] in selObjects:
            selObjects.append(objNameTemp[0])

    cmds.select(cl=True)
    duplicated = []  # 最後の選択格納用
    # ハイライトされているオブジェクト毎に処理
    for selObj in selObjects:
        # print 'currentObj : ' + str(selObj)
        compTemp = []  # バラバラのコンポーネントをオブジェクト毎に格納するリスト
        # 選択されているコンポーネントを整理
        for sel in selection:
            objNameTemp = sel.split('.')
            objName = objNameTemp[0]  # コンポーネントのオブジェクト名
            # オブジェクト名が一致且つフェイス選択ならリスト入り
            if selObj == objName and '.f[' in sel:
                compTemp.append(sel)
                # print 'compTemp add : '+str(sel)
        # print 'compTemp ALL : '+str(compTemp)
        if len(compTemp) != 0:
            dupObj = cmds.duplicate(selObj, rr=True)
            # 子供のオブジェクト取得関数呼び出し
            children = cmds.listRelatives(dupObj[0], type='transform', ad=True)
            # 子供のオブジェクトがある場合は重複を避けるため削除
            if children:
                cmds.delete(children)
            duplicated.append(dupObj[0])
            if transferWeight:  # ウェイト転送フラグが有効だったら
                weight.transfer_weight(selObj, dupObj, logTransfer=False)  # ウェイトを転送
            faces = ",".join(compTemp)  # リストを括弧のない文字列に
            faces = faces.replace(selObj, dupObj[0])  # 名前置き換え
            delface = faces.split(',')
            cmds.select(delface, r=True)
            mel.eval('InvertSelection')  # 選択の反転
            deleter = cmds.ls(sl=True)
            cmds.delete(deleter)  # 最初に選択されていなかったフェース部分のみ削除
            # 削除フラグが立っていたら古いフェイス削除
            if deleteOrg is True:
                cmds.delete(compTemp)
    if selectDuplicated:
        cmds.select(duplicated)
    return duplicated
    
#クラスタデフォーマの書き戻し 
示例19
def marge_run(self):
        objects = common.search_polygon_mesh(self.objects, serchChildeNode=True, fullPath=True)
        print objects
        #print objects
        if len(objects) < 2:
            self.marged_mesh = objects
            return True
        skined_list = []
        no_skin_list = []
        parent_list = [cmds.listRelatives(obj, p=True, f=True) for obj in objects]
        
        for obj in objects:
            skin = cmds.ls(cmds.listHistory(obj), type='skinCluster')
            if skin:
                skined_list.append(obj)
            else:
                no_skin_list.append(obj)
                
        if no_skin_list and skined_list:
            skined_mesh = skined_list[0]
            for no_skin_mesh in no_skin_list:
                weight.transfer_weight(skined_mesh, no_skin_mesh, transferWeight=False, returnInfluences=False, logTransfer=False)
                
        if skined_list:
            marged_mesh = pm.polyUniteSkinned(objects)[0]
            pm.polyMergeVertex(marged_mesh, d=0.001)
            target_mesh = pm.duplicate(marged_mesh)[0]
            weight.transfer_weight(str(marged_mesh), str(target_mesh), transferWeight=True, returnInfluences=False, logTransfer=False)
        else:
            marged_mesh = pm.polyUnite(objects, o=True)[0]
            pm.polyMergeVertex(marged_mesh, d=0.001)
            target_mesh = pm.duplicate(marged_mesh)[0]
            #pm.delete(objects)
        for obj in objects:
            if pm.ls(obj):
                pm.delete(obj)
            
        pm.delete(marged_mesh)
        
        all_attr_list = [['.sx', '.sy', '.sz'], ['.rx', '.ry', '.rz'], ['.tx', '.ty', '.tz']]
        for p_node in parent_list:
            if cmds.ls(p_node, l=True):
                all_lock_list = []
                for attr_list in all_attr_list:
                    lock_list = []
                    for attr in attr_list:
                        lock_list.append(pm.getAttr(target_mesh+attr, lock=True))
                        pm.setAttr(target_mesh+attr, lock=False)
                    all_lock_list.append(lock_list)
                pm.parent(target_mesh, p_node[0])
                for lock_list, attr_list in zip(all_lock_list, all_attr_list):
                    for lock, attr in zip(lock_list, attr_list):
                        continue
                        pm.setAttr(target_mesh[0]+attr, lock=lock)
                break
        pm.rename(target_mesh, objects[0])
        pm.select(target_mesh)
        self.marged_mesh = str(target_mesh)
        return True 
示例20
def freeze_joint(joint):
    """Freezes the given joint by duplicating it and applying the freeze to the
    duplicate and then copy the joint orientation values to the original joint.

    :param joint: The joint which wanted to be frozen
    """
    dup_joint = pm.duplicate(joint, rc=1)[0]

    # if the duplicate has any children delete them
    pm.delete(dup_joint.getChildren())

    # unlock rotate channels
    dup_joint.rotateX.unlock()
    dup_joint.rotateY.unlock()
    dup_joint.rotateZ.unlock()

    # freeze the joint
    pm.makeIdentity(dup_joint, apply=1, r=1)

    # set rotation to zero
    if not joint.rotateX.isLocked():
        joint.rotateX.set(0)
    else:
        # unlock and lock it again
        joint.rotateX.unlock()
        joint.rotateX.set(0)
        joint.rotateX.lock()

    if not joint.rotateY.isLocked():
        joint.rotateY.set(0)
    else:
        # unlock and lock it again
        joint.rotateY.unlock()
        joint.rotateY.set(0)
        joint.rotateY.lock()

    if not joint.rotateZ.isLocked():
        joint.rotateZ.set(0)
    else:
        # unlock and lock it again
        joint.rotateZ.unlock()
        joint.rotateZ.set(0)
        joint.rotateZ.lock()

    # get the joint orient
    joint.jointOrient.set(dup_joint.jointOrient.get())

    # delete the duplicate joint
    pm.delete(dup_joint) 
示例21
def duplycateSymmetry(object):
    meshNode = cmds.listRelatives(object, s=True, pa=True, type='mesh', fullPath=True)
    if meshNode is not None:
        #エラー吐くことがあるのでノンデフォーマヒストリを削除
        cmds.bakePartialHistory(object,ppt=True)
    #ネームスペースから分割
    nemeSplit = object.split('|')
    newName = nemeSplit[-1]
    #左右リネーム関数呼び出し
    newName = renameLR(newName)
    #複製して反転
    duplicated = pm.duplicate(object, name=newName)
    try:
        parentNode =  duplicated[0].firstParent()#Pymelの機能で親の階層を取得しておく。listRelativesと同じような。
        parentNode = str(parentNode)#cmdsで使えるように文字列に変換
        #左右リネーム関数呼び出し
        newParent = renameLR(parentNode)
    except:
        parentNode = None
        newParent = None
    duplicated = str(duplicated[0])#cmdsで使えるように文字列に変換
    #子供のオブジェクト取得関数呼び出し
    children = pm.listRelatives(duplicated, ad=True, type='transform', f=True)
    #子供のオブジェクトがある場合は重複を避けるため削除
    if len(children) != 0:
        cmds.delete(children)
    #アトリビュートのロック解除
    #全部のロック解除しないと親が変わったときのロカール値が変わらず、ズレることがある。
    attr = ['.translate', '.rotate', '.scale']
    axis = ['X', 'Y', 'Z']
    for varA in range(0, 3):
        for varB in range(0, 3):
            cmds.setAttr(duplicated + attr[varA] + axis[varB], lock=False)
    #ワールドスケール用ダミーロケータ作成
    dummy = common.TemporaryReparent().main(mode='create')
    cmds.parent(duplicated, dummy)
    #X方向に-1スケーリングしてからスケールフリーズ
    cmds.scale(-1, 1, 1, dummy, relative=True, pivot=(0,0,0))
    #杏仁生成を防ぐためにダミーロケータのスケールをフリーズ、負の値が親に入ってると杏仁が生成されるような。
    if cmds.nodeType(duplicated) == 'joint':
        #ジョイントを正しい回転、位置に修正するため、スケールフリーズ前のグローバル値を取得しておく
        pos = cmds.xform(duplicated, q=True, t=True, ws=True)
        rot = cmds.xform(duplicated, q=True, ro=True, ws=True)
        cmds.makeIdentity(dummy, apply=True, translate=False, rotate=False, scale=True, preserveNormals=True)
    #元の親名と違い、かつ新しい親名のオブジェクトが存在する場合は付け替え
    if parentNode is None:
            cmds.parent(duplicated, w=True)
    else:
        if parentNode != newParent and cmds.ls(newParent):
            cmds.parent(duplicated, newParent)
        else:
            cmds.parent(duplicated, parentNode)
    #ダミーペアレントを削除
    common.TemporaryReparent().main(dummyParent=dummy, mode='delete')
    cmds.makeIdentity(duplicated, apply=True, translate=False, rotate=False, scale=True, preserveNormals=True)
    if cmds.nodeType(duplicated) == 'joint':
        cmds.xform(duplicated , t=pos, ro=rot, ws=True)
    return duplicated 
示例22
def face_extraction(faces=None, deleteOrg=True, selectDuplicated=True, transferWeight=True):
    '''
    メッシュを選択したフェイスで切り分ける
    deleteOrg 切り分け元のフェイスを削除するかどうかを指定デフォルトTrue
    faces → 外部ツールからフェイスのリストを渡して実行したい場合の引数
    '''
    if faces is None:
        selection = cmds.ls(sl=True)
    else:
        selection = faces
    selObjects = []
    for sel in selection:
        objNameTemp = sel.split('.')
        if not objNameTemp[0] in selObjects:
            selObjects.append(objNameTemp[0])

    cmds.select(cl=True)
    duplicated = []  # 最後の選択格納用
    # ハイライトされているオブジェクト毎に処理
    for selObj in selObjects:
        compTemp = []  # バラバラのコンポーネントをオブジェクト毎に格納するリスト
        # 選択されているコンポーネントを整理
        for sel in selection:
            objNameTemp = sel.split('.')
            objName = objNameTemp[0]  # コンポーネントのオブジェクト名
            # オブジェクト名が一致且つフェイス選択ならリスト入り
            if selObj == objName and '.f[' in sel:
                compTemp.append(sel)
        # print 'compTemp ALL : '+str(compTemp)
        if len(compTemp) != 0:
            dupObj = cmds.duplicate(selObj, rr=True)
            # 子供のオブジェクト取得関数呼び出し
            children = cmds.listRelatives(dupObj[0], type='transform', ad=True)
            # 子供のオブジェクトがある場合は重複を避けるため削除
            if children:
                cmds.delete(children)
            duplicated.append(dupObj[0])
            if transferWeight:  # ウェイト転送フラグが有効だったら
                weight.transfer_weight(selObj, dupObj, logTransfer=False)  # ウェイトを転送
            faces = ",".join(compTemp)  # リストを括弧のない文字列に
            faces = faces.replace(selObj, dupObj[0])  # 名前置き換え
            delface = faces.split(',')
            cmds.selectMode(co=True)
            cmds.hilite(dupObj)
            cmds.select(delface, r=True)
            #print 'del face :',delface
            for obj in dupObj:
                face_count = str(len(common.conv_comp(obj, mode='face')))
                cmds.select(obj+'.f[0:'+face_count+']', tgl=True)
            #mel.eval('InvertSelection;')  # 選択の反転
            deleter = cmds.ls(sl=True)
            cmds.delete(deleter)  # 最初に選択されていなかったフェース部分のみ削除
            # 削除フラグが立っていたら古いフェイス削除
            if deleteOrg is True:
                cmds.delete(compTemp)
    if selectDuplicated:
        cmds.select(duplicated)
    return duplicated
    
#クラスタデフォーマの書き戻し 
示例23
def marge_run(self):
        objects = common.search_polygon_mesh(self.objects, serchChildeNode=True, fullPath=True)
        #print 'marge target :', objects
        if len(objects) < 2:
            self.marged_mesh = objects
            return True
        skined_list = []
        no_skin_list = []
        parent_list = [cmds.listRelatives(obj, p=True, f=True) for obj in objects]
        
        for obj in objects:
            skin = cmds.ls(cmds.listHistory(obj), type='skinCluster')
            if skin:
                skined_list.append(obj)
            else:
                no_skin_list.append(obj)
                
        if no_skin_list and skined_list:
            skined_mesh = skined_list[0]
            for no_skin_mesh in no_skin_list:
                weight.transfer_weight(skined_mesh, no_skin_mesh, transferWeight=False, returnInfluences=False, logTransfer=False)
                
        if skined_list:
            marged_mesh = pm.polyUniteSkinned(objects)[0]
            pm.polyMergeVertex(marged_mesh, d=0.001)
            target_mesh = pm.duplicate(marged_mesh)[0]
            weight.transfer_weight(str(marged_mesh), str(target_mesh), transferWeight=True, returnInfluences=False, logTransfer=False)
        else:
            marged_mesh = pm.polyUnite(objects, o=True)[0]
            pm.polyMergeVertex(marged_mesh, d=0.001)
            target_mesh = pm.duplicate(marged_mesh)[0]
            #pm.delete(objects)
        for obj in objects:
            if pm.ls(obj):
                pm.delete(obj)
            
        pm.delete(marged_mesh)
        
        all_attr_list = [['.sx', '.sy', '.sz'], ['.rx', '.ry', '.rz'], ['.tx', '.ty', '.tz']]
        for p_node in parent_list:
            if cmds.ls(p_node, l=True):
                all_lock_list = []
                for attr_list in all_attr_list:
                    lock_list = []
                    for attr in attr_list:
                        lock_list.append(pm.getAttr(target_mesh+attr, lock=True))
                        pm.setAttr(target_mesh+attr, lock=False)
                    all_lock_list.append(lock_list)
                pm.parent(target_mesh, p_node[0])
                for lock_list, attr_list in zip(all_lock_list, all_attr_list):
                    for lock, attr in zip(lock_list, attr_list):
                        #continue
                        #print 'lock attr :', lock, target_mesh, attr
                        pm.setAttr(target_mesh+attr, lock=lock)
                break
        pm.rename(target_mesh, objects[0])
        pm.select(target_mesh)
        self.marged_mesh = str(target_mesh)
        return True 
示例24
def cardIk(card):

    #ctrl = mel.eval( 'curve -d 1 -p -0.5 1 -0.866026 -p -0.5 1 0.866025 -p 1 1 0 -p -0.5 1 -0.866026 -p 0 0 0 -p -0.5 -1 -0.866026 -p -0.5 -1 0.866025 -p 0 0 0 -p -0.5 1 0.866025 -p 1 1 0 -p 0 0 0 -p 1 -1 0 -p -0.5 -1 -0.866026 -p -0.5 -1 0.866025 -p 1 -1 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 ;' )

    ctrl = PyNode(mel.eval('curve -d 1 -p 0 4 0 -p -2.828427 2.828427 -2.47269e-007 -p -4 0 -3.49691e-007 -p -2.828427 -2.828427 -2.47269e-007 -p 0 -4 0 -p 2.828427 -2.828427 0 -p 4 0 0 -p 2.828427 2.828427 0 -p 0 4 0 -p -1.23634e-007 2.828427 2.828427 -p -1.74846e-007 0 4 -p -1.23634e-007 -2.828427 2.828427 -p 0 -4 0 -p 3.70903e-007 -2.828427 -2.828427 -p 5.24537e-007 0 -4 -p 3.70903e-007 2.828427 -2.828427 -p 0 4 0 -p 0 0 0 -p 0 -4 0 -p 0 0 0 -p -4 0 0 -p 4 0 0 -p 0 0 -4 -p 0 0 4 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 18 -k 19 -k 20 -k 21 -k 22 -k 23 ;'))

    ctrl.rename( card.name() + "_target" )
    
    upCtrl = duplicate(ctrl)[0]
    upCtrl.rename( card.name() + "_up" )
    
    aim = spaceLocator()
    aim.setParent(ctrl)
    aim.t.set(0, 0, 0)
    hide(aim)
    
    up = spaceLocator()
    up.setParent( upCtrl )
    hide(up)
    
    base = spaceLocator()
    base.rename( 'cardIkBase' )
    hide(base)
    pointConstraint( card, base )

    core.dagObj.moveTo( ctrl, card.joints[-1] )
    #core.dagObj.moveTo( upCtrl, card.vtx[1] )
    core.dagObj.moveTo( upCtrl, card.cv[1][0] )

    aimConstraint( aim, card, wut='object', wuo=up, aim=[0, -1, 0], u=[0, 0, -1])

    dist = distanceDimension( base, aim )
    dist.getParent().setParent(ctrl)
    hide(dist)

    core.math.divide( dist.distance, dist.distance.get() / card.sy.get() ) >> card.sy
        
    follower = spaceLocator()
    follower.rename( 'cardIkFollower' )
    follower.setParent( card )
    follower.t.set(0, 0, 0)
    hide(follower)
    
    pointConstraint( up, follower, skip=['x', 'z'] )
    
    sideDist = distanceDimension( follower, up )
    sideDist.getParent().setParent(ctrl)
    hide(sideDist)

    core.math.divide( sideDist.distance, sideDist.distance.get() / card.sz.get() ) >> card.sz
    
    # Orient controls with the card so moving in local space initially preserves orientation.
    upCtrl.setRotation( card.getRotation(space='world'), space='world' )
    ctrl.setRotation( card.getRotation(space='world'), space='world' )

    distBetweenCtrls = (ctrl.getTranslation(space='world') - upCtrl.getTranslation(space='world') ).length()
    if distBetweenCtrls < 8.0:
        upCtrl.s.set( [distBetweenCtrls / 8.0] * 3 )
        ctrl.s.set( [distBetweenCtrls / 8.0] * 3 )
    
    select(ctrl) 
示例25
def generateReposer():
    
    rJoints = []
    rCards = []

    # Build all the cards and joints
    cards = core.findNode.allCards()
    for card in cards:
        rCard = duplicate(card, po=0)[0]
        rCard.deleteAttr('fossilRigData')
        for child in rCard.listRelatives():
            if not child.type() == 'nurbsSurface':
                delete(child)
        rCards.append(rCard)
        makeIdentity(rCard, t=False, r=False, s=True, apply=True)
        core.dagObj.lockScale( rCard )

        for jnt in card.joints:
            j = joint(None)
            j.rename(  simpleName(jnt, '{}_repose') )

            core.dagObj.matchTo(j, jnt)

            assert jnt.info.get('options', {}).get('mirroredSide', False) is False, 'parent to mirrored joints not supported yet'
            j.addAttr('bpj', at='message')
            jnt.message >> j.bpj

            rJoints.append(j)

    # Set their parents
    for j in rJoints:
        parent = j.bpj.listConnections()[0].parent
        if parent:
            j.setParent( getRJoint(parent) )

    # Put under cards, card pivot to lead joint
    for rCard, card in zip(rCards, cards):
        bpj = card.parentCardJoint
        if bpj:

            start = card.start() if card.joints else bpj
            rCard.setParent( getRJoint(bpj) )
            core.dagObj.unlock(rCard)
            xform(rCard, ws=True, piv=xform(start, q=True, t=True, ws=True) )
            core.dagObj.lockTrans(rCard)

        start = getRJoint(card.start())
        start.setParent( rCard )
        core.dagObj.lockTrans( core.dagObj.lockScale( start ) )

    for j in rJoints:
        lockRYZ(j)