private static AnimationClip loadVMD(FileStream vmd) { AnimationClip ret = new AnimationClip(); // ヘッダー string fileSignature, modelName; loadVMDHeader(vmd, out fileSignature, out modelName); // モーションレコード数 int motionRecordSize; loadVMDMotionRecordSize(vmd, out motionRecordSize); // ループ処理 Dictionary <string, List <MotionKey> > bone_key = new Dictionary <string, List <MotionKey> >(); for (int i = 0; i < motionRecordSize; ++i) { MotionKey key = MotionKey.loadMotion(vmd); if (key.BoneName == null || key.BoneName == "") { Debug.LogWarning("Bone name is null or empty!! Skipped."); continue; } if (!bone_key.ContainsKey(key.BoneName)) { bone_key.Add(key.BoneName, new List <MotionKey>()); } bone_key[key.BoneName].Add(key); } //TODO:カメラのモーションも読み込み? //読出し終了 foreach (KeyValuePair <string, List <MotionKey> > keys in bone_key) { switch (keys.Key) { case "全ての親": createCurve_Transform(keys.Value, "Motion T", ref ret); Debug.Log("Added 全ての親"); break; } } return(ret); }
public static MotionKey loadMotion(FileStream vmd) { MotionKey key = new MotionKey(); byte[] buf = new byte[16]; int readSize; readSize = vmd.Read(buf, 0, 15); if (readSize != 15) { throw new FormatException("Key Error (Bone Name) - " + readSize.ToString() + " bytes."); } key.boneName = System.Text.Encoding.GetEncoding(932).GetString(buf, 0, 15); key.boneName = trimNull(sjis2utf8(key.boneName)); readSize = vmd.Read(buf, 0, 4); if (readSize != 4) { throw new FormatException("Key Error (Frame) - " + readSize.ToString() + " bytes."); } key.frame = BitConverter.ToInt32(buf, 0); readSize = vmd.Read(buf, 0, 12); if (readSize != 12) { throw new FormatException("Key Error (Position) - " + readSize.ToString() + " bytes."); } key.position.x = BitConverter.ToInt32(buf, 0); key.position.y = BitConverter.ToInt32(buf, 4); key.position.z = BitConverter.ToInt32(buf, 8); readSize = vmd.Read(buf, 0, 16); if (readSize != 16) { throw new FormatException("Key Error (Rotation) - " + readSize.ToString() + " bytes."); } key.rotation.x = BitConverter.ToInt32(buf, 0); key.rotation.y = BitConverter.ToInt32(buf, 4); key.rotation.z = BitConverter.ToInt32(buf, 8); key.rotation.w = BitConverter.ToInt32(buf, 8); //TODO readSize = vmd.Read(buf, 0, 16); if (readSize != 16) { throw new FormatException("Key Error (curve1) - " + readSize.ToString() + " bytes."); } readSize = vmd.Read(buf, 0, 16); if (readSize != 16) { throw new FormatException("Key Error (curve2) - " + readSize.ToString() + " bytes."); } readSize = vmd.Read(buf, 0, 16); if (readSize != 16) { throw new FormatException("Key Error (curve3) - " + readSize.ToString() + " bytes."); } readSize = vmd.Read(buf, 0, 16); if (readSize != 16) { throw new FormatException("Key Error (curve4) - " + readSize.ToString() + " bytes."); } Debug.Log("Frame = " + key.frame + ", BoneName = " + key.boneName); return(key); }