mGearを使ってみた。002

mGear/Shifter/Guid Mannager起動してみたら起動できなかった。

エラー: AttributeError: file C:\Users\whaison\Documents\maya\2016\ja_JP\scripts\mGear\mgear_3.7.0_beta_01\release\scripts\mgear\core\pyqt.py line 160: ‘module’ object has no attribute ‘workspaceControl’

zipフォルダにはいってるdrag_n_drop_install.pyってなんやろね

たぶんインストールが的確じゃなかった。

drag_n_drop_install.pyの

__file__がみつかりません

エラー: line 1: NameError: file line 59: global name ‘file‘ is not defined

こうすりゃ動くはず

"""
Drag and drop this file into your viewport to run the mGear installer.

1. Default Install:
     Will install in the users documents folder where Maya is installed, a
     restart will not be required.

2. Custom Install:
    Will install in the user specified directory, this method will write the
    correct module path in the Maya.env file, but a restart will be required
    in this case.

"""
import os
import sys
import shutil

try:
    import pymel.core as pm
    from pymel import mayautils
    from maya.app.startup import basic
    is_maya = True

except ImportError():
    is_maya = False

# -- maya requires this in order to successfully execute


def onMayaDroppedPythonFile(*args, **kwargs):
    """
    This function is only supported since Maya 2017 Update 3
    """
    pass


def files_exist(file_list):
    """Get all file paths that exist.

    Args:
        file_list (list): List of paths to iterate through

    Returns:
        list: List of all paths found
    """

    file_found = []
    for item in file_list:
        if os.path.exists(item):
            found = item
            file_found.append(found)

    return file_found


def _dropped_install():

    # -- current folder where the installer resides
    #current_folder = os.path.dirname(__file__)
    current_folder = os.path.dirname("C:/Users/whaison/Documents/maya/2016/ja_JP/scripts/mGear/mgear_3.7.0_beta_01/drag_n_drop_install.py")
    # -- folder of all conents of mgear resides
    mgear_folder = os.path.normpath(os.path.join(current_folder, "release"))
    custom_path = False

    # -- default modules folder to install to
    install_path = os.path.normpath(os.path.join(
        os.environ['MAYA_APP_DIR'], "modules"))

    # -- mesage for the main installer dialog window
    message = (
        "mGear will be installed here:\n"
        "{}\n"
        "\n"
        "Make sure to SAVE your scene before continuing.\n"
        "\n"
        "NOTE: Installing to a custom directory will require a restart.\n"
        "\n"
        "Would you like to continue?".format(install_path)
    )

    # -- installer dialog window
    input = pm.confirmDialog(title="Installation Path",
                             message=message,
                             icon="question",
                             button=["OK", "Cancel", "No, Custom Path"],
                             cancelButton="Cancel",
                             dismissString="Cancel")

    if input == "Cancel":
        pm.displayError("mGear installation has been cancelled.")
        return
    elif input == "No, Custom Path":
        install_path = None

    # -- custom path will be set here
    if install_path is None:
        install_path = pm.fileDialog2(
            fileMode=3,
            okCaption="Install here",
            caption="Please choose a folder to install mGear...")[0]
        custom_path = True

    # -- if install path is still None, exit
    if not install_path:
        return

    # -- flush the undo que in case there is anything that might disrupt
    # the install
    pm.flushUndo()

    # -- create a fresh scene incase there are any solvers still
    # loaded in memory
    pm.newFile(force=True)

    # -- mgear install path
    mgear_install_path = os.path.join(install_path, "mgear")

    # -- make sure the the mgear folder does not exist
    if os.path.exists(mgear_install_path):
        shutil.rmtree(mgear_install_path)

    # -- copy to a folder because tge copytree gives issues with
    # existing folders
    shutil.copytree(mgear_folder, mgear_install_path)

    # -- look in install directory for files of same name
    search_names = ["platforms", "mGear.mod", "scripts"]

    # -- construct path names
    full_path = [os.path.join(install_path, x) for x in search_names]

    # -- files of the same name
    found = files_exist(full_path)
    if found:
        # -- message if same files are found
        message = ("mGear files already exist in the install location.\n"
                   "\n"
                   "Would you like to overrite them?")
        # -- same files dialog window
        input = pm.confirmDialog(title="Delete existing files",
                                 message=message,
                                 icon="warning",
                                 button=["OK", "Cancel"],
                                 cancelButton="Cancel",
                                 dismissString="Cancel")

        if input == "Cancel":
            # -- delete the temp folder
            shutil.rmtree(mgear_install_path)
            pm.displayError("mGear installation has been cancelled.")
            return

    # -- iterate over folders and remove them
    for item in os.listdir(mgear_install_path):
        if os.path.exists(os.path.join(install_path, item)):
            # -- unload plugins incase there is a faulty install
            try:
                pm.unloadPlugin("mgear_solvers.mll", force=True)
                pm.unloadPlugin("weightDriver.mll", force=True)
            except:
                pass
            # -- delete file and folders
            if os.path.isfile(os.path.join(install_path, item)):
                os.remove(os.path.join(install_path, item))
            elif os.path.isdir(os.path.join(install_path, item)):
                shutil.rmtree(os.path.join(install_path, item))
        # -- move the folder to the install path
        shutil.move(os.path.join(install_path, "mgear", item), install_path)

    # -- delete the temp folder
    shutil.rmtree(mgear_install_path)

    # -- now let's get mgear up and running
    # -- add to the system path
    if not os.path.join(install_path, "scripts") in sys.path:
        sys.path.append(os.path.join(install_path, "scripts"))

    if custom_path:
        # -- we look for the Maya.env file and write the path to it
        env_file = os.path.normpath(os.path.join(
            os.environ["MAYA_APP_DIR"], pm.about(version=True), "Maya.env"))
        if os.path.exists(env_file):
            f = open(env_file, "w")
            f.write("MAYA_MODULE_PATH={0}".format(install_path))
            f.close()

        # -- custom install dialog message
        message = ("A re-start of Maya will be required after this setup.")

        # -- custom install dialog window
        input = pm.confirmDialog(title="Custom Install Path Restart",
                                 message=message,
                                 icon="information",
                                 button=["OK"])

    # -- if not a custom install we can load in the module
    else:
        # -- allows for not having to restart maya
        pm.loadModule(scan=True)
        pm.loadModule(allModules=True)

        # -- reload user setup files
        basic.executeUserSetup()

        # -- force load the plugins just incase it does not happen
        try:
            pm.loadPlugin("mgear_solvers.mll")
            pm.loadPlugin("weightDriver.mll")
        except:
            pass
        # -- installation message
        message = ("Installation Complete!")
        # -- installation dialog window
        input = pm.confirmDialog(title="Installation",
                                 message=message,
                                 icon="information",
                                 button=["OK"])

    pm.displayInfo("Installation Complete")

if is_maya:
    _dropped_install()

で動いた OK押した

インストール完了と出た。

mGearを使ってみた。001

ここからリリース版をダウンロードする。

最新版は

https://github.com/mgear-dev/mgear_dist/releases

Maya2016は

https://github.com/mgear-dev/mgear/releases/tag/v2.6.1

zip をいい感じのフォルダに解凍する

普通はここに入れるものだからここに入れる。

C:\Users\whaison\Documents\maya\マヤのバージョン\ja_JP\scripts

いれたらmGear.modのフォルダまでのパスをコピーしておく

たとえば

C:\Users\whaison\Documents\maya\2020\ja_JP\scripts\mGear\mgear_3.7.0_beta_01\release

とか

C:\Users\whaison\Documents\maya\2016\ja_JP\scripts\mGear\mgear_2.6.1

C:\Users\whaison\Documents\maya\マヤのバージョン\Maya.envを開いて

MAYA_MODULE_PATH=ここにペーストして保存する。

Mayaを起動すると、、

インストールできた

Python3.7.6とPyQt5を使ってuiファイルをロードする。

import sys
from PyQt5 import QtWidgets, uic
from PyQt5.QtGui import QPixmap
import pityna
import responder


#class MainWindow(QtWidgets.QMainWindow):
class MainWindow():
    def __init__(self):
        #super().__init__()
        self.pityna=pityna.Pityna('pityna')
        self.action=True
        #self.ui = uic.loadUi("../../qt_Pityna_Simple.ui")
        self.ui = uic.loadUi("qt_Pityna_Simple.ui")
        self.ui.label_2.setPixmap(QPixmap("img1.gif"))
        self.slotSetting()
        self.ui.show()        
    def slotSetting(self):
        self.ui.buttonTalk.clicked.connect(self.buttonTalkSlot)
        self.ui.radioButton.clicked.connect(self.showResponderName)
        self.ui.radioButton_2.clicked.connect(self.HideResponderName)
        self.ui.menuClose.triggered.connect(self.close)
    def putlog(self,str):
        self.ui.listWidgetLog.addItem(str)
    def prompt(self):
        p=self.pityna.get_name()
        if self.action==True:
            p+=':'+self.pityna.get_responder_name()
        return p+'> '
    def buttonTalkSlot(self):
        print("buttonTalkSlot")
        value= self.ui.lineEdit.text()
        if not value:
            self.ui.labelResponce.setText('なに?')
        else:
            responce=self.pityna.dialogue(value)
            self.ui.labelResponce.setText(responce)
            self.putlog('> '+value)
            self.putlog(self.prompt() + responce)
            self.ui.lineEdit.clear()
    def showResponderName(self):
        print("showResponderName")
        self.action=True
    def HideResponderName(self):
        print("HideResponderName")
        self.action=False
    def close(self):
        replay = QtWidgets.QMessageBox.question(
            self.ui, 
            '確認', 
            'プログラムを終了しますか?',
            buttons=QtWidgets.QMessageBox.Yes | 
                    QtWidgets.QMessageBox.No
            )
        if replay==QtWidgets.QMessageBox.Yes:
            #event.accept()
            self.ui.close()
        else:
            #event.ignore()
            pass
        
app = QtWidgets.QApplication(sys.argv)
MainWindow=MainWindow()
ret=app.exec()
sys.exit(ret)

https://www.mediafire.com/file/zaecgqbqjx878er/Ch5_01.zip/file

https://www.mediafire.com/file/si4atzrh6uatidf/Ch6_31templateDict.zip/file

参考リンク
https://www.learnpyqt.com/blog/pyqt5-vs-pyside2/

UE4 ひとつなぎのMayaファイルからスケルトンメッシュとアニメーションフレームを指定して読み込み python

アニメーションフレームを指定して読み込み python

python

元々読み込み可能なスケルタルメッシュを推奨します。

# coding: UTF-8
import unreal
import sys
import os
import re
import datetime
import subprocess
import uuid
unreal.log_warning("--------------chara_anim_split_importer.py--start000-----------------")
unreal.log_warning("    ")

class CharaAnimSplitImporter:

    def mainWay(self):
        unreal.log_warning("mainWay 010")
        self.AssetRegistryLoaded=False
        #----------------------------------------------------------
        unreal.log_warning("mainWay 011")
        self.tickhandle = None
        unreal.log_warning("mainWay 012")

        unreal.log_warning("mainWay 0121 10s")
        self.tickhandle = unreal.register_slate_pre_tick_callback(self.testRegistry)
        unreal.log_warning("mainWay 013 tickhandle="+str(self.tickhandle))
        #self.main_way_start2()
        #self.timeloop()
        
    def testRegistry(self,deltaTime):
        unreal.log_warning("testRegistry ticking...mainWay")
        asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
        if asset_registry.is_loading_assets():
            unreal.log_warning("still loading...mainWay")
        else:
            unreal.log_warning("ready!.....mainWay")
            if(self.AssetRegistryLoaded==False):
                self.AssetRegistryLoaded=True
                self.main_way_start2()
                
            unreal.unregister_slate_pre_tick_callback(self.tickhandle)
            unreal.unregister_slate_pre_tick_callback(self.tickhandle)


    def getUE4EXT(self,file_path):
        basename_without_ext = os.path.splitext(os.path.basename(file_path))[0]
        underBarArr=basename_without_ext.split("_")
        UE4EXT=underBarArr[0]
        return UE4EXT

    def Add_Env_Variable(self):
        #pythonDir=os.path.dirname(sys.argv[0])
        #MyDir=os.path.dirname(__file__)
        MyDir=os.path.dirname(self.get__file__())
        MyDir=os.path.abspath(MyDir)
        MyDir=re.sub(r'\\', '/', MyDir)
        #MyDir=MyDir+"/"
        MyDir=MyDir
        print("MyDir="+MyDir)
        self.MyDir=MyDir
        #K:/Test_Env_Enlighten/Tool/Environment/UnUpResourceData/
        #K:/Test_Env_Enlighten/Tool/Environment/UnUpResourceData/
        
        print("------------sys.path-------------")
        for path in sys.path:
            print("path="+path)
        print("------------sys.path-------------")
        for path in sys.path:
            path=os.path.abspath(path)
            path=re.sub(r'\\', '/', path)
            #print("path ="+path)
            #print("MyDir="+MyDir)
            if(path==MyDir or path+"/"==MyDir):
                print("Hit")
                sys.path.pop()
        print("-----------DELETED------------")
        for path in sys.path:
            print("path="+path)    
        print("-----------DELETED--------------")
        
        sys.path.append(MyDir)
        print("-----------ADDED------------")
        for path in sys.path:
            print("path="+path)    
        print("-----------ADDED--------------")


    def setting_txt_to_dict(self,myDir):
        print(" setting.txt file Open!!")
        test_data = open(myDir+'/setting.txt', "r")

        # 行ごとにすべて読み込んでリストデータにする
        lines = test_data.readlines()
        
        dict = {}
        # 一行ずつ表示する
        for line in lines:
            print(line)
            if(line.find("#")>-1):
                #print("comment line= "+line)
                pass
            elif(line=="\n"):
                pass
            else:
                lines=line.split("=")
                lines[1]=lines[1].replace('\n','')
                lines[1]=lines[1].replace('"','')
                lines[1]=lines[1].replace(' ','')
                lines[0]=lines[0].replace(' ','')
                dict[lines[0]] = lines[1]
           
        for k, v in dict.items(): # for/if文では文末のコロン「:」を忘れないように
            print("key= "+k+" ,value= "+v)
        # ファイルをクローズする
        test_data.close()
        return dict 

    def main_way_start2(self):
        self.Add_Env_Variable()
        
        myDir=self.getmyDir()
        
        myCharaPath=myDir+"Female_A_V3_GameJoint.fbx"
        
        # アニメーションフレーム範囲を読み込む
        self.loadAnimChara(myCharaPath,12,100,"Female_A_V3_GameJoint_Anim_01")
        self.loadAnimChara(myCharaPath,120,180,"Female_A_V3_GameJoint_Anim_02")
        
    def loadAnimChara(self,myCharaPath,startFrame,endFrame,AnimName):
        # FBXインポート時の設定
        mesh_data = unreal.EditorAssetLibrary.find_asset_data("/Game/Mannequin/Character/Mesh/SK_Mannequin")
        #mesh_data = unreal.EditorAssetLibrary.find_asset_data("/Game/UE4_Female_A/Female_A_V3_GameJoint.Female_A_V3_GameJoint")

        mesh = mesh_data.get_asset()
        mesh.skeleton
        
        op = unreal.FbxImportUI()
        #op.import_materials = True # マテリアルもインポート
        op.import_animations=True
        op.set_editor_property("automated_import_should_detect_type", False)
        op.set_editor_property("create_physics_asset", False)
        op.set_editor_property("import_as_skeletal", False)
        op.set_editor_property("import_materials", False)
        op.set_editor_property("import_mesh", False)
        op.set_editor_property("import_rigid_mesh", False)
        op.set_editor_property("import_textures", False)
        op.set_editor_property("is_obj_import", False)
        op.set_editor_property("mesh_type_to_import", unreal.FBXImportType.FBXIT_ANIMATION)

        #op.static_mesh_import_data.combine_meshes = True # メッシュを1つにまとめる
        op.skeleton= mesh.skeleton
        #op.set_editor_property("anim_start_frame", 12)#[Read-Only]
        #op.set_editor_property("anim_end_frame", 100)#[Read-Only]
        #anim_sequence_import_data=op.set_editor_property("anim_sequence_import_data", 100)
        anim_sequence_import_data=op.get_editor_property("anim_sequence_import_data")
        anim_sequence_import_data.set_editor_property("animation_length", unreal.FBXAnimationLengthImportType.FBXALIT_SET_RANGE)
        startEnd=unreal.Int32Interval()
        #startEnd.min=12
        #startEnd.max=100
        startEnd.set_editor_property("min", startFrame)
        startEnd.set_editor_property("max", endFrame)
        #anim_sequence_import_data.frame_import_range  = startEnd
        anim_sequence_import_data.set_editor_property("frame_import_range", startEnd)
        
        
        # FBXインポートのタスクを生成
        task = unreal.AssetImportTask()
        task.automated = True
        #task.destination_path = '/Game/UE4_Female_A_Auto/' # アセットを保存するフォルダ
        task.destination_path = '/Game/UE4_Female_A/Pose/' # アセットを保存するフォルダ
        task.destination_name = 'Female_A_V3_GameJoint' # UE4上のアセット名
        task.destination_name = AnimName # UE4上のアセット名
        task.filename = "E:/download/Sculpt_forger_Girl17_Model_Download_UE4_Checked_EyeLash/Sculpt_forger_Girl17_Model_Download_UE4_Checked_EyeLash/Female_A/Female_A_V3_GameJoint.fbx" # 読み込みたいFBXファイル名を指定する
        task.options = op

        tasks = [task]

        # タスクを実行
        # FBXとマテリアルがインポートされる
        atool = unreal.AssetToolsHelpers.get_asset_tools()
        atool.import_asset_tasks(tasks)
    
    def get__file__(self):
        # 他のファイルから呼べば__file__で取れる。
        return "E:\download\Sculpt_forger_Girl17_Model_Download_UE4_Checked_EyeLash\Sculpt_forger_Girl17_Model_Download_UE4_Checked_EyeLash\Female_A\chara_anim_split_importer.py"
    
    def getmyDir(self):
        #myDir=os.path.dirname(__file__)
        myDir=os.path.dirname(self.get__file__())
        myDir=os.path.abspath(myDir)
        myDir=re.sub(r'\\', '/', myDir)
        myDir=myDir+"/"
        print("myDir="+myDir)
        self.myDir=myDir
        return myDir
        

    def debug_Write(self,s):
        #s= self.debug_data+"\n"
        dt_now = datetime.datetime.now()
        dt_format=dt_now.strftime('%Y_%m_%d__%H_%M_%S')
        #path_w=self.getmyDir()+"/debug_un_up_resource_data_log.csv"
        path_w=self.getmyDir()+"/chara_anim_split_importer_"+dt_format+".csv"
        with open(path_w, mode='w') as f:
            f.write(s)
        
        with open(path_w) as f:
            print(f.read())
        
        
unreal.log("---------------chara_anim_split_importer.py--start class_ins Make-------------------------------")
classIns=CharaAnimSplitImporter()
unreal.log("---------------chara_anim_split_importer.py--start class_ins MainWay()-------------------------------")
classIns.mainWay()

unreal.log_warning("--------------chara_anim_split_importer.py--end000-----------------")
unreal.log_warning("  END PYTHON. ")
unreal.log_warning("  END PYTHON. ")

Hello world!

WordPress へようこそ。こちらは最初の投稿です。編集または削除し、コンテンツ作成を始めてください。