public void FromXml(string version, XElement config, Dictionary <ObjectId, ObjectId> map = null) { if (VersionComparer.Instance.Compare(version, "1.2") < 0) { map = VersionMigration.Befor1_2(this, map); } foreach (var pointConfig in config.Elements(MarkupPoint.XmlName)) { MarkupPoint.FromXml(pointConfig, this, map); } var toInit = new Dictionary <MarkupLine, XElement>(); foreach (var lineConfig in config.Elements(MarkupLine.XmlName)) { if (MarkupLine.FromXml(lineConfig, this, map, out MarkupLine line)) { LinesDictionary[line.Id] = line; toInit[line] = lineConfig; } } foreach (var pair in toInit) { pair.Key.FromXml(pair.Value, map); } foreach (var fillerConfig in config.Elements(MarkupFiller.XmlName)) { if (MarkupFiller.FromXml(fillerConfig, this, map, out MarkupFiller filler)) { FillersList.Add(filler); } } }
protected virtual List <List <FillerContour.Part> > GetContours(MarkupFiller filler) { var originalContour = filler.Contour.Parts.ToList(); var contours = StyleHelper.SetOffset(originalContour, LineOffset, MedianOffset); return(contours); }
public virtual void GetUIComponents(MarkupFiller filler, List <EditorItem> components, UIComponent parent, bool isTemplate = false) { if (!isTemplate && filler.IsMedian) { components.Add(AddMedianOffsetProperty(this, parent)); } }
public override LodDictionaryArray <IStyleData> Calculate(MarkupFiller filler) { if (CurbSize == 0f && MedianCurbSize == 0f) { return(base.Calculate(filler)); } else { var originalContour = filler.Contour.Parts.ToList(); var contourDatas = StyleHelper.SetOffset(originalContour, LineOffset, MedianOffset).Select(i => new CounterData() { _side = i }).ToArray(); for (int i = 0; i < contourDatas.Length; i += 1) { contourDatas[i]._side = StyleHelper.SetCornerRadius(contourDatas[i]._side, CornerRadius, MedianCornerRadius); if (CurbSize > 0 || MedianCurbSize > 0) { contourDatas[i]._hole = StyleHelper.SetOffset(contourDatas[i]._side, CurbSize, MedianCurbSize).FirstOrDefault(); } } var data = new LodDictionaryArray <IStyleData>(); foreach (var lod in EnumExtension.GetEnumValues <MarkupLOD>()) { data[lod] = Calculate(filler, contourDatas, lod).ToArray(); } return(data); } }
private IEnumerable<IFillerVertex> GetOtherEnterPoint(MarkupFiller filler) { var otherEnterPoint = Point.IsFirst ? Enter.Next.LastPoint : Enter.Prev.FirstPoint; var vertex = new EnterFillerVertex(otherEnterPoint); if (vertex.Equals(filler.First) || !filler.Vertices.Any(v => vertex.Equals(v))) yield return vertex; }
private IEnumerable<IFillerVertex> GetNextEmptyCandidates(MarkupFiller filler) { foreach (var vertex in filler.GetLinePoints(this, First)) yield return vertex; foreach (var vertex in filler.GetLinePoints(this, Second)) yield return vertex; }
public void Update(MarkupFiller filler, bool recalculate = false) { filler.Update(); if (recalculate) { RecalculateDashes(); } }
private IEnumerable <IFillerVertex> GetPointLinesPoints(MarkupFiller filler) { foreach (var line in Point.Lines) { foreach (var vertex in filler.GetLinePoints(this, line)) { yield return(vertex); } } }
private IEnumerable<IFillerVertex> GetEnterOtherPoints(MarkupFiller filler) { filler.GetMinMaxNum(this, out byte num, out byte minNum, out byte maxNum); foreach (var point in Enter.Points.Where(p => p.Num != num && minNum < p.Num && p.Num < maxNum && (p.IsEdge || p.Lines.Any()))) yield return new EnterFillerVertex(point); if (filler.First is EnterFillerVertex first && first.Enter == Enter && (minNum == first.Point.Num || first.Point.Num == maxNum)) yield return first; }
protected override List <List <FillerContour.Part> > GetContours(MarkupFiller filler) { var contours = base.GetContours(filler); for (int i = 0; i < contours.Count; i += 1) { contours[i] = StyleHelper.SetCornerRadius(contours[i], CornerRadius, MedianCornerRadius); } return(contours); }
public virtual LodDictionaryArray <IStyleData> Calculate(MarkupFiller filler) { var contours = GetContours(filler); var data = new LodDictionaryArray <IStyleData>(); foreach (var lod in EnumExtension.GetEnumValues <MarkupLOD>()) { data[lod] = Calculate(filler, contours, lod).ToArray(); } return(data); }
public IEnumerable<IFillerVertex> GetNextCandidates(MarkupFiller filler, IFillerVertex prev) { switch (prev) { case EnterFillerVertex prevE: return filler.GetLinePoints(this, First.ContainsPoint(prevE.Point) ? Second : First); case IntersectFillerVertex prevI: return filler.GetLinePoints(this, prevI.LinePair.ContainLine(First) ? Second : First); default: return GetNextEmptyCandidates(filler); } }
public override void GetUIComponents(MarkupFiller filler, List <EditorItem> components, UIComponent parent, bool isTemplate = false) { base.GetUIComponents(filler, components, parent, isTemplate); components.Add(AddElevationProperty(this, parent)); if (!isTemplate) { components.Add(AddCornerRadiusProperty(this, parent)); if (filler.IsMedian) { components.Add(AddMedianCornerRadiusProperty(this, parent)); } } #if DEBUG //var material = GetVectorProperty(parent, "Material"); //var textureA = GetVectorProperty(parent, "TextureA"); //var textureB = GetVectorProperty(parent, "TextureB"); //material.Value = (RenderHelper.MaterialLib[MaterialType].GetTexture("_APRMap") as Texture2D).GetPixel(0, 0); //textureA.Value = RenderHelper.SurfaceALib[MaterialType].GetPixel(0, 0); //textureB.Value = RenderHelper.SurfaceBLib[MaterialType].GetPixel(0, 0); //material.OnValueChanged += MaterialValueChanged; //textureA.OnValueChanged += TextureAValueChanged; //textureB.OnValueChanged += TextureBValueChanged; //components.Add(material); //components.Add(textureA); //components.Add(textureB); //void MaterialValueChanged(Color32 value) //{ // RenderHelper.MaterialLib[MaterialType] = RenderHelper.CreateRoadMaterial(TextureHelper.CreateTexture(128, 128, UnityEngine.Color.white), TextureHelper.CreateTexture(128, 128, value)); //} //void TextureAValueChanged(Color32 value) //{ // RenderHelper.SurfaceALib[MaterialType] = TextureHelper.CreateTexture(512, 512, value); //} //void TextureBValueChanged(Color32 value) //{ // RenderHelper.SurfaceBLib[MaterialType] = TextureHelper.CreateTexture(512, 512, value); //} //static ColorPropertyPanel GetVectorProperty(UIComponent parent, string name) //{ // var vector = ComponentPool.Get<ColorPropertyPanel>(parent); // vector.Init(); // vector.Text = name; // return vector; //} #endif }
public override void GetUIComponents(MarkupFiller filler, List <EditorItem> components, UIComponent parent, bool isTemplate = false) { base.GetUIComponents(filler, components, parent, isTemplate); if (!isTemplate) { components.Add(AddCurbSizeProperty(this, parent)); if (filler.IsMedian) { components.Add(AddMedianCurbSizeProperty(this, parent)); } } }
public IEnumerable<IFillerVertex> GetNextCandidates(MarkupFiller filler, IFillerVertex prev) { if(!(prev is EnterFillerVertex prevE && Enter == prevE.Point.Enter)) foreach (var vertex in GetEnterOtherPoints(filler)) yield return vertex; if (Point.IsEdge) { foreach (var vertex in GetOtherEnterPoint(filler)) yield return vertex; } foreach (var vertex in GetPointLinesPoints(filler)) yield return vertex; }
public void FromXml(Version version, XElement config, Dictionary <ObjectId, ObjectId> map = null) { if (version < new Version("1.2")) { map = VersionMigration.Befor1_2(this, map); } foreach (var pointConfig in config.Elements(MarkupPoint.XmlName)) { MarkupPoint.FromXml(pointConfig, this, map); } var toInit = new Dictionary <MarkupLine, XElement>(); foreach (var lineConfig in config.Elements(MarkupLine.XmlName)) { if (MarkupLine.FromXml(lineConfig, this, map, out MarkupLine line)) { LinesDictionary[line.Id] = line; toInit[line] = lineConfig; } } foreach (var pair in toInit) { pair.Key.FromXml(pair.Value, map); } foreach (var fillerConfig in config.Elements(MarkupFiller.XmlName)) { if (MarkupFiller.FromXml(fillerConfig, this, map, out MarkupFiller filler)) { FillersList.Add(filler); } } foreach (var crosswalkConfig in config.Elements(MarkupCrosswalk.XmlName)) { if (MarkupCrosswalk.FromXml(crosswalkConfig, this, map, out MarkupCrosswalk crosswalk)) { CrosswalksDictionary[crosswalk.Line] = crosswalk; } } Update(); }
protected virtual IEnumerable <MarkupStylePart> CalculateProcess(MarkupFiller filler, MarkupLOD lod) { var contour = filler.IsMedian ? SetMedianOffset(filler) : filler.Contour.Trajectories.ToArray(); var rails = GetRails(filler, contour).ToArray(); foreach (var rail in rails) { var partItems = GetItems(rail, lod).ToArray(); foreach (var partItem in partItems) { foreach (var dash in GetDashes(partItem, contour)) { yield return(dash); } } } }
protected virtual IEnumerable <MarkupStylePart> CalculateProcess(MarkupFiller filler, List <List <FillerContour.Part> > contours, MarkupLOD lod) { var originalContour = filler.Contour.TrajectoriesProcessed.ToArray(); var rails = GetRails(filler, originalContour).ToArray(); foreach (var rail in rails) { var partItems = GetItems(rail, lod).ToArray(); foreach (var partItem in partItems) { foreach (var dash in GetDashes(partItem, contours)) { yield return(dash); } } } }
private List <ITrajectory> GetTrajectories(MarkupFiller filler) { var contour = filler.IsMedian ? SetMedianOffset(filler).ToList() : filler.Contour.TrajectoriesProcessed.ToList(); if (contour.Count > 3) { for (var i = 0; i < contour.Count; i += 1) { for (var j = 2; j < contour.Count - 1; j += 1) { var x = i; var y = (i + j) % contour.Count; var intersect = Intersection.CalculateSingle(contour[x], contour[y]); if (intersect.IsIntersect && (intersect.FirstT > 0.5f || intersect.SecondT < 0.5f)) { contour[x] = contour[x].Cut(0f, intersect.FirstT); contour[y] = contour[y].Cut(intersect.SecondT, 1f); if (y > x) { var count = y - (x + 1); contour.RemoveRange(x + 1, count); j -= count; } else { contour.RemoveRange(x + 1, contour.Count - (x + 1)); contour.RemoveRange(0, y); i -= y; } } } } } if (GetDirection(contour) == PolygonDirection.CounterClockWise) { contour = contour.Select(t => t.Invert()).Reverse().ToList(); } return(contour); }
public ITrajectory[] SetMedianOffset(MarkupFiller filler) { var lineParts = filler.Contour.Parts.ToArray(); var trajectories = filler.Contour.TrajectoriesRaw.ToArray(); for (var i = 0; i < lineParts.Length; i += 1) { if (trajectories[i] == null) { continue; } var line = lineParts[i].Line; if (line is MarkupEnterLine) { continue; } var prevI = i == 0 ? lineParts.Length - 1 : i - 1; if (lineParts[prevI].Line is MarkupEnterLine && trajectories[prevI] != null) { trajectories[i] = Shift(trajectories[i]); trajectories[prevI] = new StraightTrajectory(trajectories[prevI].StartPosition, trajectories[i].StartPosition); } var nextI = i + 1 == lineParts.Length ? 0 : i + 1; if (lineParts[nextI].Line is MarkupEnterLine && trajectories[nextI] != null) { trajectories[i] = Shift(trajectories[i].Invert()).Invert(); trajectories[nextI] = new StraightTrajectory(trajectories[i].EndPosition, trajectories[nextI].EndPosition); } ITrajectory Shift(ITrajectory trajectory) { var newT = trajectory.Travel(0, MedianOffset); return(trajectory.Cut(newT, 1)); } } return(trajectories.Where(t => t != null).Select(t => t).ToArray()); }
public override IStyleData Calculate(MarkupFiller filler, MarkupLOD lod) { var trajectories = GetTrajectories(filler); var parts = GetParts(trajectories, lod); var points = parts.SelectMany(p => p).Select(t => t.StartPosition).ToArray(); if (points.Length < 3) { return(null); } var triangles = Triangulator.Triangulate(points, PolygonDirection.ClockWise); if (triangles == null) { return(null); } return(new MarkupStylePolygonMesh(filler.Markup.Height, Elevation, parts.Select(g => g.Count).ToArray(), points, triangles, MaterialType)); }
public override IEnumerable <IStyleData> Calculate(MarkupFiller filler, List <List <FillerContour.Part> > contours, MarkupLOD lod) { foreach (var contour in contours) { var points = GetContourPoints(contour, lod, out var groups); if (Triangulate(points, out var triangles)) { //SplitTriangles(contour, points, triangles, 2f, out var topPoints, out var topTriangles); yield return(new MarkupStyleFillerMesh(Elevation, MarkupStyleFillerMesh.RawData.SetSide(groups, points, MaterialType.Pavement), MarkupStyleFillerMesh.RawData.SetTop(points, triangles, MaterialType))); #if DEBUG //if ((Settings.ShowFillerTriangulation & 2) != 0) // yield return GetTriangulationLines(topPoints, topTriangles, UnityEngine.Color.red, MaterialType.RectangleFillers); if ((Settings.ShowFillerTriangulation & 1) != 0) { yield return(GetTriangulationLines(points, triangles, UnityEngine.Color.green, MaterialType.RectangleLines)); } #endif } } }
public override IStyleData Calculate(MarkupFiller filler, MarkupLOD lod) { var contour = filler.IsMedian ? SetMedianOffset(filler) : filler.Contour.Trajectories.ToArray(); if (NeedReverse(contour)) { contour = contour.Select(t => t.Invert()).Reverse().ToArray(); } var parts = contour.Select(t => StyleHelper.CalculateSolid(t, lod, (tr) => tr, MinAngle, MinLength, MaxLength)).ToArray(); for (var i = 0; i < parts.Length; i += 1) { var partI = parts[i]; var partJ = parts[(i + 1) % parts.Length]; if (!FindIntersects(partI, partJ, false)) { FindIntersects(partJ, partI, true); } } var points = parts.SelectMany(p => p).Select(t => t.StartPosition).ToArray(); if (points.Length < 3) { return(null); } var polygon = new Polygon(points.Select(p => new PolygonPoint(p.x, p.z))); P2T.Triangulate(polygon); var triangles = polygon.Triangles.SelectMany(t => t.Points.Select(p => polygon.IndexOf(p))).ToArray(); return(new MarkupStylePolygonMesh(filler.Markup.Height, Elevation, parts.Select(g => g.Count).ToArray(), points, triangles, MaterialType)); }
public override void GetUIComponents(MarkupFiller filler, List <EditorItem> components, UIComponent parent, bool isTemplate = false) { base.GetUIComponents(filler, components, parent, isTemplate); components.Add(AddElevationProperty(this, parent)); }
public virtual void Render(MarkupFiller filler, OverlayData data) { }
public abstract IEnumerable <IStyleData> Calculate(MarkupFiller filler, List <List <FillerContour.Part> > contours, MarkupLOD lod);
public void RemoveFiller(MarkupFiller filler) { FillersList.Remove(filler); NeedRecalculateBatches = true; }
public void AddFiller(MarkupFiller filler) { FillersList.Add(filler); filler.RecalculateDashes(); NeedRecalculateBatches = true; }
protected abstract IEnumerable <RailLine> GetRails(MarkupFiller filler, ITrajectory[] contour);
public void Update(MarkupFiller filler) { filler.RecalculateDashes(); NeedRecalculateBatches = true; }