Contents
- Description
- Nested Class Summary
- Method Summary
- Method Details
- fromPolygons(List)
- fromPolygons(Polygon...)
- fromPolygons(PropertyStorage, List)
- fromPolygons(PropertyStorage, Polygon...)
- clone()
- getPolygons()
- getIntersections(Straight)
- getIntersectionsAndNormals(Straight)
- getCrossSection(Vector3d, Vector3d)
- optimization(CSG.OptType)
- union(CSG)
- dumbUnion(CSG)
- union(List)
- union(CSG...)
- hull(List)
- hull(CSG...)
- difference(List)
- difference(CSG...)
- difference(CSG)
- intersect(CSG)
- intersect(List)
- intersect(CSG...)
- toStlFile(String)
- toStlString()
- toStlString(StringBuilder)
- color(Color)
- toObj()
- toObjString(StringBuilder)
- toObjString()
- weighted(WeightFunction)
- transformed(Transform)
- transform(Transform)
- toJavaFXMesh()
- toJavaFXMeshSimple()
- getBounds()
- setDefaultOptType(CSG.OptType)
- setOptType(CSG.OptType)
Class CSG
java.lang.Object
eu.mihosoft.vrl.v3d.CSG
Constructive Solid Geometry (CSG).
This implementation is a Java port of
https://github.com/evanw/csg.js/
with some additional features like polygon extrude, transformations etc.
Thanks to the author for creating the CSG.js library.
Implementation Details All CSG operations are implemented in terms of two functions,
Implementation Details All CSG operations are implemented in terms of two functions,
Node.clipTo(eu.mihosoft.vrl.v3d.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.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionclone()
color
(javafx.scene.paint.Color c) difference
(CSG csg) Return a new CSG solid representing the difference of this csg and the specified csg.difference
(CSG... csgs) Return a new CSG solid representing the difference of this csg and the specified csgs.difference
(List<CSG> csgs) Return a new CSG solid representing the difference of this csg and the specified csgs.Returns a csg consisting of the polygons of this csg and the specified csg.static CSG
fromPolygons
(Polygon... polygons) Constructs a CSG from the specifiedPolygon
instances.static CSG
fromPolygons
(PropertyStorage storage, Polygon... polygons) Constructs a CSG from the specifiedPolygon
instances.static CSG
fromPolygons
(PropertyStorage storage, List<Polygon> polygons) Constructs a CSG from a list ofPolygon
instances.static CSG
fromPolygons
(List<Polygon> polygons) Constructs a CSG from a list ofPolygon
instances.Returns the bounds of this csg.getCrossSection
(Vector3d planePoint, Vector3d planeNormal) getIntersections
(Straight line) Returns the convex hull of this csg and the union of the specified csgs.Returns the convex hull of this csg and the union of the specified csgs.Return a new CSG solid representing the intersection of this csg and the specified csg.Return a new CSG solid representing the intersection of this csg and the specified csgs.Return a new CSG solid representing the intersection of this csg and the specified csgs.optimization
(CSG.OptType type) Defines the CSg optimization type.static void
setDefaultOptType
(CSG.OptType optType) void
setOptType
(CSG.OptType optType) Returns the CSG as JavaFX triangle mesh.toObj()
Returns this csg in OBJ string format.Returns this csg in OBJ string format.void
Returns this csg in STL string format.Returns this csg in STL string format.void
transformed
(Transform transform) Returns a transformed copy of this CSG.Return a new CSG solid representing the union of this csg and the specified csg.Return a new CSG solid representing the union of this csg and the specified csgs.Return a new CSG solid representing the union of this csg and the specified csgs.
-
Method Details
-
fromPolygons
-
fromPolygons
-
fromPolygons
Constructs a CSG from a list ofPolygon
instances.- Parameters:
storage
- shared storagepolygons
- polygons- Returns:
- a CSG instance
-
fromPolygons
Constructs a CSG from the specifiedPolygon
instances.- Parameters:
storage
- shared storagepolygons
- polygons- Returns:
- a CSG instance
-
clone
-
getPolygons
-
getIntersections
-
getIntersectionsAndNormals
- Parameters:
line
-- Returns:
- the positions of intersections of CSG with line
-
getCrossSection
-
optimization
Defines the CSg optimization type.- Parameters:
type
- optimization type- Returns:
- this CSG
-
union
Return a new CSG solid representing the union of this csg and the specified csg. Note: Neither this csg nor the specified csg are weighted.A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+
- Parameters:
csg
- other csg- Returns:
- union of this csg and the specified csg
-
dumbUnion
Returns a csg consisting of the polygons of this csg and the specified csg. The purpose of this method is to allow fast union operations for objects that do not intersect.WARNING: this method does not apply the csg algorithms. Therefore, please ensure that this csg and the specified csg do not intersect.
- Parameters:
csg
- csg- Returns:
- a csg consisting of the polygons of this csg and the specified csg
-
union
Return a new CSG solid representing the union of this csg and the specified csgs. Note: Neither this csg nor the specified csg are weighted.A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+
- Parameters:
csgs
- other csgs- Returns:
- union of this csg and the specified csgs
-
union
Return a new CSG solid representing the union of this csg and the specified csgs. Note: Neither this csg nor the specified csg are weighted.A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+
- Parameters:
csgs
- other csgs- Returns:
- union of this csg and the specified csgs
-
hull
-
hull
-
difference
Return a new CSG solid representing the difference of this csg and the specified csgs. Note: Neither this csg nor the specified csgs are weighted.A.difference(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+
- Parameters:
csgs
- other csgs- Returns:
- difference of this csg and the specified csgs
-
difference
Return a new CSG solid representing the difference of this csg and the specified csgs. Note: Neither this csg nor the specified csgs are weighted.A.difference(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+
- Parameters:
csgs
- other csgs- Returns:
- difference of this csg and the specified csgs
-
difference
Return a new CSG solid representing the difference of this csg and the specified csg. Note: Neither this csg nor the specified csg are weighted.A.difference(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+
- Parameters:
csg
- other csg- Returns:
- difference of this csg and the specified csg
-
intersect
Return a new CSG solid representing the intersection of this csg and the specified csg. Note: Neither this csg nor the specified csg are weighted.A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+ }
- Parameters:
csg
- other csg- Returns:
- intersection of this csg and the specified csg
-
intersect
Return a new CSG solid representing the intersection of this csg and the specified csgs. Note: Neither this csg nor the specified csgs are weighted.A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+ }
- Parameters:
csgs
- other csgs- Returns:
- intersection of this csg and the specified csgs
-
intersect
Return a new CSG solid representing the intersection of this csg and the specified csgs. Note: Neither this csg nor the specified csgs are weighted.A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+ }
- Parameters:
csgs
- other csgs- Returns:
- intersection of this csg and the specified csgs
-
toStlFile
- Throws:
IOException
-
toStlString
Returns this csg in STL string format.- Returns:
- this csg in STL string format
-
toStlString
Returns this csg in STL string format.- Parameters:
sb
- string builder- Returns:
- the specified string builder
-
color
-
toObj
-
toObjString
Returns this csg in OBJ string format.- Parameters:
sb
- string builder- Returns:
- the specified string builder
-
toObjString
Returns this csg in OBJ string format.- Returns:
- this csg in OBJ string format
-
weighted
-
transformed
-
transform
- Parameters:
transform
- the current CSG
-
toJavaFXMesh
-
toJavaFXMeshSimple
Returns the CSG as JavaFX triangle mesh.- Returns:
- the CSG as JavaFX triangle mesh
-
getBounds
-
setDefaultOptType
- Parameters:
optType
- the optType to set
-
setOptType
- Parameters:
optType
- the optType to set
-