Class: OCC

PD. OCC


new OCC()

Contains lower-level methods than PD.CADfor generating and operating on primitive shapes within OpenCascade.

This class is also exposed as just OCC within the built-in code editor panel of each framework application that uses it.

The methods in this class do the actual low-level work of interfacing with the OpenCascade module and the raw geometry it creates. They provide the engine that sits behind the higher-level methods in PD.CAD, many of which are simply wrappers that marshal arguments and cache calls to the corresponding methods in this class, and manage the final CAD model.

You can use the lower-level methods in this class directly to create interim geometry, but it will not be cached and will not become part of the final model until you specifically use the PD.CAD.add method to add them. You can also use the PD.CAD.remove method to remove shapes from the CAD model.

Unlike shape generation methods within PD.CAD, the methods in this class take a single configuration object as their primary argument and return a shape, which may be a transformed copy of a source shape or a compound assembly of multiple shapes. The properties of the configuration object provide the inputs and data required for each method. This allows these methods to be used directly with parsed JSON data, where the "type" property of each encapsulated JSON object is basically the method name. This greatly simplifies both the creation and parsing of JSON representations of complex constructive geometry.

Author:
  • drajmarsh

Methods


chamfer( [config]) <static>

Applies a flat 45deg chamfer to one or more edges in a shape.

For simple chamfers all at the same size, the config.edges array should contain a flat list of edge indices and the distance value should give the size size of the chamfer to use on those edges.

If you want to chamfer different edges with different distances, calling this method more than once is a very inefficient way of doing it and makes keeping track of the edges to chamfer almost impossible. Instead, you can include multiple arrays within the config.edges property, ensuring that each array starts with the required chamfer distance and is followed by one or more edge indices to chamfer at that distance, as shown in the third example below.

If you want to chamfer different edges with different sizes, calling this method more than once is a very inefficient way of doing it and makes keeping track of the edges indexes after each iteration almost impossible. Instead, you can include the config.distance property as an array of size/edges arrays, ensuring that each array starts with the required size and is followed by one or more edge indices to chamfer at that size, as shown in the third example below.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shape oc.TopoDS_Shape <optional>

The shape to chamfer edges within.

distance number | Array.<Array.<number>> <optional>

The distance of the chamfer, defaults to 0.

edges Array.<number> <optional>

An array of edge indices to chamfer, defaults to all edges.

Returns:

Returns the chamfered solid, or the given shape if no matching edges were found.

Type
oc.TopoDS_Solid
Example
/// Chamfer all edges.
const chamfer1 = PD.OCC.chamfer({
     shape: PD.OCC.cuboid({ size: [ 2000, 2000, 1000 ] }),
     distance: 200
});

/// Chamfer 4 vertical edges.
const chamfer2 = PD.OCC.chamfer({
     shape: PD.OCC.cuboid({ size: [ 2000, 2000, 1000 ] }),
     edges: [ 0, 2, 4, 6 ],
     distance: 200
});

/// Chamfer with different sizes.
const chamfer3 = PD.OCC.chamfer({
     shape: PD.OCC.cuboid({ size: [ 2000, 2000, 1000 ] }),
     distance: [
         [ 200, 0, 2, 4,  6 ],
         [ 100, 1, 5, 9, 11 ]
     ]
});

checkToConvertFromJSON(shapes [, ignoreSolids]) <static>

Checks for JSON data and converts to OpenCascade shapes.

Parameters:
Name Type Argument Description
shapes Array.<object> | Array.<oc.TopoDS_Shape>

A JSON or shape array.

ignoreSolids boolean <optional>

When true, solids will not be converted, defaults to false.

Returns:

Returns TopoDS_Shape(s).

Type
oc.TopoDS_Shape | Array.<oc.TopoDS_Shape>

combine( [config]) <static>

Combines the given shape(s) into a single compound shape.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes Array.<oc.TopoDS_Shape> <optional>

An array of two or more shapes to combine.

Returns:

Returns the compound shape.

Type
oc.TopoDS_Shape

compoundShell( [config]) <static>

Construct a compound shell shape from a series of vertices and faces.

A compound shell is basically just a collection of faces without any connection information such as shared vertices or edges. Use this if you just want to visualise a shape as it is quick to assemble and does not require any processing. Obviously you will not be able to convert it to a solid for use in CSG.

There are several variants of point/face meshes, and this is one of the simplest. It consists of a flat list of point in its vertices property, together with a list of arrays in its faces property, each storing the ordinal indices of each vertex in the points list that forms the outer boundary of a face. Each face only has a single boundary so cannot contain holes or separate contours. As a result, it is mainly used to efficiently store polyhedra and simple manifold shapes.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
vertices Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the corners and edges of the shape.

faces Array.<Array.<number>> | Array.<object> <optional>

An array of faces with boundaries containing ordinal indexes of the points that make up the face.

Returns:

Returns a shape sewn together from multiple faces.

Type
oc.TopoDS_Shape

cone( [config]) <static>

Construct a conical primitive shape.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
pos Array.<number> <optional>

An [x,y,z] vector array defining the shape center, defaults to the origin.

axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

radiusBot number <optional>

The base radius of the shape, defaults to 1000mm (1m).

radiusTop number <optional>

The top radius of the shape, defaults to 0 (a point).

height number <optional>

The height of the shape, defaults to 1000mm (1m).

fillet number <optional>

An optional fillet radius for the base, defaults to 0 (no fillet).

angle number <optional>

An optional angle in radians (0 to 2PI), defaults to 2PI.

Returns:

Returns a conical shape.

Type
oc.TopoDS_Shape

cuboid( [config]) <static>

Construct a rectangular prism primitive shape.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
pos Array.<number> <optional>

An [x,y,z] vector array defining the start position of the shape.

axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

size Array.<number> <optional>

An [x,y,z] vector array defining the size of the shape in each axis, defaults to [1000,1000,1000].

min Array.<number> <optional>

An [x,y,z] vector array defining the bottom-left corner.

max Array.<number> <optional>

An [x,y,z] vector array defining the top-right corner.

centered boolean <optional>

An optional flag indicating that the shape should be centered on its pos/min position rather than at its bottom-left, defaults to false.

centerXY boolean <optional>

An optional flag indicating that the shape should be centered on its X and Y pos/min position rather than at its bottom-left, defaults to false.

fillet number | Array.<number> <optional>

An optional radius or [bot,sides,top] array for filleting edges and corners, defaults to 0 (no fillet).

Returns:

Returns a rectangular prism shape.

Type
oc.TopoDS_Shape
Example
/// Define just the size.
PD.CAD.add(PD.OCC.cuboid({
    size: [ 1500, 2000, 3000 ]
}));

/// Define by min/max.
PD.CAD.add(PD.OCC.cuboid({
    min: [ -750, -1000,    0 ],
    max: [  750,  1000, 3000 ]
}));

/// Define fillet radii, etc.
PD.CAD.add(PD.OCC.cuboid({
    size: [ 1500, 2000, 3000 ],
    axis: [ 0.5773503, 0.5773503, 0.5773503 ],
    fillet: [ 50, 500, 50 ],
    centerXY: true
 }));

cylinder( [config]) <static>

Construct a cylindrical primitive shape.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
pos Array.<number> <optional>

An [x,y,z] vector array defining the shape center, defaults to the origin.

axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

height number <optional>

The height of the shape, defaults to 1000mm (1m).

radius number <optional>

The base radius of the shape, defaults to 1000mm (1m).

fillet number | Array.<number> <optional>

An optional radius or [bot,top] array for filleting edges and corners, defaults to 0 (no fillet).

chamfer number | Array.<number> <optional>

An optional radius or [bot,top] array for chamfering edges and corners, defaults to 0 (no chamfer).

angle number <optional>

An optional angle in radians (0 to 2PI), defaults to 2PI.

Returns:

Returns a cylindrical shape.

Type
oc.TopoDS_Shape

edge( [config]) <static>

Construct a straight linear edge between two points.

Edges are lines typically used to represent the connection or intersection between two faces. They may be straight lines or complex curves, and can be connected together to form wires.

If the config.points array contains more than two points, only the first two will actually be used in the edge.

Parameters:
Name Type Argument Description
config PD.OCC.ITwoPoints <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of two [x,y,z] vector arrays defining the vertices at each end.

Returns:

Returns a linear edge.

Type
oc.TopoDS_Edge

edgeArc( [config]) <static>

Construct an edge as a circular arc defined by three points.

Edges are lines typically used to represent the connection or intersection between two faces. They may be straight lines or complex curves, and can be connected together to form wires.

Parameters:
Name Type Argument Description
config PD.OCC.IArcPath <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of three [x,y,z] vector arrays defining the start, ptOnArc and end points.

Returns:

Returns a edge arc.

Type
oc.TopoDS_Edge

edgeBSpline( [config]) <static>

Construct a BSpline curved edge from control points.

Edges are lines typically used to represent the connection or intersection between two faces. They may be straight lines or complex curves, and can be connected together to form wires.

Parameters:
Name Type Argument Description
config PD.OCC.ICurvePoints <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the control points of the bspline.

closed boolean <optional>

Whether or not the edge forms a closed loop.

Returns:

Returns a curved edge.

Type
oc.TopoDS_Edge

edgeBezier( [config]) <static>

Construct a Bezier curved edge from control points.

Edges are lines typically used to represent the connection or intersection between two faces. They may be straight lines or complex curves, and can be connected together to form wires.

Parameters:
Name Type Argument Description
config PD.OCC.ICurvePoints <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the control points of the bezier curve.

closed boolean <optional>

Whether or not the edge forms a closed loop.

Returns:

Returns a curved edge.

Type
oc.TopoDS_Edge

edgeCircle( [config]) <static>

Construct a closed circular edge.

Edges are lines typically used to represent the connection or intersection between two faces. They may be straight lines or complex curves, and can be connected together to form wires.

Parameters:
Name Type Argument Description
config PD.OCC.ICentreRadius <optional>

A configuration object.

Properties of config:
Name Type Argument Description
center Array.<number> <optional>

An [x,y,z] vector array defining the center of the circle.

radius number <optional>

The radius of the circle, defaults to 1000mm (1m).

Returns:

Returns a circular edge.

Type
oc.TopoDS_Edge

extrude( [config]) <static>

Extrudes a flat polygonal face into a shape.

To extrude the shape, you can provide either an extrusion vector with absolute distances for each axis in the config.vector property, or a direction and height in the config.axis and config.height properties. The extrusion vector will be used in preference to and axis and distance, so you should include only one of the options rather than both.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
face oc.TopoDS_Face <optional>

An optional closed face to extrude.

axis Array.<number> | number <optional>

An [x,y,z] vector array defining the direction to extrude in, or a number (X:1, Y:2, Z:3), defaults to the +Z axis.

height number <optional>

The distance to extrude in the local Z axis, defaults to 1000mm (1m).

vector Array.<number> <optional>

An [x,y,z] vector array defining the absolute distances to extrude in each axis.

Returns:

Returns the extruded shape.

Type
oc.TopoDS_Shape

extrudeAndRotate( [config]) <static>

Extrude and rotate a wire into a 3D shape.

When using this method, you should include either a degrees value or an angle value. If you include both, the degrees will be used in preference to the angle value.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
wire oc.TopoDS_Wire <optional>

A wire to rotate and extrude.

axis Array.<number> | number <optional>

An [x,y,z] vector array defining the direction of the shape axis, or a number (X:1, Y:2, Z:3), defaults to the +Z axis.

height number <optional>

The height of the extrusion, defaults to 1000mm (1m).

degrees number <optional>

The angle of rotation in degrees, defaults to 0.

angle number <optional>

The angle of rotation in radians, defaults to 0.

steps number <optional>

The number of steps in the twisted rotation, defaults to 20.

Returns:

Returns the rotated twisted shape(s).

Type
oc.TopoDS_Shape

face( [config]) <static>

Construct a face from points or wires.

Faces are used to represent the surfaces of a shape. They are formed by connecting one or more wires together to form a boundary on a surface that may be curved or flat.

To create a face, you must pass either an array of wires in the config.wires property, or an array of [x,y,z] vector array coordinates in the config.points property. The list of wires will be used in preference to points, so you should only include one or the other rather than both.

Using config.points creates a simple face with a single outer boundary. For more complex faces with holes and/or multiple boundaries, you can use the PD.CAD.Shape#polygon method with config.contours or build the boundaries using a PD.CAD.Path instance.

Using config.wires, you can add internal holes to the face by including closed wires that are entirely within the outer boundary wire. You can also add additional boundaries (like multiple islands) by including closed wires entirely outside any other boundary wire(s).

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the face boundary.

wires Array.<oc.TopoDS_Wire> <optional>

An array of wires to connect together to form the face boundary.

Returns:

Returns a new face.

Type
oc.TopoDS_Face

facetedShell( [config]) <static>

Construct a shell shape sewn together from a series of facets.

This method only deals with faceted data, which means that each face is defined by or contains an array of [x,y,z] vector arrays giving the positions of each corner of its boundaries.

Each entry in the facets array is an object that has an optional plane property with the [a,b,c,d] plane equation of the face and a non-optional boundaries property containing one or more contours of [x,y,z] vertex positions. If there are multiple contours, the first will be considered the outer boundary and any subsequent contours will be treated as holes within the face.

To be valid, each boundary and hole array must contain at least three (3) or more planar vertex indices defining each of its corners.

If you have data in which vertices are given in a separate array and where each face is an ordinal index, you can use the OCC.indexedShell method instead of this one.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
facets Array.<object> <optional>

An array of facets with boundary contours defined by sequential [x,y,z] vector arrays.

Returns:

Returns a shape sewn together from multiple faces.

Type
oc.TopoDS_Shape

fillet( [config]) <static>

Applies a rounded fillet to one or more edges in a shape.

For simple fillets with the same radius, the config.edges array should contain a flat list of edge indices and the radius value should give the radius to use on those edges.

If you want to fillet different edges with different radii, calling this method more than once is a very inefficient way of doing it and makes keeping track of the edges indexes after each iteration almost impossible. Instead, you can include the config.radius property as an array of radius/edges arrays, ensuring that each array starts with the required radius and is followed by one or more edge indices to fillet at that radius, as shown in the third example below.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shape oc.TopoDS_Shape <optional>

The shape to fillet edges within.

radius number | Array.<Array.<number>> <optional>

The radius of the fillet, defaults to 0.

edges Array.<number> <optional>

An array of edge indices to fillet, defaults to all edges.

Returns:

Returns the filleted solid, or the given shape if no matching edges were found.

Type
oc.TopoDS_Shape
Example
/// Fillet all edges.
const fillet1 = PD.OCC.fillet({
     shape: PD.OCC.cuboid({ size: [ 2000, 2000, 1000 ] }),
     radius: 200
});

/// Fillet 4 vertical edges.
const fillet2 = PD.OCC.fillet({
     shape: PD.OCC.cuboid({ size: [ 2000, 2000, 1000 ] }),
     edges: [ 0, 2, 4, 6 ],
     radius: 200
});

/// Fillet with different radii.
const fillet3 = PD.OCC.fillet({
     shape: PD.OCC.cuboid({ size: [ 2000, 2000, 1000 ] }),
     radius: [
         [ 200, 0, 2, 4,  6 ],
         [ 100, 1, 5, 9, 11 ]
     ]
});

getEdge(shape [, index]) <static>

Extracts a particular edge from within a shape.

Parameters:
Name Type Argument Description
shape oc.TopoDS_Shape

The shape to extract the edge from.

index number <optional>

The ordinal index of the edge within the shape, defaults to 0.

Returns:

Returns the edge at the given index, or the given shape if no matching edge was found.

Type
oc.TopoDS_Edge | oc.TopoDS_Shape

getEdgeCount(shape) <static>

Retrieve the number of edges within a shape.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to examine.

Returns:

Returns the number of edges found.

Type
number

getFace(shape [, index]) <static>

Extracts a particular face from within a shape.

Parameters:
Name Type Argument Description
shape oc.TopoDS_Shape

The shape to extract the face from.

index number <optional>

The ordinal index of the face within the shape, defaults to 0.

Returns:

Returns the solid at the given index, or the given shape if no matching solid was found.

Type
oc.TopoDS_Face | oc.TopoDS_Shape

getFaceCount(shape) <static>

Retrieve the number of faces within a shape.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to examine.

Returns:

Returns the number of faces found.

Type
number

getFaceTriangulation(shape, maxDeviation) <static>

Compute the triangular tesselation from a shape.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to convert.

maxDeviation number

The tolerance for linear and angle deflection, defaults to 1.0.

Returns:

Returns the faces and edges that make up the shape.

Type
Array.<Array>

getOpenCascadeInstance() <static>

Retrieve the current OpenCascade WebAssembly instance being used.

Returns:

Returns the current OpenCascade instance.

Type
object

getSolid(shape [, index]) <static>

Extracts a particular solid from within a compound shape.

Parameters:
Name Type Argument Description
shape oc.TopoDS_Shape

The shape to extract the solid from.

index number <optional>

The ordinal index of the solid within the shape, defaults to 0.

Returns:

Returns the solid at the given index, or the given shape if no matching solid was found.

Type
oc.TopoDS_Shape | oc.TopoDS_Solid

getSolidCount(shape) <static>

Retrieve the number of solids within a compound shape.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to examine.

Returns:

Returns the number of solid found.

Type
number

getVertex(shape [, index]) <static>

Extracts a particular vertex from within a shape.

Parameters:
Name Type Argument Description
shape oc.TopoDS_Shape

The shape to extract the vertices from.

index number <optional>

The ordinal index of the vertex within the shape, defaults to 0.

Returns:

Returns the vertex at the given index, or the given shape if no matching vertex was found.

Type
oc.TopoDS_Vertex | null

getVertexCount(shape) <static>

Retrieve the number of edges within a shape.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to examine.

Returns:

Returns the number of edges found.

Type
number

getVertexPos(vertex) <static>

Extracts the vertex position as an [x,y,z] vector array.

Parameters:
Name Type Description
vertex oc.TopoDS_Vertex

The vertex to get the coordinates from.

Returns:

Returns the coordinates as an [x,y,z] vector array.

Type
Array.<number>

getWire(shape [, index]) <static>

Extracts a particular wire from within a shape.

Parameters:
Name Type Argument Description
shape oc.TopoDS_Shape

The shape to extract the wire from.

index number <optional>

The ordinal index of the wire within the shape, defaults to 0.

Returns:

Returns the wire at the given index, or the given shape if no matching wire was found.

Type
oc.TopoDS_Wire | oc.TopoDS_Shape

getWireCount(shape) <static>

Retrieve the number of wires within a shape.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to examine.

Returns:

Returns the number of wires found.

Type
number

hollow( [config]) <static>

Creates a hollowed out solid from a closed shell.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shape oc.TopoDS_Shape <optional>

The shape to hollow out.

faces Array.<oc.TopoDS_Face> <optional>

An array or one or more faces to hollow from.

thickness number <optional>

The side wall thickness, defaults to 250mm (0.25m).

tolerance number <optional>

The tolerance to use when hollowing, defaults to 0.1.

Returns:

Returns the hollowed out shape.

Type
oc.TopoDS_Shape

hull( [config]) <static>

Construct a convex hull solid shape from a set of points or shapes.

This method will preference points over shapes when creating the hull, so you should provide only one or the other rather than both. To support some JSON variants, this method allows the use of config.vertices as an alias for config.points.

When using shapes, the method has to extract vertices and sample points over each curved face in the shape, so you should provide a config.maxDeviation argument to control the granularity of this surface sampling.

The config.tolerance value applies to both and affects the sewing together of faces when generating the solid shell.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the vertices the shape.

shapes oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> <optional>

A shape or array of shapes to create the hull from.

tolerance number <optional>

The sewing tolerance when converting hull to a shape, defaults to 0.1.

Returns:

Returns a solid shape sewn from multiple faces.

Type
oc.TopoDS_Shape

hullChain( [config]) <static>

Construct a chain of convex hulls from a set of shapes.

The method has to extract vertices and sample points over each curved face in each shape, so you should provide a config.maxDeviation argument to control the granularity of this surface sampling.

The config.tolerance value affects the sewing together of faces when generating the solid shell(s).

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> <optional>

A shape or array of shapes to create the hull chain from.

maxDeviation number <optional>

The mesh resolution when point sampling shape surfaces, defaults to 5.

tolerance number <optional>

The sewing tolerance when converting hull to a shape, defaults to 0.1.

Returns:

Returns a solid shape sewn from multiple hulls.

Type
oc.TopoDS_Shape

indexedShell( [config]) <static>

Construct a shell shape sewn together from a series of indexed facets.

This method sews together a collection of indexed planar faces into a TopoDS_Shape. It does this by making planar TopoDS_Wire objects out of each facet boundary, then making TopoDS_Face objects out of each wire, and then sewing the faces together into a TopoDS_Shell.

This method only deals with indexed face data, which means that all the vertices in the shape are stored in one array (points) and all the faces in another (faces). The vertices must all be [x,y,z] vector arrays and each face is defined by or contains an array of ordinal indexes of each vertex that make up its boundaries.

Thus, each entry in the faces array may be either an array of vertex indices or an object containing a boundaries property that is array. If the boundaries array contain one or more sub-arrays of vertex indices, then the first will be considered as the outer boundary and any subsequent boundaries treated as holes within the face. If the boundary is a flat array of vertex indices, it will be considered as an outer boundary with no holes.

To be valid, each boundary and hole array must contain at least three (3) or more planar vertex indices defining each of its corners.

If you have data in which vertices are not given separately, but where each face is a list of [x,y,z] vector arrays, use the OCC.facetedShell method instead of this one.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the corners and edges of the shape.

faces Array.<Array.<number>> | Array.<object> <optional>

An array of faces with boundaries containing ordinal indexes of the points that make up the face.

tolerance number <optional>

An optional face sewing tolerance, defaults to 1mm.

Returns:

Returns a shell shape sewn together from multiple faces.

Type
oc.TopoDS_Shape

intersect( [config]) <static>

Computes the intersection of a set of shapes.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes Array.<oc.TopoDS_Shape> <optional>

An array of shapes to intersect.

tolerance number <optional>

The tolerance to use when intersecting, defaults to 0.1.

keepEdges boolean <optional>

Whether or not to keep the original edge(s) in the shape, defaults to false.

Returns:

Returns the intersection shape.

Type
oc.TopoDS_Shape

isFacePlanar(face [, tolerance]) <static>

Determines if the face is planar or not.

Parameters:
Name Type Argument Description
face oc.TopoDS_Face

The face to check if planar.

tolerance number <optional>

The tolerance to use when checking, defaults to 0.1.

Returns:

Returns true if the face is planar, false if it is curved.

Type
boolean

isValidCompositeSolid(shape) <static>

Checks if a shape is a non-null instance of TopAbs_COMPSOLID.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

isValidCompound(shape) <static>

Checks if a shape is a non-null instance of TopAbs_COMPOUND.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

isValidEdge(shape) <static>

Checks if a shape is a non-null instance of TopAbs_EDGE.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

isValidFace(shape) <static>

Checks if a shape is a non-null instance of TopAbs_FACE.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

isValidShell(shape) <static>

Checks if a shape is a non-null instance of TopAbs_SHELL.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

isValidSolid(shape) <static>

Checks if a shape is a non-null instance of TopAbs_SOLID.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

isValidType(shape, type) <static>

Checks if a shape is a non-null instance of the given type.

This method first checks the shape is not null and then calls its oc.TopoDS_Shape#ShapeType method to see if it matches the given type.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check.

type oc.TopAbs_ShapeEnum

The shape type to check for.

Returns:

Returns true if the shape is of the given type, otherwise false.

Type
boolean

isValidVertex(shape) <static>

Checks if a shape is a non-null instance of TopAbs_VERTEX.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

isValidWire(shape) <static>

Checks if a shape is a non-null instance of TopAbs_WIRE.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to check the type of.

Returns:

Returns true if the shape is of the right type, otherwise false.

Type
boolean

iterateEdges(shape, callback) <static>

Invokes a callback function on all the edges in a shape.

The callback function will be invoked with two arguments, the first being the item found and the second being its ordinal index.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to iterate.

callback function

The callback function to invoke.

Returns:

Returns the number of items found.

Type
number

iterateFaces(shape, callback) <static>

Invokes a callback function on all the faces in a shape.

The callback function will be invoked with two arguments, the first being the item found and the second being its ordinal index.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to iterate.

callback function

The callback function to invoke.

Returns:

Returns the number of items found.

Type
number

iterateShells(shape, callback) <static>

Invokes a callback function on all the shells in a shape.

The callback function will be invoked with two arguments, the first being the item found and the second being its ordinal index.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to iterate.

callback function

The callback function to invoke.

Returns:

Returns the number of items found.

Type
number

iterateSolids(shape, callback) <static>

Invokes a callback function on all the solids in a shape.

The callback function will be invoked with two arguments, the first being the item found and the second being its ordinal index.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to iterate.

callback function

The callback function to invoke.

Returns:

Returns the number of items found.

Type
number

iterateVertices(shape, callback) <static>

Invokes a callback function on all the vertices in a shape.

The callback function will be invoked with two arguments, the first being the item found and the second being its ordinal index.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to iterate.

callback function

The callback function to invoke.

Returns:

Returns the number of items found.

Type
number

iterateWires(shape, callback) <static>

Invokes a callback function on all the wires in a shape.

The callback function will be invoked with two arguments, the first being the item found and the second being its ordinal index.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to iterate.

callback function

The callback function to invoke.

Returns:

Returns the number of items found.

Type
number

loft( [config]) <static>

Lofts between a set of two or more wires.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
wires Array.<oc.TopoDS_Wire> <optional>

The set of two or more wires to loft between.

Returns:

Returns the lofted shape.

Type
oc.TopoDS_Shape

makeFacesFromWires(wires [, allowNonPlanar]) <static>

Generates one or more faces from a set of properly oriented wires.

If the face is non-planar and allowNonPlanar is true, the face will be converted into a fan of triangular faces about its center.

Parameters:
Name Type Argument Description
wires Array.<oc.TopoDS_Wire>

An array of one or more wires defining face contours.

allowNonPlanar boolean <optional>

A flag to enable/disable converting non-planar faces to multiple triangular faces, defaults to true.

Returns:

Returns an array of one or mor faces made from the wires.

Type
Array.<oc.TopoDS_Face>

makeTriangleFanFaces(wire) <static>

Generates one or more triangular faces from the geometric center and edges in a wire.

Parameters:
Name Type Description
wire oc.TopoDS_Wire

A wire containing one or more edges.

Returns:

Returns one or more faces made from edges in the wire.

Type
Array.<oc.TopoDS_Face>

makeWiresFromContours(contours [, vertices]) <static>

Construct an array of wires from one or more boundary contours that store actual vertex positions.

If the face boundary array contains one or more arrays of [x,y,z] vertices then the first will be considered the outer boundary and any subsequent boundaries will be treated as holes within the face. If the face boundary is a flat array of [ x,y,z] vertices, it will be considered as an outer boundary with no holes.

To be valid, each boundary and hole array must containing at least three (3) or more planar [x,y,z] vertices defining each of its corners.

Parameters:
Name Type Argument Description
contours Array.<Array.<Array.<number>>>

An array of boundary contours, each containing 3 or more [x,y,z] vector arrays defining the face outlines.

vertices Array.<Array.<number>> <optional>

An optional array of [x,y,z] vector arrays to use if contours use vertex indices not actual vertexes.

Returns:

Returns a face created from multiple wires.

Type
Array.<oc.TopoDS_Wire>

mirror( [config]) <static>

Mirrors the given shape(s) around a given axis.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> <optional>

A shape or array of shapes to rotate.

axis Array.<number> | number <optional>

An [x,y,z] vector array defining the direction of the shape axis, or a number (X:1, Y:2, Z:3), defaults to XZ axis.

about Array.<number> <optional>

An [x,y,z] vector array defining the position of the axis, defaults to the origin.

Returns:

Returns the mirrored shape(s).

Type
oc.TopoDS_Shape

move( [config]) <static>

Translates the given shape(s) by a relative vector.

This method is simply an alias for the OCC.translate method.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> <optional>

A shape or array of shapes to translate.

offset Array.<number> <optional>

An [x,y,z] vector array defining the translation offset in each axis.

Returns:

Returns the translated shape(s).

Type
oc.TopoDS_Shape

offset( [config]) <static>

Offsets the edges and faces of a shape by the given distance.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shape oc.TopoDS_Shape <optional>

The shape to offset, which can also be a wire.

distance number <optional>

The distance to offset the shape by, defaults to 250mm (0.25m).

tolerance number <optional>

The tolerance to use when offsetting, defaults to 0.1.

Returns:

Returns the offset shape.

Type
oc.TopoDS_Shape

path2D( [config]) <static>

Construct a wire as a series of 2D path segments.

This method basically wraps a PD.CAD.Path instance and takes an array of segments that encapsulate the various generation methods it offers. Each segment requires a type property that corresponds to a method name in the path instance, as well as other properties that correspond to the arguments that method takes, as shown in the code example below.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
segments Array.<Array.<number>> <optional>

An array of segment definitions, as shown in the code example.

closed boolean <optional>

Whether or not the path forms a closed loop, defaults to false.

reverse boolean <optional>

Whether or not to reverse the path direction.

Returns:

Returns a flat closed polygonal face shape.

Type
oc.TopoDS_Wire
Example
const wire = PD.CAD.Shape.path2D({
     closed: false,
     reverse: false,
     segments: [
         {
             type: "moveTo",
             point: [ 0, -1000 ]
         },
         {
             type: "lineTo",
             point: [ 0, 0 ]
         },
         {
             type: "fillet",
             radius: 500
         },
         {
             type: "lineTo",
             point: [ 1000, 0 ]
         },
         {
             type: "arcTo",
             through: [ 1500, 500 ]
             point: [ 1000, 1000 ],
         },
         {
             type: "bezierTo",
             points: [
                 [ 0, 1000 ],
                 [ 0, 2000 ]
             ]
          },
         {
             type: "bsplineTo",
             points: [
                 [     0, 3000 ],
                 [  -500, 3500 ],
                 [ -1000, 3000 ],
                 [ -1500, 3500 ],
                 [ -2000, 3000 ]
             ]
          },
     ],
});

polygon( [config]) <static>

Construct a flat closed polygonal face from one or more boundary contours.

To create a polygonal face, you must pass either an array of contours in the config.contours property, or an array of [x,y,z] vector array coordinates in the config.points property. The list of contours will be used in preference to points, so you should only include one or the other rather than both.

Using config.points creates a simple polygon with a single outer boundary. For more complex faces with holes and/or multiple boundaries, use the config.contours property or build the boundaries using a PD.CAD.Path instance.

Using config.contours, you can add internal holes to the face by including closed boundaries that are entirely within the first contour, which ia always assumed to define the outer boundary of the polygon.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
contours Array.<Array.<Array.<number>>> <optional>

An array of boundary contours, each containing 3 or more [x,y,z] vector arrays defining the polygon outlines.

points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the polygon boundary.

Returns:

Returns a flat closed polygonal face.

Type
oc.TopoDS_Face

prism( [config]) <static>

Construct an extruded prism shape from a face or connected points.

You can define the base of the prism by either:

  • providing a single face to extrude in the config.face property,
  • providing an array of [x,y,z] coordinates in the config.points property,
  • or providing a radius and number of sides in the config.radius and config.sides properties.

The single face will be used in preference to points or sides. If no face is provided, the array of points will be used in preference to the radius and sides. Thus, you should only include the properties for one of these ways.

Using config.points creates a simple prism from a face with a single outer boundary. For more complex prisms with holes and/or multiple boundaries, you can use the PD.OCC#polygon method with config.contours or build the face boundaries using a PD.CAD.Path instance. You can use this method or the PD.OCC#extrude method to make the prism from the face.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

height number <optional>

The height of the shape, defaults to 1000mm (1m).

face oc.TopoDS_Face <optional>

An optional closed face to extrude into a prism.

points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the base shape of the prism.

sides number <optional>

The number of sides of the prism (3 to 256) when no face or points are provided, defaults to 8.

radius number <optional>

The radius of the prism when no face or points are provided, defaults to 1000mm (1m).

pos Array.<number> <optional>

An [x,y,z] vector array defining the center when no face or points are provided, defaults to [0,0,0].

Returns:

Returns a rectangular prism shape.

Type
oc.TopoDS_Shape
Example
const polygon = OCC.polygon({
    contours: [
        [ // Outer boundary.
            [ -3000.0, -2000.0, 0.0 ],
            [  3000.0, -2000.0, 0.0 ],
            [  3000.0,  2000.0, 0.0 ],
            [ -3000.0,  2000.0, 0.0 ]
        ],
        [ // Internal hole.
            [ -1000.0, -1000.0, 0.0 ],
            [  1000.0, -1000.0, 0.0 ],
            [  1000.0,  1000.0, 0.0 ],
            [ -1000.0,  1000.0, 0.0 ]
        ]
     ]
});

/// Define the face to use.
CAD.add(OCC.prism({
        axis: [ 0.5773503, 0.5773503, 0.5773503 ],
        face: polygon,
        height: 5000
    })
);

/// Define some boundary points.
CAD.add(OCC.prism({
        height: 5000,
        points: [
            [ -3000.0, -2000.0, 0.0 ],
            [  3000.0, -2000.0, 0.0 ],
            [  3000.0,  2000.0, 0.0 ],
            [ -3000.0,  2000.0, 0.0 ]
        ]
    })
);

/// Define radius and sides.
CAD.add(OCC.prism({
        axis: [ 0.5773503, 0.5773503, 0.5773503 ],
        height: 5000,
        radius: 2000,
        sides: 12
    })
);

processJSON(json) <static>

Parses a JSON geometry node.

Parameters:
Name Type Description
json object | Array

A parsed JSON object or array of objects.

Returns:

Returns a shape or null if json is invalid.

Type
oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> | null

progressOperation(level [, operation]) <static>

Check first if processing has been cancelled and, if not, format the operation and add it to the progress log.

The movement of the progress bar should not be affected by the current log level so, if the log level is less than the level of this operation, we still need to send undefined to the host application to increment it.

Parameters:
Name Type Argument Description
level level

The log level of the operation.

operation string <optional>

The name of the operation to log.

Throws:

Throws and error if process cancelled.

Type
Error

pyramid( [config]) <static>

Construct a pyramid primitive shape.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
pos Array.<number> <optional>

An [x,y,z] vector array defining the start position of the shape, defaults to [0,0,0].

axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

size Array.<number> <optional>

An [x,y,z] vector array defining the size of the shape in each axis, defaults [1000,1000,1000].

min Array.<number> <optional>

An [x,y,z] vector array defining the bottom-left extents.

max Array.<number> <optional>

An [x,y,z] vector array defining the top-right extents.

truncate number <optional>

A fractional top point truncation amount (0 to 1), defaults to 1.0.

centered boolean <optional>

An optional flag indicating that the shape should be centered on its pos/min position rather than at its bottom-left, defaults to false.

centerXY boolean <optional>

An optional flag indicating that the shape should be centered on its X and Y pos/min position rather than at its bottom-left, defaults to false.

fillet number | Array.<number> <optional>

An optional radius or [bot,sides,top] array for filleting edges and corners, defaults to 0 (no fillet).

Returns:

Returns a pyramidal shape.

Type
oc.TopoDS_Shape
Example
PD.CAD.add(PD.OCC.pyramid({
    size: [ 2000, 10000, 3000 ],
    fillet: [ 100, 200, 300 ],
    centerXY: true,
    truncateX: 0.5
}));

revolve( [config]) <static>

Revolves a shape by the given angle and direction.

When using this method, you should include either a degrees value or an angle value. If you include both, the degrees will be used in preference to the angle value.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shape oc.TopoDS_Shape <optional>

A shape to rotate.

axis Array.<number> | number <optional>

An [x,y,z] vector array defining the direction of the shape axis, or a number (X:1, Y:2, Z:3), defaults to the +Z axis.

about Array.<number> <optional>

An [x,y,z] vector array defining the revolution origin, defaults to the origin.

degrees number <optional>

The angle of rotation about the given axis in degrees, defaults to 0.

angle number <optional>

The angle of rotation about the given axis in radians, defaults to 0.

copy boolean <optional>

When true revolves a copy of the given shape, defaults to false.

Returns:

Returns the revolved shape.

Type
oc.TopoDS_Shape

rotate( [config]) <static>

Rotates shape(s) around an axis.

When using this method, you should include either a degrees value or an angle value. If you include both, the degrees will be used in preference to the angle value.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> <optional>

A shape or array of shapes to rotate.

axis Array.<number> | number <optional>

An [x,y,z] vector array defining the direction of the shape axis, or a number (X:1, Y:2, Z:3), defaults to Z axis.

about Array.<number> <optional>

An [x,y,z] vector array defining the rotation origin.

degrees number <optional>

The angle of rotation about the given axis in degrees, defaults to 0.

angle number <optional>

The angle of rotation about the given axis in radians, defaults to 0.

Returns:

Returns the rotated shape(s).

Type
oc.TopoDS_Shape

scale( [config]) <static>

Scales the given shape(s) from the origin.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> <optional>

A shape or array of shapes to scale.

scale number <optional>

A relative scale factor to apply in each axis.

Returns:

Returns the scaled shape(s).

Type
oc.TopoDS_Shape

shapeToMesh(shape, maxDeviation, fullShapeEdgeHashes, fullShapeFaceHashes) <static>

Converts a shape, or composite shape to a mesh.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to convert.

maxDeviation number

The tolerance for linear and angle deflection, defaults to 0.5.

fullShapeEdgeHashes object

An object containing edge hashes.

fullShapeFaceHashes object

An object containing face hashes

Returns:

Returns the faces and edges that make up the shape.

Type
Array.<Array>

shell( [config]) <static>

Construct a shell shape sewn together from facets.

This method tries to determine what format the facet data is in and then passes it to either the OCC.indexedShell or OCC.facetedShell methods for actual processing.

Both methods sew together a collection of planar faces into a TopoDS_Shape. It does this by making planar TopoDS_Wire objects out of each facet, then making TopoDS_Face objects out of each wire, and then sewing the faces together into a TopoDS_Shell.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An optional array of [x,y,z] vector arrays defining the corners and edges of the shape.

vertices Array.<Array.<number>> <optional>

An optional array of [x,y,z] vector arrays defining the corners and edges of the shape.

faces Array.<Array.<number>> | Array.<object> <optional>

An array of faces with boundaries containing ordinal indexes of the points that make up the face.

facets Array.<object> <optional>

An array of facets with boundary contours defined by sequential [x,y,z] vector arrays.

tolerance number <optional>

An optional face sewing tolerance, defaults to 1mm.

Returns:

Returns a shell shape sewn together from faces/facets.

Type
oc.TopoDS_Shape

shellToSolid(shape) <static>

Converts a shell shape to a solid shape.

When used with CSG, shells and solids produce different results. This method first checks if the given shape is a shell and, if so, returns a solid. If it is already a solid, it is just passed through.

If the shape is not a shell or solid, and cannot be converted to a solid, the method returns null.

Parameters:
Name Type Description
shape oc.TopoDS_Shape

The shape to create a solid from.

Returns:

Returns the created solid, or null if the shape could not be converted into a solid.

Type
oc.TopoDS_Solid | null

solid( [config]) <static>

Construct a solid shape from an indexed face mesh.

This method first calls PD.OCC.shell to generate a manifold shell of faces, and then converts that into solid for use with CSG. Not all shell topology can be converted to solid, so you may end up with a compound of shells instead of a solid if that is the case.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An optional array of [x,y,z] vector arrays defining the corners and edges of the shape.

vertices Array.<Array.<number>> <optional>

An optional array of [x,y,z] vector arrays defining the corners and edges of the shape.

faces Array.<Array.<number>> | Array.<object> <optional>

An array of faces with boundaries containing ordinal indexes of the points that make up the face.

facets Array.<object> <optional>

An array of facets with boundary contours defined by sequential [x,y,z] vector arrays.

tolerance number <optional>

An optional face sewing tolerance, defaults to 1mm.

Returns:

Returns a solid shape sewn together from faces.

Type
oc.TopoDS_Shape

sphere( [config]) <static>

Construct a spherical primitive shape.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
pos Array.<number> <optional>

An [x,y,z] vector array defining the shape center, defaults to the origin.

axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

radius number <optional>

The distance of the spherical surface from the centre, defaults to 1000mm (1m).

longitude number <optional>

An optional longitudinal angle in radians to restrict the sphere to (0 to 2PI), defaults to 2PI.

latitude Array.<number> <optional>

An optional array with the start and stop latitude angles in radians (-PI/2 to PI/2), defaults to [-PI/2, PI/2].

Returns:

Returns a spherical shape.

Type
oc.TopoDS_Shape

subtract( [config]) <static>

Subtracts a set of shapes from a main body shape.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
from oc.TopoDS_Shape <optional>

The shape to subtract from.

subtract Array.<oc.TopoDS_Shape> | oc.TopoDS_Shape <optional>

An array of shapes to subtract.

tolerance number <optional>

The tolerance to use when differencing, defaults to 0.1.

keepEdges boolean <optional>

Whether or not to keep the original edge(s) in the shape, defaults to false.

Returns:

Returns the subtracted shape.

Type
oc.TopoDS_Shape

sweep( [config]) <static>

Creates a shape by sweeping a shape along a wire path.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shape oc.TopoDS_Shape <optional>

A shape to sweep along the path.

path oc.TopoDS_Wire <optional>

A wire defining the path to sweep along.

Returns:

Returns the swept shape(s).

Type
oc.TopoDS_Shape

text( [config]) <static>

Construct a set of primitive shapes representing 3D text.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
text string <optional>

The characters to be generated.

size number <optional>

The size of the text, defaults to 36.

height number <optional>

The extrusion height of the text faces, defaults to 0.15 font size.

Returns:

Returns a complex shape representing the text.

Type
oc.TopoDS_Shape | oc.TopoDS_Solid

torus( [config]) <static>

Construct a toroidal primitive shape.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
pos Array.<number> <optional>

An [x,y,z] vector array defining the shape center, defaults to the origin.

axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

radiusRing number <optional>

The radius of the torus pipe line from the center, defaults to 400mm (0.4m).

radiusPipe number <optional>

The radius of the rotated pipe, defaults to 100 (0.1m).

longitude number <optional>

An optional longitudinal angle in radians to restrict the torus to (0 to 2PI), defaults to 2PI.

latitude Array.<number> <optional>

An optional array with the start and stop latitude angles in radians (0 to 2PI), defaults to [0, 2PI].

Returns:

Returns a toroidal shape.

Type
oc.TopoDS_Shape

translate( [config]) <static>

Translates the given shape(s) by a relative vector.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes oc.TopoDS_Shape | Array.<oc.TopoDS_Shape> <optional>

A shape or array of shapes to translate.

offset Array.<number> <optional>

An [x,y,z] vector array defining the translation offset in each axis.

Returns:

Returns the translated shape(s).

Type
oc.TopoDS_Shape

union( [config]) <static>

Combines a set of shapes into a single unioned shape.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
shapes Array.<oc.TopoDS_Shape> <optional>

An array of two or more shapes to union.

tolerance number <optional>

The tolerance to use when unioning, defaults to 0.1.

keepEdges boolean <optional>

Whether or not to keep the original edge(s) in the shape, defaults to false.

Returns:

Returns the combined shape.

Type
oc.TopoDS_Shape

wedge( [config]) <static>

Construct a rectangular wedge primitive shape.

Wedges are rectangular primitives that taper in the X and/or Z axis as the shape runs along the Y axis. In addition to setting the overall size in each axis, you can provide either the taper width/height value or the minimum and maximum X and Z coordinates at the +Y end of the wedge.

This method will cache the generated shape if caching is enabled.

Parameters:
Name Type Argument Description
config object <optional>

An optional configuration object.

Properties of config:
Name Type Argument Description
pos Array.<number> <optional>

An [x,y,z] vector array defining the start position of the shape, defaults to [0,0,0].

axis Array.<number> | number <optional>

An [x,y,z] axis array or a number (X:1, Y:2, Z:3), defaults to Z axis.

size Array.<number> <optional>

An [x,y,z] vector array defining the size of the shape in each axis, defaults to [1000,1000,1000].

min Array.<number> <optional>

An [x,y,z] vector array defining the bottom-left extents.

max Array.<number> <optional>

An [x,y,z] vector array defining the top-right extents.

taperX Array.<number> <optional>

An array with the minimum and maximum X-axis values at the tapered end, defaults to [0, size[0]].

taperZ Array.<number> <optional>

An array with the minimum and maximum Z-axis values at the tapered end, defaults to [0, 0].

taperWidth number <optional>

The width of the tapered end in the X-axis, defaults to size[0].

taperHeight number <optional>

The height of the tapered end in the Z-axis, defaults to 0.

centered boolean <optional>

An optional flag indicating that the shape should be centered on its pos/min position rather than at its bottom-left, defaults to false.

centerXY boolean <optional>

An optional flag indicating that the shape should be centered on its X and Y pos/min position rather than at its bottom-left, defaults to false.

fillet number | Array.<number> <optional>

An optional radius or [bot,sides,top] array for filleting edges and corners, defaults to 0 (no fillet).

Returns:

Returns a rectangular wedge shape.

Type
oc.TopoDS_Shape
Example
/// Define just the size.
PD.CAD.add(PD.OCC.wedge({ size: [ 1000, 2000, 3000 ] }));

/// Define the height and width at end.
PD.CAD.add(PD.OCC.wedge({
     size: [ 1000, 2000, 3000 ],
     taperHeight: 50,
     taperWidth: 750,
     centerXY: true
}));

/// Define X and Z positions at end.
PD.CAD.add(PD.OCC.wedge({
    min: [ -500, -1000,    0 ],
    max: [  500,  1000, 3000 ],
    taperX: [  250, 750 ],
    taperZ: [ -100,  50 ]
}));

/// Define both dimensions.
const x_min =  0.40 * width;
const x_max =  0.75 * width;
const z_min = -0.25 * height;
const z_max =  0.25 * height;
PD.CAD.add(PD.CAD.addWedge({
    size: [ width, depth, height ],
    taperX: [ x_min, x_max ],
    taperZ[ z_min, z_max ]
}));

wire( [config]) <static>

Construct a wire from points or edges.

Wires are used to represent shape outlines or face boundaries. They are formed by connecting one or more edges together, which may be curved or linear segments.

To create a wire, you must pass either an array of edges in the config.edges property, or an array of [x,y,z] vector array coordinates in the config.points property. The list of edges will be used in preference to points, so you should only include one or the other rather than both.

Parameters:
Name Type Argument Description
config PD.OCC.IWirePath <optional>

A configuration object.

Properties of config:
Name Type Argument Description
edges Array.<oc.TopoDS_Edge> <optional>

An array of edges to connect together to form the wire path.

points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the wire path.

closed boolean <optional>

Whether or not to form a closed loop from the given points.

Returns:

Returns a new wire.

Type
oc.TopoDS_Wire

wireArc( [config]) <static>

Construct a wire from a circular arc.

Wires are used to represent shape outlines or face boundaries. They are formed by connecting one or more edges together, which may be curved or linear segments.

Parameters:
Name Type Argument Description
config PD.OCC.IArcPath <optional>

A configuration object defining the arc.

Returns:

Returns a wire arc.

Type
oc.TopoDS_Wire

wireBSpline( [config]) <static>

Construct a BSpline wire from control points.

Wires are used to represent shape outlines or face boundaries. They are formed by connecting one or more edges together, which may be curved or linear segments.

Parameters:
Name Type Argument Description
config PD.OCC.ICurvePoints <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the control points of the bspline.

closed boolean <optional>

Whether or not the wire forms a closed loop.

Returns:

Returns a curved wire.

Type
oc.TopoDS_Edge

wireBezier( [config]) <static>

Construct a Bezier curved wire from control points.

Wires are used to represent shape outlines or face boundaries. They are formed by connecting one or more edges together, which may be curved or linear segments.

Parameters:
Name Type Argument Description
config PD.OCC.ICurvePoints <optional>

A configuration object.

Properties of config:
Name Type Argument Description
points Array.<Array.<number>> <optional>

An array of [x,y,z] vector arrays defining the control points of the bezier curve.

closed boolean <optional>

Whether or not the wire forms a closed loop.

Returns:

Returns a curved wire.

Type
oc.TopoDS_Edge

wireCircle( [config]) <static>

Construct a closed circular wire.

Wires are used to represent shape outlines or face boundaries. They are formed by connecting one or more edges together, which may be curved or linear segments.

Parameters:
Name Type Argument Description
config PD.OCC.ICentreRadius <optional>

A configuration object.

Properties of config:
Name Type Argument Description
center Array.<number> <optional>

An [x,y,z] vector array defining the center of the circle.

radius number <optional>

The radius of the circle, defaults to 1000mm (1m).

Returns:

Returns a circular wire.

Type
oc.TopoDS_Wire

wires( [config]) <static>

Construct one or more wires from an array of point contours.

To create wires, you must pass an array of contours in the config.contours property, each containing two or more [x,y,z] vector array coordinates defining a connected sequence of line vertices.

Parameters:
Name Type Argument Description
config object <optional>

A configuration object.

Properties of config:
Name Type Argument Description
contours Array.<Array.<Array.<number>>> <optional>

An array of contours, each containing [x,y,z] vector arrays defining a wire path.

Returns:

Returns an array of wires new wire.

Type
Array.<oc.TopoDS_Wire>