Example #1
0
def get_srt(selection, mode='object'):
    local_sids = [1, 2, 3, 5]
    s_list = []
    r_list = []
    t_list = []
    try:  #2018up2以降の不具合対応
        sid = sb.space_group.checkedId()
    except Exception as e:
        print e.message
        return
    sym = cmds.symmetricModelling(q=True, symmetry=True)
    for sel in selection:
        try:
            parent = cmds.listRelatives(sel, p=True)
            #ワールド空間のときの処理
            if sid == 0 or sid == 4:
                scale = cmds.xform(sel, q=True, s=True, ws=True)
                rot = cmds.xform(sel, q=True, ro=True, ws=True)
                trans = cmds.xform(sel, q=True, t=True, ws=True)
            #ローカル、ペアレント空間のときの処理
            else:
                axis_attr_list = ['X', 'Y', 'Z']
                scale = cmds.xform(sel, q=True, s=True, os=True, r=True)
                rot = cmds.xform(sel, q=True, ro=True, os=True)
                if sid in local_sids:  #ローカルスペースとビューの時の処理
                    if cmds.selectMode(q=True, o=True) and mode == 'object':
                        #print sid
                        if sid == 3 or sid == 2 or sid == 5:  #ローカルスペース
                            trans = [
                                cmds.getAttr(sel + '.translate' + a)
                                for a in axis_attr_list
                            ]
                        elif sid == 1:  #オブジェクトスペース
                            trans = cmds.xform(sel, q=True, t=True, os=True)
                    else:
                        trans = cmds.xform(sel, q=True, t=True, os=True)
                else:
                    trans = cmds.xform(sel, q=True, t=True, os=True)
            if mode == 'object':
                s_list.append(scale)
                r_list.append(rot)
                t_list.append(trans)
            else:
                s_list += scale
                r_list += rot
                t_list += trans
        except:
            pass
    #print 'tarns list :', len(t_list)
    return s_list, r_list, t_list
Example #2
0
def get_matrix():
    global SYM_AVOIDANCE
    global sb
    from . import sisidebar_main as sb
    #print '-------------get Matrix---------------- :'
    #print 'select obj :', cmds.ls(sl=True)
    #current_tool = cmds.currentCtx()
    #print 'current tool ;',  current_tool
    #cmds.setToolTo('selectSuperContext')
    #cmds.setToolTo(current_tool)
    if SYM_AVOIDANCE:
        SYM_AVOIDANCE = False
        return
    #ロックの有無をチェック
    try:
        sb.window.attribute_lock_state(mode=3, check_only=True)
    except Exception as e:
        print e.message
        pass
    try:  #2018up2以降の不具合対応
        sid = sb.space_group.checkedId()
    except Exception as e:
        print e.message
        return
    #一旦スケールX値をリセットしてメインウィンドウクラスに変更をお知らせする
    #sb.set_temp_text('change')
    sb.set_active_mute()
    scale = ['', '', '']
    rot = ['', '', '']
    trans = ['', '', '']
    if cmds.selectMode(q=True, o=True):
        selection = cmds.ls(sl=True, type='transform')
        if selection:
            try:
                s_list, r_list, t_list = get_srt(selection)
            except Exception as e:
                print e.message
                return
            #print 'get matrix :', s_list, r_list, t_list
            for i in range(3):
                s_list = [
                    map(lambda a: round(float(a), view_decimal), xyz)
                    for xyz in s_list
                ]
                r_list = [
                    map(lambda a: round(float(a), view_decimal), xyz)
                    for xyz in r_list
                ]
                t_list = [
                    map(lambda a: round(float(a), view_decimal), xyz)
                    for xyz in t_list
                ]
                if not all(s[i] == s_list[0][i] for s in s_list):
                    #print 'not same'
                    scale[i] = ''
                else:
                    #print 'same'
                    scale[i] = str(s_list[0][i])
                if not all(r[i] == r_list[0][i] for r in r_list):
                    #print 'not same', r_list
                    rot[i] = ''
                else:
                    #print 'same', r_list
                    rot[i] = str(r_list[0][i])
                if not all(t[i] == t_list[0][i] for t in t_list):
                    trans[i] = ''
                else:
                    trans[i] = str(t_list[0][i])
        #sb.check_key_anim()
        if np_flag:
            sb.view_np_time(culc_time='- Numpy Calculation Mode -')
        else:
            sb.view_np_time(culc_time='- Usual Calculation Mode -')
    selection = cmds.ls(sl=True, type='float3')
    #カーブもとっておく
    cv_selection = cmds.ls(sl=True, type='double3', fl=True)
    #print cv_selection
    if selection or cv_selection:
        #ラティスポイント他すべてを有効にする
        sel_str = str(selection + cv_selection)
        '''
        if '.vtx[' in sel_str:
            cmds.selectType(polymeshVertex=True)
            #cmds.selectType(particle=True)
        '''
        if '.cv[' in sel_str:
            cmds.selectType(cv=True)
            cmds.selectMode(co=True)
        if '.pt[' in sel_str:
            cmds.selectType(latticePoint=True)
            cmds.selectMode(co=True)
        #オブジェクトモードでもコンポーネント選択がある場合は強制的にモード変更する

        components = cmds.polyListComponentConversion(selection,
                                                      tv=True) + cv_selection
        #print components
        #if not components:
        s_list, r_list, t_list = get_srt(components, mode='component')
        start = dt.datetime.now()  #計測開始
        #マニプ情報取得に必要な情報を集める
        sym = cmds.symmetricModelling(q=True, symmetry=True)
        current_tool = cmds.currentCtx()
        tools_list = [
            'scaleSuperContext', 'RotateSuperContext', 'moveSuperContext'
        ]
        if sym:
            axis_list = ['x', 'y', 'z']
            sym_axis = cmds.symmetricModelling(q=True, ax=True)
            axis_id = axis_list.index(sym_axis)
            meshes = cmds.ls(hl=True, l=True)
            #マニプが有効でない場合はシンメトリ座標を取得できないので自前計算
            if not current_tool in tools_list:
                for i, value in enumerate(t_list):
                    if i % 3 == axis_id:
                        value = math.sqrt(value**2)
                        t_list[i] = value

        if np_flag:
            #print 'culc in numpy'
            s_list = np.reshape(s_list, (len(s_list) / 3, 3))
            scale = np.average(s_list, axis=0).tolist()
            r_list = np.reshape(r_list, (len(r_list) / 3, 3))
            rot = np.average(r_list, axis=0).tolist()
            t_list = np.reshape(t_list, (len(t_list) / 3, 3))
            trans = np.average(t_list, axis=0).tolist()
        else:
            #print 'culc in math'
            srt_list = [0, 0, 0, 0, 0, 0, 0, 0, 0]
            for i in range(0, len(s_list), 3):
                srt_list[0] += s_list[i + 0]
                srt_list[1] += s_list[i + 1]
                srt_list[2] += s_list[i + 2]
            scale = map(lambda a: a / (len(s_list) / 3), srt_list[0:3])
            for i in range(0, len(r_list), 3):
                srt_list[3] += r_list[i + 0]
                srt_list[4] += r_list[i + 1]
                srt_list[5] += r_list[i + 2]
            rot = map(lambda a: a / (len(r_list) / 3), srt_list[3:6])
            for i in range(0, len(t_list), 3):
                srt_list[6] += t_list[i + 0]
                srt_list[7] += t_list[i + 1]
                srt_list[8] += t_list[i + 2]
            trans = map(lambda a: a / (len(t_list) / 3), srt_list[6:9])
        #シンメトリのときとワールド座標の場合の処理
        #ワールド空間のときもMayaのマニピュレータ位置とあわせる
        if sym or sid == 0 or sid == 4:
            if current_tool in tools_list:
                if current_tool == 'moveSuperContext':
                    trans = cmds.manipMoveContext('Move', q=True, p=True)
                elif current_tool == 'RotateSuperContext':
                    trans = cmds.manipRotateContext('Rotate', q=True, p=True)
                elif current_tool == 'scaleSuperContext':
                    trans = cmds.manipScaleContext('Scale', q=True, p=True)
                #ワールド空間でない且つ選択オブジェクトが1つの場合はマトリクス計算で座標を求める
                if sid != 0 and sid != 4 and len(meshes) == 1:
                    scale = cmds.xform(meshes[0], q=True, s=True, ws=True)
                    #scale = [1.0]*3
                    if len(meshes) == 1:
                        pos = trans + [1]  #行列掛けるようの位置配列、末尾に1つけとく
                        if np_flag:
                            #マトリクス計算で座標求める
                            matrix = cmds.xform(meshes[0],
                                                q=True,
                                                m=True,
                                                ws=True)
                            matrix = np.reshape(matrix, (4, 4))
                            rev_matrix = np.linalg.inv(matrix)  #逆行列
                            #print 'get mesh matrix :', matrix, meshes[0]
                            #print 'get rev matrix np:', rev_matrix
                            mul_matrix_trans = np.dot(pos, matrix)
                            mul_rev_matrix_trans = np.dot(pos, rev_matrix)
                            #print 'mul matrix :', mul_matrix_trans
                            #print 'mul rev matrix :', mul_rev_matrix_trans
                            trans = scale * mul_rev_matrix_trans[:3]
                            #print 'Local trans np:', trans
                        else:  #Numpy使わない処理
                            matrix = cmds.xform(meshes[0],
                                                q=True,
                                                m=True,
                                                ws=True)
                            rev_matrix = pm.ls(
                                meshes[0])[0].transformationMatrix().inverse()
                            #print 'get rev matrix :', rev_matrix
                            pos = [pos]  #行列掛けるようの位置配列、末尾に1つけとく
                            #print matrix
                            #print rev_matrix
                            mul_rev_matrix_trans = mm.dot(pos, rev_matrix)[0]
                            #print mul_rev_matrix_trans
                            trans = mm.mul(mul_rev_matrix_trans[:3], scale)
                        #print 'Local trans :', trans
                    #print 'sym pos :',  trans, meshes, sid
        #print 'trans :', trans
        end = dt.datetime.now()
        culc_time = end - start
        sb.view_np_time(culc_time='Culc Time ' + str(culc_time))
        #表示桁数を調整する
    try:
        scale = map(lambda a: round(float(a), view_decimal)
                    if a != '' else '', scale)
        rot = map(lambda a: round(float(a), view_decimal)
                  if a != '' else '', rot)
        trans = map(lambda a: round(float(a), view_decimal)
                    if a != '' else '', trans)
        #念のため0のマイナス符号を除去、main側のセットでもやってるんで一旦ミュート
        #print rot
        #scale = map(lambda a : float(str(a).replace('-0.0', '0.0')) if a=='-0.0' else a, scale)
        #rot = map(lambda a : float(str(a).replace('-0.0', '0.0')) if a=='-0.0' else a, rot)
        #trans = map(lambda a : float(str(a).replace('-0.0', '0.0')) if a=='-0.0' else a, trans)
        #print rot
        sb.set_pre_transform(trans, rot, scale)
        sb.set_srt_text(scale, rot, trans)
    except:
        sb.set_pre_transform(trans, rot, scale)
        sb.set_srt_text(scale, rot, trans)
Example #3
0
 def checkSymmetry(*args):
     # checks if symmetry is on
     symmetry = mc.symmetricModelling(query=True, symmetry=True)
     if symmetry != 0:
         mc.symmetricModelling(symmetry=0)
     return symmetry