Exemplo n.º 1
0
        public IEnumerable <IMesh> Draw()
        {
            if (_line.Line.option.endRatio - _line.Line.option.startRatio <= 0)
            {
                yield break;
            }

            //todo : merge Pairlist with TripleList to one iteration.
            var ff = true;

            Spline.LinePair last = new Spline.LinePair();
            foreach (var pair in _line.Line.TargetPairList)
            {
                if (ff)
                {
                    ff = false;
                    if (_line.Line.option.mode == LineOption.Mode.RoundEdge)// && pairList.Count() > 0)
                    {
                        foreach (var mesh in _capDrawer.Build(pair, false))
                        {
                            yield return(mesh);
                        }
                    }
                }


                foreach (var mesh in _bezierDrawer.Build(pair))
                {
                    yield return(mesh);
                }
                last = pair;
            }

            foreach (var triple in _line.Line.TripleList)
            {
                var joint = _line.Line.option.jointOption == LineOption.LineJointOption.round ? _jointDrawer : _jointIntersectDrawer;

                foreach (var mesh in joint.Build(triple))
                {
                    yield return(mesh);
                }
            }

            if (_line.Line.option.mode == LineOption.Mode.RoundEdge)
            {
                foreach (var mesh in _capDrawer.Build(last, true))
                {
                    yield return(mesh);
                }
            }
        }
Exemplo n.º 2
0
        public IEnumerable <IMesh> Build(Spline.LinePair pair)
        {
            var LineData = _line.Line;//hard copy.

            float   dt   = pair.GetDT(LineData.option.DivideLength);
            Vector3 prv1 = Vector3.zero;
            Vector3 prv2 = Vector3.zero;

            /// todo : too complicate need split code for test or something.
            for (float t = pair.start; t < pair.end; t += dt)
            {
                var ws = Mathf.Lerp(pair.n0.width, pair.n1.width, t);
                var we = Mathf.Lerp(pair.n0.width, pair.n1.width, t + dt);

                var ps = Curve.Auto(pair.n0, pair.n1, t);

                var pe = Curve.Auto(pair.n0, pair.n1, Mathf.Min(pair.end, t + dt));


                var cs = LineData.option.color.Evaluate(pair.sRatio + t * pair.RatioLength);
                var ce = LineData.option.color.Evaluate(pair.sRatio + (t + dt) * pair.RatioLength);

                var d   = pe - ps;
                var wd  = Vector3.Cross(d, Vector3.back).normalized;
                var wds = t == 0f ? Vector3.Cross(Curve.AutoDirection(pair.n0, pair.n1, 0), Vector3.back).normalized : wd;
                var wde = Vector3.Cross(pair.GetDirection(1f), Vector3.back).normalized;

                var uv = new Vector2[] { new Vector2(0, 1), new Vector2(1, 1), Vector2.zero, new Vector2(1, 0) };

                if (_line is Image && ((Image)_line).sprite != null)
                {
                    uv = ((Image)_line).sprite.uv;
                }

                var p0 = Vertex.New(t == pair.start ? ps + wds * ws : prv1, uv[0], cs);
                var p1 = Vertex.New(t == pair.start ? ps - wds * ws : prv2, uv[1], cs);

                var end = Mathf.Abs(t - pair.end) < dt;

                var p2 = Vertex.New(end ? pe + wde * we : pe + wd * we, uv[2], ce);
                var p3 = Vertex.New(end ? pe - wde * we : pe - wd * we, uv[3], ce);

                prv1 = pe + wd * we;
                prv2 = pe - wd * we;

                yield return(new Quad(p0, p1, p2, p3));
            }
        }
Exemplo n.º 3
0
        public IEnumerable <IMesh> Build(Spline.LinePair pair, bool isEnd)
        {
            var normal = Vector3.back;

            var Line = _line.Line; // hardCopy.

            var divideAngle = Line.option.DivideAngle;

            var t = isEnd ? 1f : 0f;

            var color    = Line.option.color.Evaluate(isEnd ? Line.option.endRatio : Line.option.startRatio);
            var position = pair.GetPoisition(t);

            var radian = pair.GetWidth(t);

            var direction = pair.GetDirection(isEnd ? 1 : 0) * (isEnd?-1:1);

            var wv = Vector3.Cross(direction, normal).normalized *radian;

            var dc  = Mathf.Max(1, Mathf.Floor(180f / divideAngle));
            var da  = 180f / dc;
            var rot = Quaternion.Euler(-normal * da);


            var uv = new Vector2[] { new Vector2(0, 1), new Vector2(1, 1), Vector2.zero, new Vector2(1, 0) };

            if (_line is Image && ((Image)_line).sprite != null)
            {
                uv = ((Image)_line).sprite.uv;
            }

            var center = (uv[0] + uv[1] + uv[2] + uv[3]) / 4f;

            for (float a = 0f; a < 179f; a += da)
            {
                var v0 = Vertex.New(position, center, color);
                var v1 = Vertex.New(position + wv, (!isEnd ? a > 90 : a < 90) ? uv[1]:uv[0], color);
                var v2 = Vertex.New(position + rot * wv, (!isEnd ? a > 90 : a < 90) ? uv[3]:uv[2], color);
                yield return(new Triangle(v0, v1, v2));

                wv = rot * wv;
            }
        }