private AnimationClip initAnimationClip()
        {
            if (!animationTarget.GetComponent <AnimationSerializer>())
            {
                animationTarget.AddComponent <AnimationSerializer>();
            }

            AnimationClip clip;

            //no animation available yet for this object -> create animation
            if (animData.getAnimationClips(animationTarget) == null)
            {
                clip = new AnimationClip();
                animData.addAnimationClip(animationTarget, clip);
                animatedObjects.Add(animationTarget.GetComponent <SceneObject>());
            }
            else
            {
                clip = animData.getAnimationClips(animationTarget)[0];
            }

            return(clip);
        }
Exemplo n.º 2
0
        //!
        //! activates animation editing for the currently selected object
        //!
        public void activate()
        {
            // Debug.Log("mainController.getCurrentSelection()", mainController.getCurrentSelection().gameObject);

            isActive = true;

            mainController.ActiveMode = MainController.Mode.animationEditing;
            animationTarget           = mainController.getCurrentSelection().gameObject;

            animationTarget.GetComponent <SceneObject>().setKinematic(true, false);
            animationTarget.layer = 13;     //noPhysics layer

            //no animation available yet for this object -> create animation
            if (doCreateClip && animData.getAnimationClips(animationTarget) == null)
            {
                if (!animationTarget.GetComponent <AnimationSerializer>())
                {
                    animationTarget.AddComponent <AnimationSerializer>();
                }


                //create initial animation translation
                AnimationClip  clip        = new AnimationClip();
                AnimationCurve transXcurve = new AnimationCurve();
                AnimationCurve transYcurve = new AnimationCurve();
                AnimationCurve transZcurve = new AnimationCurve();

                // create keys at current time
                transXcurve.AddKey(new Keyframe(0, animationTarget.transform.position.x, -1, 1));
                transYcurve.AddKey(new Keyframe(0, animationTarget.transform.position.y, -1, 1));
                transZcurve.AddKey(new Keyframe(0, animationTarget.transform.position.z, -1, 1));


                /*
                 * transXcurve.AddKey(new Keyframe(1, animationTarget.transform.position.x + 1, 1, -1));
                 * transYcurve.AddKey(new Keyframe(1, animationTarget.transform.position.y + 1, 1, -1));
                 * transZcurve.AddKey(new Keyframe(1, animationTarget.transform.position.z + 1, 1, -1));
                 */

                // timeline.GetComponent<TimelineScript>().updateFrames(transXcurve,clip);
                // timeLine.updateFrames(transXcurve);

                //add animation to runtime data representation
                animData.addAnimationClip(animationTarget, clip);
                animData.addAnimationCurve(clip, typeof(Transform), "m_LocalPosition.x", transXcurve);
                animData.addAnimationCurve(clip, typeof(Transform), "m_LocalPosition.y", transYcurve);
                animData.addAnimationCurve(clip, typeof(Transform), "m_LocalPosition.z", transZcurve);


                //create initial animation Rotation curve
                AnimationCurve rotXcurve = new AnimationCurve();
                AnimationCurve rotYcurve = new AnimationCurve();
                AnimationCurve rotZcurve = new AnimationCurve();
                AnimationCurve rotWcurve = new AnimationCurve();

                // create keys at current time
                rotXcurve.AddKey(new Keyframe(0, animationTarget.transform.rotation.x, -1, 1));
                rotYcurve.AddKey(new Keyframe(0, animationTarget.transform.rotation.y, -1, 1));
                rotZcurve.AddKey(new Keyframe(0, animationTarget.transform.rotation.z, -1, 1));
                rotWcurve.AddKey(new Keyframe(0, animationTarget.transform.rotation.w, -1, 1));

                /*
                 * rotXcurve.AddKey( new Keyframe( 1, animationTarget.transform.rotation.x, -1, 1 ) );
                 * rotYcurve.AddKey( new Keyframe( 1, animationTarget.transform.rotation.y, -1, 1 ) );
                 * rotZcurve.AddKey( new Keyframe( 1, animationTarget.transform.rotation.z, -1, 1 ) );
                 * rotWcurve.AddKey( new Keyframe( 1, animationTarget.transform.rotation.w, -1, 1 ) );
                 */

                // timeline.GetComponent<TimelineScript>().updateFrames( transXcurve, clip );
                // timeLine.updateFrames( transXcurve );


                //add animation to runtime data representation
                animData.addAnimationCurve(clip, typeof(Transform), "m_LocalRotation.x", rotXcurve);
                animData.addAnimationCurve(clip, typeof(Transform), "m_LocalRotation.y", rotYcurve);
                animData.addAnimationCurve(clip, typeof(Transform), "m_LocalRotation.z", rotZcurve);
                animData.addAnimationCurve(clip, typeof(Transform), "m_LocalRotation.w", rotWcurve);

                animatedObjects.Add(animationTarget.GetComponent <SceneObject>());
            }

            animationTarget.GetComponent <SceneObject>().updateAnimationCurves();


            lineRenderer.SetVertexCount(0);
            lineRenderer.enabled = true;

            updateLine();

            updateTimelineKeys();
        }