libbetterscad 0.33.3 → 0.33.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -32
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
# libbetterscad
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
[report
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`
|
|
21
|
-
the
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
3
|
+
The engine behind [BetterSCAD](https://betterscad.org) as a library: the
|
|
4
|
+
OpenSCAD language, BetterSCAD's extensions to it, and the geometry behind
|
|
5
|
+
both. Give it a `.scad` or `.bscad` file and get back diagnostics, a
|
|
6
|
+
Customizer model, meshes, and files to save. No DOM, no bundler assumptions,
|
|
7
|
+
no UI: the same code runs in Node, in a Web Worker and in the browser's main
|
|
8
|
+
thread.
|
|
9
|
+
|
|
10
|
+
It is three things at once:
|
|
11
|
+
|
|
12
|
+
- **A complete OpenSCAD.** The whole 2021.01 language, not a subset, covered
|
|
13
|
+
by tests. A file written for OpenSCAD renders unmodified and gives the same
|
|
14
|
+
geometry; the [compatibility list](https://github.com/theanam/betterScad/blob/main/docs/language.md#compatibility)
|
|
15
|
+
names every primitive, transform, boolean, extrusion, function and special
|
|
16
|
+
variable, and a model that renders differently is a bug to
|
|
17
|
+
[report](https://github.com/theanam/betterScad/issues).
|
|
18
|
+
- **The BetterSCAD language.** Rounded and chamfered `cube(r)`, `square(r)`
|
|
19
|
+
and `polygon(r)`, `negative()`, `thread()`, `gear()`, `center()`,
|
|
20
|
+
`get_size()`, text on an arc, one-axis transforms and more, each a few
|
|
21
|
+
words in the file rather than a library to include. They are listed
|
|
22
|
+
[below](#betterscads-extensions).
|
|
23
|
+
- **A way back.** Every extension has a defined rewrite to plain `.scad`, and
|
|
24
|
+
the engine writes it, so a file made with BetterSCAD opens in OpenSCAD and
|
|
25
|
+
nothing you write can strand you.
|
|
26
|
+
|
|
27
|
+
It is the same engine the BetterSCAD editor and the `bscad` command line run.
|
|
26
28
|
|
|
27
29
|
```sh
|
|
28
30
|
npm install libbetterscad
|
|
@@ -121,6 +123,32 @@ for the whole file, and `omittedLines` says which lines were left out.
|
|
|
121
123
|
A plain `compile()` function is exported too, for when no kernel is loaded at
|
|
122
124
|
all; then `get_size()` reports `undef` and everything else works.
|
|
123
125
|
|
|
126
|
+
## BetterSCAD's extensions
|
|
127
|
+
|
|
128
|
+
Everything OpenSCAD has, plus the following. The engine takes them in any
|
|
129
|
+
file; there is nothing to enable. The
|
|
130
|
+
[language guide](https://github.com/theanam/betterScad/blob/main/docs/language.md)
|
|
131
|
+
has each one in full, with what it becomes in plain `.scad`.
|
|
132
|
+
|
|
133
|
+
| Syntax | What it does |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| `negative() { … }` | Turns anything inside it into negative space, cut from what is around it |
|
|
136
|
+
| `cube(size, center, r, chamfer, centerxy)`<br>`square(size, center, r, chamfer)` | The stock box and rectangle with rounded (`r`) or chamfered edges; `centerxy` centres on X and Y and keeps the box standing on Z = 0 |
|
|
137
|
+
| `cylinder(…, chamfer, chamfer1, chamfer2, edge_style)` | Takes the rim off either end, cut flat or `edge_style = "round"` |
|
|
138
|
+
| `linear_extrude(…, scale, ease)` | Curves a tapered extrusion into its ends |
|
|
139
|
+
| `text(…, radius, start, facing)` | Runs the writing around a circle, spaced by real letter widths |
|
|
140
|
+
| `polygon(…, r)`<br>`regular_polygon(sides, length, r)` | Rounded corners, and an equilateral polygon given by its side length |
|
|
141
|
+
| `thread(d, pitch, h, internal, profile, crest)` | A screw thread, or the hole the same bolt screws into |
|
|
142
|
+
| `gear(m, teeth, h, internal, helix)` | An involute gear; any two sharing a module mesh |
|
|
143
|
+
| `translate(x, y, z)`, `translatex(d)`, `rotatez(a)`, `mirrory()`, … | Loose numbers and one-axis forms of the three transforms |
|
|
144
|
+
| `get_size(object)`<br>`get_position(object)` | How big a part is and where its lowest corner is, as `[x, y, z]`, for stacking one part on another |
|
|
145
|
+
| `center() { … }`, `centerx()`, `centerxy()`, … | Centres everything inside on the first thing inside, on the named axes |
|
|
146
|
+
| `for (i = 0; i < n; i = i + 1)` | A C-style loop as a statement |
|
|
147
|
+
| `is_range(x)` | Tests for a range, like the other `is_*` functions |
|
|
148
|
+
|
|
149
|
+
`describeExtensions(file)` tells you which of these a parsed file uses and on
|
|
150
|
+
which lines; the editor's Info tab is built on it.
|
|
151
|
+
|
|
124
152
|
## Drawing it
|
|
125
153
|
|
|
126
154
|
The engine does not draw. It hands you meshes, and any renderer takes them.
|
|
@@ -211,10 +239,30 @@ const engine = await Engine.create({ fonts });
|
|
|
211
239
|
`text(font = "Inter:style=Bold")` resolves against the registered families
|
|
212
240
|
and falls back to the default family when the one asked for is missing.
|
|
213
241
|
|
|
242
|
+
## `.bscad` files
|
|
243
|
+
|
|
244
|
+
`.bscad` is BetterSCAD's own format, and it *is* a `.scad` file: the source,
|
|
245
|
+
with one JSON comment at the top that carries what the source cannot, such as
|
|
246
|
+
Customizer presets, the camera and the editor's layout. OpenSCAD reads past
|
|
247
|
+
the comment and renders the file as it is.
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
import { parseBscad, serializeBscad, toLegacyScadSource } from 'libbetterscad';
|
|
251
|
+
|
|
252
|
+
const file = parseBscad(text); // { source, metadata, hadMetadata }
|
|
253
|
+
file.metadata.presets; // preset name -> parameter name -> value
|
|
254
|
+
const saved = serializeBscad(file.source, { ...file.metadata, activePreset: 'Large' });
|
|
255
|
+
const plain = toLegacyScadSource(text); // the source alone
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
A plain `.scad` parses the same way, with `hadMetadata` false. Anything a
|
|
259
|
+
future version adds to the metadata is preserved on a round trip.
|
|
260
|
+
|
|
214
261
|
## Plain OpenSCAD out
|
|
215
262
|
|
|
216
263
|
A file that uses BetterSCAD extensions can be written as stock OpenSCAD, with
|
|
217
|
-
each extension replaced by a generated module or a rewrite
|
|
264
|
+
each extension replaced by a generated module or a rewrite, defined once and
|
|
265
|
+
called wherever the shape was used, so the export reads like what was written:
|
|
218
266
|
|
|
219
267
|
```ts
|
|
220
268
|
import { parse, transpileToLegacyScad, describeExtensions } from 'libbetterscad';
|
|
@@ -226,12 +274,12 @@ legacy.source; // OpenSCAD 2021.01 reads this
|
|
|
226
274
|
```
|
|
227
275
|
|
|
228
276
|
Two rewrites need more than the text. `text(radius = …)` spaces glyphs by their
|
|
229
|
-
real widths, so it needs the fonts; `get_size()`
|
|
230
|
-
compile of the same source, and
|
|
231
|
-
result says when either was missing rather than
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
277
|
+
real widths, so it needs the fonts; `get_size()` and `center()` need the
|
|
278
|
+
measurements from a compile of the same source, and are written out as the
|
|
279
|
+
values they measured. The result says when either was missing rather than
|
|
280
|
+
emitting a wrong file, and `usesMeasurements(file)` says up front whether a
|
|
281
|
+
file needs them, so a caller without geometry at hand only compiles when it
|
|
282
|
+
has to.
|
|
235
283
|
|
|
236
284
|
## Lower levels
|
|
237
285
|
|
|
@@ -257,8 +305,8 @@ piece of it:
|
|
|
257
305
|
|
|
258
306
|
## Versioning
|
|
259
307
|
|
|
260
|
-
The package version is the BetterSCAD version: the engine, the
|
|
261
|
-
are released together and tested together. The `.scad` the engine writes
|
|
308
|
+
The package version is the BetterSCAD version: the engine, the editor and the
|
|
309
|
+
CLI are released together and tested together. The `.scad` the engine writes
|
|
262
310
|
targets OpenSCAD 2021.01.
|
|
263
311
|
|
|
264
312
|
## Feedback
|
package/dist/index.d.ts
CHANGED
|
@@ -175,5 +175,5 @@ export type { ManifoldAPI, WasmOptions } from './kernel/wasm.js';
|
|
|
175
175
|
export { manifoldToMesh, meshToManifold } from './kernel/primitives.js';
|
|
176
176
|
export type { Assembly, Piece, RGBA } from './kernel/geometry.js';
|
|
177
177
|
/** Engine version, reported by `betterscad --version` and the about panel. */
|
|
178
|
-
export declare const ENGINE_VERSION = "0.33.
|
|
178
|
+
export declare const ENGINE_VERSION = "0.33.4";
|
|
179
179
|
export { cosSinDegrees } from './scene.js';
|
package/dist/index.js
CHANGED
|
@@ -292,5 +292,5 @@ export { loadKernel, kernelIfReady } from './kernel/wasm.js';
|
|
|
292
292
|
export { clipPolygons } from './kernel/clip.js';
|
|
293
293
|
export { manifoldToMesh, meshToManifold } from './kernel/primitives.js';
|
|
294
294
|
/** Engine version, reported by `betterscad --version` and the about panel. */
|
|
295
|
-
export const ENGINE_VERSION = '0.33.
|
|
295
|
+
export const ENGINE_VERSION = '0.33.4';
|
|
296
296
|
export { cosSinDegrees } from './scene.js';
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libbetterscad",
|
|
3
|
-
"version": "0.33.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.33.4",
|
|
4
|
+
"description": "The BetterSCAD engine: a complete OpenSCAD implementation plus BetterSCAD's extensions (rounded cube(r), negative(), thread(), gear(), get_size() and more) and .bscad files. Parse, validate and render to meshes, read Customizer parameters, export STL, 3MF, OFF, AMF, SVG and DXF, and write plain OpenSCAD back out. Node, Web Workers and the browser. No DOM, no UI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openscad",
|
|
7
7
|
"scad",
|
|
8
8
|
"openscad-compatible",
|
|
9
|
+
"betterscad",
|
|
10
|
+
"bscad",
|
|
9
11
|
"customizer",
|
|
10
12
|
"cad",
|
|
11
13
|
"parametric",
|