private void saveArtworkgerberToolStripMenuItem_Click(object sender, EventArgs e) { if (gerbersaveFileDialog1.ShowDialog() == DialogResult.OK) { try { GerberArtWriter GAW = new GerberArtWriter(); double S = 72.0 / 200.0; foreach (var a in ArtRender.SubDivPoly) { PolyLine PL = new PolyLine(PolyLine.PolyIDs.ArtWork); PL.Add(a.Vertices[0].x * S, (Mask.Height - a.Vertices[0].y) * S); PL.Add(a.Vertices[1].x * S, (Mask.Height - a.Vertices[1].y) * S); PL.Add(a.Vertices[2].x * S, (Mask.Height - a.Vertices[2].y) * S); PL.Add(a.Vertices[0].x * S, (Mask.Height - a.Vertices[0].y) * S); GAW.AddPolyLine(PL, 0.1); } GAW.Write(gerbersaveFileDialog1.FileName); } catch (Exception E) { } } }
internal PolyLine GetBoundingPolyLine() { PolyLine Boundary = new PolyLine(State.LastShapeID++); Boundary.Add(BoundingBox.TopLeft.X, BoundingBox.TopLeft.Y); Boundary.Add(BoundingBox.BottomRight.X, BoundingBox.TopLeft.Y); Boundary.Add(BoundingBox.BottomRight.X, BoundingBox.BottomRight.Y); Boundary.Add(BoundingBox.TopLeft.X, BoundingBox.BottomRight.Y); Boundary.Close(); return(Boundary); }
void loadXML() { // DestroyObject(go); //if (done || !GetComponent<MapChunkManager>().isReady) // return; PolyLine pl = new PolyLine("TESTINGTRACER"); pl.heigth = 1; pl.width = 3; pl.material = Resources.Load("Materials/blinker") as Material; float offsetPositionX = GetComponent<MapChunkManager>().offsetX; float offsetPositionZ = GetComponent<MapChunkManager>().offsetZ; pl.SetOffset(offsetPositionX, offsetPositionZ); XmlDocument XMLFile = new XmlDocument(); XMLFile.LoadXml(gpsLog.text); XmlNodeList coords = XMLFile.GetElementsByTagName("trkpt"); List<Node> nodes = new List<Node>(); GeoUTMConverter convertor; foreach (XmlNode coord in coords) { // coord.Attributes["lat"].Value // coord.Attributes["lon"].Value Node n = new Node(); n.lat = double.Parse(coord.Attributes["lat"].Value); n.lon = double.Parse(coord.Attributes["lon"].Value); convertor = new GeoUTMConverter(); convertor.ToUTM(n.lat,n.lon); n.northing = convertor.Y; n.easthing = convertor.X; nodes.Add(n); } for (int a = 0; a < nodes.Count -1; a++) { Node n = nodes[a]; Vector3 position = new Vector3((float)(n.easthing - offsetPositionX), 99999, (float)(n.northing - offsetPositionZ)); float baseHeight = 0; RaycastHit hit; if (Physics.Raycast(position, -Vector3.up, out hit, Mathf.Infinity)) { baseHeight = hit.point.y; } n.height = baseHeight + 1f; pl.Add(n); // Debug.Log("Node is " + (float)(n.easthing - offsetPositionX) + "|" + (float)(n.northing - offsetPositionZ) + "|" + n.height); // Color random = new Color(((float)n.easthing % 255) / 255f, ((float)n.northing % 255) / 255f, ((float)n.easthing % 255) / 255f); // Debug.DrawLine(new Vector3((float)nodes[a].easthing - offsetPositionX, 200, (float)nodes[a].northing - offsetPositionZ), new Vector3((float)nodes[a + 1].easthing - offsetPositionX, 200, (float)nodes[a + 1].northing - offsetPositionZ), random,300); } // foreach (Node node in nodes) { // pl.Add (node); // } GameObject go = new GameObject(); go.transform.position = transform.position; pl.Close(go); done = true; }
public void DefaultShape() { Shapes.Clear(); PolyLine S1 = new PolyLine(State.LastShapeID++); S1.Add(0, 10); S1.Add(20, 10); S1.Add(20, 20); S1.Add(0, 20); S1.Add(0, 10); Shapes.Add(S1); PolyLine S2 = new PolyLine(State.LastShapeID++); for (int i = 0; i < 101; i++) { double p = (double)i * 0.06283f; S2.Add(10.0f + (double)Math.Sin(p) * 5.0f, 15.0f - (double)Math.Cos(p) * 5.0f); } Shapes.Add(S2); BuildBoundary(); }
/// <summary> /// Convert a Robot polyline geometry into a Nucleus polyline /// </summary> /// <param name="polyline"></param> /// <returns></returns> public static PolyLine Convert(RobotGeoPolyline polyline) { PolyLine result = new PolyLine(); RobotGeoSegmentCollection segments = polyline.Segments as RobotGeoSegmentCollection; for (int i = 1; i <= segments.Count; i++) { RobotGeoSegment segment = segments.Get(i); Vector pt = Convert(segment.P1); if (i == segments.Count && pt.Equals(result.StartPoint, Tolerance.Distance)) { result.Close(true); } else { result.Add(pt); } } return(result); }
public void WriteAntennaBoard(double width, double height, double mountholediameter, double cornerrounding, double mountholeclearance, double edgeclearance = 1.26, bool WriteCombinedImage = true, bool WriteImages = false) { int polyid = 0; FontSet FS = FontSet.Load("Font.xml"); List <String> FilesGenerated = new List <string>(); double LabelHeight = 1.2; //double PadWidth = 1.8; double DrillWidth = 1.0; string basename = String.Format("Generated_This_is_not_RocketScience_Antenna_{0}x{1}cm", width / 10.0f, height / 10.0f); try { Directory.CreateDirectory(basename); } catch (Exception) { } basename = Path.Combine(basename, String.Format("proto_{0}x{1}cm", width / 10.0f, height / 10.0f)); string OutlineFile = basename + ".gko"; string SilkFileTop = basename + ".gto"; string SilkFileBottom = basename + ".gbo"; string SolderMaskBottom = basename + ".gbs"; string SolderMaskTop = basename + ".gts"; string CopperBottom = basename + ".gbl"; string CopperTop = basename + ".gtl"; string DrillFile = basename + ".txt"; ExcellonFile EF = new ExcellonFile(); ExcellonTool MountHoleDrill = new ExcellonTool(); MountHoleDrill.Radius = mountholediameter / 2.0; PointD C1 = new PointD(mountholeclearance, mountholeclearance); PointD C2 = new PointD(width - mountholeclearance, mountholeclearance); PointD C3 = new PointD(width - mountholeclearance, height - mountholeclearance); PointD C4 = new PointD(mountholeclearance, height - mountholeclearance); MountHoleDrill.Drills.Add(C1); MountHoleDrill.Drills.Add(C2); MountHoleDrill.Drills.Add(C3); MountHoleDrill.Drills.Add(C4); EF.Tools[10] = MountHoleDrill; ViaDrill.Radius = 0.6 / 2.0; EF.Tools[11] = ViaDrill; ExcellonTool ProtoHoleDrill = new ExcellonTool(); ProtoHoleDrill.Radius = DrillWidth / 2.0; PointD pC1 = new PointD(mountholeclearance, height / 2 - 2.54); PointD pC2 = new PointD(mountholeclearance, height / 2); PointD pC3 = new PointD(mountholeclearance, height / 2 + 2.54); ProtoHoleDrill.Drills.Add(pC1); ProtoHoleDrill.Drills.Add(pC2); ProtoHoleDrill.Drills.Add(pC3); MaskBottom.AddFlash(pC1, 1); MaskBottom.AddFlash(pC2, 1); MaskBottom.AddFlash(pC3, 1); MaskTop.AddFlash(pC1, 1); MaskTop.AddFlash(pC2, 1); MaskTop.AddFlash(pC3, 1); PolyLine PL = new PolyLine(polyid++); PL.Add(cornerrounding, 0); PL.Add(width - cornerrounding, 0); PL.ArcTo(new PointD(width, cornerrounding), new PointD(0, cornerrounding), InterpolationMode.CounterClockwise); PL.Add(width, height - cornerrounding); PL.ArcTo(new PointD(width - cornerrounding, height), new PointD(-cornerrounding, 0), InterpolationMode.CounterClockwise); PL.Add(cornerrounding, height); PL.ArcTo(new PointD(0, height - cornerrounding), new PointD(0, -cornerrounding), InterpolationMode.CounterClockwise); PL.Add(0, cornerrounding); PL.ArcTo(new PointD(cornerrounding, 0), new PointD(cornerrounding, 0), InterpolationMode.CounterClockwise); PL.Close(); GAW.AddPolyLine(PL, 0); GAW.Write(OutlineFile); double AX = C1.X + mountholeclearance; double AY = C1.Y + mountholeclearance; double gap = 5; double W = width - AX * 2; double H = height - AY * 2 - gap; int rounds = 6; antennatracewidth = 0.3 / 2; double spacing = 0.8; for (int i = 0; i < rounds; i++) { double W2 = W - i * spacing * 2; double H2 = H - i * spacing * 2; double W3 = W - (i + 1) * spacing * 2; double H3 = H - (i + 1) * spacing * 2; double AX2 = AX + i * spacing; double AY2 = AY + i * spacing; double AX3 = AX + (i + 1) * spacing; double AY3 = AY + (i + 1) * spacing; PolyLine PL2 = new PolyLine(polyid++); PL2.Add(AX2, AY2 + H2 / 2); PL2.Add(AX2, AY2); PL2.Add(AX2 + W2, AY2); PL2.Add(AX2 + W2, AY2 + H2 / 2); AddAntennaTop(PL2); PolyLine PL3 = new PolyLine(polyid++); PL3.Add(AX2, AY2 + gap + H2 - (H2 / 2)); PL3.Add(AX2, AY2 + gap + H2); PL3.Add(AX2 + W2, AY2 + gap + H2); PL3.Add(AX2 + W2, AY2 + gap + H2 - (H2 / 2)); AddAntennaTop(PL3); double gs = 2; if (i % 2 == 1) { if (i < rounds - 1) { PolyLine PL4 = new PolyLine(polyid++); PL4.Add(AX2, AY2 + gap + H2 - (H2 / 2)); PL4.Add(AX2, AY2 + gap - gs + H2 - (H2 / 2)); PL4.Add(AX3, AY3 + gs + (H3 / 2)); PL4.Add(AX3, AY3 + (H3 / 2)); AddAntennaTop(PL4); PolyLine PL5 = new PolyLine(polyid++); PL5.Add(AX3, AY3 + gap + H3 - (H3 / 2)); PL5.Add(AX2, AY2 + (H2 / 2)); AddAntennaBottom(PL5); AddAntennaVia(AX3, AY3 + gap + H3 - (H3 / 2)); AddAntennaVia(AX2, AY2 + (H2 / 2)); } else { PolyLine PL4 = new PolyLine(polyid++); PL4.Add(AX2, AY2 + gap + H2 - (H2 / 2)); PL4.Add(AX2, AY2 + (H2 / 2)); AddAntennaTop(PL4); AddAntennaVia(AX2, AY2 + H2 / 2 + gap / 2); PolyLine PL5 = new PolyLine(polyid++); PL5.Add(AX2, AY2 + H2 / 2 + gap / 2); PL5.Add(AX2, AY2 + H2 / 2 - gs); PL5.Add(AX - spacing, AY2 + H2 / 2 - gs); PL5.Add(AX - spacing, AY2 + H2 / 2 + gap / 2); AddAntennaVia(AX - spacing, AY2 + H2 / 2 + gap / 2); AddAntennaBottom(PL5); } } else { PolyLine PL4 = new PolyLine(polyid++); PL4.Add(AX2 + W2, AY2 + gap + H2 - (H2 / 2)); PL4.Add(AX2 + W2, AY2 + gap - gs + H2 - (H2 / 2)); PL4.Add(AX3 + W3, AY3 + gs + (H3 / 2)); PL4.Add(AX3 + W3, AY3 + (H3 / 2)); AddAntennaTop(PL4); PolyLine PL5 = new PolyLine(polyid++); PL5.Add(AX3 + W3, AY3 + gap + H3 - (H3 / 2)); PL5.Add(AX2 + W2, AY2 + (H2 / 2)); AddAntennaBottom(PL5); PolyLine PL6 = new PolyLine(polyid++); PL6.Add(AX, AY + H / 2); PL6.Add(pC1.X, pC1.Y); AddAntennaTop(PL6); PolyLine PL7 = new PolyLine(polyid++); PL7.Add(AX, AY + H / 2 + gap); PL7.Add(pC3.X, pC3.Y); AddAntennaTop(PL7); PolyLine PL8 = new PolyLine(polyid++); PL8.Add(AX - spacing, AY2 + H2 / 2 + gap / 2); PL8.Add(pC2.X, pC2.Y); AddAntennaTop(PL8); AddAntennaVia(AX3 + W3, AY3 + gap + H3 - (H3 / 2)); AddAntennaVia(AX2 + W2, AY2 + (H2 / 2)); } } string R = "NFC antenna: " + AntennaLen.ToString("N2") + " mm"; // MaskTop.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter); // MaskBottom.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter, true); SilkTop.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter); SilkBottom.DrawString(new PointD(width / 2, 5), FS, R, LabelHeight, 0.05, StringAlign.CenterCenter, true); GAWTop.Write(CopperTop); GAWBottom.Write(CopperBottom); SilkBottom.Write(SilkFileBottom); SilkTop.Write(SilkFileTop); MaskTop.Write(SolderMaskTop); MaskBottom.Write(SolderMaskBottom); EF.Tools[12] = ProtoHoleDrill; EF.Write(DrillFile, 0, 0, 0, 0); FilesGenerated.Add(CopperBottom); FilesGenerated.Add(CopperTop); FilesGenerated.Add(OutlineFile); FilesGenerated.Add(DrillFile); FilesGenerated.Add(SilkFileBottom); FilesGenerated.Add(SilkFileTop); FilesGenerated.Add(SolderMaskBottom); FilesGenerated.Add(SolderMaskTop); if (WriteCombinedImage) { GerberImageCreator GIC = new GerberImageCreator(); GIC.AddBoardsToSet(FilesGenerated); GIC.WriteImageFiles(basename + "_render", 200, false); } if (WriteImages) { Gerber.SaveGerberFileToImage(OutlineFile, OutlineFile + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(CopperBottom, CopperBottom + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(CopperTop, CopperTop + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(DrillFile, DrillFile + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(SilkFileTop, SilkFileTop + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(SilkFileBottom, SilkFileBottom + "_render.png", 1000, Color.Black, Color.White); } }
private static void ConvertFile(string a, bool back) { string basename = a.Substring(0, a.Length - 4); string png = basename + "Silk.png"; string goldpng = basename + "Gold.png"; if (back) { png = basename + "BottomSilk.png"; goldpng = basename + "BottomGold.png"; } Bitmap B = (Bitmap)Image.FromFile(png); Bitmap B2 = null; if (System.IO.File.Exists(goldpng)) { B2 = (Bitmap)Image.FromFile(goldpng); } try { System.IO.Directory.CreateDirectory(basename); } catch (Exception) { } string newa = basename + "\\" + System.IO.Path.GetFileName(a);; string gko = basename + ".gko"; string pnl = basename + ".pnl"; if (System.IO.File.Exists(gko) == false && System.IO.File.Exists(pnl) == true) { gko = pnl; } string newgko = basename + "\\" + System.IO.Path.GetFileNameWithoutExtension(a) + ".gko";; if (System.IO.File.Exists(gko)) { System.IO.File.Copy(gko, newgko, true); } System.IO.File.Copy(a, newa, true); a = newa; string p = basename + "/topsilk.gto"; if (back) { p = basename + "/bottomsilk.gbo"; } if (back) { B.RotateFlip(RotateFlipType.RotateNoneFlipX); } B.RotateFlip(RotateFlipType.RotateNoneFlipY); if (B2 != null) { B2.RotateFlip(RotateFlipType.RotateNoneFlipY); } if (B != null) { double Res = 200.0 / 25.4; ParsedGerber PLS = null; string f = basename + ".gko"; if (System.IO.File.Exists(f)) { int polyid = 0; PLS = PolyLineSet.LoadGerberFile(f); string bottomcopper = basename + "/bottomcopper.gbl"; string topcopper = basename + "/topcopper.gtl"; string bottomsoldermask = basename + "/bottomsoldermask.gbs"; string topsoldermask = basename + "/topsoldermask.gts"; string bottomsilk = basename + "/bottomsilk.gbo"; if (back) { bottomsilk = basename + "/topsilk.gto"; } GerberArtWriter GAW3 = new GerberLibrary.GerberArtWriter(); GAW3.Write(topsoldermask); GerberArtWriter GAW = new GerberLibrary.GerberArtWriter(); PolyLine PL = new PolyLine(polyid++); PL.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y); PL.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y); PL.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y + 8); PL.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y + 8); GAW.AddPolygon(PL); PolyLine PL3 = new PolyLine(polyid++); PL3.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y - 8); PL3.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y - 8); PL3.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y); PL3.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y); GAW.AddPolygon(PL3); GAW.Write(bottomsoldermask); GerberArtWriter GAW2 = new GerberLibrary.GerberArtWriter(); PolyLine PL2 = new PolyLine(polyid++); PL2.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.TopLeft.Y); PL2.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.TopLeft.Y); PL2.Add(PLS.BoundingBox.BottomRight.X, PLS.BoundingBox.BottomRight.Y); PL2.Add(PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y); GAW2.AddPolygon(PL2); GAW2.Write(bottomcopper); if (B2 != null) { GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(topcopper, PLS, Res, B2, -128); GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(topsoldermask, PLS, Res, B2, -128); } else { GAW2.Write(topcopper); } } GerberLibrary.ArtWork.Functions.WriteBitmapToGerber(p, PLS, Res, B, -128); } }
public static List <String> WriteProtoBoardFlowerStyle(double width, double height, double mountholediameter, double cornerrounding, double mountholeclearance, double edgeclearance = 1.26, bool WriteCombinedImage = true, bool WriteImages = false) { FontSet FS = FontSet.Load("Font.xml"); int polyid = 0; List <String> FilesGenerated = new List <string>(); double LabelHeight = 1.2; double PadWidth = 1.8; double DrillWidth = 1.0; string basename = String.Format("Generated_This_is_not_RocketScience_Flower_prototoboard_{0}x{1}cm", width / 10.0f, height / 10.0f); try { Directory.CreateDirectory(basename); } catch (Exception) { } basename = Path.Combine(basename, String.Format("proto_{0}x{1}cm", width / 10.0f, height / 10.0f)); string OutlineFile = basename + ".gko"; string SilkFileTop = basename + ".gto"; string SilkFileBottom = basename + ".gbo"; string SolderMaskBottom = basename + ".gbs"; string SolderMaskTop = basename + ".gts"; string CopperBottom = basename + ".gbl"; string CopperTop = basename + ".gtl"; string DrillFile = basename + ".txt"; int XE = (int)Math.Floor((width - Math.Max(edgeclearance, LabelHeight) * 2) / 2.54); int YE = (int)Math.Floor((height - Math.Max(edgeclearance, LabelHeight) * 2) / 2.54); PrepareGridSpace(XE, YE, true, true, 3, 2); string[][] Grid = new string[XE + 1][]; for (int x = 0; x <= XE; x++) { Grid[x] = new string[YE + 1]; for (int y = 0; y <= YE; y++) { Grid[x][y] = GridSpaceType(x, y); if (y == YE) { Grid[x][y] = "None"; } if (x == XE) { Grid[x][y] = "None"; } } } double XO = (width / 2) - (XE / 2.0) * 2.54; double YO = (height / 2) - (YE / 2.0) * 2.54; Console.WriteLine("{0} rows and {1} columns", YE, XE); ExcellonFile EF = new ExcellonFile(); PointD C1 = new PointD(0, 0); PointD C2 = new PointD(width, 0); PointD C3 = new PointD(width, height); PointD C4 = new PointD(0, height); if (mountholediameter > 0) { ExcellonTool MountHoleDrill = new ExcellonTool(); MountHoleDrill.Radius = mountholediameter / 2.0; C1 = new PointD(mountholeclearance, mountholeclearance); C2 = new PointD(width - mountholeclearance, mountholeclearance); C3 = new PointD(width - mountholeclearance, height - mountholeclearance); C4 = new PointD(mountholeclearance, height - mountholeclearance); MountHoleDrill.Drills.Add(C1); MountHoleDrill.Drills.Add(C2); MountHoleDrill.Drills.Add(C3); MountHoleDrill.Drills.Add(C4); EF.Tools[10] = MountHoleDrill; } ExcellonTool ProtoHoleDrill = new ExcellonTool(); ProtoHoleDrill.Radius = DrillWidth / 2.0; PolyLine PL = new PolyLine(polyid++); PL.Add(cornerrounding, 0); PL.Add(width - cornerrounding, 0); PL.ArcTo(new PointD(width, cornerrounding), new PointD(0, cornerrounding), InterpolationMode.CounterClockwise); PL.Add(width, height - cornerrounding); PL.ArcTo(new PointD(width - cornerrounding, height), new PointD(-cornerrounding, 0), InterpolationMode.CounterClockwise); PL.Add(cornerrounding, height); PL.ArcTo(new PointD(0, height - cornerrounding), new PointD(0, -cornerrounding), InterpolationMode.CounterClockwise); PL.Add(0, cornerrounding); PL.ArcTo(new PointD(cornerrounding, 0), new PointD(cornerrounding, 0), InterpolationMode.CounterClockwise); PL.Close(); GerberArtWriter GAW = new GerberArtWriter(); GAW.AddPolyLine(PL, 0); GAW.Write(OutlineFile); GerberArtWriter GAWTop = new GerberArtWriter(); GerberArtWriter GAWBottom = new GerberArtWriter(); GerberArtWriter MaskTop = new GerberArtWriter(); GerberArtWriter MaskBottom = new GerberArtWriter(); GerberArtWriter SilkTop = new GerberArtWriter(); GerberArtWriter SilkBottom = new GerberArtWriter(); for (int x = 0; x < XE; x++) { double xc = XO + x * 2.54 + 2.54 / 2; for (int y = 0; y < YE; y++) { double yc = YO + y * 2.54 + 2.54 / 2; PointD P = new PointD(xc, yc); if ((P - C1).Length() < edgeclearance + mountholediameter / 2 + 1.27) { Grid[x][y] = "None"; } if ((P - C2).Length() < edgeclearance + mountholediameter / 2 + 1.27) { Grid[x][y] = "None"; } if ((P - C3).Length() < edgeclearance + mountholediameter / 2 + 1.27) { Grid[x][y] = "None"; } if ((P - C4).Length() < edgeclearance + mountholediameter / 2 + 1.27) { Grid[x][y] = "None"; } if (Grid[x][y] != "None") { GAWTop.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0); GAWBottom.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0); MaskTop.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0); MaskBottom.AddFlash(new PointD(xc, yc), DrillWidth * 1.3 / 2.0); ProtoHoleDrill.Drills.Add(new PointD(xc, yc)); } } } // SilkTop.DrawString(new PointD(5, 0), FS, "O0O", 5, 0.05, StringAlign.BottomCenter); // SilkTop.DrawString(new PointD(20, 0), FS, "O0O", 5, 0.05, StringAlign.CenterCenter); // SilkTop.DrawString(new PointD(40, 0), FS, "OMO", 5, 0.05, StringAlign.TopCenter); for (int x = 0; x < XE; x++) { double xc = XO + x * 2.54 + 2.54 / 2; double yc = YO + (0) * 2.54; double yc1 = YO + (YE) * 2.54 + 2.54; char T = (char)('A' + (char)((x) % 26)); if (Grid[x][0] != "None") { SilkTop.DrawString(new PointD(xc, yc), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter); SilkBottom.DrawString(new PointD(xc, yc), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true); } if (Grid[x][YE - 1] != "None") { SilkTop.DrawString(new PointD(xc, yc1), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter); SilkBottom.DrawString(new PointD(xc, yc1), FS, T.ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true); } } for (int y = 0; y < YE; y++) { double xc = XO + (0) * 2.54 - 2.54 / 2; double xc1 = XO + (XE + 1) * 2.54 - 2.54 / 2; double yc = YO + (y) * 2.54 + 2.54; if (Grid[0][y] != "None") { SilkTop.DrawString(new PointD(xc, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter); SilkBottom.DrawString(new PointD(xc, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true); } if (Grid[XE - 1][y] != "None") { SilkTop.DrawString(new PointD(xc1, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter); SilkBottom.DrawString(new PointD(xc1, yc), FS, (YE - y).ToString(), LabelHeight, 0.05, StringAlign.CenterCenter, true); } } PolyLine PL2 = new PolyLine(polyid++); double rad = 0.6; for (int i = 0; i < 20; i++) { double P = i * Math.PI / 19.0; PL2.Add(Math.Sin(P) * rad, Math.Cos(P) * rad); } PL2.Close(); PL2.Translate(-1.1, 0); for (int x = -1; x < XE + 1; x++) { for (int y = -1; y < YE + 1; y++) { string s1 = "None"; if (y >= 0 && y < YE && x < XE) { s1 = Grid[x + 1][y]; } string s2 = "None"; if (x >= 0 && x < XE && y < YE) { s2 = Grid[x][y + 1]; } string s3 = "None"; if (x >= 0 && x < XE && y >= 0 && y < YE) { s3 = Grid[x][y]; } double xc = XO + x * 2.54 + 2.54 / 2; double yc = YO + y * 2.54 + 2.54 / 2; double xc1 = XO + (x + 1) * 2.54 + 2.54 / 2; double yc1 = YO + (y + 1) * 2.54 + 2.54 / 2; if (s1 != "None" && s3 != "None") { PolyLine PLA = PL2.Copy(); PLA.Translate(xc1, yc); PolyLine PLC = PL2.Copy(); PLC.RotateDegrees(180); PLC.Translate(xc, yc); GAWTop.AddPolygon(PLA); MaskTop.AddPolygon(PLA); GAWTop.AddPolygon(PLC); MaskTop.AddPolygon(PLC); GAWBottom.AddPolygon(PLA); MaskBottom.AddPolygon(PLA); GAWBottom.AddPolygon(PLC); MaskBottom.AddPolygon(PLC); } if (s3 != "None" && s2 != "None") { PolyLine PLB = PL2.Copy(); PLB.RotateDegrees(90); PLB.Translate(xc, yc1); PolyLine PLD = PL2.Copy(); PLD.RotateDegrees(270); PLD.Translate(xc, yc); GAWTop.AddPolygon(PLB); MaskTop.AddPolygon(PLB); GAWTop.AddPolygon(PLD); MaskTop.AddPolygon(PLD); GAWBottom.AddPolygon(PLB); MaskBottom.AddPolygon(PLB); GAWBottom.AddPolygon(PLD); MaskBottom.AddPolygon(PLD); // GAWTop.AddPolygon(PLD); // MaskTop.AddPolygon(PLD); } } } GAWTop.Write(CopperTop); GAWBottom.Write(CopperBottom); SilkBottom.Write(SilkFileBottom); SilkTop.Write(SilkFileTop); MaskTop.Write(SolderMaskTop); MaskBottom.Write(SolderMaskBottom); EF.Tools[11] = ProtoHoleDrill; EF.Write(DrillFile, 0, 0, 0, 0); FilesGenerated.Add(CopperBottom); FilesGenerated.Add(CopperTop); FilesGenerated.Add(OutlineFile); FilesGenerated.Add(DrillFile); FilesGenerated.Add(SilkFileBottom); FilesGenerated.Add(SilkFileTop); FilesGenerated.Add(SolderMaskBottom); FilesGenerated.Add(SolderMaskTop); if (WriteCombinedImage) { GerberImageCreator GIC = new GerberImageCreator(); GIC.AddBoardsToSet(FilesGenerated); GIC.WriteImageFiles(basename + "_render", 200, false); } if (WriteImages) { Gerber.SaveGerberFileToImage(OutlineFile, OutlineFile + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(CopperBottom, CopperBottom + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(CopperTop, CopperTop + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(DrillFile, DrillFile + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(SilkFileTop, SilkFileTop + "_render.png", 1000, Color.Black, Color.White); Gerber.SaveGerberFileToImage(SilkFileBottom, SilkFileBottom + "_render.png", 1000, Color.Black, Color.White); } return(FilesGenerated); }
public void Build(ParsedGerber TheLines, List <Tool> Tools, Tool DefaultTool) { List <PolyLine> Shapes = new List <PolyLine>(); foreach (var A in TheLines.Shapes) { Shapes.Add(A); } Reset(); double lastx = 0; double lasty = 0; double lastdx = 0; double lastdy = 0; // add a final point to make the bezier curve neatly downward at the last PolyLine. This gets added AFTER optimize to ensure it is actually the last shape. PolyLine EndPoint = new PolyLine(-3); EndPoint.Add(0, 0); EndPoint.Draw = false; Shapes.Add(EndPoint); Reset(); // go to homing point Up(DefaultTool, true); Move(0, 0); // loop through all the polylines, add bezier-curves between them for continuous movements past the edges. This should also be done at line-kinks.. but not yet foreach (var a in Shapes) { double newx = a.Vertices[0].X; double newy = a.Vertices[0].Y; if (bezier) { double newdx = lastdx; double newdy = lastdy; if (a.Count() > 1) { newdx = a.Vertices[1].X - a.Vertices[0].X; newdy = a.Vertices[1].Y - a.Vertices[0].Y; } PointD D1 = Helpers.Normalize(new PointD((float)lastdx, (float)lastdy)); PointD D2 = Helpers.Normalize(new PointD((float)newdx, (float)newdy)); PointD AM = new PointD((float)lastx - D1.X * 10, (float)lasty - D1.Y * 10);; PointD A = new PointD((float)lastx, (float)lasty); PointD B = new PointD((float)lastx + D1.X * 7, (float)lasty + D1.Y * 7); PointD C = new PointD((float)newx - D2.X * 7, (float)newy - D2.Y * 7); PointD D = new PointD((float)newx, (float)newy); PointD DP = new PointD((float)newx + D2.X * 10, (float)newy + D2.Y * 10); for (int i = 0; i < 10; i++) { PointD T = Helpers.BezierPoint(A, B, C, D, i * 0.1f); Move(T.X, T.Y); } } Move(newx, newy); bool force = false; if (a.Count() == 1) { force = true; } if (a.Draw == true) { Down(null, force); } lastx = newx; lasty = newy; for (int i = 1; i < a.Count(); i++) { newx = a.Vertices[i].X; newy = a.Vertices[i].Y; Move(newx, newy); lastdx = newx - lastx; lastdy = newy - lasty; lastx = newx; lasty = newy; } if (a.Draw == true) { Up(null, force); } } // move back to homing point Move(0, 0); if (Gerber.ShowProgress) { Console.WriteLine("command count: {0}", CommandList.Count); } }
private void CreateRoad(Way w) { //GameObject go = new GameObject(); //go.name = "Road"; PolyLine pl = new PolyLine(w.id.ToString()); pl.SetOffset(offsetPositionX, offsetPositionZ); pl.heigth = w.height; if (w.type == WayType.Footway) { pl.material = Resources.Load("Materials/Footway Material") as Material; pl.width = 1; } if (w.type == WayType.Motorway) { pl.material = Resources.Load("Materials/Road Material") as Material; pl.width = 4; pl.lanes = 2; } if (w.type == WayType.Residential) { pl.material = Resources.Load("Materials/Road Material") as Material; pl.width = 2; } if (w.type == WayType.River) { pl.material = Resources.Load("Materials/River Material") as Material; pl.width = 8; } //Road road = go.AddComponent<Road>(); //road.groundOffset = 0.01f; //road.points.Clear(); //road.roadWidth = 0.1f;// (float)(road.roadWidth/precision); //road.mat = (Material)Resources.LoadAssetAtPath("Assets/RoadTool/Example/Texture/Materials/Road.mat", typeof(Material)); for (int a = 0; a < w.nodes.Count; a++) { Node n = w.nodes[a]; Vector3 position = new Vector3((float)(n.easthing - offsetPositionX), 5000, (float)(n.northing - offsetPositionZ)); float baseHeight = 0; RaycastHit hit; if (Physics.Raycast(position, -Vector3.up, out hit, Mathf.Infinity, layerMask)) { baseHeight = hit.point.y; } n.height = baseHeight; //Vector3 v = newn. Vector3((float)(((float)n.easthing-offsetPositionX)/precision),(float)0.0,(float)(((float)n.northing-offsetPositionZ)/precision)); //road.points.Insert(0, v); pl.Add(n); } pl.Close(transform); //go.isStatic = true; //road.Refresh(); //go.transform.parent = transform; }
private void VScore_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] D = e.Data.GetData(DataFormats.FileDrop) as string[]; BackColor = Color.Green; foreach (string S in D) { if (Directory.Exists(S)) { try { GerberLibrary.GerberImageCreator GIC = new GerberLibrary.GerberImageCreator(); var A = Directory.GetFiles(S); GIC.AddBoardsToSet(A.ToList(), new StandardConsoleLog()); GerberFrameWriter.FrameSettings FS = new GerberFrameWriter.FrameSettings(); List <String> OutputLines = new List <string>(); OutputLines.Add(String.Format("Panel for {0}", Path.GetDirectoryName(S))); Bounds PanelBounds = new Bounds(); double w = GIC.BoundingBox.Width(); double h = GIC.BoundingBox.Height(); double bx = GIC.BoundingBox.TopLeft.X; double by = GIC.BoundingBox.TopLeft.Y; GerberPanel Pnl = new GerberPanel(); Pnl.TheSet.ClipToOutlines = false; Pnl.AddGerberFolder(new StandardConsoleLog(), S); double ginbetween = (double)numericUpDown1.Value; for (int x = 0; x < (int)xbox.Value; x++) { for (int y = 0; y < (int)ybox.Value; y++) { var I = Pnl.AddInstance(S, new PointD(x * (w + ginbetween), y * (h + ginbetween))); OutputLines.Add(String.Format("Adding board instance: {0}mm x {1}mm offset", x * (w + ginbetween), y * (h + ginbetween))); if (theMode == PanelMode.Groovy) { I.IgnoreOutline = true; } PanelBounds.FitPoint(bx + ((x + 0) * (w + ginbetween)), by + ((y + 0) * (h + ginbetween))); PanelBounds.FitPoint(bx + (w + (x + 0) * (w + ginbetween)), by + ((y + 0) * (h + ginbetween))); PanelBounds.FitPoint(bx + (w + (x + 0) * (w + ginbetween)), by + (h + (y + 0) * (h + ginbetween))); PanelBounds.FitPoint(bx + ((x + 0) * (w + ginbetween)), by + (h + (y + 0) * (h + ginbetween))); } } if (theMode == PanelMode.Tabby) { OutputLines.Add("Panel created as Tabby board"); OutputLines.Add(String.Format("Space inbetween: {0}mm", ginbetween)); FS.FrameTitle = FrameTitle.Text;; FS.RenderSample = false; FS.margin = ginbetween; FS.topEdge = FS.leftEdge = (double)framebox.Value; OutputLines.Add(String.Format("Frame width: {0}mm", FS.leftEdge)); FS.roundedInnerCorners = 0; FS.roundedOuterCorners = 0; FS.RenderSample = false; FS.DirectionArrowSide = GerberLibrary.Core.BoardSide.Top; FS.RenderDirectionArrow = true; //FS.DefaultFiducials = true; //FS.FiducialSide = BoardSide.Both; FS.HorizontalTabs = false; FS.VerticalTabs = false; FS.InsideEdgeMode = GerberFrameWriter.FrameSettings.InsideMode.RegularEdge; FS.PositionAround(PanelBounds); string sS = String.Format("Frame size: {0} mm x {1} mm", FS.innerWidth + FS.margin * 2 + FS.leftEdge, FS.innerHeight + FS.margin * 2 + FS.topEdge); OutputLines.Add(sS); var OutputFolder = Path.Combine(S, "../" + Path.GetFileNameWithoutExtension(S) + "_TABBY"); Directory.CreateDirectory(OutputFolder); String FrameFolder = Path.Combine(OutputFolder, "frame"); Directory.CreateDirectory(FrameFolder); //Directory.CreateDirectory(Path.Combine(OutputFolder, "merged")); Directory.CreateDirectory(Path.Combine(OutputFolder, "merged")); GerberFrameWriter.WriteSideEdgeFrame(null, FS, Path.Combine(FrameFolder, "panelframe"), null); Pnl.AddGerberFolder(new StandardConsoleLog(), FrameFolder); Pnl.AddInstance(FrameFolder, new PointD(0, 0)); Pnl.TheSet.MergeFileTypes = false; int tabcount = 2; double tx = (w - (tabcount * ginbetween * 2)) / (tabcount + 1.0f); double ty = (h - (tabcount * ginbetween * 2)) / (tabcount + 1.0f); double txs = tx + ginbetween; double tys = ty + ginbetween; tx += ginbetween * 2; ty += ginbetween * 2; for (int x = 0; x < (int)xbox.Value + 1; x++) { for (int y = 0; y < (int)ybox.Value + 1; y++) { for (int i = 0; i < tabcount; i++) { if (x < (int)xbox.Value) { var BT1 = Pnl.AddTab(new PointD(bx + (x + 0) * (w + ginbetween) + tx * (i) + txs, by + ((y + 0) * (h + ginbetween)) - ginbetween / 2)); BT1.Radius = (float)ginbetween; } if (y < (int)ybox.Value) { var BT2 = Pnl.AddTab(new PointD(bx + (x + 0) * (w + ginbetween) - ginbetween / 2, by + ((y + 0) * (h + ginbetween)) + ty * (i) + tys)); BT2.Radius = (float)ginbetween; } } } } Pnl.UpdateShape(new StandardConsoleLog()); Pnl.SaveGerbersToFolder(Path.GetFileNameWithoutExtension(S) + "_Panel", Path.Combine(OutputFolder, "merged"), new StandardConsoleLog()); File.WriteAllLines(Path.Combine(OutputFolder, "PanelReport.txt"), OutputLines); List <String> FilesInFolder = Directory.GetFiles(Path.Combine(OutputFolder, "merged"), "*.frontpanelholes").ToList(); if (FilesInFolder.Count > 0) { String JigFolder = Path.Combine(OutputFolder, "jig"); Directory.CreateDirectory(JigFolder); File.Copy(FilesInFolder[0], Path.Combine(JigFolder, "jig.gml"), true); FS.InsideEdgeMode = GerberFrameWriter.FrameSettings.InsideMode.NoEdge; GerberFrameWriter.WriteSideEdgeFrame(null, FS, Path.Combine(JigFolder, "jig"), null); GerberMerger.Merge(Path.Combine(JigFolder, "jig.gml"), Path.Combine(JigFolder, "jig.gko"), Path.Combine(JigFolder, "jig.gko2"), new StandardConsoleLog()); File.Delete(Path.Combine(JigFolder, "jig.gko")); File.Delete(Path.Combine(JigFolder, "jig.gml")); File.Move(Path.Combine(JigFolder, "jig.gko2"), Path.Combine(JigFolder, "jig.gko")); } } if (theMode == PanelMode.Groovy) { FS.FrameTitle = FrameTitle.Text;; FS.RenderSample = false; FS.margin = 0; FS.topEdge = FS.leftEdge = (double)framebox.Value; FS.roundedInnerCorners = 0; FS.roundedOuterCorners = 0; FS.RenderSample = false; FS.RenderDirectionArrow = false; FS.DirectionArrowSide = GerberLibrary.Core.BoardSide.Top; //FS.DefaultFiducials = true; //FS.FiducialSide = BoardSide.Both; FS.HorizontalTabs = false; FS.VerticalTabs = false; FS.InsideEdgeMode = GerberFrameWriter.FrameSettings.InsideMode.NoEdge; FS.PositionAround(PanelBounds); var OutputFolder = Path.Combine(S, "../" + Path.GetFileNameWithoutExtension(S) + "_GROOVY"); Directory.CreateDirectory(OutputFolder); GerberOutlineWriter GOW = new GerberOutlineWriter(); int xmax = (int)xbox.Value + 1; int ymax = (int)ybox.Value + 1; if (ginbetween > 0) { xmax--; ymax--; } for (int x = 0; x < xmax; x++) { PolyLine PL = new PolyLine(); PL.Add(bx + (x) * (w + ginbetween), PanelBounds.TopLeft.Y - (float)framebox.Value - 10); PL.Add(bx + (x) * (w + ginbetween), PanelBounds.BottomRight.Y + (float)framebox.Value + 10); GOW.AddPolyLine(PL); if (ginbetween > 0) { PolyLine PL2 = new PolyLine(); PL2.Add(bx + (x) * (w + ginbetween) + w, PanelBounds.TopLeft.Y - (float)framebox.Value - 10); PL2.Add(bx + (x) * (w + ginbetween) + w, PanelBounds.BottomRight.Y + (float)framebox.Value + 10); GOW.AddPolyLine(PL2); } } for (int y = 0; y < ymax; y++) { PolyLine PL = new PolyLine(); PL.Add(PanelBounds.TopLeft.X - (float)framebox.Value - 10, by + (y) * (h + ginbetween)); PL.Add(PanelBounds.BottomRight.X + (float)framebox.Value + 10, by + (y) * (h + ginbetween)); GOW.AddPolyLine(PL); if (ginbetween > 0) { PolyLine PL2 = new PolyLine(); PL2.Add(PanelBounds.TopLeft.X - (float)framebox.Value - 10, by + (y) * (h + ginbetween) + h); PL2.Add(PanelBounds.BottomRight.X + (float)framebox.Value + 10, by + (y) * (h + ginbetween) + h); GOW.AddPolyLine(PL2); } } GOW.Write(Path.Combine(OutputFolder, "VGrooves.gbr")); String FrameFolder = Path.Combine(OutputFolder, "frame"); Directory.CreateDirectory(FrameFolder); Directory.CreateDirectory(Path.Combine(OutputFolder, "merged")); GerberFrameWriter.WriteSideEdgeFrame(null, FS, Path.Combine(FrameFolder, "panelframe"), null); Pnl.AddGerberFolder(new StandardConsoleLog(), FrameFolder); Pnl.AddInstance(FrameFolder, new PointD(0, 0)); Pnl.UpdateShape(new StandardConsoleLog()); Pnl.SaveGerbersToFolder(Path.GetFileNameWithoutExtension(S) + "_Panel", Path.Combine(OutputFolder, "merged"), new StandardConsoleLog()); } CountDown = 10; } catch (Exception) { BackColor = Color.Red; } } } } }
private void VScore_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] D = e.Data.GetData(DataFormats.FileDrop) as string[]; BackColor = Color.Green; foreach (string S in D) { if (Directory.Exists(S)) { try { var OutputFolder = Path.Combine(S, "../" + Path.GetFileNameWithoutExtension(S) + "_GROOVY"); Directory.CreateDirectory(OutputFolder); GerberLibrary.GerberImageCreator GIC = new GerberLibrary.GerberImageCreator(); var A = Directory.GetFiles(S); GIC.AddBoardsToSet(A.ToList(), new StandardConsoleLog()); GerberFrameWriter.FrameSettings FS = new GerberFrameWriter.FrameSettings(); FS.FrameTitle = FrameTitle.Text;; FS.RenderSample = false; FS.margin = 0; FS.topEdge = FS.leftEdge = (double)framebox.Value; FS.roundedInnerCorners = 0; FS.roundedOuterCorners = 0; FS.RenderSample = false; FS.RenderDirectionArrow = false; FS.DirectionArrowSide = GerberLibrary.Core.BoardSide.Top; //FS.DefaultFiducials = true; //FS.FiducialSide = BoardSide.Both; FS.HorizontalTabs = false; FS.VerticalTabs = false; FS.InsideEdgeMode = GerberFrameWriter.FrameSettings.InsideMode.NoEdge; Bounds PanelBounds = new Bounds(); double w = GIC.BoundingBox.Width(); double h = GIC.BoundingBox.Height(); double bx = GIC.BoundingBox.TopLeft.X; double by = GIC.BoundingBox.TopLeft.Y; GerberPanel Pnl = new GerberPanel(); Pnl.TheSet.ClipToOutlines = false; Pnl.AddGerberFolder(new StandardConsoleLog(), S); for (int x = 0; x < (int)xbox.Value; x++) { for (int y = 0; y < (int)ybox.Value; y++) { var I = Pnl.AddInstance(S, new PointD(x * w, y * h)); I.IgnoreOutline = true; PanelBounds.FitPoint(bx + ((x + 0) * w), by + ((y + 0) * h)); PanelBounds.FitPoint(bx + ((x + 1) * w), by + ((y + 0) * h)); PanelBounds.FitPoint(bx + ((x + 1) * w), by + ((y + 1) * h)); PanelBounds.FitPoint(bx + ((x + 0) * w), by + ((y + 1) * h)); } } FS.PositionAround(PanelBounds); GerberOutlineWriter GOW = new GerberOutlineWriter(); for (int x = 0; x < (int)xbox.Value + 1; x++) { PolyLine PL = new PolyLine(); PL.Add(bx + (x) * w, PanelBounds.TopLeft.Y - (float)framebox.Value - 10); PL.Add(bx + (x) * w, PanelBounds.BottomRight.Y + (float)framebox.Value + 10); GOW.AddPolyLine(PL); } for (int y = 0; y < (int)ybox.Value + 1; y++) { PolyLine PL = new PolyLine(); PL.Add(PanelBounds.TopLeft.X - (float)framebox.Value - 10, by + (y) * h); PL.Add(PanelBounds.BottomRight.X + (float)framebox.Value + 10, by + (y) * h); GOW.AddPolyLine(PL); } GOW.Write(Path.Combine(OutputFolder, "VGrooves.gbr")); String FrameFolder = Path.Combine(OutputFolder, "frame"); Directory.CreateDirectory(FrameFolder); Directory.CreateDirectory(Path.Combine(OutputFolder, "merged")); GerberFrameWriter.WriteSideEdgeFrame(null, FS, Path.Combine(FrameFolder, "panelframe"), null); Pnl.AddGerberFolder(new StandardConsoleLog(), FrameFolder); Pnl.AddInstance(FrameFolder, new PointD(0, 0)); Pnl.UpdateShape(new StandardConsoleLog()); Pnl.SaveGerbersToFolder(Path.GetFileNameWithoutExtension(S) + "_Panel", Path.Combine(OutputFolder, "merged"), new StandardConsoleLog()); CountDown = 10; } catch (Exception) { BackColor = Color.Red; } } } } }
public override IEnumerator Build(Way w, MapChunkLoader mcl) { //GameObject go = new GameObject(); //go.name = "Road"; GameObject road = new GameObject(); road.name = "Road - " + w.id.ToString(); road.isStatic = true; road.transform.parent = mcl.transform; string roadPath = Application.persistentDataPath + "Assets/Resources/Objs/" + road.name + ".obj"; if (!File.Exists(roadPath)) // If the file isn't cached we calculate everything and then we cache it { Debug.Log("STARTED CREATING ROAD"); PolyLine pl = new PolyLine(w.id.ToString()); pl.SetOffset(mcl.offsetPositionX, mcl.offsetPositionZ); pl.heigth = w.height; if (w.type == WayType.Footway) { pl.material = Resources.Load("Materials/Footway Material") as Material; pl.width = 1; } if (w.type == WayType.Motorway) { pl.material = Resources.Load("Materials/Road Material") as Material; pl.width = 4; pl.lanes = 2; } if (w.type == WayType.Residential) { pl.material = Resources.Load("Materials/Road Material") as Material; pl.width = 2; } if (w.type == WayType.River) { pl.material = Resources.Load("Materials/River Material") as Material; pl.width = 8; } for (int a = 0; a < w.nodes.Count; a++) { Node n = w.nodes[a]; Vector3 position = new Vector3((float)(n.easthing - mcl.offsetPositionX), 5000, (float)(n.northing - mcl.offsetPositionZ)); float baseHeight = 0; RaycastHit hit; if (Physics.Raycast(position, -Vector3.up, out hit, Mathf.Infinity, mcl.layerMask)) { baseHeight = hit.point.y; } n.height = baseHeight; pl.Add(n); } //Closed road; mcl.StartCoroutine(pl.Close(road)); if (mcl.exportObjs) { while (road.GetComponent<MeshFilter>() == null) { yield return null; } MeshFilter mf = road.GetComponent<MeshFilter>(); ObjExporter oe = new ObjExporter(); oe.MeshToFile(mf, roadPath); } } else { ObjImporter oi = new ObjImporter(); mcl.StartCoroutine(oi.FileToMesh("file://" + roadPath)); while (oi._myMesh == null) { yield return null; } MeshFilter mf = road.AddComponent<MeshFilter>(); MeshRenderer mr = road.AddComponent<MeshRenderer>(); mf.sharedMesh = oi._myMesh; Debug.LogWarning("Loaded Road from cache " + roadPath); if (w.type == WayType.Footway) { mr.material = Resources.Load("Materials/Footway Material") as Material; } if (w.type == WayType.Motorway) { mr.material = Resources.Load("Materials/Road Material") as Material; } if (w.type == WayType.Residential) { mr.material = Resources.Load("Materials/Road Material") as Material; } if (w.type == WayType.River) { mr.material = Resources.Load("Materials/River Material") as Material; } } }