// Use this for initialization
    void Start()
    {
        if (TardisObject != null)
        {
            TardisObject.SetActive(true);
        }
        List <AnimationAttr> listAnimations = AnimationAttr.getAnimationListsFromAssets();

        LerpManager lerpManager = null; SlerpManager slerpManager = null;

        if ((lerpManager = gameObject.GetComponent <LerpManager>()) == null)
        {
            lerpManager = gameObject.AddComponent <LerpManager>();
        }


        if ((slerpManager = gameObject.GetComponent <SlerpManager>()) == null)
        {
            slerpManager = gameObject.AddComponent <SlerpManager>();
        }

        lerpManager.Intitalize(listAnimations);
        slerpManager.Intitalize(listAnimations);

        slerpManager.StartAnimating();
        lerpManager.StartAnimating();
    }
    // Use this for initialization
    void Start()
    {
        animations.Clear();

        //get the animation per second data from the text asset
        animations.AddRange(getKeyFramesFromTextAsset());


        //Check to see if the first key entry is at time 0, for if it is, update the scene accordingly, move and rotate the object to the partiular position and delete the first entry from the queues


        AnimationAttr animationAttr = animations[0];

        if (animationAttr.time == 0)
        {
            transform.position = animationAttr.position;
            transform.rotation = animationAttr.quaternion;
            animations.RemoveAt(0);
        }


        //By now we would have the tardis at the appropriate frame for zero
        TardisObject.SetActive(true);

        //Now that we have the valid set of animations, set the lerp and slerp queues
        List <Vector3> rawPosList = animations.Select(item => item.position).ToList();


        lerpQueue  = new Queue <Vector3>(createCatmullRomSpline(rawPosList, framesBetweenEachKeyFrame, tension));
        slerpQueue = new Queue <Quaternion>(animations.Select(item => item.quaternion));

        //Now that we have the queues set up, let;s process them

        //Rotation points initialiation
        if (slerpQueue.Count > 0)
        {
            fromQuat = transform.rotation;
            toQuat   = slerpQueue.Dequeue();
            fromQuat.Normalize();
            toQuat.Normalize();
        }
        else
        {
            endOfRotationSequence = true;
        }

        startProcessing = true;
    }
    public void Intitalize(List <AnimationAttr> animations)
    {
        resetState();

        int indexNextElement = 0;

        while (!(++indexNextElement >= animations.Count))
        {
            AnimationAttr A = animations[--indexNextElement];
            AnimationAttr B = animations[++indexNextElement];

            float timerDuration = B.time - A.time;
            timerDuration = timerDuration < 0?0:timerDuration;
            //timerDuration = 1;
            Entity entity = new Entity(A.quaternion, B.quaternion, timerDuration);
            slerpEntityQueue.Enqueue(entity);
        }
    }
Esempio n. 4
0
    private void getKeyFramesFromTextAsset()
    {
        TextAsset keyframesText = Resources.Load("keyframes") as TextAsset;

        string[] keyFramesByLines = keyframesText.text.Split("\r\n".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
        foreach (string key in keyFramesByLines)
        {
            List <float> elementdetails = new List <float>();          //t,x,y,z,xa,ya,za,angle;
            string[]     sub_entries    = key.Split(new char[] { ',', ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
            foreach (string item in sub_entries)
            {
                elementdetails.Add(float.Parse(item.Trim()));
            }

            AnimationAttr animationAttr = new AnimationAttr(elementdetails[0], elementdetails[1], elementdetails[2], elementdetails[3], elementdetails[4], elementdetails[5], elementdetails[6], elementdetails[7]);
            Debug.Log(animationAttr);
            list_AnimationAttrs.Add(animationAttr);
        }
    }
Esempio n. 5
0
    private void animateAccordingToFrameData()
    {
        if (!isProcessingSet && list_AnimationAttrs.Count == 0)
        {
            //it's not lerping and the count is zero, then return
            processFinished = true;
            return;
        }

        if (!isProcessingSet)
        {
            AnimationAttr topOfStack = list_AnimationAttrs[0];
            list_AnimationAttrs.RemoveAt(0);
            startPos        = transform.position;
            endPos          = topOfStack.position;
            targetRotation  = topOfStack.quaternion;
            currentLerpTime = 0;
            isProcessingSet = true;
        }

        if (endPos != transform.position)
        {
            currentLerpTime += Time.deltaTime;
            if (currentLerpTime > lerpFactor)
            {
                currentLerpTime = lerpFactor;
            }

            float travelPerc = (currentLerpTime / lerpFactor);

            transform.position = Vector3.Lerp(startPos, endPos, calculateSmoothStep(travelPerc));
            targetRotation.Normalize();
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, calculateSmoothStep(travelPerc));

            Debug.Log(Time.time);
        }
        else
        {
            isProcessingSet = false;
        }
    }