Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@jscad/modeling

jscad21.7kMIT2.12.6TypeScript support: included

Constructive Solid Geometry (CSG) Library for JSCAD

csg, parametric, modeling, openjscad, jscad

readme

@jscad/modeling

Solid Modelling Library for 2D and 3D Geometries

NPM version NPM downloads Build Status Stability License

User Group Lerna JavaScript Style Guide

Backers Sponsors

Open Collective

Overview

This library contains boolean operations based on Constructive Solid Geometry (CSG). CSG is a modelling technique that uses boolean operations like union and intersection to combine 3D solids. This library implements CSG operations on meshes elegantly and concisely using BSP trees, and is meant to serve as an easily understandable implementation of the algorithm.

Table of Contents

Installation

This package is published and available for download via NPM

npm install @jscad/modeling

In addition this package is hosted at UNPKG, and can be imported directly into webpages.

<script language="javascript" src="https://unpkg.com/@jscad/modeling" id="MODELING"></script>

Usage

As a Node module:

const {color, connectors, geometry, math, primitives, text, utils} = require('@jscad/modeling')
const {booleans, expansions, extrusions, hulls, measurements, transforms} = require('@jscad/modeling')

Documentation

Contributing

The various JSCAD packages and all source code are part of the JSCAD Organization, and maintained by a group of volunteers. We welcome and encourage anyone to pitch in but please take a moment to read the following guidelines.

  • If you want to submit a bug report please make sure to follow the Reporting Issues guide. Bug reports are accepted as Issues via GitHub.

  • If you want to submit a change or a patch, please read the Contributing Guide. New contributions are accepted as Pull Requests via GitHub.

  • We only accept bug reports and pull requests on GitHub.

  • If you have a question about how to use JSCAD, then please start a conversation at the JSCAD User Group. You might find the answer in the JSCAD User Guide.

  • If you have a change or new feature in mind, please start a conversation with the Core Developers and start contributing changes.

Small Note: If editing this README, please conform to the standard-readme specification.

Community

Discuss designs or issues

Or chat with other users

Copyrights

Some copyrights apply from integration of original libraries.

CSG Library : Copyright (c) 2012 Joost Nieuwenhuijse, under the MIT license. Copyright (c) 2011 Evan Wallace, under MIT license.

Portions of glMatrix Library: Copyright (c) 2015-2020, Brandon Jones, Colin MacKenzie IV, under MIT license.

Quickhull Library: Copyright (c) 2015 Mauricio Poppe, under the MIT license.

License

The MIT License (MIT) (unless specified otherwise)

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.12.6 (2025-09-20)

Bug Fixes

  • modeling: corrected handling of pitch vs height in extrudeHelical (074f05a)

2.12.5 (2024-12-29)

Note: Version bump only for package @jscad/modeling

2.12.4 (2024-11-10)

Note: Version bump only for package @jscad/modeling

2.12.3 (2024-10-06)

Bug Fixes

  • modeling: added optional plane to poly3 TS definition (2a3337a)
  • modeling: corrected hull of single unconvex solid (b3901f2)
  • modeling: corrected TS definition of scission (ad3d37d)
  • modeling: expose hullPoints2 and hullPoints3 (01ceae8)

2.12.2 (2024-06-02)

Bug Fixes

  • modeling: added geom3.fromPointsConvex() (e1af657)
  • modeling: added TS definitions for mat4.isIdentity() (0d02c83)
  • modeling: create scission.d.ts and update index.d.ts (7f02f7d)
  • modeling: created TS definitions for splitPolygonByPlane (0998e7e)
  • typo: fix typo in rounded error messages (f6d5286)

2.12.1 (2024-02-18)

Bug Fixes

  • modeling: added fromNoisyPoints() to plane (1d9efb5)
  • modeling: added orientation option to polygon (6c7be85)
  • modeling: corrected geom2 mirroring transform (8b0306e)

2.12.0 (2023-06-27)

Bug Fixes

  • modeling: add missing extrudeHelical typing definition (7f5f8e1)

Features

  • modeling: allow zero size in primitives (76b7369)

Performance Improvements

  • modeling: performance improvements for retessellate as part of booleans (12157ac)

2.11.1 (2023-04-30)

Bug Fixes

  • modeling: arcLengthToT first argument is required (fc4ceef)
  • modeling: export retessellate from modifiers (fe40aea)
  • modeling: fix line2.closestPoint (4419fe5)

2.11.0 (2022-11-26)

Bug Fixes

  • modeling: added TS definitions for missing measurement functions (acf79ca)

Features

2.10.0 (2022-08-21)

Bug Fixes

  • modeling: added TS definitions for modifiers (33ae2c4)
  • modeling: export modifiers for TypeScript (#1129) (a936675)

Features

  • modeling: added TAU constant to maths, and refactored code and documentation (#1128) (b8dd700)

2.9.6 (2022-07-17)

Bug Fixes

  • modeling: corrected concat to prevent modifying original paths (#1118) (ebeaa26)

Performance Improvements

  • modeling: convert {} objects to Map in insertTjunctions (#1109) (03c7fd1)

2.9.5 (2022-06-12)

Bug Fixes

  • modeling: use special trig functions for rotations in maths and primitives (#1090) (42c2664)

Performance Improvements

  • modeling: optimize poly3.measureBoundingSphere and cache results for performance (6ad02d5)
  • modeling: replace Math.hypot with faster Math.sqrt()(#1099) (1f71c5b)

2.9.4 (2022-05-15)

Performance Improvements

  • maths: reworked mat4 isMirror to use pure math, eliminating vec3 creation (#1088) (db4f220)
  • modeling: improved performance of reTesselateCoplanarPolygons by using maps or sets (#1085) (fc57103)
  • modeling: use Map instead of {} for slice.repair (#1083) (05d2984)

2.9.3 (2022-04-24)

Bug Fixes

  • modeling: corrected torus manifolds (#1046) (fe3901f)
  • modeling: removed path2.eachPoint which was broken and unused (#1069) (f704548)
  • modeling: reworked project to correct union of small polygons (#1058) (45d04ac)

Performance Improvements

  • modeling: changed internals to use geom3.create(), path2.create(), poly3.create() (#1072) (dc4cd15)
  • modeling: faster geom2.toOutlines (#1064) (5cb2f65)
  • modeling: performance improvements to mergePolygons and triangulatePolygons (647ffdf)

2.9.2 (2022-04-03)

Note: Version bump only for package @jscad/modeling

2.9.1 (2022-04-03)

Bug Fixes

  • modeling: corrected ellipse and ellipsoid manifolds (#1043) (3af3506)
  • modeling: fix assignHoles function when there are nested holes (#1038) (f015224)
  • modeling: fixed areAllShapesTheSameType and add a test (#1034) (c92e9be)
  • modeling: fixed cylinder construction, enhanced to support zero radius (#1039) (93f103d)

2.9.0 (2022-03-13)

Features

  • modeling: added earcut triangulation algorithm for extrusion caps (#1021) (c7f8ddf)

2.8.0 (2022-03-06)

Bug Fixes

  • modeling: fixed type of relativeTo in align() options, TS (#1015) (ca4927e)

Features

  • modeling: enchanced extrudeLinear to support path2 (#1009) (5a62a6b)

Performance Improvements

  • modeling: improved performace of path2 offsets (#1013) (47f824b)
  • modeling: improved performance of expanding geom3, and bug fix (#1008) (d0d035a)
  • modeling: use Set to create unique points in hullPath2 (#1007) (bd75a98)

2.7.2 (2022-02-19)

Performance Improvements

  • modeling: changed geom2.toOutlines to use a map when creating unique edges (#997) (338065f)
  • modeling: Use hypot instead of sqrt when possible (#996) (113c636)

2.7.1 (2021-12-26)

Bug Fixes

  • modeling: revert measureBoundingBox to only cache per geometry (#967) (b18c02c)

2.7.0 (2021-12-11)

Bug Fixes

  • modeling: compute planes from average of all vertex normals (#953) (c8a37ad)

Features

Performance Improvements

  • modeling: improved measureBoundingBox by eliminating allocations (8abe361)

2.6.1 (2021-11-07)

Bug Fixes

  • modeling: corrected measureBoundingBox for mirrored shapes (#946) (ab2d505)
  • modeling: handle negative area polygons in snapPolygons (#941) (971343a)

2.6.0 (2021-10-17)

Features

  • modeling: add new measurements for BoundingSphere, Center, CenterOfMass, and Dimensions (#850) (ad032f4)
  • modeling: change geometry transforms to preserve user attributes (#927) (a581a02)
  • modeling: Performance improvement for measure bounding box (#869) (ee1c7b1)

2.5.3 (2021-10-04)

Bug Fixes

  • modeling: corrected vec2.rotate, and enhanced test cases (#918) (e2bea2d)

2.5.2 (2021-09-27)

Bug Fixes

  • modeling: added exit condition to Node to prevent infinite loops in boolean ops (#898) (bf4d6d4)
  • modeling: corrected concat to ignore duplicate points (#913)corrected appendArc to maintain last point (3eea3ef)

2.5.1 (2021-09-09)

Bug Fixes

  • modeling: corrected CCW determination in 2D hulls (#897) (23fe2ac), closes #114
  • web: added open issues and discord community to help (4ea1196)

2.5.0 (2021-06-20)

Features

  • modeling: added mat4.isIdentity() (c22b7cc)

2.4.0 (2021-06-11)

Bug Fixes

  • modeling: corrected snapPolygons to maintain color attributes (eba8ebc)
  • modeling: corrected triangulatePolygons to maintain color attributes (f59958a)

Features

2.3.0 (2021-06-01)

Bug Fixes

  • modeling: fixed use of vec3.snap in triangulatePolygons (c0b82a0)
  • modeling: rewrote vec3 orthogonal() to do the correct thing, and adjusted test suites (f5cb4a3)
  • modeling: update and correct TypeScript type definitions (#849) (6036be7)

Features

  • modeling: added aboutEqualNormals() to math utils (986d402)
  • modeling: added fromVectorRotation() to mat4 (9e3acae)
  • modeling: added projectionOfPoint() to plane (5ea7bfd)
  • modeling: new project() function added to extrusions (#844) (065469c)
  • modeling: new scission() function added to booleans (#846) (b8b3bae)
  • modeling: rework math objects to conform with gl-matrix (#804) (2e52f10)

2.2.0 (2021-04-20)

Bug Fixes

  • all: V2 : several fixes for modeling (#705) (62017a4)
  • core: Remove connectors from public api (#703) (a3bf8a4)
  • core,modeling: V2 fix extrude (#751) (767b6fc)
  • modeling: Adding & improving tests, docs, removing some equals() (1f3724b)
  • modeling: correced snapPolygons to remove duplicate vertices which is possible (#791) (1eaf86f)
  • modeling: ensure extrude rectangular expand produces shapes with positive area (43ce5dd)
  • modeling: fix extrude rotate (#727) (13de037)
  • modeling: fix torus offset when outerRotation is supplied (f7b3a2a)
  • modeling: re-implemented poly2.isPointInside to correct issues (#741) (4266c8f)
  • modeling: V2 - primitives revisited (#697) (4721484)
  • modeling: V2 revisit modifiers (#773) (1e28120)

Features

  • examples: examples overhaul for V2 JSCAD (d73e06f)
  • modeling: add align() and measureAggregateBoundingBox() functions (72df65c)
  • modeling: added aggregate functions for area, volume, epsilon measurements (cf558bb)
  • modeling: V2 : adding new class of operations to modeling; modifiers (#743) (9e20303)
  • modeling: V2 : rename option to align and center (#775) (c5b0f48)
  • modeling: V2 fix extrusions (#761) (466910e)

2.1.0 (2021-04-15)

Bug Fixes

  • all: V2 : several fixes for modeling (#705) (62017a4)
  • core: Remove connectors from public api (#703) (a3bf8a4)
  • core,modeling: V2 fix extrude (#751) (767b6fc)
  • modeling: Adding & improving tests, docs, removing some equals() (1f3724b)
  • modeling: correced snapPolygons to remove duplicate vertices which is possible (#791) (1eaf86f)
  • modeling: ensure extrude rectangular expand produces shapes with positive area (43ce5dd)
  • modeling: fix extrude rotate (#727) (13de037)
  • modeling: fix torus offset when outerRotation is supplied (f7b3a2a)
  • modeling: re-implemented poly2.isPointInside to correct issues (#741) (4266c8f)
  • modeling: V2 - primitives revisited (#697) (4721484)
  • modeling: V2 revisit modifiers (#773) (1e28120)

Features

  • examples: examples overhaul for V2 JSCAD (d73e06f)
  • modeling: add align() and measureAggregateBoundingBox() functions (72df65c)
  • modeling: added aggregate functions for area, volume, epsilon measurements (cf558bb)
  • modeling: V2 : adding new class of operations to modeling; modifiers (#743) (9e20303)
  • modeling: V2 : rename option to align and center (#775) (c5b0f48)
  • modeling: V2 fix extrusions (#761) (466910e)

2.0.0 (2021-04-12)

Note: Version bump only for package @jscad/modeling

2.0.0-alpha.11 (2021-03-07)

Bug Fixes

Features

  • modeling: V2 : rename option to align and center (#775) (c5b0f48)

2.0.0-alpha.10 (2021-02-07)

Features

  • modeling: adding new class of operations to modeling; modifiers (#743) (9e20303)
  • modeling: enhanced options to extrudeFromSlices (#761) (466910e)

2.0.0-alpha.9 (2021-01-02)

Bug Fixes

  • core,modeling: V2 fix extrude (#751) (767b6fc)
  • modeling: re-implemented poly2.isPointInside to correct issues (#741) (4266c8f)

2.0.0-alpha.8 (2020-12-04)

Note: Version bump only for package @jscad/modeling

2.0.0-alpha.7 (2020-11-07)

Bug Fixes

2.0.0-alpha.6 (2020-10-11)

Bug Fixes

  • all: V2 : several fixes for modeling (#705) (62017a4)
  • core: Remove connectors from public api (#703) (a3bf8a4)

2.0.0-alpha.5 (2020-09-29)

Bug Fixes

2.0.0-alpha.4 (2020-09-28)

Features

  • modeling: added aggregate functions for area, volume, epsilon measurements (cf558bb)

2.0.0-alpha.3 (2020-09-19)

Features

  • modeling: add align() and measureAggregateBoundingBox() functions (72df65c)

2.0.0-alpha.2 (2020-09-08)

Bug Fixes

  • modeling: Adding & improving tests, docs, removing some equals() (1f3724b)
  • modeling: fix torus offset when outerRotation is supplied (f7b3a2a)

Features

  • examples: examples overhaul for V2 JSCAD (d73e06f)

2.0.0-alpha.1 (2020-08-19)

Bug Fixes

  • modeling: ensure extrude rectangular expand produces shapes with positive area (43ce5dd)

2.0.0-alpha.0 (2020-08-13)

Bug Fixes

  • booleans: corrected fromFakePolygons to ignore 0 length sides (#552) (a44650b)
  • booleans: added dynamic EPS for 2d boolean operations (#535) (510e909)
  • colors: colorize is now immutable & returns new geometries (#566) (916824c)
  • mat4: Missing variable declaration. (6c68e81)
  • geometries: corrected order of transforms in geom2, geom3, and path2 (2cde371)
  • transforms: adjusted transforms to allow various lengths arrays as parameters
  • geometries: reworked toCompactBinary and fromCompactBinary functions
  • primitives: enhance primitives settings & defaults
  • geometries: added color support to to/fromCompactBinary functions
  • maths: updated vec2 and vec3 to use the same logic as glmatrix
  • maths: changed line2/mat4/vec2/vec3/vec4 to create arrays of Numbers
  • measurements: enhanced measurements to cache values as object attributes
  • utils: exposed additional user utility functions
  • geometries: corrected order of transforms in geom2, geom3, and path2

Features

  • modeling: merge csg.js into main repo (#482)
  • primitives: remove center on primitives (#512) (7fdc3eb)
  • primitives: restored center parameter to primitives
  • modeling:: renamed color.color to colors.colorize
  • colors: improve (values & arrays supported) & cleanup color api (#542) (0f4feab)
  • hulls: added 3D hull functionality based on quickhull (#483) (c991eb7)
  • primitives: enhanced polyhedron to accept an array of colors (#544) (3a2e863)
  • geometries: added invert to geom3, as well as a new test suite
  • geometries: renamed flip to invert in poly3, adjusted test suites
  • geometries: removed plane from poly3 data structure, added plane() function
  • modeling: renamed math to maths
  • modeling: renamed geometry API to geometries, and adjusted tests…
  • modeling: moved measurements out of operations
  • modeling: adding curves/bezier object for curve-based easing and…

0.6.0 (2018-06-21)

Bug Fixes

Features

  • 2d polygons: add support for polygons (2D) with holes(#101) (22f8f80)
  • vector_text/char: big overhaul & additions to the vector_text/ char system (#107) (eadcd58)

0.5.4 (2018-03-16)

Bug Fixes

  • center: Correcting center() functionality (#97) (52e792d)

0.5.3 (2018-02-13)

0.5.2 (2018-01-29)

Bug Fixes

  • rotate: fixing angle-axis style rotation (#90) (6c28c1c)

0.5.1 (2018-01-29)

Bug Fixes

  • CAG: added back missing CAG.fromCompactBinary (#91) (57e8f5d)

0.5.0 (2018-01-19)

0.4.1 (2018-01-19)

0.4.0 (2018-01-05)

Bug Fixes

  • docstring: fixed a few bad docstrings which prevented docs from being generated (#76) (441fd18)

0.3.8 (2018-01-04)

Bug Fixes

  • shared object: support shared objects without color (#74) (f90ad50)

0.3.7 (2017-11-13)

0.3.6 (2017-11-03)

0.3.5 (2017-11-03)

Bug Fixes

  • fixTJunctions: fixes issues with fixTJunctions (#63) (78c5102)

0.3.4 (2017-11-01)

Bug Fixes

  • ConnectorsList: add back missing ConnectorsList (#62) (cfc1c7e)

0.3.3 (2017-11-01)

0.3.2 (2017-10-28)

Bug Fixes

  • path2D: added missing innerToCAG method to path2D proto & added tests & docs (#52) (4a5e37e)

0.3.1 (2017-06-11)

0.3.0 (2017-05-30)

Features

  • CAG.toPoints: CAG Enhancement for toPoints() (d023243)

0.2.4 (2017-05-20)

Bug Fixes

  • CAG: reverted back CAG to default to canonicalized = false (68a0558)

0.2.3 (2017-05-19)

0.2.2 (2017-05-19)

0.2.1 (2017-04-27)

0.2.0 (2017-04-27)

Bug Fixes

  • asserts: fixed issue with asserts in latest ava (1210f66)

0.1.4 (2017-01-27)

Bug Fixes

  • README: more attempts at fixing README on npm ... (a5ae096)

0.1.3 (2017-01-27)

0.1.2 (2017-01-27)

Bug Fixes

  • typo: fixed typo in package name (4f2aec6)

0.1.1 (2017-01-27)

Bug Fixes

  • babelrc: added missing babelrc (94f9684)
  • package: removed part of package relevant to 'builds' (7bf4815)

0.1.0 (2017-01-16)

Bug Fixes

  • bools fail if cylinder resolution not integer. Solution: parse all resolution as int (af6453c)
  • package: fixed package name (cbba148)

Features

  • csg.js: updated csg.js based on recent changes in OpenjSCAD.org (db1d133)