Example #1
0
        public static void Perform(IEnumerable <Node> nodes, Widget container, bool flipX, bool flipY)
        {
            if (!flipX && !flipY)
            {
                return;
            }
            var roots = new List <Bone>();

            foreach (var bone in nodes.OfType <Bone>())
            {
                var root = BoneUtils.FindBoneRoot(bone, container.Nodes);
                if (!roots.Contains(root))
                {
                    if (flipX && flipY)
                    {
                        SetAnimableProperty.Perform(root, nameof(Bone.Rotation), root.Rotation + 180);
                    }
                    else
                    {
                        SetAnimableProperty.Perform(root, nameof(Bone.Rotation), (flipY ? 180 : 0) - root.Rotation);
                        SetAnimableProperty.Perform(root, nameof(Bone.Length), -root.Length);
                        var bones = BoneUtils.FindBoneDescendats(root,
                                                                 Document.Current.Container.Nodes.OfType <Bone>());
                        foreach (var childBone in bones)
                        {
                            SetAnimableProperty.Perform(childBone, nameof(Bone.Rotation), -childBone.Rotation);
                            SetAnimableProperty.Perform(childBone, nameof(Bone.Length), -childBone.Length);
                        }
                    }
                    roots.Add(root);
                }
            }
        }
Example #2
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 #3
0
        public static void Perform(object obj, string propertyName, object value)
        {
            var       animable = obj as IAnimable;
            IAnimator animator;

            if (animable != null && animable.Animators.TryFind(propertyName, out animator, Document.Current.AnimationId) &&
                animator.ReadonlyKeys.Count > 0)
            {
                SetAnimableProperty.Perform(obj, propertyName, value);
            }
            else
            {
                SetProperty.Perform(obj, propertyName, value);
            }
        }
Example #4
0
        public static void Perform(IEnumerable <Bone> bones, IEnumerable <Widget> widgets)
        {
            var boneList = bones.ToList();

            if (!widgets.Any() || !bones.Any())
            {
                return;
            }
            if (!CheckConsistency(bones, widgets))
            {
                throw new InvalidOperationException("Not all bones and widgets have the same parent");
            }
            foreach (var widget in widgets)
            {
                if (widget is DistortionMesh)
                {
                    var mesh = widget as DistortionMesh;
                    foreach (PointObject point in mesh.Nodes)
                    {
                        if (!CanApplyBone(point.SkinningWeights))
                        {
                            throw new TieWidgetsWithBonesException(point);
                        }
                        SetProperty.Perform(point, nameof(PointObject.SkinningWeights),
                                            CalcSkinningWeight(point.SkinningWeights, point.CalcPositionInSpaceOf(widget.ParentWidget), boneList));
                    }
                }
                else
                {
                    if (!CanApplyBone(widget.SkinningWeights))
                    {
                        throw new TieWidgetsWithBonesException(widget);
                    }
                    SetProperty.Perform(widget, nameof(Widget.SkinningWeights),
                                        CalcSkinningWeight(widget.SkinningWeights, widget.Position, boneList));
                }
            }
            foreach (var bone in bones)
            {
                var entry = bone.Parent.AsWidget.BoneArray[bone.Index];
                SetAnimableProperty.Perform(bone, nameof(Bone.RefPosition), entry.Joint, CoreUserPreferences.Instance.AutoKeyframes);
                SetAnimableProperty.Perform(bone, nameof(Bone.RefLength), entry.Length, CoreUserPreferences.Instance.AutoKeyframes);
                SetAnimableProperty.Perform(bone, nameof(Bone.RefRotation), entry.Rotation, CoreUserPreferences.Instance.AutoKeyframes);
            }
        }
Example #5
0
 public static void Perform(IEnumerable <Node> nodes, Widget container, bool flipX, bool flipY)
 {
     if (!flipX && !flipY)
     {
         return;
     }
     foreach (var widget in nodes.OfType <Widget>())
     {
         var s = widget.Scale;
         if (flipX)
         {
             s.X = -s.X;
         }
         if (flipY)
         {
             s.Y = -s.Y;
         }
         SetAnimableProperty.Perform(widget, nameof(Widget.Scale), s);
     }
     FlipBones.Perform(nodes, container, flipX, flipY);
 }