//-------------------------------------------------------------------------------- // PMDファイルの読み込み // PMDファイルをUnity形式に変換 void BurnUnityFormatForPMD() { MMD.PMD.PMDConverter conv = new MMD.PMD.PMDConverter(); GameObject obj = new GameObject(this.format.name); this.format.fst = this.fst; this.format.caller = obj; this.format.shader_type = this.shader_type; Mesh mesh = conv.CreateMesh(this.format); // メッシュの生成・設定 Material[] materials = conv.CreateMaterials(this.format); // マテリアルの生成・設定 GameObject[] bones = conv.CreateBones(this.format); // ボーンの生成・設定 // バインドポーズの作成 conv.BuildingBindpose(this.format, mesh, materials, bones); obj.AddComponent<Animation>(); // アニメーションを追加 MMDEngine engine = obj.AddComponent<MMDEngine>(); // IKの登録 if (this.use_ik) engine.ik_list = conv.EntryIKSolver(this.format, bones); // 剛体関連 if (this.rigidFlag) { try { var rigids = conv.CreateRigids(this.format, bones); conv.AssignRigidbodyToBone(this.format, bones, rigids); conv.SetRigidsSettings(this.format, bones, rigids); conv.SettingJointComponent(this.format, bones, rigids); // 非衝突グループ List<int>[] ignoreGroups = conv.SettingIgnoreRigidGroups(this.format, rigids); int[] groupTarget = conv.GetRigidbodyGroupTargets(this.format, rigids); MMDEngine.Initialize(engine, groupTarget, ignoreGroups, rigids); } catch { } } // Mecanim設定 (not work yet..) #if UNITY_4_0 || UNITY_4_1 AvatarSettingScript avt_setting = new AvatarSettingScript(this.format.caller); avt_setting.SettingAvatar(); #endif // プレファブに登録 Object prefab = PrefabUtility.CreateEmptyPrefab(this.format.folder + "/" + format.name + ".prefab"); PrefabUtility.ReplacePrefab(this.format.caller, prefab); // アセットリストの更新 AssetDatabase.Refresh(); // 一度,表示されているモデルを削除して新しくPrefabのインスタンスを作る GameObject.DestroyImmediate(obj); PrefabUtility.InstantiatePrefab(prefab); }
// 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); }
// 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>(); // アニメーションを追加 //conv.EntryIKSolver(format, this.bones); MMDEngine engine = obj.AddComponent<MMDEngine>(); // 剛体関連 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 { } } var window = LoadedWindow.Init(); window.Text = format.head.comment; CreatePrefab(format); EndOfScript(format); }
//-------------------------------------------------------------------------------- // PMDファイルの読み込み // PMDファイルをUnity形式に変換 void BurnUnityFormatForPMD() { MMD.PMD.PMDConverter conv = new MMD.PMD.PMDConverter(); GameObject obj = new GameObject(this.format.name); this.format.fst = this.fst; this.format.caller = obj; this.format.shader_type = this.shader_type; Mesh mesh = conv.CreateMesh(this.format); // メッシュの生成・設定 Material[] materials = conv.CreateMaterials(this.format); // マテリアルの生成・設定 GameObject[] bones = conv.CreateBones(this.format); // ボーンの生成・設定 // バインドポーズの作成 conv.BuildingBindpose(this.format, mesh, materials, bones); obj.AddComponent <Animation>(); // アニメーションを追加 MMDEngine engine = obj.AddComponent <MMDEngine>(); // IKの登録 if (this.use_ik) { engine.ik_list = conv.EntryIKSolver(this.format, bones); } // 剛体関連 if (this.rigidFlag) { try { var rigids = conv.CreateRigids(this.format, bones); conv.AssignRigidbodyToBone(this.format, bones, rigids); conv.SetRigidsSettings(this.format, bones, rigids); conv.SettingJointComponent(this.format, bones, rigids); // 非衝突グループ List <int>[] ignoreGroups = conv.SettingIgnoreRigidGroups(this.format, rigids); int[] groupTarget = conv.GetRigidbodyGroupTargets(this.format, rigids); MMDEngine.Initialize(engine, groupTarget, ignoreGroups, rigids); } catch { } } // Mecanim設定 (not work yet..) #if UNITY_4_0 || UNITY_4_1 AvatarSettingScript avt_setting = new AvatarSettingScript(this.format.caller); avt_setting.SettingAvatar(); #endif // プレファブに登録 Object prefab = PrefabUtility.CreateEmptyPrefab(this.format.folder + "/" + format.name + ".prefab"); PrefabUtility.ReplacePrefab(this.format.caller, prefab); // アセットリストの更新 AssetDatabase.Refresh(); // 一度,表示されているモデルを削除して新しくPrefabのインスタンスを作る GameObject.DestroyImmediate(obj); PrefabUtility.InstantiatePrefab(prefab); }