Ejemplo n.º 1
0
 private void CloseTriggersPanel()
 {
     if (_trigger == null)
     {
         return;
     }
     _trigger.ClosePanel();
     _trigger = null;
 }
 public void SetKeyframe(int ms, AtomAnimationTrigger value)
 {
     if (value == null)
     {
         triggersMap.Remove(ms);
     }
     else
     {
         triggersMap[ms] = value;
     }
     dirty = true;
 }
Ejemplo n.º 3
0
        private AtomAnimationTrigger GetOrCreateTriggerAtCurrentTime()
        {
            AtomAnimationTrigger trigger;
            var ms = plugin.animation.clipTime.Snap().ToMilliseconds();

            if (!target.triggersMap.TryGetValue(ms, out trigger))
            {
                trigger = new AtomAnimationTrigger();
                target.SetKeyframe(ms, trigger);
            }
            return(trigger);
        }
        public void SetCurveSnapshot(float time, TriggerSnapshot snapshot)
        {
            AtomAnimationTrigger trigger;
            var ms = time.ToMilliseconds();

            if (!triggersMap.TryGetValue(ms, out trigger))
            {
                trigger = new AtomAnimationTrigger();
                SetKeyframe(ms, trigger);
            }
            trigger.RestoreFromJSON(snapshot.json);
            dirty = true;
        }
Ejemplo n.º 5
0
        private void AddAnimationAsCopy()
        {
            var clip = animation.CreateClip(current.animationLayer);

            clip.loop                       = current.loop;
            clip.animationLength            = current.animationLength;
            clip.nextAnimationName          = current.nextAnimationName;
            clip.nextAnimationTime          = current.nextAnimationTime;
            clip.ensureQuaternionContinuity = current.ensureQuaternionContinuity;
            clip.blendDuration              = current.blendDuration;
            operations.Resize().CropOrExtendEnd(current.animationLength);
            foreach (var origTarget in current.targetControllers)
            {
                var newTarget = clip.Add(origTarget.controller);
                for (var i = 0; i < origTarget.curves.Count; i++)
                {
                    newTarget.curves[i].keys = origTarget.curves[i].keys.ToArray();
                }
                foreach (var kvp in origTarget.settings)
                {
                    newTarget.settings[kvp.Key] = new KeyframeSettings {
                        curveType = kvp.Value.curveType
                    };
                }
                newTarget.dirty = true;
            }
            foreach (var origTarget in current.targetFloatParams)
            {
                var newTarget = clip.Add(origTarget.storable, origTarget.floatParam);
                newTarget.value.keys = origTarget.value.keys.ToArray();
                newTarget.dirty      = true;
            }
            foreach (var origTarget in current.targetTriggers)
            {
                var newTarget = clip.Add(new TriggersAnimationTarget {
                    name = origTarget.name
                });
                foreach (var origTrigger in origTarget.triggersMap)
                {
                    var trigger = new AtomAnimationTrigger();
                    trigger.RestoreFromJSON(origTrigger.Value.GetJSON());
                    newTarget.SetKeyframe(origTrigger.Key, trigger);
                }
                newTarget.dirty = true;
            }

            animation.SelectAnimation(clip.animationName);
            onScreenChangeRequested.Invoke(EditAnimationScreen.ScreenName);
        }
Ejemplo n.º 6
0
        private void EditTriggers()
        {
            if (!plugin.animationEditContext.CanEdit())
            {
                return;
            }

            _trigger = GetOrCreateTriggerAtCurrentTime();

            _trigger.handler = this;
            _trigger.triggerActionsParent = popupParent;
            _trigger.atom = plugin.containingAtom;
            _trigger.InitTriggerUI();
            _trigger.OpenTriggerActionsPanel();
            // When already open but in the wrong parent:
            _trigger.SetPanelParent(popupParent);
        }
Ejemplo n.º 7
0
        public AtomAnimationClip AddAnimationAsCopy()
        {
            var clip = AddAnimationWithSameSettings();

            foreach (var origTarget in _clip.targetControllers)
            {
                var newTarget = CopyTarget(clip, origTarget);
                for (var i = 0; i < origTarget.curves.Count; i++)
                {
                    newTarget.curves[i].keys = new List <BezierKeyframe>(origTarget.curves[i].keys);
                }
                newTarget.dirty = true;
            }
            foreach (var origTarget in _clip.targetFloatParams)
            {
                if (!origTarget.EnsureAvailable(false))
                {
                    continue;
                }
                var newTarget = clip.Add(new FloatParamAnimationTarget(origTarget));
                newTarget.value.keys = new List <BezierKeyframe>(origTarget.value.keys);
                newTarget.dirty      = true;
            }
            foreach (var origTarget in _clip.targetTriggers)
            {
                var newTarget = clip.Add(new TriggersAnimationTarget {
                    name = origTarget.name
                });
                foreach (var origTrigger in origTarget.triggersMap)
                {
                    var trigger = new AtomAnimationTrigger();
                    trigger.RestoreFromJSON(origTrigger.Value.GetJSON());
                    newTarget.SetKeyframe(origTrigger.Key, trigger);
                }
                newTarget.dirty = true;
            }
            return(clip);
        }
 public void SetKeyframe(float time, AtomAnimationTrigger value)
 {
     SetKeyframe(time.ToMilliseconds(), value);
 }
        private void DeserializeClip(AtomAnimationClip clip, JSONClass clipJSON)
        {
            var animationPatternUID = clipJSON["AnimationPattern"]?.Value;

            if (!string.IsNullOrEmpty(animationPatternUID))
            {
                var animationPattern = SuperController.singleton.GetAtomByUid(animationPatternUID)?.GetComponentInChildren <AnimationPattern>();
                if (animationPattern == null)
                {
                    SuperController.LogError($"Animation Pattern '{animationPatternUID}' linked to animation '{clip.animationName}' of atom '{_atom.uid}' was not found in scene");
                }
                else
                {
                    clip.animationPattern = animationPattern;
                }
            }

            JSONArray controllersJSON = clipJSON["Controllers"].AsArray;

            if (controllersJSON != null)
            {
                foreach (JSONClass controllerJSON in controllersJSON)
                {
                    var controllerName = controllerJSON["Controller"].Value;
                    var controller     = _atom.freeControllers.Single(fc => fc.name == controllerName);
                    if (controller == null)
                    {
                        SuperController.LogError($"VamTimeline: Atom '{_atom.uid}' does not have a controller '{controllerName}'");
                        continue;
                    }
                    var target = new FreeControllerAnimationTarget(controller);
                    clip.Add(target);
                    DeserializeCurve(target.x, controllerJSON["X"], clip.animationLength, target.settings);
                    DeserializeCurve(target.y, controllerJSON["Y"], clip.animationLength);
                    DeserializeCurve(target.z, controllerJSON["Z"], clip.animationLength);
                    DeserializeCurve(target.rotX, controllerJSON["RotX"], clip.animationLength);
                    DeserializeCurve(target.rotY, controllerJSON["RotY"], clip.animationLength);
                    DeserializeCurve(target.rotZ, controllerJSON["RotZ"], clip.animationLength);
                    DeserializeCurve(target.rotW, controllerJSON["RotW"], clip.animationLength);
                    AddMissingKeyframeSettings(target);
                    target.AddEdgeFramesIfMissing(clip.animationLength);
                }
            }

            JSONArray floatParamsJSON = clipJSON["FloatParams"].AsArray;

            if (floatParamsJSON != null)
            {
                foreach (JSONClass paramJSON in floatParamsJSON)
                {
                    var storableId     = paramJSON["Storable"].Value;
                    var floatParamName = paramJSON["Name"].Value;
                    var target         = new FloatParamAnimationTarget(_atom, storableId, floatParamName);
                    clip.Add(target);
                    DeserializeCurve(target.value, paramJSON["Value"], clip.animationLength, target.settings);
                    AddMissingKeyframeSettings(target);
                    target.AddEdgeFramesIfMissing(clip.animationLength);
                }
            }

            JSONArray triggersJSON = clipJSON["Triggers"].AsArray;

            if (triggersJSON != null)
            {
                foreach (JSONClass triggerJSON in triggersJSON)
                {
                    var target = new TriggersAnimationTarget
                    {
                        name = DeserializeString(triggerJSON["Name"], "Trigger")
                    };
                    foreach (JSONClass entryJSON in triggerJSON["Triggers"].AsArray)
                    {
                        var trigger = new AtomAnimationTrigger();
                        trigger.RestoreFromJSON(entryJSON);
                        target.SetKeyframe(trigger.startTime, trigger);
                    }
                    target.AddEdgeFramesIfMissing(clip.animationLength);
                    clip.Add(target);
                }
            }
        }