コード例 #1
0
 private void HandleCancelMultiStepAction()
 {
     if (view.DoCancelMultistepAction(false))
     {
         m_PrevCreatedBone = null;
     }
 }
コード例 #2
0
        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");
                    }
                }
            }
        }
コード例 #3
0
 private void OnBoneNameChanged(BoneCache bone)
 {
     if (m_Model.view.visible)
     {
         m_Model.view.OnSkeletonChanged();
     }
 }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        private List <SpriteBone> GetSpriteBoneDataRecursively(BoneCache bone)
        {
            var bones = new List <SpriteBone>(bone.skeleton.BoneCount);

            AppendSpriteBoneDataRecursively(bones, bone, -1);
            return(bones);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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));
        }
コード例 #9
0
 void OnBoneDepthChanged(BoneCache bone)
 {
     SetAnimationEvent(new AnimationEvent()
     {
         sub_type = AnimationEventType.BoneDepthChanged,
         data     = ""
     });
 }
コード例 #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;
            }
        }
コード例 #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();
     }
 }
コード例 #12
0
        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);
        }
コード例 #13
0
        private void OnBoneNameChanged(BoneCache bone)
        {
            var character = skinningCache.character;

            if (character != null && character.skeleton == bone.skeleton)
            {
                skinningCache.SyncSpriteSheetSkeletons();
            }
            DataModified();
        }
コード例 #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);
        }
コード例 #15
0
        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);
        }
コード例 #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);
            }
        }
コード例 #17
0
        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);
        }
コード例 #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();
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        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);
        }
コード例 #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();
        }
コード例 #22
0
        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));
        }
コード例 #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();
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #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();
        }
コード例 #27
0
        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();
                }
            }
        }
コード例 #28
0
        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
            });
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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));
        }