Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Sep 11, 2019
1 parent 7f9117b commit 68ca7e8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
24 changes: 17 additions & 7 deletions src/groupmesh.cpp
Expand Up @@ -143,7 +143,7 @@ void Group::GenerateForStepAndRepeat(T *steps, T *outs, Group::CombineAs forWhat
// And tack this transformed copy on to the return.
if(soFar->IsEmpty()) {
scratch->MakeFromCopyOf(&transd);
} else if (forWhat == CombineAs::ASSEMBLE) {
} else if(forWhat == CombineAs::ASSEMBLE) {
scratch->MakeFromAssemblyOf(soFar, &transd);
} else {
scratch->MakeFromUnionOf(soFar, &transd);
Expand All @@ -170,12 +170,22 @@ void Group::GenerateForBoolean(T *prevs, T *thiss, T *outs, Group::CombineAs how

// So our group's shell appears in thisShell. Combine this with the
// previous group's shell, using the requested operation.
if(how == CombineAs::UNION) {
outs->MakeFromUnionOf(prevs, thiss);
} else if(how == CombineAs::DIFFERENCE) {
outs->MakeFromDifferenceOf(prevs, thiss);
} else {
outs->MakeFromAssemblyOf(prevs, thiss);
switch(how) {
case CombineAs::UNION:
outs->MakeFromUnionOf(prevs, thiss);
break;

case CombineAs::DIFFERENCE:
outs->MakeFromDifferenceOf(prevs, thiss);
break;

case CombineAs::ASSEMBLE:
outs->MakeFromAssemblyOf(prevs, thiss);
break;

case CombineAs::INTERSECTION:
outs->MakeFromIntersectionOf(prevs, thiss);
break;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/mesh.cpp
Expand Up @@ -286,6 +286,14 @@ void SMesh::MakeFromDifferenceOf(SMesh *a, SMesh *b) {
AddAgainstBsp(a, bspb);
}

void SMesh::MakeFromIntersectionOf(SMesh *a, SMesh *b) {
SBsp3 *bspa = SBsp3::FromMesh(a);
SBsp3 *bspb = SBsp3::FromMesh(b);

AddAgainstBsp(a, bspb);
AddAgainstBsp(b, bspa);
}

void SMesh::MakeFromCopyOf(SMesh *a) {
ssassert(this != a, "Can't make from copy of self");
for(int i = 0; i < a->l.n; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/polygon.h
Expand Up @@ -270,6 +270,7 @@ class SMesh {
void AddAgainstBsp(SMesh *srcm, SBsp3 *bsp3);
void MakeFromUnionOf(SMesh *a, SMesh *b);
void MakeFromDifferenceOf(SMesh *a, SMesh *b);
void MakeFromIntersectionOf(SMesh *a, SMesh *b);

void MakeFromCopyOf(SMesh *a);
void MakeFromTransformationOf(SMesh *a, Vector trans,
Expand Down
3 changes: 2 additions & 1 deletion src/sketch.h
Expand Up @@ -239,7 +239,8 @@ class Group {
enum class CombineAs : uint32_t {
UNION = 0,
DIFFERENCE = 1,
ASSEMBLE = 2
ASSEMBLE = 2,
INTERSECTION = 3,
};
CombineAs meshCombine;

Expand Down
11 changes: 11 additions & 0 deletions src/srf/boolean.cpp
Expand Up @@ -16,6 +16,10 @@ void SShell::MakeFromDifferenceOf(SShell *a, SShell *b) {
MakeFromBoolean(a, b, SSurface::CombineAs::DIFFERENCE);
}

void SShell::MakeFromIntersectionOf(SShell *a, SShell *b) {
MakeFromBoolean(a, b, SSurface::CombineAs::INTERSECT);
}

//-----------------------------------------------------------------------------
// Take our original pwl curve. Wherever an edge intersects a surface within
// either agnstA or agnstB, split the piecewise linear element. Then refine
Expand Down Expand Up @@ -217,6 +221,13 @@ static bool KeepRegion(SSurface::CombineAs type, bool opA, SShell::Class shell,
return (inShell && !inFace) || inSame;
}

case SSurface::CombineAs::INTERSECT:
if(opA) {
return (!inShell && inFace);
} else {
return (!inShell && inFace) || inSame;
}

default: ssassert(false, "Unexpected combine type");
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/srf/surface.h
Expand Up @@ -390,7 +390,9 @@ class SShell {
void MakeFirstOrderRevolvedSurfaces(Vector pt, Vector axis, int i0);
void MakeFromUnionOf(SShell *a, SShell *b);
void MakeFromDifferenceOf(SShell *a, SShell *b);
void MakeFromIntersectionOf(SShell *a, SShell *b);
void MakeFromBoolean(SShell *a, SShell *b, SSurface::CombineAs type);

void CopyCurvesSplitAgainst(bool opA, SShell *agnst, SShell *into);
void CopySurfacesTrimAgainst(SShell *sha, SShell *shb, SShell *into, SSurface::CombineAs type);
void MakeIntersectionCurvesAgainst(SShell *against, SShell *into);
Expand Down
5 changes: 5 additions & 0 deletions src/textscreens.cpp
Expand Up @@ -375,11 +375,13 @@ void TextWindow::ShowGroupInfo() {
g->type == Group::Type::HELIX) {
bool un = (g->meshCombine == Group::CombineAs::UNION);
bool diff = (g->meshCombine == Group::CombineAs::DIFFERENCE);
bool intr = (g->meshCombine == Group::CombineAs::INTERSECTION);
bool asy = (g->meshCombine == Group::CombineAs::ASSEMBLE);

Printf(false, " %Ftsolid model as");
Printf(false, "%Ba %f%D%Lc%Fd%s union%E "
"%f%D%Lc%Fd%s difference%E "
"%f%D%Lc%Fd%s intersection%E "
"%f%D%Lc%Fd%s assemble%E ",
&TextWindow::ScreenChangeGroupOption,
Group::CombineAs::UNION,
Expand All @@ -388,6 +390,9 @@ void TextWindow::ShowGroupInfo() {
Group::CombineAs::DIFFERENCE,
diff ? RADIO_TRUE : RADIO_FALSE,
&TextWindow::ScreenChangeGroupOption,
Group::CombineAs::INTERSECTION,
intr ? RADIO_TRUE : RADIO_FALSE,
&TextWindow::ScreenChangeGroupOption,
Group::CombineAs::ASSEMBLE,
(asy ? RADIO_TRUE : RADIO_FALSE));

Expand Down

0 comments on commit 68ca7e8

Please sign in to comment.