示例#1
0
 internal static Dictionary<string, List<MMDFaceKeyFrame>> SplitFaceMotion(MMDFaceKeyFrame[] keyframes)
 {
     Dictionary<string, List<MMDFaceKeyFrame>> result = new Dictionary<string, List<MMDFaceKeyFrame>>();
     foreach (var keyframe in keyframes)
     {
         if (!result.ContainsKey(keyframe.FaceName))
             result.Add(keyframe.FaceName, new List<MMDFaceKeyFrame>());
         result[keyframe.FaceName].Add(keyframe);
     }
     foreach (var boneframes in result)
     {
         boneframes.Value.Sort((x, y) => (int)((long)x.FrameNo - (long)y.FrameNo));
     }
     return result;
 }
示例#2
0
        internal static MMDMotion Convert(MikuMikuDance.Motion.Motion2.MMDMotion2 input)
        {
            MMDMotion result = new MMDMotion();

            //ボーンモーションデータの変換
            MMDBoneKeyFrame[] BoneFrames = new MMDBoneKeyFrame[input.Motions.LongLength];
            for (long i = 0; i < input.Motions.LongLength; i++)
            {
                BoneFrames[i]          = new MMDBoneKeyFrame();
                BoneFrames[i].BoneName = input.Motions[i].BoneName;
                BoneFrames[i].FrameNo  = input.Motions[i].FrameNo;

                BoneFrames[i].Curve = new BezierCurve[4];
                for (int j = 0; j < BoneFrames[i].Curve.Length; j++)
                {
                    BezierCurve curve = new BezierCurve();
                    curve.v1 = new Vector2((float)input.Motions[i].Interpolation[0][0][j] / 128f, (float)input.Motions[i].Interpolation[0][1][j] / 128f);
                    curve.v2 = new Vector2((float)input.Motions[i].Interpolation[0][2][j] / 128f, (float)input.Motions[i].Interpolation[0][3][j] / 128f);
                    BoneFrames[i].Curve[j] = curve;
                }
                BoneFrames[i].Scales    = new Vector3(1, 1, 1);
                BoneFrames[i].Location  = new Vector3((decimal)input.Motions[i].Location[0], (decimal)input.Motions[i].Location[1], (decimal)input.Motions[i].Location[2]);
                BoneFrames[i].Quatanion = new Quaternion((decimal)input.Motions[i].Quatanion[0], (decimal)input.Motions[i].Quatanion[1], (decimal)input.Motions[i].Quatanion[2], (decimal)input.Motions[i].Quatanion[3]);
                BoneFrames[i].Quatanion.Normalize();
            }
            result.BoneFrames = MotionHelper.SplitBoneMotion(BoneFrames);
            //表情モーションの変換
            MMDFaceKeyFrame[] FaceFrames = new MMDFaceKeyFrame[input.FaceMotions.LongLength];
            for (long i = 0; i < input.FaceMotions.Length; i++)
            {
                FaceFrames[i]          = new MMDFaceKeyFrame();
                FaceFrames[i].Rate     = input.FaceMotions[i].Rate;
                FaceFrames[i].FaceName = input.FaceMotions[i].FaceName;
                FaceFrames[i].FrameNo  = input.FaceMotions[i].FrameNo;
                float temp = input.FaceMotions[i].FrameNo;
            }
            result.FaceFrames = MotionHelper.SplitFaceMotion(FaceFrames);
            //カメラモーションは無視(使わんので)
            //ライトモーションは無視(使わんので)
            //変換したデータを返却
            return(result);
        }
示例#3
0
        internal static MMDMotion Convert(MikuMikuDance.Motion.Motion2.MMDMotion2 input)
        {
            MMDMotion result = new MMDMotion();
            //ボーンモーションデータの変換
            MMDBoneKeyFrame[] BoneFrames = new MMDBoneKeyFrame[input.Motions.LongLength];
            for (long i = 0; i < input.Motions.LongLength; i++)
            {
                BoneFrames[i] = new MMDBoneKeyFrame();
                BoneFrames[i].BoneName = input.Motions[i].BoneName;
                BoneFrames[i].FrameNo = input.Motions[i].FrameNo;

                BoneFrames[i].Curve = new BezierCurve[4];
                for (int j = 0; j < BoneFrames[i].Curve.Length; j++)
                {
                    BezierCurve curve = new BezierCurve();
                    curve.v1 = new Vector2((float)input.Motions[i].Interpolation[0][0][j] / 128f, (float)input.Motions[i].Interpolation[0][1][j] / 128f);
                    curve.v2 = new Vector2((float)input.Motions[i].Interpolation[0][2][j] / 128f, (float)input.Motions[i].Interpolation[0][3][j] / 128f);
                    BoneFrames[i].Curve[j] = curve;
                }
                BoneFrames[i].Scales = new Vector3(1, 1, 1);
                BoneFrames[i].Location = new Vector3((decimal)input.Motions[i].Location[0], (decimal)input.Motions[i].Location[1], (decimal)input.Motions[i].Location[2]);
                BoneFrames[i].Quatanion = new Quaternion((decimal)input.Motions[i].Quatanion[0], (decimal)input.Motions[i].Quatanion[1], (decimal)input.Motions[i].Quatanion[2], (decimal)input.Motions[i].Quatanion[3]);
                BoneFrames[i].Quatanion.Normalize();
            }
            result.BoneFrames = MotionHelper.SplitBoneMotion(BoneFrames);
            //表情モーションの変換
            MMDFaceKeyFrame[] FaceFrames = new MMDFaceKeyFrame[input.FaceMotions.LongLength];
            for (long i = 0; i < input.FaceMotions.Length; i++)
            {
                FaceFrames[i] = new MMDFaceKeyFrame();
                FaceFrames[i].Rate = input.FaceMotions[i].Rate;
                FaceFrames[i].FaceName = input.FaceMotions[i].FaceName;
                FaceFrames[i].FrameNo = input.FaceMotions[i].FrameNo;
                float temp = input.FaceMotions[i].FrameNo;
            }
            result.FaceFrames = MotionHelper.SplitFaceMotion(FaceFrames);
            //カメラモーションは無視(使わんので)
            //ライトモーションは無視(使わんので)
            //変換したデータを返却
            return result;
        }
示例#4
0
 /// <summary>
 /// 表情の補完
 /// </summary>
 /// <param name="frame1">フレーム1</param>
 /// <param name="frame2">フレーム2</param>
 /// <param name="progress">進行度合い</param>
 /// <returns>表情適用量</returns>
 public static float Lerp(MMDFaceKeyFrame frame1, MMDFaceKeyFrame frame2, float progress)
 {
     return MathHelper.Lerp(frame1.Rate, frame2.Rate, progress);
 }
 /// <summary>
 /// 表情の補完
 /// </summary>
 /// <param name="frame1">フレーム1</param>
 /// <param name="frame2">フレーム2</param>
 /// <param name="progress">進行度合い</param>
 /// <returns>表情適用量</returns>
 public static float Lerp(MMDFaceKeyFrame frame1, MMDFaceKeyFrame frame2, float progress)
 {
     return(MathHelper.Lerp(frame1.Rate, frame2.Rate, progress));
 }