Ejemplo n.º 1
0
        private void CharacterPartChanged(CharacterPartCache characterPart)
        {
            var meshPreview = characterPart.sprite.GetMeshPreview();

            Debug.Assert(meshPreview != null);
            meshPreview.SetSkinningDirty();
        }
 void OnCharacterPartChanged(CharacterPartCache part)
 {
     SetAnimationEvent(new AnimationEvent()
     {
         sub_type = AnimationEventType.CharacterPartChanged,
         data     = ""
     });
 }
Ejemplo n.º 3
0
        private TreeViewItem CreateTreeViewItem(CharacterPartCache part, CharacterGroupCache[] groups, int depth)
        {
            var name = part.sprite.name;

            return(new TreeViewItemBase <ISpriteVisibilityItem>(part.sprite.GetInstanceID(), depth, name,
                                                                new SpriteVisibilitySpriteItem()
            {
                sprite = part,
            }));
        }
Ejemplo n.º 4
0
        private bool NeedsAssociateBones(CharacterPartCache characterPart)
        {
            if (characterPart == null)
            {
                return(false);
            }

            var skeleton = characterPart.skinningCache.character.skeleton;

            return(characterPart.BoneCount == 0 ||
                   (characterPart.BoneCount == 1 && characterPart.GetBone(0) == skeleton.GetBone(0)));
        }
Ejemplo n.º 5
0
        private void CharacterPartChanged(CharacterPartCache characterPart)
        {
            var character = skinningCache.character;

            Debug.Assert(character != null);

            using (new DefaultPoseScope(character.skeleton))
            {
                skinningCache.CreateSpriteSheetSkeleton(characterPart);
                DataModified();
            }

            if (skinningCache.mode == SkinningMode.Character)
            {
                characterPart.SyncSpriteSheetSkeleton();
            }
        }
Ejemplo n.º 6
0
        private void UpdateCharacterPart(CharacterPartCache characterPart)
        {
            var sprite             = characterPart.sprite;
            var characterPartBones = characterPart.bones;
            var newBones           = new List <BoneCache>(characterPartBones);

            newBones.RemoveAll(b => b == null || IsRemoved(b) || b.skeleton != character.skeleton);
            var removedBonesCount = characterPartBones.Length - newBones.Count;

            characterPartBones  = newBones.ToArray();
            characterPart.bones = characterPartBones;
            sprite.UpdateMesh(characterPartBones);

            if (removedBonesCount > 0)
            {
                sprite.SmoothFill();
            }
        }
Ejemplo n.º 7
0
        public void CreateSpriteSheetSkeleton(CharacterPartCache characterPart)
        {
            UpdateCharacterPart(characterPart);

            Debug.Assert(character != null);
            Debug.Assert(character.skeleton != null);
            Debug.Assert(character.skeleton.isPosePreview == false);

            var sprite             = characterPart.sprite;
            var characterPartBones = characterPart.bones;
            var skeleton           = sprite.GetSkeleton();

            Debug.Assert(skeleton != null);

            var spriteBones = characterPartBones.ToSpriteBone(characterPart.localToWorldMatrix);

            skeleton.SetBones(CreateBoneCacheFromSpriteBones(spriteBones, 1.0f), false);

            events.skeletonTopologyChanged.Invoke(skeleton);
        }
        public static void SyncSpriteSheetSkeleton(this CharacterPartCache characterPart)
        {
            var skinningCache       = characterPart.skinningCache;
            var character           = skinningCache.character;
            var characterSkeleton   = character.skeleton;
            var spriteSkeleton      = characterPart.sprite.GetSkeleton();
            var spriteSkeletonBones = spriteSkeleton.bones;
            var characterPartBones  = characterPart.bones;

            if (spriteSkeletonBones.Length != characterPartBones.Length)
            {
                return;
            }

            for (var i = 0; i < characterPartBones.Length; ++i)
            {
                var spriteBone     = spriteSkeletonBones[i];
                var characterBone  = characterPartBones[i];
                var childWorldPose = spriteBone.GetChildrenWoldPose();

                spriteBone.position = spriteSkeleton.localToWorldMatrix.MultiplyPoint3x4(
                    characterPart.worldToLocalMatrix.MultiplyPoint3x4(characterBone.position));
                spriteBone.rotation      = characterBone.rotation;
                spriteBone.length        = characterBone.length;
                spriteBone.guid          = characterBone.guid;
                spriteBone.name          = characterBone.name;
                spriteBone.depth         = characterBone.depth;
                spriteBone.bindPoseColor = characterBone.bindPoseColor;

                spriteBone.SetChildrenWorldPose(childWorldPose);
            }

            if (characterSkeleton.isPosePreview)
            {
                spriteSkeleton.SetPosePreview();
            }
            else
            {
                spriteSkeleton.SetDefaultPose();
            }
        }
        public static void DeassociateUnusedBones(this CharacterPartCache characterPart)
        {
            var skinningCache = characterPart.skinningCache;
            var bones         = characterPart.bones;

            if (bones.Length == 0)
            {
                return;
            }

            Debug.Assert(characterPart.sprite != null);

            var mesh = characterPart.sprite.GetMesh();

            Debug.Assert(mesh != null);

            var vertices    = mesh.vertices;
            var newBonesSet = new HashSet <BoneCache>();

            foreach (var vertex in vertices)
            {
                var boneWeight = vertex.editableBoneWeight;

                foreach (BoneWeightChannel channel in boneWeight)
                {
                    if (channel.enabled)
                    {
                        newBonesSet.Add(bones[channel.boneIndex]);
                    }
                }
            }

            bones = new List <BoneCache>(newBonesSet).ToArray();

            characterPart.bones = bones;

            characterPart.sprite.UpdateMesh(bones);

            skinningCache.events.characterPartChanged.Invoke(characterPart);
        }
Ejemplo n.º 10
0
 internal void SpriteVisibilityChanged(CharacterPartCache cc)
 {
     m_State.lastSpriteVisibility[cc.sprite.id] = cc.isVisible;
 }