Starting with JSCAD
Starting with JSCAD
Section titled “Starting with JSCAD”JavaSculpt is a browser-based 3D modelling environment powered by JSCAD. You write JavaScript, and JSCAD turns it into geometry that you can preview, tweak, and export — all without installing anything.
Your first design
Section titled “Your first design”Open the Modelling tab and click New project. A starter file is created for you with a simple parametric cube. Hit ▶ Run in the toolbar to render it.
const jscad = require('@jscad/modeling')const { cube } = jscad.primitives
function main(params) { return cube({ size: params.cubeSize })}Every design exports a main() function. Whatever it returns — a single shape
or an array of shapes — is what gets rendered.
Primitives
Section titled “Primitives”JSCAD provides a set of built-in 3D and 2D shapes called primitives. Explore them in the Reference tab. Each entry shows the available parameters, a live preview, and a code snippet you can paste straight into your file with + Add to file.
Common 3D primitives:
| Shape | Function |
|---|---|
| Box | cuboid({ size: [w, h, d] }) |
| Sphere | sphere({ radius: r }) |
| Cylinder | cylinder({ radius: r, height: h }) |
| Torus | torus({ innerRadius: r1, outerRadius: r2 }) |
Boolean operations
Section titled “Boolean operations”Combine shapes with union, subtract, and intersect:
const { cuboid, sphere } = jscad.primitivesconst { subtract } = jscad.booleans
function main() { const box = cuboid({ size: [20, 20, 20] }) const ball = sphere({ radius: 13 }) return subtract(box, ball)}Transforms
Section titled “Transforms”Move, rotate, and scale shapes with the transforms module:
const { translate, rotate, scale, mirror } = jscad.transforms
const moved = translate([10, 0, 0], shape)const rotated = rotate([0, 0, Math.PI / 4], shape)Parameters
Section titled “Parameters”Make your designs interactive by exporting a getParameterDefinitions()
function. Parameters appear in the panel beneath the renderer and re-run the
script automatically when changed.
const getParameterDefinitions = () => [ { name: 'radius', type: 'number', widget: 'slider', caption: 'Radius', default: 10, min: 1, max: 50 }, { name: 'color', type: 'choice', caption: 'Color', values: ['red', 'blue', 'green'], default: 'blue' },]Colours
Section titled “Colours”Use colorize to apply a colour to any shape:
const { colorize, colorNameToRgb } = jscad.colors
const redSphere = colorize(colorNameToRgb('red'), sphere({ radius: 10 }))Exporting
Section titled “Exporting”Once your design is rendered, click ↓ Export in the renderer toolbar to download it. STL is the most common format for 3D printing; DXF and SVG work for 2D laser-cutting profiles.
Next steps
Section titled “Next steps”- Browse the Reference tab to discover every available primitive and its parameters.
- Use Edit imports… in the editor toolbar to manage which JSCAD modules are in scope.
- Use Edit parameters… to add or edit
getParameterDefinitionsvisually.