{"id":13456536,"url":"https://github.com/scad-js/scad-js","last_synced_at":"2026-02-08T11:14:19.627Z","repository":{"id":40708836,"uuid":"281176211","full_name":"scad-js/scad-js","owner":"scad-js","description":"A Javascript frontend for solid modeling that compiles OpenSCAD.","archived":false,"fork":false,"pushed_at":"2023-03-05T15:11:36.000Z","size":223,"stargazers_count":83,"open_issues_count":6,"forks_count":10,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-29T00:32:14.746Z","etag":null,"topics":["cad","javascript","js","openjscad","openscad","openscad-extension","openscad-library","scad","scad-js","scadjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scad-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-20T16:57:42.000Z","updated_at":"2024-07-27T04:05:03.000Z","dependencies_parsed_at":"2024-07-31T08:24:44.069Z","dependency_job_id":null,"html_url":"https://github.com/scad-js/scad-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scad-js%2Fscad-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scad-js%2Fscad-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scad-js%2Fscad-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scad-js%2Fscad-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scad-js","download_url":"https://codeload.github.com/scad-js/scad-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245252563,"owners_count":20585092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cad","javascript","js","openjscad","openscad","openscad-extension","openscad-library","scad","scad-js","scadjs"],"created_at":"2024-07-31T08:01:23.687Z","updated_at":"2026-02-08T11:14:19.621Z","avatar_url":"https://github.com/scad-js.png","language":"JavaScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"https://i.imgur.com/IiI57LR.png\" alt=\"scad-js\" height=\"128\"\u003e SCAD-JS\n\u003c/h1\u003e\n\n\u003e **scad-js** transpile your TypeScript to **OpenSCAD** letting you create programmatic 3D solid models with the familiar TypeScript/JavaScript syntax.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/scad-js\"\u003e\n    \u003cimg alt=\"Latest release\" src=\"https://img.shields.io/npm/v/scad-js?style=for-the-badge\"\u003e\n    \u003cimg alt=\"Codecov coverage\" src=\"https://img.shields.io/codecov/c/github/scad-js/scad-js?style=for-the-badge\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/scad-js\"\u003e\n    \u003cimg alt=\"scad-js demo\" src=\"https://i.imgur.com/GhjNUxM.gif\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n**OpenSCAD** is an amazing software for creating solid 3D CAD objects, but modeling with the **OpenSCAD** language can be really cumbersome and limited.\n\n**scad-js** overcomes these limitations with the power of TypeScript, providing full type safety for your 3D models.\n\n## Getting started\nFirst make sure you have [OpenSCAD](https://www.openscad.org/downloads.html) installed on your system, we will use it to visualize the model.\n\nYou can create a new project from scratch:\n\n```bash\nmkdir my-scad-project\ncd my-scad-project\nbun init -y\nbun add scad-js typescript\n```\n\nOr clone the starter template:\n\n```bash\ngit clone https://github.com/scad-js/scad-js-starter.git my-scad-js-project\ncd my-scad-js-project\nbun install\n```\n\n## Using with TypeScript\n\nCreate a simple model with TypeScript:\n\n```typescript\nimport { cube, sphere, cylinder, difference, union } from 'scad-js';\nimport * as fs from 'fs';\n\n// Create a base cube\nconst base = cube(10).translate([0, 0, 0]);\n\n// Create a sphere for the top\nconst top = sphere(3).translate([0, 0, 10]);\n\n// Create cylindrical holes\nconst hole1 = cylinder(20, 1).translate([3, 3, -5]);\nconst hole2 = cylinder(20, 1).translate([-3, 3, -5]);\nconst hole3 = cylinder(20, 1).translate([3, -3, -5]);\nconst hole4 = cylinder(20, 1).translate([-3, -3, -5]);\n\n// Combine everything using operations\nconst model = difference(\n  union(base, top),\n  hole1, hole2, hole3, hole4\n);\n\n// Serialize to OpenSCAD code\nconst scadCode = model.serialize();\n\n// Save the result to a file\nfs.writeFileSync('model.scad', scadCode);\n\n// Or render directly to STL (requires openscad-wasm)\nconst stlData = await model.render();\nfs.writeFileSync('model.stl', stlData);\n```\n\nThen run:\n\n```bash\nbun run your-model.ts\n```\n\nThis will generate an OpenSCAD file that you can open and render, or directly generate an STL file.\n\n## Documentation\n\nFor detailed documentation on how to use scad-js visit [scad-js-docs](https://github.com/scad-js/scad-js-docs), you can also look at the official [OpenSCAD Documentation](https://www.openscad.org/documentation.html) page.\n\n## Type Safety\n\nscad-js provides TypeScript definitions that help you catch errors early:\n\n- Vector dimensions ([2D] or [3D]) are type-checked\n- SCAD primitives and operations have correct parameter types\n- Transformation methods are properly typed\n- Intellisense support in most editors\n\n## Examples\n\nHere are some examples to help you get started with scad-js:\n\n### Simple Example\n\nThis example demonstrates basic operations like union, difference, and combining primitive shapes:\n\n```typescript\nimport { cube, sphere, cylinder, difference, union } from 'scad-js';\nimport * as fs from 'fs';\n\n// Create a simple model with TypeScript\nconst createModel = (): string =\u003e {\n  // Create a base cube\n  const base = cube(10).translate([0, 0, 0]);\n  \n  // Create a sphere for the top\n  const top = sphere(3).translate([0, 0, 10]);\n  \n  // Create cylindrical holes\n  const hole1 = cylinder(20, 1).translate([3, 3, -5]);\n  const hole2 = cylinder(20, 1).translate([-3, 3, -5]);\n  const hole3 = cylinder(20, 1).translate([3, -3, -5]);\n  const hole4 = cylinder(20, 1).translate([-3, -3, -5]);\n  \n  // Combine everything using operations\n  const model = difference(\n    union(base, top),\n    hole1, hole2, hole3, hole4\n  );\n  \n  // Serialize to OpenSCAD code\n  return model.serialize();\n};\n\n// Generate the OpenSCAD code\nconst scadCode = createModel();\n\n// Save the result to a file\nfs.writeFileSync('model.scad', scadCode);\n```\n\n### Hollowed Cube (Simple Version)\n\nA cube with a spherical cavity, created using a single sphere subtraction:\n\n```typescript\nimport { cube, sphere, difference } from 'scad-js';\nimport * as fs from 'fs';\n\n// Create a hollowed cube model using a simple sphere subtraction\nconst createHollowedCubeSimple = (): string =\u003e {\n  // Size parameters\n  const cubeSize = 20;\n  const sphereRadius = 16; // Bigger than half the cube size to create large holes\n  \n  // Create the main cube\n  const mainCube = cube(cubeSize);\n  \n  // Create the sphere\n  const innerSphere = sphere(sphereRadius);\n  \n  // Combine using difference operation to cut out the sphere from the cube\n  const model = difference(mainCube, innerSphere)\n    .translate([-cubeSize/2, -cubeSize/2, -cubeSize/2]); // Center the model\n  \n  // Set color to yellow/gold\n  const coloredModel = (model as any).color([1, 0.8, 0]);\n  \n  // Serialize to OpenSCAD code\n  return coloredModel.serialize();\n};\n\n// Generate the OpenSCAD code\nconst scadCode = createHollowedCubeSimple();\nfs.writeFileSync('hollowed-cube-simple.scad', scadCode);\n```\n\n\n### Parametric Tower Generator (Advanced)\n\nThis example showcases the true power of JavaScript for generative 3D modeling by creating complex architectural structures:\n\n```typescript\nimport { cube, cylinder, sphere, union, difference, hull, type ScadObject } from 'scad-js';\nimport { writeFileSync } from 'fs';\n\n// Tower configuration - easily customizable parameters\ninterface TowerConfig {\n  floors: number;\n  floorHeight: number;\n  baseWidth: number;\n  topWidth: number;\n  windowsPerFloor: number;\n  curveIntensity: number; // Creates organic curves\n  balconyEveryNFloors: number;\n}\n\nconst config: TowerConfig = {\n  floors: 12,\n  floorHeight: 4,\n  baseWidth: 20,\n  topWidth: 12,\n  windowsPerFloor: 8,\n  curveIntensity: 0.3,\n  balconyEveryNFloors: 3\n};\n\n// Mathematical curve calculation for organic shapes\nfunction calculateFloorWidth(floorIndex: number, totalFloors: number, baseWidth: number, topWidth: number, curveIntensity: number): number {\n  const linearRatio = floorIndex / (totalFloors - 1);\n  const curveOffset = Math.sin(linearRatio * Math.PI) * curveIntensity * (baseWidth - topWidth) * 0.3;\n  const width = baseWidth + (topWidth - baseWidth) * linearRatio + curveOffset;\n  return Math.max(width, topWidth * 0.8);\n}\n\n// Generate multiple tower variations from the same codebase\nconst towers = [\n  { name: 'classic_tower', config: { ...config } },\n  { name: 'curved_tower', config: { ...config, curveIntensity: 0.8, floors: 15 } },\n  { name: 'modern_tower', config: { ...config, windowsPerFloor: 12, floors: 18 } }\n];\n\n// Generate all variations using JavaScript loops and math\ntowers.forEach(({ name, config }) =\u003e {\n  const tower = generateParametricTower(config);\n  writeFileSync(`${name}.scad`, tower.serialize({ $fn: 50 }));\n});\n```\n\n**This example demonstrates:**\n- 🔄 **Loops** for generating repetitive elements (floors, windows)\n- 📐 **Mathematical calculations** for organic curves and precise positioning  \n- 🎛️ **Conditional logic** for feature placement (balconies, decorative elements)\n- 🧩 **Modular functions** for reusable components\n- 📊 **Data structures** for managing complex geometry collections\n- ⚙️ **Parameterization** for instant design variations\n- 🎨 **Multiple outputs** from a single codebase\n\n*This level of parametric modeling would be extremely difficult to achieve in pure OpenSCAD!*\n\n### Functional Design Examples\n\n**scad-js** excels at creating practical, real-world objects with complex engineering requirements:\n\n#### 📱 Parametric Phone Stand\n\n```typescript\n// Customizable for any device size and viewing angle\nconst phoneStand = generatePhoneStand({\n  phoneWidth: 75,\n  standAngle: 60,          // Perfect viewing angle\n  cableSlot: true,         // Charging cable management\n  weightingHoles: true,    // Add coins for stability\n  rubberGrips: true        // Non-slip base pads\n});\n\n// Generate multiple variations for different use cases\nconst variations = [\n  { name: 'desk_work', angle: 45, depth: 60 },\n  { name: 'video_calls', angle: 75, height: 70 },\n  { name: 'bedside', angle: 55, compact: true }\n];\n```\n\n#### 🖊️ Modular Pen Holder\n\n```typescript\n// Smart compartment arrangement with automatic layout\nconst penHolder = generatePenHolder({\n  compartments: [\n    { type: 'pen', quantity: 3 },\n    { type: 'marker', quantity: 2 },\n    { type: 'business_cards', quantity: 1 },\n    { type: 'scissors', quantity: 1 }\n  ],\n  phoneSlot: true,         // Built-in phone stand\n  drawerSlot: true,        // Hidden storage drawer\n  cableManagement: true,   // Wire routing holes\n  labelAreas: true         // Raised text areas\n});\n```\n\n**Engineering features demonstrated:**\n- 📐 **Precise angle calculations** for optimal viewing/ergonomics\n- 🔧 **Engineering tolerances** for 3D printing requirements  \n- 📱 **Multi-device compatibility** through parameterization\n- 🎯 **Functional features** like cable management and stability\n- 🏗️ **Modular design** with reusable components\n- 📊 **Automatic layout algorithms** for optimal space usage\n\n### Running Examples\n\nTo run any of these examples:\n\n```bash\nbun run ./examples/your-example.ts\n```\n\nThis will generate OpenSCAD files that you can open and render in OpenSCAD, plus STL files ready for 3D printing.\n\n## Acknowledgements\n\nThis project was inspired by many other projects: [farrellm/scad-clj](https://github.com/farrellm/scad-clj), [OpenJSCAD.org](https://openjscad.org/), [tasn/scadjs](https://github.com/tasn/scadjs) and more... And of course it would not even exist without [OpenSCAD](https://www.openscad.org) itself.\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscad-js%2Fscad-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscad-js%2Fscad-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscad-js%2Fscad-js/lists"}