public static Rhino.Geometry.Extrusion ToNative(this SpeckleExtrusion extrusion) { Curve profile = null; switch (extrusion.Profile.Type) { case "Curve": profile = (( SpeckleCurve )extrusion.Profile).ToNative(); break; case "Polycurve": profile = ((( SpecklePolycurve )extrusion.Profile).ToNative()); if (!profile.IsClosed) { profile.Reverse(); } break; case "Polyline": profile = (( SpecklePolyline )extrusion.Profile).ToNative(); if (!profile.IsClosed) { profile.Reverse(); } break; case "Arc": profile = (( SpeckleArc )extrusion.Profile).ToNative(); break; case "Circle": profile = (( SpeckleCircle )extrusion.Profile).ToNative(); break; case "Ellipse": profile = (( SpeckleEllipse )extrusion.Profile).ToNative(); break; case "Line": profile = (( SpeckleLine )extrusion.Profile).ToNative(); break; default: profile = null; break; } if (profile == null) { return(null); } var myExtrusion = Extrusion.Create(profile.ToNurbsCurve(), extrusion.Length, extrusion.Capped); var res = myExtrusion.SetPathAndUp(extrusion.PathStart.ToNative().Location, extrusion.PathEnd.ToNative().Location, extrusion.PathTangent.ToNative()); var resss = res; myExtrusion.UserDictionary.ReplaceContentsWith(extrusion.Properties.ToNative()); return(myExtrusion); }
// TODO: See above. We're no longer creating new extrusions. This is here just for backwards compatibility. public static Rhino.Geometry.Extrusion ToNative(this SpeckleExtrusion extrusion) { Curve outerProfile = ( Curve )Converter.Deserialise(extrusion.Profile); Curve innerProfile = null; if (extrusion.Profiles.Count == 2) { innerProfile = ( Curve )Converter.Deserialise(extrusion.Profiles[1]); } try { var IsClosed = extrusion.Profile.GetType().GetProperty("IsClosed").GetValue(extrusion.Profile, null) as bool?; if (IsClosed != true) { outerProfile.Reverse(); } } catch { } var myExtrusion = Extrusion.Create(outerProfile.ToNurbsCurve(), ( double )extrusion.Length, ( bool )extrusion.Capped); if (innerProfile != null) { myExtrusion.AddInnerProfile(innerProfile); } return(myExtrusion); }
public bool createBlocks(urbanModel model, int hMaxRW) { Random blockType = new Random(); Brep precintPolySurface = model.precinctSrf.ToBrep().Faces[0].Split(model.roadNetwork, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); //split face using 3D trimming curves List <Brep> allBlocks = new List <Brep>(); // keep as list in createBlocks only foreach (BrepFace itBF in precintPolySurface.Faces) { Brep itBlock = itBF.DuplicateFace(false); // a collection of Brep faces itBlock.Faces.ShrinkFaces(); itBlock.Flip(); allBlocks.Add(itBlock); // all blocks, including road surfaces/blocks which don't need saving, so temporary } ///////// ALL ADDED BELOW List <block> blocks = new List <block>(); // assign to model.blocks - plots will also be assigned to these blocks //max road width as integer; int halfR = 2 * hMaxRW; foreach (Brep itB in allBlocks) //save only blocks (to bldBlocks) wider than the widest road (i.e. 2*halfRoad) to list, i.e. exclude road surfaces { if (itB.Edges[0].GetLength() > 2 * halfR && itB.Edges[1].GetLength() > 2 * halfR && itB.Edges[2].GetLength() > 2 * halfR && itB.Edges[3].GetLength() > 2 * halfR) { int theBlockType = blockType.Next(4); //the random type chosen, up to integer 4 blocks.Add(new block(itB, theBlockType)); // assigns to block method in urbanModel, taking itB input and theBlockType from the random integer ObjectAttributes oaPk = new ObjectAttributes(); //makes type 0 parks plus green surface oaPk.ColorSource = ObjectColorSource.ColorFromObject; oaPk.ObjectColor = System.Drawing.Color.FromArgb(0, 153, 76); Extrusion parkExt = new Extrusion(); if (theBlockType == 0) { Curve boundary = Curve.JoinCurves(itB.DuplicateNakedEdgeCurves(true, false))[0]; parkExt = Extrusion.Create(boundary, 0.1, true); RhinoDoc.ActiveDoc.Objects.AddExtrusion(parkExt, oaPk); } RhinoDoc.ActiveDoc.Objects.AddBrep(itB); RhinoDoc.ActiveDoc.Views.Redraw(); } } ///////// ALL ADDED ABOVE if (blocks.Count > 0) { model.blocks = blocks; //assigns blocks to to model.blocks in urbanModel return(true); } else { return(false); } }
public static Rhino.Geometry.Extrusion ToNative(this SpeckleExtrusion extrusion) { Curve profile = null; switch (extrusion.Profile) { case SpeckleCore.SpeckleCurve curve: profile = curve.ToNative(); break; case SpeckleCore.SpecklePolycurve polycurve: profile = polycurve.ToNative(); if (!profile.IsClosed) { profile.Reverse(); } break; case SpeckleCore.SpecklePolyline polyline: profile = polyline.ToNative(); if (!profile.IsClosed) { profile.Reverse(); } break; case SpeckleCore.SpeckleArc arc: profile = arc.ToNative(); break; case SpeckleCore.SpeckleCircle circle: profile = circle.ToNative(); break; case SpeckleCore.SpeckleEllipse ellipse: profile = ellipse.ToNative(); break; case SpeckleCore.SpeckleLine line: profile = line.ToNative(); break; default: profile = null; break; } if (profile == null) { return(null); } var myExtrusion = Extrusion.Create(profile.ToNurbsCurve(), ( double )extrusion.Length, ( bool )extrusion.Capped); myExtrusion.UserDictionary.ReplaceContentsWith(extrusion.Properties.ToNative()); return(myExtrusion); }
private bool ProcesssCurveItem(HbInputItem hbInputItem, double verticalHeight) { try { List <Point3d> points; Curve curve; Extrusion extrusion = null; //Brep brep = null; HbToRhino(hbInputItem.HbCurve, out points, out curve); // Add to outputs this.dataTreePoints.AddRange(points, new GH_Path(indexPoints)); indexPoints++; this.dataTreeCurves.AddRange(new List <Curve> { curve }, new GH_Path(indexCurves)); indexCurves++; if (verticalHeight > 0) { extrusion = Extrusion.Create(curve, verticalHeight, false); this.dataTreeBreps.AddRange(new List <Brep> { Brep.CreateFromSurface(extrusion) }, new GH_Path(indexBreps)); indexBreps++; } // Create Geometry if (createGeometryPoints) { if (points != null) { foreach (Point3d point3d in points) { Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(point3d); } } } if (createGeometryCurves) { if (curve != null) { Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(curve); } } if (createGeometrySurfaces) { if (extrusion != null) { Rhino.RhinoDoc.ActiveDoc.Objects.AddExtrusion(extrusion); } } return(true); } catch { return(false); } }
private static GH_Mesh CreateMesh(Point3d centerPoint, double radius, double height) { var circle = new Circle(centerPoint, radius); var extrusion = Extrusion.Create( circle.ToNurbsCurve(), height, true ); return(new GH_Mesh(Mesh.CreateFromSurface(extrusion))); }
public static Extrusion OgrPolygonToExtrusion(OSGeo.OGR.Geometry polygon, Transform transform, double height, double min_height, bool underground) { List <Curve> pList = new List <Curve>(); OSGeo.OGR.Geometry sub_geom; int direction = 1; if (underground) { direction = -1; } //pList = OgrMultiLinestringToCurves(polygon, transform); for (int i = 0; i < polygon.GetGeometryCount(); i++) { sub_geom = polygon.GetGeometryRef(i); Curve crv = Heron.Convert.OgrRingToCurve(sub_geom, transform); if (crv.ClosedCurveOrientation(Plane.WorldXY.ZAxis) == CurveOrientation.Clockwise) { crv.Reverse(); } pList.Add(crv); sub_geom.Dispose(); } pList[0].TryGetPlane(out var profilePlane); Transform profileTransform = Transform.PlaneToPlane(profilePlane, Plane.WorldXY); Extrusion extrusion = Extrusion.Create(pList[0], (height - min_height) * direction, true); if (extrusion == null) { return(null); } if (pList.Count > 1) { pList.RemoveAt(0); foreach (Curve innerCurve in pList) { Curve crv = innerCurve.DuplicateCurve(); crv.Transform(profileTransform); extrusion.AddInnerProfile(crv); } } Vector3d moveDir = new Vector3d(0, 0, min_height); extrusion.Translate(moveDir); return(extrusion); }
public Extrusion GetOffsetExtrusion() { var offsetCrv = SITE.Offset( CENTROID, Vector3d.ZAxis, SETBACKDIST, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.Sharp ); double ar = AreaMassProperties.Compute(offsetCrv[0]).Area; HEIGHT = GFA / ar; SOLID = Extrusion.Create(offsetCrv[0], -HEIGHT, true); return(SOLID); }
public static Brep DrawCore(Core hhp) { double height = hhp.Stories == 0 ? Consts.PilotiHeight : Consts.FloorHeight; Vector3d x = hhp.XDirection; Vector3d y = hhp.YDirection; double width = hhp.Width; double depth = hhp.Depth; PolylineCurve plc = new PolylineCurve(new Point3d[] { hhp.Origin, hhp.Origin + x * width, hhp.Origin + x * width + y * depth, hhp.Origin + y * depth, hhp.Origin }); if (plc.ClosedCurveOrientation(Plane.WorldXY) == CurveOrientation.CounterClockwise) { plc.Reverse(); } return(Extrusion.Create(plc, height, true).ToBrep()); }
public void genBaseMass() { PolylineCurve outerCrv = new PolylineCurve(outerPtLi); double outerAr = AreaMassProperties.Compute(outerCrv).Area; PolylineCurve innerCrv = new PolylineCurve(innerPtLi); double innerAr = AreaMassProperties.Compute(innerCrv).Area; double diffAr = outerAr - innerAr; int numBaseFlrs = (int)(SITE_AR * baseFsr / diffAr) + 1; double baseHt = numBaseFlrs * flrHt; Extrusion outerExtr = Extrusion.Create(outerCrv, baseHt, true); Extrusion innerExtr = Extrusion.Create(innerCrv, baseHt, true); Brep[] outerBrep = { outerExtr.ToBrep() }; Brep[] innerBrep = { innerExtr.ToBrep() }; Brep[] diffBrep = Brep.CreateBooleanDifference(outerBrep, innerBrep, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); for (int i = 0; i < diffBrep.Length; i++) { globalBrepLi.Add(diffBrep[i]); } globalBaseCrvLi = new List <Curve>(); double spineHt = 0.0; for (int i = 0; i < numBaseFlrs; i++) { Curve outerCrvDup = outerCrv.DuplicateCurve(); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, spineHt); outerCrvDup.Transform(xform); Curve innerCrvDup = innerCrv.DuplicateCurve(); innerCrvDup.Transform(xform); globalBaseCrvLi.Add(innerCrvDup); globalBaseCrvLi.Add(outerCrvDup); spineHt += flrHt; } BaseMassHt = baseHt; }
//// CLASS BUILDING FOLLOWS public bool createBuilding(int inpPlotType) //ALL TO BECOME BUILDING CLASS? BUT WHY PUT IT HERE AND NOT UNDER URBSIMCOMMAND?? { if (this.plotSrf.GetArea() < 50) //skip areas that are too small { return(false); } if (inpPlotType > 0) // skip parks, type 0 (or, green rgb 90,143,41?) { int minBldHeight = 0; int maxBldHeight = 9; if (inpPlotType == 1) // low rise { minBldHeight = 12; maxBldHeight = 24; } if (inpPlotType == 2) // mid rise { minBldHeight = 36; maxBldHeight = 72; } if (inpPlotType == 3) // high rise { minBldHeight = 84; maxBldHeight = 120; } double actBuildingHeight = this.bldHeight.Next(minBldHeight, maxBldHeight); System.Drawing.Color bldCol = System.Drawing.Color.White; if (actBuildingHeight < 10) { bldCol = System.Drawing.Color.FromArgb(204, 0, 0); } else if (actBuildingHeight < 36) { bldCol = System.Drawing.Color.FromArgb(204, 102, 0); } else if (actBuildingHeight < 50) { bldCol = System.Drawing.Color.FromArgb(204, 204, 0); } else if (actBuildingHeight < 73) { bldCol = System.Drawing.Color.FromArgb(0, 204, 204); } else if (actBuildingHeight < 91) { bldCol = System.Drawing.Color.FromArgb(0, 102, 204); } else if (actBuildingHeight > 91) { bldCol = System.Drawing.Color.FromArgb(102, 0, 204); } ObjectAttributes oa = new ObjectAttributes(); oa.ColorSource = ObjectColorSource.ColorFromObject; oa.ObjectColor = bldCol; Curve border = Curve.JoinCurves(this.plotSrf.DuplicateNakedEdgeCurves(true, false))[0]; //makes first index of list these joined curves i.e. a polyline = border this.buildingOutline = Curve.JoinCurves(border.Offset(Plane.WorldXY, -4, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None))[0]; //makes first index of list these offset joined curves i.e.a polyline = buildingOutline double maxStoreyHeight = 3.6; //applies to all building types; make different for each type? double actStoNo = Math.Floor(actBuildingHeight / maxStoreyHeight); //so 25m at max 3 each gives 8 storeys double actstoHt = actBuildingHeight / actStoNo; // so 25m, 8 storeys of 3.125m each this.buildingExtrusion = Extrusion.Create(this.buildingOutline, actBuildingHeight, true); RhinoDoc.ActiveDoc.Objects.AddExtrusion(this.buildingExtrusion, oa); //// CLASS UNIT FOLLOWS //extrude first curve of bldgoutline to storey height only List <Brep> bUnits = new List <Brep>(); // units for each building collected here Brep gUnit; // ground level unit added to list first gUnit = Extrusion.Create(this.buildingOutline, actstoHt, true).ToBrep(); bUnits.Add(gUnit); RhinoDoc.ActiveDoc.Objects.AddBrep(gUnit, oa); allUnits.AddRange(bUnits); //copy building outline Curve newOline = this.buildingOutline; for (int t = 0; t < (actStoNo - 1); t++) //storeys less 1, because startS level 1, not ground { //make a point3d to storey height above and vector Point3d pt1 = newOline.PointAtStart; Plane perpFrm; newOline.PerpendicularFrameAt(0.0, out perpFrm); Point3d pt2 = Point3d.Add(pt1, perpFrm.ZAxis * actstoHt); Vector3d vecD = (pt2 - pt1); //translate curve to storey height above newOline.Translate(vecD); //extrude newOline and make brep Brep upUnit = Extrusion.Create(newOline, actstoHt, true).ToBrep(); bUnits.Add(upUnit); RhinoDoc.ActiveDoc.Objects.AddBrep(upUnit, oa); } // with bUnits collected, add these to a list outside of //this.buildingUnits = allUnits; //assign units to buildings //extract data from building and levels //link to Excel spreadsheet ///// ALL ADDED ABOVE } return(true); }
public static bool TryGetExtrusion(this Brep brep, out Extrusion extrusion) { if (brep.IsSurface) { return(brep.Faces[0].TryGetExtrusion(out extrusion)); } extrusion = null; if (brep.Faces.Count < 3) { return(false); } // Requiere manifold breps if (brep.SolidOrientation == BrepSolidOrientation.None || brep.SolidOrientation == BrepSolidOrientation.Unknown) { return(false); } // If brep has more that 3 faces we should check if there are faces with interior loops if (brep.Faces.Count > 3 && brep.Faces.Where(face => face.Loops.Count != 1).Any()) { return(false); } var candidateFaces = new List <int[]>(); // Array with just planar faces sorted by its area to search for similar faces var planarFaces = brep.Faces. Select(face => new PlanarBrepFace(face)). Where(face => face.Plane.IsValid). OrderByDescending(face => face.LoopArea). ToArray(); // A capped Extrusion converted to Brep has wall surfaces in face[0] to face[N-3], caps are face[N-2] and face[N-1] // I iterate in reverse order to be optimisitc, maybe brep comes from an Extrusion.ToBrep() call for (int f = planarFaces.Length - 1; f > 0; --f) { var planeF = planarFaces[f].Plane; var loopF = planarFaces[f].Loop; var centroidF = planarFaces[f].Centroid; // Check if they have same area. for (int g = f - 1; g >= 0 && RhinoMath.EpsilonEquals(planarFaces[f].LoopArea, planarFaces[g].LoopArea, RhinoMath.SqrtEpsilon); --g) { // Planes should be parallel or anti-parallel if (planeF.Normal.IsParallelTo(planarFaces[g].Plane.Normal, RhinoMath.DefaultAngleTolerance / 100.0) == 0) { continue; } // Here f, ang are perfect candidates to test adjacent faces for perpendicularity to them, // but we may try to quick reject some candidates if it's obvious that doesn't match // A "perfect" curve overlap match may be a test but is too much in this ocasion // We expect same NURBS structure, so point count should match if (loopF.Points.Count != planarFaces[g].Loop.Points.Count) { continue; } // Since we have computed the area the centroid comes for free. // Centroids should also match if (planeF.ClosestPoint(planarFaces[g].Centroid).DistanceToSquared(centroidF) > RhinoMath.SqrtEpsilon) { continue; } // Add result to candidates List reversing index order to keep extrusion creation direction // Breps that come from a Extrusion have the Cap[0] before Cap[1] candidateFaces.Add(new int[] { g, f }); } } // No twin faces found if (candidateFaces.Count == 0) { return(false); } // Candidates are in 'LoopArea' order, we will find here smaller profiles sooner // This is good for beam like objects, bad for slab like objects. // On box-like Breps the result could be ambigous for the user so, // to give him some control on the result, we will prioritize first and last faces no matter their area. // First and Last are "special" because if somebody observe an extrusion-like Brep and sees // it as an extrusion he tends to categorize faces in one of the following schemas: // { Cap[0], Wall[0] .. Wall[N], Cap[1] } // { Cap[0], Cap[1], Wall[0] .. Wall[N] } // { Wall[0] .. Wall[N], Cap[0], Cap[1] } // So if he is using the join command to create a Brep from surfaces at the model, // it's natural to start or end the selection with one of the extrusion caps. // On horizontal extrusions, slab-like Breps, the user use to observe the model from above, // so probably he will end with the bottom cap. // Also Last face is a Cap in Breps that come from Extrusion // If caps and walls are interleaved, smallest pair of faces will be used as caps, producing beam-like extrusions. // System.Linq.Enumerable.OrderBy performs a stable sort so only first and last face will be moved if found. foreach (var candidate in candidateFaces.OrderBy(pair => (planarFaces[pair[1]].Face.FaceIndex == brep.Faces.Count - 1) ? 0 : // Last, in case it comes from Extrusion (planarFaces[pair[0]].Face.FaceIndex == 0) ? 1 : // First, in case it comes from a JOIN command int.MaxValue)) // Others { var startFace = planarFaces[candidate[0]]; var endFace = planarFaces[candidate[1]]; // If any face, ignorig twins candidates, does not degenrate // to a curve when projected to 'planeF', then brep is not an extrusion if ( brep.Faces. Where(face => face.FaceIndex != startFace.Face.FaceIndex && face.FaceIndex != endFace.Face.FaceIndex). Select(face => startFace.ProjectionDegenartesToCurve(face.UnderlyingSurface())). Any(degenerateToCurve => degenerateToCurve == false) ) { return(false); } // We use the orginal OuterLoop as profile not the NURBS version of it // to keep the structure as much as possible var profile = startFace.Face.OuterLoop.To3dCurve(); double height = startFace.Face.OrientationIsReversed ? -startFace.Plane.DistanceTo(endFace.Plane.Origin) : +startFace.Plane.DistanceTo(endFace.Plane.Origin); extrusion = Extrusion.Create(profile, height, true); return(true); } return(false); }
public bool createBuilding(int inpPlotType) { if (this.plotSrf.GetArea() < 50) { return(false); } if (inpPlotType > 0) // Skip Parks { int minBldHeight = 0; int maxBldHeight = 3; if (inpPlotType == 1) //Low Rise { minBldHeight = 3; maxBldHeight = 9; } if (inpPlotType == 2) //Mid Rise { minBldHeight = 15; maxBldHeight = 32; } if (inpPlotType == 3) //High Rise { minBldHeight = 60; maxBldHeight = 120; } double actBuildingHeight = this.bldHeight.Next(minBldHeight, maxBldHeight); System.Drawing.Color bldCol = System.Drawing.Color.White; if (actBuildingHeight < 6) { bldCol = System.Drawing.Color.FromArgb(168, 126, 198); } else if (actBuildingHeight < 12) { bldCol = System.Drawing.Color.FromArgb(255, 173, 194); } else if (actBuildingHeight < 36) { bldCol = System.Drawing.Color.FromArgb(243, 104, 75); } else if (actBuildingHeight < 92) { bldCol = System.Drawing.Color.FromArgb(225, 164, 24); } else if (actBuildingHeight > 92) { bldCol = System.Drawing.Color.FromArgb(254, 255, 51); } ObjectAttributes oa = new ObjectAttributes(); oa.ColorSource = ObjectColorSource.ColorFromObject; oa.ObjectColor = bldCol; Curve border = Curve.JoinCurves(this.plotSrf.DuplicateNakedEdgeCurves(true, false))[0]; this.buildingOutline = Curve.JoinCurves(border.Offset(Plane.WorldXY, -4, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None))[0]; this.building = Extrusion.Create(this.buildingOutline, actBuildingHeight, true); RhinoDoc.ActiveDoc.Objects.AddCurve(buildingOutline); RhinoDoc.ActiveDoc.Objects.AddExtrusion(this.building, oa); } return(true); }
protected override void SolveInstance(IGH_DataAccess DA) { Curve siteCrv = null; double flrHt = double.NaN; double minAr = double.NaN; string stepbackstr = "2,3,4"; string htstr = "2,3,4"; string outputMsg = ""; List <double> stepbackLi = new List <double>(); List <double> htLi = new List <double>(); if (!DA.GetData(0, ref siteCrv)) { return; } //if (!DA.GetData(1, ref fsr)) return; if (!DA.GetData(1, ref flrHt)) { return; } // if (!DA.GetData(3, ref stepbackstr)) return; // if (!DA.GetData(4, ref htstr)) return; bool t0 = DA.GetData(2, ref stepbackstr); bool t1 = DA.GetData(3, ref htstr); if (!DA.GetData(4, ref minAr)) { return; } string[] stepbackArr = stepbackstr.Split(','); for (int i = 0; i < stepbackArr.Length; i++) { double x = Convert.ToDouble(stepbackArr[i]); stepbackLi.Add(x); } string[] htArr = htstr.Split(','); for (int i = 0; i < htArr.Length; i++) { double x = Convert.ToDouble(htArr[i]); htLi.Add(x); } List <string> flrReqLi = new List <string>(); List <Brep> brepLi = new List <Brep>(); List <Curve> flrCrvLi = new List <Curve>(); double spineht = 0.0; double flrItr = 0.0; // continuous ht counter for floors try { for (int i = 0; i < stepbackLi.Count; i++) { Curve c0_ = siteCrv.DuplicateCurve(); Curve c0 = Rhino.Geometry.Curve.ProjectToPlane(c0_, Plane.WorldXY); double got_ar = AreaMassProperties.Compute(c0).Area; if (got_ar < minAr) { continue; } // this curve has less area than min specs Point3d cen = AreaMassProperties.Compute(c0).Centroid; double di = stepbackLi[i]; if (i > 0 && stepbackLi[i] < stepbackLi[i - 1]) { stepbackLi[i - 1] += 1; } Curve[] c1 = c0.Offset(cen, Vector3d.ZAxis, di, 0.01, CurveOffsetCornerStyle.Sharp); Curve c2_ = null; Curve c2 = null; if (c1.Length != 1) { c2 = c0; } else { c2_ = c1[0].DuplicateCurve(); c2 = Curve.ProjectToPlane(c2_, Plane.WorldXY); } double ht = htLi[i]; if (ht == 0) { continue; } double numFlrs = ht / flrHt; for (int j = 0; j < numFlrs; j++) { Curve c3 = c2.DuplicateCurve(); Rhino.Geometry.Transform xform_itr = Rhino.Geometry.Transform.Translation(0, 0, flrItr); c3.Transform(xform_itr); flrCrvLi.Add(c3); flrItr += flrHt; } flrReqLi.Add(numFlrs.ToString()); Extrusion mass = Rhino.Geometry.Extrusion.Create(c2, ht, true); // var B = mass.GetBoundingBox(true); if (B.Max.Z < 0.01) { mass = Extrusion.Create(c2, -ht, true); // } Brep brep = mass.ToBrep(); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, spineht); brep.Transform(xform); brepLi.Add(brep); spineht += ht; } DA.SetDataList(0, flrCrvLi); DA.SetDataList(1, brepLi); } catch (Exception) { } double grossFlrAr = 0.0; for (int i = 0; i < flrCrvLi.Count; i++) { grossFlrAr += AreaMassProperties.Compute(flrCrvLi[i]).Area; } double siteAr = AreaMassProperties.Compute(siteCrv).Area; double gotfsr = grossFlrAr / siteAr; outputMsg = "Gross Floor Area = " + Math.Round(grossFlrAr, 2).ToString() + ", Got fsr / far = " + Math.Round(gotfsr, 2).ToString(); DA.SetData(2, outputMsg); DA.SetDataList(3, flrReqLi); }
private static void CreateFinGeometry(RhinoDoc doc, double parentRadius, double xStart, double xEnd, ref Result result, int count, PositionType positionType, double position, double cant, double thickness, double rootChord, double tabHeight, ref double tabLength, RelativePositionType tabPositionType, List <Point3d> points) { if (tabHeight * tabLength > 0) { List <Point3d> tabPts = new List <Point3d>(); // add points from aft end of fin. double remainingLength = rootChord - tabLength; if (remainingLength < 0) { tabLength = rootChord; remainingLength = 0; } switch (tabPositionType) { case RelativePositionType.Front: tabPts.Add(new Point3d(points[0].X + tabLength, 0, 0)); tabPts.Add(new Point3d(points[0].X + tabLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X, 0, 0)); break; case RelativePositionType.Center: remainingLength /= 2; tabPts.Add(new Point3d(points[0].X + tabLength + remainingLength, 0, 0)); tabPts.Add(new Point3d(points[0].X + tabLength + remainingLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, 0, 0)); tabPts.Add(new Point3d(points[0].X, 0, 0)); break; case RelativePositionType.End: tabPts.Add(new Point3d(points[0].X + tabLength, 0, 0)); tabPts.Add(new Point3d(points[0].X + tabLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, 0, 0)); break; } points.AddRange(tabPts); } Brep brep = null; Polyline curve = new Polyline(points); double xLoc = 0; switch (positionType) { case PositionType.Top: xLoc = xStart + position; break; case PositionType.Bottom: xLoc = xEnd - rootChord + position; break; case PositionType.Middle: xLoc = (xEnd - xStart) / 2 + position; break; case PositionType.After: xLoc = xEnd + position; break; case PositionType.Absolute: xLoc = position; break; } List <Brep> breps = new List <Brep>(); if (curve.IsClosed) { Extrusion ext = Extrusion.Create(curve.ToNurbsCurve(), thickness, true); brep = ext.ToBrep(); Transform trans = Transform.Translation(new Vector3d(0, parentRadius, thickness / 2)); brep.Transform(trans); trans = Transform.Rotation(cant * Math.PI / 180.0, Vector3d.YAxis, new Point3d(rootChord / 2, 0, 0)); brep.Transform(trans); trans = Transform.Translation(new Vector3d(xLoc, 0, 0)); brep.Transform(trans); breps.Add(brep); double deltaAng = 360 / count; for (int i = 1; i < count; i++) { Transform copyTrans = Transform.Rotation(i * deltaAng * Math.PI / 180.0, Vector3d.XAxis, new Point3d(0, 0, 0)); Brep newBrep = brep.DuplicateBrep(); newBrep.Transform(copyTrans); breps.Add(newBrep); } foreach (Brep brp in breps) { if (doc.Objects.AddBrep(brp) != Guid.Empty) { result = Rhino.Commands.Result.Success; } } doc.Views.Redraw(); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { ///Gather GHA inputs Curve boundary = null; DA.GetData <Curve>(0, ref boundary); string osmFilePath = string.Empty; DA.GetData <string>("OSM Data Location", ref osmFilePath); //string userSRStext = "WGS84"; //DA.GetData<string>(2, ref userSRStext); List <string> filterWords = new List <string>(); DA.GetDataList <string>(2, filterWords); List <string> filterKeyValue = new List <string>(); DA.GetDataList <string>(3, filterKeyValue); Transform xformToMetric = new Transform(scaleToMetric); Transform xformFromMetric = new Transform(scaleFromMetric); ///Declare trees Rectangle3d recs = new Rectangle3d(); GH_Structure <GH_String> fieldNames = new GH_Structure <GH_String>(); GH_Structure <GH_String> fieldValues = new GH_Structure <GH_String>(); GH_Structure <IGH_GeometricGoo> geometryGoo = new GH_Structure <IGH_GeometricGoo>(); GH_Structure <IGH_GeometricGoo> buildingGoo = new GH_Structure <IGH_GeometricGoo>(); Point3d max = new Point3d(); Point3d min = new Point3d(); if (boundary != null) { Point3d maxM = boundary.GetBoundingBox(true).Corner(true, false, true); max = Heron.Convert.XYZToWGS(maxM); Point3d minM = boundary.GetBoundingBox(true).Corner(false, true, true); min = Heron.Convert.XYZToWGS(minM); } /// get extents (why is this not part of OsmSharp?) System.Xml.Linq.XDocument xdoc = System.Xml.Linq.XDocument.Load(osmFilePath); if (xdoc.Root.Element("bounds") != null) { double minlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlat").Value); double minlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlon").Value); double maxlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlat").Value); double maxlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlon").Value); Point3d boundsMin = Heron.Convert.WGSToXYZ(new Point3d(minlon, minlat, 0)); Point3d boundsMax = Heron.Convert.WGSToXYZ(new Point3d(maxlon, maxlat, 0)); recs = new Rectangle3d(Plane.WorldXY, boundsMin, boundsMax); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Cannot determine the extents of the OSM file. A 'bounds' element may not be present in the file. " + "Try turning off clipping in this component's menu."); } using (var fileStreamSource = File.OpenRead(osmFilePath)) { /// create a source. OsmSharp.Streams.XmlOsmStreamSource source = new OsmSharp.Streams.XmlOsmStreamSource(fileStreamSource); /// filter by bounding box OsmSharp.Streams.OsmStreamSource sourceClipped = source; if (clipped) { sourceClipped = source.FilterBox((float)max.X, (float)max.Y, (float)min.X, (float)min.Y, true); } /// create a dictionary of elements OsmSharp.Db.Impl.MemorySnapshotDb sourceMem = new OsmSharp.Db.Impl.MemorySnapshotDb(sourceClipped); /// filter the source var filtered = from osmGeos in sourceClipped where osmGeos.Tags != null select osmGeos; if (filterWords.Any()) { filtered = from osmGeos in filtered where osmGeos.Tags.ContainsAnyKey(filterWords) select osmGeos; } if (filterKeyValue.Any()) { List <Tag> tags = new List <Tag>(); foreach (string term in filterKeyValue) { string[] kv = term.Split(','); Tag tag = new Tag(kv[0], kv[1]); tags.Add(tag); } filtered = from osmGeos in filtered where osmGeos.Tags.Intersect(tags).Any() select osmGeos; } source.Dispose(); /// loop over all objects and count them. int nodes = 0, ways = 0, relations = 0; Dictionary <PolylineCurve, GH_Path> bldgOutlines = new Dictionary <PolylineCurve, GH_Path>(); List <BuildingPart> buildingParts = new List <BuildingPart>(); foreach (OsmSharp.OsmGeo osmGeo in filtered) { //NODES if (osmGeo.Type == OsmGeoType.Node) { OsmSharp.Node n = (OsmSharp.Node)osmGeo; GH_Path nodesPath = new GH_Path(0, nodes); //populate Fields and Values for each node fieldNames.AppendRange(GetKeys(osmGeo), nodesPath); fieldValues.AppendRange(GetValues(osmGeo), nodesPath); //get geometry for node Point3d nPoint = Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0)); geometryGoo.Append(new GH_Point(nPoint), nodesPath); //increment nodes nodes++; } //////////////////////////////////////////////////////////// //WAYS if (osmGeo.Type == OsmGeoType.Way) { OsmSharp.Way w = (OsmSharp.Way)osmGeo; GH_Path waysPath = new GH_Path(1, ways); //populate Fields and Values for each way fieldNames.AppendRange(GetKeys(osmGeo), waysPath); fieldValues.AppendRange(GetValues(osmGeo), waysPath); //get polyline geometry for way List <Point3d> wayNodes = new List <Point3d>(); foreach (long j in w.Nodes) { OsmSharp.Node n = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, j); wayNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0))); } PolylineCurve pL = new PolylineCurve(wayNodes); if (pL.IsClosed) { //create base surface Brep[] breps = Brep.CreatePlanarBreps(pL, DocumentTolerance()); geometryGoo.Append(new GH_Brep(breps[0]), waysPath); } else { geometryGoo.Append(new GH_Curve(pL), waysPath); } //building massing if ((w.Tags.ContainsKey("building") || w.Tags.ContainsKey("building:part")))// && !w.Tags.ContainsKey("construction")) { if (pL.IsClosed) { ///Populate dictionary for sorting building parts later if (w.Tags.ContainsKey("building")) { bldgOutlines.Add(pL, waysPath); } CurveOrientation orient = pL.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { pL.Reverse(); } ///Move polylines to min height double minHeightWay = GetMinBldgHeight(osmGeo); Vector3d minVec = new Vector3d(0, 0, minHeightWay); //minVec.Transform(xformFromMetric); if (minHeightWay > 0.0) { var minHeightTranslate = Transform.Translation(minVec); pL.Transform(minHeightTranslate); } Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo) - minHeightWay); //hVec.Transform(xformFromMetric); Extrusion ex = Extrusion.Create(pL, hVec.Z, true); IGH_GeometricGoo bldgGoo = GH_Convert.ToGeometricGoo(ex); ///Save building parts for sorting later and remove part from geometry goo tree if (w.Tags.ContainsKey("building:part")) { BuildingPart bldgPart = new BuildingPart(pL, bldgGoo, fieldNames[waysPath], fieldValues[waysPath], osmGeo); buildingParts.Add(bldgPart); fieldNames.RemovePath(waysPath); fieldValues.RemovePath(waysPath); geometryGoo.RemovePath(waysPath); ways = ways - 1; } else { buildingGoo.Append(bldgGoo, waysPath); } } } //increment ways ways++; } /////////////////////////////////////////////////////////// //RELATIONS if (osmGeo.Type == OsmGeoType.Relation) { OsmSharp.Relation r = (OsmSharp.Relation)osmGeo; GH_Path relationPath = new GH_Path(2, relations); //populate Fields and Values for each relation fieldNames.AppendRange(GetKeys(osmGeo), relationPath); fieldValues.AppendRange(GetValues(osmGeo), relationPath); List <Curve> pLines = new List <Curve>(); // start members loop for (int mem = 0; mem < r.Members.Length; mem++) { GH_Path memberPath = new GH_Path(2, relations, mem); OsmSharp.RelationMember rMem = r.Members[mem]; OsmSharp.OsmGeo rMemGeo = sourceMem.Get(rMem.Type, rMem.Id); if (rMemGeo != null) { //get geometry for node if (rMemGeo.Type == OsmGeoType.Node) { long memNodeId = rMem.Id; OsmSharp.Node memN = (OsmSharp.Node)sourceMem.Get(rMem.Type, rMem.Id); Point3d memPoint = Heron.Convert.WGSToXYZ(new Point3d((double)memN.Longitude, (double)memN.Latitude, 0)); geometryGoo.Append(new GH_Point(memPoint), memberPath); } //get geometry for way if (rMem.Type == OsmGeoType.Way) { long memWayId = rMem.Id; OsmSharp.Way memWay = (OsmSharp.Way)rMemGeo; //get polyline geometry for way List <Point3d> memNodes = new List <Point3d>(); foreach (long memNodeId in memWay.Nodes) { OsmSharp.Node memNode = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, memNodeId); memNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)memNode.Longitude, (double)memNode.Latitude, 0))); } PolylineCurve memPolyline = new PolylineCurve(memNodes); geometryGoo.Append(new GH_Curve(memPolyline.ToNurbsCurve()), memberPath); CurveOrientation orient = memPolyline.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { memPolyline.Reverse(); } pLines.Add(memPolyline.ToNurbsCurve()); } //get nested relations if (rMem.Type == OsmGeoType.Relation) { ///not sure if this is needed } } } //end members loop bool allClosed = true; foreach (Curve pc in pLines) { if (!pc.IsClosed) { allClosed = false; } } if (pLines.Count > 0 && allClosed) { ///Move polylines to min height double minHeight = GetMinBldgHeight(osmGeo); if (minHeight > 0.0) { Vector3d minVec = new Vector3d(0, 0, minHeight); //minVec.Transform(xformFromMetric); var minHeightTranslate = Transform.Translation(minVec); for (int i = 0; i < pLines.Count; i++) { pLines[i].Transform(minHeightTranslate); } } ///Create base surface Brep[] breps = Brep.CreatePlanarBreps(pLines, DocumentTolerance()); geometryGoo.RemovePath(relationPath); foreach (Brep b in breps) { geometryGoo.Append(new GH_Brep(b), relationPath); ///Building massing if (r.Tags.ContainsKey("building") || r.Tags.ContainsKey("building:part")) { Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo) - minHeight); //hVec.Transform(xformFromMetric); ///Create extrusion from base surface buildingGoo.Append(new GH_Brep(Brep.CreateFromOffsetFace(b.Faces[0], hVec.Z, DocumentTolerance(), false, true)), relationPath); } } } ///Increment relations relations++; } ///End relation loop } ///End filtered loop ///Add building parts to sub-branches under main building for (int partIndex = 0; partIndex < buildingParts.Count; partIndex++) { BuildingPart bldgPart = buildingParts[partIndex]; Point3d partPoint = bldgPart.PartFootprint.PointAtStart; partPoint.Z = 0; bool replaceBuidingMass = false; GH_Path mainBuildingMassPath = new GH_Path(); PolylineCurve massOutline = new PolylineCurve(); bool isRoof = bldgPart.PartOsmGeo.Tags.TryGetValue("roof:shape", out string isRoofString); if (isRoof) { bldgPart.PartGoo = BldgPartToRoof(bldgPart); } foreach (KeyValuePair <PolylineCurve, GH_Path> pair in bldgOutlines) { PointContainment pc = pair.Key.Contains(partPoint, Plane.WorldXY, DocumentTolerance()); if (pc != PointContainment.Outside) { ///Create new sub-branch int numSubBranches = 0; GH_Path partPath = pair.Value.AppendElement(numSubBranches); while (buildingGoo.PathExists(partPath)) { numSubBranches++; partPath = pair.Value.AppendElement(numSubBranches); } ///Add data to sub-branch fieldNames.AppendRange(bldgPart.PartFieldNames, partPath); fieldValues.AppendRange(bldgPart.PartFieldValues, partPath); buildingGoo.Append(bldgPart.PartGoo, partPath); ///Remove the main building mass replaceBuidingMass = true; mainBuildingMassPath = pair.Value; massOutline = pair.Key; } } ///Remove the main building mass if (replaceBuidingMass) { buildingGoo.RemovePath(mainBuildingMassPath); buildingGoo.Append(new GH_Curve(massOutline), mainBuildingMassPath); } else { GH_Path extrasPath = new GH_Path(3, partIndex); buildingGoo.Append(bldgPart.PartGoo, extrasPath); fieldNames.AppendRange(bldgPart.PartFieldNames, extrasPath); fieldValues.AppendRange(bldgPart.PartFieldValues, extrasPath); } } } ///end osm source loop if (recs.IsValid) { DA.SetData(0, recs); } DA.SetDataTree(1, fieldNames); DA.SetDataTree(2, fieldValues); DA.SetDataTree(3, geometryGoo); DA.SetDataTree(4, buildingGoo); } ///end SolveInstance
public List <Brep> Compute() { globalBaseCrvLi = new List <Curve>(); // global parameter globalTowerCrvLi = new List <Curve>(); // global parameter globalPtCrvLi = new List <Point3d>(); double[] p = c2.DivideByCount(numDiv, true); List <Point3d> ptLi = new List <Point3d>(); // points on the site boundary for (int i = 0; i < p.Length; i++) { Point3d pts = c2.PointAt(p[i]); ptLi.Add(pts); globalPtCrvLi.Add(pts); } // GENERATE NORMALS FROM THE POINT - SCALE=SETBACK DISTANCE List <LineCurve> lineLi = new List <LineCurve>(); for (int i = 0; i < ptLi.Count; i++) { Point3d P = Point3d.Unset; Point3d Q = Point3d.Unset; if (i == 0) { P = ptLi[ptLi.Count - 1]; Q = ptLi[0]; } else { P = ptLi[i - 1]; Q = ptLi[i]; } double sc = 1 / P.DistanceTo(Q); double sc2 = OFFSET_INP; double dx = P.X - (Q.Y - P.Y) * sc; double dy = P.Y + (Q.X - P.X) * sc; Point3d u = new Point3d(dx, dy, 0); double dx2 = P.X - (Q.Y - P.Y) * sc * sc2; double dy2 = P.Y + (Q.X - P.X) * sc * sc2; double ex2 = P.X + (Q.Y - P.Y) * sc * sc2; double ey2 = P.Y - (Q.X - P.X) * sc * sc2; Point3d u2 = new Point3d(dx2, dy2, 0); Point3d v2 = new Point3d(ex2, ey2, 0); Rhino.Geometry.PointContainment contU = c2.Contains(u, Plane.WorldXY, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); if (contU.ToString() == "Inside") { LineCurve linePu = new LineCurve(P, u2); lineLi.Add(linePu); } else { LineCurve linePu = new LineCurve(P, v2); lineLi.Add(linePu); } } // FIND INTX - NORMAL x SETBACK CURVE; REMOVE OTHER NORMALS List <LineCurve> fLineLi = new List <LineCurve>(); for (int i = 0; i < lineLi.Count; i++) { double t = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; var evt = Rhino.Geometry.Intersect.Intersection.CurveCurve(OFFSET_CRV, lineLi[i], t, t); try { Point3d A = lineLi[i].PointAtStart; Point3d pA = evt[0].PointA; LineCurve line = new LineCurve(A, pA); fLineLi.Add(line); } catch (Exception) { } } // JOIN ADJACENT NORMAL SEGMENTS TO FORM POLYGONS // 1st point is point on site, 2nd = normal @ setback dist List <PolylineCurve> polyCrvLi = new List <PolylineCurve>(); for (int i = 0; i < lineLi.Count; i++) { if (i == 0) { LineCurve A = lineLi[lineLi.Count - 1]; LineCurve B = lineLi[0]; Point3d a0 = A.PointAtStart; Point3d a1 = A.PointAtEnd; Point3d b0 = B.PointAtStart; Point3d b1 = B.PointAtEnd; Point3d[] pts = { a0, b0, b1, a1, a0 }; PolylineCurve poly = new PolylineCurve(pts); double ar2 = AreaMassProperties.Compute(poly).Area; if (ar2 > minTowerAr) { polyCrvLi.Add(poly); } //polyCrvLi.Add(poly); } else { LineCurve A = lineLi[i - 1]; LineCurve B = lineLi[i]; Point3d a0 = A.PointAtStart; Point3d a1 = A.PointAtEnd; Point3d b0 = B.PointAtStart; Point3d b1 = B.PointAtEnd; Point3d[] pts = { a0, b0, b1, a1, a0 }; PolylineCurve poly = new PolylineCurve(pts); double ar2 = AreaMassProperties.Compute(poly).Area; if (ar2 > minTowerAr) { polyCrvLi.Add(poly); } //polyCrvLi.Add(poly); } } double baseExtrHt = 0.0; double spineHt = 0.0; List <Brep> fbrepLi = new List <Brep>(); try { // BASE PROCESSES= EXTRUSION & COPY double c2Area = AreaMassProperties.Compute(c2).Area; double offsetArea = AreaMassProperties.Compute(OFFSET_CRV).Area; double flrAr = c2Area - offsetArea; int numFlrs2 = (int)(SITE_AR * baseFsr / flrAr) + 1; baseExtrHt = numFlrs2 * flrHt; for (int i = 0; i < numFlrs2; i++) { Curve c2_copy = c2.DuplicateCurve(); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, spineHt); c2_copy.Transform(xform); Curve OFFSET_CRV_copy = OFFSET_CRV.DuplicateCurve(); OFFSET_CRV_copy.Transform(xform); spineHt += flrHt; globalBaseCrvLi.Add(c2_copy); globalBaseCrvLi.Add(OFFSET_CRV_copy); } // base extrusions Extrusion outerExtr = Rhino.Geometry.Extrusion.Create(c2, baseExtrHt, true); var t0 = outerExtr.GetBoundingBox(true); if (t0.Max.Z <= 0) { outerExtr = Rhino.Geometry.Extrusion.Create(c2, baseExtrHt, true); } Brep outerBrep = outerExtr.ToBrep(); Extrusion innerExtr = Rhino.Geometry.Extrusion.Create(OFFSET_CRV, -baseExtrHt, true); var t1 = innerExtr.GetBoundingBox(true); if (t1.Max.Z <= 0) { innerExtr = Rhino.Geometry.Extrusion.Create(OFFSET_CRV, baseExtrHt, true); } Brep innerBrep = innerExtr.ToBrep(); Brep[] netBrepArr = Brep.CreateBooleanDifference(outerBrep, innerBrep, 0.01); Brep netBrep = netBrepArr[0]; fbrepLi.Add(netBrep); } catch (Exception) { } // Tower POLY FOR THE TOWERS List <Curve> towerPolyLi = new List <Curve>(); List <PolylineCurve> fPolyLi = new List <PolylineCurve>(); int numSel = numTowers; double cumuArPoly = 0.0; for (int i = 0; i < numSel; i++) { int idx = rnd.Next(polyCrvLi.Count); fPolyLi.Add(polyCrvLi[idx]); cumuArPoly += AreaMassProperties.Compute(polyCrvLi[idx]).Area; } // Tower POLY EXTRUSION double towerHtReq = SITE_AR * towerFsr / cumuArPoly; for (int i = 0; i < fPolyLi.Count; i++) { PolylineCurve crv = fPolyLi[i]; Extrusion extr0 = Extrusion.Create(crv, -towerHtReq * flrHt, true); var t0 = extr0.GetBoundingBox(true); if (t0.Max.Z <= 0) { extr0 = Extrusion.Create(crv, towerHtReq * flrHt, true); } Brep brep = extr0.ToBrep(); Transform xform = Rhino.Geometry.Transform.Translation(0, 0, baseExtrHt); brep.Transform(xform); fbrepLi.Add(brep); } // Tower POLY FLOOR COPIES // spineHt initialized above & updated from base curve copies int numFlrs = (int)(SITE_AR * towerFsr / cumuArPoly) + 1; for (int i = 0; i < numFlrs; i++) { for (int j = 0; j < fPolyLi.Count; j++) { Curve crv = fPolyLi[j].DuplicateCurve(); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, spineHt); crv.Transform(xform); globalTowerCrvLi.Add(crv); } spineHt += flrHt; } return(fbrepLi); }
public static void Make3d(string schemeName) { string inputLayerPath = schemeName + "::EJLT Shapes"; string outputLayerPath = schemeName + "::Walls"; string doorsLayerPath = schemeName + "::Doors"; List <int> layerIndexs; List <Curve> curves = LayerHelper.GetCurvesFromChild(inputLayerPath, out layerIndexs); List <Curve> doors = LayerHelper.GetCurvesFrom(doorsLayerPath); List <LineCurve> afterCut = new List <LineCurve>(); List <Line> exploded = new List <Line>(); foreach (Curve c in curves) { Polyline poly; c.TryGetPolyline(out poly); exploded.AddRange(poly.GetSegments()); } List <Line> lineSegDoor = new List <Line>(); List <List <LineCurve> > doorsPerSeg = new List <List <LineCurve> >(); foreach (Line lineSeg in exploded) { List <LineCurve> doorsThisSeg = new List <LineCurve>(); foreach (Curve door in doors) { CurveIntersections inter = Intersection.CurveLine(door, lineSeg, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, 0.0); if (inter.Count == 2) { LineCurve l1; Point3d p1 = inter.First().PointA; Point3d p2 = inter[1].PointA; l1 = new LineCurve(p1, p2); doorsThisSeg.Add(l1); } } if (doorsThisSeg.Count > 0) { lineSegDoor.Add(lineSeg); doorsPerSeg.Add(doorsThisSeg); } else { // no intersection, add to after cut afterCut.Add(new LineCurve(lineSeg)); } } for (int i = 0; i < lineSegDoor.Count; i++) { // points from all intersection points List <Point3d> intersectionPts = new List <Point3d>(); intersectionPts.Add(lineSegDoor[i].From); intersectionPts.Add(lineSegDoor[i].To); foreach (LineCurve doorLine in doorsPerSeg[i]) { intersectionPts.Add(doorLine.PointAtStart); intersectionPts.Add(doorLine.PointAtEnd); } List <Point3d> sortedPoints = intersectionPts.OrderBy(pnt => pnt.Y).ThenBy(pnt => pnt.X).ToList(); // construct line segments for (int pi = 0; pi < sortedPoints.Count; pi = pi + 2) { LineCurve cuttedSegment = new LineCurve(sortedPoints[pi], sortedPoints[pi + 1]); bool indoor = false; foreach (Curve door in doors) { if (door.Contains(cuttedSegment.PointAt(0.5), Plane.WorldXY, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) == PointContainment.Inside) { indoor = true; break; } } if (!indoor) { afterCut.Add(cuttedSegment); } } } UnitSystem currentDocUnits = RhinoDoc.ActiveDoc.ModelUnitSystem; double unitSystemScaler = RhinoMath.UnitScale(UnitSystem.Feet, currentDocUnits); foreach (LineCurve wallLine in afterCut) { LayerHelper.BakeObjectToLayer(Extrusion.Create(wallLine, 8 * unitSystemScaler, false).ToBrep(), "Walls", schemeName); } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
public override Brep ToBrep() { return(Extrusion.Create(Outline, Depth, true).ToBrep()); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { ///Gather GHA inputs Curve boundary = null; DA.GetData <Curve>(0, ref boundary); string osmFilePath = string.Empty; DA.GetData <string>("OSM Data Location", ref osmFilePath); //string userSRStext = "WGS84"; //DA.GetData<string>(2, ref userSRStext); List <string> filterWords = new List <string>(); DA.GetDataList <string>(2, filterWords); List <string> filterKeyValue = new List <string>(); DA.GetDataList <string>(3, filterKeyValue); Transform xformToMetric = new Transform(Rhino.RhinoMath.UnitScale(RhinoDoc.ActiveDoc.ModelUnitSystem, Rhino.UnitSystem.Meters)); Transform xformFromMetric = new Transform(Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Meters, RhinoDoc.ActiveDoc.ModelUnitSystem)); ///Declare trees Rectangle3d recs = new Rectangle3d(); GH_Structure <GH_String> fieldNames = new GH_Structure <GH_String>(); GH_Structure <GH_String> fieldValues = new GH_Structure <GH_String>(); GH_Structure <IGH_GeometricGoo> geometryGoo = new GH_Structure <IGH_GeometricGoo>(); GH_Structure <IGH_GeometricGoo> buildingGoo = new GH_Structure <IGH_GeometricGoo>(); Point3d max = new Point3d(); Point3d min = new Point3d(); if (boundary != null) { Point3d maxM = boundary.GetBoundingBox(true).Corner(true, false, true); max = Heron.Convert.XYZToWGS(maxM); Point3d minM = boundary.GetBoundingBox(true).Corner(false, true, true); min = Heron.Convert.XYZToWGS(minM); } /// get extents (why is this not part of OsmSharp?) System.Xml.Linq.XDocument xdoc = System.Xml.Linq.XDocument.Load(osmFilePath); if (xdoc.Root.Element("bounds") != null) { double minlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlat").Value); double minlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("minlon").Value); double maxlat = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlat").Value); double maxlon = System.Convert.ToDouble(xdoc.Root.Element("bounds").Attribute("maxlon").Value); Point3d boundsMin = Heron.Convert.WGSToXYZ(new Point3d(minlon, minlat, 0)); Point3d boundsMax = Heron.Convert.WGSToXYZ(new Point3d(maxlon, maxlat, 0)); recs = new Rectangle3d(Plane.WorldXY, boundsMin, boundsMax); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Cannot determine the extents of the OSM file. A 'bounds' element may not be present in the file."); } using (var fileStreamSource = File.OpenRead(osmFilePath)) { /// create a source. OsmSharp.Streams.XmlOsmStreamSource source = new OsmSharp.Streams.XmlOsmStreamSource(fileStreamSource); /// filter by bounding box OsmSharp.Streams.OsmStreamSource sourceClipped = source; if (clipped) { sourceClipped = source.FilterBox((float)max.X, (float)max.Y, (float)min.X, (float)min.Y, true); } /// create a dictionary of elements OsmSharp.Db.Impl.MemorySnapshotDb sourceMem = new OsmSharp.Db.Impl.MemorySnapshotDb(sourceClipped); /// filter the source var filtered = from osmGeos in sourceClipped where osmGeos.Tags != null select osmGeos; if (filterWords.Any()) { filtered = from osmGeos in filtered where osmGeos.Tags.ContainsAnyKey(filterWords) select osmGeos; } if (filterKeyValue.Any()) { List <Tag> tags = new List <Tag>(); foreach (string term in filterKeyValue) { string[] kv = term.Split(','); Tag tag = new Tag(kv[0], kv[1]); tags.Add(tag); } filtered = from osmGeos in filtered where osmGeos.Tags.Intersect(tags).Any() select osmGeos; } source.Dispose(); /// loop over all objects and count them. int nodes = 0, ways = 0, relations = 0; foreach (OsmSharp.OsmGeo osmGeo in filtered) { //NODES if (osmGeo.Type == OsmGeoType.Node) { OsmSharp.Node n = (OsmSharp.Node)osmGeo; GH_Path nodesPath = new GH_Path(0, nodes); //populate Fields and Values for each node fieldNames.AppendRange(GetKeys(osmGeo), nodesPath); fieldValues.AppendRange(GetValues(osmGeo), nodesPath); //get geometry for node Point3d nPoint = Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0)); geometryGoo.Append(new GH_Point(nPoint), nodesPath); //increment nodes nodes++; } //////////////////////////////////////////////////////////// //WAYS if (osmGeo.Type == OsmGeoType.Way) { OsmSharp.Way w = (OsmSharp.Way)osmGeo; GH_Path waysPath = new GH_Path(1, ways); //populate Fields and Values for each way fieldNames.AppendRange(GetKeys(osmGeo), waysPath); fieldValues.AppendRange(GetValues(osmGeo), waysPath); //get polyline geometry for way List <Point3d> wayNodes = new List <Point3d>(); foreach (long j in w.Nodes) { OsmSharp.Node n = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, j); wayNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)n.Longitude, (double)n.Latitude, 0))); } PolylineCurve pL = new PolylineCurve(wayNodes); if (pL.IsClosed) { //create base surface Brep[] breps = Brep.CreatePlanarBreps(pL, DocumentTolerance()); geometryGoo.Append(new GH_Brep(breps[0]), waysPath); } else { geometryGoo.Append(new GH_Curve(pL), waysPath); } //building massing if (w.Tags.ContainsKey("building") || w.Tags.ContainsKey("building:part")) { if (pL.IsClosed) { CurveOrientation orient = pL.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { pL.Reverse(); } Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo)); hVec.Transform(xformFromMetric); Extrusion ex = Extrusion.Create(pL, hVec.Z, true); IGH_GeometricGoo bldgGoo = GH_Convert.ToGeometricGoo(ex); buildingGoo.Append(bldgGoo, waysPath); } } //increment ways ways++; } /////////////////////////////////////////////////////////// //RELATIONS if (osmGeo.Type == OsmGeoType.Relation) { OsmSharp.Relation r = (OsmSharp.Relation)osmGeo; GH_Path relationPath = new GH_Path(2, relations); //populate Fields and Values for each relation fieldNames.AppendRange(GetKeys(osmGeo), relationPath); fieldValues.AppendRange(GetValues(osmGeo), relationPath); List <Curve> pLines = new List <Curve>(); // start members loop for (int mem = 0; mem < r.Members.Length; mem++) { GH_Path memberPath = new GH_Path(2, relations, mem); OsmSharp.RelationMember rMem = r.Members[mem]; OsmSharp.OsmGeo rMemGeo = sourceMem.Get(rMem.Type, rMem.Id); if (rMemGeo != null) { //get geometry for node if (rMemGeo.Type == OsmGeoType.Node) { long memNodeId = rMem.Id; OsmSharp.Node memN = (OsmSharp.Node)sourceMem.Get(rMem.Type, rMem.Id); Point3d memPoint = Heron.Convert.WGSToXYZ(new Point3d((double)memN.Longitude, (double)memN.Latitude, 0)); geometryGoo.Append(new GH_Point(memPoint), memberPath); } //get geometry for way if (rMem.Type == OsmGeoType.Way) { long memWayId = rMem.Id; OsmSharp.Way memWay = (OsmSharp.Way)rMemGeo; //get polyline geometry for way List <Point3d> memNodes = new List <Point3d>(); foreach (long memNodeId in memWay.Nodes) { OsmSharp.Node memNode = (OsmSharp.Node)sourceMem.Get(OsmGeoType.Node, memNodeId); memNodes.Add(Heron.Convert.WGSToXYZ(new Point3d((double)memNode.Longitude, (double)memNode.Latitude, 0))); } PolylineCurve memPolyline = new PolylineCurve(memNodes); geometryGoo.Append(new GH_Curve(memPolyline.ToNurbsCurve()), memberPath); CurveOrientation orient = memPolyline.ClosedCurveOrientation(Plane.WorldXY); if (orient != CurveOrientation.CounterClockwise) { memPolyline.Reverse(); } pLines.Add(memPolyline.ToNurbsCurve()); } //get nested relations if (rMem.Type == OsmGeoType.Relation) { ///not sure if this is needed } } } //end members loop bool allClosed = true; foreach (Curve pc in pLines) { if (!pc.IsClosed) { allClosed = false; } } if (pLines.Count > 0 && allClosed) { //create base surface Brep[] breps = Brep.CreatePlanarBreps(pLines, DocumentTolerance()); geometryGoo.RemovePath(relationPath); foreach (Brep b in breps) { geometryGoo.Append(new GH_Brep(b), relationPath); //building massing if (r.Tags.ContainsKey("building") || r.Tags.ContainsKey("building:part")) { Vector3d hVec = new Vector3d(0, 0, GetBldgHeight(osmGeo)); hVec.Transform(xformFromMetric); //create extrusion from base surface buildingGoo.Append(new GH_Brep(Brep.CreateFromOffsetFace(b.Faces[0], hVec.Z, DocumentTolerance(), false, true)), relationPath); } } } //increment relations relations++; } ///end relation loop } ///end filtered loop } ///end osm source loop if (recs.IsValid) { DA.SetData(0, recs); } DA.SetDataTree(1, fieldNames); DA.SetDataTree(2, fieldValues); DA.SetDataTree(3, geometryGoo); DA.SetDataTree(4, buildingGoo); } ///end SolveInstance
public void createBuliding(int inpPlotType) { Random bldHeights = new Random(); if (this.plotSrf.GetArea() < 50) { return(false); } if (inpPlotType > 0) { int minBldHeight = 0; int maxBldHeight = 3; if (inpPlotType == 1) { minBldHeight = 3; maxBldHeight = 9; } if (inpPlotType == 2) { minBldHeight = 18; maxBldHeight = 30; } if (inpPlotType == 3) { minBldHeight = 60; maxBldHeight = 150; } double actualBulidingHeight = this.bldHeights.Next(minBldHeight, maxBldHeight); System.Drawing.Color bldCol = System.Drawing.Color.White; if (actualBulidingHeight < 6) { ; } bldCol = System.Drawing.Color.FromArgb(168, 126, 198); else if (actualBulidingHeight < 12) { bldCol = System.Drawing.Color.FromArgb(255, 173, 194); } else if (actualBulidingHeight < 36) { bldCol = System.Drawing.Color.FromArgb(243, 104, 75); } else if (actualBulidingHeight < 92) { bldCol = System.Drawing.Color.FromArgb(225, 164, 24); } else if (actualBulidingHeight < 120) { bldCol = System.Drawing.Color.FromArgb(254, 255, 51); } ObjectAttributes oa = new ObjectAttributes oa.ColorSource = ObjectColorSource.ColorFromObjects; oa.ObjectColor = System.Drawing.Color.FromArgb() Curve border = Curve.JoinCurves(this.plotSrf.DuplicateNakedEdgeCurves(true, false))[0]; this.bulidingOutlines = Curve.JoinCurves(border.Offset(Plane.WorldXY, -5, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.None))[0]; this.buliding = Extrusion.Create(this.bulidingOutlines, actualBulidingHeight, true); RhinoDoc.ActiveDoc.Objects.AddExtrusion(this.buliding, oa); RhinoDoc.ActiveDoc.Objects.AddCurve(bulidingOutlines); }
protected override void SolveInstance(IGH_DataAccess DA) { List <Curve> sites = new List <Curve>(); double fsr = double.NaN; double setback = double.NaN; double flrHt = double.NaN; double minAr = double.NaN; double slendernessRatio = double.NaN; if (!DA.GetDataList(0, sites)) { return; } if (!DA.GetData(1, ref setback)) { return; } if (!DA.GetData(2, ref fsr)) { return; } if (!DA.GetData(3, ref flrHt)) { return; } if (!DA.GetData(4, ref minAr)) { return; } if (!DA.GetData(5, ref slendernessRatio)) { return; } List <Extrusion> massLi = new List <Extrusion>(); List <List <Curve> > listFlrCrvLi = new List <List <Curve> >(); List <Curve> flrCrvLi = new List <Curve>(); string msg = ""; msg += "\nfsr: " + fsr.ToString(); msg += "\nsetback: " + setback.ToString(); string MSG = "Debug BLOCK:\n"; for (int i = 0; i < sites.Count; i++) { //OFFSET FROM THE SITE BOUNDARY Curve c1 = sites[i].DuplicateCurve(); Curve c2 = Rhino.Geometry.Curve.ProjectToPlane(c1, Plane.WorldXY); Curve[] c2Offs; Point3d cen = AreaMassProperties.Compute(c2).Centroid; Rhino.Geometry.PointContainment cont = sites[i].Contains(cen, Plane.WorldXY, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); if (cont.ToString() == "Inside") { c2Offs = c2.Offset(cen, Vector3d.ZAxis, setback, 0.01, CurveOffsetCornerStyle.Sharp); } else { c2Offs = c2.Offset(cen, Vector3d.ZAxis, -setback, 0.01, CurveOffsetCornerStyle.Sharp); } try { if (c2Offs.Length == 1) { Curve OFFSET_CRV_ = c2Offs[0]; Curve OFFSET_CRV = Curve.ProjectToPlane(OFFSET_CRV_, Plane.WorldXY); double arSite = Rhino.Geometry.AreaMassProperties.Compute(sites[i]).Area; double arOffset = AreaMassProperties.Compute(OFFSET_CRV).Area; // 1 floor double num_flrs = fsr * arSite / arOffset; double ht = num_flrs * flrHt; double gotSlendernessRatio = ht / arOffset; if (gotSlendernessRatio < slendernessRatio) { msg += "\nExceeded slenderness ratio"; } else if (arOffset <= minAr) { msg += "\nar site: " + arSite.ToString() + "\nar offset: " + arOffset.ToString() + "\nht: " + ht.ToString(); } else { Vector3d vec = new Vector3d(0, 0, ht); Curve c3 = Rhino.Geometry.Curve.ProjectToPlane(OFFSET_CRV, Plane.WorldXY); Extrusion mass = Rhino.Geometry.Extrusion.Create(c3, ht, true); var B = mass.GetBoundingBox(true); MSG += "Z = " + B.Max.Z.ToString() + ", " + B.Min.Z.ToString(); if (B.Max.Z <= 0.01) { mass = Extrusion.Create(c3, -ht, true); } massLi.Add(mass); for (int j = 0; j < num_flrs; j++) { Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, j * flrHt); Curve c4 = c3.DuplicateCurve(); c4.Transform(xform); flrCrvLi.Add(c4); } } } } catch (Exception) { } //listFlrCrvLi.Add(flrCrvLi); } DA.SetDataList(0, massLi); DA.SetDataList(1, flrCrvLi); // DA.SetData(2, msg); // DA.SetData(3, MSG); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // 1 - Select a site curve GetObject obj = new GetObject(); obj.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; obj.SetCommandPrompt("Please select a curve representing your site"); GetResult res = obj.Get(); Curve site; if (res != GetResult.Object) { RhinoApp.WriteLine("The user did not select a curve"); return(Result.Failure); // Failed to get a curve } if (obj.ObjectCount == 1) { site = obj.Object(0).Curve(); } else { return(Result.Failure); //Failed to get a curve } // 2 - Extract the border from the precinct surface //Offset for Shop Curve[] offsets = site.Offset(Plane.WorldXY, -2.5, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.Chamfer); Curve[] joinedoffset = Curve.JoinCurves(offsets); //join offset curves //Offset for Apartment Curve[] offsetBst = site.Offset(Plane.WorldXY, -4, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.Chamfer); Curve[] joinedoffsetBst = Curve.JoinCurves(offsetBst); //join offset curves //Offset for Base Curve[] offsetTop = site.Offset(Plane.WorldXY, -3, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, CurveOffsetCornerStyle.Chamfer); Curve[] joinedoffsetTop = Curve.JoinCurves(offsetTop); //join offset curves //List of offset curves List <Curve> buildingsCrv = new List <Curve>(); buildingsCrv.AddRange(offsets); buildingsCrv.AddRange(offsetBst); buildingsCrv.AddRange(offsetTop); // 3 - Extrude all the offset curves //Extrusions Extrusion Shop = Extrusion.Create(buildingsCrv[0], 3.1, true); Extrusion Apa = Extrusion.Create(buildingsCrv[1], 18.6, true); Extrusion Base = Extrusion.Create(buildingsCrv[2], -3.1, true); //List of extrusions List <Extrusion> buildingsExt = new List <Extrusion>(); buildingsExt.Add(Shop); buildingsExt.Add(Apa); buildingsExt.Add(Base); //Draw all the extrusions foreach (Extrusion itExt in buildingsExt) { RhinoDoc.ActiveDoc.Objects.Add(itExt); } // 4 - Create contour lines on extrusions to represent floors //Define extrusions as Breps for contours Brep ShopBrep = Shop.ToBrep(); Brep BrepApa = Apa.ToBrep(); //List of Breps List <Brep> BuildingBreps = new List <Brep>(); BuildingBreps.Add(ShopBrep); BuildingBreps.Add(BrepApa); //Points to define contours Point3d start = new Point3d(0, 0, 0); Point3d end = new Point3d(0, 0, 30); //Contours Curve[] Shopflr = Brep.CreateContourCurves(ShopBrep as Brep, start, end, 3.1); Curve[] ApaFlr = Brep.CreateContourCurves(BrepApa as Brep, start, end, 3.1); //List of Contour Curves List <Curve> Floors = new List <Curve>(); Floors.AddRange(Shopflr); Floors.AddRange(ApaFlr); //Draw all the Contour curves foreach (Curve itCrv in Floors) { RhinoDoc.ActiveDoc.Objects.Add(itCrv); } RhinoDoc.ActiveDoc.Views.Redraw(); return(Result.Success); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { //Create class instances Curve centreCrv = new PolylineCurve(); int floors = 1; double thickness = 1; double levelHeight = 1; Rectangle3d garden = new Rectangle3d(); Point3d accessPt = new Point3d(); //Get Data if (!DA.GetData(0, ref centreCrv)) { return; } if (!DA.GetData(1, ref floors)) { return; } if (!DA.GetData(2, ref thickness)) { return; } if (!DA.GetData(3, ref levelHeight)) { return; } if (!DA.GetData(4, ref garden)) { return; } if (!DA.GetData(5, ref accessPt)) { return; } //Set properties PlotPlanning.ObjectModel.MultiFamily house = new ObjectModel.MultiFamily(); house.Floors = floors; house.Thickness = thickness; house.LevelHeight = levelHeight; house.GardenBound = garden.ToPolyline(); house.AccessPoint = accessPt; //Create geometry. Brep[] b = Engine.Geometry.Compute.Sweep(centreCrv, thickness, 2); //Get and join all brep edges Curve[] En = b[0].DuplicateNakedEdgeCurves(true, true); Curve[] bound = Curve.JoinCurves(En); // TODO: make sure all the bounding curves are clockwise. This is to ensure extrution in the correct diection // For now I used a neg sign before extrution height.... Extrusion ex = Extrusion.Create(bound[0], -levelHeight * floors, true); if (centreCrv.IsClosed) { //Sort profiles by length. The longer curve will be the outer profile. The shorter the inner. Curve innerCrv = bound.ToList().OrderBy(x => x.GetLength()).First(); Extrusion exInner = Extrusion.Create(innerCrv, levelHeight * floors, true); Brep[] diff = Brep.CreateBooleanDifference(ex.ToBrep(), exInner.ToBrep(), ObjectModel.Tolerance.Distance); house.HouseGeom = diff[0]; } else { house.HouseGeom = ex.ToBrep(); } //Set data DA.SetData(0, house); }
public static List <Brep> DrawHouse(Household hhp) { double height = Consts.FloorHeight; Curve outline = hhp.GetOutline(); Polyline outPoly = CurveTools.ToPolyline(outline); Brep x = Extrusion.Create(outline, height, true).ToBrep(); x.CapPlanarHoles(1); double windowSide = 300; double windowLow = 300; double windowHeight = 2100; double windowDepth = 200; List <Brep> wins = new List <Brep>(); for (int i = 0; i < hhp.LightingEdge.Count; i++) { //Rhino.RhinoDoc.ActiveDoc.Objects.Add(hhp.LightingEdge[i].ToNurbsCurve()); //var c = hhp.LightingEdge[i].ToNurbsCurve().Trim(CurveEnd.Both, 300); //var p1 = c.PointAtStart + Vector3d.ZAxis * 300; //var p2 = c.PointAtStart + Vector3d.ZAxis * 2400; //var p3 = c.PointAtEnd + Vector3d.ZAxis * 2400; //var p4 = c.PointAtEnd + Vector3d.ZAxis * 300; //Brep[] open = Brep.CreatePlanarBreps(new PolylineCurve(new Point3d[] { p1, p2, p3, p4, p1 })); Line tempLine = hhp.LightingEdge[i]; Point3d midPoint = tempLine.PointAt(0.5); Vector3d windowVec = tempLine.UnitTangent; windowVec.Rotate(Math.PI / 2, Vector3d.ZAxis); midPoint.Transform(Transform.Translation(Vector3d.Multiply(windowVec, 10))); if (hhp.GetOutline().Contains(midPoint) == Rhino.Geometry.PointContainment.Inside) { tempLine.Flip(); } tempLine.Extend(-windowSide, -windowSide); Curve tempCurve = tempLine.ToNurbsCurve(); tempCurve.Translate(Vector3d.Multiply(Vector3d.ZAxis, windowLow)); Point3d pt1 = tempCurve.PointAtStart; Point3d pt2 = tempCurve.PointAtEnd; Point3d pt3 = tempCurve.PointAtEnd; pt3.Transform(Transform.Translation(Vector3d.Multiply(Vector3d.ZAxis, windowHeight))); Point3d pt4 = tempCurve.PointAtStart; pt4.Transform(Transform.Translation(Vector3d.Multiply(Vector3d.ZAxis, windowHeight))); Point3d pt5 = tempCurve.PointAtStart; List <Point3d> windowPoints = new List <Point3d>(); windowPoints.Add(pt1); windowPoints.Add(pt2); windowPoints.Add(pt3); windowPoints.Add(pt4); windowPoints.Add(pt5); Polyline windowPolyline = new Polyline(windowPoints); Curve win = windowPolyline.ToNurbsCurve(); Plane windowPlane; win.TryGetPlane(out windowPlane); Vector3d windowNormal = windowPlane.Normal; Curve windowCurve = win.Duplicate() as Curve; windowCurve.Translate(Vector3d.Multiply(windowNormal, windowDepth)); Surface windowSurface = Surface.CreateExtrusion(windowCurve, Vector3d.Multiply(windowNormal, -windowDepth * 2)); Brep windowBrep = windowSurface.ToBrep(); Brep[] withHolesTemp = x.Split(windowBrep, 1); if (withHolesTemp.Length != 0) { x = withHolesTemp[0]; } Curve duplicatedWindowCurve = (win.Duplicate() as Curve); duplicatedWindowCurve.Transform(Transform.Translation(windowNormal * (windowDepth - 100))); Curve windowCurveBottom = duplicatedWindowCurve.DuplicateSegments()[0]; Curve heightCurve = duplicatedWindowCurve.DuplicateSegments()[1]; wins.AddRange(DrawWindowAll(windowCurveBottom, heightCurve.GetLength(), false)); Curve[] tempLoftBase = { win, duplicatedWindowCurve }; Curve pathCurve = new LineCurve(Point3d.Origin, new Point3d(windowNormal * (-windowDepth + 100))); wins.Add(Brep.JoinBreps(Brep.CreateFromLoft(tempLoftBase, Point3d.Unset, Point3d.Unset, LoftType.Normal, false), 0)[0]); } //1. 양쪽에서 300씩 , 위400 아래300 사각형.빵꾸. 안쪽으로 200 //->창틀 //2. 사방 30씩, 안쪽으로 100 //->창문와꾸 //3. 창 안쪽에서 20, 창문와꾸 30, 바깥쪽50 ,길이 1200 * 2 //4. ㅊ //Brep w1 = Brep.create hhp.LightingEdge[0] wins.Add(x); return(wins); }
protected override void SolveInstance(IGH_DataAccess DA) { Curve siteCrv = null; double fsr = double.NaN; double flrHt = double.NaN; double setback = double.NaN; double bayDepth = double.NaN; double slendernessRatio = double.NaN; if (!DA.GetData(0, ref siteCrv)) { return; } if (!DA.GetData(1, ref fsr)) { return; } if (!DA.GetData(2, ref flrHt)) { return; } if (!DA.GetData(3, ref setback)) { return; } if (!DA.GetData(4, ref bayDepth)) { return; } if (!DA.GetData(5, ref slendernessRatio)) { return; } Curve c0_ = siteCrv.DuplicateCurve(); Curve c0 = Curve.ProjectToPlane(c0_, Plane.WorldXY); Point3d cen = AreaMassProperties.Compute(c0).Centroid; Curve[] outerCrvArr = c0.Offset(cen, Vector3d.ZAxis, setback, 0.01, CurveOffsetCornerStyle.Sharp); Curve[] innerCrvArr = outerCrvArr[0].Offset(cen, Vector3d.ZAxis, bayDepth, 0.01, CurveOffsetCornerStyle.Sharp); string debugMsg = ""; try { if (innerCrvArr.Length != 1) { debugMsg += "\ninner crv error"; return; } if (outerCrvArr.Length != 1) { debugMsg += "\nouter crv error"; return; } double siteAr = AreaMassProperties.Compute(siteCrv).Area; double GFA = siteAr * fsr; double outerAr = AreaMassProperties.Compute(outerCrvArr[0]).Area; double innerAr = AreaMassProperties.Compute(innerCrvArr[0]).Area; double netAr = outerAr - innerAr; double numFlrs = GFA / netAr; double reqHt = numFlrs * flrHt; double gotSlendernessRatio = reqHt / netAr; if (gotSlendernessRatio < slendernessRatio) { return; } if (setback > 0 && bayDepth > 0 && flrHt > 0) { List <string> numFlrReqLi = new List <string>(); List <Curve> crvLi = new List <Curve>(); double flrCounter = 0.0; for (int i = 0; i < numFlrs; i++) { Curve c0crv = outerCrvArr[0].DuplicateCurve(); Curve c1crv = innerCrvArr[0].DuplicateCurve(); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(0, 0, flrCounter); c0crv.Transform(xform); c1crv.Transform(xform); crvLi.Add(c0crv); crvLi.Add(c1crv); flrCounter += flrHt; } numFlrReqLi.Add(flrCounter.ToString()); List <Brep> brepLi = new List <Brep>(); Extrusion outerMass = Rhino.Geometry.Extrusion.Create(outerCrvArr[0], reqHt, true); var B = outerMass.GetBoundingBox(true); if (B.Max.Z < 0.01) { outerMass = Extrusion.Create(outerCrvArr[0], -reqHt, true); } Brep outerBrep = outerMass.ToBrep(); Extrusion innerMass = Rhino.Geometry.Extrusion.Create(innerCrvArr[0], reqHt, true); var B2 = innerMass.GetBoundingBox(true); if (B2.Max.Z < 0.01) { innerMass = Extrusion.Create(innerCrvArr[0], -reqHt, true); } Brep innerBrep = innerMass.ToBrep(); Brep[] netBrep = Brep.CreateBooleanDifference(outerBrep, innerBrep, 0.1); try { brepLi.Add(netBrep[0]); } catch (Exception) { debugMsg += "Error in brep subtraction"; } DA.SetDataList(0, crvLi); DA.SetDataList(1, brepLi); } } catch (Exception) { debugMsg += "Error in system"; } // DA.SetDataList(2, debugMsg); }