예제 #1
0
        internal static UndoPropertyModification[] HandleEulerModifications(AnimationTrack track, TimelineClip clip, AnimationClip animClip, float time, UndoPropertyModification[] mods)
        {
            if (mods.Any(x => x.currentValue.propertyPath.StartsWith(kLocalEulerHint) || x.currentValue.propertyPath.StartsWith(kLocalRotation)))
            {
                // if there is a rotational offsets, we need to strip the euler hints, since they are used by the animation recording system
                //  over the quaternion.
                var localToTrack = GetLocalToTrack(track, clip);
                if (localToTrack.rotation != Quaternion.identity)
                {
                    if (s_LastTrackWarning != track)
                    {
                        s_LastTrackWarning = track;
                        Debug.LogWarning(kRotationWarning);
                    }

                    Transform transform = mods[0].currentValue.target as Transform;
                    if (transform != null)
                    {
                        var trackToLocal = TimelineAnimationUtilities.RigidTransform.Inverse(localToTrack);
                        // since the euler angles are going to be transformed, we do a best guess at a euler that gives the shortest path
                        var quatMods  = mods.Where(x => !x.currentValue.propertyPath.StartsWith(kLocalEulerHint));
                        var eulerMods = FindBestEulerHint(trackToLocal.rotation * transform.localRotation, animClip, time, transform);
                        return(quatMods.Union(eulerMods).ToArray());
                    }
                    return(mods.Where(x => !x.currentValue.propertyPath.StartsWith(kLocalEulerHint)).ToArray());
                }
            }
            return(mods);
        }
예제 #2
0
        public static void AddAnimationTrack(int index = -1)
        {
            if (index < 0)
            {
                index = Document.Current.Animation.Tracks.Count;
            }
            Document.Current.History.DoTransaction(() => {
                var track = new AnimationTrack {
                    Id = GenerateTrackId()
                };
                Core.Operations.InsertIntoList <AnimationTrackList, AnimationTrack> .Perform(Document.Current.Animation.Tracks, index, track);
                Core.Operations.ClearRowSelection.Perform();
                Core.Operations.SelectRow.Perform(Document.Current.GetRowForObject(track));
            });

            string GenerateTrackId()
            {
                for (int i = 1; ; i++)
                {
                    var id = "Track" + i;
                    if (!Document.Current.Animation.Tracks.Any(t => t.Id == id))
                    {
                        return(id);
                    }
                }
                throw new System.Exception();
            }
        }
예제 #3
0
    public void ParseTrack()
    {
        foreach (PlayableBinding pb in director.playableAsset.outputs)
        {
            if (pb.sourceObject is AnimationTrack)
            {
                AnimationTrack track    = pb.sourceObject as AnimationTrack;
                int            cnt      = track.GetMarkerCount();
                var            tfTracks = new List <AnchorSignalEmitter>();
                var            marks    = track.GetMarkers().GetEnumerator();
                while (marks.MoveNext())
                {
                    IMarker mark = marks.Current;
                    if (mark is AnchorSignalEmitter)
                    {
                        tfTracks.Add(mark as AnchorSignalEmitter);
                    }
                }
                marks.Dispose();

                for (int i = 0; i < tfTracks.Count; i++)
                {
                    AnchorSignalEmitter sign = tfTracks[i];
                    Debug.Log(sign.time + " " + sign.position);
                }
            }
        }
    }
예제 #4
0
 public TransformKeyFrame(AnimationTrack parent, float time) : this(OgrePINVOKE.new_TransformKeyFrame(AnimationTrack.getCPtr(parent), time), true)
 {
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #5
0
        [Test] public void Basics()
        {
            AnimationTrack <float> track;

            track = new AnimationTrack <float>(0.0f, 1.0f);
            for (int i = 0; i <= 100; i++)
            {
                float time = (float)i / 100.0f;
                Assert.AreEqual(time, track[time], 0.001f);
            }
            track.ScaleToDuration(10.0f);
            for (int i = 0; i <= 100; i++)
            {
                float time = (float)i / 100.0f;
                Assert.AreEqual(time, track[10.0f * time], 0.001f);
            }

            track = new AnimationTrack <float>
            {
                { 0.5f, 10.0f },
                { 1.0f, 20.0f },
                { 1.5f, 30.0f }
            };
            Assert.AreEqual(10.0f, track[0.0f], 0.001f);
            Assert.AreEqual(30.0f, track[2.0f], 0.001f);

            track.IsLooping = true;
            Assert.AreEqual(10.0f, track[0.0f], 0.001f);
            Assert.AreEqual(10.0f, track[2.0f], 0.001f);
        }
        public static bool Do(WindowState state, TrackAsset track)
        {
            AnimationClip clipToEdit = null;

            AnimationTrack animationTrack = track as AnimationTrack;

            if (animationTrack != null)
            {
                if (!animationTrack.CanConvertToClipMode())
                {
                    return(false);
                }

                clipToEdit = animationTrack.infiniteClip;
            }
            else if (track.hasCurves)
            {
                clipToEdit = track.curves;
            }

            if (clipToEdit == null)
            {
                return(false);
            }

            var gameObject     = state.GetSceneReference(track);
            var timeController = TimelineAnimationUtilities.CreateTimeController(state, CreateTimeControlClipData(track));

            TimelineAnimationUtilities.EditAnimationClipWithTimeController(clipToEdit, timeController, gameObject);

            return(true);
        }
예제 #7
0
        public void Basics()
        {
            AnimationTrack<float> track;

            track = new AnimationTrack<float>(0.0f, 1.0f);
            for (int i = 0; i <= 100; i++)
            {
                float time = (float)i / 100.0f;
                Assert.AreEqual(time, track[time], 0.001f);
            }
            track.ScaleToDuration(10.0f);
            for (int i = 0; i <= 100; i++)
            {
                float time = (float)i / 100.0f;
                Assert.AreEqual(time, track[10.0f * time], 0.001f);
            }

            track = new AnimationTrack<float>
            {
                { 0.5f, 10.0f },
                { 1.0f, 20.0f },
                { 1.5f, 30.0f }
            };
            Assert.AreEqual(10.0f, track[0.0f], 0.001f);
            Assert.AreEqual(30.0f, track[2.0f], 0.001f);

            track.IsLooping = true;
            Assert.AreEqual(10.0f, track[0.0f], 0.001f);
            Assert.AreEqual(10.0f, track[2.0f], 0.001f);
        }
예제 #8
0
        private void UpdateDragTarget(TimelineClipGUI uiClip, Vector2 point, TimelineWindow.TimelineState state)
        {
            List <IBounds>   elementsAtPosition = Manipulator.GetElementsAtPosition(state.quadTree, point);
            TimelineTrackGUI timelineTrackGUI   = elementsAtPosition.OfType <TimelineTrackGUI>().FirstOrDefault((TimelineTrackGUI t) => MoveClip.ValidateClipDrag(t.track, uiClip.clip));

            this.m_HasValidDropTarget = (timelineTrackGUI != null && timelineTrackGUI.track.IsCompatibleWithItem(uiClip.clip));
            if (this.m_HasValidDropTarget)
            {
                AnimationTrack animationTrack = timelineTrackGUI.track as AnimationTrack;
                float          start          = state.PixelToTime(this.m_PreviewRect.get_x());
                float          end            = state.PixelToTime(this.m_PreviewRect.get_xMax());
                bool           hasValidDropTarget;
                if (animationTrack != null && animationTrack.CanConvertToClipMode())
                {
                    hasValidDropTarget = ((animationTrack.animClip.get_startTime() < start || animationTrack.animClip.get_stopTime() > end) && (start <animationTrack.animClip.get_startTime() || end> animationTrack.animClip.get_stopTime()));
                }
                else
                {
                    float num = end - start;
                    start = Math.Max(start, 0f);
                    end   = start + num;
                    hasValidDropTarget = (!timelineTrackGUI.track.clips.Any((TimelineClip x) => x.start >= (double)start && x.end <= (double)end) && !timelineTrackGUI.track.clips.Any((TimelineClip x) => (double)start >= x.start && (double)end <= x.end));
                }
                this.m_HasValidDropTarget = hasValidDropTarget;
            }
            this.m_DropTarget = ((!this.m_HasValidDropTarget) ? null : timelineTrackGUI);
        }
예제 #9
0
        private static Animation CreateAnimation(SerializableAnimation animationContent)
        {
            Animation animation = new Animation(animationContent.name);

            animation.SetLength(animationContent.length);

            foreach (SerializableTrack trackContent in animationContent.tracks)
            {
                AnimationTrack track = animation.CreateTrack(trackContent.name);

                for (int i = 0; i < trackContent.keyframes.Count; i++)
                {
                    SerializableKeyFrame keyFrameContent = trackContent.keyframes[i];
                    AnimationKeyFrame    keyFrame        = new AnimationKeyFrame
                    {
                        rotation    = keyFrameContent.rotation,
                        scale       = keyFrameContent.scale,
                        translation = keyFrameContent.translation,
                        time        = keyFrameContent.time
                    };

                    track.AddKeyFrame(keyFrame);
                }
            }

            return(animation);
        }
예제 #10
0
 private void RefreshLabels(Widget widget, AnimationTrack track)
 {
     widget.Nodes.Clear();
     foreach (var clip in track.Clips)
     {
         var clipLabel   = clip.AnimationId;
         var beginMarker = clip.FindAnimation()?.Markers.GetByFrame(clip.InFrame);
         var endMarker   = clip.FindAnimation()?.Markers.GetByFrame(clip.InFrame + clip.DurationInFrames);
         if (beginMarker != null || endMarker != null)
         {
             clipLabel +=
                 " (" + (beginMarker?.Id ?? clip.InFrame.ToString()) + ".." +
                 (endMarker?.Id ?? (clip.InFrame + clip.DurationInFrames).ToString()) + ")";
         }
         widget.AddNode(new SimpleText {
             Position     = new Vector2((clip.BeginFrame + 0.5f) * TimelineMetrics.ColWidth, 0),
             Size         = new Vector2((clip.DurationInFrames + 0.5f) * TimelineMetrics.ColWidth, widget.Height),
             Localizable  = false,
             Text         = clipLabel,
             Padding      = new Thickness(4),
             VAlignment   = VAlignment.Center,
             OverflowMode = TextOverflowMode.Ellipsis,
             Color        = ColorTheme.Current.TimelineGrid.AnimationClipLabel
         });
     }
 }
예제 #11
0
        /// <summary>
        /// Get the GameObject that the editor clip is bound to in the timeline using reflection.
        /// </summary>
        /// <param name="editorClip"></param>
        /// <returns>The GameObject bound to the editor clip or null if none.</returns>
        private static GameObject GetGameObjectBoundToEditorClip(object editorClip)
        {
            object         clipItem    = GetPropertyReflection(editorClip, "item");
            object         parentTrack = GetPropertyReflection(clipItem, "parentTrack");
            AnimationTrack animTrack   = parentTrack as AnimationTrack;

#if UNITY_2018_2_OR_NEWER
            Object animationTrackObject = UnityEditor.Timeline.TimelineEditor.inspectedDirector.GetGenericBinding(animTrack);
#else // UNITY_2018_2_OR_NEWER
            Object animationTrackObject = UnityEditor.Timeline.TimelineEditor.playableDirector.GetGenericBinding(animTrack);
#endif // UNITY_2018_2_OR_NEWER

            GameObject animationTrackGO = null;
            if (animationTrackObject is GameObject)
            {
                animationTrackGO = animationTrackObject as GameObject;
            }
            else if (animationTrackObject is Animator)
            {
                animationTrackGO = (animationTrackObject as Animator).gameObject;
            }

            if (animationTrackGO == null)
            {
                Debug.LogErrorFormat("Could not export animation track object of type {0}", animationTrackObject.GetType().Name);
                return(null);
            }
            return(animationTrackGO);
        }
예제 #12
0
        /// <summary>
        /// Get the GameObject that the editor clip is bound to in the timeline using reflection.
        /// </summary>
        /// <param name="editorClip"></param>
        /// <returns>The GameObject bound to the editor clip or null if none.</returns>
        private static GameObject GetGameObjectBoundToEditorClip(object editorClip)
        {
            var            timelineClip = GetTimelineClipFromEditorClip(editorClip);
            object         parentTrack  = timelineClip.parentTrack;
            AnimationTrack animTrack    = parentTrack as AnimationTrack;

            Object animationTrackObject = UnityEditor.Timeline.TimelineEditor.inspectedDirector.GetGenericBinding(animTrack);

            GameObject animationTrackGO = null;

            if (animationTrackObject is GameObject)
            {
                animationTrackGO = animationTrackObject as GameObject;
            }
            else if (animationTrackObject is Animator)
            {
                animationTrackGO = (animationTrackObject as Animator).gameObject;
            }

            if (animationTrackGO == null)
            {
                Debug.LogErrorFormat("Could not export animation track object of type {0}", animationTrackObject.GetType().Name);
                return(null);
            }
            return(animationTrackGO);
        }
예제 #13
0
        internal static TimelineAnimationUtilities.RigidTransform GetLocalToTrack(AnimationTrack track, TimelineClip clip)
        {
            if (track == null)
            {
                return(TimelineAnimationUtilities.RigidTransform.Compose(Vector3.zero, Quaternion.identity));
            }

            var trackPos = track.position;
            var trackRot = track.rotation;

            if (track.trackOffset == TrackOffset.ApplySceneOffsets)
            {
                trackPos = track.sceneOffsetPosition;
                trackRot = Quaternion.Euler(track.sceneOffsetRotation);
            }

            var clipWrapper   = clip == null ? null : clip.asset as AnimationPlayableAsset;
            var clipTransform = TimelineAnimationUtilities.RigidTransform.Compose(Vector3.zero, Quaternion.identity);

            if (clipWrapper != null)
            {
                clipTransform = TimelineAnimationUtilities.RigidTransform.Compose(clipWrapper.position, clipWrapper.rotation);
            }
            else
            {
                clipTransform = TimelineAnimationUtilities.RigidTransform.Compose(track.infiniteClipOffsetPosition, track.infiniteClipOffsetRotation);
            }

            var trackTransform = TimelineAnimationUtilities.RigidTransform.Compose(trackPos, trackRot);

            return(TimelineAnimationUtilities.RigidTransform.Mul(trackTransform, clipTransform));
        }
예제 #14
0
        // If we are adding to an infinite clip, strip the objects position and rotation and set it as the clip offset
        internal static void AddTrackOffset(AnimationTrack track, UndoPropertyModification[] mods, AnimationClip clip, Animator animator)
        {
            var copyTrackOffset = !track.inClipMode &&
                                  !ClipHasPositionOrRotation(clip) &&
                                  mods.Any(x => IsPositionOrRotation(x) && IsRootModification(x)) &&
                                  animator != null;

            if (copyTrackOffset)
            {
                // in scene offset mode, makes sure we have the correct initial transform set
                if (track.trackOffset == TrackOffset.ApplySceneOffsets)
                {
                    var rigidTransform = GetInitialTransform(mods, animator);
                    track.sceneOffsetPosition = rigidTransform.position;
                    track.sceneOffsetRotation = rigidTransform.rotation.eulerAngles;
                    SetPreviousPositionAndRotation(mods, animator, rigidTransform.position, rigidTransform.rotation);
                }
                else
                {
                    var rigidTransform = ComputeInitialClipOffsets(track, mods, animator);
                    track.infiniteClipOffsetPosition    = rigidTransform.position;
                    track.infiniteClipOffsetEulerAngles = rigidTransform.rotation.eulerAngles;
                }
            }
        }
 public static void ConvertToClipMode(this AnimationTrack track)
 {
     if (track.CanConvertToClipMode())
     {
         TimelineUndo.PushUndo(track, "Convert To Clip");
         if (!track.animClip.get_empty())
         {
             TimelineUndo.PushUndo(track.animClip, "Convert To Clip");
             float num = AnimationClipCurveCache.Instance.GetCurveInfo(track.animClip).keyTimes.FirstOrDefault <float>();
             track.animClip.ShiftBySeconds(-num);
             TimelineClip timelineClip = track.CreateClipFromAsset(track.animClip);
             TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, track);
             timelineClip.start = (double)num;
             timelineClip.preExtrapolationMode  = track.openClipPreExtrapolation;
             timelineClip.postExtrapolationMode = track.openClipPostExtrapolation;
             timelineClip.recordable            = true;
             if (Math.Abs(timelineClip.duration) < 1.4012984643248171E-45)
             {
                 timelineClip.duration = 1.0;
             }
             AnimationPlayableAsset animationPlayableAsset = timelineClip.asset as AnimationPlayableAsset;
             if (animationPlayableAsset)
             {
                 animationPlayableAsset.position = track.openClipOffsetPosition;
                 animationPlayableAsset.rotation = track.openClipOffsetRotation;
                 track.openClipOffsetPosition    = Vector3.get_zero();
                 track.openClipOffsetRotation    = Quaternion.get_identity();
             }
             track.CalculateExtrapolationTimes();
         }
         track.animClip = null;
         EditorUtility.SetDirty(track);
     }
 }
예제 #16
0
 private void DoOffsetManipulator()
 {
     if (base.get_targets().Length <= 1)
     {
         if (!(base.timelineWindow == null) && base.timelineWindow.state != null && !(base.timelineWindow.state.currentDirector == null))
         {
             AnimationTrack animationTrack = base.get_target() as AnimationTrack;
             if (animationTrack != null && animationTrack.applyOffsets && this.m_OffsetEditMode != TimelineAnimationUtilities.OffsetEditMode.None)
             {
                 GameObject sceneGameObject = TimelineUtility.GetSceneGameObject(base.timelineWindow.state.currentDirector, animationTrack);
                 Transform  transform       = (!(sceneGameObject != null)) ? null : sceneGameObject.get_transform();
                 TimelineAnimationUtilities.RigidTransform trackOffsets = TimelineAnimationUtilities.GetTrackOffsets(animationTrack, transform);
                 EditorGUI.BeginChangeCheck();
                 TimelineAnimationUtilities.OffsetEditMode offsetEditMode = this.m_OffsetEditMode;
                 if (offsetEditMode != TimelineAnimationUtilities.OffsetEditMode.Translation)
                 {
                     if (offsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Rotation)
                     {
                         trackOffsets.rotation = Handles.RotationHandle(trackOffsets.rotation, trackOffsets.position);
                     }
                 }
                 else
                 {
                     trackOffsets.position = Handles.PositionHandle(trackOffsets.position, (Tools.get_pivotRotation() != 1) ? trackOffsets.rotation : Quaternion.get_identity());
                 }
                 if (EditorGUI.EndChangeCheck())
                 {
                     TimelineAnimationUtilities.UpdateTrackOffset(animationTrack, transform, trackOffsets);
                     this.Evaluate();
                     base.Repaint();
                 }
             }
         }
     }
 }
예제 #17
0
        // Checks whether there are any offsets applied to a clip
        internal static bool HasOffsets(AnimationTrack track, TimelineClip clip)
        {
            if (track == null)
            {
                return(false);
            }

            bool hasClipOffsets  = false;
            bool hasTrackOffsets = false;

            var clipWrapper = clip == null ? null : clip.asset as AnimationPlayableAsset;

            if (clipWrapper != null)
            {
                hasClipOffsets |= clipWrapper.position != Vector3.zero || clipWrapper.rotation != Quaternion.identity;
            }

            if (track.trackOffset == TrackOffset.ApplySceneOffsets)
            {
                hasTrackOffsets = track.sceneOffsetPosition != Vector3.zero || track.sceneOffsetRotation != Vector3.zero;
            }
            else
            {
                hasTrackOffsets = (track.position != Vector3.zero || track.rotation != Quaternion.identity);
                if (!track.inClipMode)
                {
                    hasClipOffsets |= track.infiniteClipOffsetPosition != Vector3.zero || track.infiniteClipOffsetRotation != Quaternion.identity;
                }
            }

            return(hasTrackOffsets || hasClipOffsets);
        }
예제 #18
0
        internal static void ReapplyOffsets(UndoPropertyModification modification, AnimationTrack track, TimelineClip clip, UndoPropertyModification[] mods)
        {
            if (IsPositionOrRotation(modification))
            {
                var modifiedGO   = GetGameObjectFromModification(modification);
                var target       = TimelineAnimationUtilities.RigidTransform.Compose(modifiedGO.transform.localPosition, modifiedGO.transform.localRotation);
                var localToTrack = GetLocalToTrack(track, clip);
                var trackSpace   = TimelineAnimationUtilities.RigidTransform.Mul(localToTrack, target);

                // Update the undo call values
                var prevPos = modifiedGO.transform.localPosition;
                var prevRot = modifiedGO.transform.localRotation;
                GetPreviousPositionAndRotation(mods, ref prevPos, ref prevRot);
                var previousRigidTransform = TimelineAnimationUtilities.RigidTransform.Mul(localToTrack, TimelineAnimationUtilities.RigidTransform.Compose(prevPos, prevRot));
                SetPreviousPositionAndRotation(mods, previousRigidTransform.position, previousRigidTransform.rotation);

                var currentPos = modifiedGO.transform.localPosition;
                var currentRot = modifiedGO.transform.localRotation;
                GetCurrentPositionAndRotation(mods, ref currentPos, ref currentRot);
                var currentRigidTransform = TimelineAnimationUtilities.RigidTransform.Mul(localToTrack, TimelineAnimationUtilities.RigidTransform.Compose(currentPos, currentRot));
                SetCurrentPositionAndRotation(mods, currentRigidTransform.position, currentRigidTransform.rotation);

                modifiedGO.transform.localPosition = trackSpace.position;
                modifiedGO.transform.localRotation = trackSpace.rotation;
            }
        }
예제 #19
0
 private void UpdateInfiniteClipEditor(AnimationTrack animationTrack, TimelineWindow window)
 {
     if (animationTrack != null && this.clipCurveEditor == null && animationTrack.ShouldShowInfiniteClipEditor())
     {
         this.clipCurveEditor = new ClipCurveEditor(new InfiniteClipCurveDataSource(this), window);
     }
 }
	public void SetupVibration( string _UnitName , string _ComponentName )
	{
		GUIUpdate guiUpdate = GlobalSingleton.GetGUIUpdateComponent() ;
		if( null == guiUpdate )
			return ;
		
		GUIObjNameSet guiSet = null ;
		if( _UnitName == guiUpdate.m_SelectTargetName )
			guiSet = guiUpdate.m_SelectTargetComponentGUIObjNames ;
		else if( _UnitName == ConstName.MainCharacterObjectName )
		{
			guiSet = guiUpdate.m_MainCharacterComponentGUIObjNames ;
		}
		else
			return ;
		
		if( false == guiSet.m_ObjMap.ContainsKey( _ComponentName ) )
			return ;
		
		AnimationTrack addTrack = new AnimationTrack() ;
		addTrack.m_Object.Setup( guiSet.m_ObjMap[ _ComponentName ] );
		addTrack.m_TimeStart = Time.time ;
		if( null != guiSet.m_ObjMap[ _ComponentName ].Obj )
		{
			GUIText guiText = guiSet.m_ObjMap[ _ComponentName ].Obj.GetComponentInChildren<GUIText>() ;
			if( null != guiText )
				addTrack.m_ResumePosition = guiText.pixelOffset ;
		}
		
		m_VibrationMap[ guiSet.m_ObjMap[ _ComponentName ].Name ] = addTrack ;
	}
예제 #21
0
    public void AddAnimationTrack(AnimatedObject obj)
    {
        GameObject g = Instantiate(timeline.trackPrefab.gameObject, timeline.transform.parent);

        g.transform.rotation   = timeline.trackPrefab.transform.rotation;
        g.transform.localScale = timeline.trackPrefab.transform.localScale;

        AnimationTrack newTrack = g.GetComponent <AnimationTrack>();

        animationTracks.Add(newTrack);

        int     trackIndex       = animationTracks.IndexOf(newTrack);
        Vector3 newTrackPosition = TimelineTrackPosition(trackIndex);

        newTrack.SetUpTrackProperties(obj, newTrackPosition, timeline, trackIndex, timeline.trackPrefab.unselectedColor, timeline.trackPrefab.selectedColor);
        obj.animTrack = newTrack;

        /// add animationOwner
        GameObject trackOwner = Instantiate(timeline.timelineTrackOwnerPrefab.gameObject, timeline.transform);

        Debug.Log("created trackOwner " + trackOwner);
        trackOwner.transform.rotation   = timeline.timelineTrackOwnerPrefab.transform.rotation;
        trackOwner.transform.localScale = new Vector3(1, 1, 1);

        trackOwner.transform.localPosition = TimelineTrackOwnerPosition(trackIndex);
        TimelineTrackOwner newTrackOwner = trackOwner.GetComponent <TimelineTrackOwner>();

        newTrack.timelineTrackOwner = newTrackOwner;
        newTrackOwner.track         = newTrack;
    }
예제 #22
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyBigExplosion ();

            var spr = new Sprite (256, 128);
            //spr.AddTexture (Resource.GetTexture ("media/BigExplosion.png"));
            spr.AddTexture (new Texture ("./media/BigExplosion.png"));
            spr.SetTextureOffset (0, 0);
            spr.SetOffset (-128, -64);

            var track = new AnimationTrack ("TextureOffset", InterpolationType.Step);
            track.AddKeyframe (0, new Vector2 (0, 0));
            track.AddKeyframe (200, new Vector2 (256, 0));
            track.AddKeyframe (400, new Vector2 (512, 0));
            track.AddKeyframe (600, new Vector2 (0, 128));
            track.AddKeyframe (800, new Vector2 (256, 128));
            track.AddKeyframe (1000, new Vector2 (512, 128));
            track.AddKeyframe (1200, new Vector2 (0, 256));
            track.AddKeyframe (1400, new Vector2 (256, 256));
            track.AddKeyframe (1600, new Vector2 (512, 256));
            track.AddKeyframe (1800, new Vector2 (0, 384));
            track.AddKeyframe (2000, new Vector2 (256, 384));
            track.AddKeyframe (2200, new Vector2 (512, 384));

            cmp.clip = new AnimationClip (2400, "Fire-Animation");
            cmp.clip.AddTrack (spr, track);

            var node = new Node ();
            node.Attach (cmp);
            node.Attach (spr);

            node.Translation = pos;

            return node;
        }
예제 #23
0
    public void RemoveAnimationTrack(AnimationTrack track)
    {
        // first -> search for animation track on list
        if (animationTracks.Contains(track))
        {
            // second - > get index of track
            int trackIndex = animationTracks.IndexOf(track);
            // remove -> remove that track at that point
            animationTracks.RemoveAt(trackIndex);
            track.animatedObject.beizerPathGroup.ResetBeizerPathCurves();

            Destroy(track.gameObject);
            Destroy(track.timelineTrackOwner.gameObject);

            // recalculate track positions accordingly
            int tracksAfterTrackIndex = trackIndex + 1;

            for (int i = tracksAfterTrackIndex; i <= animationTracks.Count; i++)
            {
                Vector3 newTrackPosition      = TimelineTrackPosition(i);
                Vector3 newTrackOwnerPosition = TimelineTrackOwnerPosition(i);

                animationTracks[i].transform.localPosition = newTrackPosition;
                animationTracks[i].timelineTrackOwner.transform.localPosition = newTrackOwnerPosition;
            }
        }
    }
        // Given a track, return the animation clip
        internal static AnimationClip FindRecordingAnimationClipAtTime(this TrackAsset trackAsset, double time)
        {
            if (trackAsset == null)
                return null;

            AnimationTrack animTrack = trackAsset as AnimationTrack;
            if (animTrack != null && !animTrack.inClipMode)
            {
                return animTrack.infiniteClip;
            }

            TimelineClip displayBackground = null;
            trackAsset.FindRecordingClipAtTime(time, out displayBackground);
            if (displayBackground != null)
            {
                if (displayBackground.recordable)
                {
                    AnimationPlayableAsset asset = displayBackground.asset as AnimationPlayableAsset;
                    if (asset != null)
                        return asset.clip;
                }
                else if (animTrack == null)
                {
                    AnimatedParameterExtensions.CreateCurvesIfRequired(displayBackground);
                    return displayBackground.curves;
                }
            }

            return null;
        }
예제 #25
0
        public static void InsertClip(AnimationTrack track, AnimationClip newClip)
        {
            AnimationClip clip;

            using (Document.Current.History.BeginTransaction()) {
                if (TryFindClip(track, newClip.BeginFrame, out clip))
                {
                    if (newClip.BeginFrame > clip.BeginFrame)
                    {
                        SplitClip(track, clip, newClip.BeginFrame);
                    }
                }
                if (TryFindClip(track, newClip.EndFrame - 1, out clip))
                {
                    if (newClip.EndFrame < clip.EndFrame)
                    {
                        SplitClip(track, clip, newClip.EndFrame);
                    }
                }
                for (int i = track.Clips.Count - 1; i >= 0; i--)
                {
                    var c = track.Clips[i];
                    if (c.BeginFrame >= newClip.BeginFrame && c.BeginFrame < newClip.EndFrame)
                    {
                        RemoveClip(track, c);
                    }
                }
                var index = FindClipInsertionIndex(track, newClip.BeginFrame);
                Core.Operations.InsertIntoList <AnimationClipList, AnimationClip> .Perform(track.Clips, index, newClip);

                Document.Current.History.CommitTransaction();
            }
        }
        string GetErrorText(AnimationPlayableAsset animationAsset, AnimationTrack track, string defaultError)
        {
            if (animationAsset.clip == null)
            {
                return(k_NoClipAssignedError);
            }
            if (animationAsset.clip.legacy)
            {
                return(k_LegacyClipError);
            }
            if (animationAsset.clip.hasMotionCurves || animationAsset.clip.hasRootCurves)
            {
                if (track != null && track.trackOffset == TrackOffset.Auto)
                {
                    var animator = track.GetBinding(TimelineEditor.inspectedDirector);
                    if (animator != null && !animator.applyRootMotion && !animationAsset.clip.hasGenericRootTransform)
                    {
                        if (animationAsset.clip.hasMotionCurves)
                        {
                            return(k_MotionCurveError);
                        }
                        return(k_RootCurveError);
                    }
                }
            }

            return(defaultError);
        }
예제 #27
0
 private void DoManipulators()
 {
     if (!(this.m_EditorClip == null) && this.m_EditorClip.clip != null)
     {
         AnimationPlayableAsset animationPlayableAsset = this.m_EditorClip.clip.asset as AnimationPlayableAsset;
         AnimationTrack         animationTrack         = this.m_EditorClip.clip.parentTrack as AnimationTrack;
         Transform transform = this.GetTransform();
         if (transform != null && animationPlayableAsset != null && this.m_OffsetEditMode != TimelineAnimationUtilities.OffsetEditMode.None && animationTrack != null)
         {
             Vector3    vector     = transform.get_position();
             Quaternion quaternion = transform.get_rotation();
             EditorGUI.BeginChangeCheck();
             if (this.m_OffsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Translation)
             {
                 vector = Handles.PositionHandle(vector, (Tools.get_pivotRotation() != 1) ? quaternion : Quaternion.get_identity());
             }
             else if (this.m_OffsetEditMode == TimelineAnimationUtilities.OffsetEditMode.Rotation)
             {
                 quaternion = Handles.RotationHandle(quaternion, vector);
             }
             if (EditorGUI.EndChangeCheck())
             {
                 TimelineAnimationUtilities.RigidTransform rigidTransform = TimelineAnimationUtilities.UpdateClipOffsets(animationPlayableAsset, animationTrack, transform, vector, quaternion);
                 animationPlayableAsset.position = rigidTransform.position;
                 animationPlayableAsset.rotation = rigidTransform.rotation;
                 this.Reevaluate();
                 base.Repaint();
             }
         }
     }
 }
예제 #28
0
 private static int CalcLabelsHashCode(Widget gridWidget, AnimationTrack track)
 {
     unchecked {
         var r = -511344;
         r = r * -1521134295 + (int)(TimelineMetrics.ColWidth * 100);
         r = r * -1521134295 + (int)(gridWidget.Height * 100);
         foreach (var clip in track.Clips)
         {
             r = r * -1521134295 + clip.AnimationIdComparisonCode;
             r = r * -1521134295 + clip.BeginFrame;
             r = r * -1521134295 + clip.EndFrame;
             r = r * -1521134295 + clip.InFrame;
             var beginMarker = clip.FindAnimation()?.Markers.GetByFrame(clip.InFrame);
             if (beginMarker != null)
             {
                 r = r * -1521134295 + beginMarker.Id.GetHashCode();
             }
             var endMarker = clip.FindAnimation()?.Markers.GetByFrame(clip.InFrame + clip.DurationInFrames);
             if (endMarker != null)
             {
                 r = r * -1521134295 + endMarker.Id.GetHashCode();
             }
         }
         return(r);
     }
 }
예제 #29
0
    void OnGUI()
    {
        source = EditorGUILayout.ObjectField(source, typeof(TextAsset), true);

        if (GUILayout.Button("Add to scene"))
        {
            //find director
            timeline = GameObject.Find("TIMELINE");
            PlayableDirector director      = timeline.GetComponent <PlayableDirector>();
            TimelineAsset    timelineAsset = (TimelineAsset)director.playableAsset;

            //load json into class
            string          jsonText          = File.ReadAllText(Application.dataPath + "/Resources/json/" + source.name + ".json");
            PlayerStatsList myPlayerStatsList = new PlayerStatsList();
            JsonUtility.FromJsonOverwrite(jsonText, myPlayerStatsList);
            //loop through objects in class
            foreach (PlayerStats p in myPlayerStatsList.characters)
            {
                //place asset in scene
                MyClass myObject = new MyClass();
                myObject.characterPath = p.model;
                tempobj      = (GameObject)Instantiate(Resources.Load(myObject.characterPath), new Vector3(0, 0, 0), Quaternion.identity);
                tempobj.name = p.name;

                //create animation track on TIMELINE
                AnimationTrack newTrack = timelineAsset.CreateTrack <AnimationTrack>(null, "Animation Track " + tempobj.name);
                director.SetGenericBinding(newTrack, tempobj);
                myObject.animPath = p.anim;
                animObject        = Resources.Load("AnimTest/" + myObject.animPath);
                AnimationClip animClip;
                animClip = Resources.Load <AnimationClip>("AnimTest/" + myObject.animPath);
                newTrack.CreateClip(animClip);
            }
        }
    }
예제 #30
0
 //  
 public AnimationInstance(Animation anim)
 {
   animation_ = anim;
   frameRate_ = anim.FrameRate;
   //  The time of the last frame is less than the duration of the animation,
   //  as the last frame has some duration itself.
   lastFrameTime_ = (anim.NumFrames - 1) / frameRate_;
   invFrameRate_ = 1.0f / frameRate_;
   duration_ = anim.NumFrames * invFrameRate_;
   int max = 0;
   //  calculate max bone index
   //  todo: do in content pipeline
   foreach (KeyValuePair<int, AnimationTrack> kvp in anim.Tracks)
   {
     if (kvp.Key >= max)
       max = kvp.Key + 1;
   }
   //  Allocate animation keyframes (for lerping between times).
   keyframes_ = new Keyframe[max];
   //  Load all the tracks (one track per bone).
   tracks_ = new AnimationTrack[max];
   foreach (int i in anim.Tracks.Keys)
   {
     keyframes_[i] = new Keyframe();
     tracks_[i] = anim.Tracks[i];
   }
 }
예제 #31
0
        public void FinializeTrack(TrackAsset track, TimelineWindow.TimelineState state)
        {
            AnimationTrack animationTrack = track as AnimationTrack;

            if (!animationTrack.inClipMode)
            {
                EditorUtility.SetDirty(animationTrack.GetOrCreateClip());
            }
            if (this.recordClip != null)
            {
                if (!this.m_ProcessedClips.Contains(this.recordClip.animationClip))
                {
                    this.m_ProcessedClips.Add(this.recordClip.animationClip);
                }
                if (this.m_ClipTime > this.recordClip.duration)
                {
                    TimelineUndo.PushUndo(track, "Add Key");
                    this.recordClip.duration = this.m_ClipTime;
                    this.m_RefreshState      = true;
                }
                track.CalculateExtrapolationTimes();
            }
            this.recordClip = null;
            this.m_ClipTime = 0.0;
            if (this.m_needRebuildRects)
            {
                state.CalculateRowRects();
                this.m_needRebuildRects = false;
            }
        }
        protected void TransformTrack(Matrix4 unscaledTransform, float scale,
                                      Animation newAnim, Animation anim, Bone bone)
        {
            AnimationTrack track             = GetBoneTrack(anim, bone.Handle);
            AnimationTrack newTrack          = GetBoneTrack(newAnim, bone.Handle);
            Bone           oldNode           = (Bone)track.TargetNode;
            Bone           newNode           = (Bone)newTrack.TargetNode;
            Quaternion     exportRotation    = GetRotation(unscaledTransform);
            Vector3        exportTranslation = unscaledTransform.Translation;

            for (int i = 0; i < track.KeyFrames.Count; ++i)
            {
                KeyFrame   keyFrame       = track.KeyFrames[i];
                Quaternion oldOrientation = Quaternion.Identity;
                Vector3    oldTranslation = Vector3.Zero;
                // Now build the composite transform for the old node
                GetCompositeTransform(ref oldOrientation, ref oldTranslation, oldNode, anim, i);
                Quaternion targetOrientation = exportRotation * oldOrientation;
                Vector3    targetTranslation = exportTranslation + scale * (exportRotation * oldTranslation);
                KeyFrame   newKeyFrame       = newTrack.CreateKeyFrame(keyFrame.Time);
                // we have a parent - where is it?
                Quaternion parentOrientation = Quaternion.Identity;
                Vector3    parentTranslation = Vector3.Zero;
                GetCompositeTransform(ref parentOrientation, ref parentTranslation, (Bone)newNode.Parent, newAnim, i);
                newKeyFrame.Rotation  = newNode.Orientation.Inverse() * parentOrientation.Inverse() * targetOrientation;
                newKeyFrame.Translate = (-1 * newNode.Position) + (-1 * parentTranslation) + targetTranslation;
            }
        }
예제 #33
0
 private static void AddAssetOnTrack(Type typeOfClip, TrackAsset track, ITimelineState state)
 {
     state.AddStartFrameDelegate(delegate(ITimelineState istate, Event currentEvent)
     {
         ObjectSelector.get_get().Show(null, typeOfClip, null, false);
         ObjectSelector.get_get().objectSelectorID = 0;
         ObjectSelector.get_get().set_searchFilter("");
         return(true);
     });
     state.AddStartFrameDelegate(delegate(ITimelineState istate, Event currentEvent)
     {
         bool result;
         if (currentEvent.get_commandName() == "ObjectSelectorClosed")
         {
             AnimationTrack animationTrack = track as AnimationTrack;
             if (animationTrack && !animationTrack.inClipMode)
             {
                 animationTrack.ConvertToClipMode();
             }
             TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(EditorGUIUtility.GetObjectPickerObject(), track, istate, TimelineHelpers.sInvalidMousePosition);
             if (timelineClip != null && timelineClip.asset != null)
             {
                 TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, track);
             }
             result = true;
         }
         else
         {
             result = false;
         }
         return(result);
     });
 }
 /// <summary>
 /// Method that allows querying if a track is current enabled for animation recording.
 /// </summary>
 /// <param name="track">The track to query.</param>
 /// <returns>True if currently recording and False otherwise.</returns>
 public static bool IsRecording(this AnimationTrack track)
 {
     if (track == null)
     {
         throw new ArgumentNullException(nameof(track));
     }
     return(TimelineEditor.state != null && TimelineEditor.state.IsArmedForRecord(track));
 }
예제 #35
0
        public void Test_New()
        {
            var track = new AnimationTrack ("PropetyName", InterpolationType.Step);

            Assert.AreEqual ("PropetyName", track.TargetProperty);
            Assert.AreEqual (0, track.KeyframeCount);
            Assert.AreEqual (0, track.ComponentCount);
            Assert.AreEqual (null, track.ComponentType);
        }
예제 #36
0
        public void ColorRgbaAnimation()
        {
            AnimationTrack<ColorRgba> track;

            track = new AnimationTrack<ColorRgba>(ColorRgba.Red, ColorRgba.Green);
            Assert.AreEqual(ColorRgba.Red, track[0.0f]);
            Assert.AreEqual(ColorRgba.Lerp(ColorRgba.Red, ColorRgba.Green, 0.5f), track[0.5f]);
            Assert.AreEqual(ColorRgba.Green, track[1.0f]);
        }
예제 #37
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyFireExplosion ();

               var spr = new Sprite (100, 100);
               spr.AddTexture (new Texture ("media/FireExplosion.png"));

               var track = new AnimationTrack ("TextureOffset", InterpolationType.Step);
               track.AddKeyframe (0, new Vector2 (0, 0));
               track.AddKeyframe (100, new Vector2 (100, 0));
               track.AddKeyframe (200, new Vector2 (200, 0));
               track.AddKeyframe (300, new Vector2 (300, 0));
               track.AddKeyframe (400, new Vector2 (400, 0));
               track.AddKeyframe (500, new Vector2 (500, 0));
               track.AddKeyframe (600, new Vector2 (600, 0));
               track.AddKeyframe (700, new Vector2 (700, 0));
               track.AddKeyframe (800, new Vector2 (800, 0));
               track.AddKeyframe (900, new Vector2 (900, 0));
               track.AddKeyframe (1000, new Vector2 (0, 100));
               track.AddKeyframe (1100, new Vector2 (100, 100));
               track.AddKeyframe (1200, new Vector2 (200, 100));
               track.AddKeyframe (1300, new Vector2 (300, 100));
               track.AddKeyframe (1400, new Vector2 (400, 100));
               track.AddKeyframe (1500, new Vector2 (500, 100));
               track.AddKeyframe (1600, new Vector2 (600, 100));
               track.AddKeyframe (1700, new Vector2 (700, 100));
               track.AddKeyframe (1800, new Vector2 (800, 100));
               track.AddKeyframe (1900, new Vector2 (900, 100));
               track.AddKeyframe (2000, new Vector2 (0, 200));
               track.AddKeyframe (2100, new Vector2 (100, 200));
               track.AddKeyframe (2200, new Vector2 (200, 200));
               track.AddKeyframe (2300, new Vector2 (300, 200));
               track.AddKeyframe (2400, new Vector2 (400, 200));
               track.AddKeyframe (2500, new Vector2 (500, 200));
               track.AddKeyframe (2600, new Vector2 (600, 200));
               track.AddKeyframe (2700, new Vector2 (700, 200));
               track.AddKeyframe (2800, new Vector2 (800, 200));
               track.AddKeyframe (2900, new Vector2 (900, 200));

               var clip = new AnimationClip (3000, "FireExplosion");
               clip.AddTrack (spr, track);
               clip.WrapMode = WrapMode.Loop;

               var anim = new AnimationController ();
               anim.AddClip (clip);

               var node = new Node ();
               node.Attach (cmp);
               node.Attach (spr);
               node.Attach (anim);

               node.Translation = pos;

               return node;
        }
예제 #38
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyFireExplosion ();

            var spr = new Sprite (100, 100);
            spr.AddTexture(Resource.GetTexture ("media/FireExplosion.png"));

            var node = new Node ("FireExplosion");
            node.Attach (spr);
            node.Attach (cmp);

            node.Translation = pos - new Vector3(34, 34, 0);   // 爆発の中心を地球にあわせる

            var track = new AnimationTrack ("TextureOffset", InterpolationType.Step);
            track.AddKeyframe (0, new Vector2 (0, 0));
            track.AddKeyframe (100, new Vector2 (100, 0));
            track.AddKeyframe (200, new Vector2 (200, 0));
            track.AddKeyframe (300, new Vector2 (300, 0));
            track.AddKeyframe (400, new Vector2 (400, 0));
            track.AddKeyframe (500, new Vector2 (500, 0));
            track.AddKeyframe (600, new Vector2 (600, 0));
            track.AddKeyframe (700, new Vector2 (700, 0));
            track.AddKeyframe (800, new Vector2 (800, 0));
            track.AddKeyframe (900, new Vector2 (900, 0));
            track.AddKeyframe (1000, new Vector2 (0, 100));
            track.AddKeyframe (1100, new Vector2 (100, 100));
            track.AddKeyframe (1200, new Vector2 (200, 100));
            track.AddKeyframe (1300, new Vector2 (300, 100));
            track.AddKeyframe (1400, new Vector2 (400, 100));
            track.AddKeyframe (1500, new Vector2 (500, 100));
            track.AddKeyframe (1600, new Vector2 (600, 100));
            track.AddKeyframe (1700, new Vector2 (700, 100));
            track.AddKeyframe (1800, new Vector2 (800, 100));
            track.AddKeyframe (1900, new Vector2 (900, 100));
            track.AddKeyframe (2000, new Vector2 (0, 200));
            track.AddKeyframe (2100, new Vector2 (100, 200));
            track.AddKeyframe (2200, new Vector2 (200, 200));
            track.AddKeyframe (2300, new Vector2 (300, 200));
            track.AddKeyframe (2400, new Vector2 (400, 200));
            track.AddKeyframe (2500, new Vector2 (500, 200));
            track.AddKeyframe (2600, new Vector2 (600, 200));
            track.AddKeyframe (2700, new Vector2 (700, 200));
            track.AddKeyframe (2800, new Vector2 (800, 200));
            track.AddKeyframe (2900, new Vector2 (900, 200));

            var clip = new AnimationClip (3000, "Explosion");
            clip.AddTrack (spr, track);
            clip.WrapMode = WrapMode.Once;

            node.UserData.Add (clip.Name, clip);

            return node;
        }
예제 #39
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyExplosion ();

            var spr = new Sprite (100, 100);
            spr.AddTexture (new Texture("media/FireExplosion.png"));
            spr.SetTextureOffset (0, 0);
            spr.SetOffset (-50, -50);

            var track = new AnimationTrack ("TextureOffset", InterpolationType.Step);
            track.AddKeyframe (0, new Vector2 (0, 0));
            track.AddKeyframe (100, new Vector2 (100 , 0));
            track.AddKeyframe (200, new Vector2 (200 , 0));
            track.AddKeyframe (300, new Vector2 (300 , 0));
            track.AddKeyframe (400, new Vector2 (400 , 0));
            track.AddKeyframe (500, new Vector2 (500 , 0));
            track.AddKeyframe (600, new Vector2 (600 , 0));
            track.AddKeyframe (700, new Vector2 (700 , 0));
            track.AddKeyframe (800, new Vector2 (800 , 0));
            track.AddKeyframe (900, new Vector2 (900 , 0));
            track.AddKeyframe (1000, new Vector2 (0, 100));
            track.AddKeyframe (1100, new Vector2 (100, 100));
            track.AddKeyframe (1200, new Vector2 (200, 100));
            track.AddKeyframe (1300, new Vector2 (300, 100));
            track.AddKeyframe (1400, new Vector2 (400, 100));
            track.AddKeyframe (1500, new Vector2 (500, 100));
            track.AddKeyframe (1600, new Vector2 (600, 100));
            track.AddKeyframe (1700, new Vector2 (700, 100));
            track.AddKeyframe (1800, new Vector2 (800, 100));
            track.AddKeyframe (1900, new Vector2 (900, 100));
            track.AddKeyframe (2000, new Vector2 (0, 200));
            track.AddKeyframe (2100, new Vector2 (100, 200));
            track.AddKeyframe (2200, new Vector2 (200, 200));
            track.AddKeyframe (2300, new Vector2 (300, 200));
            track.AddKeyframe (2400, new Vector2 (400, 200));
            track.AddKeyframe (2500, new Vector2 (500, 200));
            track.AddKeyframe (2600, new Vector2 (600, 200));
            track.AddKeyframe (2700, new Vector2 (700, 200));
            track.AddKeyframe (2800, new Vector2 (800, 200));
            track.AddKeyframe (2900, new Vector2 (900, 200));

            cmp.clip = new AnimationClip (3000, "Fire-Animation");
            cmp.clip.AddTrack (spr, track);

            var node = new Node ();
            node.Attach (cmp);
            node.Attach (spr);

            node.DrawPriority = -3;
            node.Translation = pos;

            return node;
        }
예제 #40
0
        public void Test_Sample_Linear_Primitive()
        {
            var track = new AnimationTrack ("PropetyName", InterpolationType.Linear);

            track.AddKeyframe (1, 1.0f);
            track.AddKeyframe (2, 2.0f);

            Assert.AreEqual (1.0f, track.Sample (0.0f), 0.0001f);
            Assert.AreEqual (1.0f, track.Sample (0.5f), 0.0001f);
            Assert.AreEqual (1.0f, track.Sample (1.0f), 0.0001f);
            Assert.AreEqual (1.5f, track.Sample (1.5f), 0.0001f);
            Assert.AreEqual (2.0f, track.Sample (2.0f), 0.0001f);
            Assert.AreEqual (2.0f, track.Sample (2.5f), 0.0001f);
        }
예제 #41
0
		[Test] public void Vector3Animation()
		{
			AnimationTrack<Vector3> track;
			
			track = new AnimationTrack<Vector3>(Vector3.Zero, Vector3.One);
			Assert.AreEqual(0.0f, track[0.0f].X, 0.0001f);
			Assert.AreEqual(0.0f, track[0.0f].Y, 0.0001f);
			Assert.AreEqual(0.0f, track[0.0f].Z, 0.0001f);
			Assert.AreEqual(0.5f, track[0.5f].X, 0.0001f);
			Assert.AreEqual(0.5f, track[0.5f].Y, 0.0001f);
			Assert.AreEqual(0.5f, track[0.5f].Z, 0.0001f);
			Assert.AreEqual(1.0f, track[1.0f].X, 0.0001f);
			Assert.AreEqual(1.0f, track[1.0f].Y, 0.0001f);
			Assert.AreEqual(1.0f, track[1.0f].Z, 0.0001f);
		}
예제 #42
0
        public void Test_AddTrack()
        {
            var clip = new AnimationClip (100, "ClipName");
            var track1 = new AnimationTrack ("PropName", InterpolationType.Linear);
            var track2 = new AnimationTrack ("PropName", InterpolationType.Linear);
            var dummy = new Node ();

            clip.AddTrack (dummy, track1);
            clip.AddTrack (dummy, track2);

            Assert.AreEqual (2, clip.TrackCount);
            Assert.AreEqual (2, clip.Tracks.Count ());
            Assert.AreEqual (track1, clip.GetTrack (0).Item2);
            Assert.AreEqual (track2, clip.GetTrack (1).Item2);
        }
예제 #43
0
        public void IntAnimation()
        {
            AnimationTrack<int> track;

            track = new AnimationTrack<int>(0, 100);
            for (int i = 0; i <= 100; i++)
            {
                float time = (float)i / 100.0f + 0.0001f;
                Assert.AreEqual(i, track[time]);
            }

            Assert.AreEqual(1, track[0.011f]);
            Assert.AreEqual(1, track[0.013f]);
            Assert.AreEqual(1, track[0.019f]);
            Assert.AreEqual(2, track[0.021f]);
        }
예제 #44
0
        public void Test_AddKeyframe_ValueType()
        {
            var track = new AnimationTrack ("PropetyName", InterpolationType.Step);

            track.AddKeyframe (1, new Vector3 (1, 2, 3));
            track.AddKeyframe (2, new Vector3 (4, 5, 6));
            track.AddKeyframe (3, new Vector3 (7, 8, 9));
            track.AddKeyframe (4, new Vector3 (10, 11, 12));

            Assert.AreEqual (1, track.GetKeyframe (0).Time);
            Assert.AreEqual (new Vector3(1,2,3), track.GetKeyframe (0).Value);

            Assert.AreEqual (2, track.GetKeyframe (1).Time);
            Assert.AreEqual (new Vector3 (4,5,6), track.GetKeyframe (1).Value);

            Assert.AreEqual (3, track.GetKeyframe (2).Time);
            Assert.AreEqual (new Vector3 (7,8,9), track.GetKeyframe (2).Value);

            Assert.AreEqual (4, track.GetKeyframe (3).Time);
            Assert.AreEqual (new Vector3 (10,11,12), track.GetKeyframe (3).Value);
        }
예제 #45
0
        public void Test_AddKeyframe_Primitive()
        {
            var track = new AnimationTrack ("PropetyName", InterpolationType.Step);

            // 内部でソート
            track.AddKeyframe (4, 4);
            track.AddKeyframe (3, 3);
            track.AddKeyframe (2, 2);
            track.AddKeyframe (1, 1);

            Assert.AreEqual (1, track.GetKeyframe (0).Time);
            Assert.AreEqual (1, track.GetKeyframe (0).Value);

            Assert.AreEqual (2, track.GetKeyframe (1).Time);
            Assert.AreEqual (2, track.GetKeyframe (1).Value);

            Assert.AreEqual (3, track.GetKeyframe (2).Value);
            Assert.AreEqual (3, track.GetKeyframe (2).Time);

            Assert.AreEqual (4, track.GetKeyframe (3).Value);
            Assert.AreEqual (4, track.GetKeyframe (3).Time);
        }
예제 #46
0
        public void Test_Sample_ValueType_Float2Int()
        {
            var track = new AnimationTrack ("PropetyName", InterpolationType.Linear);

            track.AddKeyframe (1, new MyStruct (1, 0));     // Int
            track.AddKeyframe (100, new MyStruct (100, 0)); // Int

            Assert.AreEqual (1, track.Sample (1).X);         // Int
            Assert.AreEqual (50, track.Sample (50).X);       // Int
            Assert.AreEqual (100, track.Sample (100).X);     // Int
        }
예제 #47
0
        public void Test_RemoveTrack()
        {
            var clip = new AnimationClip (100, "ClipName");
            var track1 = new AnimationTrack ("PropName",  InterpolationType.Linear);
            var track2 = new AnimationTrack ("PropName", InterpolationType.Linear);
            var target = new Node ();

            clip.AddTrack (target, track1);
            clip.AddTrack (target, track2);

            Assert.AreEqual (2, clip.TrackCount);
            Assert.AreEqual (2, clip.Tracks.Count());

            clip.RemoveTrack (track1);
            clip.RemoveTrack (track2);

            Assert.AreEqual (0, clip.TrackCount);
            Assert.AreEqual (0, clip.Tracks.Count ());
        }
예제 #48
0
        public void Test_Sample_Linear_ValueType()
        {
            var track = new AnimationTrack ("PropetyName", InterpolationType.Linear);

            track.AddKeyframe (1, new Vector3 (1, 2, 0));
            track.AddKeyframe (2, new Vector3 (2, 3, 0));

            Assert.AreEqual (1.0f, track.Sample (0.0f).X, 0.0001f);
            Assert.AreEqual (1.0f, track.Sample (0.5f).X, 0.0001f);
            Assert.AreEqual (1.0f, track.Sample (1.0f).X, 0.0001f);
            Assert.AreEqual (1.5f, track.Sample (1.5f).X, 0.0001f);
            Assert.AreEqual (2.0f, track.Sample (2.0f).X, 0.0001f);
            Assert.AreEqual (2.0f, track.Sample (2.5f).X, 0.0001f);

            Assert.AreEqual (2.0f, track.Sample (0.0f).Y, 0.0001f);
            Assert.AreEqual (2.0f, track.Sample (0.5f).Y, 0.0001f);
            Assert.AreEqual (2.0f, track.Sample (1.0f).Y, 0.0001f);
            Assert.AreEqual (2.5f, track.Sample (1.5f).Y, 0.0001f);
            Assert.AreEqual (3.0f, track.Sample (2.0f).Y, 0.0001f);
            Assert.AreEqual (3.0f, track.Sample (2.5f).Y, 0.0001f);
        }
예제 #49
0
    //C4Dの座標系を変換
    private float ConvertC4DSpace(AnimationTrack.TRACK_TYPE type, float keyValue)
    {
        switch(type)
        {
            case AnimationTrack.TRACK_TYPE.POS_X: keyValue = keyValue / 100.0f * -1.0f; break;
            case AnimationTrack.TRACK_TYPE.POS_Y: keyValue = keyValue / 100.0f; break;
            case AnimationTrack.TRACK_TYPE.POS_Z: keyValue = keyValue / 100.0f * -1.0f; break;
            case AnimationTrack.TRACK_TYPE.ROT_X: keyValue = keyValue * Mathf.Rad2Deg * -1.0f; break;
            case AnimationTrack.TRACK_TYPE.ROT_Y: keyValue = (keyValue < 0.0f) ? 180.0f - (keyValue * Mathf.Rad2Deg) : (keyValue * Mathf.Rad2Deg) + 180.0f; break;
            case AnimationTrack.TRACK_TYPE.ROT_Z: keyValue = keyValue * Mathf.Rad2Deg * -1.0f; break;
            default: break;
        }

        return keyValue;
    }
예제 #50
0
    //カーブを選択取得
    public AnimationCurve GetCurve(AnimationTrack.TRACK_TYPE type)
    {
        AnimationCurve curve = null;
        AnimationTrack track = Array.Find(animTracks, t => (t.type == type));

        if(track != null)
            curve = track.curve;

        return curve;
    }
예제 #51
0
        public static Node Create(Vector3 pos)
        {
            var cmp = new MyCharacter ();

            // Body
            var spr1 = new Sprite (24, 32);
            spr1.AddTexture (new Texture ("media/Character-Gelato.png"));

            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (spr1.Width / 2, spr1.Height / 2, 1);
            col1.Offset = new Vector3 (spr1.Width / 2, spr1.Height / 2, 1);
            col1.IgnoreWith = (int)MyGroup.Character;

            // Foot
            var spr2 = new Sprite (24, 4);
            spr2.AddTexture (new Texture ("media/image128x128(Red).png"));

            var col2 = new CollisionObject ();
            col2.Shape = new BoxShape (2,2, 2);
            spr2.Offset = new Vector2 (0, spr1.Height + 2);
            col2.Offset = new Vector3 (spr1.Width / 2, spr1.Height + 2 + 4/2, 1);
            col2.IgnoreWith = (int)MyGroup.Character;

            var node = new Node ("MyCharacter");
            node.Attach (cmp);
            node.Attach (spr1);
            node.Attach (col1);
            node.Attach (spr2);
            node.Attach (col2);

            node.Translation = pos;
            node.DrawPriority = -1;
            node.GroupID = (int)MyGroup.Character;

            // アニメーションの設定
            var track1 = new AnimationTrack ("TextureOffset", InterpolationType.Step);
            track1.AddKeyframe (0, new Vector2 (0, 64));
            track1.AddKeyframe (300, new Vector2 (24, 64));
            track1.AddKeyframe (600, new Vector2 (48, 64));
            var clip1 = new AnimationClip (900, "MyCharacter.Down");
            clip1.AddTrack (spr1, track1);

            var track2 = new AnimationTrack ("TextureOffset", InterpolationType.Step);
            track2.AddKeyframe (0, new Vector2 (0, 0));
            track2.AddKeyframe (300, new Vector2 (24, 0));
            track2.AddKeyframe (600, new Vector2 (48, 0));
            var clip2 = new AnimationClip (900, "MyCharacter.Up");
            clip2.AddTrack (spr1, track2);

            var track3 = new AnimationTrack ("TextureOffset", InterpolationType.Step);
            track3.AddKeyframe (0, new Vector2 (0, 32));
            track3.AddKeyframe (300, new Vector2 (24, 32));
            track3.AddKeyframe (600, new Vector2 (48, 32));
            var clip3 = new AnimationClip (900, "MyCharacter.Right");
            clip3.AddTrack (spr1, track3);

            var track4 = new AnimationTrack ("TextureOffset", InterpolationType.Step);
            track4.AddKeyframe (0, new Vector2 (0, 96));
            track4.AddKeyframe (300, new Vector2 (24, 96));
            track4.AddKeyframe (600, new Vector2 (48, 96));
            var clip4 = new AnimationClip (900, "MyCharacter.Left");
            clip4.AddTrack (spr1, track4);

            node.UserData.Add (clip1.Name, clip1);
            node.UserData.Add (clip2.Name, clip2);
            node.UserData.Add (clip3.Name, clip3);
            node.UserData.Add (clip4.Name, clip4);

            // ステート管理
            cmp.sm.Configure (State.Down)
                    .Ignore (Trigger.Down)
                    .Permit (Trigger.Up, State.Up)
                    .Permit (Trigger.Right, State.Right)
                    .Permit (Trigger.Left, State.Left)
                    .OnExit (x => clip1.Stop ())
                    .OnEntry (x => clip1.Play ());

            cmp.sm.Configure (State.Up)
                    .Permit (Trigger.Down, State.Down)
                    .Ignore (Trigger.Up)
                    .Permit (Trigger.Right, State.Right)
                    .Permit (Trigger.Left, State.Left)
                    .OnExit (x => clip2.Stop ())
                    .OnEntry (x => clip2.Play ());

            cmp.sm.Configure (State.Right)
                    .Permit (Trigger.Down, State.Down)
                    .Permit (Trigger.Up, State.Up)
                    .Ignore (Trigger.Right)
                    .Permit (Trigger.Left, State.Left)
                    .OnExit (x => clip3.Stop ())
                    .OnEntry (x => clip3.Play ());

            cmp.sm.Configure (State.Left)
                    .Permit (Trigger.Down, State.Down)
                    .Permit (Trigger.Up, State.Up)
                    .Permit (Trigger.Right, State.Right)
                    .Ignore (Trigger.Left)
                    .OnExit (x => clip4.Stop ())
                    .OnEntry (x => clip4.Play ());

            return node;
        }
예제 #52
0
        /// <summary>
        /// The workhorse of the animation processor. It loops through all 
        /// animations, all tracks, and all keyframes, and converts to the format
        /// expected by the runtime animation classes.
        /// </summary>
        /// <param name="input">The NodeContent to process. Comes from the base ModelProcessor.</param>
        /// <param name="output">The ModelContent that was produced. You don't typically change this.</param>
        /// <param name="context">The build context (logger, etc).</param>
        /// <returns>An allocated AnimationSet with the animations to include.</returns>
        public virtual AnimationSet BuildAnimationSet(NodeContent input, ref ModelContent output, 
        ContentProcessorContext context)
        {
            AnimationSet ret = new AnimationSet();
              if (!DoAnimations)
              {
            context.Logger.LogImportantMessage("DoAnimation is set to false for {0}; not generating animations.", input.Name);
            return ret;
              }

              //  go from name to index
              Dictionary<string, ModelBoneContent> nameToIndex = new Dictionary<string, ModelBoneContent>();
              foreach (ModelBoneContent mbc in output.Bones)
            nameToIndex.Add(GetBoneName(mbc), mbc);

              AnimationContentDictionary adict = MergeAnimatedBones(input);
              if (adict == null || adict.Count == 0)
              {
            context.Logger.LogWarning("http://kwxport.sourceforge.net/", input.Identity,
            "Model processed with AnimationProcessor has no animations.");
            return ret;
              }

              foreach (AnimationContent ac in adict.Values)
              {
            if (!IncludeAnimation(ac))
            {
              context.Logger.LogImportantMessage(String.Format("Not including animation named {0}.", ac.Name));
              continue;
            }
            context.Logger.LogImportantMessage(
            "Processing animation {0} duration {1} sample rate {2} reduction tolerance {3}.",
            ac.Name, ac.Duration, SampleRate, Tolerance);
            AnimationChannelDictionary acdict = ac.Channels;
            AnimationTrackDictionary tracks = new AnimationTrackDictionary();
            TimeSpan longestUniqueDuration = new TimeSpan(0);
            foreach (string name in acdict.Keys)
            {
              if (!IncludeTrack(name))
              {
            context.Logger.LogImportantMessage(String.Format("Not including track named {0}.", name));
            continue;
              }

              int ix = 0;
              AnimationChannel achan = acdict[name];
              int bix = nameToIndex[name].Index;
              context.Logger.LogMessage("Processing bone {0}:{1}.", name, bix);
              AnimationTrack at;
              if (tracks.TryGetValue(bix, out at))
              {
            throw new System.ArgumentException(
                String.Format("Bone index {0} is used by multiple animations in the same clip (name {1}).",
                bix, name));
              }

              //  Sample at given frame rate from 0 .. Duration
              List<Keyframe> kfl = new List<Keyframe>();
              int nFrames = (int)Math.Floor(ac.Duration.TotalSeconds * SampleRate + 0.5);
              for (int i = 0; i < nFrames; ++i)
              {
            Keyframe k = SampleChannel(achan, i / SampleRate, ref ix);
            kfl.Add(k);
              }

              //  Run keyframe elimitation
              Keyframe[] frames = kfl.ToArray();
              int nReduced = 0;
              if (tolerance_ > 0)
            nReduced = ReduceKeyframes(frames, tolerance_);
              if (nReduced > 0)
            context.Logger.LogMessage("Reduced '{2}' from {0} to {1} frames.",
                frames.Length, frames.Length - nReduced, name);

              //  Create an AnimationTrack
              at = new AnimationTrack(bix, frames);
              Debug.Assert(name != null);
              at.Name = name;
              tracks.Add(bix, at);
            }
            if (ShouldTrimAnimation(ac))
            {
              TrimAnimationTracks(ac.Name, tracks, context);
            }

            Animation a = new Animation(ac.Name, tracks, SampleRate);
            ret.AddAnimation(a);
              }

              //  build the special "identity" and "bind pose" animations
              AnimationTrackDictionary atd_id = new AnimationTrackDictionary();
              AnimationTrackDictionary atd_bind = new AnimationTrackDictionary();
              foreach (KeyValuePair<string, ModelBoneContent> nip in nameToIndex)
              {
            if (!IncludeTrack(nip.Key))
              continue;
            Keyframe[] frames_id = new Keyframe[2];
            frames_id[0] = new Keyframe();
            frames_id[1] = new Keyframe();
            AnimationTrack at_id = new AnimationTrack(nip.Value.Index, frames_id);
            at_id.Name = nip.Key;
            atd_id.Add(nip.Value.Index, at_id);

            Keyframe[] frames_bind = new Keyframe[2];
            Matrix mat = nip.Value.Transform;
            frames_bind[0] = Keyframe.CreateFromMatrix(mat);
            frames_bind[1] = new Keyframe();
            frames_bind[1].CopyFrom(frames_bind[0]);
            AnimationTrack at_bind = new AnimationTrack(nip.Value.Index, frames_bind);
            at_bind.Name = nip.Key;
            atd_bind.Add(nip.Value.Index, at_bind);
              }
              ret.AddAnimation(new Animation("$id$", atd_id, 1.0f));
              ret.AddAnimation(new Animation("$bind$", atd_bind, 1.0f));

              return ret;
        }
예제 #53
0
        public void Test_OnAnimate_Float_Once()
        {
            var track = new AnimationTrack ("Speed", InterpolationType.Step);
            track.AddKeyframe (1, 1.0f);
            track.AddKeyframe (2, 2.0f);

            var clip = new AnimationClip (3, "TestClip");
            clip.WrapMode = WrapMode.Once;
            clip.Duration = 3;
            clip.Play ();

            var target = new MyTarget ();

            clip.AddTrack (target, track);

            var anim = new AnimationController ();
            anim.AddClip (clip);

            Assert.AreEqual (0.0f, target.Speed);

            anim.OnAnimate (1, 0);
            Assert.AreEqual (1.0f, target.Speed);

            anim.OnAnimate (2, 0);
            Assert.AreEqual (2.0f, target.Speed);

            anim.OnAnimate (3, 0);
            Assert.AreEqual (2.0f, target.Speed);
        }
예제 #54
0
        public void Test_OnAnimate_Point_Once()
        {
            var clip = new AnimationClip (3, "TestClip");
            clip.WrapMode = WrapMode.Once;
            clip.Duration = 3;
            clip.Play ();

            var track = new AnimationTrack ("Point", InterpolationType.Step);
            track.AddKeyframe (1, new Vector3 (1, 2, 0));
            track.AddKeyframe (2, new Vector3 (2, 3, 0));

            var target = new MyTarget ();

            clip.AddTrack (target, track);

            var anim = new AnimationController ();
            anim.AddClip (clip);

            Assert.AreEqual (0f, target.Point.X, 0.0001f);
            Assert.AreEqual (0f, target.Point.Y, 0.0001f);

            anim.OnAnimate (1, 0);
            Assert.AreEqual (1.0f, target.Point.X, 0.0001f);
            Assert.AreEqual (2.0f, target.Point.Y, 0.0001f);

            anim.OnAnimate (2, 0);
            Assert.AreEqual (2.0f, target.Point.X, 0.0001f);
            Assert.AreEqual (3.0f, target.Point.Y, 0.0001f);

            anim.OnAnimate (3, 0);
            Assert.AreEqual (2.0f, target.Point.X, 0.0001f);
            Assert.AreEqual (3.0f, target.Point.Y, 0.0001f);
        }
예제 #55
0
        public void Test_Sample_ValueType_Convert_Float2Int()
        {
            var track = new AnimationTrack ("PropetyName", InterpolationType.Linear);

            track.AddKeyframe (1, 1);                         // Int
            track.AddKeyframe (100, 100);                     // Int

            Assert.AreEqual (1, track.Sample (1), 0.0001f);      // Int
            Assert.AreEqual (50, track.Sample (50), 0.0001f);    // Int
            Assert.AreEqual (100, track.Sample (100), 0.0001f);  // Int
        }
예제 #56
0
        public void Test_WeakReferenceTrack()
        {
            var target = new MyTarget ();
            var track = new AnimationTrack ("Speed", InterpolationType.Linear);
            track.AddKeyframe (0, 100.0f);
            track.AddKeyframe (100, 100.0f);

            var clip = new AnimationClip (100, "Clip");
            clip.AddTrack (target, track);

            var anim = new AnimationController ();
            anim.AddClip (clip);

            // ターゲットの解放
            target = null;
            GC.Collect ();

            Assert.AreEqual (1, clip.TrackCount);
            Assert.AreEqual (false, clip.GetTrack (0).Item1.IsAlive);

            // 解放済みのターゲットを含むアニメーションの実行。
            // エラーが起きてはならない
            anim.OnAnimate (0, 0);
        }