Beispiel #1
0
        /// <summary>
        ///     Create pmx from pmx list
        /// </summary>
        private void CreatePmx()
        {
            var       model_agent = new ModelAgent(Statement.PmxFiles[Statement.CurrentPmx]);
            PMXFormat pmx_format;

            try
            {
                //PMX読み込みを試みる
                pmx_format = PMXLoaderScript.Import(model_agent.file_path_);
            }
            catch
            {
                //PMXとして読み込めなかったら
                //PMDとして読み込む
                var pmd_format = PMDLoaderScript.Import(model_agent.file_path_);
                pmx_format = PMXLoaderScript.PMD2PMX(pmd_format);
            }

            fbxGameObject = PMXConverter.CreateGameObject(pmx_format, false, PMXConverter.AnimationType.LegacyAnimation,
                                                          false, 1f);

            fbxGameObject.transform.SetParent(GameObject.Find("Parent").transform);
            fbxGameObject.transform.localScale    = new Vector3(0.085f, 0.085f, 0.085f);
            fbxGameObject.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
        }
Beispiel #2
0
        public static void LoadT()
        {
            CleanAssetDatabase();
            string path = EditorUtility.OpenFilePanel("Overwrite with png", "", "*");

            Debug.Log(path);
            var model_agent = new ModelAgent(path);

            MMD.PMX.PMXFormat pmx_format;
            try
            {
                //PMX読み込みを試みる
                pmx_format = PMXLoaderScript.Import(model_agent.file_path_);
            }
            catch
            {
                //PMXとして読み込めなかったら
                //PMDとして読み込む
                MMD.PMD.PMDFormat pmd_format = PMDLoaderScript.Import(model_agent.file_path_);
                pmx_format = PMXLoaderScript.PMD2PMX(pmd_format);
            }

            var fbxGameObject = MMD.PMXConverter.CreateGameObject(pmx_format, false, MMD.PMXConverter.AnimationType.LegacyAnimation, false, 1f);

            fbxGameObject.transform.SetParent(GameObject.Find("Parent").transform);
            fbxGameObject.transform.localScale    = new Vector3(0.085f, 0.085f, 0.085f);
            fbxGameObject.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
        }
Beispiel #3
0
        /// <summary>
        /// プレファブを作成する
        /// </summary>
        /// <param name='shader_type'>シェーダーの種類</param>
        /// <param name='use_rigidbody'>剛体を使用するか</param>
        /// <param name='animation_type'>アニメーションタイプ</param>
        /// <param name='use_ik'>IKを使用するか</param>
        /// <param name='scale'>スケール</param>
        /// <param name='is_pmx_base_import'>PMX Baseでインポートするか</param>
        public void CreatePrefab(PMDConverter.ShaderType shader_type, bool use_rigidbody, PMXConverter.AnimationType animation_type, bool use_ik, float scale, bool is_pmx_base_import)
        {
            GameObject game_object;
            string     prefab_path;

            if (is_pmx_base_import)
            {
                //PMX Baseでインポートする
                //PMXファイルのインポート
                PMX.PMXFormat pmx_format = null;
                try {
                    //PMX読み込みを試みる
                    pmx_format = PMXLoaderScript.Import(file_path_);
                } catch (System.FormatException) {
                    //PMXとして読み込めなかったら
                    //PMDとして読み込む
                    PMD.PMDFormat pmd_format = PMDLoaderScript.Import(file_path_);
                    pmx_format = PMXLoaderScript.PMD2PMX(pmd_format);
                }
                header_ = pmx_format.header;
                //ゲームオブジェクトの作成
                game_object = PMXConverter.CreateGameObject(pmx_format, use_rigidbody, animation_type, use_ik, scale);

                // プレファブパスの設定
                prefab_path = pmx_format.meta_header.folder + "/" + pmx_format.meta_header.name + ".prefab";
            }
            else
            {
                //PMXエクスポーターを使用しない
                //PMDファイルのインポート
                PMD.PMDFormat pmd_format = null;
                try {
                    //PMX読み込みを試みる
                    PMX.PMXFormat pmx_format = PMXLoaderScript.Import(file_path_);
                    pmd_format = PMXLoaderScript.PMX2PMD(pmx_format);
                } catch (System.FormatException) {
                    //PMXとして読み込めなかったら
                    //PMDとして読み込む
                    pmd_format = PMDLoaderScript.Import(file_path_);
                }
                header_ = PMXLoaderScript.PMD2PMX(pmd_format.head);

                //ゲームオブジェクトの作成
                bool use_mecanim = PMXConverter.AnimationType.LegacyAnimation == animation_type;
                game_object = PMDConverter.CreateGameObject(pmd_format, shader_type, use_rigidbody, use_mecanim, use_ik, scale);

                // プレファブパスの設定
                prefab_path = pmd_format.folder + "/" + pmd_format.name + ".prefab";
            }
            // プレファブ化
            PrefabUtility.CreatePrefab(prefab_path, game_object, ReplacePrefabOptions.ConnectToPrefab);

            // アセットリストの更新
            AssetDatabase.Refresh();
        }
Beispiel #4
0
        /// <summary>
        /// プレファブを作成する
        /// </summary>
        /// <param name='shader_type'>シェーダーの種類</param>
        /// <param name='use_rigidbody'>剛体を使用するか</param>
        /// <param name='use_mecanim'>Mecanimを使用するか</param>
        /// <param name='use_ik'>IKを使用するか</param>
        /// <param name='scale'>スケール</param>
        /// <param name='is_pmx_base_import'>PMX Baseでインポートするか</param>
        public void CreatePrefab(PMD.PMDConverter.ShaderType shader_type, bool use_rigidbody, bool use_mecanim, bool use_ik, float scale, bool is_pmx_base_import)
        {
            GameObject game_object;
            Object     prefab;

            if (is_pmx_base_import)
            {
                //PMX Baseでインポートする
                //PMXファイルのインポート
                PMX.PMXFormat format = PMXLoaderScript.Import(file_path_);
                //ゲームオブジェクトの作成
                game_object = PMXConverter.CreateGameObject(format, use_rigidbody, use_mecanim, use_ik, scale);

                // プレファブに登録
                prefab = PrefabUtility.CreateEmptyPrefab(format.meta_header.folder + "/" + format.meta_header.name + ".prefab");
            }
            else
            {
                //V2エクスポーターを使用しない
                //PMDファイルのインポート
                if (null == format_)
                {
                    //まだ読み込んでいないなら読むこむ
                    try {
                        //PMX読み込みを試みる
                        format_ = PMXLoaderScript.PmdImport(file_path_);
                    } catch (System.FormatException) {
                        //PMXとして読み込めなかったら
                        //PMDとして読み込む
                        format_ = PMDLoaderScript.Import(file_path_);
                    }
                    header_ = format_.head;
                }

                //ゲームオブジェクトの作成
                game_object = PMDConverter.CreateGameObject(format_, shader_type, use_rigidbody, use_mecanim, use_ik, scale);

                // プレファブに登録
                prefab = PrefabUtility.CreateEmptyPrefab(format_.folder + "/" + format_.name + ".prefab");
            }
            PrefabUtility.ReplacePrefab(game_object, prefab);

            // アセットリストの更新
            AssetDatabase.Refresh();

            // 一度,表示されているモデルを削除して新しくPrefabのインスタンスを作る
            GameObject.DestroyImmediate(game_object);
            PrefabUtility.InstantiatePrefab(prefab);
        }
    void OnGUI()
    {
        const int height = 20;
        int       width  = (int)position.width; // -16;

        pmdFile = EditorGUI.ObjectField(
            new Rect(0, 0, width, height), "PMD File", pmdFile, typeof(Object), false);

        // シェーダの種類
        shader_type = (ShaderType)EditorGUI.EnumPopup(new Rect(0, height, width, height), "Shader Type", shader_type);

        // 剛体を入れるかどうか
        rigidFlag = EditorGUI.Toggle(new Rect(0, height * 2, width / 2, height), "Rigidbody", rigidFlag);

        // Mecanimを使うかどうか
        use_mecanim = false;         // EditorGUI.Toggle(new Rect(0, height * 3, width / 2, height), "Use Mecanim", use_mecanim);

        // IKを使うかどうか
        use_ik = EditorGUI.Toggle(new Rect(0, height * 4, width / 2, height), "Use IK", use_ik);

        int buttonHeight = height * 5;

        if (pmdFile != null)
        {
            if (GUI.Button(new Rect(0, buttonHeight, width / 2, height), "Convert"))
            {
                var loader = new PMDLoaderScript(pmdFile, shader_type, rigidFlag, use_mecanim, use_ik);

                // 読み込み完了メッセージ
                var window = LoadedWindow.Init();
                window.Text = string.Format(
                    "----- model name -----\n{0}\n\n----- comment -----\n{1}",
                    loader.format.head.model_name,
                    loader.format.head.comment
                    );
                window.Show();

                pmdFile = null;         // 読み終わったので空にする
            }
        }
        else
        {
            EditorGUI.LabelField(new Rect(0, buttonHeight, width, height), "Missing", "Select PMD File");
        }
    }
Beispiel #6
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name='file'>読み込むファイルパス</param>
 public ModelAgent(string file_path)
 {
     if (string.IsNullOrEmpty(file_path))
     {
         throw new System.ArgumentException();
     }
     file_path_ = file_path;
     header_    = null;
     try {
         //PMX読み込みを試みる
         header_ = PMXLoaderScript.GetPmdHeader(file_path_);
     } catch (System.FormatException) {
         //PMXとして読み込めなかったら
         //PMDとして読み込む
         header_ = PMDLoaderScript.GetHeader(file_path_);
     }
     format_ = null;
 }
    void OnGUI()
    {
        const int height = 20;
        int width = (int)position.width;// -16;

        pmdFile = EditorGUI.ObjectField(
            new Rect(0, 0, width, height), "PMD File" , pmdFile, typeof(Object), false);

        // シェーダの種類
        shader_type = (ShaderType)EditorGUI.EnumPopup(new Rect(0, height, width, height), "Shader Type", shader_type);

        // 剛体を入れるかどうか
        rigidFlag = EditorGUI.Toggle(new Rect(0, height * 2, width / 2, height), "Rigidbody", rigidFlag);

        // Mecanimを使うかどうか
        use_mecanim = false; // EditorGUI.Toggle(new Rect(0, height * 3, width / 2, height), "Use Mecanim", use_mecanim);

        // IKを使うかどうか
        use_ik = EditorGUI.Toggle(new Rect(0, height * 4, width / 2, height), "Use IK", use_ik);

        int buttonHeight = height * 5;
        if (pmdFile != null) {
            if (GUI.Button(new Rect(0, buttonHeight, width / 2, height), "Convert")) {
                var loader = new PMDLoaderScript(pmdFile, shader_type, rigidFlag, use_mecanim, use_ik);

                // 読み込み完了メッセージ
                var window = LoadedWindow.Init();
                window.Text = string.Format(
                  "----- model name -----\n{0}\n\n----- comment -----\n{1}",
                  loader.format.head.model_name,
                  loader.format.head.comment
                );
                window.Show();

                pmdFile = null;		// 読み終わったので空にする
            }
        } else {
            EditorGUI.LabelField(new Rect(0, buttonHeight, width, height), "Missing", "Select PMD File");
        }
    }
        /// <summary>
        /// Create pmx from pmx list
        /// </summary>
        private void CreatePmx()
        {
            var       modelAgent = new ModelAgent(CurrentMmdObject.FilePath);
            PMXFormat pmxFormat;

            try
            {
                pmxFormat = PMXLoaderScript.Import(modelAgent.file_path_);
            }
            catch
            {
                var pmdFormat = PMDLoaderScript.Import(modelAgent.file_path_);
                pmxFormat = PMXLoaderScript.PMD2PMX(pmdFormat);
            }

            _fbxGameObject = PMXConverter.CreateGameObject(pmxFormat, false, PMXConverter.AnimationType.LegacyAnimation,
                                                           false, 1f);

            _fbxGameObject.transform.SetParent(parent.transform);
            _fbxGameObject.transform.localScale    = new Vector3(0.085f, 0.085f, 0.085f);
            _fbxGameObject.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
        }
Beispiel #9
0
    void OnGUI()
    {
        const int height = 20;
        int width = (int)position.width - 16;

        pmdFile = EditorGUI.ObjectField(
            new Rect(0, 0, width, height), "PMD File" ,pmdFile, typeof(Object));

        // シェーダの種類
        shader_type = (ShaderType)EditorGUI.EnumPopup(new Rect(0, height, width, height), "Shader Type", shader_type);

        // 剛体を入れるかどうか
        rigidFlag = EditorGUI.Toggle(new Rect(0, height * 2, width / 2, height), "Rigidbody", rigidFlag);

        int buttonHeight = height * 3;
        if (pmdFile != null) {
            if (GUI.Button(new Rect(0, buttonHeight, width / 2, height), "Convert")) {
                PMDLoaderScript pmdLoader = new PMDLoaderScript(pmdFile, shader_type, rigidFlag);
                pmdFile = null;		// 読み終わったので空にする
            }
        } else {
            EditorGUI.LabelField(new Rect(0, buttonHeight, width, height), "Missing", "Select PMD File");
        }
    }
Beispiel #10
0
	/// <summary>
	/// PMDファイルのインポート
	/// </summary>
	/// <param name='file_path'>PMDファイルのパス</param>
	/// <returns>内部形式データ</returns>
	public static PMDFormat Import(string file_path) {
		PMDLoaderScript loader = new PMDLoaderScript();
		return loader.Import_(file_path);
	}
Beispiel #11
0
	/// <summary>
	/// PMDファイルのヘッダー取得
	/// </summary>
	/// <param name='file_path'>PMDファイルのパス</param>
	/// <returns>ヘッダー</returns>
	public static PMDFormat.Header GetHeader(string file_path) {
		PMDLoaderScript loader = new PMDLoaderScript();
		return loader.GetHeader_(file_path);
	}
    /// <summary>
    /// PMDファイルのインポート
    /// </summary>
    /// <param name='file_path'>PMDファイルのパス</param>
    /// <returns>内部形式データ</returns>
    public static PMDFormat Import(string file_path)
    {
        PMDLoaderScript loader = new PMDLoaderScript();

        return(loader.Import_(file_path));
    }
    /// <summary>
    /// PMDファイルのヘッダー取得
    /// </summary>
    /// <param name='file_path'>PMDファイルのパス</param>
    /// <returns>ヘッダー</returns>
    public static PMDFormat.Header GetHeader(string file_path)
    {
        PMDLoaderScript loader = new PMDLoaderScript();

        return(loader.GetHeader_(file_path));
    }