public class CSG
extends java.lang.Object
Node.clipTo(Node)
and Node.invert()
,
which remove parts of a BSP tree inside another BSP tree and swap solid and empty space, respectively. To find the
union of a
and b
, we want to remove everything in a
inside b
and everything in
b
inside a
, then combine polygons from a
and b
into one solid:
The only tricky part is handling overlapping coplanar polygons in both trees. The code above keeps both copies, but we need to keep them in one tree and remove them in the other tree. To remove them froma.clipTo(b); b.clipTo(a); a.build(b.allPolygons());
b
we can clip the
inverse of b
against a
. The code for union now looks like this:
Subtraction and intersection naturally follow from set operations. If union isa.clipTo(b); b.clipTo(a); b.invert(); b.clipTo(a); b.invert(); a.build(b.allPolygons());
A | B
, differenceion is
A - B = ~(~A | B)
and intersection is A & B =
~(~A | ~B)
where ~
is the complement operator.Modifier and Type | Class and Description |
---|---|
static class |
CSG.OptType |
Modifier and Type | Method and Description |
---|---|
CSG |
clone() |
CSG |
color(javafx.scene.paint.Color c) |
CSG |
difference(CSG... csgs)
Return a new CSG solid representing the difference of this csg and the specified csgs.
|
CSG |
difference(CSG csg)
Return a new CSG solid representing the difference of this csg and the specified csg.
|
CSG |
difference(java.util.List<CSG> csgs)
Return a new CSG solid representing the difference of this csg and the specified csgs.
|
CSG |
dumbUnion(CSG csg)
Returns a csg consisting of the polygons of this csg and the specified csg.
|
static CSG |
fromPolygons(java.util.List<Polygon> polygons)
Constructs a CSG from a list of
Polygon instances. |
static CSG |
fromPolygons(Polygon... polygons)
Constructs a CSG from the specified
Polygon instances. |
static CSG |
fromPolygons(PropertyStorage storage,
java.util.List<Polygon> polygons)
Constructs a CSG from a list of
Polygon instances. |
static CSG |
fromPolygons(PropertyStorage storage,
Polygon... polygons)
Constructs a CSG from the specified
Polygon instances. |
Bounds |
getBounds()
Returns the bounds of this csg.
|
java.util.List<Polygon> |
getPolygons() |
CSG |
hull()
Returns the convex hull of this csg.
|
CSG |
hull(CSG... csgs)
Returns the convex hull of this csg and the union of the specified csgs.
|
CSG |
hull(java.util.List<CSG> csgs)
Returns the convex hull of this csg and the union of the specified csgs.
|
CSG |
intersect(CSG... csgs)
Return a new CSG solid representing the intersection of this csg and the specified csgs.
|
CSG |
intersect(CSG csg)
Return a new CSG solid representing the intersection of this csg and the specified csg.
|
CSG |
intersect(java.util.List<CSG> csgs)
Return a new CSG solid representing the intersection of this csg and the specified csgs.
|
CSG |
optimization(CSG.OptType type)
Defines the CSg optimization type.
|
static void |
setDefaultOptType(CSG.OptType optType) |
void |
setOptType(CSG.OptType optType) |
MeshContainer |
toJavaFXMesh() |
MeshContainer |
toJavaFXMeshSimple()
Returns the CSG as JavaFX triangle mesh.
|
ObjFile |
toObj() |
ObjFile |
toObj(int maxNumberOfVerts) |
java.lang.String |
toObjString()
Returns this csg in OBJ string format.
|
java.lang.StringBuilder |
toObjString(java.lang.StringBuilder sb)
Returns this csg in OBJ string format.
|
java.lang.String |
toStlString()
Returns this csg in STL string format.
|
java.lang.StringBuilder |
toStlString(java.lang.StringBuilder sb)
Returns this csg in STL string format.
|
CSG |
transformed(eu.mihosoft.vvecmath.Transform transform)
Returns a transformed copy of this CSG.
|
CSG |
union(CSG... csgs)
Return a new CSG solid representing the union of this csg and the specified csgs.
|
CSG |
union(CSG csg)
Return a new CSG solid representing the union of this csg and the specified csg.
|
CSG |
union(java.util.List<CSG> csgs)
Return a new CSG solid representing the union of this csg and the specified csgs.
|
CSG |
weighted(WeightFunction f) |
public static CSG fromPolygons(java.util.List<Polygon> polygons)
Polygon
instances.polygons
- polygonspublic static CSG fromPolygons(Polygon... polygons)
Polygon
instances.polygons
- polygonspublic static CSG fromPolygons(PropertyStorage storage, java.util.List<Polygon> polygons)
Polygon
instances.storage
- shared storagepolygons
- polygonspublic static CSG fromPolygons(PropertyStorage storage, Polygon... polygons)
Polygon
instances.storage
- shared storagepolygons
- polygonspublic CSG clone()
clone
in class java.lang.Object
public java.util.List<Polygon> getPolygons()
public CSG optimization(CSG.OptType type)
type
- optimization typepublic CSG union(CSG csg)
A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+
csg
- other csgpublic CSG dumbUnion(CSG csg)
WARNING: this method does not apply the csg algorithms. Therefore, please ensure that this csg and the specified csg do not intersect.
csg
- csgpublic CSG union(java.util.List<CSG> csgs)
A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+
csgs
- other csgspublic CSG union(CSG... csgs)
A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+
csgs
- other csgspublic CSG hull()
public CSG hull(java.util.List<CSG> csgs)
csgs
- csgspublic CSG hull(CSG... csgs)
csgs
- csgspublic CSG difference(java.util.List<CSG> csgs)
A.difference(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+
csgs
- other csgspublic CSG difference(CSG... csgs)
A.difference(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+
csgs
- other csgspublic CSG difference(CSG csg)
A.difference(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+
csg
- other csgpublic CSG intersect(CSG csg)
A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+ }
csg
- other csgpublic CSG intersect(java.util.List<CSG> csgs)
A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+ }
csgs
- other csgspublic CSG intersect(CSG... csgs)
A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+ }
csgs
- other csgspublic java.lang.String toStlString()
public java.lang.StringBuilder toStlString(java.lang.StringBuilder sb)
sb
- string builderpublic CSG color(javafx.scene.paint.Color c)
public ObjFile toObj()
public ObjFile toObj(int maxNumberOfVerts)
public java.lang.StringBuilder toObjString(java.lang.StringBuilder sb)
sb
- string builderpublic java.lang.String toObjString()
public CSG weighted(WeightFunction f)
public CSG transformed(eu.mihosoft.vvecmath.Transform transform)
transform
- the transform to applypublic MeshContainer toJavaFXMesh()
public MeshContainer toJavaFXMeshSimple()
public Bounds getBounds()
public static void setDefaultOptType(CSG.OptType optType)
optType
- the optType to setpublic void setOptType(CSG.OptType optType)
optType
- the optType to set