API Reference

Complete reference for JSCAD functions and modules in STL.Show

Primitives

Basic geometric shapes and primitives for creating 3D objects.

cube(options)

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] })

Parameters

  • size: number or [number, number, number] - Size of cube
  • center: [boolean, boolean, boolean] - Center the cube on axes

sphere(options)

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] })

Parameters

  • radius: number - Radius of the sphere
  • segments: number - Number of segments (default: 32)
  • center: [number, number, number] - Center point

cylinder(options)

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] })

Parameters

  • radius: number - Radius of the cylinder
  • height: number - Height of the cylinder
  • segments: number - Number of segments (default: 32)
  • center: [number, number, number] - Center point

cone(options)

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 })

Parameters

  • radius: number - Base radius
  • height: number - Height of the cone
  • topRadius: number - Top radius (for truncated cone)
  • segments: number - Number of segments (default: 32)

Transformations

Functions to transform and manipulate 3D objects.

translate(offset, object)

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 }))

Parameters

  • offset: [number, number, number] - Translation vector
  • object: geometry - Object to translate

rotate(angles, object)

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 }))

Parameters

  • angles: [number, number, number] - Rotation angles in radians
  • object: geometry - Object to rotate

scale(factors, object)

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 }))

Parameters

  • factors: [number, number, number] - Scale factors
  • object: geometry - Object to scale

mirror(plane, object)

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 }))

Parameters

  • plane: [number, number, number] - Normal vector of mirror plane
  • object: geometry - Object to mirror

Boolean Operations

Functions to combine, subtract, and intersect geometries.

union(...objects)

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 }))

Parameters

  • objects: ...geometry - Objects to combine

subtract(object, ...objects)

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 }))

Parameters

  • object: geometry - Base object
  • objects: ...geometry - Objects to subtract

intersect(...objects)

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 }))

Parameters

  • objects: ...geometry - Objects to intersect

Extrusions

Functions to create 3D objects from 2D shapes.

extrudeLinear(options, shape)

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)

Parameters

  • height: number - Height of extrusion
  • twistAngle: number - Twist angle in radians
  • twistSteps: number - Number of twist steps
  • shape: geometry2d - 2D shape to extrude

extrudeRotate(options, shape)

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)

Parameters

  • angle: number - Rotation angle in radians
  • startAngle: number - Starting angle
  • segments: number - Number of segments
  • shape: geometry2d - 2D shape to extrude

Hulls

Functions to create convex hulls around objects.

hull(...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 }))
)

Parameters

  • objects: ...geometry - Objects to create hull around

Colors

Functions to add colors and materials to objects.

color(color, object)

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 }))

Parameters

  • color: [number, number, number, number?] or string - Color value
  • object: geometry - Object to color

Function Index

Primitives:
• cube()
• sphere()
• cylinder()
• cone()
Transforms:
• translate()
• rotate()
• scale()
• mirror()
Booleans:
• union()
• subtract()
• intersect()