Beispiel #1
0
        //!
        //! updates the saved animation curve's keyframe with the current values of the keyframe in the GUI
        //! this is called when repositioning the keyframe
        //!
        public void updateKeyInCurve()
        {
            AnimationCurve transXcurve = animData.getAnimationCurve(clip, "m_LocalPosition.x");
            AnimationCurve transYcurve = animData.getAnimationCurve(clip, "m_LocalPosition.y");
            AnimationCurve transZcurve = animData.getAnimationCurve(clip, "m_LocalPosition.z");

            transXcurve.MoveKey(keyFrameNumber, new Keyframe(transXcurve.keys[keyFrameNumber].time, this.transform.position.x, transXcurve.keys[keyFrameNumber].inTangent, transXcurve.keys[keyFrameNumber].outTangent));
            transYcurve.MoveKey(keyFrameNumber, new Keyframe(transYcurve.keys[keyFrameNumber].time, this.transform.position.y, transYcurve.keys[keyFrameNumber].inTangent, transYcurve.keys[keyFrameNumber].outTangent));
            transZcurve.MoveKey(keyFrameNumber, new Keyframe(transZcurve.keys[keyFrameNumber].time, this.transform.position.z, transZcurve.keys[keyFrameNumber].inTangent, transZcurve.keys[keyFrameNumber].outTangent));

            animData.changeAnimationCurve(clip, typeof(Transform), "m_LocalPosition.x", transXcurve);
            animData.changeAnimationCurve(clip, typeof(Transform), "m_LocalPosition.y", transYcurve);
            animData.changeAnimationCurve(clip, typeof(Transform), "m_LocalPosition.z", transZcurve);
        }
Beispiel #2
0
        //!
        //! update the animation curves
        //! normally called after the animation curve has changed
        //!
        public void updateAnimationCurves()
        {
            if (animData.getAnimationClips(target.gameObject) != null)
            {
                transCurves[0] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalPosition.x");
                transCurves[1] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalPosition.y");
                transCurves[2] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalPosition.z");

                rotationCurves[0] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.x");
                rotationCurves[1] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.y");
                rotationCurves[2] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.z");
                rotationCurves[3] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalRotation.w");

                scaleCurves[0] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalScale.x");
                scaleCurves[1] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalScale.y");
                scaleCurves[2] = animData.getAnimationCurve(animData.getAnimationClips(target.gameObject)[0], "m_LocalScale.z");

                // TODO: fix one length for all curves
                animationDuration = animData.getAnimationClips(target.gameObject)[0].length;
                setAnimationState(animationController.currentAnimationTime);
            }
        }
Beispiel #3
0
        //!
        //! updates the rendered line (animation path)
        //!
        private void updateLine()
        {
            print("updateLine");
            if (animData.getAnimationClips(animationTarget) != null)
            {
                foreach (AnimationClip clip in animData.getAnimationClips(animationTarget))
                {
                    //! AnimationCurves for X, Y and Z Translation of this clip
                    AnimationCurve transXcurve = animData.getAnimationCurve(clip, "m_LocalPosition.x");
                    AnimationCurve transYcurve = animData.getAnimationCurve(clip, "m_LocalPosition.y");
                    AnimationCurve transZcurve = animData.getAnimationCurve(clip, "m_LocalPosition.z");

                    int pointCount = 0;
                    List <Vector3[]> pointArraysList = new List <Vector3[]>(0);

                    for (int i = 0; i <= transXcurve.keys.Length - 1; i++)
                    {
                        if (i != transXcurve.keys.Length - 1)
                        {
                            Vector3[] pointArray = getHermiteInterpolationLine(transXcurve.keys[i], transYcurve.keys[i], transZcurve.keys[i], transXcurve.keys[i + 1], transYcurve.keys[i + 1], transZcurve.keys[i + 1]);
                            pointArraysList.Add(pointArray);
                            pointCount += pointArray.Length;
                        }
                        if (i < keyframeSpheres.Count)
                        {
                            keyframeSpheres[i].transform.position = new Vector3(transXcurve.keys[i].value, transYcurve.keys[i].value, transZcurve.keys[i].value);
                        }
                        else
                        {
                            GameObject sphere = GameObject.Instantiate <GameObject>(keySpherePrefab);
                            sphere.transform.position   = new Vector3(transXcurve.keys[i].value, transYcurve.keys[i].value, transZcurve.keys[i].value);
                            sphere.transform.localScale = new Vector3(keyHandleScale, keyHandleScale, keyHandleScale);
                            sphere.transform.parent     = frameSphereContainer.transform;
                            sphere.layer = 13;
                            sphere.name  = i.ToString();
                            keyframeSpheres.Add(sphere);
                        }
                    }
                    if (transXcurve.keys.Length < keyframeSpheres.Count)
                    {
                        for (int i = transXcurve.keys.Length; i < keyframeSpheres.Count; i++)
                        {
                            Destroy(keyframeSpheres[i], 0);
                        }
                        keyframeSpheres.RemoveRange(transXcurve.keys.Length, keyframeSpheres.Count - transXcurve.keys.Length);
                    }

                    lineRenderer.SetVertexCount(pointCount);
                    int     currentPosition = 0;
                    Vector3 lastPoint       = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

                    for (int i = 0; i < pointArraysList.Count; i++)
                    {
                        for (int j = 0; j < pointArraysList[i].Length; j++)
                        {
                            if (lastPoint != pointArraysList[i][j])
                            {
                                lineRenderer.SetPosition(currentPosition, pointArraysList[i][j]);
                                lastPoint = pointArraysList[i][j];
                                currentPosition++;
                            }
                            else
                            {
                                pointCount--;
                                lineRenderer.SetVertexCount(pointCount);
                            }
                        }
                    }
                }
            }
        }
        public void setKeyFrame()
        {
            currentAnimationTime = timeLine.CurrentTime;

            if (animationTarget != null)
            {
                AnimationClip clip = initAnimationClip();



                // add animation curves if not there already
                if (animData.getAnimationCurve(clip, animationProperties[0]) == null)
                {
                    foreach (string prop in animationProperties)
                    {
                        // add property curve
                        AnimationCurve _curve = new AnimationCurve();

                        //add curve to runtime data representation
                        animData.addAnimationCurve(clip, typeof(Transform), prop, _curve);
                    }
                }


                for (int n = 0; n < animationProperties.Length; n++)
                {
                    // named property in curve
                    string prop = animationProperties[n];
                    // property delegate
                    PropertyInfo field = animationFields[n];


                    // get or create curve
                    AnimationCurve _curve = animData.getAnimationCurve(clip, prop);
                    if (_curve == null)
                    {
                        _curve = new AnimationCurve();
                    }

                    // add or move keyframe
                    bool     movedSuccessfully = false;
                    int      keyIndex          = -1;
                    Keyframe key = new Keyframe(currentAnimationTime, (float)field.GetValue(animationInstance, null));
                    for (int i = 0; i < _curve.length; i++)
                    {
                        if (Mathf.Abs(_curve.keys[i].time - currentAnimationTime) < 0.04)
                        {
                            _curve.MoveKey(i, key);
                            keyIndex          = i;
                            movedSuccessfully = true;
                        }
                    }
                    if (!movedSuccessfully)
                    {
                        keyIndex          = _curve.AddKey(key);
                        movedSuccessfully = false;
                    }
                    if (_curve.keys.Length > 1)
                    {
                        if (keyIndex == 0)
                        {
                            _curve.SmoothTangents(1, 0);
                        }
                        if (keyIndex == _curve.keys.Length - 1)
                        {
                            _curve.SmoothTangents(_curve.keys.Length - 2, 0);
                        }
                    }
                    _curve.SmoothTangents(keyIndex, 0);

                    // update animation data
                    animData.changeAnimationCurve(clip, typeof(Transform), prop, _curve);
                }

                // TODO: cheesy
                // animationTarget.GetComponent<SceneObject>().setKeyframe();
                animationTarget.GetComponent <SceneObject>().updateAnimationCurves();
                updateTimelineKeys();
                updateLine();
            }
        }