private void GenerateWeights(SpriteCache sprite)
 {
     using (m_GenerateWeightsPanel.associateBones ? new AssociateBonesScope(sprite) : null)
     {
         m_SpriteMeshDataController.spriteMeshData = sprite.GetMesh();
         m_SpriteMeshDataController.CalculateWeights(m_WeightGenerator, skinningCache.vertexSelection, kWeightTolerance);
         m_SpriteMeshDataController.SortTrianglesByDepth();
     }
 }
        private void HandleWeightsForSprite(SpriteCache sprite, Action <SpriteCache> action)
        {
            Debug.Assert(sprite != null);

            using (new DefaultPoseScope(skinningCache.GetEffectiveSkeleton(sprite)))
            {
                action(sprite);
            }

            skinningCache.events.meshChanged.Invoke(sprite.GetMesh());
        }
        public static void UpdateMesh(this SpriteCache sprite, BoneCache[] bones)
        {
            var mesh        = sprite.GetMesh();
            var previewMesh = sprite.GetMeshPreview();

            Debug.Assert(mesh != null);
            Debug.Assert(previewMesh != null);

            mesh.bones = bones;

            previewMesh.SetWeightsDirty();
        }
Example #4
0
        internal void SetupSprite(SpriteCache sprite)
        {
            var mesh = sprite.GetMesh();

            if (m_Mesh != mesh && selection.Count > 0)
            {
                selection.Clear();
            }

            m_Mesh = mesh;
            m_SpriteMeshController.spriteMeshData = m_Mesh;
        }
        public static void SmoothFill(this SpriteCache sprite)
        {
            var mesh = sprite.GetMesh();

            if (mesh == null)
            {
                return;
            }

            var controller = new SpriteMeshDataController();

            controller.spriteMeshData = mesh;
            controller.SmoothFill();
        }
        private void DrawDefaultSpriteMesh(SpriteCache sprite)
        {
            Debug.Assert(m_Material != null);

            var meshPreview = sprite.GetMeshPreview();
            var meshCache   = sprite.GetMesh();
            var skeleton    = skinningCache.GetEffectiveSkeleton(sprite);

            Debug.Assert(meshPreview != null);

            if (meshPreview.canSkin == false || skeleton.isPosePreview == false)
            {
                m_Material.mainTexture = meshCache.textureDataProvider.texture;
                m_Material.SetFloat("_Opacity", 1f);
                m_Material.SetFloat("_VertexColorBlend", 0f);
                m_Material.color = new Color(1f, 1f, 1f, 1f);

                DrawingUtility.DrawMesh(meshPreview.defaultMesh, m_Material, sprite.GetLocalToWorldMatrixFromMode());
            }
        }
Example #7
0
        private void GenerateWeights(SpriteCache sprite)
        {
            Debug.Assert(sprite != null);

            var mesh = sprite.GetMesh();

            Debug.Assert(mesh != null);

            using (new DefaultPoseScope(skinningCache.GetEffectiveSkeleton(sprite)))
            {
                if (NeedsAssociateBones(sprite.GetCharacterPart()))
                {
                    using (new AssociateBonesScope(sprite))
                    {
                        GenerateWeights(mesh);
                    }
                }
                else
                {
                    GenerateWeights(mesh);
                }
            }
        }
Example #8
0
        private void GenerateGeometry(SpriteCache sprite, float outlineDetail, byte alphaTolerance, float subdivide)
        {
            Debug.Assert(sprite != null);

            var mesh = sprite.GetMesh();

            Debug.Assert(mesh != null);

            m_SpriteMeshDataController.spriteMeshData = mesh;
            m_SpriteMeshDataController.OutlineFromAlpha(m_OutlineGenerator, mesh.textureDataProvider, outlineDetail, alphaTolerance);
            m_SpriteMeshDataController.Triangulate(m_Triangulator);

            if (subdivide > 0f)
            {
                var largestAreaFactor = Mathf.Lerp(0.5f, 0.05f, Math.Min(subdivide, 100f) / 100f);
                m_SpriteMeshDataController.Subdivide(m_Triangulator, largestAreaFactor);
            }

            foreach (var vertex in mesh.vertices)
            {
                vertex.position -= sprite.textureRect.position;
            }
        }
        private void DrawSpriteMesh(SpriteCache sprite, float weightMapOpacity)
        {
            Debug.Assert(m_Material != null);

            var meshPreview = sprite.GetMeshPreview();
            var meshCache   = sprite.GetMesh();

            Debug.Assert(meshPreview != null);

            if (meshPreview.mesh == null || meshPreview.mesh.vertexCount == 0)
            {
                DrawDefaultSpriteMesh(sprite);
            }
            else
            {
                m_Material.mainTexture = meshCache.textureDataProvider.texture;
                m_Material.SetFloat("_Opacity", 1f);
                m_Material.SetFloat("_VertexColorBlend", weightMapOpacity);

                m_Material.color = Color.white;

                DrawingUtility.DrawMesh(meshPreview.mesh, m_Material, sprite.GetLocalToWorldMatrixFromMode());
            }
        }
Example #10
0
        public bool ShouldDisable(SpriteCache sprite)
        {
            var mesh = sprite.GetMesh();

            return(mesh == null || mesh.vertices.Count == 0);
        }
 private void ClearWeights(SpriteCache sprite)
 {
     m_SpriteMeshDataController.spriteMeshData = sprite.GetMesh();
     m_SpriteMeshDataController.ClearWeights(skinningCache.vertexSelection);
 }
 private void NormalizeWeights(SpriteCache sprite)
 {
     m_SpriteMeshDataController.spriteMeshData = sprite.GetMesh();
     m_SpriteMeshDataController.NormalizeWeights(skinningCache.vertexSelection);
     m_SpriteMeshDataController.SortTrianglesByDepth();
 }