internal void Setup(VRM10Controller target, ILookAtEyeDirectionProvider eyeDirectionProvider, ILookAtEyeDirectionApplicable eyeDirectionApplicable)
        {
            Restore();

            _merger = new ExpressionMerger(Clips, target.transform);
            _keys   = Clips.Select(ExpressionKey.CreateFromClip).ToList();
            var oldInputWeights = _inputWeights;

            _inputWeights = _keys.ToDictionary(x => x, x => 0f);
            foreach (var key in _keys)
            {
                // remain user input weights.
                if (oldInputWeights.ContainsKey(key))
                {
                    _inputWeights[key] = oldInputWeights[key];
                }
            }
            _actualWeights          = _keys.ToDictionary(x => x, x => 0f);
            _validator              = ExpressionValidatorFactory.Create(this);
            _eyeDirectionProvider   = eyeDirectionProvider;
            _eyeDirectionApplicable = eyeDirectionApplicable;
        }
Beispiel #2
0
        public void ChangeAnimation(string animationName)
        {
            var clip = Clips.FirstOrDefault(c => c.AnimationName == animationName);

            if (clip == null)
            {
                throw new NullReferenceException($"Could not find animation '{animationName}'. Found animations: '{string.Join("', '", Clips.Select(c => c.AnimationName).ToArray())}'.");
            }
            var targetAnim = _unityAnimation[animationName];
            var time       = Time;

            if (_isPlaying)
            {
                if (HasAnimatableControllers())
                {
                    targetAnim.time    = 0f;
                    targetAnim.enabled = true;
                    targetAnim.weight  = 0f;
                    _unityAnimation.Blend(Current.AnimationName, 0f, Current.BlendDuration);
                    _unityAnimation.Blend(animationName, 1f, Current.BlendDuration);
                }
                if (Current.AnimationPattern != null)
                {
                    // Let the loop finish during the transition
                    Current.AnimationPattern.SetBoolParamValue("loopOnce", true);
                }
                _previousClip     = Current;
                _blendingTimeLeft = _blendingDuration = Current.BlendDuration;
            }

            var previous = Current;

            Current    = clip;
            _animState = targetAnim;

            if (_isPlaying)
            {
                DetermineNextAnimation(_playTime);

                if (Current.AnimationPattern != null)
                {
                    Current.AnimationPattern.SetBoolParamValue("loopOnce", false);
                    Current.AnimationPattern.ResetAndPlay();
                }
            }
            else
            {
                Time = 0f;
                Sample();
                CurrentAnimationChanged.Invoke(new CurrentAnimationChangedEventArgs
                {
                    Before = previous,
                    After  = Current
                });
            }
        }
Beispiel #3
0
        public override void Draw(byte[] RgbValues, BitmapData bmpData, bool Antialiesing)
        {
            base.Draw(RgbValues, bmpData, Antialiesing);

            if (!Fill)
            {
                return;
            }

            ClippedLine.Clip clip;

            if (Clips == null || Clips.Count() == 0)
            {
                clip = new ClippedLine.Clip()
                {
                    down  = int.MinValue,
                    up    = int.MaxValue,
                    left  = int.MinValue,
                    right = int.MaxValue
                }
            }
            ;
            else
            {
                clip = Clips.Select(rec => new ClippedLine.Clip(rec)).Aggregate((a, b) => a * b);
            }

            int Ymax = (int)Math.Round(Points.Select(p => p.Y).Max());
            int Ymin = (int)Math.Round(Points.Select(p => p.Y).Min());

            List <LinkedList <aetElem> > et = new List <LinkedList <aetElem> >(new LinkedList <aetElem> [Ymax - Ymin + 1]);

            for (int i = 0; i < et.Count; i++)
            {
                et[i] = new LinkedList <aetElem>();
            }

            for (int i = 0; i < Points.Count; i++)
            {
                DrawingPoint p1 = Points[i], p2 = Points[(i + 1) % Points.Count];
                aetElem      elem = new aetElem(p1, p2);
                et[(int)Math.Round(Math.Min(p1.Y, p2.Y)) - Ymin].AddLast(elem);
            }

            LinkedList <aetElem> aet = new LinkedList <aetElem>();

            int y = Ymin;

            while (y <= Ymax && y <= clip.up)
            {
                foreach (var e in et[y - Ymin])
                {
                    aet.AddLast(e);
                }

                for (var i = aet.First; i != null;)
                {
                    bool rm = i.Value.Ymax == y;
                    var  k  = i;
                    i = i.Next;
                    if (rm)
                    {
                        aet.Remove(k);
                    }
                }

                if (y >= clip.down)
                {
                    for (var i = aet.OrderBy(e => e.x).GetEnumerator(); i.MoveNext();)
                    {
                        var i1 = i.Current;
                        i.MoveNext();
                        var i2 = i.Current;
                        for (int x = Math.Max((int)Math.Ceiling(i1.x), (int)Math.Ceiling(clip.left));
                             x <= Math.Min((int)i2.x, (int)clip.right);
                             x++)
                        {
                            PutPixel(x, y, RgbValues, bmpData);
                        }
                    }
                }

                foreach (var e in aet)
                {
                    e.x += e.mi;
                }

                y++;
            }
        }