Ejemplo n.º 1
0
        public uiMeshMesh transform(uiMatrix3?matrix)
        {
            var vertices = ObjectPool <uiList <Vector3> > .alloc();

            vertices.SetCapacity(this.vertices.Count);
            vertices.AddRange(this.vertices.data);

            var triangles = ObjectPool <uiList <int> > .alloc();

            triangles.SetCapacity(this.triangles.Count);
            triangles.AddRange(this.triangles.data);


            uiList <Vector2> uv = null;

            if (this.uv != null)
            {
                uv = ObjectPool <uiList <Vector2> > .alloc();

                uv.SetCapacity(this.uv.Count);
                uv.AddRange(this.uv.data);
            }


            var ret = create(matrix, vertices, triangles, uv, this.rawBounds);

            return(ret);
        }
Ejemplo n.º 2
0
        uiVertexUV _expandFill(float fringe)
        {
            float aa     = fringe;
            float woff   = aa * 0.5f;
            var   points = this._points;
            var   paths  = this._paths;

            this._calculateJoins(fringe, StrokeJoin.miter, 4.0f);

            var cvertices = 0;

            for (var i = 0; i < paths.Count; i++)
            {
                var path = paths[i];
                if (path.count <= 2)
                {
                    continue;
                }

                cvertices += path.count;
            }

            this._fillConvex = false;
            for (var i = 0; i < paths.Count; i++)
            {
                var path = paths[i];
                if (path.count <= 2)
                {
                    continue;
                }

                if (this._fillConvex)
                {
                    // if more than two paths, convex is false.
                    this._fillConvex = false;
                    break;
                }

                if (!path.convex)
                {
                    // if not convex, convex is false.
                    break;
                }

                this._fillConvex = true;
            }

            var _vertices = ObjectPool <uiList <Vector3> > .alloc();

            _vertices.SetCapacity(cvertices);
            var _uv = ObjectPool <uiList <Vector2> > .alloc();

            _uv.SetCapacity(cvertices);
            for (var i = 0; i < paths.Count; i++)
            {
                var path = paths[i];
                if (path.count <= 2)
                {
                    continue;
                }

                path.ifill = _vertices.Count;
                for (var j = 0; j < path.count; j++)
                {
                    var p = points[path.first + j];
                    if (aa > 0.0f)
                    {
                        _vertices.Add(new Vector2(p.x + p.dmx * woff, p.y + p.dmy * woff));
                    }
                    else
                    {
                        _vertices.Add(new Vector2(p.x, p.y));
                    }

                    _uv.Add(new Vector2(0.5f, 1.0f));
                }

                path.nfill = _vertices.Count - path.ifill;
                paths[i]   = path;
            }

            uiList <Vector3> _strokeVertices = null;
            uiList <Vector2> _strokeUV       = null;

            if (aa > 0.0f)
            {
                _strokeVertices = ObjectPool <uiList <Vector3> > .alloc();

                _strokeUV = ObjectPool <uiList <Vector2> > .alloc();

                cvertices = 0;
                for (var i = 0; i < paths.Count; i++)
                {
                    var path = paths[i];
                    if (path.count <= 2)
                    {
                        continue;
                    }

                    cvertices += path.count * 2;
                }
                _strokeVertices.SetCapacity(cvertices);
                _strokeUV.SetCapacity(cvertices);

                float lw = this._fillConvex ? woff : aa + woff;
                float rw = aa - woff;
                float lu = this._fillConvex ? 0.5f : 0.0f;
                float ru = 1.0f;

                for (var i = 0; i < paths.Count; i++)
                {
                    var path = paths[i];
                    if (path.count <= 2)
                    {
                        continue;
                    }

                    path.istroke = _strokeVertices.Count;
                    for (var j = 0; j < path.count; j++)
                    {
                        var p = points[path.first + j];
                        _strokeVertices.Add(new Vector2(p.x + p.dmx * lw, p.y + p.dmy * lw));
                        _strokeUV.Add(new Vector2(lu, 1.0f));
                        _strokeVertices.Add(new Vector2(p.x - p.dmx * rw, p.y - p.dmy * rw));
                        _strokeUV.Add(new Vector2(ru, 1.0f));
                    }

                    path.nstroke = _strokeVertices.Count - path.istroke;
                    paths[i]     = path;
                }
            }

            return(new uiVertexUV {
                fillVertices = _vertices,
                fillUV = _uv,
                strokeVertices = _strokeVertices,
                strokeUV = _strokeUV,
            });
        }