Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 68ca7e8

Browse files
committedSep 11, 2019
wip
1 parent 7f9117b commit 68ca7e8

File tree

7 files changed

+46
-8
lines changed

7 files changed

+46
-8
lines changed
 

‎src/groupmesh.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void Group::GenerateForStepAndRepeat(T *steps, T *outs, Group::CombineAs forWhat
143143
// And tack this transformed copy on to the return.
144144
if(soFar->IsEmpty()) {
145145
scratch->MakeFromCopyOf(&transd);
146-
} else if (forWhat == CombineAs::ASSEMBLE) {
146+
} else if(forWhat == CombineAs::ASSEMBLE) {
147147
scratch->MakeFromAssemblyOf(soFar, &transd);
148148
} else {
149149
scratch->MakeFromUnionOf(soFar, &transd);
@@ -170,12 +170,22 @@ void Group::GenerateForBoolean(T *prevs, T *thiss, T *outs, Group::CombineAs how
170170

171171
// So our group's shell appears in thisShell. Combine this with the
172172
// previous group's shell, using the requested operation.
173-
if(how == CombineAs::UNION) {
174-
outs->MakeFromUnionOf(prevs, thiss);
175-
} else if(how == CombineAs::DIFFERENCE) {
176-
outs->MakeFromDifferenceOf(prevs, thiss);
177-
} else {
178-
outs->MakeFromAssemblyOf(prevs, thiss);
173+
switch(how) {
174+
case CombineAs::UNION:
175+
outs->MakeFromUnionOf(prevs, thiss);
176+
break;
177+
178+
case CombineAs::DIFFERENCE:
179+
outs->MakeFromDifferenceOf(prevs, thiss);
180+
break;
181+
182+
case CombineAs::ASSEMBLE:
183+
outs->MakeFromAssemblyOf(prevs, thiss);
184+
break;
185+
186+
case CombineAs::INTERSECTION:
187+
outs->MakeFromIntersectionOf(prevs, thiss);
188+
break;
179189
}
180190
}
181191

‎src/mesh.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ void SMesh::MakeFromDifferenceOf(SMesh *a, SMesh *b) {
286286
AddAgainstBsp(a, bspb);
287287
}
288288

289+
void SMesh::MakeFromIntersectionOf(SMesh *a, SMesh *b) {
290+
SBsp3 *bspa = SBsp3::FromMesh(a);
291+
SBsp3 *bspb = SBsp3::FromMesh(b);
292+
293+
AddAgainstBsp(a, bspb);
294+
AddAgainstBsp(b, bspa);
295+
}
296+
289297
void SMesh::MakeFromCopyOf(SMesh *a) {
290298
ssassert(this != a, "Can't make from copy of self");
291299
for(int i = 0; i < a->l.n; i++) {

‎src/polygon.h

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ class SMesh {
270270
void AddAgainstBsp(SMesh *srcm, SBsp3 *bsp3);
271271
void MakeFromUnionOf(SMesh *a, SMesh *b);
272272
void MakeFromDifferenceOf(SMesh *a, SMesh *b);
273+
void MakeFromIntersectionOf(SMesh *a, SMesh *b);
273274

274275
void MakeFromCopyOf(SMesh *a);
275276
void MakeFromTransformationOf(SMesh *a, Vector trans,

‎src/sketch.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ class Group {
239239
enum class CombineAs : uint32_t {
240240
UNION = 0,
241241
DIFFERENCE = 1,
242-
ASSEMBLE = 2
242+
ASSEMBLE = 2,
243+
INTERSECTION = 3,
243244
};
244245
CombineAs meshCombine;
245246

‎src/srf/boolean.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ void SShell::MakeFromDifferenceOf(SShell *a, SShell *b) {
1616
MakeFromBoolean(a, b, SSurface::CombineAs::DIFFERENCE);
1717
}
1818

19+
void SShell::MakeFromIntersectionOf(SShell *a, SShell *b) {
20+
MakeFromBoolean(a, b, SSurface::CombineAs::INTERSECT);
21+
}
22+
1923
//-----------------------------------------------------------------------------
2024
// Take our original pwl curve. Wherever an edge intersects a surface within
2125
// either agnstA or agnstB, split the piecewise linear element. Then refine
@@ -217,6 +221,13 @@ static bool KeepRegion(SSurface::CombineAs type, bool opA, SShell::Class shell,
217221
return (inShell && !inFace) || inSame;
218222
}
219223

224+
case SSurface::CombineAs::INTERSECT:
225+
if(opA) {
226+
return (!inShell && inFace);
227+
} else {
228+
return (!inShell && inFace) || inSame;
229+
}
230+
220231
default: ssassert(false, "Unexpected combine type");
221232
}
222233
}

‎src/srf/surface.h

+2
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ class SShell {
390390
void MakeFirstOrderRevolvedSurfaces(Vector pt, Vector axis, int i0);
391391
void MakeFromUnionOf(SShell *a, SShell *b);
392392
void MakeFromDifferenceOf(SShell *a, SShell *b);
393+
void MakeFromIntersectionOf(SShell *a, SShell *b);
393394
void MakeFromBoolean(SShell *a, SShell *b, SSurface::CombineAs type);
395+
394396
void CopyCurvesSplitAgainst(bool opA, SShell *agnst, SShell *into);
395397
void CopySurfacesTrimAgainst(SShell *sha, SShell *shb, SShell *into, SSurface::CombineAs type);
396398
void MakeIntersectionCurvesAgainst(SShell *against, SShell *into);

‎src/textscreens.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,13 @@ void TextWindow::ShowGroupInfo() {
375375
g->type == Group::Type::HELIX) {
376376
bool un = (g->meshCombine == Group::CombineAs::UNION);
377377
bool diff = (g->meshCombine == Group::CombineAs::DIFFERENCE);
378+
bool intr = (g->meshCombine == Group::CombineAs::INTERSECTION);
378379
bool asy = (g->meshCombine == Group::CombineAs::ASSEMBLE);
379380

380381
Printf(false, " %Ftsolid model as");
381382
Printf(false, "%Ba %f%D%Lc%Fd%s union%E "
382383
"%f%D%Lc%Fd%s difference%E "
384+
"%f%D%Lc%Fd%s intersection%E "
383385
"%f%D%Lc%Fd%s assemble%E ",
384386
&TextWindow::ScreenChangeGroupOption,
385387
Group::CombineAs::UNION,
@@ -388,6 +390,9 @@ void TextWindow::ShowGroupInfo() {
388390
Group::CombineAs::DIFFERENCE,
389391
diff ? RADIO_TRUE : RADIO_FALSE,
390392
&TextWindow::ScreenChangeGroupOption,
393+
Group::CombineAs::INTERSECTION,
394+
intr ? RADIO_TRUE : RADIO_FALSE,
395+
&TextWindow::ScreenChangeGroupOption,
391396
Group::CombineAs::ASSEMBLE,
392397
(asy ? RADIO_TRUE : RADIO_FALSE));
393398

0 commit comments

Comments
 (0)
Please sign in to comment.