示例#1
0
        private void DrawWireframe(SpriteCache sprite)
        {
            Debug.Assert(Event.current.type == EventType.Repaint);
            Debug.Assert(sprite != null);

            var meshPreview = sprite.GetMeshPreview();
            Debug.Assert(meshPreview != null);

            m_Material.mainTexture = null;
            m_Material.SetFloat("_Opacity", 0.35f);
            m_Material.SetFloat("_VertexColorBlend", 0f);
            m_Material.color = Color.white;

            GL.wireframe = true;
            DrawingUtility.DrawMesh(meshPreview.mesh, m_Material, sprite.GetLocalToWorldMatrixFromMode());
            GL.wireframe = false;
        }
示例#2
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();
            }
        }
示例#3
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());
            }
        }
        internal void RenderSpriteOutline(ISpriteEditor spriteEditor, SpriteCache sprite)
        {
            if (sprite == null)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                UnityEngine.Profiling.Profiler.BeginSample("SpriteOutlineRenderer::RenderSpriteOutline");
                m_OutlineMaterial.SetColor("_OutlineColor", SelectionOutlineSettings.outlineColor);
                m_OutlineMaterial.SetFloat("_AdjustLinearForGamma", PlayerSettings.colorSpace == ColorSpace.Linear ? 1.0f : 0.0f);
                var   texture     = spriteEditor.GetDataProvider <ITextureDataProvider>().texture;
                float outlineSize = Mathf.Max(texture.width, texture.height) * SelectionOutlineSettings.selectedSpriteOutlineSize / 1024.0f;
                m_OutlineMaterial.SetFloat("_OutlineSize", outlineSize);
                var mesh = GetMesh(sprite);
                m_OutlineMaterial.SetPass(0);
                GL.PushMatrix();
                GL.MultMatrix(Handles.matrix * sprite.GetLocalToWorldMatrixFromMode());

                Rect r = new Rect(mesh.bounds.min.x, mesh.bounds.min.y, mesh.bounds.size.x, mesh.bounds.size.y);
                GL.Begin(GL.QUADS);
                GL.Color(Color.white);
                GL.TexCoord(new Vector3(0, 0, 0));
                GL.Vertex3(r.xMin, r.yMin, 0);

                GL.TexCoord(new Vector3(1, 0, 0));
                GL.Vertex3(r.xMax, r.yMin, 0);

                GL.TexCoord(new Vector3(1, 1, 0));
                GL.Vertex3(r.xMax, r.yMax, 0);

                GL.TexCoord(new Vector3(0, 1, 0));
                GL.Vertex3(r.xMin, r.yMax, 0);
                GL.End();
                GL.PopMatrix();
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
示例#5
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());
            }
        }