cadcode 0.1.0 → 0.3.0
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/LICENSE +21 -0
- package/README.md +22 -9
- package/client/favicon.svg +17 -0
- package/client/index.html +48 -32
- package/client/render-worker.js +333 -0
- package/client/scene.js +166 -0
- package/client/viewer.css +423 -109
- package/client/viewer.js +144 -153
- package/package.json +9 -3
- package/src/core/evaluate.js +59 -0
- package/src/core/program.js +4 -44
- package/src/dev/server.js +26 -3
- package/src/dev/worker.js +25 -15
- package/src/export/stl.js +9 -7
package/src/export/stl.js
CHANGED
|
@@ -3,14 +3,16 @@ import { mergedSolid } from '../core/mesh.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Binary STL of the part's solids merged into one.
|
|
5
5
|
* @param {import('../lib/shapes.js').Solid[]} solids
|
|
6
|
-
*
|
|
6
|
+
* Plain typed arrays rather than a Buffer, so it also runs in the browser.
|
|
7
|
+
* @returns {Uint8Array}
|
|
7
8
|
*/
|
|
8
9
|
export function toSTL(solids) {
|
|
9
10
|
const { numProp, vertProperties, triVerts } = mergedSolid(solids).manifold.getMesh();
|
|
10
11
|
const triCount = triVerts.length / 3;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const bytes = new Uint8Array(84 + triCount * 50);
|
|
13
|
+
bytes.set(new TextEncoder().encode('cadcode'));
|
|
14
|
+
const view = new DataView(bytes.buffer);
|
|
15
|
+
view.setUint32(80, triCount, true);
|
|
14
16
|
|
|
15
17
|
const p = (v, k) => vertProperties[v * numProp + k];
|
|
16
18
|
let o = 84;
|
|
@@ -20,9 +22,9 @@ export function toSTL(solids) {
|
|
|
20
22
|
const w = [p(c, 0) - p(a, 0), p(c, 1) - p(a, 1), p(c, 2) - p(a, 2)];
|
|
21
23
|
const n = [u[1] * w[2] - u[2] * w[1], u[2] * w[0] - u[0] * w[2], u[0] * w[1] - u[1] * w[0]];
|
|
22
24
|
const len = Math.hypot(...n) || 1;
|
|
23
|
-
for (const value of [n[0] / len, n[1] / len, n[2] / len]) (
|
|
24
|
-
for (const v of [a, b, c]) for (let k = 0; k < 3; k++) (
|
|
25
|
+
for (const value of [n[0] / len, n[1] / len, n[2] / len]) (view.setFloat32(o, value, true), (o += 4));
|
|
26
|
+
for (const v of [a, b, c]) for (let k = 0; k < 3; k++) (view.setFloat32(o, p(v, k), true), (o += 4));
|
|
25
27
|
o += 2; // attribute byte count
|
|
26
28
|
}
|
|
27
|
-
return
|
|
29
|
+
return bytes;
|
|
28
30
|
}
|