@es3d/es3d 1.0.0 → 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.
Files changed (79) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +86 -86
  3. package/docs/SPEC.md +417 -417
  4. package/package.json +1 -1
  5. package/scripts/es3d-cli.mjs +377 -377
  6. package/src/cache/geometry-store.js +392 -392
  7. package/src/cache/mesh-bundle.js +123 -123
  8. package/src/cache/sha256.js +73 -73
  9. package/src/format/ast.js +238 -238
  10. package/src/format/colors.js +93 -93
  11. package/src/format/compact-parser.js +171 -171
  12. package/src/format/compact-tokenizer.js +165 -165
  13. package/src/format/errors.js +247 -247
  14. package/src/format/json.js +55 -55
  15. package/src/format/limits.js +14 -14
  16. package/src/format/parse.js +92 -92
  17. package/src/format/schema.js +617 -617
  18. package/src/format/serializer.js +333 -333
  19. package/src/format/validator.js +330 -330
  20. package/src/format/value-error.js +12 -12
  21. package/src/format/value-format.js +314 -314
  22. package/src/format/values.js +459 -459
  23. package/src/format/xml-parser.js +136 -136
  24. package/src/format/xml-tokenizer.js +237 -237
  25. package/src/geometry/contour.js +86 -86
  26. package/src/geometry/extrude.js +175 -175
  27. package/src/geometry/gear.js +85 -85
  28. package/src/geometry/geometry-cache.js +159 -159
  29. package/src/geometry/lod-error.js +178 -178
  30. package/src/geometry/mesh.js +458 -458
  31. package/src/geometry/primitives.js +299 -299
  32. package/src/geometry/registry.js +645 -645
  33. package/src/geometry/revolve.js +136 -136
  34. package/src/geometry/sweep.js +441 -441
  35. package/src/index.js +47 -47
  36. package/src/io/compression.js +67 -67
  37. package/src/io/convert.js +236 -236
  38. package/src/io/download.js +13 -13
  39. package/src/io/external-scene.js +127 -127
  40. package/src/io/file-loader.js +28 -28
  41. package/src/io/gltf.js +630 -630
  42. package/src/io/mesh-import.js +104 -104
  43. package/src/io/obj.js +352 -352
  44. package/src/io/step-brep.js +439 -439
  45. package/src/io/step-exact.js +1149 -1149
  46. package/src/io/step.js +1418 -1418
  47. package/src/io/stl.js +193 -193
  48. package/src/io/svg-import.js +787 -787
  49. package/src/material/materials.js +154 -154
  50. package/src/math/mat4.js +475 -475
  51. package/src/math/random.js +30 -30
  52. package/src/math/trig.js +65 -65
  53. package/src/math/vec3.js +81 -81
  54. package/src/optimize/optimizer.js +579 -579
  55. package/src/path/path-flatten.js +322 -322
  56. package/src/path/path-parser.js +332 -332
  57. package/src/path/shapes.js +129 -129
  58. package/src/path/triangulate.js +517 -517
  59. package/src/pipeline.js +74 -74
  60. package/src/render/camera.js +168 -168
  61. package/src/render/frame-builder.js +362 -362
  62. package/src/render/geometry-pool.js +149 -149
  63. package/src/render/lighting.js +149 -149
  64. package/src/render/orbit-controls.js +237 -237
  65. package/src/render/renderer.js +258 -249
  66. package/src/render/scroll-timeline.js +104 -104
  67. package/src/render/shaders/glsl.js +285 -285
  68. package/src/render/shaders/wgsl.js +252 -252
  69. package/src/render/stage.js +364 -352
  70. package/src/render/texture-cache.js +40 -40
  71. package/src/render/textures.js +223 -223
  72. package/src/render/webgl2/webgl2-backend.js +586 -532
  73. package/src/render/webgpu/webgpu-backend.js +482 -480
  74. package/src/scene/flatten.js +754 -754
  75. package/src/scene/picking.js +161 -161
  76. package/src/scene/scene-graph.js +320 -320
  77. package/src/transform/transform.js +211 -211
  78. package/src/wasm/kernels-binary.js +3 -3
  79. package/src/wasm/kernels.js +385 -385
@@ -1,104 +1,104 @@
1
- // Page scroll -> animation progress for timeline="scroll" animations.
2
- //
3
- // Progress runs from 0 to 1 while a section of the page scrolls past. The
4
- // usual layout is a tall section with a sticky canvas inside it:
5
- //
6
- // <section id="tour" style="height: 400vh">
7
- // <div style="position: sticky; top: 0; height: 100vh"> canvas </div>
8
- // <p data-es3d-stop>…</p> <p data-es3d-stop="0.5">…</p> …
9
- // </section>
10
- //
11
- // Without stops, progress is 0 when the section's top reaches the top of the
12
- // viewport and 1 when its bottom reaches the bottom. Elements inside it with
13
- // data-es3d-stop pin progress values to page content instead: a stop is
14
- // reached when the element's centre is at the viewport's centre (its value,
15
- // or i / (n - 1) for the i-th of n stops when the attribute is empty), and
16
- // progress is interpolated between stops. Give the camera's keyTimes the same
17
- // values and each key view lines up with its paragraph.
18
- //
19
- // Scroll events only mark the timeline stale; update() reads layout at most
20
- // once per frame. The value eases towards the scroll position so wheel steps
21
- // do not jerk the camera. With reduced motion it jumps from stop to stop.
22
-
23
- const reducedMotionQuery = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
24
-
25
- export class ScrollTimeline {
26
- /**
27
- * @param {HTMLElement} section element whose scroll position drives progress
28
- * @param {{smoothing?: number, reducedMotion?: boolean}} [opts] smoothing: time constant in seconds (0 = none)
29
- */
30
- constructor(section, opts = {}) {
31
- this.section = section;
32
- this.smoothing = opts.smoothing ?? 0.12;
33
- this.reducedMotion = opts.reducedMotion ?? reducedMotionQuery();
34
- this.value = NaN; // current (smoothed) progress
35
- this.target = 0; // progress the scroll position asks for
36
- this.stale = true;
37
- this.markStale = () => {
38
- this.stale = true;
39
- };
40
- addEventListener('scroll', this.markStale, { passive: true, capture: true });
41
- addEventListener('resize', this.markStale, { passive: true });
42
- }
43
-
44
- dispose() {
45
- removeEventListener('scroll', this.markStale, { capture: true });
46
- removeEventListener('resize', this.markStale);
47
- }
48
-
49
- /** Stops inside the section: [{el, value}] in document order. */
50
- stops() {
51
- const els = [...this.section.querySelectorAll('[data-es3d-stop]')];
52
- return els.map((el, i) => {
53
- const raw = el.getAttribute('data-es3d-stop');
54
- const v = raw === null || raw.trim() === '' ? (els.length > 1 ? i / (els.length - 1) : 0) : Number(raw);
55
- return { el, value: Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0 };
56
- });
57
- }
58
-
59
- /** Progress for the current scroll position (reads layout). */
60
- measure() {
61
- const vh = innerHeight || 1;
62
- const stops = this.stops();
63
- if (!stops.length) {
64
- const r = this.section.getBoundingClientRect();
65
- const range = r.height - vh;
66
- if (range <= 0) return r.top <= 0 ? 1 : 0;
67
- return Math.min(1, Math.max(0, -r.top / range));
68
- }
69
- // signed distance of each stop's centre below the viewport centre
70
- const d = stops.map((s) => {
71
- const r = s.el.getBoundingClientRect();
72
- return r.top + r.height / 2 - vh / 2;
73
- });
74
- if (d[0] >= 0) return stops[0].value;
75
- const last = stops.length - 1;
76
- if (d[last] <= 0) return stops[last].value;
77
- let i = 0;
78
- while (i < last - 1 && d[i + 1] <= 0) i++;
79
- const u = d[i] === d[i + 1] ? 0 : -d[i] / (d[i + 1] - d[i]);
80
- if (this.reducedMotion) return u < 0.5 ? stops[i].value : stops[i + 1].value;
81
- return stops[i].value + (stops[i + 1].value - stops[i].value) * u;
82
- }
83
-
84
- /**
85
- * Advance by dt seconds. Returns true when the value changed (redraw).
86
- * @param {number} dt
87
- */
88
- update(dt) {
89
- if (this.stale) {
90
- this.stale = false;
91
- this.target = this.measure();
92
- }
93
- if (Number.isNaN(this.value) || this.reducedMotion || !(this.smoothing > 0)) {
94
- if (this.value === this.target) return false;
95
- this.value = this.target;
96
- return true;
97
- }
98
- const diff = this.target - this.value;
99
- if (diff === 0) return false;
100
- if (Math.abs(diff) < 1e-4) this.value = this.target;
101
- else this.value += diff * (1 - Math.exp(-Math.max(dt, 0) / this.smoothing));
102
- return true;
103
- }
104
- }
1
+ // Page scroll -> animation progress for timeline="scroll" animations.
2
+ //
3
+ // Progress runs from 0 to 1 while a section of the page scrolls past. The
4
+ // usual layout is a tall section with a sticky canvas inside it:
5
+ //
6
+ // <section id="tour" style="height: 400vh">
7
+ // <div style="position: sticky; top: 0; height: 100vh"> canvas </div>
8
+ // <p data-es3d-stop>…</p> <p data-es3d-stop="0.5">…</p> …
9
+ // </section>
10
+ //
11
+ // Without stops, progress is 0 when the section's top reaches the top of the
12
+ // viewport and 1 when its bottom reaches the bottom. Elements inside it with
13
+ // data-es3d-stop pin progress values to page content instead: a stop is
14
+ // reached when the element's centre is at the viewport's centre (its value,
15
+ // or i / (n - 1) for the i-th of n stops when the attribute is empty), and
16
+ // progress is interpolated between stops. Give the camera's keyTimes the same
17
+ // values and each key view lines up with its paragraph.
18
+ //
19
+ // Scroll events only mark the timeline stale; update() reads layout at most
20
+ // once per frame. The value eases towards the scroll position so wheel steps
21
+ // do not jerk the camera. With reduced motion it jumps from stop to stop.
22
+
23
+ const reducedMotionQuery = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
24
+
25
+ export class ScrollTimeline {
26
+ /**
27
+ * @param {HTMLElement} section element whose scroll position drives progress
28
+ * @param {{smoothing?: number, reducedMotion?: boolean}} [opts] smoothing: time constant in seconds (0 = none)
29
+ */
30
+ constructor(section, opts = {}) {
31
+ this.section = section;
32
+ this.smoothing = opts.smoothing ?? 0.12;
33
+ this.reducedMotion = opts.reducedMotion ?? reducedMotionQuery();
34
+ this.value = NaN; // current (smoothed) progress
35
+ this.target = 0; // progress the scroll position asks for
36
+ this.stale = true;
37
+ this.markStale = () => {
38
+ this.stale = true;
39
+ };
40
+ addEventListener('scroll', this.markStale, { passive: true, capture: true });
41
+ addEventListener('resize', this.markStale, { passive: true });
42
+ }
43
+
44
+ dispose() {
45
+ removeEventListener('scroll', this.markStale, { capture: true });
46
+ removeEventListener('resize', this.markStale);
47
+ }
48
+
49
+ /** Stops inside the section: [{el, value}] in document order. */
50
+ stops() {
51
+ const els = [...this.section.querySelectorAll('[data-es3d-stop]')];
52
+ return els.map((el, i) => {
53
+ const raw = el.getAttribute('data-es3d-stop');
54
+ const v = raw === null || raw.trim() === '' ? (els.length > 1 ? i / (els.length - 1) : 0) : Number(raw);
55
+ return { el, value: Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0 };
56
+ });
57
+ }
58
+
59
+ /** Progress for the current scroll position (reads layout). */
60
+ measure() {
61
+ const vh = innerHeight || 1;
62
+ const stops = this.stops();
63
+ if (!stops.length) {
64
+ const r = this.section.getBoundingClientRect();
65
+ const range = r.height - vh;
66
+ if (range <= 0) return r.top <= 0 ? 1 : 0;
67
+ return Math.min(1, Math.max(0, -r.top / range));
68
+ }
69
+ // signed distance of each stop's centre below the viewport centre
70
+ const d = stops.map((s) => {
71
+ const r = s.el.getBoundingClientRect();
72
+ return r.top + r.height / 2 - vh / 2;
73
+ });
74
+ if (d[0] >= 0) return stops[0].value;
75
+ const last = stops.length - 1;
76
+ if (d[last] <= 0) return stops[last].value;
77
+ let i = 0;
78
+ while (i < last - 1 && d[i + 1] <= 0) i++;
79
+ const u = d[i] === d[i + 1] ? 0 : -d[i] / (d[i + 1] - d[i]);
80
+ if (this.reducedMotion) return u < 0.5 ? stops[i].value : stops[i + 1].value;
81
+ return stops[i].value + (stops[i + 1].value - stops[i].value) * u;
82
+ }
83
+
84
+ /**
85
+ * Advance by dt seconds. Returns true when the value changed (redraw).
86
+ * @param {number} dt
87
+ */
88
+ update(dt) {
89
+ if (this.stale) {
90
+ this.stale = false;
91
+ this.target = this.measure();
92
+ }
93
+ if (Number.isNaN(this.value) || this.reducedMotion || !(this.smoothing > 0)) {
94
+ if (this.value === this.target) return false;
95
+ this.value = this.target;
96
+ return true;
97
+ }
98
+ const diff = this.target - this.value;
99
+ if (diff === 0) return false;
100
+ if (Math.abs(diff) < 1e-4) this.value = this.target;
101
+ else this.value += diff * (1 - Math.exp(-Math.max(dt, 0) / this.smoothing));
102
+ return true;
103
+ }
104
+ }