예제 #1
0
 private void OnSelectionChanged(SpriteCache spriteCache)
 {
     CheckDataProviderChanged();
     AddOrUpdateMaskTexture(spriteCache, false);
 }
예제 #2
0
 private void OnSpriteSelectionChange(SpriteCache sprite)
 {
     skinningCache.events.selectedSpriteChanged.RemoveListener(OnSpriteSelectionChange);
     selectedSprite = sprite;
     skinningCache.events.selectedSpriteChanged.AddListener(OnSpriteSelectionChange);
 }
 public CharacterPartCache GetSpriteCharacterPart(SpriteCache sprite)
 {
     return(sprite.GetCharacterPart());
 }
예제 #4
0
 private void OnSelectedSpriteChanged(SpriteCache sprite)
 {
     UpdatePanel();
 }
예제 #5
0
 public bool OverlayWireframe(SpriteCache sprite)
 {
     return(sprite.IsVisible() && sprite.skinningCache.selectedSprite == sprite);
 }
예제 #6
0
 private void ClearWeights(SpriteCache sprite)
 {
     m_SpriteMeshDataController.spriteMeshData = sprite.GetMesh();
     m_SpriteMeshDataController.ClearWeights(skinningCache.vertexSelection);
 }
예제 #7
0
 private void SelectedSpriteChanged(SpriteCache sprite)
 {
     SetupSkeleton(skinningCache.GetEffectiveSkeleton(sprite));
 }
예제 #8
0
        public NewBonesStore PasteSkeletonBones(SpriteCache sprite, List <SpriteBone> spriteBones, bool flipX, bool flipY, float scale = 1.0f)
        {
            NewBonesStore newBonesStore = new NewBonesStore();

            newBonesStore.newBones = skinningCache.CreateBoneCacheFromSpriteBones(spriteBones.ToArray(), scale);
            if (newBonesStore.newBones.Length == 0)
            {
                return(null);
            }

            if (sprite == null || (skinningCache.mode == SkinningMode.SpriteSheet && skinningCache.hasCharacter))
            {
                return(null);
            }

            var spriteRect = sprite.textureRect;
            var skeleton   = skinningCache.GetEffectiveSkeleton(sprite);

            var rectPosition = spriteRect.position;

            if (skinningCache.mode == SkinningMode.Character)
            {
                var characterPart = sprite.GetCharacterPart();
                if (characterPart == null)
                {
                    return(null);
                }
                rectPosition = characterPart.position;
            }

            var newPositions = new Vector3[newBonesStore.newBones.Length];
            var newRotations = new Quaternion[newBonesStore.newBones.Length];

            for (var i = 0; i < newBonesStore.newBones.Length; ++i)
            {
                newPositions[i] = GetFlippedBonePosition(newBonesStore.newBones[i], rectPosition, spriteRect, flipX, flipY);
                newRotations[i] = GetFlippedBoneRotation(newBonesStore.newBones[i], flipX, flipY);
            }
            for (var i = 0; i < newBonesStore.newBones.Length; ++i)
            {
                if (newBonesStore.newBones[i].parent == null)
                {
                    SetBonePositionAndRotation(newBonesStore.newBones, newBonesStore.newBones[i], newPositions, newRotations);
                }
            }

            if (skinningCache.mode == SkinningMode.SpriteSheet)
            {
                newBonesStore.MapAllExistingBones();
                skeleton.SetBones(newBonesStore.newBones);
            }
            else
            {
                var existingBoneNames = skeleton.bones.Select(x => x.name).ToList();

                skeleton.AddBones(newBonesStore.newBones);

                var bones = skeleton.bones;

                // Update names of all newly pasted bones
                foreach (var bone in newBonesStore.newBones)
                {
                    if (existingBoneNames.Contains(bone.name))
                    {
                        var oldBoneName = bone.name;
                        bone.name = SkeletonController.AutoBoneName(bone.parentBone, bones);
                        existingBoneNames.Add(bone.name);
                        newBonesStore.newBoneNameDict.Add(oldBoneName, bone.name);
                    }
                    else
                    {
                        newBonesStore.newBoneNameDict.Add(bone.name, bone.name);
                    }
                }

                skeleton.SetDefaultPose();
            }

            skinningCache.events.skeletonTopologyChanged.Invoke(skeleton);
            return(newBonesStore);
        }
예제 #9
0
        public void PasteMesh(SpriteCache sprite, SkinningCopySpriteData skinningSpriteData, bool flipX, bool flipY, float scale, NewBonesStore newBonesStore)
        {
            if (sprite == null)
            {
                return;
            }

            meshTool.SetupSprite(sprite);
            meshTool.mesh.vertices = skinningSpriteData.vertices;
            if (!Mathf.Approximately(scale, 1f) || flipX || flipY)
            {
                var spriteRect = sprite.textureRect;
                foreach (var vertex in meshTool.mesh.vertices)
                {
                    var position = vertex.position;
                    if (!Mathf.Approximately(scale, 1f))
                    {
                        position = position * scale;
                    }
                    if (flipX)
                    {
                        position.x = spriteRect.width - vertex.position.x;
                    }
                    if (flipY)
                    {
                        position.y = spriteRect.height - vertex.position.y;
                    }
                    vertex.position = position;
                }
            }
            meshTool.mesh.indices = skinningSpriteData.indices;
            meshTool.mesh.edges   = skinningSpriteData.edges;

            int[]       copyBoneToNewBones = new int[skinningSpriteData.boneWeightNames.Count];
            BoneCache[] setBones           = null;

            if (newBonesStore != null && newBonesStore.newBones != null)
            {
                // Update bone weights with new bone indices
                var setBonesList = new List <BoneCache>();
                copyBoneToNewBones = new int[skinningSpriteData.boneWeightNames.Count];
                int index = 0;
                for (int i = 0; i < skinningSpriteData.boneWeightNames.Count; ++i)
                {
                    string oldBoneName = skinningSpriteData.boneWeightNames[i];
                    string newBoneName;
                    newBonesStore.newBoneNameDict.TryGetValue(oldBoneName, out newBoneName);
                    var newBone = newBonesStore.newBones.FirstOrDefault(bone => bone.name == newBoneName);
                    copyBoneToNewBones[i] = -1;
                    if (newBone == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < skinningSpriteData.spriteBones.Count; ++j)
                    {
                        if (skinningSpriteData.spriteBones[j].spriteBone.name == oldBoneName)
                        {
                            copyBoneToNewBones[i] = index++;
                            setBonesList.Add(newBone);
                            break;
                        }
                    }
                }
                setBones = setBonesList.ToArray();
            }
            else
            {
                // Attempt to link weights based on existing bone names
                var skeleton       = skinningCache.GetEffectiveSkeleton(sprite);
                var characterBones = new List <BoneCache>();
                for (int i = 0; i < skinningSpriteData.boneWeightNames.Count; ++i)
                {
                    copyBoneToNewBones[i] = -1;
                    var boneName = skinningSpriteData.boneWeightNames[i];
                    for (int j = 0; j < skeleton.bones.Length; ++j)
                    {
                        if (skeleton.bones[j].name == boneName)
                        {
                            copyBoneToNewBones[i] = characterBones.Count;
                            characterBones.Add(skeleton.bones[j]);
                            break;
                        }
                    }
                }
                setBones = characterBones.ToArray();
            }

            // Remap new bone indexes from copied bone indexes
            foreach (var vertex in meshTool.mesh.vertices)
            {
                var editableBoneWeight = vertex.editableBoneWeight;

                for (var i = 0; i < editableBoneWeight.Count; ++i)
                {
                    if (!editableBoneWeight[i].enabled)
                    {
                        continue;
                    }

                    if (copyBoneToNewBones.Length > editableBoneWeight[i].boneIndex)
                    {
                        var boneIndex = copyBoneToNewBones[editableBoneWeight[i].boneIndex];
                        if (boneIndex != -1)
                        {
                            editableBoneWeight[i].boneIndex = boneIndex;
                        }
                    }
                }
            }

            // Update associated bones for mesh
            meshTool.mesh.SetCompatibleBoneSet(setBones);
            meshTool.mesh.bones = setBones; // Fixes weights for bones that do not exist

            // Update associated bones for character
            if (skinningCache.hasCharacter)
            {
                var characterPart = sprite.GetCharacterPart();
                if (characterPart != null)
                {
                    characterPart.bones = setBones;
                    skinningCache.events.characterPartChanged.Invoke(characterPart);
                }
            }

            meshTool.UpdateMesh();
        }
예제 #10
0
        public SkinningCopyData CopySingle(SpriteCache sprite)
        {
            var skinningCopyData = new SkinningCopyData();

            skinningCopyData.pixelsPerUnit = pixelsPerUnit;

            // Mesh
            var skinningSpriteData = new SkinningCopySpriteData();

            skinningCopyData.copyData.Add(skinningSpriteData);

            CopyMeshFromSpriteCache(sprite, skinningSpriteData);

            // Bones
            var rootBones = new List <BoneCache>();

            BoneCache[] boneCache = null;
            if (skinningCache.hasCharacter)
            {
                var characterPart = skinningCache.GetCharacterPart(sprite);
                if (characterPart != null && characterPart.bones != null)
                {
                    boneCache = characterPart.bones;
                    var bones = characterPart.bones.FindRoots();
                    foreach (var bone in bones)
                    {
                        rootBones.Add(bone);
                    }
                }
            }
            else
            {
                var skeleton = skinningCache.GetEffectiveSkeleton(sprite);
                if (skeleton != null && skeleton.BoneCount > 0)
                {
                    boneCache = skeleton.bones;
                    var bones = boneCache.FindRoots();
                    foreach (var bone in bones)
                    {
                        rootBones.Add(bone);
                    }
                }
            }

            if (rootBones.Count > 0)
            {
                skinningSpriteData.spriteBones = new List <SpriteBoneCopyData>();
                foreach (var rootBone in rootBones)
                {
                    var rootBoneIndex = skinningSpriteData.spriteBones.Count;
                    GetSpriteBoneDataRecursively(skinningSpriteData.spriteBones, rootBone, boneCache.ToList());
                    if (skinningCache.hasCharacter)
                    {
                        // Offset the bones based on the currently selected Sprite in Character mode
                        var characterPart = sprite.GetCharacterPart();
                        if (characterPart != null)
                        {
                            var offset         = characterPart.position;
                            var rootSpriteBone = skinningSpriteData.spriteBones[rootBoneIndex];
                            rootSpriteBone.spriteBone.position            = rootSpriteBone.spriteBone.position - offset;
                            skinningSpriteData.spriteBones[rootBoneIndex] = rootSpriteBone;
                        }
                    }
                }
            }

            return(skinningCopyData);
        }
예제 #11
0
        public void OnPasteActivated(bool bone, bool mesh, bool flipX, bool flipY)
        {
            var copyBuffer = m_CopyToolStringStore.stringStore;

            if (!IsValidCopyData(copyBuffer))
            {
                Debug.LogError(TextContent.copyError1);
                return;
            }

            var skinningCopyData = SkinningCopyUtility.DeserializeStringToSkinningCopyData(copyBuffer);

            if (skinningCopyData == null || skinningCopyData.copyData.Count == 0)
            {
                Debug.LogError(TextContent.copyError2);
                return;
            }

            var scale = 1f;

            if (skinningCopyData.pixelsPerUnit > 0f)
            {
                scale = pixelsPerUnit / skinningCopyData.pixelsPerUnit;
            }

            var sprites      = skinningCache.GetSprites();
            var copyMultiple = skinningCopyData.copyData.Count > 1;

            if (copyMultiple && skinningCopyData.copyData.Count != sprites.Length && mesh)
            {
                Debug.LogError(String.Format(TextContent.copyError3, sprites.Length, skinningCopyData.copyData.Count));
                return;
            }

            using (skinningCache.UndoScope(TextContent.pasteData))
            {
                NewBonesStore newBonesStore = null;
                if (bone && copyMultiple && skinningCache.hasCharacter)
                {
                    newBonesStore = new NewBonesStore();
                    var skinningSpriteData = skinningCopyData.copyData[0];
                    newBonesStore.newBones = skinningCache.CreateBoneCacheFromSpriteBones(skinningSpriteData.spriteBones.Select(y => y.spriteBone).ToArray(), scale);
                    if (flipX || flipY)
                    {
                        var characterRect = new Rect(Vector2.zero, skinningCache.character.dimension);
                        var newPositions  = new Vector3[newBonesStore.newBones.Length];
                        var newRotations  = new Quaternion[newBonesStore.newBones.Length];
                        for (var i = 0; i < newBonesStore.newBones.Length; ++i)
                        {
                            newPositions[i] = GetFlippedBonePosition(newBonesStore.newBones[i], Vector2.zero, characterRect, flipX, flipY);
                            newRotations[i] = GetFlippedBoneRotation(newBonesStore.newBones[i], flipX, flipY);
                        }
                        for (var i = 0; i < newBonesStore.newBones.Length; ++i)
                        {
                            newBonesStore.newBones[i].position = newPositions[i];
                            newBonesStore.newBones[i].rotation = newRotations[i];
                        }
                    }
                    newBonesStore.MapAllExistingBones();
                    var skeleton = skinningCache.character.skeleton;
                    skeleton.SetBones(newBonesStore.newBones);
                    skinningCache.events.skeletonTopologyChanged.Invoke(skeleton);
                }

                foreach (var skinningSpriteData in skinningCopyData.copyData)
                {
                    SpriteCache sprite = null;
                    if (!String.IsNullOrEmpty(skinningSpriteData.spriteName))
                    {
                        sprite = sprites.FirstOrDefault(x => x.name == skinningSpriteData.spriteName);
                    }
                    if (sprite == null && (skinningCopyData.copyData.Count == 1 || String.IsNullOrEmpty(skinningSpriteData.spriteName)))
                    {
                        sprite = skinningCache.selectedSprite;
                    }
                    if (sprite == null)
                    {
                        continue;
                    }

                    if (bone && (!skinningCache.hasCharacter || !copyMultiple))
                    {
                        var spriteBones = new SpriteBone[skinningSpriteData.spriteBones.Count];
                        for (int i = 0; i < skinningSpriteData.spriteBones.Count; ++i)
                        {
                            var order = skinningSpriteData.spriteBones[i].order;
                            spriteBones[order] = skinningSpriteData.spriteBones[i].spriteBone;
                            var parentId = spriteBones[order].parentId;
                            if (parentId >= 0)
                            {
                                spriteBones[order].parentId = skinningSpriteData.spriteBones[parentId].order;
                            }
                        }
                        newBonesStore = PasteSkeletonBones(sprite, spriteBones.ToList(), flipX, flipY, scale);
                    }

                    if (mesh && meshTool != null)
                    {
                        PasteMesh(sprite, skinningSpriteData, flipX, flipY, scale, newBonesStore);
                    }
                }

                if (newBonesStore != null && newBonesStore.newBones != null)
                {
                    skinningCache.skeletonSelection.elements = newBonesStore.newBones;
                    skinningCache.events.boneSelectionChanged.Invoke();
                }
            }
            skinningCache.events.paste.Invoke(bone, mesh, flipX, flipY);
        }
예제 #12
0
 private void OnSelectedSpriteChanged(SpriteCache sprite)
 {
     SetupSprite(sprite);
 }
예제 #13
0
 public void SetSelection(SpriteCache sprite)
 {
     ((SpriteTreeView)m_TreeView).SetSelection(sprite);
 }
예제 #14
0
        public void SetSelection(SpriteCache sprite)
        {
            var id = GetController().GetTreeViewSelectionID(sprite);

            SetSelection(new[] { id }, TreeViewSelectionOptions.RevealAndFrame);
        }
예제 #15
0
 private void OnSelectionChange(SpriteCache sprite)
 {
     SetupSkeleton();
     m_Model.SetAllVisibility(null, true);
 }
예제 #16
0
 public bool DrawWireframe(SpriteCache sprite)
 {
     return(false);
 }
예제 #17
0
 private void NormalizeWeights(SpriteCache sprite)
 {
     m_SpriteMeshDataController.spriteMeshData = sprite.GetMesh();
     m_SpriteMeshDataController.NormalizeWeights(skinningCache.vertexSelection);
     m_SpriteMeshDataController.SortTrianglesByDepth();
 }
예제 #18
0
 public bool Overlay(SpriteCache sprite)
 {
     return(false);
 }
예제 #19
0
 void OnSpriteSelectionChanged(SpriteCache sprite)
 {
     m_GenerateWeightsPanel.generateButtonText = sprite != null ? TextContent.generate : TextContent.generateAll;
 }
예제 #20
0
 public float GetWeightMapOpacity(SpriteCache sprite)
 {
     return(0f);
 }
예제 #21
0
 private void StorePersistentStateVisibilityForSkeleton(SkeletonCache skeleton, SpriteCache sprite)
 {
     foreach (var bone in skeleton.bones)
     {
         var id = GetBoneNameHash(m_StringBuilder, bone, sprite);
         m_State.lastBoneVisibility[id] = bone.isVisible;
     }
 }
 public AssociateBonesScope(SpriteCache sprite)
 {
     m_Sprite         = sprite;
     m_AssociateBones = m_Sprite.AssociatePossibleBones();
 }