// PMDファイルをUnity形式に変換 void BurnUnityFormatForPMD(MMD.PMD.PMDFormat format) { format.fst = this.fst; obj = new GameObject(format.name); format.caller = obj; format.shader_type = this.shader_type; MMD.PMD.PMDConverter conv = new MMD.PMD.PMDConverter(); this.mesh = conv.CreateMesh(format); // メッシュの生成・設定 this.materials = conv.CreateMaterials(format); // マテリアルの生成・設定 this.bones = conv.CreateBones(format); // ボーンの生成・設定 // バインドポーズの作成 conv.BuildingBindpose(format, this.mesh, this.materials, this.bones); obj.AddComponent <Animation>(); // アニメーションを追加 MMDEngine engine = obj.AddComponent <MMDEngine>(); // IKの登録 if (this.use_ik) { engine.ik_list = conv.EntryIKSolver(format, this.bones); } // 剛体関連 if (this.rigidFlag) { try { this.rigids = conv.CreateRigids(format, bones); conv.AssignRigidbodyToBone(format, this.bones, this.rigids); conv.SetRigidsSettings(format, this.bones, this.rigids); conv.SettingJointComponent(format, this.bones, this.rigids); // 非衝突グループ List <int>[] ignoreGroups = conv.SettingIgnoreRigidGroups(format, this.rigids); int[] groupTarget = conv.GetRigidbodyGroupTargets(format, rigids); MMDEngine.Initialize(engine, groupTarget, ignoreGroups, this.rigids); } catch { } } #if UNITY_4_0 AvatarSettingScript avt_setting = new AvatarSettingScript(format.caller); avt_setting.SettingAvatar(); #endif var window = LoadedWindow.Init(); window.Text = format.head.comment; CreatePrefab(format); EndOfScript(format); }
void LoadModel() { string file_path = AssetDatabase.GetAssetPath(pmdFile); MMD.ModelAgent model_agent = new MMD.ModelAgent(file_path); model_agent.CreatePrefab(shader_type, rigidFlag, use_mecanim, use_ik, scale, is_pmx_base_import); // 読み込み完了メッセージ var window = LoadedWindow.Init(); window.Text = string.Format( "----- model name -----\n{0}\n\n----- comment -----\n{1}", model_agent.name, model_agent.comment ); window.Show(); }
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"); } }