Ejemplo n.º 1
0
		public void Apply(SVGAsset svgAsset)
		{
			this.format = svgAsset.format;
            this.useGradients = svgAsset.useGradients;
            this.antialiasing = svgAsset.antialiasing;
            this.antialiasingWidth = svgAsset.antialiasingWidth;
			this.meshCompression = svgAsset.meshCompression;
			this.scale = svgAsset.scale;
			this.vpm = svgAsset.vpm;
			this.depthOffset = svgAsset.depthOffset;
			this.compressDepth = svgAsset.compressDepth;
			this.customPivotPoint = svgAsset.customPivotPoint;
			this.pivotPoint = svgAsset.pivotPoint;
            this.border = svgAsset.border;
            this.sliceMesh = svgAsset.sliceMesh;
            this.generateCollider = svgAsset.generateCollider;
			this.keepSVGFile = svgAsset.keepSVGFile;
            this.ignoreSVGCanvas = svgAsset.ignoreSVGCanvas;
            this.optimizeMesh = svgAsset.optimizeMesh;
            this.generateNormals = svgAsset.generateNormals;
            this.generateTangents = svgAsset.generateTangents;
		}
Ejemplo n.º 2
0
		public void Apply(SerializedObject serializedObject)
		{
			this.format = (SVGAssetFormat)serializedObject.FindProperty("_format").enumValueIndex;
            this.useGradients = (SVGUseGradients)serializedObject.FindProperty("_useGradients").enumValueIndex;
            this.antialiasing = serializedObject.FindProperty("_antialiasing").boolValue;
            this.antialiasingWidth = serializedObject.FindProperty("_antialiasingWidth").floatValue;
			this.meshCompression = (SVGMeshCompression)serializedObject.FindProperty("_meshCompression").enumValueIndex;
			this.scale = serializedObject.FindProperty("_scale").floatValue;
			this.vpm = serializedObject.FindProperty("_vpm").floatValue;
			this.depthOffset = serializedObject.FindProperty("_depthOffset").floatValue;
			this.compressDepth = serializedObject.FindProperty("_compressDepth").boolValue;
			this.customPivotPoint = serializedObject.FindProperty("_customPivotPoint").boolValue;
			this.pivotPoint = serializedObject.FindProperty("_pivotPoint").vector2Value;
            this.border = serializedObject.FindProperty("_border").vector4Value;
            this.sliceMesh = serializedObject.FindProperty("_sliceMesh").boolValue;
            this.generateCollider = serializedObject.FindProperty("_generateCollider").boolValue;
			this.keepSVGFile = serializedObject.FindProperty("_keepSVGFile").boolValue;
            this.ignoreSVGCanvas = serializedObject.FindProperty("_ignoreSVGCanvas").boolValue;
            this.optimizeMesh = serializedObject.FindProperty("_optimizeMesh").boolValue;
            this.generateNormals = serializedObject.FindProperty("_generateNormals").boolValue;
            this.generateTangents = serializedObject.FindProperty("_generateTangents").boolValue;
		}
Ejemplo n.º 3
0
        public static Mesh CombineMeshes(List<SVGMesh> meshes, out SVGLayer[] layers, out Shader[] shaders, SVGUseGradients useGradients = SVGUseGradients.Always, SVGAssetFormat format = SVGAssetFormat.Transparent, bool compressDepth = true)
        {
            layers = new SVGLayer[0];
            shaders = new Shader[0];

            //if(SVGAssetImport.sliceMesh) Create9Slice();

            SVGFill fill;
            bool useOpaqueShader = false;
            bool useTransparentShader = false;
            bool hasGradients = (useGradients == SVGUseGradients.Always);

            int totalMeshes = meshes.Count, totalTriangles = 0, opaqueTriangles = 0, transparentTriangles = 0;

            // Z Sort meshes
            if(format == SVGAssetFormat.Opaque)
            {
                if(compressDepth)
                {
                    SVGBounds meshBounds = SVGBounds.InfiniteInverse;
                    for (int i = 0; i < totalMeshes; i++)
                    {
                        if (meshes [i] == null) continue;
                        meshBounds.Encapsulate(meshes [i].bounds);
                    }

                    if(!meshBounds.isInfiniteInverse)
                    {
                        SVGGraphics.depthTree.Clear();
                        SVGGraphics.depthTree = new SVGDepthTree(meshBounds);

                        for (int i = 0; i < totalMeshes; i++)
                        {
                            fill = meshes [i]._fill;
                            SVGMesh[] nodes = SVGGraphics.depthTree.TestDepthAdd(meshes [i], new SVGBounds(meshes [i]._bounds));
                            int nodesLength = 0;
                            if(nodes == null || nodes.Length == 0)
                            {
                                meshes [i]._depth = 0;
                            } else {
                                nodesLength = nodes.Length;
                                int highestDepth = 0;
                                SVGMesh highestMesh = null;
                                for(int j = 0; j < nodesLength; j++)
                                {
                                    if(nodes[j].depth > highestDepth)
                                    {
                                        highestDepth = nodes[j].depth;
                                        highestMesh = nodes[j];
                                    }
                                }

                                if(fill.blend == FILL_BLEND.OPAQUE)
                                {
                                    meshes [i]._depth = highestDepth + 1;
                                } else {
                                    if(highestMesh != null && highestMesh.fill.blend == FILL_BLEND.OPAQUE)
                                    {
                                        meshes [i]._depth = highestDepth + 1;
                                    } else {
                                        meshes [i]._depth = highestDepth;
                                    }
                                }
                            }

                            meshes [i].UpdateDepth();
                        }
                    }
                } else {
                    int highestDepth = 0;
                    for (int i = 0; i < totalMeshes; i++)
                    {
                        fill = meshes [i]._fill;
                        if (fill.blend == FILL_BLEND.OPAQUE || lastBlendType == FILL_BLEND.OPAQUE)
                        {
                            meshes[i]._depth = ++highestDepth;
                        } else
                        {
                            meshes[i]._depth = highestDepth;
                        }

                        lastBlendType = fill.blend;
                        meshes[i].UpdateDepth();
                    }
                }
            }

            layers = new SVGLayer[totalMeshes];
            int totalVertices = 0, vertexCount, vertexStart, currentVertex;
            for(int i = 0; i < totalMeshes; i++)
            {
                fill = meshes[i]._fill;
                if(fill.blend == FILL_BLEND.OPAQUE) {
                    opaqueTriangles += meshes[i]._triangles.Length;
                    useOpaqueShader = true;
                }
                else if(fill.blend == FILL_BLEND.ALPHA_BLENDED) {
                    transparentTriangles += meshes[i]._triangles.Length;
                    useTransparentShader = true;
                }
                if(fill.fillType == FILL_TYPE.GRADIENT) hasGradients = true;

                vertexCount = meshes[i]._vertices.Length;
                Bounds bounds = meshes[i]._bounds;
                layers[i] = new SVGLayer(meshes[i]._name, totalVertices, vertexCount, bounds.center, bounds.size);
                totalVertices += vertexCount;
            }

            totalTriangles = opaqueTriangles + transparentTriangles;

            if(useGradients == SVGUseGradients.Never) hasGradients = false;
            if(format != SVGAssetFormat.Opaque)
            {
                useOpaqueShader = false;
                useTransparentShader = true;
            }

            Vector3[] vertices = new Vector3[totalVertices];
            Color32[] colors32 = new Color32[totalVertices];
            Vector2[] uv = null;
            Vector2[] uv2 = null;
            int[][] triangles = null;

            for(int i = 0; i < totalMeshes; i++)
            {
                vertexStart = layers[i].vertexStart;
                vertexCount = layers[i].vertexCount;
                for(int j = 0; j < vertexCount; j++)
                {
                    currentVertex = vertexStart + j;
                    vertices[currentVertex] = meshes[i]._vertices[j];
                    colors32[currentVertex] = meshes[i]._colors[j];
                }
            }

            List<Shader> outputShaders = new List<Shader>();
            //            Debug.Log("hasGradients: "+hasGradients);
            if(hasGradients)
            {
                uv = new Vector2[totalVertices];
                uv2 = new Vector2[totalVertices];

                for(int i = 0; i < totalMeshes; i++)
                {
                    vertexStart = layers[i].vertexStart;
                    vertexCount = layers[i].vertexCount;
                    for(int j = 0; j < vertexCount; j++)
                    {
                        currentVertex = vertexStart + j;
                        uv[currentVertex] = meshes[i]._uvs[j];
                        uv2[currentVertex] = meshes[i]._uvs2[j];
                    }
                }

                if(useOpaqueShader)
                {
                    outputShaders.Add(SVGShader.GradientColorOpaque);
                }
                if(useTransparentShader)
                {
                    outputShaders.Add(SVGShader.GradientColorAlphaBlended);
                }
            } else {
                if(useOpaqueShader)
                {
                    outputShaders.Add(SVGShader.SolidColorOpaque);
                }
                if(useTransparentShader)
                {
                    outputShaders.Add(SVGShader.SolidColorAlphaBlended);
                }
            }

            if(useOpaqueShader && useTransparentShader)
            {
                triangles = new int[2][]{new int[opaqueTriangles], new int[transparentTriangles]};

                int lastVertexIndex = 0;
                int triangleCount;
                int lastOpauqeTriangleIndex = 0;
                int lastTransparentTriangleIndex = 0;

                for(int i = 0; i < totalMeshes; i++)
                {
                    triangleCount = meshes[i]._triangles.Length;
                    if(meshes[i]._fill.blend == FILL_BLEND.OPAQUE)
                    {
                        for(int j = 0; j < triangleCount; j++)
                        {
                            triangles[0][lastOpauqeTriangleIndex++] = lastVertexIndex + meshes[i]._triangles[j];
                        }
                    } else {
                        for(int j = 0; j < triangleCount; j++)
                        {
                            triangles[1][lastTransparentTriangleIndex++] = lastVertexIndex + meshes[i]._triangles[j];
                        }
                    }

                    lastVertexIndex += layers[i].vertexCount;
                }
            } else {
                triangles = new int[1][]{new int[totalTriangles]};

                int lastVertexIndex = 0;
                int triangleCount;
                int lastTriangleIndex = 0;

                for(int i = 0; i < totalMeshes; i++)
                {
                    triangleCount = meshes[i]._triangles.Length;
                    for(int j = 0; j < triangleCount; j++)
                    {
                        triangles[0][lastTriangleIndex++] = lastVertexIndex + meshes[i]._triangles[j];
                    }
                    lastVertexIndex += layers[i].vertexCount;
                }
            }

            if(outputShaders.Count != 0) shaders = outputShaders.ToArray();

            Mesh output = new Mesh();
            output.vertices = vertices;
            output.colors32 = colors32;

            if(hasGradients)
            {
                output.uv = uv;
                output.uv2 = uv2;
            }

            if(triangles.Length == 1)
            {
                output.triangles = triangles[0];
            } else {
                output.subMeshCount = triangles.Length;
                for(int i = 0; i < triangles.Length; i++)
                {
                    output.SetTriangles(triangles[i], i);
                }
            }

            return output;
        }