Skip to main content

The JSCAD kernel

JSCAD builds solids from polygons. It is the quickest of the three kernels to get something on screen: a few primitives, booleans, extrusions and hulls make most simple objects, and it writes text with a stroke font of its own. It is not a precise CAD kernel: curves are divided into a fixed number of segments, and there is no fillet operation, though cuboids and cylinders come in rounded variants. Choosing a kernel compares it with OpenCascade and Manifold.

What it has​

  • Solids (jscad.shapes): cubes, cuboids, spheres, geodesic spheres, ellipsoids, cylinders and a torus, rounded cuboids and cylinders, each with a variant that places one on every point of a list.
  • Flat shapes and paths (jscad.polygon, jscad.path): circles, rectangles, stars and polygons, and the open polylines walls follow.
  • Extrusions (jscad.extrusions): straight along Z with a twist, a wall along an outline, and a revolution around Z.
  • Hulls (jscad.hulls): the convex hull of shapes, or a chain of hulls between consecutive ones, which joins a row of spheres into a rounded tube.
  • Booleans and expansions: union, subtract and intersect; grow or shrink a shape by a distance.
  • Text (jscad.text): a stroke font, as pen paths, or as solid letters of hulled spheres or cylinders.

JSCAD builds along Z, like Manifold: an extrusion rises along Z, which lies flat in Bitbybit's Y-up scene.

A twisted star​

A seven-pointed star is extruded four units along Z, turning a quarter of the way as it rises:

Bitbybit Platform

A star extruded with a twist in Rete

rete logoRete
Script Source (rete)
{
"id": "rete-v2-json",
"nodes": {
"star": {
"id": "star",
"name": "bitbybit.jscad.polygon.star",
"customName": "star",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"center": [
0,
0
],
"vertices": 7,
"density": 1,
"outerRadius": 3,
"innerRadius": 1.5,
"startAngle": 0
},
"inputs": {},
"position": [
40,
40
]
},
"extrude": {
"id": "extrude",
"name": "bitbybit.jscad.extrusions.extrudeLinear",
"customName": "extrude linear",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"height": 4,
"twistAngle": 90,
"twistSteps": 30
},
"inputs": {
"geometry": {
"connections": [
{
"node": "star",
"output": "result",
"data": {}
}
]
}
},
"position": [
460,
40
]
}
},
"modules": {}
}

Rounded text​

sphericalText writes a word with JSCAD's stroke font, every stroke a chain of spheres hulled into a tube:

Bitbybit Platform

Text written in rounded strokes in Rete

rete logoRete
Script Source (rete)
{
"id": "rete-v2-json",
"nodes": {
"text": {
"id": "text",
"name": "bitbybit.jscad.text.sphericalText",
"customName": "spherical text",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "bitbybit",
"radius": 0.12,
"segments": 24,
"xOffset": 0,
"yOffset": 0,
"height": 2,
"lineSpacing": 1.4,
"letterSpacing": 1,
"align": "center",
"extrudeOffset": 0
},
"inputs": {},
"position": [
40,
40
]
}
},
"modules": {}
}

A JSCAD shape can carry a colour of its own (jscad.colors), and that colour wins over the one in the drawing options, as Conventions explains.

Every function​

FunctionWhat it does
booleans.intersectKeeps only the volume or area that all the inputs share, dropping everything else.
booleans.intersectTwoKeeps only the volume or area that first and second share, the two-input form of intersect.
booleans.minkowskiSumSweeps each later solid over the whole surface of the running result and fuses everything it passes through, so the first solid grows by the shape of the others - the Minkowski sum, which is how a solid is rounded or padded by a sphere.
booleans.subtractCuts every later input out of the first one, leaving what remains of the first.
booleans.subtractFromCuts every entry of meshes out of from, leaving what remains of from; the same as subtract with the base geometry named separately.
booleans.subtractTwoCuts second out of first, the two-input form of subtract.
booleans.unionFuses all the inputs into one solid or one 2D shape, merging where they overlap and keeping separate parts as one entity.
booleans.unionTwoFuses first and second into one, the two-input form of union.
colors.colorizeGives a solid, a 2D shape or a path a fixed color from a hex string, returning a colored copy; a list gives a list of colored copies in the same order.
downloadGeometry3MFWrites a solid, a 2D shape, a path or a list of them as a 3MF file, a modern 3D printing format, and downloads it in the browser as fileName plus .3mf.
downloadGeometryDxfWrites a solid, a 2D shape, a path or a list of them as a DXF drawing file and downloads it in the browser as fileName plus .dxf.
downloadSolidsSTLWrites several solids into one binary STL file and downloads it in the browser as fileName plus .stl.
downloadSolidSTLWrites a solid as a binary STL file, the common format for 3D printing, and downloads it in the browser as fileName plus .stl.
expansions.expandGrows geometry by moving its whole boundary outward by delta, or shrinks it when delta is negative.
expansions.offsetBuilds the outline of a 2D shape or path at distance delta from the original, outward for positive and inward for negative.
extrusions.extrudeLinearExtrudes a flat 2D shape straight along Z by height into a solid, twisting it on the way when twistAngle is not zero.
extrusions.extrudeRectangularBuilds a wall along the outline of a 2D shape or path: the outline is thickened by size on each side and raised by height along Z.
extrusions.extrudeRectangularPointsBuilds a wall along a polyline of points, as extrudeRectangular does for a path: the line is thickened by size on each side and raised by height along Z.
extrusions.extrudeRotateRevolves a flat 2D shape around the Z axis into a solid.
hulls.hullWraps all the inputs in one convex hull, the smallest shape without dents that contains them all, regardless of their order.
hulls.hullChainWraps each consecutive pair of inputs in a convex hull and fuses the hulls, so a row of shapes becomes a continuous strand that follows their order.
hulls.isConvexTells whether a solid is convex, meaning it already equals its own hull: every straight line between two of its points stays inside it.
path.appendArcAdds an elliptical arc from the last point of an open 2D path to endPoint, giving a longer copy.
path.appendPointsAdds points to the end of an open 2D path, giving a longer copy.
path.appendPolylineAdds the points of a polyline to the end of an open 2D path, giving a longer copy.
path.closeCloses an open 2D path by joining its last point back to its first, giving a closed copy; a path that is already closed comes back closed.
path.createEmptyMakes an empty open 2D path with no points, a starting point for appendPoints, appendPolyline and appendArc.
path.createFromPointsBuilds a 2D path through the points in order, open or closed back to the first point as closed says.
path.createFromPolylineBuilds a 2D path through the points of a polyline, open or closed back to the first point as closed says, whatever the polyline's own flag holds.
path.createPathsFromPointsBuilds one 2D path per list of points, in the same order; a list whose last point coincides with its first becomes a closed path, any other stays open.
polygon.circleBuilds a filled circle of the given radius around a 2D center; segments is the number of straight sides that approximate it.
polygon.createFromCurveBuilds a filled 2D shape from a NURBS curve by sampling it into points and closing the outline.
polygon.createFromPathBuilds a filled 2D shape from the points of a 2D path, closed back to the first point.
polygon.createFromPointsBuilds a filled 2D shape from the outline points, taken in order and closed back to the first.
polygon.createFromPolylineBuilds a filled 2D shape from the points of a polyline, closed back to the first point whatever the polyline says.
polygon.ellipseBuilds a filled ellipse around a 2D center, with radius holding the X and Y half-sizes; segments is the number of straight sides that approximate it.
polygon.rectangleBuilds a filled rectangle around a 2D center, with width along X and length along Y.
polygon.roundedRectangleBuilds a filled rectangle with its four corners rounded by roundRadius, around a 2D center with width along X and length along Y.
polygon.squareBuilds a filled square of side size around a 2D center, with its sides parallel to the axes.
polygon.starBuilds a filled star with vertices tips around a 2D center, the tips at outerRadius and the notches between them at innerRadius.
shapes.cubeBuilds a cube of edge length size centered on center, with its faces parallel to the axes.
shapes.cubesOnCenterPointsBuilds one cube of edge length size on every point of centers, in the same order.
shapes.cuboidBuilds a box centered on center with width along X, height along Y and length along Z, its faces parallel to the axes.
shapes.cuboidsOnCenterPointsBuilds one box of the given width, height and length on every point of centers, in the same order.
shapes.cylinderBuilds a round cylinder of the given radius standing along Z, with height split evenly above and below center.
shapes.cylinderEllipticBuilds a cylinder with an elliptical cross-section whose radii can differ at the two ends, standing along Z and centered on center.
shapes.cylinderEllipticOnCenterPointsBuilds one elliptic cylinder with the given radii and height on every point of centers, in the same order, as cylinderElliptic does for one.
shapes.cylindersOnCenterPointsBuilds one cylinder of the given radius and height on every point of centers, in the same order, as cylinder does for one.
shapes.ellipsoidBuilds an ellipsoid, a sphere stretched separately along X, Y and Z, centered on center.
shapes.ellipsoidsOnCenterPointsBuilds one ellipsoid with the given radii on every point of centers, in the same order, as ellipsoid does for one.
shapes.fromPolygonPointsBuilds a solid from its faces, each given as a list of points that go around the face.
shapes.geodesicSphereBuilds a sphere from evenly sized triangles, the way a geodesic dome is built, centered on center.
shapes.geodesicSpheresOnCenterPointsBuilds one geodesic sphere of the given radius on every point of centers, in the same order, as geodesicSphere does for one.
shapes.roundedCuboidBuilds a box with all its edges and corners rounded by roundRadius, centered on center with width along X, height along Y and length along Z.
shapes.roundedCuboidsOnCenterPointsBuilds one rounded box with the given sides and rounding on every point of centers, in the same order, as roundedCuboid does for one.
shapes.roundedCylinderBuilds a cylinder standing along Z whose two rims are rounded by roundRadius, with height split evenly above and below center.
shapes.roundedCylindersOnCenterPointsBuilds one rounded cylinder with the given size and rounding on every point of centers, in the same order, as roundedCylinder does for one.
shapes.sphereBuilds a sphere of the given radius centered on center; segments is the number of facets around it, so more makes it rounder.
shapes.spheresOnCenterPointsBuilds one sphere of the given radius on every point of centers, in the same order, as sphere does for one.
shapes.torusBuilds a torus, a ring with a round cross-section, lying flat in the XY plane around center with Z through its hole.
text.createVectorTextWrites text as pen strokes: each stroke is a list of 2D points in the XY plane, and a letter may take several.
text.cylindricalTextWrites text as solids: every pen stroke becomes a chain of cylinders standing along Z, hulled together into one smooth solid, so a letter like A gives several solids.
text.sphericalTextWrites text as solids: every pen stroke becomes a chain of spheres hulled together into one rounded solid, so a letter like A gives several solids.
toPolygonPointsTurns a solid into a list of triangles, each given as three points, with the solid's own transform already applied.
transformSolidMoves, rotates or scales a solid with a transformation, giving a new solid.
transformSolidsMoves, rotates or scales several solids with the same transformation, giving new solids in the same order.