コード例 #1
0
        private void CharacterPartChanged(CharacterPartCache characterPart)
        {
            var meshPreview = characterPart.sprite.GetMeshPreview();

            Debug.Assert(meshPreview != null);
            meshPreview.SetSkinningDirty();
        }
コード例 #2
0
 void OnCharacterPartChanged(CharacterPartCache part)
 {
     SetAnimationEvent(new AnimationEvent()
     {
         sub_type = AnimationEventType.CharacterPartChanged,
         data     = ""
     });
 }
コード例 #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,
            }));
        }
コード例 #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)));
        }
コード例 #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();
            }
        }
コード例 #6
0
        private void UpdateCharacterPart(CharacterPartCache characterPart)
        {
            var sprite             = characterPart.sprite;
            var characterPartBones = characterPart.bones;
            var newBones           = new List <BoneCache>(characterPartBones);
            var hasNullBones       = newBones.Contains(null);

            newBones.RemoveAll(b => IsRemoved(b));

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

            if (hasNullBones)
            {
                sprite.SmoothFill();
            }
        }
コード例 #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);
        }
コード例 #8
0
        private void UpdateCharacterPart(CharacterPartCache characterPart)
        {
            var sprite             = characterPart.sprite;
            var characterPartBones = characterPart.bones;
            var newBones           = new List <BoneCache>(characterPartBones);

            newBones.RemoveAll(b =>
            {
                return(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();
            }
        }
        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);
        }
コード例 #10
0
        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;

            Debug.Assert(spriteSkeletonBones.Length == characterPartBones.Length);

            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.name          = characterBone.name;
                spriteBone.depth         = characterBone.depth;
                spriteBone.bindPoseColor = characterBone.bindPoseColor;

                spriteBone.SetChildrenWorldPose(childWorldPose);
            }

            if (characterSkeleton.isPosePreview)
            {
                spriteSkeleton.SetPosePreview();
            }
            else
            {
                spriteSkeleton.SetDefaultPose();
            }
        }
コード例 #11
0
        private TreeViewItem CreateTreeViewItem(CharacterPartCache part)
        {
            var name = part.sprite.name;

            return(new TreeViewItemBase <CharacterPartCache>(part.GetInstanceID(), 0, name, part));
        }