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());
        }
Exemplo n.º 3
0
        internal void SetupSprite(SpriteCache sprite)
        {
            var mesh = sprite.GetMesh();

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

            m_Mesh = mesh;
            m_SpriteMeshController.spriteMeshData = m_Mesh;
        }
Exemplo n.º 4
0
        internal void RenderSpriteOutline(ISpriteEditor spriteEditor, SpriteCache sprite)
        {
            if (spriteEditor == null || sprite == null)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                if (SelectionOutlineSettings.selectedSpriteOutlineSize < 0.01f || SelectionOutlineSettings.outlineColor.a < 0.01f)
                {
                    return;
                }

                var mesh = GetMesh(sprite);
                if (mesh == null)
                {
                    return;
                }

                UnityEngine.Profiling.Profiler.BeginSample("SpriteOutlineRenderer::RenderSpriteOutline");

                var vertices   = mesh.vertices;
                var edges      = sprite.GetMesh().edges;
                var multMatrix = Handles.matrix * sprite.GetLocalToWorldMatrixFromMode();

                var texture        = spriteEditor.GetDataProvider <ITextureDataProvider>().texture;
                var outlineSize    = SelectionOutlineSettings.selectedSpriteOutlineSize;
                var outlineColor   = SelectionOutlineSettings.outlineColor;
                var adjustForGamma = PlayerSettings.colorSpace == ColorSpace.Linear ? 1.0f : 0.0f;

                if (edges != null && edges.Count > 0 && vertices.Length > 0)
                {
                    var finalOutlineSize = outlineSize / spriteEditor.zoomLevel;
                    DrawEdgeOutline(edges, vertices, multMatrix, finalOutlineSize, outlineColor, adjustForGamma);
                }
                else // Fallback: Draw using the Sobel filter.
                {
                    var finalOutlineSize = Mathf.Max(texture.width, texture.height) * outlineSize / k_ReferenceTextureSize;
                    DrawMeshOutline(mesh, sprite, multMatrix, finalOutlineSize, outlineColor, adjustForGamma);
                }

                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
Exemplo n.º 5
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 = subdivide != 0 ? Mathf.Lerp(0.5f, 0.05f, Math.Min(subdivide, 100f) / 100f) : subdivide;
                m_SpriteMeshDataController.Subdivide(m_Triangulator, largestAreaFactor, 0f);
            }
        }
Exemplo n.º 6
0
        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());
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 8
0
        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());
            }
        }
        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();
 }