private void HandleCancelMultiStepAction()
 {
     if (view.DoCancelMultistepAction(false))
     {
         m_PrevCreatedBone = null;
     }
 }
        private void ValidateBone(BoneCache bone)
        {
            if (bone == null)
            {
                return;
            }

            var skinningCache = bone.skinningCache;

            if (skinningCache.hasCharacter)
            {
                if (bone.skeleton != skinningCache.character.skeleton)
                {
                    throw new Exception("Selection Exception: bone does not belong to character skeleton");
                }
            }
            else
            {
                var selectedSprite = skinningCache.selectedSprite;

                if (selectedSprite == null)
                {
                    throw new Exception("Selection Exception: skeleton not selected");
                }
                else
                {
                    var skeleton = selectedSprite.GetSkeleton();

                    if (bone.skeleton != skeleton)
                    {
                        throw new Exception("Selection Exception: bone's skeleton does not match selected skeleton");
                    }
                }
            }
        }
 private void OnBoneNameChanged(BoneCache bone)
 {
     if (m_Model.view.visible)
     {
         m_Model.view.OnSkeletonChanged();
     }
 }
        private void AppendSpriteBoneDataRecursively(List <SpriteBone> spriteBones, BoneCache bone, int parentIndex)
        {
            int currentParentIndex = spriteBones.Count;

            var spriteBone = new SpriteBone();

            spriteBone.name     = bone.name;
            spriteBone.parentId = parentIndex;
            if (parentIndex == -1 && bone.parentBone != null)
            {
                spriteBone.position = bone.position;
                spriteBone.rotation = bone.rotation;
            }
            else
            {
                spriteBone.position = bone.localPosition;
                spriteBone.rotation = bone.localRotation;
            }
            spriteBone.position = new Vector3(spriteBone.position.x, spriteBone.position.y, bone.depth);

            spriteBone.length = bone.localLength;
            spriteBones.Add(spriteBone);

            foreach (var child in bone)
            {
                var childBone = child as BoneCache;
                if (childBone != null)
                {
                    AppendSpriteBoneDataRecursively(spriteBones, childBone, currentParentIndex);
                }
            }
        }
Exemple #5
0
        private List <SpriteBone> GetSpriteBoneDataRecursively(BoneCache bone)
        {
            var bones = new List <SpriteBone>(bone.skeleton.BoneCount);

            AppendSpriteBoneDataRecursively(bones, bone, -1);
            return(bones);
        }
        private Vector3 GetFlippedBonePosition(BoneCache bone, Vector2 startPosition, Rect spriteRect
                                               , bool flipX, bool flipY)
        {
            Vector3 position = startPosition;

            if (flipX)
            {
                position.x += spriteRect.width - bone.position.x;
            }
            else
            {
                position.x += bone.position.x;
            }

            if (flipY)
            {
                position.y += spriteRect.height - bone.position.y;
            }
            else
            {
                position.y += bone.position.y;
            }

            position.z = bone.position.z;
            return(position);
        }
        public static BoneCache CreateBone(this SkeletonCache skeleton, BoneCache parentBone, Vector3 position, Vector3 endPosition, bool isChained, string name)
        {
            Debug.Assert(skeleton != null);

            if (parentBone != null)
            {
                Debug.Assert(skeleton.Contains(parentBone));
            }

            var bone = skeleton.skinningCache.CreateCache <BoneCache>();

            bone.SetParent(parentBone);
            bone.name          = name;
            bone.bindPoseColor = ModuleUtility.CalculateNiceColor(skeleton.BoneCount, 6);
            bone.position      = position;
            bone.endPosition   = endPosition;

            if (isChained && parentBone != null)
            {
                parentBone.chainedChild = bone;
            }

            skeleton.AddBone(bone);


            return(bone);
        }
        public string GetUniqueName(BoneCache bone)
        {
            Debug.Assert(Contains(bone));

            var boneName = bone.name;
            var names    = m_Bones.ConvertAll(b => b.name);
            var index    = IndexOf(bone);
            var count    = 0;

            Debug.Assert(index < names.Count);

            for (var i = 0; i < index; ++i)
            {
                if (names[i].Equals(boneName))
                {
                    ++count;
                }
            }

            if (count == 0)
            {
                return(boneName);
            }

            return(string.Format("{0} ({1})", boneName, count + 1));
        }
 void OnBoneDepthChanged(BoneCache bone)
 {
     SetAnimationEvent(new AnimationEvent()
     {
         sub_type = AnimationEventType.BoneDepthChanged,
         data     = ""
     });
 }
Exemple #10
0
        public void SetTreeViewBoneName(IList <TreeViewItem> items, BoneCache bone)
        {
            var treeBone = items.FirstOrDefault(x => ((TreeViewItemBase <BoneCache>)x).customData == bone);

            if (treeBone != null)
            {
                treeBone.displayName = bone.name;
            }
        }
Exemple #11
0
 public void SetName(BoneCache bone, string name)
 {
     var characterBone = bone.ToCharacterIfNeeded();
     characterBone.name = name;
     if (characterBone != bone || skinningCache.mode == SkinningMode.Character)
     {
         skinningCache.SyncSpriteSheetSkeletons();
     }
 }
        private void DrawBone(BoneCache bone, Color color)
        {
            var isSelected           = selection.Contains(bone.ToCharacterIfNeeded());
            var isNotOnVisualElement = !skinningCache.IsOnVisualElement();
            var isJointHovered       = view.IsActionHot(SkeletonAction.None) && hoveredJoint == bone && isNotOnVisualElement;
            var isTailHovered        = view.IsActionHot(SkeletonAction.None) && hoveredTail == bone && isNotOnVisualElement;

            view.DrawBone(bone.position, bone.right, Vector3.forward, bone.length, color, bone.chainedChild != null, isSelected, isJointHovered, isTailHovered, bone == hotBone);
        }
Exemple #13
0
        private void OnBoneNameChanged(BoneCache bone)
        {
            var character = skinningCache.character;

            if (character != null && character.skeleton == bone.skeleton)
            {
                skinningCache.SyncSpriteSheetSkeletons();
            }
            DataModified();
        }
Exemple #14
0
        public void SetDepth(BoneCache bone, int depth)
        {
            var characterBone = bone.ToCharacterIfNeeded();
            characterBone.depth = depth;
            
            if (characterBone != bone || skinningCache.mode == SkinningMode.Character)
                skinningCache.SyncSpriteSheetSkeletons();

            skinningCache.events.boneDepthChanged.Invoke(bone);
        }
        public static void SetEndPosition(this SkeletonCache skeleton, BoneCache bone, Vector3 endPosition)
        {
            Debug.Assert(skeleton != null);
            Debug.Assert(bone != null);
            Debug.Assert(skeleton.Contains(bone));

            var childrenStorage = bone.GetChildrenWoldPose();

            bone.endPosition = endPosition;
            bone.SetChildrenWorldPose(childrenStorage);
        }
Exemple #16
0
        private static void AddTreeViewItem(IList <TreeViewItem> rows, BoneCache bone, BoneCache[] bones, int depth)
        {
            var item = new TreeViewItemBase <BoneCache>(bone.GetInstanceID(), -1, bone.name, bone);

            item.depth = depth;
            rows.Add(item);

            foreach (var childBone in bones.Where(x => x.parentBone == bone))
            {
                AddTreeViewItem(rows, childBone, bones, depth + 1);
            }
        }
        public void AddBone(BoneCache bone, bool worldPositionStays)
        {
            Debug.Assert(bone != null);
            Debug.Assert(!Contains(bone));

            if (bone.parent == null)
            {
                bone.SetParent(this, worldPositionStays);
            }

            m_Bones.Add(bone);
        }
Exemple #18
0
        public void SetBoneParent(BoneCache newParent, BoneCache bone)
        {
            TransformCache parent = newParent;

            if (newParent == null)
            {
                parent = bone.skeleton;
            }

            skinningCache.RestoreBindPose();
            bone.SetParent(parent, true);
            bone.SetDefaultPose();
        }
        private static void AddTreeViewItem(IList <TreeViewItem> rows, BoneCache bone, BoneCache[] bones, int depth)
        {
            var item = new TreeViewItemBase <BoneCache>(bone.GetInstanceID(), depth, bone.name, bone);

            rows.Add(item);

            var children = bones.Where(x => x.parentBone == bone).ToArray();

            System.Array.Sort(children, (a, b) => a.siblingIndex.CompareTo(b.siblingIndex));

            foreach (var childBone in children)
            {
                AddTreeViewItem(rows, childBone, bones, depth + 1);
            }
        }
        public void DestroyBone(BoneCache bone)
        {
            Debug.Assert(bone != null);
            Debug.Assert(Contains(bone));

            m_Bones.Remove(bone);

            var children = bone.children;

            foreach (var child in children)
            {
                child.SetParent(bone.parent);
            }

            skinningCache.Destroy(bone);
        }
Exemple #21
0
        public void SetBoneParent(BoneCache newParent, BoneCache bone, int insertAtIndex)
        {
            TransformCache parent = newParent;

            if (newParent == null)
                parent = bone.skeleton;

            skinningCache.RestoreBindPose();
            bone.SetParent(parent, true);

            if (insertAtIndex == -1)
                insertAtIndex = parent.ChildCount;

            bone.siblingIndex = insertAtIndex;
            bone.SetDefaultPose();
        }
        public Color GetOutlineColor(BoneCache bone, bool isSelected, bool isHovered)
        {
            var skinningCache = bone.skinningCache;

            if (isSelected)
            {
                return(SelectionOutlineSettings.outlineColor);
            }

            if (isHovered)
            {
                return(Handles.preselectionColor);
            }

            return(SetAlpha(CalculateOutlineColor(GetBoneColorRaw(bone), VisibilityToolSettings.boneOpacity), GetAlpha(bone), VisibilityToolSettings.boneOpacity));
        }
Exemple #23
0
        public override void Initialize(LayoutOverlay layout)
        {
            base.Initialize(layout);

            m_WeightPainterPanel = WeightPainterPanel.GenerateFromUXML();
            m_WeightPainterPanel.SetHiddenFromLayout(true);
            layout.rightOverlay.Add(m_WeightPainterPanel);

            m_WeightPainterPanel.sliderStarted += () =>
            {
                EditStart(skinningCache.vertexSelection, false);
            };
            m_WeightPainterPanel.sliderChanged += (value) =>
            {
                EditWeights(value, true);
                meshTool.UpdateWeights();
            };
            m_WeightPainterPanel.sliderEnded += () =>
            {
                EditEnd();
            };
            m_WeightPainterPanel.bonePopupChanged += (i) =>
            {
                var skeleton = skinningCache.GetEffectiveSkeleton(skinningCache.selectedSprite);

                if (skeleton != null)
                {
                    BoneCache bone = null;

                    if (i != -1)
                    {
                        bone = skeleton.GetBone(i).ToCharacterIfNeeded();
                    }

                    if (bone != skinningCache.skeletonSelection.activeElement)
                    {
                        using (skinningCache.UndoScope(TextContent.boneSelection))
                        {
                            skinningCache.skeletonSelection.activeElement = bone;
                            InvokeBoneSelectionChanged();
                        }
                    }
                }
            };
            m_WeightPainterPanel.weightsChanged += () => meshTool.UpdateWeights();
        }
        protected override float GetAlpha(BoneCache bone)
        {
            var skinningCache  = bone.skinningCache;
            var selectedSprite = skinningCache.selectedSprite;
            var alpha          = 0.9f;

            if (skinningCache.mode == SkinningMode.Character && skinningCache.selectedSprite != null)
            {
                var characterPart = selectedSprite.GetCharacterPart();

                if (characterPart.Contains(bone) == false)
                {
                    alpha = 0.25f;
                }
            }

            return(alpha);
        }
        public static BoneCache ToSpriteSheetIfNeeded(this BoneCache bone)
        {
            if (bone == null)
            {
                return(null);
            }

            var skinningCache = bone.skinningCache;

            if (skinningCache.hasCharacter && skinningCache.mode == SkinningMode.SpriteSheet)
            {
                var selectedSprite = skinningCache.selectedSprite;

                if (selectedSprite == null)
                {
                    return(null);
                }

                var characterSkeleton = skinningCache.character.skeleton;

                Debug.Assert(bone.skeleton == characterSkeleton);

                var skeleton      = selectedSprite.GetSkeleton();
                var characterPart = selectedSprite.GetCharacterPart();

                Debug.Assert(skeleton != null);
                Debug.Assert(characterPart != null);
                Debug.Assert(skeleton.BoneCount == characterPart.BoneCount);

                var index = characterPart.IndexOf(bone);

                if (index == -1)
                {
                    bone = null;
                }
                else
                {
                    bone = skeleton.GetBone(index);
                }
            }

            return(bone);
        }
Exemple #26
0
        private void OnBoneDepthChanged(BoneCache bone)
        {
            var sprites    = skinningCache.GetSprites();
            var controller = new SpriteMeshDataController();

            foreach (var sprite in sprites)
            {
                var mesh = sprite.GetMesh();

                if (mesh.ContainsBone(bone))
                {
                    controller.spriteMeshData = mesh;
                    controller.SortTrianglesByDepth();
                    skinningCache.events.meshChanged.Invoke(mesh);
                }
            }

            DataModified();
        }
        private void HandleCreateBone()
        {
            Vector3 position;

            if (view.DoCreateBoneStart(out position))
            {
                m_PrevCreatedBone = null;

                if (hoveredTail != null)
                {
                    m_PrevCreatedBone         = hoveredTail;
                    m_CreateBoneStartPosition = hoveredTail.endPosition;
                }
                else
                {
                    m_CreateBoneStartPosition = position;
                }
            }

            if (view.DoCreateBone(out position))
            {
                using (skinningCache.UndoScope(TextContent.createBone))
                {
                    var isChained  = m_PrevCreatedBone != null;
                    var parentBone = isChained ? m_PrevCreatedBone : rootBone;

                    if (isChained)
                    {
                        m_CreateBoneStartPosition = m_PrevCreatedBone.endPosition;
                    }

                    var name = AutoBoneName(parentBone, skeleton.bones);
                    var bone = m_Skeleton.CreateBone(parentBone, m_CreateBoneStartPosition, position, isChained, name);

                    m_PrevCreatedBone         = bone;
                    m_CreateBoneStartPosition = bone.endPosition;

                    InvokeTopologyChanged();
                    InvokePoseChanged();
                }
            }
        }
        public static SpriteBone ToSpriteBone(this BoneCache bone, Matrix4x4 rootTransform, int parentId)
        {
            var position = bone.localPosition;
            var rotation = bone.localRotation;

            if (parentId == -1)
            {
                rotation = bone.rotation;
                position = rootTransform.inverse.MultiplyPoint3x4(bone.position);
            }

            return(new SpriteBone()
            {
                name = bone.name,
                position = new Vector3(position.x, position.y, bone.depth),
                rotation = rotation,
                length = bone.localLength,
                parentId = parentId
            });
        }
        public static BoneCache SplitBone(this SkeletonCache skeleton, BoneCache boneToSplit, float splitLength, string name)
        {
            Debug.Assert(skeleton.Contains(boneToSplit));
            Debug.Assert(boneToSplit.length > splitLength);

            var endPosition   = boneToSplit.endPosition;
            var chainedChild  = boneToSplit.chainedChild;
            var splitPosition = boneToSplit.position + boneToSplit.right * splitLength;

            boneToSplit.length = splitLength;

            var bone = skeleton.CreateBone(boneToSplit, splitPosition, endPosition, true, name);

            if (chainedChild != null)
            {
                chainedChild.SetParent(bone);
                bone.chainedChild = chainedChild;
            }

            return(bone);
        }
        private Quaternion GetFlippedBoneRotation(BoneCache bone, bool flipX, bool flipY)
        {
            var euler = bone.rotation.eulerAngles;

            if (flipX)
            {
                if (euler.z <= 180)
                {
                    euler.z = 180 - euler.z;
                }
                else
                {
                    euler.z = 540 - euler.z;
                }
            }
            if (flipY)
            {
                euler.z = 360 - euler.z;
            }
            return(Quaternion.Euler(euler));
        }