@mulmoclaude/shapescript-plugin 2.0.0 → 2.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.
Files changed (52) hide show
  1. package/README.md +112 -26
  2. package/dist/core/definition.d.ts.map +1 -1
  3. package/dist/core/index.d.ts +2 -1
  4. package/dist/core/index.d.ts.map +1 -1
  5. package/dist/core/plugin.d.ts.map +1 -1
  6. package/dist/{core-DZvhTmuk.cjs → core-BBgBeYYe.cjs} +1 -1
  7. package/dist/{core-BvTjfhU2.js → core-yB1Eiacr.js} +2 -2
  8. package/dist/core.cjs +1 -1
  9. package/dist/core.js +4 -4
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.js +4 -4
  12. package/dist/lang/de.d.ts.map +1 -1
  13. package/dist/lang/en.d.ts.map +1 -1
  14. package/dist/lang/es.d.ts.map +1 -1
  15. package/dist/lang/fr.d.ts.map +1 -1
  16. package/dist/lang/ja.d.ts.map +1 -1
  17. package/dist/lang/ko.d.ts.map +1 -1
  18. package/dist/lang/messages.d.ts +4 -0
  19. package/dist/lang/messages.d.ts.map +1 -1
  20. package/dist/lang/ptBR.d.ts.map +1 -1
  21. package/dist/lang/zh.d.ts.map +1 -1
  22. package/dist/render/page.d.ts.map +1 -1
  23. package/dist/render.cjs +8 -4
  24. package/dist/render.js +14 -10
  25. package/dist/{samples-CXhuDdDd.js → samples-CT-c9o1S.js} +281 -276
  26. package/dist/samples-D2_jOmoh.cjs +319 -0
  27. package/dist/shapescript/builders.d.ts +12 -2
  28. package/dist/shapescript/builders.d.ts.map +1 -1
  29. package/dist/shapescript/evaluator.d.ts +76 -2
  30. package/dist/shapescript/evaluator.d.ts.map +1 -1
  31. package/dist/shapescript/meshValues.d.ts +54 -0
  32. package/dist/shapescript/meshValues.d.ts.map +1 -0
  33. package/dist/shapescript/minkowski.d.ts +37 -0
  34. package/dist/shapescript/minkowski.d.ts.map +1 -0
  35. package/dist/shapescript/parser.d.ts +66 -2
  36. package/dist/shapescript/parser.d.ts.map +1 -1
  37. package/dist/shapescript/toThreeJS.d.ts +144 -8
  38. package/dist/shapescript/toThreeJS.d.ts.map +1 -1
  39. package/dist/shapescript/types.d.ts +145 -17
  40. package/dist/shapescript/types.d.ts.map +1 -1
  41. package/dist/style.css +1 -1
  42. package/dist/{toThreeJS-FsP-Na75.js → toThreeJS-CKjSbEnA.js} +6670 -4712
  43. package/dist/toThreeJS-Cs0UJm82.cjs +10 -0
  44. package/dist/vue/Preview.vue.d.ts.map +1 -1
  45. package/dist/vue/View.vue.d.ts.map +1 -1
  46. package/dist/vue/index.d.ts +1 -1
  47. package/dist/vue/index.d.ts.map +1 -1
  48. package/dist/vue.cjs +35 -25
  49. package/dist/vue.js +1532 -1493
  50. package/package.json +1 -1
  51. package/dist/samples-DGD0Kjwg.cjs +0 -276
  52. package/dist/toThreeJS-MvllBF9e.cjs +0 -10
@@ -0,0 +1,319 @@
1
+ const e=require("./toThreeJS-Cs0UJm82.cjs");let t=require("@mulmoclaude/core/artifacts");var n=`presentShapeScript`,r={type:`function`,name:n,description:"Display interactive 3D visualizations using ShapeScript with expressions, variables, control flow, and functions. A new `script` is saved to `artifacts/shapes/` and the returned `filePath` names it; pass `path` instead to present a source that already exists.",parameters:{type:`object`,properties:{title:{type:`string`,description:`Title for the 3D visualization`},script:{type:`string`,description:`ShapeScript code defining the 3D scene. Supported features and syntax are listed below. Syntax, evaluation, geometry and resource-limit errors are returned as diagnostics; correct the script and retry.
2
+
3
+ ## SYNTAX OVERVIEW:
4
+
5
+ ### Expressions & Operators:
6
+ - Arithmetic: +, -, *, /, % with proper precedence
7
+ - Comparison: =, <>, <, <=, >, >=
8
+ - Boolean: and, or, not
9
+ - Parentheses for grouping: (2 + 3) * 4
10
+
11
+ ### Variables:
12
+ define radius 2
13
+ define red (1 0 0)
14
+ sphere {
15
+ size radius
16
+ color red
17
+ }
18
+
19
+ ### Control Flow:
20
+
21
+ For loops with variables:
22
+ for i in 1 to 5 {
23
+ cube {
24
+ position (i * 2) 0 0
25
+ size 1
26
+ }
27
+ }
28
+
29
+ For loops with step:
30
+ for i in 0 to 10 step 2 {
31
+ sphere { position 0 i 0 }
32
+ }
33
+
34
+ If/else conditionals:
35
+ define showSphere 1
36
+ if showSphere {
37
+ sphere { size 2 }
38
+ } else {
39
+ cube { size 2 }
40
+ }
41
+
42
+ Switch statements:
43
+ define shape 2
44
+ switch shape {
45
+ case 1
46
+ cube
47
+ case 2
48
+ sphere
49
+ else
50
+ cone
51
+ }
52
+
53
+ ### Built-in Functions:
54
+
55
+ Math: round, floor, ceil, abs, sign, sqrt, pow, min, max
56
+ Trig: sin, cos, tan, asin, acos, atan, atan2 (uses radians)
57
+ Vector: dot, cross, length, normalize, sum
58
+ Colour: rgb(r g b [a]), hsb(h s b [a]); strings: join, split, trim
59
+
60
+ Two call spellings, both as upstream: C-like max(0 (j - 1)) with NO space before the parenthesis, or the
61
+ bare form max 0 (j - 1) / sqrt 9 / sin pi / 2, where the function takes every value after it. Separate
62
+ arguments with spaces; commas also work here (max(0, j - 1)) but NOT in the upstream ShapeScript app.
63
+ Inside a larger expression parenthesise a bare call: (sqrt 9) + (sqrt 16).
64
+ Custom functions: define hyp(a b) { sqrt(a * a + b * b) } — parameters, optional defines, then the result
65
+ expression. A function may also build shapes: define face(data) { polygon { … } } returns what it built.
66
+ Write ONE statement per line. This parser accepts "define a 1 define b 2" on one line; the upstream app
67
+ rejects it, and "size 2 1 radius 0.5" on one line reads radius as a fourth size component in both.
68
+
69
+ Examples:
70
+ for i in 1 to 8 {
71
+ define angle (i * 0.785) // 45 degrees in radians
72
+ cube { position (cos(angle) * 3) 0 (sin(angle) * 3) }
73
+ }
74
+
75
+ ### Primitives & Properties:
76
+
77
+ Shapes: cube, sphere, icosphere, cylinder, cone, torus, circle, square, roundrect (radius 0–0.5 of the smaller side), polygon (sides 3–256)
78
+ Properties: position X Y Z, orientation ROLL YAW PITCH (alias: rotation), size X Y Z, detail N, smoothing N, name "label"
79
+ Materials (as properties or as scoped commands): color, opacity, metallicity, roughness, glow, material NAME
80
+ - color takes 1–4 values: luminance, luminance+alpha, RGB, RGBA. Also hex #F00 / #FF0000 / #FF000080, the names
81
+ black blue green cyan red magenta purple yellow white orange gray/grey, hsb(...), and "color red 0.5" to set alpha.
82
+ - opacity multiplies through nested scopes (opacity 0.5 twice = 0.25); glow is an emissive colour; smoothing 0 = flat shading.
83
+ - define shiny material { color blue metallicity 1 roughness 0.1 } bundles properties; apply with material shiny.
84
+ - texture "file.png" and background "file.png" are accepted with a warning (not drawn); background R G B sets the scene colour.
85
+ - camera { … } and light { … } blocks are accepted and skipped with a warning.
86
+
87
+ UNITS (same as upstream ShapeScript — https://shapescript.info/mac/):
88
+ - size is the DIAMETER of sphere/icosphere/cylinder/cone/circle/polygon/torus (a bare sphere fits the unit cube); for cube/square it is the edge length. size 1 2 means 1 2 1 (the third value repeats the first).
89
+ - orientation / rotate use HALF-TURNS in roll (Z), yaw (Y), pitch (X) order: 0.5 = 90°, 1 = 180°. Positive is clockwise. A lone value is a roll: orientation 0.25 = 45° about Z. Angle-axis also works: orientation 0.5 0 1 0.
90
+ - rotate / translate / scale as commands are relative and accumulate; orientation as a command is absolute.
91
+ - SCOPE: a shape block, group, builder or custom block resets transforms and materials at its closing brace.
92
+ for / if / switch bodies do NOT: a translate inside a loop carries on after it (upstream's rule). Symbols
93
+ (define) are scoped by every block.
94
+ - Trig FUNCTIONS (sin, cos, …) still take radians. Convert with pi: a half-turn value h is h * pi radians.
95
+
96
+ ### CSG Operations:
97
+ union, difference, intersection, xor, stencil
98
+
99
+ Example:
100
+ difference {
101
+ sphere {
102
+ size 2
103
+ color (1 0.5 0)
104
+ }
105
+ cube { size 1.5 }
106
+ }
107
+
108
+ ### Paths:
109
+ path { point X Y … } — coordinates are ABSOLUTE in the path's frame. Close a path by repeating the first point.
110
+ A bare path draws as a LINE (stroke), as upstream; use fill / extrude / lathe / loft to make a surface or solid.
111
+ - arc { angle A } inside a path: A half-turns clockwise from +Y, radius size/2 (default 0.5), with optional
112
+ position / orientation / size — e.g. two quarter arcs and two points make a rounded slab.
113
+ - curve X Y is a quadratic Bézier CONTROL point: the outline passes through the point commands on either side, not through it. Two curves in a row get an implicit on-curve midpoint, so eight curves in an octagon draw a circle.
114
+ - A path may carry position / orientation / size of its own (path { position 0 0 2 orientation 0 0.5 0 point … }); that is how a loft section is placed in 3D. Give loft and extrude PATH children, not fill{} meshes — the upstream app rejects a mesh there.
115
+ - rotate (half-turns) / translate / scale inside a path move the frame for later points:
116
+ path {
117
+ for 0 to 8 {
118
+ curve 0 1
119
+ rotate 1 / 8
120
+ }
121
+ } // semicircle
122
+
123
+ ### Builders:
124
+ - extrude: extrude polygon { sides 3 } / extrude { … } or an inline path (size X Y scale the profile, size Z = depth, default 1):
125
+ extrude path {
126
+ point 0 0
127
+ point 1 0
128
+ point 0 1
129
+ point 0 0
130
+ }
131
+ - fill: fill { square } or fill path { ... }
132
+ - lathe (revolves the XY profile about Y):
133
+ lathe path {
134
+ point 0 0
135
+ point 1 0
136
+ curve 1.5 1
137
+ point 1 2
138
+ point 0 2
139
+ }
140
+ - loft (closed planar sections joined with caps):
141
+ loft {
142
+ square
143
+ translate 0 0 2
144
+ circle
145
+ }
146
+ - hull (convex envelope):
147
+ hull {
148
+ cube { position -1 0 0 }
149
+ cube { position 1 0 0 }
150
+ }
151
+ - stencil preserves the first shape and paints its surface with later shapes' materials.
152
+ - minkowski (the Minkowski sum; with inset it rounds edges, as upstream's Fillet example does):
153
+ define fillet(source radius) {
154
+ minkowski {
155
+ inset(source radius)
156
+ sphere { size radius * 2 }
157
+ }
158
+ }
159
+ fillet(cone { color red } 0.1)
160
+ - extrude … along (a section swept along a path, capped at the ends of an open path):
161
+ extrude {
162
+ circle { size 0.1 }
163
+ along path { for i in 0 to 20 { curve 0 1 - i / 20 rotate 0.2 } }
164
+ }
165
+ Loft sections must each have one perimeter and enclose an area; extrude/fill primitive profiles must lie in XY.
166
+ An extrude path is a solid only when it is closed (its last point repeats its first); an open path extrudes
167
+ to a wall, as upstream. inset(mesh distance) moves a mesh value's faces inward (outward when negative).
168
+ A material command inside a builder block (extrude { color red … }) colours the result; size on a builder or
169
+ group scales it. Not supported: extrude twist, svgpath, text.
170
+ - mesh { polygon { point x y z … } … }: a mesh from explicit faces; polygon { color red point a point b point c }
171
+ takes 3D points (a tuple works: point v) and a colour per face. Faces may come from a function: mesh { for f in faces { face f } }.
172
+
173
+ ### Additional Expressions:
174
+ - Constants: pi, true, false (tau exists here but NOT in the upstream app; write 2 * pi)
175
+ - A lone position / translate value is X alone (position 1 = 1 0 0); a lone size is uniform; a lone orientation is a roll.
176
+ - Scientific notation and unary plus: 1e-3, +2
177
+ - Ranges as values: define loops 1 to 5 step 2, then for i in loops { … }, for i in loops step 1, and
178
+ "if 3 in loops"; the in operator also tests tuples (2 in (1 2 3)) and strings.
179
+ - Tuple/vector members: .x .y .z, .width .height .depth, .roll .yaw .pitch, .red .green .blue .alpha, .hue .saturation .brightness
180
+ - Tuple/string length: value.count; zero-based indexing values[0], negative from the end values[-1], by name values["y"];
181
+ ordinals: v.first v.second … v.last, v.allButFirst, v.allButLast
182
+ - String literals, join(...), split(...), trim(...); min/max also accept tuples
183
+ - print a b … records output that is returned with the tool result; assert condition stops the script when false
184
+ - Custom shapes with options:
185
+ define post {
186
+ option height 2
187
+ cylinder { size 0.2 height }
188
+ }
189
+ post { height 3 }
190
+ - Random numbers: rnd (0–1) and seed N (scoped to the enclosing block, same generator as upstream)
191
+ - Shapes as values: define ico icosphere { detail 0 } then ico (places it), ico.polygons (faces, each with
192
+ .center .points .bounds), ico.triangles, ico.bounds (.min .max .center .size .width .height .depth), ico.volume.
193
+ - for / if as expressions: define scales for i in 1 to 3 { i / 3 }; define c if big { red } else { white }
194
+ - Functions may build shapes: define face(data) { polygon { … } } and are called bare as statements: face data
195
+
196
+ ### Compatibility:
197
+ This plugin implements the documented modeling subset, not all upstream ShapeScript syntax; units, scoping,
198
+ materials and path semantics follow upstream, so a script written against the upstream docs renders the
199
+ same here. Not supported (each is refused by name): import, text/font, svgpath, extrude twist,
200
+ object values and paths as values. Textures, cameras and lights are accepted but not drawn.
201
+
202
+ ### Comments:
203
+ // Single-line comment
204
+ /* Multi-line
205
+ comment */
206
+
207
+ ## COMPLETE EXAMPLES:
208
+
209
+ Linear arrangement with expressions:
210
+ define spacing 1.5
211
+ for i in 1 to 4 {
212
+ cylinder {
213
+ position ((i - 2.5) * spacing) 0 0
214
+ size 0.4 1
215
+ }
216
+ }
217
+
218
+ Circular pattern:
219
+ define count 12
220
+ for i in 1 to count {
221
+ define angle ((i / count) * 6.283) // 2 * PI
222
+ cube {
223
+ position (cos(angle) * 3) 0 (sin(angle) * 3)
224
+ color (i / count) 0.5 (1 - i / count)
225
+ size 0.5
226
+ }
227
+ }
228
+
229
+ Conditional geometry:
230
+ define makeHollow 1
231
+ if makeHollow {
232
+ difference {
233
+ sphere {
234
+ size 2
235
+ color (1 0 0)
236
+ }
237
+ sphere { size 1.7 }
238
+ }
239
+ } else {
240
+ sphere {
241
+ size 2
242
+ color (1 0 0)
243
+ }
244
+ }
245
+
246
+ Mathematical visualization:
247
+ for x in -5 to 5 {
248
+ for z in -5 to 5 {
249
+ define height (sin(x * 0.5) * cos(z * 0.5) * 2)
250
+ cube {
251
+ position (x * 0.3) height (z * 0.3)
252
+ size 0.25 (abs(height) + 0.1) 0.25
253
+ color (0.5 + height * 0.25) 0.3 (0.5 - height * 0.25)
254
+ }
255
+ }
256
+ }`},path:{type:`string`,description:"Path to an EXISTING ShapeScript source to present in place, instead of `script` — a `.shape` file this tool saved earlier (`artifacts/shapes/…`) or any other on disk. Provide either `script` or `path`, never both. Edits the user makes in the view write back to that same file."}},required:[`title`]}},i=`shapes`,a=`shape`,o=[`.shape`];function s(e,n=a){return(0,t.slugifyArtifact)(e,n)}function c(){let e=globalThis.crypto;if(e?.getRandomValues){let t=e.getRandomValues(new Uint8Array(4));return Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return Math.random().toString(16).slice(2,10).padEnd(8,`0`)}function l(e,n=new Date,r=c()){let o=(0,t.buildArtifactRelPath)({dir:i,title:e,ext:`.shape`,fallback:a,now:n,partitioned:!1,suffix:r});return{relPath:o,filePath:(0,t.toWorkspaceArtifactPath)(o)}}function u(e,n=new Date,r=c()){let o=(0,t.buildArtifactRelPath)({dir:i,title:e,ext:`.usdz`,fallback:a,now:n,partitioned:!1,suffix:r});return{relPath:o,filePath:(0,t.toWorkspaceArtifactPath)(o)}}function d(e){return!e.startsWith(`${t.ARTIFACTS_ROOT}/${i}/`)||!e.endsWith(`.shape`)?!1:!(0,t.hasUnsafePathSegment)(e)}function f(e){return e.startsWith(`${t.ARTIFACTS_ROOT}/`)?e.slice(t.ARTIFACTS_ROOT.length+1):e}function p(e){return(0,t.classifyFilePath)(e,o)!==null}function m(e,t){if(d(t))return{files:e.files.artifacts,rel:f(t)};let n=e.files.byPath;return n&&p(t)?{files:n,rel:t}:null}async function h(e,t){if(typeof t?.path!=`string`)throw Error(`path must be an existing .shape file`);let n=m(e,t.path);if(!n)throw Error(`path must be an existing .shape file`);switch(t.kind){case`loadShape`:return{script:await n.files.read(n.rel)};case`saveShape`:if(typeof t.script!=`string`)throw Error("saveShape requires `script` as a string");if(!await n.files.exists(n.rel))throw Error(`No ShapeScript exists at ${t.path}`);return await n.files.write(n.rel,t.script),{path:t.path};default:throw Error(`shapescript plugin: unknown dispatch kind ${JSON.stringify(t)}`)}}var g=`Acknowledge that the 3D visualization has been created and is displayed to the user. They can rotate, zoom, and pan the camera.`,_=e=>typeof e==`string`&&e.trim()!==``;function v(t){let n=e.r(e.s(t)),r=e.i(n);return e.a(n),r}function y(e){let t=[];return e.warnings.length&&t.push(`Not rendered: ${e.warnings.join(`; `)}`),e.logs.length&&t.push(`Output:\n${e.logs.join(`
257
+ `)}`),t.length?`\n${t.join(`
258
+ `)}`:``}async function b(e,t){let n=e.files;if(!n)throw Error("This host cannot open a ShapeScript by path — pass the source as `script` instead");let r=m({files:n},t);if(!r)throw Error("`path` must be a .shape file, without `.` / `..` segments");if(!await r.files.exists(r.rel))throw Error(`No ShapeScript exists at ${t}`);return r.files.read(r.rel)}var x=5;async function S(e,t,n){let r=e.files?.artifacts;if(r){for(let e=0;e<x;e++){let{relPath:e,filePath:i}=l(n);if(!await r.exists(e))return await r.write(e,t),i}throw Error(`Could not allocate a free path under artifacts/shapes — try again with a different title`)}}async function C(e,t){if(_(t.path)&&_(t.script))throw Error("Provide either `script` or `path`, not both");if(_(t.path))return{script:await b(e,t.path),filePath:t.path};if(!_(t.script))throw Error(`ShapeScript code is required but was not provided`);return{script:t.script}}var w=async(t,n)=>{let r=`INVALID_ARGUMENT`;try{if(!e.zn(n))throw Error("presentShapeScript args must be an object with `script` or `path`");if(!_(n.title))throw Error(`A nonempty visualization title is required`);let i=await C(t??{},n);r=`EVALUATION_ERROR`;let a=v(i.script),o=i.filePath??await S(t??{},i.script,n.title);return{message:(o?`Saved ShapeScript to ${o}`:`Created 3D visualization: ${n.title}`)+y(a),title:n.title,data:o?{script:i.script,filePath:o}:{script:i.script},instructions:g}}catch(t){let n={code:t instanceof e.Rn?`PARSE_ERROR`:t instanceof e.n?`LIMIT_EXCEEDED`:r,message:t instanceof Error?t.message:String(t),...t instanceof e.Rn&&t.line!==void 0?{line:t.line}:{},...t instanceof e.Rn&&t.column!==void 0?{column:t.column}:{}};return{message:`ShapeScript error: ${n.message}`,error:n,jsonData:{error:n},instructions:`The visualization was not created. Correct the ShapeScript using the returned diagnostic and call presentShapeScript again.`}}},T={toolDefinition:r,execute:w,generatingMessage:`Creating 3D visualization...`,waitingMessage:`Tell the user that the 3D visualization was created and will be presented shortly.`,isEnabled:()=>!0},E=w,D=Uint8Array,O=Uint16Array,k=Int32Array,ee=new D([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),te=new D([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),A=new D([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),j=function(e,t){for(var n=new O(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new k(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},M=j(ee,2),N=M.b,P=M.r;N[28]=258,P[258]=28;var F=j(te,0);F.b;for(var I=F.r,L=new O(32768),R=0;R<32768;++R){var z=(R&43690)>>1|(R&21845)<<1;z=(z&52428)>>2|(z&13107)<<2,z=(z&61680)>>4|(z&3855)<<4,L[R]=((z&65280)>>8|(z&255)<<8)>>1}for(var B=(function(e,t,n){for(var r=e.length,i=0,a=new O(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new O(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new O(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[L[d]>>c]=l}else for(s=new O(r),i=0;i<r;++i)e[i]&&(s[i]=L[o[e[i]-1]++]>>15-e[i]);return s}),V=new D(288),R=0;R<144;++R)V[R]=8;for(var R=144;R<256;++R)V[R]=9;for(var R=256;R<280;++R)V[R]=7;for(var R=280;R<288;++R)V[R]=8;for(var H=new D(32),R=0;R<32;++R)H[R]=5;var ne=B(V,9,0),re=B(H,5,0),ie=function(e){return(e+7)/8|0},U=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new D(e.subarray(t,n))},W=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],G=function(e,t,n){var r=Error(t||W[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,G),!n)throw r;return r},K=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8},q=function(e,t,n){n<<=t&7;var r=t/8|0;e[r]|=n,e[r+1]|=n>>8,e[r+2]|=n>>16},J=function(e,t){for(var n=[],r=0;r<e.length;++r)e[r]&&n.push({s:r,f:e[r]});var i=n.length,a=n.slice();if(!i)return{t:le,l:0};if(i==1){var o=new D(n[0].s+1);return o[n[0].s]=1,{t:o,l:1}}n.sort(function(e,t){return e.f-t.f}),n.push({s:-1,f:25001});var s=n[0],c=n[1],l=0,u=1,d=2;for(n[0]={s:-1,f:s.f+c.f,l:s,r:c};u!=i-1;)s=n[n[l].f<n[d].f?l++:d++],c=n[l!=u&&n[l].f<n[d].f?l++:d++],n[u++]={s:-1,f:s.f+c.f,l:s,r:c};for(var f=a[0].s,r=1;r<i;++r)a[r].s>f&&(f=a[r].s);var p=new O(f+1),m=Y(n[u-1],p,0);if(m>t){var r=0,h=0,g=m-t,_=1<<g;for(a.sort(function(e,t){return p[t.s]-p[e.s]||e.f-t.f});r<i;++r){var v=a[r].s;if(p[v]>t)h+=_-(1<<m-p[v]),p[v]=t;else break}for(h>>=g;h>0;){var y=a[r].s;p[y]<t?h-=1<<t-p[y]++-1:++r}for(;r>=0&&h;--r){var b=a[r].s;p[b]==t&&(--p[b],++h)}m=t}return{t:new D(p),l:m}},Y=function(e,t,n){return e.s==-1?Math.max(Y(e.l,t,n+1),Y(e.r,t,n+1)):t[e.s]=n},ae=function(e){for(var t=e.length;t&&!e[--t];);for(var n=new O(++t),r=0,i=e[0],a=1,o=function(e){n[r++]=e},s=1;s<=t;++s)if(e[s]==i&&s!=t)++a;else{if(!i&&a>2){for(;a>138;a-=138)o(32754);a>2&&(o(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(o(i),--a;a>6;a-=6)o(8304);a>2&&(o(a-3<<5|8208),a=0)}for(;a--;)o(i);a=1,i=e[s]}return{c:n.subarray(0,r),n:t}},X=function(e,t){for(var n=0,r=0;r<t.length;++r)n+=e[r]*t[r];return n},oe=function(e,t,n){var r=n.length,i=ie(t+2);e[i]=r&255,e[i+1]=r>>8,e[i+2]=e[i]^255,e[i+3]=e[i+1]^255;for(var a=0;a<r;++a)e[i+a+4]=n[a];return(i+4+r)*8},se=function(e,t,n,r,i,a,o,s,c,l,u){K(t,u++,n),++i[256];for(var d=J(i,15),f=d.t,p=d.l,m=J(a,15),h=m.t,g=m.l,_=ae(f),v=_.c,y=_.n,b=ae(h),x=b.c,S=b.n,C=new O(19),w=0;w<v.length;++w)++C[v[w]&31];for(var w=0;w<x.length;++w)++C[x[w]&31];for(var T=J(C,7),E=T.t,D=T.l,k=19;k>4&&!E[A[k-1]];--k);var j=l+5<<3,M=X(i,V)+X(a,H)+o,N=X(i,f)+X(a,h)+o+14+3*k+X(C,E)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&j<=M&&j<=N)return oe(t,u,e.subarray(c,c+l));var P,F,I,L;if(K(t,u,1+(N<M)),u+=2,N<M){P=B(f,p,0),F=f,I=B(h,g,0),L=h;var R=B(E,D,0);K(t,u,y-257),K(t,u+5,S-1),K(t,u+10,k-4),u+=14;for(var w=0;w<k;++w)K(t,u+3*w,E[A[w]]);u+=3*k;for(var z=[v,x],ie=0;ie<2;++ie)for(var U=z[ie],w=0;w<U.length;++w){var W=U[w]&31;K(t,u,R[W]),u+=E[W],W>15&&(K(t,u,U[w]>>5&127),u+=U[w]>>12)}}else P=ne,F=V,I=re,L=H;for(var w=0;w<s;++w){var G=r[w];if(G>255){var W=G>>18&31;q(t,u,P[W+257]),u+=F[W+257],W>7&&(K(t,u,G>>23&31),u+=ee[W]);var Y=G&31;q(t,u,I[Y]),u+=L[Y],Y>3&&(q(t,u,G>>5&8191),u+=te[Y])}else q(t,u,P[G]),u+=F[G]}return q(t,u,P[256]),u+F[256]},ce=new k([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),le=new D(0),ue=function(e,t,n,r,i,a){var o=a.z||e.length,s=new D(r+o+5*(1+Math.ceil(o/7e3))+i),c=s.subarray(r,s.length-i),l=a.l,u=(a.r||0)&7;if(t){u&&(c[0]=a.r>>3);for(var d=ce[t-1],f=d>>13,p=d&8191,m=(1<<n)-1,h=a.p||new O(32768),g=a.h||new O(m+1),_=Math.ceil(n/3),v=2*_,y=function(t){return(e[t]^e[t+1]<<_^e[t+2]<<v)&m},b=new k(25e3),x=new O(288),S=new O(32),C=0,w=0,T=a.i||0,E=0,A=a.w||0,j=0;T+2<o;++T){var M=y(T),N=T&32767,F=g[M];if(h[N]=F,g[M]=N,A<=T){var L=o-T;if((C>7e3||E>24576)&&(L>423||!l)){u=se(e,c,0,b,x,S,w,E,j,T-j,u),E=C=w=0,j=T;for(var R=0;R<286;++R)x[R]=0;for(var R=0;R<30;++R)S[R]=0}var z=2,B=0,V=p,H=N-F&32767;if(L>2&&M==y(T-H))for(var ne=Math.min(f,L)-1,re=Math.min(32767,T),W=Math.min(258,L);H<=re&&--V&&N!=F;){if(e[T+z]==e[T+z-H]){for(var G=0;G<W&&e[T+G]==e[T+G-H];++G);if(G>z){if(z=G,B=H,G>ne)break;for(var K=Math.min(H,G-2),q=0,R=0;R<K;++R){var J=T-H+R&32767,Y=J-h[J]&32767;Y>q&&(q=Y,F=J)}}}N=F,F=h[N],H+=N-F&32767}if(B){b[E++]=268435456|P[z]<<18|I[B];var ae=P[z]&31,X=I[B]&31;w+=ee[ae]+te[X],++x[257+ae],++S[X],A=T+z,++C}else b[E++]=e[T],++x[e[T]]}}for(T=Math.max(T,A);T<o;++T)b[E++]=e[T],++x[e[T]];u=se(e,c,l,b,x,S,w,E,j,T-j,u),l||(a.r=u&7|c[u/8|0]<<3,u-=7,a.h=g,a.p=h,a.i=T,a.w=A)}else{for(var T=a.w||0;T<o+l;T+=65535){var le=T+65535;le>=o&&(c[u/8|0]=l,le=o),u=oe(c,u+1,e.subarray(T,le))}a.i=o}return U(s,0,r+ie(u)+i)},de=(function(){for(var e=new Int32Array(256),t=0;t<256;++t){for(var n=t,r=9;--r;)n=(n&1&&-306674912)^n>>>1;e[t]=n}return e})(),fe=function(){var e=-1;return{p:function(t){for(var n=e,r=0;r<t.length;++r)n=de[n&255^t[r]]^n>>>8;e=n},d:function(){return~e}}},pe=function(e,t,n,r,i){if(!i&&(i={l:1},t.dictionary)){var a=t.dictionary.subarray(-32768),o=new D(a.length+e.length);o.set(a),o.set(e,a.length),e=o,i.w=a.length}return ue(e,t.level==null?6:t.level,t.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(e.length)))*1.5):20:12+t.mem,n,r,i)},me=function(e,t){var n={};for(var r in e)n[r]=e[r];for(var r in t)n[r]=t[r];return n},Z=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8};function he(e,t){return pe(e,t||{},0,0)}var ge=function(e,t,n,r){for(var i in e){var a=e[i],o=t+i,s=r;Array.isArray(a)&&(s=me(r,a[1]),a=a[0]),a instanceof D?n[o]=[a,s]:(n[o+=`/`]=[new D(0),s],ge(a,o,n,r))}},_e=typeof TextEncoder<`u`&&new TextEncoder,ve=typeof TextDecoder<`u`&&new TextDecoder;try{ve.decode(le,{stream:!0})}catch{}function ye(e,t){if(t){for(var n=new D(e.length),r=0;r<e.length;++r)n[r]=e.charCodeAt(r);return n}if(_e)return _e.encode(e);for(var i=e.length,a=new D(e.length+(e.length>>1)),o=0,s=function(e){a[o++]=e},r=0;r<i;++r){if(o+5>a.length){var c=new D(o+8+(i-r<<1));c.set(a),a=c}var l=e.charCodeAt(r);l<128||t?s(l):l<2048?(s(192|l>>6),s(128|l&63)):l>55295&&l<57344?(l=65536+(l&1047552)|e.charCodeAt(++r)&1023,s(240|l>>18),s(128|l>>12&63),s(128|l>>6&63),s(128|l&63)):(s(224|l>>12),s(128|l>>6&63),s(128|l&63))}return U(a,0,o)}var be=function(e){var t=0;if(e)for(var n in e){var r=e[n].length;r>65535&&G(9),t+=r+4}return t},xe=function(e,t,n,r,i,a,o,s){var c=r.length,l=n.extra,u=s&&s.length,d=be(l);Z(e,t,o==null?67324752:33639248),t+=4,o!=null&&(e[t++]=20,e[t++]=n.os),e[t]=20,t+=2,e[t++]=n.flag<<1|(a<0&&8),e[t++]=i&&8,e[t++]=n.compression&255,e[t++]=n.compression>>8;var f=new Date(n.mtime==null?Date.now():n.mtime),p=f.getFullYear()-1980;if((p<0||p>119)&&G(10),Z(e,t,p<<25|f.getMonth()+1<<21|f.getDate()<<16|f.getHours()<<11|f.getMinutes()<<5|f.getSeconds()>>1),t+=4,a!=-1&&(Z(e,t,n.crc),Z(e,t+4,a<0?-a-2:a),Z(e,t+8,n.size)),Z(e,t+12,c),Z(e,t+14,d),t+=16,o!=null&&(Z(e,t,u),Z(e,t+6,n.attrs),Z(e,t+10,o),t+=14),e.set(r,t),t+=c,d)for(var m in l){var h=l[m],g=h.length;Z(e,t,+m),Z(e,t+2,g),e.set(h,t+4),t+=4+g}return u&&(e.set(s,t),t+=u),t},Se=function(e,t,n,r,i){Z(e,t,101010256),Z(e,t+8,n),Z(e,t+10,n),Z(e,t+12,r),Z(e,t+16,i)};function Ce(e,t){t||={};var n={},r=[];ge(e,``,n,t);var i=0,a=0;for(var o in n){var s=n[o],c=s[0],l=s[1],u=l.level==0?0:8,d=ye(o),f=d.length,p=l.comment,m=p&&ye(p),h=m&&m.length,g=be(l.extra);f>65535&&G(11);var _=u?he(c,l):c,v=_.length,y=fe();y.p(c),r.push(me(l,{size:c.length,crc:y.d(),c:_,f:d,m,u:f!=o.length||m&&p.length!=h,o:i,compression:u})),i+=30+f+g+v,a+=76+2*(f+g)+(h||0)+v}for(var b=new D(a+22),x=i,S=a-i,C=0;C<r.length;++C){var d=r[C];xe(b,d.o,d,d.f,d.u,d.c.length);var w=30+d.f.length+be(d.extra);b.set(d.c,d.o+w),xe(b,i,d,d.f,d.u,d.c.length,d.o,d.m),i+=16+w+(d.m?d.m.length:0)}return Se(b,i,r.length,S,x),b}var Q=class{constructor(e,t=``,n=[],r=[]){this.name=e,this.type=t,this.metadata=n,this.properties=r,this.children=[]}addMetadata(e,t){this.metadata.push({key:e,value:t})}addProperty(e,t=[]){this.properties.push({property:e,metadata:t})}addChild(e){this.children.push(e)}toString(e=0){let t=` `.repeat(e),n=this.metadata.map(e=>{let n=e.key,r=e.value;if(Array.isArray(r)){let e=[];return e.push(`${n} = {`),r.forEach(n=>{e.push(`${t}\t\t${n}`)}),e.push(`${t}\t}`),e.join(`
259
+ `)}return`${n} = ${r}`}),r=n.length?` (\n${n.map(e=>`${t}\t${e}`).join(`
260
+ `)}\n${t})`:``,i=this.properties.map(e=>{let n=e.property.replace(/\n/g,`
261
+ `+t+` `),r=e.metadata.length?` (\n${e.metadata.map(e=>`${t}\t\t${e}`).join(`
262
+ `)}\n${t}\t)`:``;return`${t}\t${n}${r}`}),a=this.children.map(t=>t.toString(e+1)),o=[];if(i.length>0&&o.push(...i),a.length>0){i.length>0&&o.push(``);for(let e=0;e<a.length;e++)o.push(a[e]),e<a.length-1&&o.push(``)}let s=o.join(`
263
+ `);return`${t}def ${this.type?this.type+` `:``}"${this.name}"${r}\n${t}{\n${s}\n${t}}`}},we=class{constructor(){this.textureUtils=null}setTextureUtils(e){this.textureUtils=e}parse(e,t,n,r){this.parseAsync(e,r).then(t).catch(n)}async parseAsync(e,t={}){t=Object.assign({ar:{anchoring:{type:`plane`},planeAnchoring:{alignment:`horizontal`}},includeAnchoringProperties:!0,onlyVisible:!0,quickLookCompatible:!1,maxTextureSize:1024,animations:[],animationFrameRate:60},t);let n=new Set,r={},i=`model.usda`;r[i]=null;let a=ke(e,t.animations);t.animationTracks=a;let o=new Q(`Root`,`Xform`),s=new Q(`Scenes`,`Scope`);s.addMetadata(`kind`,`"sceneLibrary"`),o.addChild(s);let c=`Scene`,l=new Q(c,`Xform`);l.addMetadata(`customData`,[`bool preliminary_collidesWithEnvironment = 0`,`string sceneName = "${c}"`]),l.addMetadata(`sceneName`,`"${c}"`),t.includeAnchoringProperties&&(l.addProperty(`token preliminary:anchoring:type = "${t.ar.anchoring.type}"`),l.addProperty(`token preliminary:planeAnchoring:alignment = "${t.ar.planeAnchoring.alignment}"`)),s.addChild(l);let u,d={},f={};e.isScene?Ne(e,l,d,n,r,t):Pe(e,l,d,n,r,t);let p=Ke(d,f,t.quickLookCompatible);u=Oe(a.size>0?{fps:t.animationFrameRate,endTimeCode:Ae(t.animations)*t.animationFrameRate}:null)+`
264
+ `+o.toString()+`
265
+
266
+ `+p.toString(),r[i]=ye(u),u=null;for(let e in f){let n=f[e];if(n.isCompressedTexture===!0){if(this.textureUtils===null)throw Error(`THREE.USDZExporter: setTextureUtils() must be called to process compressed textures.`);n=await this.textureUtils.decompress(n)}let i=De(n.image,n.flipY,t.maxTextureSize),a=n.userData.mimeType===`image/jpeg`?`image/jpeg`:`image/png`,o=await new Promise(e=>i.toBlob(e,a));r[`textures/Texture_${e}.${Ee(n)}`]=new Uint8Array(await o.arrayBuffer())}let m=0;for(let e in r){let t=r[e],n=34+e.length;m+=n;let i=m&63;if(i!==4){let n=64-i;r[e]=[t,{extra:{12345:new Uint8Array(n)}}]}m=t.length}return Ce(r,{level:0})}};function Te(e,t){let n=e.name;return n=n.replace(/[^A-Za-z0-9_]/g,``),/^[0-9]/.test(n)&&(n=`_`+n),n===``&&(n=e.isCamera?`Camera`:`Object`),t.has(n)&&(n=n+`_`+e.id),t.add(n),n}function Ee(e){return e.userData.mimeType===`image/jpeg`?`jpg`:`png`}function De(e,t,n){if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<`u`&&e instanceof OffscreenCanvas||typeof ImageBitmap<`u`&&e instanceof ImageBitmap){let r=n/Math.max(e.width,e.height),i=document.createElement(`canvas`);i.width=e.width*Math.min(1,r),i.height=e.height*Math.min(1,r);let a=i.getContext(`2d`);return t===!0&&(a.translate(0,i.height),a.scale(1,-1)),a.drawImage(e,0,0,i.width,i.height),i}throw Error(`THREE.USDZExporter: No valid image data found. Unable to process texture.`)}var $=7;function Oe(e=null){return`#usda 1.0
267
+ (
268
+ customLayerData = {
269
+ string creator = "Three.js USDZExporter"
270
+ }
271
+ defaultPrim = "Root"
272
+ metersPerUnit = 1
273
+ upAxis = "Y"${e?`
274
+ startTimeCode = 0
275
+ endTimeCode = ${e.endTimeCode}
276
+ timeCodesPerSecond = ${e.fps}
277
+ framesPerSecond = ${e.fps}`:``}
278
+ )
279
+ `}function ke(t,n){let r=new Map;for(let i=0;i<n.length;i++){let a=n[i];for(let n=0;n<a.tracks.length;n++){let i=a.tracks[n],o=e.ot.parseTrackName(i.name),s=e.ot.findNode(t,o.nodeName);if(s==null)continue;let c=o.propertyName;if(c!==`position`&&c!==`quaternion`&&c!==`scale`)continue;let l=r.get(s);l===void 0&&(l={},r.set(s,l)),l[c]=i}}return r}function Ae(e){let t=0;for(let n=0;n<e.length;n++)e[n].duration>t&&(t=e[n].duration);return t}function je(e,t,n,r){let i=n.times,a=n.values,o=[];for(let e=0;e<i.length;e++){let t=e*3;o.push(`${(i[e]*r).toPrecision($)}: (${a[t].toPrecision($)}, ${a[t+1].toPrecision($)}, ${a[t+2].toPrecision($)})`)}return`${t} ${e}.timeSamples = {\n\t${o.join(`,
280
+ `)},\n}`}function Me(e,t){let n=e.times,r=e.values,i=[];for(let e=0;e<n.length;e++){let a=e*4;i.push(`${(n[e]*t).toPrecision($)}: (${r[a+3].toPrecision($)}, ${r[a].toPrecision($)}, ${r[a+1].toPrecision($)}, ${r[a+2].toPrecision($)})`)}return`quatf xformOp:orient.timeSamples = {\n\t${i.join(`,
281
+ `)},\n}`}function Ne(e,t,n,r,i,a){for(let o=0,s=e.children.length;o<s;o++)Pe(e.children[o],t,n,r,i,a)}function Pe(e,t,n,r,i,a){if(e.visible===!1&&a.onlyVisible===!0)return;let o;if(e.isMesh){let t=e.geometry,s=Array.isArray(e.material),c=s?e.material:[e.material];for(let e=0;e<c.length;e++){let t=c[e];t.isMeshStandardMaterial||console.warn(`THREE.USDZExporter: Use MeshStandardMaterial for best results.`),t.uuid in n||(n[t.uuid]=t)}let l=c.map(e=>n[e.uuid]);if(s===!1){let e=`geometries/Geometry_${t.id}.usda`;if(!(e in i)){let n=Be(t);i[e]=ye(Oe()+`
282
+ `+n.toString())}}o=Le(e,t,l,r,a)}else o=e.isCamera?Ze(e,r,a):Ie(e,r,a);t.addChild(o),Ne(e,o,n,r,i,a)}function Fe(e,t,n){let r=n.animationTracks.get(t),i=t.pivot!==null;if(!i&&r===void 0){let n=Re(t.matrix);e.addProperty(`matrix4d xformOp:transform = ${n}`),e.addProperty(`uniform token[] xformOpOrder = ["xformOp:transform"]`);return}let a=n.animationFrameRate,o=t.position,s=t.quaternion,c=t.scale;if(r!==void 0&&r.position!==void 0?e.addProperty(je(`xformOp:translate`,`float3`,r.position,a)):e.addProperty(`float3 xformOp:translate = (${o.x.toPrecision($)}, ${o.y.toPrecision($)}, ${o.z.toPrecision($)})`),i){let n=t.pivot;e.addProperty(`float3 xformOp:translate:pivot = (${n.x.toPrecision($)}, ${n.y.toPrecision($)}, ${n.z.toPrecision($)})`)}r!==void 0&&r.quaternion!==void 0?e.addProperty(Me(r.quaternion,a)):e.addProperty(`quatf xformOp:orient = (${s.w.toPrecision($)}, ${s.x.toPrecision($)}, ${s.y.toPrecision($)}, ${s.z.toPrecision($)})`),r!==void 0&&r.scale!==void 0?e.addProperty(je(`xformOp:scale`,`float3`,r.scale,a)):e.addProperty(`float3 xformOp:scale = (${c.x.toPrecision($)}, ${c.y.toPrecision($)}, ${c.z.toPrecision($)})`),i?e.addProperty(`uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:translate:pivot", "xformOp:orient", "xformOp:scale", "!invert!xformOp:translate:pivot"]`):e.addProperty(`uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]`)}function Ie(e,t,n){let r=Te(e,t);e.matrix.determinant()<0&&console.warn(`THREE.USDZExporter: USDZ does not support negative scales`,e);let i=new Q(r,`Xform`);return Fe(i,e,n),i}function Le(e,t,n,r,i){let a=Ie(e,r,i);return n.length===1?(a.addMetadata(`prepend references`,`@./geometries/Geometry_${t.id}.usda@</Geometry>`),a.addMetadata(`prepend apiSchemas`,`["MaterialBindingAPI"]`),a.addProperty(`rel material:binding = </Materials/Material_${n[0].id}>`)):a.addChild(Ve(t,n)),a}function Re(e){let t=e.elements;return`( ${ze(t,0)}, ${ze(t,4)}, ${ze(t,8)}, ${ze(t,12)} )`}function ze(e,t){return`(${e[t+0]}, ${e[t+1]}, ${e[t+2]}, ${e[t+3]})`}function Be(e){let t=new Q(`Geometry`),n=Ve(e);return t.addChild(n),t}function Ve(e,t=null){let n=e.attributes,r=n.position.count,i=new Q(`Geometry`,`Mesh`);i.addProperty(`int[] faceVertexCounts = [${He(e)}]`),i.addProperty(`int[] faceVertexIndices = [${Ue(e)}]`),i.addProperty(`normal3f[] normals = [${We(n.normal,r)}]`,[`interpolation = "vertex"`]),i.addProperty(`point3f[] points = [${We(n.position,r)}]`);for(let e=0;e<4;e++){let t=e>0?e:``,r=n[`uv`+t];r!==void 0&&i.addProperty(`texCoord2f[] primvars:st${t} = [${Ge(r)}]`,[`interpolation = "vertex"`])}let a=n.color;if(a!==void 0&&i.addProperty(`color3f[] primvars:displayColor = [${We(a,r)}]`,[`interpolation = "vertex"`]),i.addProperty(`uniform token subdivisionScheme = "none"`),t!==null){let r=e.groups,a=(e.index===null?n.position.count:e.index.count)/3;for(let e=0;e<r.length;e++){let n=r[e],o=t[n.materialIndex];if(o===void 0)continue;let s=Math.floor(n.start/3),c=Math.min(s+Math.floor(n.count/3),a),l=[];for(let e=s;e<c;e++)l.push(e);let u=new Q(`subset_${e}`,`GeomSubset`);u.addMetadata(`prepend apiSchemas`,`["MaterialBindingAPI"]`),u.addProperty(`uniform token elementType = "face"`),u.addProperty(`uniform token familyName = "materialBind"`),u.addProperty(`int[] indices = [${l.join(`, `)}]`),u.addProperty(`rel material:binding = </Materials/Material_${o.id}>`),i.addChild(u)}}return i}function He(e){let t=e.index===null?e.attributes.position.count:e.index.count;return Array(t/3).fill(3).join(`, `)}function Ue(e){let t=e.index,n=[];if(t!==null)for(let e=0;e<t.count;e++)n.push(t.getX(e));else{let t=e.attributes.position.count;for(let e=0;e<t;e++)n.push(e)}return n.join(`, `)}function We(e,t){if(e===void 0)return console.warn(`USDZExporter: Normals missing.`),Array(t).fill(`(0, 0, 0)`).join(`, `);let n=[];for(let t=0;t<e.count;t++){let r=e.getX(t),i=e.getY(t),a=e.getZ(t);n.push(`(${r.toPrecision($)}, ${i.toPrecision($)}, ${a.toPrecision($)})`)}return n.join(`, `)}function Ge(e){let t=[];for(let n=0;n<e.count;n++){let r=e.getX(n),i=e.getY(n);t.push(`(${r.toPrecision($)}, ${1-i.toPrecision($)})`)}return t.join(`, `)}function Ke(e,t,n=!1){let r=new Q(`Materials`);for(let i in e){let a=e[i];r.addChild(qe(a,t,n))}return r}function qe(t,n,r=!1){let i=new Q(`Material_${t.id}`,`Material`);function a(e,i,a){let o=e.source.id+`_`+e.flipY;n[o]=e;let s=e.channel>0?`st`+e.channel:`st`,c={1e3:`repeat`,1001:`clamp`,1002:`mirror`},l=e.repeat.clone(),u=e.offset.clone(),d=e.rotation,f=Math.sin(d),p=Math.cos(d);u.y=1-u.y-l.y,r?(u.x/=l.x,u.y/=l.y,u.x+=f/l.x,u.y+=p-1):(u.x+=f*l.x,u.y+=(1-p)*l.y);let m=new Q(`PrimvarReader_${i}`,`Shader`);m.addProperty(`uniform token info:id = "UsdPrimvarReader_float2"`),m.addProperty(`float2 inputs:fallback = (0.0, 0.0)`),m.addProperty(`string inputs:varname = "${s}"`),m.addProperty(`float2 outputs:result`);let h=new Q(`Transform2d_${i}`,`Shader`);h.addProperty(`uniform token info:id = "UsdTransform2d"`),h.addProperty(`float2 inputs:in.connect = </Materials/Material_${t.id}/PrimvarReader_${i}.outputs:result>`),h.addProperty(`float inputs:rotation = ${(180/Math.PI*d).toFixed($)}`),h.addProperty(`float2 inputs:scale = ${Xe(l)}`),h.addProperty(`float2 inputs:translation = ${Xe(u)}`),h.addProperty(`float2 outputs:result`);let g=new Q(`Texture_${e.id}_${i}`,`Shader`);if(g.addProperty(`uniform token info:id = "UsdUVTexture"`),g.addProperty(`asset inputs:file = @textures/Texture_${o}.${Ee(e)}@`),g.addProperty(`float2 inputs:st.connect = </Materials/Material_${t.id}/Transform2d_${i}.outputs:result>`),a!==void 0){let e=i===`diffuse`?t.opacity:1;g.addProperty(`float4 inputs:scale = ${Ye(a,e)}`)}if(i===`normal`){let e=t.normalScale.x;g.addProperty(`float4 inputs:scale = (${2*e}, ${2*e}, 2, 1)`),g.addProperty(`float4 inputs:bias = (${-e}, ${-e}, -1, 0)`)}return g.addProperty(`token inputs:sourceColorSpace = "${e.colorSpace===``?`raw`:`sRGB`}"`),g.addProperty(`token inputs:wrapS = "${c[e.wrapS]}"`),g.addProperty(`token inputs:wrapT = "${c[e.wrapT]}"`),g.addProperty(`float outputs:r`),g.addProperty(`float outputs:g`),g.addProperty(`float outputs:b`),g.addProperty(`float3 outputs:rgb`),(t.transparent||t.alphaTest>0)&&g.addProperty(`float outputs:a`),[m,h,g]}t.side===2&&console.warn(`THREE.USDZExporter: USDZ does not support double sided materials`,t);let o=new Q(`PreviewSurface`,`Shader`);if(o.addProperty(`uniform token info:id = "UsdPreviewSurface"`),t.map===null?o.addProperty(`color3f inputs:diffuseColor = ${Je(t.color)}`):(o.addProperty(`color3f inputs:diffuseColor.connect = </Materials/Material_${t.id}/Texture_${t.map.id}_diffuse.outputs:rgb>`),t.transparent?o.addProperty(`float inputs:opacity.connect = </Materials/Material_${t.id}/Texture_${t.map.id}_diffuse.outputs:a>`):t.alphaTest>0&&(o.addProperty(`float inputs:opacity.connect = </Materials/Material_${t.id}/Texture_${t.map.id}_diffuse.outputs:a>`),o.addProperty(`float inputs:opacityThreshold = ${t.alphaTest}`)),a(t.map,`diffuse`,t.color).forEach(e=>i.addChild(e))),t.emissive){let n=t.emissiveIntensity??1;if(t.emissiveMap){o.addProperty(`color3f inputs:emissiveColor.connect = </Materials/Material_${t.id}/Texture_${t.emissiveMap.id}_emissive.outputs:rgb>`);let r=new e.g(t.emissive.r*n,t.emissive.g*n,t.emissive.b*n);a(t.emissiveMap,`emissive`,r).forEach(e=>i.addChild(e))}else t.emissive.getHex()>0&&o.addProperty(`color3f inputs:emissiveColor = ${Je(t.emissive)}`)}if(t.normalMap&&(o.addProperty(`normal3f inputs:normal.connect = </Materials/Material_${t.id}/Texture_${t.normalMap.id}_normal.outputs:rgb>`),a(t.normalMap,`normal`).forEach(e=>i.addChild(e))),t.aoMap){o.addProperty(`float inputs:occlusion.connect = </Materials/Material_${t.id}/Texture_${t.aoMap.id}_occlusion.outputs:r>`);let n=t.aoMapIntensity??1,r=new e.g(n,n,n);a(t.aoMap,`occlusion`,r).forEach(e=>i.addChild(e))}if(t.roughnessMap){o.addProperty(`float inputs:roughness.connect = </Materials/Material_${t.id}/Texture_${t.roughnessMap.id}_roughness.outputs:g>`);let n=new e.g(t.roughness,t.roughness,t.roughness);a(t.roughnessMap,`roughness`,n).forEach(e=>i.addChild(e))}else o.addProperty(`float inputs:roughness = ${t.roughness??1}`);if(t.metalnessMap){o.addProperty(`float inputs:metallic.connect = </Materials/Material_${t.id}/Texture_${t.metalnessMap.id}_metallic.outputs:b>`);let n=new e.g(t.metalness,t.metalness,t.metalness);a(t.metalnessMap,`metallic`,n).forEach(e=>i.addChild(e))}else o.addProperty(`float inputs:metallic = ${t.metalness??0}`);if(t.alphaMap?(o.addProperty(`float inputs:opacity.connect = </Materials/Material_${t.id}/Texture_${t.alphaMap.id}_opacity.outputs:r>`),o.addProperty(`float inputs:opacityThreshold = 0.0001`),a(t.alphaMap,`opacity`).forEach(e=>i.addChild(e))):o.addProperty(`float inputs:opacity = ${t.opacity}`),t.isMeshPhysicalMaterial){if(t.clearcoatMap!==null){o.addProperty(`float inputs:clearcoat.connect = </Materials/Material_${t.id}/Texture_${t.clearcoatMap.id}_clearcoat.outputs:r>`);let n=new e.g(t.clearcoat,t.clearcoat,t.clearcoat);a(t.clearcoatMap,`clearcoat`,n).forEach(e=>i.addChild(e))}else o.addProperty(`float inputs:clearcoat = ${t.clearcoat}`);if(t.clearcoatRoughnessMap!==null){o.addProperty(`float inputs:clearcoatRoughness.connect = </Materials/Material_${t.id}/Texture_${t.clearcoatRoughnessMap.id}_clearcoatRoughness.outputs:g>`);let n=new e.g(t.clearcoatRoughness,t.clearcoatRoughness,t.clearcoatRoughness);a(t.clearcoatRoughnessMap,`clearcoatRoughness`,n).forEach(e=>i.addChild(e))}else o.addProperty(`float inputs:clearcoatRoughness = ${t.clearcoatRoughness}`);o.addProperty(`float inputs:ior = ${t.ior}`)}return o.addProperty(`int inputs:useSpecularWorkflow = 0`),o.addProperty(`token outputs:surface`),i.addChild(o),i.addProperty(`token outputs:surface.connect = </Materials/Material_${t.id}/PreviewSurface.outputs:surface>`),i}function Je(e){return`(${e.r}, ${e.g}, ${e.b})`}function Ye(e,t=1){return`(${e.r}, ${e.g}, ${e.b}, ${t})`}function Xe(e){return`(${e.x}, ${e.y})`}function Ze(e,t,n){let r=Te(e,t);e.matrix.determinant()<0&&console.warn(`THREE.USDZExporter: USDZ does not support negative scales`,e);let i=new Q(r,`Camera`);Fe(i,e,n);let a=e.isOrthographicCamera?`orthographic`:`perspective`;i.addProperty(`token projection = "${a}"`);let o=`(${e.near.toPrecision($)}, ${e.far.toPrecision($)})`;i.addProperty(`float2 clippingRange = ${o}`);let s;s=e.isOrthographicCamera?((Math.abs(e.left)+Math.abs(e.right))*10).toPrecision($):e.getFilmWidth().toPrecision($),i.addProperty(`float horizontalAperture = ${s}`);let c;if(c=e.isOrthographicCamera?((Math.abs(e.top)+Math.abs(e.bottom))*10).toPrecision($):e.getFilmHeight().toPrecision($),i.addProperty(`float verticalAperture = ${c}`),e.isPerspectiveCamera){let t=e.getFocalLength().toPrecision($);i.addProperty(`float focalLength = ${t}`);let n=e.focus.toPrecision($);i.addProperty(`float focusDistance = ${n}`)}return i}var Qe=`model/vnd.usdz+zip`,$e=`.usdz`;async function et(e){let t=await new we().parseAsync(e,{quickLookCompatible:!0});return new Uint8Array(t)}async function tt(t,n={}){let r=e.r(e.s(t),{...n,wireframe:!1});try{return await et(r)}finally{e.a(r)}}var nt=[{name:`Basic Shapes`,args:{title:`Basic 3D Shapes`,script:`// Basic shapes demonstration
283
+ cube { position -2 0 0 size 1 color (1 0.3 0.3) }
284
+ sphere { position 0 0 0 size 1 color (0.3 1 0.3) }
285
+ cylinder { position 2 0 0 size 0.5 1 color (0.3 0.3 1) }`}},{name:`Circular Pattern`,args:{title:`Circular Pattern`,script:`// 12個の立方体を円形に配置
286
+
287
+ define count 12
288
+ define radius 3
289
+
290
+ for i in 1 to count {
291
+ // 各立方体の角度を計算(2 * PI = 6.283ラジアン)
292
+ define angle ((i / count) * 6.283)
293
+
294
+ // 円形配置のためのX座標とZ座標を計算
295
+ define x (cos(angle) * radius)
296
+ define z (sin(angle) * radius)
297
+
298
+ // グラデーションカラーを作成
299
+ define colorValue (i / count)
300
+
301
+ cube {
302
+ position x 0 z
303
+ size 0.5
304
+ color colorValue 0.5 (1 - colorValue)
305
+ }
306
+ }
307
+
308
+ // 中心に参考用の球体を配置
309
+ sphere {
310
+ position 0 0 0
311
+ size 0.3
312
+ color 1 1 0
313
+ opacity 0.5
314
+ }`}},{name:`CSG Difference`,args:{title:`Hollow Sphere`,script:`// Create a hollow sphere using CSG difference
315
+ difference {
316
+ sphere { size 2 color (1 0.5 0) }
317
+ sphere { size 1.7 color (1 1 1) }
318
+ cube { position 0 0 2 size 2 }
319
+ }`}}];Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return et}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Qe}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return nt}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return n}});
@@ -2,6 +2,16 @@ import * as THREE from "three";
2
2
  /** Read an ordered perimeter from a triangulated planar profile. Interior
3
3
  * vertices (e.g. the centre of CircleGeometry) must never enter a loft ring. */
4
4
  export declare function profileOf(mesh: THREE.Mesh): THREE.Vector3[];
5
- /** Straight interpolation between successive rings, with triangulated end caps. */
6
- export declare function loftGeometry(profiles: THREE.Vector3[][]): THREE.BufferGeometry;
5
+ /** Straight interpolation between successive rings, with triangulated end
6
+ * caps or, for a `closed` chain (a section swept around a loop), the last
7
+ * ring joined back to the first and no caps at all. */
8
+ export declare function loftGeometry(profiles: THREE.Vector3[][], closed?: boolean): THREE.BufferGeometry;
9
+ /** A section ring (in the XY plane, its normal +Z) placed at every point of a
10
+ * path, the way `extrude … along` sweeps it: +Z turns to the path tangent
11
+ * (mitred at corners, and the ring widened there so the walls meet), +Y to
12
+ * the path's plane normal. A `closed` path wraps the first corner too. */
13
+ export declare function sweepRings(section: THREE.Vector3[], path: THREE.Vector3[], closed: boolean): THREE.Vector3[][];
14
+ /** An OPEN path extruded: a wall of `depth` along the path with no caps, faced
15
+ * both ways as upstream draws an open surface. */
16
+ export declare function ribbonGeometry(points: THREE.Vector3[], depth: number): THREE.BufferGeometry;
7
17
  //# sourceMappingURL=builders.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/shapescript/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;gFACgF;AAChF,wBAAgB,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,CAiD3D;AA0CD,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,cAAc,CAoE9E"}
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/shapescript/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;gFACgF;AAChF,wBAAgB,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,CAiD3D;AA0CD;;wDAEwD;AACxD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,UAAQ,GAAG,KAAK,CAAC,cAAc,CAqE9F;AAED;;;2EAG2E;AAC3E,wBAAgB,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE,CAwB9G;AAgBD;mDACmD;AACnD,wBAAgB,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,cAAc,CA2B3F"}
@@ -1,5 +1,46 @@
1
- import { Expression, Vector3, Color } from "./types";
2
- export type Value = number | boolean | string | Value[];
1
+ import { Expression, Vector3, Color, DefineNode, SceneNode } from "./types";
2
+ import { type MeshValue, type PolygonValue, type BoundsValue, type PointValue } from "./meshValues";
3
+ import type * as THREE from "three";
4
+ export type { MeshValue, PolygonValue, BoundsValue, PointValue } from "./meshValues";
5
+ /** `1 to 5 step 2` as a value: walked by `for`, tested by `in`. */
6
+ export interface RangeValue {
7
+ kind: "range";
8
+ from: number;
9
+ to: number;
10
+ step: number;
11
+ /** Whether a `step` was written: `in` then tests only the stepped values,
12
+ * while an unstepped range contains every number between its bounds. */
13
+ stepped: boolean;
14
+ }
15
+ /** A `define name(a b) { … }` function, kept as its definition node. */
16
+ export interface FunctionValue {
17
+ kind: "function";
18
+ definition: DefineNode;
19
+ }
20
+ /** An evaluated `material { … }` block. Colours carry alpha; a texture is
21
+ * kept only so the renderer can warn about it. */
22
+ export interface MaterialValue {
23
+ kind: "material";
24
+ color?: RGBA;
25
+ opacity?: number;
26
+ metallicity?: number;
27
+ roughness?: number;
28
+ glow?: RGBA;
29
+ texture?: string;
30
+ }
31
+ export type RGBA = [number, number, number, number];
32
+ export type ObjectValue = RangeValue | FunctionValue | MaterialValue | MeshValue | PolygonValue | BoundsValue | PointValue;
33
+ export type Value = number | boolean | string | Value[] | ObjectValue;
34
+ export declare const isObjectValue: (value: Value | undefined) => value is ObjectValue;
35
+ /** What the evaluator needs from the converter: shapes as values are built
36
+ * there, and a function whose body builds shapes runs there. */
37
+ export interface EvaluatorHooks {
38
+ shape(node: SceneNode): Value;
39
+ call(fn: FunctionValue, args: Value[]): Value;
40
+ /** A geometry a builtin allocated that stays alive as a value: charged
41
+ * against the vertex budget by the converter, or refused. */
42
+ retain(geometry: THREE.BufferGeometry): void;
43
+ }
3
44
  /** Upstream's `rnd` generator, bit for bit: a 32-bit LCG kept in a double,
4
45
  * `x = (x * 1664525 + 1013904223) mod 2^32`, returning `x / 2^32`. Matching
5
46
  * it means `seed 57` scatters shapes exactly as it does in the upstream app.
@@ -27,6 +68,12 @@ export declare class SymbolTable {
27
68
  get(name: string): Value | undefined;
28
69
  has(name: string): boolean;
29
70
  }
71
+ /** Every built-in a bare call may name (`max 0 1`). */
72
+ export declare const BUILT_IN_FUNCTION_NAMES: readonly string[];
73
+ export declare function valuesEqual(a: Value, b: Value): boolean;
74
+ /** The values a `for` loop visits: a range walked by its step, a tuple's
75
+ * elements, or a lone value. The count is bounded by the caller. */
76
+ export declare function iterationValues(iterable: Value, limit: number, exceeded: () => Error): Value[];
30
77
  /** Seeds the generator behind `rnd` / `rand()` when a caller names none.
31
78
  *
32
79
  * The same script is evaluated TWICE for one visualization — once on the
@@ -42,15 +89,42 @@ export declare class SymbolTable {
42
89
  export declare const DEFAULT_RANDOM_SEED = 0;
43
90
  export declare class Evaluator {
44
91
  private symbols;
92
+ private callDepth;
93
+ /** Set by the converter, which owns geometry. */
94
+ hooks: EvaluatorHooks | undefined;
95
+ /** The same per-loop ceiling the converter applies to `for` statements. */
96
+ maxLoopIterations: number;
45
97
  constructor(symbols?: SymbolTable, seed?: number);
46
98
  private random;
47
99
  /** The `seed` command. Scoped: see `SymbolTable.reseed`. */
48
100
  reseed(seed: number): void;
49
101
  getSymbols(): SymbolTable;
50
102
  evaluate(expr: Expression | number | string | Vector3 | Color): Value;
103
+ /** `from to to [step]`, or `range step s` when `to` is absent. */
104
+ private evaluateRange;
105
+ private evaluateMaterial;
106
+ /** `inset(mesh distance)`: a new mesh value with the faces moved inward.
107
+ * Its geometry is a fresh allocation that lives on as a value, so it is
108
+ * charged the way a defined shape is. */
109
+ private inset;
110
+ /** Bind the parameters in a fresh scope, run the body's `define`s, and
111
+ * evaluate the result expression. */
112
+ private callFunction;
113
+ /** Bind parameters in a fresh scope around `run`. Public so the converter
114
+ * can run a shape-building function body under the same binding. */
115
+ withArguments<T>(params: readonly string[], args: readonly Value[], run: () => T): T;
116
+ /** A `define` of a value or a function. Custom shape blocks are stored by
117
+ * the converter, which owns their bodies. */
118
+ define(node: DefineNode): boolean;
51
119
  evaluateToNumber(expr: Expression | number): number;
52
120
  evaluateToBoolean(expr: Expression): boolean;
53
121
  evaluateToVector3(expr: Expression | Vector3): Vector3;
54
122
  evaluateToColor(expr: Expression | Color): Color;
123
+ /** A colour value with alpha, by upstream's count rules: one number is a
124
+ * luminance, two are luminance and alpha, three RGB, four RGBA; and a colour
125
+ * followed by a number (`red 0.5`, `#ff0 0.5`) is that colour with its
126
+ * alpha replaced. */
127
+ evaluateToRGBA(expr: Expression | Color): RGBA;
55
128
  }
129
+ export declare function rgbaOf(value: Value): RGBA;
56
130
  //# sourceMappingURL=evaluator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/shapescript/evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,EAAE,CAAC;AAExD;;;;;wDAKwD;AACxD,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAc;IAC7C,OAAO,CAAC,KAAK,CAAS;gBAEV,IAAI,EAAE,MAAM;IAIxB,OAAO,CAAC,MAAM,CAAC,IAAI;IAKnB,IAAI,IAAI,MAAM;CAIf;AAOD,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAe;gBAEjB,IAAI,GAAE,MAA4B;IAK9C,OAAO,CAAC,SAAS;IAMjB,SAAS,IAAI,IAAI;IAKjB,QAAQ,IAAI,IAAI;IAMhB;mFAC+E;IAC/E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1B,UAAU,IAAI,MAAM;IAIpB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAIrC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IA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EAAE,MAAM,GAAG,IAAI;IAK1B,UAAU,IAAI,WAAW;IAIzB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK;IA+PrE,kEAAkE;IAClE,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,gBAAgB;IAYxB;;8CAE0C;IAC1C,OAAO,CAAC,KAAK;IAiBb;0CACsC;IACtC,OAAO,CAAC,YAAY;IAsBpB;yEACqE;IACrE,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC;IAUpF;kDAC8C;IAC9C,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO;IAYjC,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM;IAKnD,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO;IAK5C,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,OAAO;IAmBtD,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,KAAK,GAAG,KAAK;IAKhD;;;0BAGsB;IACtB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,KAAK,GAAG,IAAI;CAI/C;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAyBzC"}
@@ -0,0 +1,54 @@
1
+ import * as THREE from "three";
2
+ import type { RGBA } from "./evaluator";
3
+ /** The value types that hold geometry, shared by the evaluator (members) and
4
+ * the converter (building and placing them). */
5
+ export type Point3 = [number, number, number];
6
+ /** A `polygon { point … }`, or one face of a mesh value. */
7
+ export interface PolygonValue {
8
+ kind: "polygon";
9
+ points: Point3[];
10
+ /** Per-vertex colours when the polygon block set `color`; one per point. */
11
+ colors?: RGBA[];
12
+ }
13
+ /** A shape used as a value. The geometry is in the shape's own frame, with
14
+ * the transform it was declared with already applied. */
15
+ export interface MeshValue {
16
+ kind: "mesh";
17
+ geometry: THREE.BufferGeometry;
18
+ /** Kept when the mesh was built from polygons, so `.polygons` returns them
19
+ * in the order the script (or Euclid) produced them. */
20
+ polygons?: PolygonValue[];
21
+ name?: string;
22
+ }
23
+ /** `shape.bounds` / `polygon.bounds`. */
24
+ export interface BoundsValue {
25
+ kind: "bounds";
26
+ min: Point3;
27
+ max: Point3;
28
+ }
29
+ /** A vertex of a polygon, from `polygon.points`. */
30
+ export interface PointValue {
31
+ kind: "point";
32
+ position: Point3;
33
+ color?: RGBA;
34
+ }
35
+ export declare function boundsOf(points: readonly Point3[]): BoundsValue;
36
+ export declare function centerOf(points: readonly Point3[]): Point3;
37
+ /** Every triangle of a geometry as a polygon, in buffer order. */
38
+ export declare function trianglesOf(geometry: THREE.BufferGeometry): PolygonValue[];
39
+ export declare function meshPolygons(mesh: MeshValue): PolygonValue[];
40
+ export declare function meshPoints(mesh: MeshValue): Point3[];
41
+ /** Signed volume of a closed triangle mesh. */
42
+ export declare function meshVolume(mesh: MeshValue): number;
43
+ /** Triangulate a planar polygon (convex or not) into index triples. */
44
+ export declare function triangulatePolygon(points: readonly Point3[]): [number, number, number][];
45
+ /** Euclid's icosahedron, vertex for vertex and face for face, so that
46
+ * `icosphere.polygons` indexes the same way upstream's scripts expect. */
47
+ export declare function icosphereGeometry(radius: number, subdivisions: number): {
48
+ geometry: THREE.BufferGeometry;
49
+ polygons: PolygonValue[];
50
+ };
51
+ /** A flat-shaded, non-indexed geometry from polygons, with per-vertex
52
+ * colours when any polygon carries them. */
53
+ export declare function geometryFromPolygons(polygons: readonly PolygonValue[], withColors: boolean): THREE.BufferGeometry;
54
+ //# sourceMappingURL=meshValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meshValues.d.ts","sourceRoot":"","sources":["../../src/shapescript/meshValues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA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EAAE,SAAS,GAAG,MAAM,CAYlD;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAsBxF;AAED;2EAC2E;AAC3E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC;IAAC,QAAQ,EAAE,YAAY,EAAE,CAAA;CAAE,CA+DpI;AAED;6CAC6C;AAC7C,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,UAAU,EAAE,OAAO,GAAG,KAAK,CAAC,cAAc,CAsBjH"}
@@ -0,0 +1,37 @@
1
+ import * as THREE from "three";
2
+ /** The most faces a non-convex operand may contribute pieces for. */
3
+ export declare const MAX_MINKOWSKI_PIECES = 2048;
4
+ /** The most points one hull may be built from. */
5
+ export declare const MAX_HULL_POINTS = 400000;
6
+ /** The distinct vertex positions of a geometry, in world space. */
7
+ export declare function uniquePoints(geometry: THREE.BufferGeometry, matrix: THREE.Matrix4): THREE.Vector3[];
8
+ /** The triangles of a geometry as world-space corner triples. */
9
+ export declare function worldTriangles(geometry: THREE.BufferGeometry, matrix: THREE.Matrix4): THREE.Vector3[][];
10
+ /** +1 when the triangles wind outward, −1 when a mirroring `size` or `scale`
11
+ * turned them inside out — the sign of the enclosed volume. */
12
+ export declare function windingSign(triangles: readonly THREE.Vector3[][]): number;
13
+ /** Whether every vertex lies on or behind every face plane: a convex solid,
14
+ * however its faces wind, whose Minkowski sum with another convex solid is
15
+ * the hull of their pairwise vertex sums. */
16
+ export declare function isConvex(triangles: readonly THREE.Vector3[][], points: readonly THREE.Vector3[]): boolean;
17
+ /** The convex hull of `points`. A whole sum (`smooth`) is the rounded solid
18
+ * itself, so shared vertices average their face normals. A per-face PIECE
19
+ * keeps flat normals: its rounded sides are interior once the pieces overlap,
20
+ * and averaging them into its flat top tilted that face's border — a visible
21
+ * bump along every seam of a flat face. Coplanar points (two parallel faces
22
+ * summed) give a flat sliver rather than a throw from `ConvexGeometry`; that
23
+ * is `undefined` here. */
24
+ export declare function hullGeometry(points: THREE.Vector3[], smooth: boolean): THREE.BufferGeometry | undefined;
25
+ export interface MinkowskiOperand {
26
+ geometry: THREE.BufferGeometry;
27
+ matrix: THREE.Matrix4;
28
+ }
29
+ /** `a ⊕ b`. Two convex solids sum to one hull; when one is not convex, every
30
+ * face of it is summed with the other on its own and the pieces are merged
31
+ * (their union), as upstream decomposes it. */
32
+ export declare function minkowskiSum(a: MinkowskiOperand, b: MinkowskiOperand): THREE.BufferGeometry;
33
+ /** Every face moved inward by `distance` (outward when negative): each vertex
34
+ * slides to where its faces' offset planes meet — exact at any corner where
35
+ * the planes are consistent, least-squares where more than three meet. */
36
+ export declare function insetGeometry(geometry: THREE.BufferGeometry, distance: number): THREE.BufferGeometry;
37
+ //# sourceMappingURL=minkowski.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minkowski.d.ts","sourceRoot":"","sources":["../../src/shapescript/minkowski.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,qEAAqE;AACrE,eAAO,MAAM,oBAAoB,OAAO,CAAC;AACzC,kDAAkD;AAClD,eAAO,MAAM,eAAe,SAAU,CAAC;AAIvC,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,CAYnG;AAED,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE,CASvG;AAED;gEACgE;AAChE,wBAAgB,WAAW,CAAC,SAAS,EAAE,S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