private void BuildWater(Path clipRect) { _clipper.AddPaths(_tile.Canvas.Water.Select(a => a.Points), PolyType.ptSubject, _scale, true); var solution = new Paths(); _clipper.Execute(ClipType.ctUnion, solution); _clipper.Clear(); _water = new MeshCanvas.Region { Shape = ClipByRectangle(clipRect, solution) }; }
private void BuildRoads(Path clipRect) { var carRoadPaths = GetOffsetSolution( BuildRoadMap(_tile.Canvas.Roads.Where(r => r.Type == RoadElement.RoadType.Car))); var walkRoadsPaths = GetOffsetSolution( BuildRoadMap(_tile.Canvas.Roads.Where(r => r.Type == RoadElement.RoadType.Pedestrian))); _clipper.AddPaths(carRoadPaths, PolyType.ptClip, true); _clipper.AddPaths(walkRoadsPaths, PolyType.ptSubject, true); var extrudedWalkRoads = new Paths(); _clipper.Execute(ClipType.ctDifference, extrudedWalkRoads); _clipper.Clear(); _carRoads = CreateRoadRegionData(clipRect, carRoadPaths); _walkRoads = CreateRoadRegionData(clipRect, extrudedWalkRoads); }
private void BuildBackground(Path clipRect) { _clipper.AddPath(clipRect, PolyType.ptSubject, true); _clipper.AddPaths(_carRoads.Shape, PolyType.ptClip, true); _clipper.AddPaths(_walkRoads.Shape, PolyType.ptClip, true); _clipper.AddPaths(_water.Shape, PolyType.ptClip, true); _clipper.AddPaths(_surfaces.SelectMany(r => r.Shape), PolyType.ptClip, true); var solution = new Paths(); _clipper.Execute(ClipType.ctDifference, solution, PolyFillType.pftPositive, PolyFillType.pftPositive); _clipper.Clear(); _background = new MeshCanvas.Region() { Shape = solution }; }
private MeshRegion CreateMeshRegions(Path clipRect, MeshCanvas.Region region, RenderMode renderMode, ref Rectangle2d rect, bool useContours = false) { using (var polygon = new Polygon(256, _objectPool)) { var simplifiedPath = ClipByRectangle(clipRect, region.Shape); var contours = new List <List <Point> >(useContours ? simplifiedPath.Count : 0); foreach (var path in simplifiedPath) { var area = Clipper.Area(path); // skip small polygons to prevent triangulation issues if (Math.Abs(area / DoubleScale) < 0.001) { continue; } var vertices = GetVertices(path, renderMode, ref rect); // sign of area defines polygon orientation polygon.AddContour(vertices, area < 0); if (useContours) { contours.Add(vertices); } } contours.ForEach(c => c.Reverse()); var mesh = polygon.Points.Any() ? GetMesh(polygon, renderMode) : null; return(new MeshRegion { GradientKey = region.GradientKey, ElevationNoiseFreq = region.ElevationNoiseFreq, ColorNoiseFreq = region.ColorNoiseFreq, ModifyMeshAction = region.ModifyMeshAction, Mesh = mesh, Contours = contours }); } }