new Solid( [manifold])
Creates a new solid ready for constructive solid geometry.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
manifold |
Manifold |
<optional> |
An optional Manifold object. |
Members
-
:boolean
isSolid <readonly>
-
A flag identifying this object as a solid.
Type
- boolean
-
:Manifold|null
manifold
-
A Manifold instance containing the current 3D solid.
Type
- Manifold | null
-
:Array.<{time:number, action:string, error:string}>
errorLog <static>
-
An array of error log entries. Each entry is an object with
time,action, anderrorproperties.Type
- Array.<{time:number, action:string, error:string}>
-
:number
maxErrorLog <static>
-
The maximum number of error messages to store in the error log.
Type
- number
- Default Value:
-
- 100
Methods
-
NEW_toShellWithUnionedFaces( [shell])
-
Copies the CSG data into the given shell, trying to union together coplanar facets.
Parameters:
Name Type Argument Description shellPD.Shell <optional>
An optional shell to store the resulting shape.
Returns:
Returns the given shell or a newly created one.
- Type
- PD.Shell
-
OLD_toBRepUnioned( [brep])
-
Copies the CSG data into the given boundary representation, trying to union together coplanar facets.
Parameters:
Name Type Argument Description brepPD.BRep <optional>
An optional boundary representation to store the result.
Returns:
Returns the given BRep or a newly created one.
- Type
- PD.BRep
-
XXX_toBRepUnioned( [brep])
-
Copies the CSG data into the given boundary representation, trying to union together coplanar facets.
Parameters:
Name Type Argument Description brepPD.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)
-
Add face triangles from a
PD.BRepto this solid.Parameters:
Name Type Description brepPD.BRep the boundary representation containing polygonal faces.
Returns:
Returns this CSG solid to support method chaining.
- Type
- PD.Solid
-
addBufferGeometry(geometry)
-
Add triangles from a
THREE.BufferGeometryto this solid.Parameters:
Name Type Description geometryTHREE.BufferGeometry The buffer geometry to convert.
Returns:
Returns this CSG solid to support method chaining.
- Type
- PD.Solid
-
addPolyMesh(polyMesh)
-
Add triangles from a
PD.PolyMeshto this solid.Parameters:
Name Type Description polyMeshPD.PolyMesh The poly mesh to convert.
Returns:
Returns this CSG solid to support method chaining.
- Type
- PD.Solid
-
addShell(shell)
-
Add facet triangles from a
PD.Shellto this solid.Parameters:
Name Type Description shellPD.Shell The shell containing the triangles.
Returns:
Returns this CSG solid to support method chaining.
- Type
- PD.Solid
-
dispose()
-
Releases any resources this solid has within the Manifold WASM module.
This method must be called when the solid is no longer needed as any associated resources in the WASM module will not be automatically freed by the garbage collector.
Returns:
Returns this solid to support method chaining.
- Type
- PD.Solid
-
intersect(solid)
-
Intersects a CSG solid with this solid.
A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+Parameters:
Name Type Description solidPD.Solid | Array.<PD.Solid> The CSG solid(s) to intersect with this one.
Returns:
Returns this updated CSG solid to support method chaining.
- Type
- PD.Solid
-
isEmpty()
-
Checks if the solid either has no manifold or the manifold is empty.
Returns:
Returns
trueif this solid is empty.- Type
- boolean
-
replaceManifold(manifold)
-
Replaces any existing Manifold stored by this solid with the given one.
Parameters:
Name Type Description manifoldManifold | ManifoldMesh | null The new Manifold or ManifoldMesh to set.
-
rotate(euler)
-
Rotates the solid by the given Euler angles.
Parameters:
Name Type Description eulerArray.<number> The [rx,ry,rz] Euler angle rotation array.
Returns:
Returns
trueif the solid was rotated,falseif manifold is not valid.- Type
- boolean
-
scale(scale)
-
Applies the given transformation matrix to the solid.
Parameters:
Name Type Description scaleArray.<number> The [sx,sy,sz] scale factor array.
Returns:
Returns
trueif the solid was scaled,falseif manifold is not valid.- Type
- boolean
-
splitByPlane(plane)
-
Splits the solid by the given plane.
Parameters:
Name Type Description planeTHREE.Plane | Array.<number> The plane to split the solid with, as an [normal,constant] object or an [a,b,c,d] array.
Returns:
Returns an array of two resulting solids, or an empty array if manifold is not valid or not split.
- Type
- Array.<PD.Solid>
-
subtract(solid)
-
Subtracts a CSG solid from this solid.
A.subtract(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+Parameters:
Name Type Description solidPD.Solid | Array.<PD.Solid> The CSG solid(s) to subtract with this one.
Returns:
Returns this updated CSG solid to support method chaining.
- Type
- PD.Solid
-
toBRep( [brep])
-
Copies the CSG data into the given boundary representation as individual triangles.
Parameters:
Name Type Argument Description brepPD.BRep <optional>
An optional boundary representation to store the result.
Returns:
Returns the given BRep or a newly created one.
- Type
- PD.BRep
-
toBRepAsFaces( [brep])
-
Copies the CSG data into the given boundary representation, trying to group triangles into faces by face IDs.
Parameters:
Name Type Argument Description brepPD.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 group coplanar triangles into facets.
Parameters:
Name Type Argument Description brepPD.BRep <optional>
An optional boundary representation to store the result.
Returns:
Returns the given BRep or a newly created one.
- Type
- PD.BRep
-
toBufferGeometry()
-
Converts the current CSG solid to a
THREE.BufferGeometry.Returns:
Returns a new buffer geometry, or
nullif invalid or empty.- Type
- THREE.BufferGeometry | null
-
toPolyMesh( [polyMesh])
-
Adds the current CSG data into the given PolyMesh or a new one.
Parameters:
Name Type Argument Description polyMeshPD.PolyMesh <optional>
An optional PolyMesh to store the resulting shape.
Returns:
Returns the given PolyMesh or a newly created one.
- Type
- PD.PolyMesh
-
toShell( [shell])
-
Copies the CSG data into the given shell.
Parameters:
Name Type Argument Description shellPD.Shell <optional>
An optional shell to store the resulting shape.
Returns:
Returns the given shell or a newly created one.
- Type
- PD.Shell
-
toShellWithUnionedFaces( [shell])
-
Copies the CSG data into the given shell, trying to union together coplanar facets.
Parameters:
Name Type Argument Description shellPD.Shell <optional>
An optional shell to store the resulting shape.
Returns:
Returns the given shell or a newly created one.
- Type
- PD.Shell
-
transform(matrix)
-
Applies the given transformation matrix to the solid.
Parameters:
Name Type Description matrixPD.MatrixArray The [4x4] transformation matrix.
Returns:
Returns
trueif the solid was transformed,falseif manifold is not valid.- Type
- boolean
-
translate(translate)
-
Translates the solid by the given vector array.
Parameters:
Name Type Description translateArray.<number> The [dx,dy,dz] translation vector array.
Returns:
Returns
trueif the solid was translated,falseif manifold is not valid.- Type
- boolean
-
union(solid)
-
Adds a CSG solid to this solid by unioning them.
A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+Parameters:
Name Type Description solidPD.Solid | Array.<PD.Solid> The CSG solid(s) to union with this one.
Returns:
. Returns this updated CSG solid to support method chaining.
- Type
- PD.Solid
-
computeBoundariesFromTriangles(triangles) <static>
-
Computes one or more outer boundaries from a collection of triangles.
This method analyses a flat triangle array (where every 3 consecutive points form a triangle) and computes the outer boundary loops. Any common points are assumed to be shared by reference, so the same object instance is used.
This method assumes that the triangles form a well-defined shape where the edges of each triangle are either adjacent to another triangle or are part of the outer boundary. Triangles do not need to be coplanar, but they must have the same winding order and form a connected shape where adjacent edges share common point instances in the opposite order. These condition are true for Manifold solids.
This format for storing triangles is common to both the
PD.ShellandPD.BRepframework classes. The resulting boundary loops can be used to constructPD.PolygonorPD.BRep.Faceobjects.Parameters:
Name Type Description trianglesArray.<PD.Point> A flat array of point objects, where every 3 consecutive points forms a triangle and common points are shared by reference.
Returns:
Returns an array of boundaries, where each is an array of points ordered to form a closed loop.
- Type
- Array.<Array.<PD.Point>>
-
cone( [options]) <static>
-
Construct a solid cone or pyramid.
Parameters:
Name Type Argument Description optionsobject <optional>
An optional configuration object.
Properties of
options:Name Type Argument Description heightnumber <optional>
The height of the cylinder as a single positive number, defaults to 1.
radiusnumber <optional>
The bottom radius of the cylinder as a single positive number, defaults to 1.
segmentsnumber <optional>
The number of segments used to approximate the cylinder [3 to 1800], defaults to 18.
centeredboolean <optional>
Whether or not the cylinder is centered at the origin rather that it being on its base, defaults to false.
originArray.<number> <optional>
The [x,y,z] position of the center of the cylinder, defaults to [0,0,0].
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
const cone = PD.Solid.cone({ radius: 250.0, height: 1200.0, centered: false, origin: [ 0, 0, 0 ], segments: 16 }); -
cuboid( [options]) <static>
-
Constructs an axis-aligned solid cuboid.
Parameters:
Name Type Argument Description optionsobject <optional>
An optional configuration object.
Properties of
options:Name Type Argument Description originArray.<number> <optional>
The [x,y,z] position of the cube, defaults to [0,0,0].
centeredboolean <optional>
Whether or not the cube is centered at the origin rather that it being the minimum corner, defaults to false.
sizenumber | Array.<number> <optional>
The size of the cube, as a single number or [x,y,z] vector array, defaults to 1.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
const cube = PD.Solid.cube({ origin: [ 10, 25, 5 ], size: [ 5, 3, 1 ], centered: true }); -
cylinder( [options]) <static>
-
Construct a solid cylinder.
Parameters:
Name Type Argument Description optionsobject <optional>
An optional configuration object.
Properties of
options:Name Type Argument Description heightnumber <optional>
The height of the cylinder as a single positive number, defaults to 1.
botRadiusnumber <optional>
The bottom radius of the cylinder as a single positive number, defaults to 1.
topRadiusnumber <optional>
The top radius of the cylinder as a single positive number, defaults to
botRadius.originArray.<number> <optional>
The [x,y,z] position of the center of the cylinder, defaults to [0,0,0].
segmentsnumber <optional>
The number of segments used to approximate the cylinder [3 to 1800], defaults to 18.
centeredboolean <optional>
Whether or not the cylinder is centered at the origin rather that it being on its base, defaults to false.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
const cylinder = PD.Solid.cylinder({ origin: [ 0, 0, 0 ], topRadius: 250.0, botRadius: 250.0, height: 1200.0, centered: false, segments: 16 }); -
extrude(options) <static>
-
Construct a solid by extruding 2D shape(s).
Parameters:
Name Type Description optionsobject A configuration object.
Properties of
options:Name Type Argument Description shapesArray.<Array.<Array.<number>>> An array of one or more 2D shapes to extrude.
heightnumber <optional>
An optional height of the extrusion as a single positive number, defaults to 1.
segmentsnumber <optional>
An optional number of extra vertical segments along the extrusion [0 to 1800], defaults to 0.
twistAnglenumber <optional>
An optional amount of rotational twist about the extrusion axis in decimal degrees, defaults to 0.
topScaleArray.<number> <optional>
An optional [sx,sy] scale factor for the top, where [0,0] produces a cone and [1,1] produces a cylinder, defaults to [1,1].
translateArray.<number> <optional>
An optional [dx,dy,dz] translation vector of the base from the origin, defaults to [0,0,0].
centeredboolean <optional>
Whether or not the extrusion is centered at the origin rather that it being on its base, defaults to false.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
const extrusion = PD.Solid.extrude({ shapes: [ [ // Shape 1. [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ] ] ], centered: true, height: 3 }); -
extrudeAperture(innerContour, outerContour, height) <static>
-
Extrudes a planar polygon in the opposite direction of its surface normal.
Parameters:
Name Type Description innerContourArray.<Array.<number>> The inner contour of the aperture defined by [x,y,z] vector arrays.
outerContourArray.<Array.<number>> The outer contour of the aperture defined by [x,y,z] vector arrays.
heightnumber The height of the vertical extrusion.
-
extrudePolyline(polyline, vector, botOffset, topOffset [, reverse]) <static>
-
Extrudes a planar polygon in the opposite direction of its surface normal.
^ _+--|---------+ _.-' : _| / :\ _.-' ___|_|/ : \ +' 3- - - - - - 2_.+ |'. . ' __..--'' | | .'. __..--'' ' | 4 '+'' _.1 '. | __..--'' '. | __..--'' '0''Parameters:
Name Type Argument Description polylinePD.Polyline The polyline to extrude.
vectorTHREE.Vector3 The normalised direction to extrude the polyline in.
botOffsetnumber The distance to the
bottomalong the extrusion vector, defaults to 0.0.topOffsetnumber The distance to the
topalong the extrusion vector, defaults to 1000mm or 3' (36").reverseboolean <optional>
Whether or not to reverse each polygon, defaults to false.
-
extrudeProfile(profile, base, height) <static>
-
Extrudes a planar polygon in the opposite direction of its surface normal.
Parameters:
Name Type Description profileArray.<Array.<number>> A closed contour defined by [x,y,z] vector arrays.
basenumber The base height of the vertical extrusion.
heightnumber The height of the vertical extrusion.
-
fromBRep(brep) <static>
-
Construct a new solid from a
PD.BRep.If the BRep does not contain a manifold shape, the resulting solid will be empty. You can test for a valid solid by checking the
PD.Solid#isEmptymethod.Parameters:
Name Type Description brepPD.BRep The BRep containing triangulated faces.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
/// Create a PD.BRep. /// Note that BRep must be triangulated and manifold. /// If not, the resulting solid will be empty. const brep = new PD.BRep(); /// ... Add vertices and facets to BRep... /// Convert the PD.BRep to a PD.Solid. const solid = PD.Solid.fromBRep(brep); if (!solid.isEmpty()) { /// Do something with the solid... } -
fromBufferGeometry(geometry) <static>
-
Construct a new solid from a
THREE.BufferGeometry.If the buffer geometry does not contain a manifold shape, the resulting solid will be empty. You can test for a valid solid by checking the
PD.Solid#isEmptymethod.Parameters:
Name Type Description geometryTHREE.BufferGeometry The buffer geometry to convert.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
const geometry = new THREE.BufferGeometry(); /// ... Add vertices, indices, normals, colors, etc to geometry... const solid = PD.Solid.fromBufferGeometry(geometry); if (!solid.isEmpty()) { /// Do something with the solid... } -
fromShell(shell) <static>
-
Construct a new solid from a
PD.Shell.If the shell does not contain a manifold shape, the resulting solid will be empty. You can test for a valid solid by checking the
PD.Solid#isEmptymethod.Parameters:
Name Type Description shellPD.Shell The shell containing triangulated facets.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
/// Create a PD.Shell. /// Note that shell must be triangulated and manifold. /// If not, the resulting solid will be empty. const shell = new PD.Shell(); /// ... Add vertices and facets to shell... /// Convert the PD.Shell to a PD.Solid. const solid = PD.Solid.fromShell(shell); if (!solid.isEmpty()) { /// Do something with the solid... } -
fromThreeMesh(mesh) <static>
-
Construct a new solid from a
THREE.Mesh.If the mesh geometry does not contain a manifold shape, the resulting solid will be empty. You can test for a valid solid by checking the
PD.Solid#isEmptymethod.Parameters:
Name Type Description meshTHREE.Mesh The triangulated mesh to convert.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
/// Create a THREE.Mesh. /// Note that mesh geometry must be triangulated and manifold. /// If not, the resulting solid will be empty. const threeMesh = new THREE.Mesh(geometry, material); /// Convert the THREE.Mesh to a PD.Solid. const solid = PD.Solid.fromThreeMesh(threeMesh); if (!solid.isEmpty()) { /// Do something with the solid... } -
intersect(solids) <static>
-
Returns a new solid as the intersection of all the given solids.
None of the given CSG solids are modified by this method.
intersect([A,B]) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+Parameters:
Name Type Description solidsArray.<PD.Solid> An array of two or more CSG solids to intersect.
Returns:
Returns a new solid or
nullif intersection failed.- Type
- PD.Solid | null
-
logError(action, error) <static>
-
Logs an error message.
Parameters:
Name Type Description actionstring The action being performed when the error occurred.
errorstring The error message to log.
-
revolve( [options]) <static>
-
Construct a solid by revolving 2D shape(s).
Parameters:
Name Type Argument Description optionsobject <optional>
An optional configuration object.
Properties of
options:Name Type Argument Description shapesArray.<Array.<Array.<number>>> <optional>
An array of one or more 2D shapes to revolve.
segmentsnumber <optional>
The number of rotational segments [3 to 1800], defaults to 18.
anglenumber <optional>
The amount of rotation in decimal degrees, defaults to 360.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
const revolution = PD.Solid.revolve({ shapes: [ [ // Shape 1. [ 0, -10 ], [ 1, -5 ], [ 1, 5 ], [ 1.5, 7.5 ] ] ], centered: true, height: 3 }); -
sphere( [options]) <static>
-
Construct a solid sphere.
Parameters:
Name Type Argument Description optionsobject <optional>
An optional configuration object.
Properties of
options:Name Type Argument Description originArray.<number> <optional>
The [x,y,z] position of the center of the sphere, defaults to [0,0,0].
segmentsnumber <optional>
The number of segments used to approximate the sphere [3 to 1800], defaults to 18.
sizenumber | Array.<number> <optional>
The radius of the sphere in each axis, as a single number or [x,y,z] vector array, defaults to 1.
Returns:
Returns a new CSG solid.
- Type
- PD.Solid
Example
const sphere = PD.Solid.sphere({ origin: [ 0, 0, 0 ], size: [ 1, 1.5, 2 ], segments: 16 }); -
subtract(solids) <static>
-
Returns a new solid as the difference of all subsequent solids in the array from the first solid.
None of the given CSG solids are modified by this method.
subtract([A,B]) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+Parameters:
Name Type Description solidsArray.<PD.Solid> An array of two or more CSG solids to subtract.
Returns:
Returns a new solid or
nullif subtraction failed.- Type
- PD.Solid | null
-
union(solids) <static>
-
Returns a new solid as the union of all the given solids.
None of the given CSG solids are modified by this method.
union([A,B]) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+Parameters:
Name Type Description solidsArray.<PD.Solid> An array of two or more CSG solids to union.
Returns:
Returns a new solid or
nullif union failed.- Type
- PD.Solid | null