Пример #1
0
        public static IEnumerable <IDrawData> FromDashes(IEnumerable <MarkupStylePart> dashes)
        {
            var materialGroups = dashes.GroupBy(d => d.MaterialType);

            foreach (var materialGroup in materialGroups)
            {
                var sizeGroups = materialGroup.Where(d => d.Length >= 0.1f).GroupBy(d => new Vector3(Round(d.Length), MeshHeight, d.Width));

                foreach (var sizeGroup in sizeGroups)
                {
                    var groupEnumerator = sizeGroup.GetEnumerator();

                    var buffer = new MarkupStylePart[16];
                    var count  = 0;

                    bool isEnd = groupEnumerator.MoveNext();
                    do
                    {
                        buffer[count] = groupEnumerator.Current;
                        count        += 1;
                        isEnd         = !groupEnumerator.MoveNext();
                        if (isEnd || count == 16)
                        {
                            var batch = new RenderBatch(buffer, count, sizeGroup.Key, materialGroup.Key);
                            yield return(batch);

                            count = 0;
                        }
                    }while (!isEnd);
                }
            }
        }
Пример #2
0
        public static bool CalculateSolidPart(LineBorders borders, ITrajectory trajectory, float offset, float width, Color32 color, out MarkupStylePart part)
        {
            part = CalculateSolidPart(trajectory, offset, width, color);

            if (borders.IsEmpty)
            {
                return(true);
            }

            var vertex = borders.GetVertex(part);

            var from = 0f;
            var to   = 1f;

            foreach (var border in borders)
            {
                for (var i = 0; i < vertex.Length; i += 2)
                {
                    var start = Intersection.CalculateSingle(border, vertex[i]);
                    var end   = Intersection.CalculateSingle(border, vertex[i + 1]);

                    if (start.IsIntersect && end.IsIntersect)
                    {
                        return(false);
                    }

                    if (!start.IsIntersect && !end.IsIntersect)
                    {
                        continue;
                    }

                    var intersect = Intersection.CalculateSingle(border, new StraightTrajectory(vertex[i].EndPosition, vertex[i + 1].EndPosition));
                    if (intersect.IsIntersect)
                    {
                        if (start.IsIntersect)
                        {
                            from = Mathf.Max(from, intersect.SecondT);
                        }
                        else if (end.IsIntersect)
                        {
                            to = Mathf.Min(to, intersect.SecondT);
                        }
                    }
                }
            }

            if (from != 0f || to != 1f)
            {
                var dir  = part.Angle.Direction();
                var line = new StraightTrajectory(part.Position + dir * (part.Length / 2), part.Position - dir * (part.Length / 2)).Cut(from, to);
                part = new MarkupStylePart(line.StartPosition, line.EndPosition, line.Direction, part.Width, part.Color);
            }
            return(true);
        }
Пример #3
0
        public static bool CalculateDashedParts(LineBorders borders, ITrajectory trajectory, float startT, float endT, float dashLength, float offset, float width, Color32 color, out MarkupStylePart part)
        {
            part = CalculateDashedPart(trajectory, startT, endT, dashLength, offset, width, color);

            if (borders.IsEmpty)
            {
                return(true);
            }

            var vertex = borders.GetVertex(part);

            return(!borders.Any(c => vertex.Any(v => Intersection.CalculateSingle(c, v).IsIntersect)));
        }