Class: CSG

PD. CSG

Defines a 3D shape or solid as a collection of bounding planar faces.

Two solids can be combined using the union(), subtract(), and intersect() methods.


new CSG( [polygons])

Creates a new faceted solid ready for constructive solid geometry.

Parameters:
Name Type Argument Description
polygons Array.<CSGPolygon> <optional>

An optional array of polygon facets.

Members


:boolean

isCSG <readonly>

A flag identifying this object as a CSG instance.

Type
  • boolean

:Array.<CSGPolygon>

polygons

A list of connected polygons that define the boundary of a 3D shape.

Type

Methods


OLD_toBRepUnioned( [brep])

Copies the CSG data into the given boundary representation, trying to union together coplanar facets.

Parameters:
Name Type Argument Description
brep PD.BRep <optional>

An optional boundary representation to store the result.

Returns:

Returns the given BRep or a newly created one.

Type
PD.BRep

addBRep(brep)

Adds faces from a PD.BRep to this instance, converting polygonal faces directly to polygons..

Parameters:
Name Type Description
brep PD.BRep

the boundary representation containing polygonal faces.

Returns:

Returns this CSG shape instance.

Type
PD.CSG

addBRepTriangles(brep)

Adds faces from a PD.BRep to this instance, converting individual triangles in each face to polygons.

Parameters:
Name Type Description
brep PD.BRep

The BRep containing the triangles.

Returns:

Returns a new CSG shape.

Type
PD.CSG

addShell(shell)

Add facets from a PD.Shell to this instance, converting polygonal facets directly to polygons.

Parameters:
Name Type Description
shell PD.Shell

The shell containing polygonal facets.

Returns:

Returns this CSG shape instance.

Type
PD.CSG

addShellTriangles(shell)

Add facets from a PD.Shell to this instance, converting individual triangles in each face to polygons.

Parameters:
Name Type Description
shell PD.Shell

the shell containing the triangles.

Returns:

Returns this CSG shape instance.

Type
PD.CSG

clone()

Creates a deep copy of this CSG shape.

Returns:

Returns the new cloned object.

Type
PD.CSG

intersect(csg)

Returns a new solid representing the space both this solid and in csg.

Neither this solid nor the solid csg are modified.

  A.intersect(B)
    +-------+
    |       |
    |   A   |
    |    +--+----+   =   +--+
    +----+--+    |       +--+
         |   B   |
         |       |
         +-------+
Parameters:
Name Type Description
csg PD.CSG

The CSG solid to union with this one.

Returns:

Returns the new unioned solid.

Type
PD.CSG

inverse()

Return a new solid with solid and empty space switched.

This solid is not modified.

Returns:

Returns the new unioned solid.

Type
PD.CSG

isEmpty()

Checks if this shape is empty (contains no polygons).

Returns:

Returns true if this shape contains no polygons.

Type
boolean

subtract(csg)

Returns a new solid representing the space in this solid but not in csg.

Neither this solid nor the solid csg are modified.

  A.subtract(B)
    +-------+            +-------+
    |       |            |       |
    |   A   |            |       |
    |    +--+----+   =   |    +--+
    +----+--+    |       +----+
         |   B   |
         |       |
         +-------+
Parameters:
Name Type Description
csg PD.CSG

The CSG solid to union with this one.

Returns:

Returns the new unioned solid.

Type
PD.CSG

toBRep( [brep])

Copies the CSG data into the given boundary representation.

Parameters:
Name Type Argument Description
brep PD.BRep <optional>

An optional boundary representation to store the result.

Returns:

Returns the given BRep or a newly created one.

Type
PD.BRep

toBRepUnioned( [brep])

Copies the CSG data into the given boundary representation, trying to union together coplanar facets.

Parameters:
Name Type Argument Description
brep PD.BRep <optional>

An optional boundary representation to store the result.

Returns:

Returns the given BRep or a newly created one.

Type
PD.BRep

toPolygons()

Retrieves a list of all the polygons that make up this shape.

Returns:

Returns an array of bounding polygons.

Type
Array

toShell( [shell])

Copies the CSG data into the given shell.

Parameters:
Name Type Argument Description
shell PD.Shell <optional>

An optional shell to store the resulting shape.

Returns:

Returns the given shell or a newly created one.

Type
PD.Shell

union(csg)

Returns a new solid representing the space in either this solid or csg.

Neither this solid nor the solid csg are modified.

    A.union(B)
    +-------+            +-------+
    |       |            |       |
    |   A   |            |       |
    |    +--+----+   =   |       +----+
    +----+--+    |       +----+       |
         |   B   |            |       |
         |       |            |       |
         +-------+            +-------+
Parameters:
Name Type Description
csg PD.CSG

The CSG solid to union with this one.

Returns:

Returns the new unioned solid.

Type
PD.CSG

bbox(corners, shared) <static>

Construct an axis-aligned solid rectangular prism.

Parameters are a list of 8 vertices in the order shown below. Each vertex is an [x,y,z] position array in model units.

    +Z              max
     |  7-----------6
     | /|  +Y      /|
     |/ |  /      / |
     4----/------5  |
     |  |/       |  |
     |  3--------|--2
     | /         | /
     |/          |/
     0-----------1-----+X
   min
Parameters:
Name Type Description
corners Array

An array of 8 points defining the cube corners.

shared object

An object to be shared by all faces, such as a color.

Returns:

Returns a new CSG shape.

Type
PD.CSG

cube( [options]) <static>

Constructs an axis-aligned solid cuboid.

Optional parameters are center and radius, which default to [0, 0, 0] and [1, 1, 1]. The radius can be specified using a single number or an array of three numbers, one for each axis.

Parameters:
Name Type Argument Description
options object <optional>

An optional configuration object.

Properties of options:
Name Type Argument Description
center PD.CSG.Vector <optional>

The position of the center of the cube.

radius number | Array <optional>

The size of the cube, as a single number or [x,y,z] array.

Returns:

Returns a new CSG shape.

Type
PD.CSG
Example
const cube = PD.CSG.cube({
      center: [0, 0, 0],
      radius: 1
    });

cylinder() <static>

Construct a solid cylinder.

Optional parameters are start, end, radius, and slices, which default to [0, -1, 0], [0, 1, 0], 1, and 16. The slices parameter controls the tessellation.

Returns:

Returns a new CSG shape.

Type
PD.CSG
Example
const cylinder = PD.CSG.cylinder({
      start: [0, -1, 0],
      end: [0, 1, 0],
      radius: 1,
      slices: 16
    });

extrudeClipPath(clipPath, vector [, botOffset] [, topOffset]) <static>

Construct an extruded CSG shape from a ClipperLib path.

Parameters:
Name Type Argument Description
clipPath Array

An array of ClipperLib {X,Y} points, or an array of such arrays.

vector THREE.Vector3

The normalised extrusion direction vector.

botOffset number <optional>

An optional offset to apply to the bottom face along the extrusion vector, defaults to 0.

topOffset number <optional>

An optional offset to apply to the top face along the extrusion vector, defaults to 0.

Returns:

Returns a new CSG shape, or null if the clip path is invalid.

Type
PD.CSG

extrudePolyline(polyline, vector [, botOffset] [, topOffset]) <static>

Construct an extruded CSG shape from a ClipperLib path.

Parameters:
Name Type Argument Description
polyline Array

An array of ClipperLib {X,Y} points, or an array of such arrays.

vector THREE.Vector3

The normalised extrusion direction vector.

botOffset number <optional>

An optional offset to apply to the bottom face along the extrusion vector, defaults to 0.

topOffset number <optional>

An optional offset to apply to the top face along the extrusion vector, defaults to 1000mm or 3' (36").

Returns:

Returns a new CSG shape, or null if the clip path is invalid.

Type
PD.CSG

fromBRep(brep) <static>

Construct a CSG solid from a PD.BRep instance converting polygonal faces to polygons.

Parameters:
Name Type Description
brep PD.BRep

The BRep containing the polygon facets.

Returns:

Returns a new CSG shape.

Type
PD.CSG

fromBRepTriangles(brep) <static>

Construct a CSG solid from a PD.BRep instance converting individual triangles in each face to polygons.

Parameters:
Name Type Description
brep PD.BRep

The BRep containing the triangles.

Returns:

Returns a new CSG shape.

Type
PD.CSG

fromPolygons(polygons) <static>

Construct a CSG solid from a list of CSG.Polygon instances.

Parameters:
Name Type Description
polygons Array

An array of connected bounding polygons.

Returns:

Returns a new CSG shape.

Type
PD.CSG

fromShell(shell) <static>

Construct a CSG solid from a PD.Shell instance, converting polygonal facets directly to polygons.

Parameters:
Name Type Description
shell PD.Shell

the shell containing the polygon facets.

Returns:

Returns a new CSG shape.

Type
PD.CSG

fromShellTriangles(shell) <static>

Construct a CSG solid from a PD.Shell instance, converting individual triangles in each face to polygons.

Parameters:
Name Type Description
shell PD.Shell

the shell containing the triangles.

Returns:

Returns a new CSG shape.

Type
PD.CSG

sphere() <static>

Construct a solid sphere.

Optional parameters are center, radius, slices, and stacks, which default to [0, 0, 0], 1, 16, and 8. The slices and stacks parameters control the tessellation along the longitude and latitude directions.

Example
const sphere = PD.CSG.sphere({
      center: [0, 0, 0],
      radius: 1,
      slices: 16,
      stacks: 8
    });