Exemple #1
0
 public PerformanceType(PoseAnimation aAnim, PType aType)
 {
     PA         = aAnim;
     PT         = aType;
     Offset     = 0;
     BPM        = 0;
     ChangeTime = 4;
 }
Exemple #2
0
    public static PoseAnimation load_from_folder(string aFolder)
    {
        Debug.Log("trying to load poses from folder " + aFolder);
        PoseAnimation r = new PoseAnimation();

        //Debug.Log(Directory.GetFiles(aFolder).Where(e => Path.GetExtension(e) == ".txt").Count());
        foreach (string e in Directory.GetFiles(aFolder).Where(e => System.IO.Path.GetExtension(e) == ".txt"))
        {
            //string text = (new StreamReader(e)).ReadToEnd();
            r.poses.Add(ProGrading.from_file(e));
        }
        return(r);
    }
 public void set_pose_animation(PoseAnimation aAnim, int aDiff)
 {
     if (aAnim.poses.Count > 0)
     {
         mCurrentPoseAnimation    = aAnim.Clone();
         NGM.CurrentPoseAnimation = new PerformanceType(aAnim, new CharacterIndex(2, 0)); //forces it to be switch
         NGM.CurrentPoseAnimation.set_change_time(GameConstants.difficultyToChangeTime [aDiff]);
         NGM.CurrentPoseAnimation.PT         = mLastPoseMode;
         NGM.CurrentPoseAnimation.ChangeTime = mLastPoseSpeed;
         set_pose_index(0);
     }
     else
     {
         Gui.ErrorMessage = "ERROR: trying to set pose animation with no poses. Report to Peter if you get this message!";
     }
 }
    //functions for AuthoringGuiBehaviour to call
    public void load_char_from_folder(CharacterIndex aChar, int aDiff)
    {
        var aFolder = "POSETEST/" + aChar.StringIdentifier + "_" + aDiff;

        //string[] dirs = System.IO.Directory.GetDirectories("POSETEST");
        //string dir = System.IO.Directory.GetDirectories("POSETEST").FirstOrDefault(e => e == aFolder);
        //if(dir != null && dir != "")
        if (System.IO.Directory.Exists(aFolder))
        {
            set_pose_animation(PoseAnimation.load_from_folder(aFolder), aDiff);
        }
        else
        {
            Gui.ErrorMessage = "ERROR: poses do not exist for " + aChar.StringIdentifier + " diff " + aDiff;
        }
    }
Exemple #5
0
    public PerformanceType(PoseAnimation aAnim, CharacterIndex aIndex)
    {
        PA         = aAnim;
        PT         = PType.SWITCH;
        Offset     = 0;
        BPM        = 0;
        ChangeTime = 4;

        /*
         * if(aIndex.LevelIndex == 0 || aIndex.LevelIndex == 1 || aIndex.LevelIndex == 7 )
         *      PT = PType.STATIC;
         * if(aIndex.LevelIndex == 2 || aIndex.LevelIndex == 6 )
         *      PT = PType.SWITCH;
         * if(aIndex.LevelIndex == 3 || aIndex.LevelIndex == 5 )
         *      PT = PType.SLOW;
         * if(aIndex.LevelIndex == 4)
         *      PT = PType.SLOWSWITCH;*/
    }
    public PoseAnimation get_pose(CharacterIndex aIndex, int aDiff)
    {
        PoseAnimation r = new PoseAnimation();

        if (mPoses.ContainsKey(construct_pose_string(aIndex, aDiff, 1)))
        {
            for (int stage = 1; ; stage++)
            {
                string find = construct_pose_string(aIndex, aDiff, stage);
                if (mPoses.ContainsKey(find))
                {
                    r.poses.Add(mPoses[find]);
                }
                else
                {
                    break;
                }
            }
            return(r);
        }

        /*else if(aIndex.Choice > 0)
         * {
         *      Debug.Log ("grabbed fallback for " + construct_pose_string(aIndex,aDiff,1));
         *      CharacterIndex fallback = new CharacterIndex(aIndex.LevelIndex,aIndex.Choice-1);
         *      return get_pose(fallback,aDiff);
         * }*/
        else if (aIndex.LevelIndex > 1)
        {
            Debug.Log("grabbed fallback for " + construct_pose_string(aIndex, aDiff, 1));
            CharacterIndex fallback = new CharacterIndex(aIndex.LevelIndex - 1, aIndex.Choice);
            return(get_pose(fallback, aDiff));
        }
        else
        {
            r.poses.Add(mManager.mReferences.mCheapPose.to_pose());
            return(r);
        }
    }
Exemple #7
0
        public PoseAnimation GetIkLessPoseAnimation(PmdModel pmdModel, Func <double, bool> progressHook)
        {
            var curves     = GetBoneCurves();
            var ikArmature = pmdModel.GetIkArmature();
            var ikPose     = new IKPose();
            var pose       = new Pose();

            var iterators = new Dictionary <string, IEnumerator <ControlPoint <JointChange> > >();

            foreach (var item in curves)
            {
                var boneName = item.Key;
                var curve    = item.Value;
                iterators[boneName] = curve.GetControlPointIterator();
            }

            var frames = new Dictionary <string, ControlPoint <JointChange> >();

            foreach (var item in iterators)
            {
                var boneName = item.Key;
                var iterator = item.Value;
                if (iterator.MoveNext())
                {
                    frames[boneName] = iterator.Current;
                }
            }

            var ikJointCurves = new Dictionary <string, Polyline <JointChange> >();

            foreach (var ikJoint in ikArmature.GetIkJoints())
            {
                ikJointCurves[ikJoint.Name] = new Polyline_JointChange();
            }

            while (frames.Count > 0)
            {
                var earliestTime = 1e20f;
                foreach (var item in frames)
                {
                    var boneName = item.Key;
                    var frame    = item.Value;
                    if (frame.Time < earliestTime)
                    {
                        earliestTime = frame.Time;
                    }
                }

                var vpd_pose = GetVpdPose(curves, pmdModel, earliestTime);
                pose = pmdModel.GetIkLessPose(vpd_pose);

                foreach (var item in ikJointCurves)
                {
                    var ikJointName = item.Key;
                    var curve       = item.Value;
                    curve.SetControlPoint(earliestTime, pose.GetJointChange(ikJointName));
                }

                var boneNamesWithEarliestTime = new List <string>();
                foreach (var item in frames)
                {
                    var boneName = item.Key;
                    var frame    = item.Value;
                    if (Math.Abs(frame.Time - earliestTime) < 0.0001)
                    {
                        boneNamesWithEarliestTime.Add(boneName);
                    }
                }

                foreach (var boneName in boneNamesWithEarliestTime)
                {
                    var iterator = iterators[boneName];
                    if (iterator.MoveNext())
                    {
                        frames[boneName] = iterator.Current;
                    }
                    else
                    {
                        frames.Remove(boneName);
                    }
                }

                if (progressHook != null)
                {
                    var continuing = progressHook(earliestTime);
                    if (!continuing)
                    {
                        return(null);
                    }
                }
            }

            var poseAnimation = new PoseAnimation();

            curves = new Dictionary <string, Polyline <JointChange> >();
            foreach (var boneFrame in boneFrames)
            {
                if (!curves.ContainsKey(boneFrame.BoneName))
                {
                    curves[boneFrame.BoneName] = new Polyline_JointChange();
                }
                var position = new Vector3D(boneFrame.Position.X, boneFrame.Position.Y, -boneFrame.Position.Z);
                // var z_flip_matrix = matrix4x4.scale(1, 1, -1);
                var orientation = new Quaternion(boneFrame.Orientation.X,
                                                 boneFrame.Orientation.Y,
                                                 -boneFrame.Orientation.Z,
                                                 -boneFrame.Orientation.W);
                curves[boneFrame.BoneName].SetControlPoint(boneFrame.FrameNumber,
                                                           new JointChange(position, orientation));
            }
            foreach (var item in curves)
            {
                var boneName = item.Key;
                var curve    = item.Value;
                if (pmdModel.BonesByName.ContainsKey(boneName))
                {
                    var bone = pmdModel.GetBoneByName(boneName);
                    if (bone.BoneType != Bone.BONE_IK)
                    {
                        poseAnimation.SetJointCurve(boneName, curve);
                    }
                }
            }
            foreach (var item in ikJointCurves)
            {
                var boneName     = item.Key;
                var ikJointCurve = item.Value;
                poseAnimation.SetJointCurve(boneName, ikJointCurve);
            }

            foreach (var bone in pmdModel.Bones)
            {
                if (bone.BoneType == Bone.BONE_ROTATION_INFLUENCED)
                {
                    var sourceBone = pmdModel.Bones.ElementAt(bone.IkBoneIndex);
                    var boneCurve  = new Polyline_JointChange();
                    if (curves.ContainsKey(sourceBone.Name))
                    {
                        var sourceCurve = curves[sourceBone.Name];
                        foreach (var controlPoint in sourceCurve.GetControlPoints())
                        {
                            var time = controlPoint.Time;
                            var jc   = controlPoint.Value;
                            boneCurve.SetControlPoint(time, new JointChange(new Vector3D(0, 0, 0), jc.Orientation));
                        }
                    }
                    poseAnimation.SetJointCurve(bone.Name, boneCurve);
                }
            }
            poseAnimation.UpdateRange();
            return(poseAnimation);
        }