Skip to content

Commit

Permalink
Merge pull request #6 from illwieckz/csgmakeroom
Browse files Browse the repository at this point in the history
Correct CSG Make Room operation, algorithm by Garux
This fixes #4747
  • Loading branch information
codereader committed Mar 15, 2018
2 parents 2ad55e9 + c532ee8 commit addb935
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions radiant/brush/csg/CSG.cpp
Expand Up @@ -47,6 +47,13 @@ void hollowBrush(const BrushNodePtr& sourceBrush, bool makeRoom)
BrushNodePtr brushNode = std::dynamic_pointer_cast<BrushNode>(newNode);
assert(brushNode);

float offset = GlobalGrid().getGridSize();

if (makeRoom)
{
face.getPlane().offset(offset);
}

// Add the child to the same parent as the source brush
parent->addChildNode(brushNode);

Expand All @@ -56,24 +63,25 @@ void hollowBrush(const BrushNodePtr& sourceBrush, bool makeRoom)
// Copy all faces from the source brush
brushNode->getBrush().copy(sourceBrush->getBrush());

if (makeRoom)
{
face.getPlane().offset(-offset);
}

Node_setSelected(brushNode, true);

FacePtr newFace = brushNode->getBrush().addFace(face);

if (newFace != 0)
{
float offset = GlobalGrid().getGridSize();

newFace->flipWinding();
newFace->getPlane().offset(offset);
newFace->planeChanged();

if (makeRoom)
{
// Retrieve the normal vector of the "source" face
brushNode->getBrush().transform(Matrix4::getTranslation(face.getPlane().getPlane().normal() * offset));
brushNode->getBrush().freezeTransform();
}
if (!makeRoom)
{
newFace->getPlane().offset(offset);
}

newFace->planeChanged();
}

brushNode->getBrush().removeEmptyFaces();
Expand Down

0 comments on commit addb935

Please sign in to comment.