Example #1
0
 private static void BakeSkinningTransform(SkinningWeights newSkinningWeights, Node node)
 {
     if (node is PointObject)
     {
         var point                  = (PointObject)node;
         var originTranslation      = point.TransformedPosition;
         var boneArray              = node.Parent.Parent.AsWidget.BoneArray;
         var localToParentTransform = node.Parent.AsWidget.CalcLocalToParentTransform();
         var transformedPosition    = originTranslation * localToParentTransform *
                                      boneArray.CalcWeightedRelativeTransform(newSkinningWeights).CalcInversed() * localToParentTransform.CalcInversed();
         var translation = (transformedPosition - point.Offset) / point.Parent.AsWidget.Size;
         SetAnimableProperty.Perform(node, nameof(PointObject.Position), translation);
     }
     else
     {
         var widget = node.AsWidget;
         var originLocalToParent = node.AsWidget.CalcLocalToParentTransform();
         var transform           = (originLocalToParent *
                                    widget.Parent.AsWidget.BoneArray.CalcWeightedRelativeTransform(newSkinningWeights).CalcInversed()).ToTransform2();
         SetAnimableProperty.Perform(node, nameof(Widget.Rotation), transform.Rotation);
         var localToParentTransform =
             Matrix32.Translation(-(widget.Pivot * widget.Size)) *
             Matrix32.Transformation(
                 Vector2.Zero,
                 widget.Scale,
                 widget.Rotation * Mathf.Pi / 180f,
                 Vector2.Zero);
         SetAnimableProperty.Perform(node, nameof(Widget.Position), transform.Translation - localToParentTransform.T);
     }
 }
Example #2
0
 void Render(Widget widget)
 {
     widget.PrepareRendererState();
     Renderer.DrawRect(Vector2.Zero, RootWidget.Size, ColorTheme.Current.Toolbar.Background);
     Renderer.Transform1 *= Matrix32.Translation(-Timeline.Instance.Offset.X, 0);
     RenderCursor();
     for (int i = 0; i < Timeline.Instance.ColumnCount; i++)
     {
         var x = i * TimelineMetrics.ColWidth + 0.5f;
         if (i % 10 == 0)
         {
             float textHeight = Theme.Metrics.TextHeight;
             float y          = (RootWidget.Height - textHeight) / 2;
             Renderer.DrawTextLine(
                 new Vector2(x, y), i.ToString(),
                 Theme.Metrics.TextHeight,
                 Theme.Colors.BlackText,
                 0.0f);
             Renderer.DrawLine(x, 0, x, RootWidget.Height, ColorTheme.Current.TimelineRuler.Notchings);
         }
     }
     foreach (var m in Document.Current.Container.Markers)
     {
         RenderMarker(m);
     }
 }
Example #3
0
        public static void ApplyTransformationToWidgetsGroupOobb(IList <Widget> widgetsInParentSpace,
                                                                 Vector2 pivotInParentSpace, bool oobbInFirstWidgetSpace,
                                                                 Vector2 curMousePosInParentSpace, Vector2 prevMousePosInParentSpace,
                                                                 Func <Vector2, Vector2, Matrix32> onCalcTransformationFromOriginalVectorInOobbSpaceAndDeformedVectorInOobbSpace)
        {
            if (widgetsInParentSpace.Count == 0)
            {
                return;
            }

            Matrix32 originalOobbToParentSpace = Matrix32.Translation(pivotInParentSpace);

            if (oobbInFirstWidgetSpace)
            {
                Matrix32 firstWidgetToParentSpace = widgetsInParentSpace[0].CalcLocalToParentTransform();

                originalOobbToParentSpace = firstWidgetToParentSpace *
                                            Matrix32.Translation(firstWidgetToParentSpace.T).CalcInversed() * Matrix32.Translation(pivotInParentSpace);
            }

            ApplyTransformationToWidgetsGroupOobb(
                widgetsInParentSpace, widgetsInParentSpace[0].ParentWidget, originalOobbToParentSpace, curMousePosInParentSpace, prevMousePosInParentSpace,
                onCalcTransformationFromOriginalVectorInOobbSpaceAndDeformedVectorInOobbSpace
                );
        }
Example #4
0
        void Render(Widget widget)
        {
            widget.PrepareRendererState();
            Renderer.DrawRect(Vector2.Zero, RootWidget.Size, ColorTheme.Current.Toolbar.Background);
            Renderer.MultiplyTransform1(Matrix32.Translation(-Timeline.Instance.Offset.X.Round(), 0));
            RenderCursor();
            Timeline.Instance.GetVisibleColumnRange(out var minColumn, out var maxColumn);
            for (int i = minColumn; i <= maxColumn; i++)
            {
                if (i % 10 == 0)
                {
                    var   x          = i * TimelineMetrics.ColWidth + 0.5f;
                    float textHeight = Theme.Metrics.TextHeight;
                    float y          = (RootWidget.Height - textHeight) / 2;
                    Renderer.DrawTextLine(
                        new Vector2(x, y), i.ToString(),
                        Theme.Metrics.TextHeight,
                        Theme.Colors.BlackText,
                        0.0f);
                    if (!Document.Current.Animation.IsCompound)
                    {
                        Renderer.DrawLine(x, 0, x, RootWidget.Height, ColorTheme.Current.TimelineRuler.Notchings);
                    }
                }
            }
            bool metUpperMarker = false;

            foreach (var m in Document.Current.Animation.Markers)
            {
                if (upperMarker != m)
                {
                    RenderMarker(m);
                }
                else
                {
                    metUpperMarker = true;
                }
            }
            if (!metUpperMarker && upperMarker != null)
            {
                upperMarker = null;
            }
            RenderUpperMarker();
        }
Example #5
0
            private void DrawSegments(RulerData rulerData, float strokeDelta, float strokeLength, float?strokeValue = null)
            {
                var maskInverted  = rulerData.RulerOrientation.GetDirection();
                var mask          = (Vector2.One - maskInverted);
                var delta         = mask * strokeDelta;
                var j             = -(int)Math.Round(((rulerData.Origin * mask).Length - rulerData.LeftStoper) / strokeDelta);
                var b             = maskInverted * rulerData.Offset + rulerData.Origin * mask + j * strokeDelta * mask;
                var a             = b - maskInverted * strokeLength;
                var fontHeight    = 14f;
                var letterspacing = 1f;
                var textOffset    = Vector2.Zero;

                do
                {
                    if (GetVectorComponentForOrientation(a, rulerData.RulerOrientation) - rulerData.Offset >= 0)
                    {
                        Renderer.DrawLine(a, b, ColorTheme.Current.SceneView.RulerTextColor);
                        if (strokeValue != null)
                        {
                            var lengthMarkerText     = ((int)(j * strokeValue.Value)).ToString();
                            var textLength           = FontPool.Instance.DefaultFont.MeasureTextLine(lengthMarkerText, fontHeight, letterspacing);
                            var lengthMarkerPosition = a + textOffset;
                            Renderer.PushState(RenderState.Transform1);
                            Renderer.MultiplyTransform1(Matrix32.Translation(lengthMarkerPosition.X.Round(), lengthMarkerPosition.Y.Round()));
                            if (rulerData.RulerOrientation == RulerOrientation.Vertical)
                            {
                                Renderer.MultiplyTransform1(Matrix32.Rotation(-Mathf.HalfPi));
                                textOffset = Vector2.Down * (5 + textLength.X);
                            }
                            else
                            {
                                textOffset = Vector2.Right * 5;
                            }
                            Renderer.DrawTextLine(Vector2.Zero, lengthMarkerText, fontHeight, ColorTheme.Current.SceneView.RulerTextColor, letterspacing);
                            Renderer.PopState();
                        }
                    }
                    j++;
                    a += delta;
                    b += delta;
                } while (rulerData.RightStoper > GetVectorComponentForOrientation(a, rulerData.RulerOrientation));
            }
Example #6
0
        private void Render(Widget widget)
        {
            var maxCol = Timeline.Instance.ColumnCount;

            widget.PrepareRendererState();
            Renderer.DrawRect(Vector2.Zero, widget.ContentSize, ColorTheme.Current.TimelineGrid.PropertyRowBackground);
            var colorIndex = PropertyAttributes <TangerineKeyframeColorAttribute> .Get(animator.Animable.GetType(), animator.TargetPropertyPath)?.ColorIndex ?? 0;

            var color = KeyframePalette.Colors[colorIndex];

            for (int i = 0; i < animator.ReadonlyKeys.Count; i++)
            {
                var key = animator.ReadonlyKeys[i];
                Renderer.Transform1 =
                    Matrix32.RotationRough(Mathf.Pi / 4) *
                    Matrix32.Translation((key.Frame + 0.5f) * TimelineMetrics.ColWidth + 0.5f, widget.Height / 2 + 0.5f) *
                    widget.LocalToWorldTransform;
                var v = TimelineMetrics.ColWidth / 3 * Vector2.One;
                Renderer.DrawRect(-v, v, color);
            }
        }
Example #7
0
 public override void Render()
 {
     Renderer.Transform1 = Matrix32.Translation(Offset) * LocalToWorldTransform;
     SpriteList.Render(Color, MaterialProvider);
 }