@mulmoclaude/shapescript-plugin 2.0.0 → 2.4.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 (54) hide show
  1. package/README.md +117 -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-BvTjfhU2.js → core-CvNYv5VF.js} +2 -2
  7. package/dist/{core-DZvhTmuk.cjs → core-DmD6zaRF.cjs} +1 -1
  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-BrJ4z8v-.cjs +324 -0
  26. package/dist/{samples-CXhuDdDd.js → samples-y59fsGq8.js} +281 -276
  27. package/dist/shapescript/builders.d.ts +17 -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 +81 -2
  36. package/dist/shapescript/parser.d.ts.map +1 -1
  37. package/dist/shapescript/text.d.ts +29 -0
  38. package/dist/shapescript/text.d.ts.map +1 -0
  39. package/dist/shapescript/toThreeJS.d.ts +159 -9
  40. package/dist/shapescript/toThreeJS.d.ts.map +1 -1
  41. package/dist/shapescript/types.d.ts +160 -17
  42. package/dist/shapescript/types.d.ts.map +1 -1
  43. package/dist/style.css +1 -1
  44. package/dist/toThreeJS-CaZGJjfO.cjs +24 -0
  45. package/dist/{toThreeJS-FsP-Na75.js → toThreeJS-OGEAi4zV.js} +6136 -3781
  46. package/dist/vue/Preview.vue.d.ts.map +1 -1
  47. package/dist/vue/View.vue.d.ts.map +1 -1
  48. package/dist/vue/index.d.ts +1 -1
  49. package/dist/vue/index.d.ts.map +1 -1
  50. package/dist/vue.cjs +37 -25
  51. package/dist/vue.js +1534 -1493
  52. package/package.json +1 -1
  53. package/dist/samples-DGD0Kjwg.cjs +0 -276
  54. package/dist/toThreeJS-MvllBF9e.cjs +0 -10
@@ -0,0 +1,324 @@
1
+ const e=require("./toThreeJS-CaZGJjfO.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.
170
+ - text "Hello" / text { size 0.5 wrapwidth 3 linespacing 0.2 "Line one" "Line two" }: glyph outlines in the built-in
171
+ Helvetica-like font, left margin at x 0 and first baseline at y 0, one unit per line (size scales it). Bare text draws
172
+ outlines; fill text "Hi" makes faces and extrude { size 1 1 0.3 text "Hi" } solids. Values interpolate:
173
+ text "Bob has " apples " apples", text i. Centre it with its bounds: define t text "Hi" then
174
+ translate -t.bounds.width/2 -t.bounds.height/2 before fill t. font is accepted and ignored (one face only).
175
+ - mesh { polygon { point x y z … } … }: a mesh from explicit faces; polygon { color red point a point b point c }
176
+ 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 } }.
177
+
178
+ ### Additional Expressions:
179
+ - Constants: pi, true, false (tau exists here but NOT in the upstream app; write 2 * pi)
180
+ - A lone position / translate value is X alone (position 1 = 1 0 0); a lone size is uniform; a lone orientation is a roll.
181
+ - Scientific notation and unary plus: 1e-3, +2
182
+ - Ranges as values: define loops 1 to 5 step 2, then for i in loops { … }, for i in loops step 1, and
183
+ "if 3 in loops"; the in operator also tests tuples (2 in (1 2 3)) and strings.
184
+ - Tuple/vector members: .x .y .z, .width .height .depth, .roll .yaw .pitch, .red .green .blue .alpha, .hue .saturation .brightness
185
+ - Tuple/string length: value.count; zero-based indexing values[0], negative from the end values[-1], by name values["y"];
186
+ ordinals: v.first v.second … v.last, v.allButFirst, v.allButLast
187
+ - String literals, join(...), split(...), trim(...); min/max also accept tuples
188
+ - print a b … records output that is returned with the tool result; assert condition stops the script when false
189
+ - Custom shapes with options:
190
+ define post {
191
+ option height 2
192
+ cylinder { size 0.2 height }
193
+ }
194
+ post { height 3 }
195
+ - Random numbers: rnd (0–1) and seed N (scoped to the enclosing block, same generator as upstream)
196
+ - Shapes as values: define ico icosphere { detail 0 } then ico (places it), ico.polygons (faces, each with
197
+ .center .points .bounds), ico.triangles, ico.bounds (.min .max .center .size .width .height .depth), ico.volume.
198
+ - for / if as expressions: define scales for i in 1 to 3 { i / 3 }; define c if big { red } else { white }
199
+ - Functions may build shapes: define face(data) { polygon { … } } and are called bare as statements: face data
200
+
201
+ ### Compatibility:
202
+ This plugin implements the documented modeling subset, not all upstream ShapeScript syntax; units, scoping,
203
+ materials and path semantics follow upstream, so a script written against the upstream docs renders the
204
+ same here. Not supported (each is refused by name): import, svgpath, extrude twist,
205
+ object values and paths as values. Textures, fonts, cameras and lights are accepted but not drawn.
206
+
207
+ ### Comments:
208
+ // Single-line comment
209
+ /* Multi-line
210
+ comment */
211
+
212
+ ## COMPLETE EXAMPLES:
213
+
214
+ Linear arrangement with expressions:
215
+ define spacing 1.5
216
+ for i in 1 to 4 {
217
+ cylinder {
218
+ position ((i - 2.5) * spacing) 0 0
219
+ size 0.4 1
220
+ }
221
+ }
222
+
223
+ Circular pattern:
224
+ define count 12
225
+ for i in 1 to count {
226
+ define angle ((i / count) * 6.283) // 2 * PI
227
+ cube {
228
+ position (cos(angle) * 3) 0 (sin(angle) * 3)
229
+ color (i / count) 0.5 (1 - i / count)
230
+ size 0.5
231
+ }
232
+ }
233
+
234
+ Conditional geometry:
235
+ define makeHollow 1
236
+ if makeHollow {
237
+ difference {
238
+ sphere {
239
+ size 2
240
+ color (1 0 0)
241
+ }
242
+ sphere { size 1.7 }
243
+ }
244
+ } else {
245
+ sphere {
246
+ size 2
247
+ color (1 0 0)
248
+ }
249
+ }
250
+
251
+ Mathematical visualization:
252
+ for x in -5 to 5 {
253
+ for z in -5 to 5 {
254
+ define height (sin(x * 0.5) * cos(z * 0.5) * 2)
255
+ cube {
256
+ position (x * 0.3) height (z * 0.3)
257
+ size 0.25 (abs(height) + 0.1) 0.25
258
+ color (0.5 + height * 0.25) 0.3 (0.5 - height * 0.25)
259
+ }
260
+ }
261
+ }`},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(`
262
+ `)}`),t.length?`\n${t.join(`
263
+ `)}`:``}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(`
264
+ `)}return`${n} = ${r}`}),r=n.length?` (\n${n.map(e=>`${t}\t${e}`).join(`
265
+ `)}\n${t})`:``,i=this.properties.map(e=>{let n=e.property.replace(/\n/g,`
266
+ `+t+` `),r=e.metadata.length?` (\n${e.metadata.map(e=>`${t}\t\t${e}`).join(`
267
+ `)}\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(`
268
+ `);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)+`
269
+ `+o.toString()+`
270
+
271
+ `+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
272
+ (
273
+ customLayerData = {
274
+ string creator = "Three.js USDZExporter"
275
+ }
276
+ defaultPrim = "Root"
277
+ metersPerUnit = 1
278
+ upAxis = "Y"${e?`
279
+ startTimeCode = 0
280
+ endTimeCode = ${e.endTimeCode}
281
+ timeCodesPerSecond = ${e.fps}
282
+ framesPerSecond = ${e.fps}`:``}
283
+ )
284
+ `}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(`,
285
+ `)},\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(`,
286
+ `)},\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()+`
287
+ `+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
288
+ cube { position -2 0 0 size 1 color (1 0.3 0.3) }
289
+ sphere { position 0 0 0 size 1 color (0.3 1 0.3) }
290
+ cylinder { position 2 0 0 size 0.5 1 color (0.3 0.3 1) }`}},{name:`Circular Pattern`,args:{title:`Circular Pattern`,script:`// 12個の立方体を円形に配置
291
+
292
+ define count 12
293
+ define radius 3
294
+
295
+ for i in 1 to count {
296
+ // 各立方体の角度を計算(2 * PI = 6.283ラジアン)
297
+ define angle ((i / count) * 6.283)
298
+
299
+ // 円形配置のためのX座標とZ座標を計算
300
+ define x (cos(angle) * radius)
301
+ define z (sin(angle) * radius)
302
+
303
+ // グラデーションカラーを作成
304
+ define colorValue (i / count)
305
+
306
+ cube {
307
+ position x 0 z
308
+ size 0.5
309
+ color colorValue 0.5 (1 - colorValue)
310
+ }
311
+ }
312
+
313
+ // 中心に参考用の球体を配置
314
+ sphere {
315
+ position 0 0 0
316
+ size 0.3
317
+ color 1 1 0
318
+ opacity 0.5
319
+ }`}},{name:`CSG Difference`,args:{title:`Hollow Sphere`,script:`// Create a hollow sphere using CSG difference
320
+ difference {
321
+ sphere { size 2 color (1 0.5 0) }
322
+ sphere { size 1.7 color (1 1 1) }
323
+ cube { position 0 0 2 size 2 }
324
+ }`}}];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}});