@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,92 +1,92 @@
1
- // Entry point for reading ES3D documents in any of the surface syntaxes:
2
- // markup (XML-like, canonical) <es3d version="1"> ... </es3d>
3
- // compact (ES3D-C) es3d version=1 box s=2 ...
4
- // JSON (JsonML-style) ["es3d", {"version":"1"}, ...]
5
- // All of them produce the same AST, which is then validated against the schema.
6
-
7
- import { Document } from './ast.js';
8
- import { Diagnostic, ES3DError, LineIndex } from './errors.js';
9
- import { parseXml } from './xml-parser.js';
10
- import { parseCompact } from './compact-parser.js';
11
- import { validate } from './validator.js';
12
- import { fromJsonTree } from './json.js';
13
-
14
- /** Detect the surface syntax of a text document. */
15
- export function detectSyntax(text) {
16
- let i = 0;
17
- const n = text.length;
18
- if (text.charCodeAt(0) === 0xfeff) i = 1;
19
- for (;;) {
20
- while (i < n && /\s/.test(text[i])) i++;
21
- if (text.startsWith('//', i)) {
22
- const e = text.indexOf('\n', i);
23
- i = e < 0 ? n : e + 1;
24
- continue;
25
- }
26
- if (text.startsWith('/*', i)) {
27
- const e = text.indexOf('*/', i + 2);
28
- i = e < 0 ? n : e + 2;
29
- continue;
30
- }
31
- break;
32
- }
33
- const c = text[i];
34
- if (c === '<') return 'xml';
35
- if (c === '[' || c === '{') return 'json';
36
- return 'compact';
37
- }
38
-
39
- function failedDocument(err, syntax, text, lineIndex) {
40
- const doc = new Document({ root: null, syntax, source: text });
41
- doc.lineIndex = lineIndex;
42
- doc.diagnostics = err instanceof ES3DError ? err.diagnostics : [new Diagnostic({ code: 'E_INTERNAL', message: String(err && err.message ? err.message : err) })];
43
- return doc;
44
- }
45
-
46
- /**
47
- * Parse (and by default validate) an ES3D document.
48
- * Never throws for malformed input: problems are reported in doc.diagnostics.
49
- * @param {string|ArrayBuffer|Uint8Array} input
50
- * @param {{syntax?: 'xml'|'compact'|'json', validate?: boolean}} [opts]
51
- * @returns {Document}
52
- */
53
- export function parse(input, opts = {}) {
54
- if (typeof input !== 'string') input = new TextDecoder('utf-8').decode(input instanceof Uint8Array ? input : new Uint8Array(input));
55
- const text = input;
56
- const syntax = opts.syntax || detectSyntax(text);
57
- const lineIndex = new LineIndex(text);
58
- let doc;
59
- try {
60
- if (syntax === 'xml') doc = parseXml(text, lineIndex);
61
- else if (syntax === 'compact') doc = parseCompact(text, lineIndex);
62
- else if (syntax === 'json') {
63
- let tree;
64
- try {
65
- tree = JSON.parse(text);
66
- } catch (e) {
67
- const m = /position (\d+)/.exec(e.message);
68
- const d = new Diagnostic({ code: 'E_JSON', message: `Invalid JSON: ${e.message}`, offset: m ? Number(m[1]) : 0, length: 1 });
69
- d.locate(lineIndex);
70
- throw new ES3DError([d], lineIndex);
71
- }
72
- doc = fromJsonTree(tree);
73
- doc.source = text;
74
- } else throw new Error(`Unknown syntax '${syntax}'`);
75
- } catch (e) {
76
- return failedDocument(e, syntax, text, lineIndex);
77
- }
78
- if (!doc.lineIndex && syntax !== 'json') doc.lineIndex = lineIndex;
79
- return opts.validate === false ? doc : validate(doc);
80
- }
81
-
82
- /** Parse and throw an ES3DError when the document has errors. */
83
- export function parseStrict(input, opts = {}) {
84
- const doc = parse(input, opts);
85
- if (!doc.ok) throw new ES3DError(doc.errors, doc.lineIndex);
86
- return doc;
87
- }
88
-
89
- /** Human readable report of all diagnostics. */
90
- export function formatDiagnostics(doc) {
91
- return doc.diagnostics.map((d) => d.format(doc.lineIndex)).join('\n\n');
92
- }
1
+ // Entry point for reading ES3D documents in any of the surface syntaxes:
2
+ // markup (XML-like, canonical) <es3d version="1"> ... </es3d>
3
+ // compact (ES3D-C) es3d version=1 box s=2 ...
4
+ // JSON (JsonML-style) ["es3d", {"version":"1"}, ...]
5
+ // All of them produce the same AST, which is then validated against the schema.
6
+
7
+ import { Document } from './ast.js';
8
+ import { Diagnostic, ES3DError, LineIndex } from './errors.js';
9
+ import { parseXml } from './xml-parser.js';
10
+ import { parseCompact } from './compact-parser.js';
11
+ import { validate } from './validator.js';
12
+ import { fromJsonTree } from './json.js';
13
+
14
+ /** Detect the surface syntax of a text document. */
15
+ export function detectSyntax(text) {
16
+ let i = 0;
17
+ const n = text.length;
18
+ if (text.charCodeAt(0) === 0xfeff) i = 1;
19
+ for (;;) {
20
+ while (i < n && /\s/.test(text[i])) i++;
21
+ if (text.startsWith('//', i)) {
22
+ const e = text.indexOf('\n', i);
23
+ i = e < 0 ? n : e + 1;
24
+ continue;
25
+ }
26
+ if (text.startsWith('/*', i)) {
27
+ const e = text.indexOf('*/', i + 2);
28
+ i = e < 0 ? n : e + 2;
29
+ continue;
30
+ }
31
+ break;
32
+ }
33
+ const c = text[i];
34
+ if (c === '<') return 'xml';
35
+ if (c === '[' || c === '{') return 'json';
36
+ return 'compact';
37
+ }
38
+
39
+ function failedDocument(err, syntax, text, lineIndex) {
40
+ const doc = new Document({ root: null, syntax, source: text });
41
+ doc.lineIndex = lineIndex;
42
+ doc.diagnostics = err instanceof ES3DError ? err.diagnostics : [new Diagnostic({ code: 'E_INTERNAL', message: String(err && err.message ? err.message : err) })];
43
+ return doc;
44
+ }
45
+
46
+ /**
47
+ * Parse (and by default validate) an ES3D document.
48
+ * Never throws for malformed input: problems are reported in doc.diagnostics.
49
+ * @param {string|ArrayBuffer|Uint8Array} input
50
+ * @param {{syntax?: 'xml'|'compact'|'json', validate?: boolean}} [opts]
51
+ * @returns {Document}
52
+ */
53
+ export function parse(input, opts = {}) {
54
+ if (typeof input !== 'string') input = new TextDecoder('utf-8').decode(input instanceof Uint8Array ? input : new Uint8Array(input));
55
+ const text = input;
56
+ const syntax = opts.syntax || detectSyntax(text);
57
+ const lineIndex = new LineIndex(text);
58
+ let doc;
59
+ try {
60
+ if (syntax === 'xml') doc = parseXml(text, lineIndex);
61
+ else if (syntax === 'compact') doc = parseCompact(text, lineIndex);
62
+ else if (syntax === 'json') {
63
+ let tree;
64
+ try {
65
+ tree = JSON.parse(text);
66
+ } catch (e) {
67
+ const m = /position (\d+)/.exec(e.message);
68
+ const d = new Diagnostic({ code: 'E_JSON', message: `Invalid JSON: ${e.message}`, offset: m ? Number(m[1]) : 0, length: 1 });
69
+ d.locate(lineIndex);
70
+ throw new ES3DError([d], lineIndex);
71
+ }
72
+ doc = fromJsonTree(tree);
73
+ doc.source = text;
74
+ } else throw new Error(`Unknown syntax '${syntax}'`);
75
+ } catch (e) {
76
+ return failedDocument(e, syntax, text, lineIndex);
77
+ }
78
+ if (!doc.lineIndex && syntax !== 'json') doc.lineIndex = lineIndex;
79
+ return opts.validate === false ? doc : validate(doc);
80
+ }
81
+
82
+ /** Parse and throw an ES3DError when the document has errors. */
83
+ export function parseStrict(input, opts = {}) {
84
+ const doc = parse(input, opts);
85
+ if (!doc.ok) throw new ES3DError(doc.errors, doc.lineIndex);
86
+ return doc;
87
+ }
88
+
89
+ /** Human readable report of all diagnostics. */
90
+ export function formatDiagnostics(doc) {
91
+ return doc.diagnostics.map((d) => d.format(doc.lineIndex)).join('\n\n');
92
+ }