コード例 #1
0
        public IEnumerator Execute(List <FreeControllerV3> controllers)
        {
            var containingAtom = _containingAtom;
            var keyOps         = new KeyframesOperations(clip);
            var targetOps      = new TargetsOperations(_containingAtom, _animation, clip);

            yield return(0);

            var controlCounter = 0;
            var motControls    = containingAtom.motionAnimationControls
                                 .Where(m => m?.clip?.clipLength > 0.1f)
                                 .Where(m => controllers.Count == 0 || controllers.Contains(m.controller))
                                 .Where(m => m.clip.steps.Any(s => s.positionOn || s.rotationOn))
                                 .ToList();

            foreach (var mot in motControls)
            {
                FreeControllerAnimationTarget target = null;
                FreeControllerV3 ctrl;

                yield return(new Progress {
                    controllersProcessed = ++controlCounter, controllersTotal = motControls.Count
                });

                try
                {
                    ctrl   = mot.controller;
                    target = clip.targetControllers.FirstOrDefault(t => t.controller == ctrl);

                    if (_animation.index.ByLayer().Where(l => l.Key != clip.animationLayer).Select(l => l.Value.First()).SelectMany(c => c.targetControllers).Any(t2 => t2.controller == ctrl))
                    {
                        SuperController.LogError($"Skipping controller {ctrl.name} because it was used in another layer.");
                        continue;
                    }

                    if (target == null)
                    {
                        target = targetOps.Add(ctrl);
                        target.AddEdgeFramesIfMissing(clip.animationLength);
                    }
                    else
                    {
                        keyOps.RemoveAll(target);
                    }
                    target.StartBulkUpdates();
                    target.Validate(clip.animationLength);

                    var enumerator = ProcessController(mot.clip, target, ctrl).GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        yield return(enumerator.Current);
                    }
                }
                finally
                {
                    // NOTE: This should not be necessary, but for some reason dirty is set back to false too early and some changes are not picked up
                    target.dirty = true;
                    target?.EndBulkUpdates();
                }
            }
        }
コード例 #2
0
ファイル: MocapScreen.cs プロジェクト: jayjaywon/vam-timeline
        private IEnumerator ImportRecordedCoroutine()
        {
            var containingAtom = plugin.containingAtom;
            var totalStopwatch = Stopwatch.StartNew();

            yield return(0);

            var controlCounter = 0;
            var filterSelected = current.targetControllers.Any(c => c.selected);

            foreach (var mot in containingAtom.motionAnimationControls)
            {
                FreeControllerAnimationTarget target = null;
                FreeControllerV3 ctrl;

                _importRecordedUI.buttonText.text = $"Importing, please wait... ({++controlCounter} / {containingAtom.motionAnimationControls.Length})";

                try
                {
                    if (mot == null || mot.clip == null)
                    {
                        continue;
                    }
                    if (mot.clip.clipLength <= 0.1)
                    {
                        continue;
                    }
                    ctrl   = mot.controller;
                    target = current.targetControllers.FirstOrDefault(t => t.controller == ctrl);
                    if (filterSelected && (target == null || !target.selected))
                    {
                        continue;
                    }

                    if (animation.EnumerateLayers().Where(l => l != current.animationLayer).Select(l => animation.clips.First(c => c.animationLayer == l)).SelectMany(c => c.targetControllers).Any(t2 => t2.controller == ctrl))
                    {
                        SuperController.LogError($"Skipping controller {ctrl.name} because it was used in another layer.");
                        continue;
                    }

                    if (target == null)
                    {
                        if (!mot.clip.steps.Any(s => s.positionOn || s.rotationOn))
                        {
                            continue;
                        }
                        target = operations.Targets().Add(ctrl);
                        target.AddEdgeFramesIfMissing(current.animationLength);
                    }
                    target.Validate(current.animationLength);
                    target.StartBulkUpdates();
                    operations.Keyframes().RemoveAll(target);
                }
                catch (Exception exc)
                {
                    SuperController.LogError($"VamTimeline.{nameof(MocapScreen)}.{nameof(ImportRecordedCoroutine)}[Init]: {exc}");
                    target?.EndBulkUpdates();
                    yield break;
                }

                IEnumerator enumerator;
                try
                {
                    if (_importRecordedOptionsJSON.val == "Keyframe Reduction")
                    {
                        enumerator = ExtractFramesWithReductionTechnique(mot.clip, target, ctrl).GetEnumerator();
                    }
                    else
                    {
                        enumerator = ExtractFramesWithFpsTechnique(mot.clip, target, ctrl).GetEnumerator();
                    }
                }
                catch
                {
                    target.EndBulkUpdates();
                    throw;
                }

                while (TryMoveNext(enumerator, target))
                {
                    yield return(enumerator.Current);
                }

                target.EndBulkUpdates();
            }

            _importRecordedUI.buttonText.text     = "Import recorded animation (mocap)";
            _importRecordedUI.button.interactable = true;
        }