Complete reference for JSCAD functions and modules in STL.Show
Basic geometric shapes and primitives for creating 3D objects.
Creates a cube with specified dimensions.
const { cube } = jscad.primitives;
// Basic cube
cube({ size: 10 })
// Rectangular cube
cube({ size: [width, height, depth] })
// Centered cube
cube({ size: 10, center: [true, true, true] })Creates a sphere with specified radius and resolution.
const { sphere } = jscad.primitives;
// Basic sphere
sphere({ radius: 5 })
// High resolution sphere
sphere({ radius: 5, segments: 64 })
// Centered sphere
sphere({ radius: 5, center: [0, 0, 0] })Creates a cylinder with specified radius and height.
const { cylinder } = jscad.primitives;
// Basic cylinder
cylinder({ radius: 5, height: 10 })
// High resolution cylinder
cylinder({ radius: 5, height: 10, segments: 64 })
// Centered cylinder
cylinder({ radius: 5, height: 10, center: [0, 0, 0] })Creates a cone with specified base radius and height.
const { cone } = jscad.primitives;
// Basic cone
cone({ radius: 5, height: 10 })
// Truncated cone
cone({ radius: 5, height: 10, topRadius: 2 })
// High resolution cone
cone({ radius: 5, height: 10, segments: 64 })Functions to transform and manipulate 3D objects.
Moves an object by the specified offset.
const { translate } = jscad.transforms;
const { cube } = jscad.primitives;
// Move cube by 10 units in X direction
translate([10, 0, 0], cube({ size: 5 }))
// Move cube by offset in all directions
translate([5, 3, 2], cube({ size: 5 }))Rotates an object around the specified axes.
const { rotate } = jscad.transforms;
const { cube } = jscad.primitives;
// Rotate 45 degrees around Z axis
rotate([0, 0, Math.PI / 4], cube({ size: 5 }))
// Rotate around multiple axes
rotate([Math.PI / 6, Math.PI / 4, 0], cube({ size: 5 }))Scales an object by the specified factors.
const { scale } = jscad.transforms;
const { cube } = jscad.primitives;
// Scale uniformly
scale([2, 2, 2], cube({ size: 5 }))
// Scale non-uniformly
scale([1, 2, 3], cube({ size: 5 }))Mirrors an object across the specified plane.
const { mirror } = jscad.transforms;
const { cube } = jscad.primitives;
// Mirror across XZ plane
mirror([0, 1, 0], cube({ size: 5 }))
// Mirror across XY plane
mirror([0, 0, 1], cube({ size: 5 }))Functions to combine, subtract, and intersect geometries.
Combines multiple objects into a single object.
const { union } = jscad.booleans;
const { cube, sphere } = jscad.primitives;
const { translate } = jscad.transforms;
// Combine two objects
const obj1 = cube({ size: 10 });
const obj2 = translate([5, 0, 0], sphere({ radius: 3 }));
union(obj1, obj2)
// Combine multiple objects
union(cube({ size: 5 }), sphere({ radius: 3 }), cylinder({ radius: 2, height: 8 }))Subtracts objects from the first object.
const { subtract } = jscad.booleans;
const { cube, sphere } = jscad.primitives;
// Subtract sphere from cube
const outer = cube({ size: 10 });
const inner = sphere({ radius: 3 });
subtract(outer, inner)
// Subtract multiple objects
subtract(cube({ size: 10 }), sphere({ radius: 2 }), sphere({ radius: 1 }))Keeps only the overlapping parts of objects.
const { intersect } = jscad.booleans;
const { cube, sphere } = jscad.primitives;
// Intersect cube and sphere
const cube1 = cube({ size: 8 });
const sphere1 = sphere({ radius: 6 });
intersect(cube1, sphere1)
// Intersect multiple objects
intersect(cube({ size: 10 }), sphere({ radius: 5 }), cylinder({ radius: 3, height: 8 }))Functions to create 3D objects from 2D shapes.
Extrudes a 2D shape along a straight path.
const { extrudeLinear } = jscad.extrusions;
const { rectangle } = jscad.primitives;
// Extrude rectangle to create a box
const rect = rectangle({ size: [10, 5] });
extrudeLinear({ height: 8 }, rect)
// Extrude with different options
extrudeLinear({
height: 10,
twistAngle: Math.PI / 4,
twistSteps: 10
}, rect)Extrudes a 2D shape by rotating it around an axis.
const { extrudeRotate } = jscad.extrusions;
const { rectangle } = jscad.primitives;
// Create a cylinder by rotating a rectangle
const rect = rectangle({ size: [2, 10] });
extrudeRotate({ angle: Math.PI * 2 }, rect)
// Partial rotation
extrudeRotate({
angle: Math.PI,
startAngle: 0,
segments: 32
}, rect)Functions to create convex hulls around objects.
Creates a convex hull around multiple objects.
const { hull } = jscad.hulls;
const { sphere } = jscad.primitives;
const { translate } = jscad.transforms;
// Create hull around two spheres
const sphere1 = sphere({ radius: 2 });
const sphere2 = translate([10, 0, 0], sphere({ radius: 3 }));
hull(sphere1, sphere2)
// Create hull around multiple objects
hull(
sphere({ radius: 1 }),
translate([5, 0, 0], sphere({ radius: 2 })),
translate([10, 5, 0], sphere({ radius: 1.5 }))
)Functions to add colors and materials to objects.
Applies a color to an object.
const { color } = jscad.colors;
const { cube } = jscad.primitives;
// Apply red color
color([1, 0, 0], cube({ size: 10 }))
// Apply color with alpha
color([0, 1, 0, 0.8], cube({ size: 10 }))
// Named colors
color('red', cube({ size: 10 }))
color('blue', cube({ size: 10 }))