Example #1
0
    }    //end PLayback Method

    void Record()
    {
        rsRigidBody.isKinematic = false;
        offsetSet    = false;
        bufferOffset = 0;

        int frameNumber = Time.frameCount % bufferSize;

        //print ("Recording FrameBuffer " + frameNumber);
        keyFrames [frameNumber] = new MyKeyframe(Time.time, transform.position, transform.rotation);
    }    //end record method
Example #2
0
    //Vector3 ComputeInitialSwivelAngle(ArmInfo armInfo) {
    //    float theta;
    //    Vector3 u = new Vector3(1,0,0); //Local x axis
    //    Vector3 n = armInfo.wrist.position - armInfo.shoulder.position;
    //    Vector3 c =  HandleUtility.ProjectPointLine (armInfo.elbow.position, armInfo.shoulder.position, armInfo.wrist.position);
    //    Vector3 pcap = armInfo.elbow.position - c;
    //    Vector3 ptilda = pcap - Vector3.Dot (pcap, n) * n;
    //    theta = Mathf.Atan2(Vector3.Cross(pcap, u).magnitude , Vector3.Dot (ptilda,u));
    //    return new Vector3(theta,0,0);
    //}
    //ARminfo is passed as a transform because animation is sampled
    //We want the end effector position at the sampled time
    public void InitKeyPoints()
    {
        TorsoController torso = GetComponent<TorsoController>();
        ArmInfo[] arms = GetComponent<ArmController>().Arms;

        AssignGoalKeys();

        #if EDITORMODE

          // AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(animation[animName].clip, true);
          // Keyframe[] frames = curveDatas[0].curve.keys;

        //AnimationCurve xCurve = AnimationUtility.GetEditorCurve(animation[animName].clip,"Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm/RightHand",typeof(Transform),"m_LocalRotation.x");
        //forearm keys are fewer in number, looks better with  EMOTE
        //AnimationCurve xCurve = AnimationUtility.GetEditorCurve(animation[AnimName].clip, "Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm", typeof(Transform), "m_LocalRotation.x");
        AnimationCurve xCurve = AnimationUtility.GetEditorCurve(animation[AnimName].clip, "Hips/Spine/Spine1/RightShoulder/RightArm", typeof(Transform), "m_LocalRotation.x");

          Keyframe[] frames = xCurve.keys;

          using (StreamWriter sw = new StreamWriter("keyframes_" + AnimName + ".txt")) {
          sw.WriteLine("MyKeyTimes = new float" + "[" + frames.Length + "];");
            foreach (Keyframe kf in frames) {
                sw.WriteLine("MyKeyTimes[i++]  = " + kf.time + "f; ");
            }
        }
          Debug.Log(AnimName);
        #elif !EDITORMODE

          		//file io does not work in web player
          /*      string[] content = File.ReadAllLines("keyframes.txt");
        MyKeyframe[] frames = new MyKeyframe[content.Length];

        for (int i = 0; i < content.Length; i++) {
            frames[i] = new MyKeyframe();
            frames[i].time = float.Parse(content[i]);

        }*/
        //Will write IO operations  later
          MyKeyframe[] frames = new MyKeyframe[MyKeyTimes.Length];
        for (int i = 0; i < MyKeyTimes.Length; i++) {
            frames[i] = new MyKeyframe();
            frames[i].Time = MyKeyTimes[i];
        }

        #endif
        animation.Play(AnimName);
        int goalKeyInd = 0;

        Keys = new KeyInfo[frames.Length ];

        for(int i = 0; i < frames.Length; i++) {
            animation[AnimName].enabled = true;

        animation[AnimName].time = frames[i].Time;

        animation.Sample ();
        Keys[i] = new KeyInfo();
        Keys[i].Time = animation[AnimName].time;

        //Keys[i].Time = animation[AnimName].length * i / (frames.Length - 1); //FUNDA : If we are using equally-spaced keys. We still sample from original frames, but we change key times.
        if(i == GoalKeys[goalKeyInd]) {
            Keys[i].IsGoal = true;
            goalKeyInd++;
        }
        else if(i < GoalKeys[goalKeyInd])
            Keys[i].IsGoal = false;

        if (Keys[i].FrameNo >= FrameCnt) {
            Keys[i].FrameNo = FrameCnt - 1;
        }

        //body chain and transformation arrays for the specific animation
        BodyChain = torso.BodyChainToArray(torso.Torso.Root);
        Keys[i].BodyPos = torso.BodyPosArr(BodyChain);
        Keys[i].BodyRot = torso.BodyRotArr(BodyChain);

           /*
        BodyChain = torso.BodyChain;
        Keys[i].BodyPos = torso.BodyPos;
        Keys[i].BodyRot = torso.BodyRot;
        */
        for(int arm = 0; arm < 2; arm++) {
            Keys[i].ShoulderPos[arm] = Keys[i].ShoulderPosOrig[arm] = arms[arm].Shoulder.position;
            Keys[i].EePos[arm] = Keys[i].EePosOrig[arm] = arms[arm].Wrist.position;
            Keys[i].ElbowRot[arm] = Keys[i].ElbowRotOrig[arm] = arms[arm].Elbow.localRotation;
            Keys[i].ElbowPos[arm] = Keys[i].ElbowPosOrig[arm] = arms[arm].Elbow.position;
        }
        }

        animation.Stop(AnimName);
        animation.enabled = false;
    }
Example #3
0
    //Vector3 ComputeInitialSwivelAngle(ArmInfo armInfo) {
    //    float theta;
    //    Vector3 u = new Vector3(1,0,0); //Local x axis
    //    Vector3 n = armInfo.wrist.position - armInfo.shoulder.position;
    //    Vector3 c =  HandleUtility.ProjectPointLine (armInfo.elbow.position, armInfo.shoulder.position, armInfo.wrist.position);
    //    Vector3 pcap = armInfo.elbow.position - c;
    //    Vector3 ptilda = pcap - Vector3.Dot (pcap, n) * n;
    //    theta = Mathf.Atan2(Vector3.Cross(pcap, u).magnitude , Vector3.Dot (ptilda,u));
    //    return new Vector3(theta,0,0);

    //}

    //ARminfo is passed as a transform because animation is sampled
    //We want the end effector position at the sampled time

    public void InitKeyPoints()
    {
        TorsoController torso = GetComponent <TorsoController>();

        ArmInfo[] arms = GetComponent <ArmController>().Arms;

        AssignGoalKeys();

#if EDITORMODE
        // AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(animation[animName].clip, true);
        // Keyframe[] frames = curveDatas[0].curve.keys;

        //AnimationCurve xCurve = AnimationUtility.GetEditorCurve(animation[animName].clip,"Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm/RightHand",typeof(Transform),"m_LocalRotation.x");
        //forearm keys are fewer in number, looks better with  EMOTE
        //AnimationCurve xCurve = AnimationUtility.GetEditorCurve(animation[AnimName].clip, "Hips/Spine/Spine1/RightShoulder/RightArm/RightForeArm", typeof(Transform), "m_LocalRotation.x");
        AnimationCurve xCurve = AnimationUtility.GetEditorCurve(animation[AnimName].clip, "Hips/Spine/Spine1/RightShoulder/RightArm", typeof(Transform), "m_LocalRotation.x");

        Keyframe[] frames = xCurve.keys;

        using (StreamWriter sw = new StreamWriter("keyframes_" + AnimName + ".txt")) {
            sw.WriteLine("MyKeyTimes = new float" + "[" + frames.Length + "];");
            foreach (Keyframe kf in frames)
            {
                sw.WriteLine("MyKeyTimes[i++]  = " + kf.time + "f; ");
            }
        }
        Debug.Log(AnimName);
#elif !EDITORMODE
        //file io does not work in web player

        /*      string[] content = File.ReadAllLines("keyframes.txt");
         *    MyKeyframe[] frames = new MyKeyframe[content.Length];
         *
         *
         *    for (int i = 0; i < content.Length; i++) {
         *        frames[i] = new MyKeyframe();
         *        frames[i].time = float.Parse(content[i]);
         *
         *    }*/
        //Will write IO operations  later
        MyKeyframe[] frames = new MyKeyframe[MyKeyTimes.Length];
        for (int i = 0; i < MyKeyTimes.Length; i++)
        {
            frames[i]      = new MyKeyframe();
            frames[i].Time = MyKeyTimes[i];
        }
#endif
        animation.Play(AnimName);
        int goalKeyInd = 0;

        Keys = new KeyInfo[frames.Length];

        for (int i = 0; i < frames.Length; i++)
        {
            animation[AnimName].enabled = true;

            animation[AnimName].time = frames[i].Time;


            animation.Sample();
            Keys[i]      = new KeyInfo();
            Keys[i].Time = animation[AnimName].time;

            //Keys[i].Time = animation[AnimName].length * i / (frames.Length - 1); //FUNDA : If we are using equally-spaced keys. We still sample from original frames, but we change key times.
            if (i == GoalKeys[goalKeyInd])
            {
                Keys[i].IsGoal = true;
                goalKeyInd++;
            }
            else if (i < GoalKeys[goalKeyInd])
            {
                Keys[i].IsGoal = false;
            }

            if (Keys[i].FrameNo >= FrameCnt)
            {
                Keys[i].FrameNo = FrameCnt - 1;
            }



            //body chain and transformation arrays for the specific animation
            BodyChain       = torso.BodyChainToArray(torso.Torso.Root);
            Keys[i].BodyPos = torso.BodyPosArr(BodyChain);
            Keys[i].BodyRot = torso.BodyRotArr(BodyChain);



            /*
             * BodyChain = torso.BodyChain;
             * Keys[i].BodyPos = torso.BodyPos;
             * Keys[i].BodyRot = torso.BodyRot;
             */
            for (int arm = 0; arm < 2; arm++)
            {
                Keys[i].ShoulderPos[arm] = Keys[i].ShoulderPosOrig[arm] = arms[arm].Shoulder.position;
                Keys[i].EePos[arm]       = Keys[i].EePosOrig[arm] = arms[arm].Wrist.position;
                Keys[i].ElbowRot[arm]    = Keys[i].ElbowRotOrig[arm] = arms[arm].Elbow.localRotation;
                Keys[i].ElbowPos[arm]    = Keys[i].ElbowPosOrig[arm] = arms[arm].Elbow.position;
            }
        }


        animation.Stop(AnimName);
        animation.enabled = false;
    }
Example #4
0
    private void Record()
    {
        _rigidBody.isKinematic = false;

        int frame = Time.frameCount % BufferFrames;
        float time = Time.deltaTime;

        Debug.Log("Writing frame " + frame);

        _keyFrames[frame] = new MyKeyframe(time, transform.position, transform.rotation);
    }