Beispiel #1
0
    /// <summary>
    /// ボーンモーフ計算
    /// </summary>
    void ComputeBoneMorph()
    {
        if (0 < bone_morph.indices.Length)
        {
            //各表情の合成ベクトルを初期化しておく
            BoneMorph.BoneMorphParameter[] composite = new BoneMorph.BoneMorphParameter[bone_morph.source.Length];
            System.Array.Copy(bone_morph.source, composite, bone_morph.source.Length);

            // 表情ごとに計算する
            bool is_update = false;
            foreach (var morph in bone_morph.script)
            {
                if (morph.Compute(composite))
                {
                    is_update = true;
                }
            }

            // ここで計算結果を入れていく
            if (is_update)
            {
                for (int i = 0, i_max = bone_morph.indices.Length; i < i_max; ++i)
                {
                    bones[bone_morph.indices[i]].localPosition = composite[i].position;
                    bones[bone_morph.indices[i]].localRotation = composite[i].rotation;
                }
            }
        }
    }
Beispiel #2
0
 /// <summary>
 /// ボーンモーフ設定
 /// </summary>
 /// <returns>ボーンモーフスクリプト</returns>
 /// <param name='morph'>モーフのゲームオブジェクト</param>
 /// <param name='data'>PMX用モーフデータ</param>
 /// <param name='index_reverse_dictionary'>インデックス逆引き用辞書</param>
 BoneMorph AssignBoneMorph(GameObject morph, PMXFormat.MorphData data, Dictionary<uint, uint> index_reverse_dictionary)
 {
     BoneMorph result = morph.AddComponent<BoneMorph>();
     result.panel = (MorphManager.PanelType)data.handle_panel;
     result.indices = data.morph_offset.Select(x=>((PMXFormat.BoneMorphOffset)x).bone_index) //インデックスを取り出し
                                         .Select(x=>(int)index_reverse_dictionary[x]) //逆変換を掛ける
                                         .ToArray();
     result.values = data.morph_offset.Select(x=>{
                                                 PMXFormat.BoneMorphOffset y = (PMXFormat.BoneMorphOffset)x;
                                                 BoneMorph.BoneMorphParameter param = new BoneMorph.BoneMorphParameter();
                                                 param.position = y.move_value * scale_;
                                                 param.rotation = y.rotate_value;
                                                 return param;
                                             })
                                     .ToArray();
     return result;
 }
Beispiel #3
0
	/// <summary>
	/// ボーンモーフ計算
	/// </summary>
	void ComputeBoneMorph()
	{
		if (0 < bone_morph.indices.Length) {
			//各表情の合成ベクトルを初期化しておく
			BoneMorph.BoneMorphParameter[] composite = new BoneMorph.BoneMorphParameter[bone_morph.source.Length];
			System.Array.Copy(bone_morph.source, composite, bone_morph.source.Length);
	
			// 表情ごとに計算する
			bool is_update = false;
			foreach (var morph in bone_morph.script) {
				if (morph.Compute(composite)) {
					is_update = true;
				}
			}
	
			// ここで計算結果を入れていく
			if (is_update) {
				for (int i = 0, i_max = bone_morph.indices.Length; i < i_max; ++i) {
					bones[bone_morph.indices[i]].localPosition = composite[i].position;
					bones[bone_morph.indices[i]].localRotation = composite[i].rotation;
				}
			}
		}
	}
Beispiel #4
0
        /// <summary>
        /// ボーンモーフ作成
        /// </summary>
        /// <param name='morph_manager'>表情マネージャー</param>
        /// <param name='morphs'>モーフのゲームオブジェクト</param>
        void CreateBoneMorph(MorphManager morph_manager, GameObject[] morphs)
        {
            //インデックスと元データの作成
            List<uint> original_indices = format_.morph_list.morph_data.Where(x=>(PMXFormat.MorphData.MorphType.Bone == x.morph_type)) //該当モーフに絞る
                                                                        .SelectMany(x=>x.morph_offset.Select(y=>((PMXFormat.BoneMorphOffset)y).bone_index)) //インデックスの取り出しと連結
                                                                        .Distinct() //重複したインデックスの削除
                                                                        .ToList(); //ソートに向けて一旦リスト化
            original_indices.Sort(); //ソート
            int[] indices = original_indices.Select(x=>(int)x).ToArray();
            BoneMorph.BoneMorphParameter[] source = indices.Where(x=>x<format_.bone_list.bone.Length)
                                                            .Select(x=>{  //インデックスを用いて、元データをパック
                                                                    PMXFormat.Bone y = format_.bone_list.bone[x];
                                                                    BoneMorph.BoneMorphParameter result = new BoneMorph.BoneMorphParameter();
                                                                    result.position = y.bone_position;
                                                                    if (y.parent_bone_index < (uint)format_.bone_list.bone.Length) {
                                                                        //親が居たらローカル座標化
                                                                        result.position -= format_.bone_list.bone[y.parent_bone_index].bone_position;
                                                                    }
                                                                    result.position *= scale_;
                                                                    result.rotation = Quaternion.identity;
                                                                    return result;
                                                                })
                                                            .ToArray();

            //インデックス逆引き用辞書の作成
            Dictionary<uint, uint> index_reverse_dictionary = new Dictionary<uint, uint>();
            for (uint i = 0, i_max = (uint)indices.Length; i < i_max; ++i) {
                index_reverse_dictionary.Add((uint)indices[i], i);
            }

            //個別モーフスクリプトの作成
            BoneMorph[] script = Enumerable.Range(0, format_.morph_list.morph_data.Length)
                                            .Where(x=>PMXFormat.MorphData.MorphType.Bone == format_.morph_list.morph_data[x].morph_type) //該当モーフに絞る
                                            .Select(x=>AssignBoneMorph(morphs[x], format_.morph_list.morph_data[x], index_reverse_dictionary))
                                            .ToArray();

            //表情マネージャーにインデックス・元データ・スクリプトの設定
            morph_manager.bone_morph = new MorphManager.BoneMorphPack(indices, source, script);
        }