示例#1
0
        public void Paste(float time, AtomClipboardEntry clipboard, bool dirty = true)
        {
            if (loop && time >= animationLength - float.Epsilon)
            {
                time = 0f;
            }

            time = time.Snap();

            foreach (var entry in clipboard.controllers)
            {
                var target = TargetControllers.FirstOrDefault(c => c.controller == entry.controller);
                if (target == null)
                {
                    target = Add(entry.controller);
                }
                target.SetCurveSnapshot(time, entry.snapshot, dirty);
            }
            foreach (var entry in clipboard.floatParams)
            {
                var target = TargetFloatParams.FirstOrDefault(c => c.floatParam == entry.floatParam);
                if (target == null)
                {
                    target = Add(entry.storable, entry.floatParam);
                }
                target.SetKeyframe(time, entry.snapshot.value, dirty);
            }
        }
示例#2
0
        private void StartRecordOffset()
        {
            if (current.clipTime < _startJSON.val || current.clipTime > _endJSON.val)
            {
                SuperController.LogError($"VamTimeline: Cannot offset, current time is outside of the bounds of the selection");
                return;
            }
            _offsetSnapshot = current.Copy(current.clipTime, current.GetAllOrSelectedTargets().OfType <FreeControllerAnimationTarget>().Cast <IAtomAnimationTarget>());
            if (_offsetSnapshot.controllers.Count == 0)
            {
                SuperController.LogError($"VamTimeline: Cannot offset, no keyframes were found at time {current.clipTime}.");
                return;
            }

            _offsetControllerUI.label = _offsetControllerUIOfsettingLabel;
            _offsetting = true;
        }
示例#3
0
        private void StartRecordOffset()
        {
            if (current.clipTime < _startJSON.val || current.clipTime > _endJSON.val)
            {
                SuperController.LogError("Timeline: Cannot offset, current time is outside of the bounds of the selection");
                return;
            }

            _offsetSnapshot = operations.Offset().Start(current.clipTime, animationEditContext.GetAllOrSelectedTargets().OfType <FreeControllerAnimationTarget>());

            if (_offsetSnapshot == null)
            {
                return;
            }

            _offsetControllerUI.label = _offsetControllerUIOfsettingLabel;
            _offsetting = true;
        }
        public void Paste(float time, AtomClipboardEntry clipboard, bool dirty = true)
        {
            if (loop && time >= animationLength - float.Epsilon)
            {
                time = 0f;
            }

            time = time.Snap();

            foreach (var entry in clipboard.controllers)
            {
                var target = targetControllers.FirstOrDefault(c => c.controller == entry.controller);
                if (target == null)
                {
                    SuperController.LogError($"Cannot paste controller {entry.controller.name} in animation [{animationLayer}] {animationName} because the target was not added.");
                    continue;
                }
                target.SetCurveSnapshot(time, entry.snapshot, dirty);
            }
            foreach (var entry in clipboard.floatParams)
            {
                var target = targetFloatParams.FirstOrDefault(c => c.storableId == entry.storableId && c.floatParamName == entry.floatParamName);
                if (target == null)
                {
                    SuperController.LogError($"Cannot paste storable {entry.storableId}/{entry.floatParamName} in animation [{animationLayer}] {animationName} because the target was not added.");
                    continue;
                }
                target.SetCurveSnapshot(time, entry.snapshot, dirty);
            }
            foreach (var entry in clipboard.triggers)
            {
                if (!dirty)
                {
                    throw new InvalidOperationException("Cannot paste triggers without dirty");
                }
                var target = targetTriggers.FirstOrDefault(t => t.name == entry.name) ?? targetTriggers.FirstOrDefault();
                if (target == null)
                {
                    SuperController.LogError($"Cannot paste triggers {entry.name} in animation [{animationLayer}] {animationName} because the target was not added.");
                    continue;
                }
                target.SetCurveSnapshot(time, entry.snapshot);
            }
        }
示例#5
0
        public void Apply(AtomClipboardEntry offsetSnapshot, float from, float to, string offsetMode)
        {
            foreach (var snap in offsetSnapshot.controllers)
            {
                var target = _clip.targetControllers.First(t => t.controller == snap.controller);
                if (!target.EnsureParentAvailable(false))
                {
                    continue;
                }
                var posLink    = target.GetPositionParentRB();
                var hasPosLink = !ReferenceEquals(posLink, null);
                var rotLink    = target.GetRotationParentRB();
                var hasRotLink = !ReferenceEquals(rotLink, null);

                Vector3    pivot;
                Vector3    positionDelta;
                Quaternion rotationDelta;

                {
                    var positionBefore = new Vector3(snap.snapshot.x.value, snap.snapshot.y.value, snap.snapshot.z.value);
                    var rotationBefore = new Quaternion(snap.snapshot.rotX.value, snap.snapshot.rotY.value, snap.snapshot.rotZ.value, snap.snapshot.rotW.value);

                    var positionAfter = hasPosLink ? posLink.transform.InverseTransformPoint(snap.controller.transform.position) : snap.controller.control.localPosition;
                    var rotationAfter = hasRotLink ? Quaternion.Inverse(rotLink.rotation) * snap.controller.transform.rotation : snap.controller.control.localRotation;

                    pivot         = positionBefore;
                    positionDelta = positionAfter - positionBefore;
                    rotationDelta = Quaternion.Inverse(rotationBefore) * rotationAfter;
                }

                foreach (var key in target.GetAllKeyframesKeys())
                {
                    var time = target.GetKeyframeTime(key);
                    if (time < from - 0.0001f || time > to + 0.001f)
                    {
                        continue;
                    }
                    // Do not double-apply
                    if (Math.Abs(time - offsetSnapshot.time) < 0.0001)
                    {
                        continue;
                    }

                    var positionBefore = target.GetKeyframePosition(key);
                    var rotationBefore = target.GetKeyframeRotation(key);

                    switch (offsetMode)
                    {
                    case ChangePivotMode:
                    {
                        var positionAfter = rotationDelta * (positionBefore - pivot) + pivot + positionDelta;
                        target.SetKeyframeByKey(key, positionAfter, rotationBefore * rotationDelta);
                        break;
                    }

                    case OffsetMode:
                        target.SetKeyframeByKey(key, positionBefore + positionDelta, rotationBefore * rotationDelta);
                        break;

                    default:
                        throw new NotImplementedException($"Offset mode '{offsetMode}' is not implemented");
                    }
                }
            }
        }