@es3d/es3d 0.0.0-stage → 1.0.1
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 +201 -0
- package/README.md +85 -2
- package/docs/REFERENCE.md +581 -0
- package/docs/SPEC.md +417 -0
- package/package.json +50 -4
- package/scripts/es3d-cli.mjs +377 -0
- package/src/cache/geometry-store.js +392 -0
- package/src/cache/mesh-bundle.js +123 -0
- package/src/cache/sha256.js +73 -0
- package/src/format/ast.js +238 -0
- package/src/format/colors.js +93 -0
- package/src/format/compact-parser.js +171 -0
- package/src/format/compact-tokenizer.js +165 -0
- package/src/format/errors.js +247 -0
- package/src/format/json.js +55 -0
- package/src/format/limits.js +14 -0
- package/src/format/parse.js +92 -0
- package/src/format/schema.js +617 -0
- package/src/format/serializer.js +333 -0
- package/src/format/validator.js +330 -0
- package/src/format/value-error.js +12 -0
- package/src/format/value-format.js +314 -0
- package/src/format/values.js +459 -0
- package/src/format/xml-parser.js +136 -0
- package/src/format/xml-tokenizer.js +237 -0
- package/src/geometry/contour.js +86 -0
- package/src/geometry/extrude.js +175 -0
- package/src/geometry/gear.js +85 -0
- package/src/geometry/geometry-cache.js +159 -0
- package/src/geometry/lod-error.js +178 -0
- package/src/geometry/mesh.js +458 -0
- package/src/geometry/primitives.js +299 -0
- package/src/geometry/registry.js +645 -0
- package/src/geometry/revolve.js +136 -0
- package/src/geometry/sweep.js +441 -0
- package/src/index.js +47 -0
- package/src/io/compression.js +67 -0
- package/src/io/convert.js +236 -0
- package/src/io/download.js +13 -0
- package/src/io/external-scene.js +127 -0
- package/src/io/file-loader.js +28 -0
- package/src/io/gltf.js +630 -0
- package/src/io/mesh-import.js +104 -0
- package/src/io/obj.js +352 -0
- package/src/io/step-brep.js +439 -0
- package/src/io/step-exact.js +1149 -0
- package/src/io/step.js +1418 -0
- package/src/io/stl.js +193 -0
- package/src/io/svg-import.js +787 -0
- package/src/material/materials.js +154 -0
- package/src/math/mat4.js +475 -0
- package/src/math/random.js +30 -0
- package/src/math/trig.js +65 -0
- package/src/math/vec3.js +81 -0
- package/src/optimize/optimizer.js +579 -0
- package/src/path/path-flatten.js +322 -0
- package/src/path/path-parser.js +332 -0
- package/src/path/shapes.js +129 -0
- package/src/path/triangulate.js +517 -0
- package/src/pipeline.js +74 -0
- package/src/render/camera.js +168 -0
- package/src/render/frame-builder.js +362 -0
- package/src/render/geometry-pool.js +149 -0
- package/src/render/lighting.js +149 -0
- package/src/render/orbit-controls.js +237 -0
- package/src/render/renderer.js +258 -0
- package/src/render/scroll-timeline.js +104 -0
- package/src/render/shaders/glsl.js +285 -0
- package/src/render/shaders/wgsl.js +252 -0
- package/src/render/stage.js +364 -0
- package/src/render/texture-cache.js +40 -0
- package/src/render/textures.js +223 -0
- package/src/render/webgl2/webgl2-backend.js +586 -0
- package/src/render/webgpu/webgpu-backend.js +482 -0
- package/src/scene/animation.js +171 -0
- package/src/scene/camera-constraints.js +117 -0
- package/src/scene/flatten.js +754 -0
- package/src/scene/picking.js +161 -0
- package/src/scene/scene-graph.js +320 -0
- package/src/transform/transform.js +211 -0
- package/src/wasm/kernels-binary.js +3 -0
- package/src/wasm/kernels.js +385 -0
package/src/math/trig.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Normative sine and cosine for placement.
|
|
2
|
+
//
|
|
3
|
+
// IEEE 754 does not require Math.sin and Math.cos to be correctly rounded, so
|
|
4
|
+
// two readers can disagree in the last bit. Scatter positions and rotation
|
|
5
|
+
// matrices use the functions below instead. Every operation is a binary64
|
|
6
|
+
// round-to-nearest add, subtract or multiply, in the order written, so every
|
|
7
|
+
// IEEE 754 implementation produces the same bits.
|
|
8
|
+
//
|
|
9
|
+
// Tessellation of spheres, gears and paths may keep the platform sin and cos.
|
|
10
|
+
// Those meshes are bounded by a chordal error, not hashed.
|
|
11
|
+
|
|
12
|
+
const PI = Math.PI;
|
|
13
|
+
const TWO_PI = PI * 2;
|
|
14
|
+
const HALF_PI = PI * 0.5;
|
|
15
|
+
const QUARTER_PI = PI * 0.25;
|
|
16
|
+
|
|
17
|
+
// fdlibm __kernel_sin coefficients, as binary64 literals. Valid for |x| <= π/4.
|
|
18
|
+
const S1 = -1.66666666666666324348e-1;
|
|
19
|
+
const S2 = 8.33333333332248946124e-3;
|
|
20
|
+
const S3 = -1.98412698298579493134e-4;
|
|
21
|
+
const S4 = 2.75573137070700676789e-6;
|
|
22
|
+
const S5 = -2.50507602534068634195e-8;
|
|
23
|
+
const S6 = 1.58969099521155010221e-10;
|
|
24
|
+
|
|
25
|
+
// fdlibm __kernel_cos coefficients.
|
|
26
|
+
const C1 = 4.16666666666666019037e-2;
|
|
27
|
+
const C2 = -1.38888888888741095749e-3;
|
|
28
|
+
const C3 = 2.48015872894767294178e-5;
|
|
29
|
+
const C4 = -2.75573143513906633035e-7;
|
|
30
|
+
const C5 = 2.0875723212981748279e-9;
|
|
31
|
+
const C6 = -1.13596475577881948265e-11;
|
|
32
|
+
|
|
33
|
+
function kernelSin(x) {
|
|
34
|
+
const z = x * x;
|
|
35
|
+
const v = z * x;
|
|
36
|
+
const r = S2 + z * (S3 + z * (S4 + z * (S5 + z * S6)));
|
|
37
|
+
return x + v * (S1 + z * r);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function kernelCos(x) {
|
|
41
|
+
const z = x * x;
|
|
42
|
+
const r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6)))));
|
|
43
|
+
// 1 - z/2 + z^2 * (C1 + ...). The extra z is the Taylor power; r already holds one.
|
|
44
|
+
return 1 - 0.5 * z + z * r;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Sine of a radian angle. Finite inputs only; non-finite values pass through. */
|
|
48
|
+
export function es3dSin(x) {
|
|
49
|
+
if (!Number.isFinite(x)) return x;
|
|
50
|
+
let y = x - TWO_PI * Math.round(x / TWO_PI);
|
|
51
|
+
let sign = 1;
|
|
52
|
+
if (y < 0) {
|
|
53
|
+
sign = -1;
|
|
54
|
+
y = -y;
|
|
55
|
+
}
|
|
56
|
+
if (y > HALF_PI) y = PI - y;
|
|
57
|
+
if (y < 0) y = 0;
|
|
58
|
+
const s = y > QUARTER_PI ? kernelCos(HALF_PI - y) : kernelSin(y);
|
|
59
|
+
return sign < 0 ? -s : s;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Cosine. Defined as sin(x + π/2) with the same reduction. */
|
|
63
|
+
export function es3dCos(x) {
|
|
64
|
+
return es3dSin(x + HALF_PI);
|
|
65
|
+
}
|
package/src/math/vec3.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Small vector helpers operating on plain arrays [x, y, z].
|
|
2
|
+
|
|
3
|
+
export const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
4
|
+
export const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
5
|
+
export const scale = (a, s) => [a[0] * s, a[1] * s, a[2] * s];
|
|
6
|
+
export const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
7
|
+
export const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
8
|
+
export const length = (a) => Math.hypot(a[0], a[1], a[2]);
|
|
9
|
+
export const distance = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
|
10
|
+
export const lerp = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
11
|
+
|
|
12
|
+
export function normalize(a) {
|
|
13
|
+
const l = Math.hypot(a[0], a[1], a[2]);
|
|
14
|
+
return l > 1e-20 ? [a[0] / l, a[1] / l, a[2] / l] : [0, 0, 0];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Any unit vector perpendicular to a (unit) vector. */
|
|
18
|
+
export function perpendicular(a) {
|
|
19
|
+
const ax = Math.abs(a[0]), ay = Math.abs(a[1]), az = Math.abs(a[2]);
|
|
20
|
+
const other = ax <= ay && ax <= az ? [1, 0, 0] : ay <= az ? [0, 1, 0] : [0, 0, 1];
|
|
21
|
+
return normalize(cross(a, other));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Rotate v around unit axis k by angle (Rodrigues). */
|
|
25
|
+
export function rotateAround(v, k, angle) {
|
|
26
|
+
const c = Math.cos(angle), s = Math.sin(angle);
|
|
27
|
+
const kv = cross(k, v);
|
|
28
|
+
const kd = dot(k, v) * (1 - c);
|
|
29
|
+
return [v[0] * c + kv[0] * s + k[0] * kd, v[1] * c + kv[1] * s + k[1] * kd, v[2] * c + kv[2] * s + k[2] * kd];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Axis-aligned bounding box helpers: {min:[3], max:[3]} */
|
|
33
|
+
export function emptyBounds() {
|
|
34
|
+
return { min: [Infinity, Infinity, Infinity], max: [-Infinity, -Infinity, -Infinity] };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function boundsIsEmpty(b) {
|
|
38
|
+
return !(b.min[0] <= b.max[0]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function expandBounds(b, x, y, z) {
|
|
42
|
+
if (x < b.min[0]) b.min[0] = x;
|
|
43
|
+
if (y < b.min[1]) b.min[1] = y;
|
|
44
|
+
if (z < b.min[2]) b.min[2] = z;
|
|
45
|
+
if (x > b.max[0]) b.max[0] = x;
|
|
46
|
+
if (y > b.max[1]) b.max[1] = y;
|
|
47
|
+
if (z > b.max[2]) b.max[2] = z;
|
|
48
|
+
return b;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function unionBounds(a, b) {
|
|
52
|
+
expandBounds(a, b.min[0], b.min[1], b.min[2]);
|
|
53
|
+
expandBounds(a, b.max[0], b.max[1], b.max[2]);
|
|
54
|
+
return a;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Transform an AABB by a matrix (returns the AABB of the transformed box). */
|
|
58
|
+
export function transformBounds(b, m) {
|
|
59
|
+
const out = emptyBounds();
|
|
60
|
+
if (boundsIsEmpty(b)) return out;
|
|
61
|
+
for (let i = 0; i < 8; i++) {
|
|
62
|
+
const x = i & 1 ? b.max[0] : b.min[0];
|
|
63
|
+
const y = i & 2 ? b.max[1] : b.min[1];
|
|
64
|
+
const z = i & 4 ? b.max[2] : b.min[2];
|
|
65
|
+
expandBounds(
|
|
66
|
+
out,
|
|
67
|
+
m[0] * x + m[4] * y + m[8] * z + m[12],
|
|
68
|
+
m[1] * x + m[5] * y + m[9] * z + m[13],
|
|
69
|
+
m[2] * x + m[6] * y + m[10] * z + m[14],
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function boundsCenter(b) {
|
|
76
|
+
return [(b.min[0] + b.max[0]) / 2, (b.min[1] + b.max[1]) / 2, (b.min[2] + b.max[2]) / 2];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function boundsRadius(b) {
|
|
80
|
+
return Math.hypot(b.max[0] - b.min[0], b.max[1] - b.min[1], b.max[2] - b.min[2]) / 2;
|
|
81
|
+
}
|