Skip to content

Commit

Permalink
Merge pull request #224 from hrntsm/feature/support-wall-open
Browse files Browse the repository at this point in the history
Add Wall open support
  • Loading branch information
hrntsm authored Mar 21, 2022
2 parents 249e551 + 2d42a01 commit 8dc3f27
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
- name: Restore Tool
run: dotnet tool restore
- name: Lint
Expand Down
2 changes: 1 addition & 1 deletion HoaryFox/RH7/Component/Geometry/Stb2Brep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void CreateBrep()
_brepList[3] = brepFromStb.Beam(member.StbBeams);
_brepList[4] = brepFromStb.Brace(member.StbBraces);
_brepList[5] = brepFromStb.Slab(member.StbSlabs);
_brepList[6] = brepFromStb.Wall(member.StbWalls);
_brepList[6] = brepFromStb.Wall(member.StbWalls, member.StbOpens);
}

private void BakeBrep()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,7 @@ private GH_Brep CreateSlabBrep(double depth, IList<PolylineCurve> curveList, IEn
{
return NonPlanarBrep(depth, curveList);
}

if (capedBrep.SolidOrientation == BrepSolidOrientation.Inward)
{
capedBrep.Flip();
}
capedBrep.Faces.SplitKinkyFaces();
CheckBrepOrientation(capedBrep);

return new GH_Brep(capedBrep);
}
Expand Down Expand Up @@ -312,7 +307,7 @@ private GH_Brep NonPlanarBrep(double depth, IList<PolylineCurve> curveList)
return new GH_Brep(Brep.JoinBreps(nonPlanarBrep, _tolerance[0])[0] ?? topBrep);
}

public GH_Structure<GH_Brep> Wall(IEnumerable<StbWall> walls)
public GH_Structure<GH_Brep> Wall(IEnumerable<StbWall> walls, IEnumerable<StbOpen> opens)
{
var brepList = new GH_Structure<GH_Brep>();
if (walls == null)
Expand All @@ -326,7 +321,7 @@ public GH_Structure<GH_Brep> Wall(IEnumerable<StbWall> walls)
var curveList = new PolylineCurve[2];
double thickness = BrepMaker.Wall.GetThickness(_sections, wall);
string[] nodeIds = wall.StbNodeIdOrder.Split(' ');
var topPts = new List<Point3d>();
var wallPts = new List<Point3d>();
foreach (string nodeId in nodeIds)
{
var offsetVec = new Vector3d();
Expand All @@ -343,28 +338,83 @@ public GH_Structure<GH_Brep> Wall(IEnumerable<StbWall> walls)
}

StbNode node = _nodes.First(n => n.id == nodeId);
topPts.Add(new Point3d(node.X, node.Y, node.Z) + offsetVec);
wallPts.Add(new Point3d(node.X, node.Y, node.Z) + offsetVec);
}

topPts.Add(topPts[0]);
var centerCurve = new PolylineCurve(topPts);
wallPts.Add(wallPts[0]);
var centerCurve = new PolylineCurve(wallPts);
Vector3d normal = Vector3d.CrossProduct(centerCurve.TangentAtEnd, centerCurve.TangentAtStart);
curveList[0] = new PolylineCurve(topPts.Select(pt => pt + normal * thickness / 2));
curveList[1] = new PolylineCurve(topPts.Select(pt => pt - normal * thickness / 2));
curveList[0] = new PolylineCurve(wallPts.Select(pt => pt + normal * thickness / 2));
curveList[1] = new PolylineCurve(wallPts.Select(pt => pt - normal * thickness / 2));
Brep brep = Brep.CreateFromLoft(curveList, Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0].CapPlanarHoles(_tolerance[0]);
if (brep != null)
{
if (brep.SolidOrientation == BrepSolidOrientation.Inward)
{
brep.Flip();
}
brep.Faces.SplitKinkyFaces();
}
CheckBrepOrientation(brep);

brep = ApplyWallOpen(opens, wall, wallPts, brep);
brepList.Append(new GH_Brep(brep), new GH_Path(0, i));
}

return brepList;
}

private static void CheckBrepOrientation(Brep brep)
{
if (brep == null)
{
return;
}

if (brep.SolidOrientation == BrepSolidOrientation.Inward)
{
brep.Flip();
}
brep.Faces.SplitKinkyFaces();
}

private Brep ApplyWallOpen(IEnumerable<StbOpen> opens, StbWall wall, IReadOnlyList<Point3d> wallPts, Brep brep)
{
double thickness = BrepMaker.Wall.GetThickness(_sections, wall);
var centerCurve = new PolylineCurve(wallPts);
Vector3d normal = Vector3d.CrossProduct(centerCurve.TangentAtEnd, centerCurve.TangentAtStart);
var openIds = new List<string>();
if (wall.StbOpenIdList != null)
{
openIds.AddRange(wall.StbOpenIdList.Select(openId => openId.id));
foreach (string id in openIds)
{
StbOpen open = opens.First(o => o.id == id);
Point3d[] openCurvePts = GetOpenCurvePts(wallPts, open);
PolylineCurve[] openCurve = GetOpenCurve(thickness, normal, openCurvePts);
Brep openBrep = Brep.CreateFromLoft(openCurve, Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0].CapPlanarHoles(_tolerance[0]);
CheckBrepOrientation(openBrep);

brep = Brep.CreateBooleanDifference(brep, openBrep, 1)[0];
}
}

return brep;
}

private static PolylineCurve[] GetOpenCurve(double thickness, Vector3d normal, Point3d[] openCurvePts)
{
var openCurve = new PolylineCurve[2];
openCurve[0] = new PolylineCurve(openCurvePts.Select(pt => pt + normal * thickness * 2));
openCurve[1] = new PolylineCurve(openCurvePts.Select(pt => pt - normal * thickness * 2));
return openCurve;
}

private static Point3d[] GetOpenCurvePts(IReadOnlyList<Point3d> wallPts, StbOpen open)
{
var openXVec = new Vector3d(wallPts[1] - wallPts[0]);
openXVec.Unitize();
Vector3d openYVec = Vector3d.ZAxis;

var openCurvePts = new Point3d[5];
openCurvePts[0] = wallPts[0] + openXVec * open.position_X + openYVec * open.position_Y;
openCurvePts[1] = openCurvePts[0] + openXVec * open.length_X;
openCurvePts[2] = openCurvePts[1] + openYVec * open.length_Y;
openCurvePts[3] = openCurvePts[0] + openYVec * open.length_Y;
openCurvePts[4] = openCurvePts[0];

return openCurvePts;
}
}
}

0 comments on commit 8dc3f27

Please sign in to comment.