@algorisys/tinyfly 0.100.0 → 0.102.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 (71) hide show
  1. package/README.md +6 -6
  2. package/bin/tinyfly.mjs +16 -6
  3. package/docs/character-appearance.md +26 -0
  4. package/docs/editor-guide.md +1 -1
  5. package/docs/examples.md +1 -1
  6. package/docs/getting-started.md +1 -1
  7. package/docs/gsap-compat.md +1 -1
  8. package/docs/llm-guide.md +22 -4
  9. package/docs/maps.md +2 -2
  10. package/docs/scene-3d.md +140 -9
  11. package/docs/teaching.md +1 -1
  12. package/docs/video-rendering.md +198 -1
  13. package/lib/addons/adapters.js +431 -332
  14. package/lib/addons/characters.js +3889 -3773
  15. package/lib/addons/load-scene-oWNsYYC1.js +372 -0
  16. package/lib/addons/scene-3d-webgl.js +31 -31
  17. package/lib/addons/scene-3d.js +669 -314
  18. package/lib/addons/shading-0lPgnXmD.js +96 -0
  19. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +2 -2
  20. package/lib/browser/tinyfly-scene-3d.iife.js +2 -2
  21. package/lib/browser/tinyfly.iife.js +15 -15
  22. package/lib/browser/tinyfly.js +6232 -5723
  23. package/lib/browser/tinyfly.umd.js +15 -15
  24. package/lib/engine/tinyfly-engine.js +1563 -1170
  25. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  26. package/lib/headless/headless.js +189 -6
  27. package/lib/types/adapters/canvas/framing.d.ts +27 -0
  28. package/lib/types/adapters/canvas/impossible.d.ts +15 -0
  29. package/lib/types/adapters/canvas/index.d.ts +4 -0
  30. package/lib/types/adapters/canvas/nested-zoom.d.ts +40 -0
  31. package/lib/types/adapters/canvas/zoom-blur.d.ts +49 -0
  32. package/lib/types/characters/character-script-3d.d.ts +21 -1
  33. package/lib/types/characters/character.d.ts +23 -3
  34. package/lib/types/characters/head/face.d.ts +19 -2
  35. package/lib/types/characters/index.d.ts +2 -1
  36. package/lib/types/characters/staging-3d.d.ts +56 -0
  37. package/lib/types/engine/authoring/beat-loop.d.ts +46 -0
  38. package/lib/types/engine/authoring/curve.d.ts +26 -0
  39. package/lib/types/engine/authoring/framing.d.ts +48 -0
  40. package/lib/types/engine/authoring/index.d.ts +4 -0
  41. package/lib/types/engine/authoring/periodic.d.ts +89 -0
  42. package/lib/types/engine/path/goo.d.ts +103 -0
  43. package/lib/types/engine/path/impossible.d.ts +92 -0
  44. package/lib/types/engine/path/index.d.ts +6 -0
  45. package/lib/types/engine/path/similarity.d.ts +48 -0
  46. package/lib/types/headless/audio-mix.d.ts +40 -0
  47. package/lib/types/headless/ffmpeg-args.d.ts +2 -0
  48. package/lib/types/headless/frame-renderer.d.ts +7 -1
  49. package/lib/types/headless/index.d.ts +2 -0
  50. package/lib/types/headless/loop-audio.d.ts +21 -0
  51. package/lib/types/headless/node-audio.d.ts +39 -0
  52. package/lib/types/headless/node-video.d.ts +2 -0
  53. package/lib/types/headless/video-scene.d.ts +21 -0
  54. package/lib/types/scene-3d/camera.d.ts +11 -2
  55. package/lib/types/scene-3d/geometry/mesh.d.ts +2 -0
  56. package/lib/types/scene-3d/geometry/primitives.d.ts +7 -0
  57. package/lib/types/scene-3d/impossible-3d.d.ts +29 -0
  58. package/lib/types/scene-3d/index.d.ts +7 -3
  59. package/lib/types/scene-3d/lighting.d.ts +58 -0
  60. package/lib/types/scene-3d/resolve-scene.d.ts +18 -2
  61. package/lib/types/scene-3d/scene-3d-adapter.d.ts +4 -0
  62. package/lib/types/scene-3d/scene-types.d.ts +43 -6
  63. package/lib/types/scene-3d/shading.d.ts +2 -0
  64. package/lib/types/scene-3d/shots.d.ts +162 -0
  65. package/lib/types/scene-3d/software-renderer.d.ts +40 -0
  66. package/llms-full.txt +395 -23
  67. package/llms.txt +29 -29
  68. package/package.json +1 -1
  69. package/skills/tinyfly/SKILL.md +11 -1
  70. package/lib/addons/load-scene-CQvcFWGJ.js +0 -331
  71. package/lib/addons/shading-o5T_v9DT.js +0 -89
@@ -0,0 +1,96 @@
1
+ import { vec3 as f } from "@algorisys/tinyfly";
2
+ const b = /* @__PURE__ */ new Map();
3
+ function d(n) {
4
+ const i = b.get(n);
5
+ if (i) return i;
6
+ let a = [1, 1, 1];
7
+ const e = n.trim().replace("#", "");
8
+ if (n.trim().startsWith("#") && (e.length === 3 || e.length === 6)) {
9
+ const t = e.length === 3 ? e.split("").map((s) => s + s).join("") : e;
10
+ a = [0, 2, 4].map((s) => Number.parseInt(t.slice(s, s + 2), 16) / 255);
11
+ } else {
12
+ const t = n.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);
13
+ t && (a = [Number(t[1]) / 255, Number(t[2]) / 255, Number(t[3]) / 255]);
14
+ }
15
+ return b.size < 512 && b.set(n, a), a;
16
+ }
17
+ const y = [
18
+ { id: "default-ambient", light: "ambient", color: "#ffffff", intensity: 0.35, position: [0, 0, 0], direction: [0, -1, 0], angle: 30 },
19
+ { id: "default-key", light: "directional", color: "#ffffff", intensity: 0.8, position: [3, 5, 4], direction: f.normalize([-3, -5, -4]), angle: 30 }
20
+ ], v = (n, i, a) => {
21
+ const e = Math.min(1, Math.max(0, (a - n) / (i - n)));
22
+ return e * e * (3 - 2 * e);
23
+ };
24
+ function g(n, i, a) {
25
+ const e = [0, 0, 0];
26
+ for (const t of a) {
27
+ const s = d(t.color);
28
+ let c;
29
+ if (t.light === "ambient")
30
+ c = t.intensity;
31
+ else if (t.light === "directional")
32
+ c = t.intensity * Math.max(0, -f.dot(i, t.direction));
33
+ else {
34
+ const o = f.subtract(t.position, n), m = f.length(o), u = m > 0 ? f.scale(o, 1 / m) : i, r = t.range ? Math.max(0, 1 - m / t.range) ** 2 : 1;
35
+ if (c = t.intensity * Math.max(0, f.dot(i, u)) * r, t.light === "spot") {
36
+ const l = Math.cos(t.angle * Math.PI / 180), h = Math.cos(t.angle * 0.8 * Math.PI / 180);
37
+ c *= v(l, h, -f.dot(u, t.direction));
38
+ }
39
+ }
40
+ e[0] += s[0] * c, e[1] += s[1] * c, e[2] += s[2] * c;
41
+ }
42
+ return e;
43
+ }
44
+ function $(n, i) {
45
+ const a = Math.max(2, Math.round(i));
46
+ return Math.min(1.2, Math.ceil(Math.min(1, n) * a - 1e-9) / a);
47
+ }
48
+ function x(n, i) {
49
+ return n ? Math.min(1, Math.max(0, (i - n.near) / (n.far - n.near))) : 0;
50
+ }
51
+ function N(n, i, a) {
52
+ const e = x(i, a);
53
+ if (!i || e <= 0) return n;
54
+ const t = d(n), s = d(i.color), c = (o) => Math.round(Math.min(1, Math.max(0, o)) * 255);
55
+ return `rgb(${c(t[0] + (s[0] - t[0]) * e)}, ${c(t[1] + (s[1] - t[1]) * e)}, ${c(t[2] + (s[2] - t[2]) * e)})`;
56
+ }
57
+ function A(n, i, a, e) {
58
+ const t = n.material, s = d(n.color ?? t.color), c = t.shading ?? "lambert";
59
+ let o;
60
+ if (c === "unlit")
61
+ o = [...s];
62
+ else {
63
+ const r = i.length > 0 ? i : y;
64
+ let l;
65
+ if (c === "lambert") {
66
+ const h = [0, 0, 0];
67
+ for (const M of n.vertexNormals) {
68
+ const p = g(n.centroid, M, r);
69
+ h[0] += p[0] / 3, h[1] += p[1] / 3, h[2] += p[2] / 3;
70
+ }
71
+ l = h;
72
+ } else if (l = g(n.centroid, n.normal, r), c === "toon") {
73
+ const h = Math.max(l[0], l[1], l[2]), M = h > 0 ? $(h, t.bands ?? 3) / h : 0;
74
+ l = [l[0] * M, l[1] * M, l[2] * M];
75
+ }
76
+ o = [s[0] * l[0], s[1] * l[1], s[2] * l[2]];
77
+ }
78
+ if (t.emissive) {
79
+ const r = d(t.emissive);
80
+ o = [o[0] + r[0], o[1] + r[1], o[2] + r[2]];
81
+ }
82
+ const m = x(e, f.distance(n.centroid, a.position));
83
+ if (e && m > 0) {
84
+ const r = d(e.color);
85
+ o = [o[0] + (r[0] - o[0]) * m, o[1] + (r[1] - o[1]) * m, o[2] + (r[2] - o[2]) * m];
86
+ }
87
+ const u = (r) => Math.round(Math.min(1, Math.max(0, r)) * 255);
88
+ return { color: `rgb(${u(o[0])}, ${u(o[1])}, ${u(o[2])})`, alpha: n.opacity };
89
+ }
90
+ export {
91
+ x as f,
92
+ N as i,
93
+ g as l,
94
+ d as p,
95
+ A as s
96
+ };
@@ -1,4 +1,4 @@
1
- (function(h){"use strict";function j(e,i){return[e[0]*i,e[1]*i,e[2]*i]}function X(e){return Math.hypot(e[0],e[1],e[2])}function B(e){const i=X(e);return i===0?[0,0,0]:j(e,1/i)}function W(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Y(e){const i=new Array(16);for(let t=0;t<4;t++)for(let o=0;o<4;o++)i[o*4+t]=e[t*4+o];return i}function z(e){const[i,t,o,r,n,l,s,u,_,a,f,m,v,p,b,w]=e,A=i*l-t*n,y=i*s-o*n,E=i*u-r*n,R=t*s-o*l,L=t*u-r*l,M=o*u-r*s,F=_*p-a*v,T=_*b-f*v,C=_*w-m*v,S=a*b-f*p,I=a*w-m*p,x=f*w-m*b,O=A*x-y*I+E*S+R*C-L*T+M*F;if(Math.abs(O)<1e-12)return null;const c=1/O;return[(l*x-s*I+u*S)*c,(o*I-t*x-r*S)*c,(p*M-b*L+w*R)*c,(f*L-a*M-m*R)*c,(s*C-n*x-u*T)*c,(i*x-o*C+r*T)*c,(b*E-v*M-w*y)*c,(_*M-f*E+m*y)*c,(n*I-l*C+u*F)*c,(t*C-i*I-r*F)*c,(v*L-p*E+w*A)*c,(a*E-_*L-m*A)*c,(l*T-n*S-s*F)*c,(i*S-t*T+o*F)*c,(p*y-v*R-b*A)*c,(_*R-a*y+f*A)*c]}const N=new Map;function g(e){const i=N.get(e);if(i)return i;let t=[1,1,1];const o=e.trim().replace("#","");if(e.trim().startsWith("#")&&(o.length===3||o.length===6)){const r=o.length===3?o.split("").map(n=>n+n).join(""):o;t=[0,2,4].map(n=>Number.parseInt(r.slice(n,n+2),16)/255)}else{const r=e.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);r&&(t=[Number(r[1])/255,Number(r[2])/255,Number(r[3])/255])}return N.size<512&&N.set(e,t),t}B([-3,-5,-4]);const d=8,P={unlit:0,flat:1,lambert:2,toon:3},k={ambient:0,directional:1,point:2,spot:3},K=`#version 300 es
1
+ (function(h){"use strict";function j(e,i){return[e[0]*i,e[1]*i,e[2]*i]}function X(e){return Math.hypot(e[0],e[1],e[2])}function U(e){const i=X(e);return i===0?[0,0,0]:j(e,1/i)}function W(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function Y(e){const i=new Array(16);for(let t=0;t<4;t++)for(let o=0;o<4;o++)i[o*4+t]=e[t*4+o];return i}function z(e){const[i,t,o,r,n,l,s,u,_,a,f,m,v,p,b,w]=e,A=i*l-t*n,y=i*s-o*n,E=i*u-r*n,R=t*s-o*l,L=t*u-r*l,M=o*u-r*s,F=_*p-a*v,T=_*b-f*v,C=_*w-m*v,S=a*b-f*p,I=a*w-m*p,x=f*w-m*b,O=A*x-y*I+E*S+R*C-L*T+M*F;if(Math.abs(O)<1e-12)return null;const c=1/O;return[(l*x-s*I+u*S)*c,(o*I-t*x-r*S)*c,(p*M-b*L+w*R)*c,(f*L-a*M-m*R)*c,(s*C-n*x-u*T)*c,(i*x-o*C+r*T)*c,(b*E-v*M-w*y)*c,(_*M-f*E+m*y)*c,(n*I-l*C+u*F)*c,(t*C-i*I-r*F)*c,(v*L-p*E+w*A)*c,(a*E-_*L-m*A)*c,(l*T-n*S-s*F)*c,(i*S-t*T+o*F)*c,(p*y-v*R-b*A)*c,(_*R-a*y+f*A)*c]}const N=new Map;function g(e){const i=N.get(e);if(i)return i;let t=[1,1,1];const o=e.trim().replace("#","");if(e.trim().startsWith("#")&&(o.length===3||o.length===6)){const r=o.length===3?o.split("").map(n=>n+n).join(""):o;t=[0,2,4].map(n=>Number.parseInt(r.slice(n,n+2),16)/255)}else{const r=e.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);r&&(t=[Number(r[1])/255,Number(r[2])/255,Number(r[3])/255])}return N.size<512&&N.set(e,t),t}U([-3,-5,-4]);const d=8,B={unlit:0,flat:1,lambert:2,toon:3},P={ambient:0,directional:1,point:2,spot:3},K=`#version 300 es
2
2
  in vec3 a_position;
3
3
  in vec3 a_normal;
4
4
  uniform mat4 u_model;
@@ -113,4 +113,4 @@ out vec4 outColor;
113
113
  void main() {
114
114
  outColor = u_ink;
115
115
  }
116
- `,Q=[{id:"default-ambient",light:"ambient",color:"#ffffff",intensity:.35,position:[0,0,0],direction:[0,-1,0],angle:30},{id:"default-key",light:"directional",color:"#ffffff",intensity:.8,position:[3,5,4],direction:B([-3,-5,-4]),angle:30}];function D(e){const i=(e.length>0?e:Q).slice(0,d),t={count:i.length,kind:new Int32Array(d),color:new Float32Array(d*3),intensity:new Float32Array(d),position:new Float32Array(d*3),direction:new Float32Array(d*3),range:new Float32Array(d),cone:new Float32Array(d*2)};return i.forEach((o,r)=>{t.kind[r]=k[o.light],t.color.set(g(o.color),r*3),t.intensity[r]=o.intensity,t.position.set(o.position,r*3),t.direction.set(o.direction,r*3),t.range[r]=o.range??0,t.cone[r*2]=Math.cos(o.angle*Math.PI/180),t.cone[r*2+1]=Math.cos(o.angle*.8*Math.PI/180)}),t}function G(e,i,t){return{color:g(i??e.color),emissive:e.emissive?g(e.emissive):[0,0,0],opacity:t,shading:P[e.shading??"lambert"],bands:e.bands??3}}function U(e){const i=Y(z(e)??W());return new Float32Array([i[0],i[1],i[2],i[4],i[5],i[6],i[8],i[9],i[10]])}class J{gl;surface;outline;buffers=new WeakMap;overlay;constructor(i,t={}){this.gl=i,this.overlay=t.overlay,this.surface=H(i,K,V),this.outline=H(i,$,q)}render(i){const t=this.gl,o=t.drawingBufferWidth,r=t.drawingBufferHeight;t.viewport(0,0,o,r);const n=i.background&&i.background!=="transparent"?g(i.background):null;t.clearColor(n?.[0]??0,n?.[1]??0,n?.[2]??0,n?1:0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.CULL_FACE),t.frontFace(t.CCW);const l=i.meshes.filter(a=>a.opacity>=1),s=i.camera.position,u=a=>Math.hypot(a.world[12]-s[0],a.world[13]-s[1],a.world[14]-s[2]),_=i.meshes.filter(a=>a.opacity<1).sort((a,f)=>u(f)-u(a)||a.objectIndex-f.objectIndex);t.disable(t.BLEND),t.depthMask(!0);for(const a of l)a.material.outline&&this.drawOutline(i,a,o,r);for(const a of l)this.drawSurface(i,a);t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.depthMask(!1);for(const a of _)this.drawSurface(i,a);if(t.depthMask(!0),t.disable(t.BLEND),this.overlay&&i.drawables.length>0){const a=this.overlay;a.save(),a.setTransform(a.canvas.width/i.width,0,0,a.canvas.height/i.height,0,0),a.clearRect(0,0,i.width,i.height);for(const f of i.drawables)a.save(),f.draw(a,i),a.restore();a.restore()}else this.overlay&&this.overlay.clearRect(0,0,this.overlay.canvas.width,this.overlay.canvas.height)}drawSurface(i,t){const o=this.gl,r=this.surface;o.useProgram(r.program),t.material.doubleSided?o.disable(o.CULL_FACE):(o.enable(o.CULL_FACE),o.cullFace(o.BACK)),this.bindMesh(r,t.mesh);const n=r.uniform;o.uniformMatrix4fv(n("u_model"),!1,t.world),o.uniformMatrix4fv(n("u_view"),!1,i.camera.view),o.uniformMatrix4fv(n("u_projection"),!1,i.camera.projection),o.uniformMatrix3fv(n("u_normalMatrix"),!1,U(t.world));const l=D(i.lights);o.uniform1i(n("u_lightCount"),l.count),o.uniform1iv(n("u_lightKind"),l.kind),o.uniform3fv(n("u_lightColor"),l.color),o.uniform1fv(n("u_lightIntensity"),l.intensity),o.uniform3fv(n("u_lightPosition"),l.position),o.uniform3fv(n("u_lightDirection"),l.direction),o.uniform1fv(n("u_lightRange"),l.range),o.uniform2fv(n("u_lightCone"),l.cone);const s=G(t.material,t.color,t.opacity);o.uniform3fv(n("u_color"),s.color),o.uniform3fv(n("u_emissive"),s.emissive),o.uniform1f(n("u_opacity"),s.opacity),o.uniform1i(n("u_shading"),s.shading),o.uniform1f(n("u_bands"),s.bands),o.uniform3fv(n("u_eye"),i.camera.position),o.uniform3fv(n("u_forward"),i.camera.forward),o.uniform1i(n("u_orthographic"),i.camera.orthographic?1:0),o.uniform1i(n("u_fog"),i.fog?1:0),i.fog&&(o.uniform3fv(n("u_fogColor"),g(i.fog.color)),o.uniform2f(n("u_fogRange"),i.fog.near,i.fog.far)),o.drawElements(o.TRIANGLES,t.mesh.indices.length,o.UNSIGNED_INT,0)}drawOutline(i,t,o,r){const n=this.gl,l=this.outline,s=t.material.outline;n.useProgram(l.program),n.enable(n.CULL_FACE),n.cullFace(n.FRONT),this.bindMesh(l,t.mesh);const u=l.uniform;n.uniformMatrix4fv(u("u_model"),!1,t.world),n.uniformMatrix4fv(u("u_view"),!1,i.camera.view),n.uniformMatrix4fv(u("u_projection"),!1,i.camera.projection),n.uniformMatrix3fv(u("u_normalMatrix"),!1,U(t.world)),n.uniform2f(u("u_viewport"),o,r),n.uniform1f(u("u_width"),s.width*(o/i.width));const[_,a,f]=g(s.color);n.uniform4f(u("u_ink"),_,a,f,1),n.drawElements(n.TRIANGLES,t.mesh.indices.length,n.UNSIGNED_INT,0),n.cullFace(n.BACK)}bindMesh(i,t){const o=this.gl;let r=this.buffers.get(t);if(!r){const l=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,l),o.bufferData(o.ARRAY_BUFFER,new Float32Array(t.positions),o.STATIC_DRAW);const s=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,s),o.bufferData(o.ARRAY_BUFFER,new Float32Array(t.normals),o.STATIC_DRAW);const u=o.createBuffer();o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,u),o.bufferData(o.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),o.STATIC_DRAW),r={position:l,normal:s,index:u},this.buffers.set(t,r)}const n=(l,s)=>{const u=o.getAttribLocation(i.program,l);u<0||(o.bindBuffer(o.ARRAY_BUFFER,s),o.enableVertexAttribArray(u),o.vertexAttribPointer(u,3,o.FLOAT,!1,0,0))};n("a_position",r.position),n("a_normal",r.normal),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,r.index)}destroy(){this.gl.deleteProgram(this.surface.program),this.gl.deleteProgram(this.outline.program)}}function H(e,i,t){const o=(l,s)=>{const u=e.createShader(l);if(e.shaderSource(u,s),e.compileShader(u),!e.getShaderParameter(u,e.COMPILE_STATUS))throw new Error(`scene-3d webgl: shader failed to compile — ${e.getShaderInfoLog(u)}`);return u},r=e.createProgram();if(e.attachShader(r,o(e.VERTEX_SHADER,i)),e.attachShader(r,o(e.FRAGMENT_SHADER,t)),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS))throw new Error(`scene-3d webgl: program failed to link — ${e.getProgramInfoLog(r)}`);const n=new Map;return{program:r,uniform:l=>(n.has(l)||n.set(l,e.getUniformLocation(r,l)),n.get(l))}}h.LIGHT_CODE=k,h.MAX_LIGHTS=d,h.SHADING_CODE=P,h.WebGL2Renderer=J,h.normalMatrix3=U,h.packLights=D,h.surfaceUniforms=G,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
116
+ `,Q=[{id:"default-ambient",light:"ambient",color:"#ffffff",intensity:.35,position:[0,0,0],direction:[0,-1,0],angle:30},{id:"default-key",light:"directional",color:"#ffffff",intensity:.8,position:[3,5,4],direction:U([-3,-5,-4]),angle:30}];function D(e){const i=(e.length>0?e:Q).slice(0,d),t={count:i.length,kind:new Int32Array(d),color:new Float32Array(d*3),intensity:new Float32Array(d),position:new Float32Array(d*3),direction:new Float32Array(d*3),range:new Float32Array(d),cone:new Float32Array(d*2)};return i.forEach((o,r)=>{t.kind[r]=P[o.light],t.color.set(g(o.color),r*3),t.intensity[r]=o.intensity,t.position.set(o.position,r*3),t.direction.set(o.direction,r*3),t.range[r]=o.range??0,t.cone[r*2]=Math.cos(o.angle*Math.PI/180),t.cone[r*2+1]=Math.cos(o.angle*.8*Math.PI/180)}),t}function G(e,i,t){return{color:g(i??e.color),emissive:e.emissive?g(e.emissive):[0,0,0],opacity:t,shading:B[e.shading??"lambert"],bands:e.bands??3}}function k(e){const i=Y(z(e)??W());return new Float32Array([i[0],i[1],i[2],i[4],i[5],i[6],i[8],i[9],i[10]])}class J{gl;surface;outline;buffers=new WeakMap;overlay;constructor(i,t={}){this.gl=i,this.overlay=t.overlay,this.surface=H(i,K,V),this.outline=H(i,$,q)}render(i){const t=this.gl,o=t.drawingBufferWidth,r=t.drawingBufferHeight;t.viewport(0,0,o,r);const n=i.background&&i.background!=="transparent"?g(typeof i.background=="string"?i.background:i.background.bottom):null;t.clearColor(n?.[0]??0,n?.[1]??0,n?.[2]??0,n?1:0),t.clearDepth(1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.CULL_FACE),t.frontFace(t.CCW);const l=i.meshes.filter(a=>a.opacity>=1),s=i.camera.position,u=a=>Math.hypot(a.world[12]-s[0],a.world[13]-s[1],a.world[14]-s[2]),_=i.meshes.filter(a=>a.opacity<1).sort((a,f)=>u(f)-u(a)||a.objectIndex-f.objectIndex);t.disable(t.BLEND),t.depthMask(!0);for(const a of l)a.material.outline&&this.drawOutline(i,a,o,r);for(const a of l)this.drawSurface(i,a);t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.depthMask(!1);for(const a of _)this.drawSurface(i,a);if(t.depthMask(!0),t.disable(t.BLEND),this.overlay&&i.drawables.length>0){const a=this.overlay;a.save(),a.setTransform(a.canvas.width/i.width,0,0,a.canvas.height/i.height,0,0),a.clearRect(0,0,i.width,i.height);for(const f of i.drawables)a.save(),f.draw(a,i),a.restore();a.restore()}else this.overlay&&this.overlay.clearRect(0,0,this.overlay.canvas.width,this.overlay.canvas.height)}drawSurface(i,t){const o=this.gl,r=this.surface;o.useProgram(r.program),t.material.doubleSided?o.disable(o.CULL_FACE):(o.enable(o.CULL_FACE),o.cullFace(o.BACK)),this.bindMesh(r,t.mesh);const n=r.uniform;o.uniformMatrix4fv(n("u_model"),!1,t.world),o.uniformMatrix4fv(n("u_view"),!1,i.camera.view),o.uniformMatrix4fv(n("u_projection"),!1,i.camera.projection),o.uniformMatrix3fv(n("u_normalMatrix"),!1,k(t.world));const l=D(i.lights);o.uniform1i(n("u_lightCount"),l.count),o.uniform1iv(n("u_lightKind"),l.kind),o.uniform3fv(n("u_lightColor"),l.color),o.uniform1fv(n("u_lightIntensity"),l.intensity),o.uniform3fv(n("u_lightPosition"),l.position),o.uniform3fv(n("u_lightDirection"),l.direction),o.uniform1fv(n("u_lightRange"),l.range),o.uniform2fv(n("u_lightCone"),l.cone);const s=G(t.material,t.color,t.opacity);o.uniform3fv(n("u_color"),s.color),o.uniform3fv(n("u_emissive"),s.emissive),o.uniform1f(n("u_opacity"),s.opacity),o.uniform1i(n("u_shading"),s.shading),o.uniform1f(n("u_bands"),s.bands),o.uniform3fv(n("u_eye"),i.camera.position),o.uniform3fv(n("u_forward"),i.camera.forward),o.uniform1i(n("u_orthographic"),i.camera.orthographic?1:0),o.uniform1i(n("u_fog"),i.fog?1:0),i.fog&&(o.uniform3fv(n("u_fogColor"),g(i.fog.color)),o.uniform2f(n("u_fogRange"),i.fog.near,i.fog.far)),o.drawElements(o.TRIANGLES,t.mesh.indices.length,o.UNSIGNED_INT,0)}drawOutline(i,t,o,r){const n=this.gl,l=this.outline,s=t.material.outline;n.useProgram(l.program),n.enable(n.CULL_FACE),n.cullFace(n.FRONT),this.bindMesh(l,t.mesh);const u=l.uniform;n.uniformMatrix4fv(u("u_model"),!1,t.world),n.uniformMatrix4fv(u("u_view"),!1,i.camera.view),n.uniformMatrix4fv(u("u_projection"),!1,i.camera.projection),n.uniformMatrix3fv(u("u_normalMatrix"),!1,k(t.world)),n.uniform2f(u("u_viewport"),o,r),n.uniform1f(u("u_width"),s.width*(o/i.width));const[_,a,f]=g(s.color);n.uniform4f(u("u_ink"),_,a,f,1),n.drawElements(n.TRIANGLES,t.mesh.indices.length,n.UNSIGNED_INT,0),n.cullFace(n.BACK)}bindMesh(i,t){const o=this.gl;let r=this.buffers.get(t);if(!r){const l=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,l),o.bufferData(o.ARRAY_BUFFER,new Float32Array(t.positions),o.STATIC_DRAW);const s=o.createBuffer();o.bindBuffer(o.ARRAY_BUFFER,s),o.bufferData(o.ARRAY_BUFFER,new Float32Array(t.normals),o.STATIC_DRAW);const u=o.createBuffer();o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,u),o.bufferData(o.ELEMENT_ARRAY_BUFFER,new Uint32Array(t.indices),o.STATIC_DRAW),r={position:l,normal:s,index:u},this.buffers.set(t,r)}const n=(l,s)=>{const u=o.getAttribLocation(i.program,l);u<0||(o.bindBuffer(o.ARRAY_BUFFER,s),o.enableVertexAttribArray(u),o.vertexAttribPointer(u,3,o.FLOAT,!1,0,0))};n("a_position",r.position),n("a_normal",r.normal),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,r.index)}destroy(){this.gl.deleteProgram(this.surface.program),this.gl.deleteProgram(this.outline.program)}}function H(e,i,t){const o=(l,s)=>{const u=e.createShader(l);if(e.shaderSource(u,s),e.compileShader(u),!e.getShaderParameter(u,e.COMPILE_STATUS))throw new Error(`scene-3d webgl: shader failed to compile — ${e.getShaderInfoLog(u)}`);return u},r=e.createProgram();if(e.attachShader(r,o(e.VERTEX_SHADER,i)),e.attachShader(r,o(e.FRAGMENT_SHADER,t)),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS))throw new Error(`scene-3d webgl: program failed to link — ${e.getProgramInfoLog(r)}`);const n=new Map;return{program:r,uniform:l=>(n.has(l)||n.set(l,e.getUniformLocation(r,l)),n.get(l))}}h.LIGHT_CODE=P,h.MAX_LIGHTS=d,h.SHADING_CODE=B,h.WebGL2Renderer=J,h.normalMatrix3=k,h.packLights=D,h.surfaceUniforms=G,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
@@ -1,3 +1,3 @@
1
- (function(T){"use strict";const Gt=[{name:"position",vector:"position",components:["x","y","z"]},{name:"rotation",vector:"quaternion",components:["rotateX","rotateY","rotateZ"]}];function wt(t,s=[]){const i=[],n=new Map;for(const o of t.objects){if(o.id?n.has(o.id)&&i.push(`two objects share the id "${o.id}"`):i.push("an object has no id"),o.parent!==void 0&&!n.has(o.parent)&&i.push(`"${o.id}" has parent "${o.parent}", which must be an earlier object`),o.quaternion&&o.quaternion.length!==4&&i.push(`"${o.id}": a quaternion has four numbers`),o.kind==="mesh"){t.materials?.[o.material]||i.push(`"${o.id}" uses material "${o.material}", which is not in materials`);const r=o.geometry,a=r.type==="box"||r.type==="plane"?r.size:r.type==="torus"?[r.radius,r.tube]:r.type==="sphere"?[r.radius]:r.type==="extrude"?[r.depth,r.width??1]:[r.radius,r.height];r.type==="extrude"&&!(typeof r.path=="string"&&/^\s*[Mm]/.test(r.path))&&i.push(`"${o.id}": an extrude needs a path that starts with M`),a.every(h=>Number.isFinite(h)&&h>0)||i.push(`"${o.id}": a ${r.type}'s sizes must be positive`)}if(o.kind==="line"||o.kind==="trail"){o.width!==void 0&&!(o.width>0)&&i.push(`"${o.id}": width must be positive`);for(const r of["taper","fade","opacity"]){const a=o[r];a!==void 0&&!(a>=0&&a<=1)&&i.push(`"${o.id}": ${r} is between 0 and 1`)}}o.kind==="line"&&(Array.isArray(o.points)&&o.points.length>=2&&o.points.every(a=>Array.isArray(a)&&a.length===3&&a.every(Number.isFinite))||i.push(`"${o.id}": a line needs two or more points of three numbers`)),o.kind==="trail"&&(o.length>0||i.push(`"${o.id}": a trail's length (ms) must be positive`),(o.follow===o.id||!t.objects.some(r=>r.id===o.follow))&&i.push(`"${o.id}" follows "${o.follow}", which is not another object in the scene`),o.samples!==void 0&&!(o.samples>=2)&&i.push(`"${o.id}": a trail needs at least 2 samples`)),o.kind==="camera"&&(o.near>0&&o.far>o.near||i.push(`camera "${o.id}": near must be above 0 and far beyond it`),o.projection==="perspective"&&!(o.fov>0&&o.fov<180)&&i.push(`camera "${o.id}": fov is between 0 and 180 degrees`),o.projection==="orthographic"&&!(o.height>0)&&i.push(`camera "${o.id}": height must be positive`)),o.id&&n.set(o.id,o)}const e=n.get(t.camera);e?e.kind!=="camera"&&i.push(`the scene's camera "${t.camera}" is a ${e.kind}, not a camera`):i.push(`the scene's camera "${t.camera}" is not one of its objects`),t.fog&&!(t.fog.far>t.fog.near)&&i.push("fog: far must be beyond near");const c=new Map;for(const o of s){if(!o.target.startsWith(`${t.id}/`))continue;const r=o.target.slice(t.id.length+1);c.has(r)||c.set(r,new Set),c.get(r).add(o.property)}for(const[o,r]of c){n.has(o)||i.push(`a track animates "${t.id}/${o}", which is not in the scene`);for(const a of Gt)r.has(a.vector)&&a.components.some(h=>r.has(h))&&i.push(`"${o}": its ${a.name} is animated both by ${a.vector} and by ${a.components.join(" / ")}; use one`)}return i}class z{positions=[];normals=[];indices=[];vertex(s,i,n,e,c,o){const r=Math.hypot(e,c,o)||1;return this.positions.push(s,i,n),this.normals.push(e/r,c/r,o/r),this.positions.length/3-1}triangle(s,i,n){this.indices.push(s,i,n)}quad(s,i,n,e){this.indices.push(s,i,n,s,n,e)}build(){return{positions:this.positions,normals:this.normals,indices:this.indices}}}function vt(t){const s=new Map,i=[];for(let e=0;e<t.positions.length/3;e++){const c=[0,1,2].map(o=>Math.round(t.positions[e*3+o]*1e6)).join(",");s.has(c)||s.set(c,e),i.push(s.get(c))}const n=new Map;for(let e=0;e<t.indices.length/3;e++)for(let c=0;c<3;c++){const o=i[t.indices[e*3+c]],r=i[t.indices[e*3+(c+1)%3]];if(o===r)continue;const a=o<r?`${o}-${r}`:`${r}-${o}`,h=n.get(a);h?h.faces.push(e):n.set(a,{a:Math.min(o,r),b:Math.max(o,r),faces:[e]})}return[...n.values()]}const xt=32,Bt=256,F=new Map,Jt=/[MmLlHhVvCcSsQqTtAaZz]/,Kt=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,tn={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function nn(t){const s=[];let i=0,n=null;const e=()=>{for(;i<t.length&&/[\s,]/.test(t[i]);)i++};for(;i<t.length&&(e(),!(i>=t.length));){const c=t[i];if(Jt.test(c)){n={type:c,args:[]},s.push(n),i++;continue}if(!n)break;const o=n.type==="A"||n.type==="a",r=n.args.length%7;if(o&&(r===3||r===4)){if(c!=="0"&&c!=="1")break;n.args.push(c==="1"?1:0),i++;continue}const a=Kt.exec(t.slice(i));if(!a)break;n.args.push(parseFloat(a[0])),i+=a[0].length}return s}function en(t,s,i,n,e,c,o,r,a){if(t===r&&s===a)return[];let h=Math.abs(i),d=Math.abs(n);if(h===0||d===0)return[[t,s,r,a,r,a]];const u=e*Math.PI/180,f=Math.cos(u),p=Math.sin(u),M=(t-r)/2,g=(s-a)/2,m=f*M+p*g,l=-p*M+f*g,w=m*m/(h*h)+l*l/(d*d);if(w>1){const X=Math.sqrt(w);h*=X,d*=X}const A=c===o?-1:1,b=h*h*d*d-h*h*l*l-d*d*m*m,y=h*h*l*l+d*d*m*m,x=A*Math.sqrt(Math.max(0,b/y)),v=x*h*l/d,I=-x*d*m/h,E=f*v-p*I+(t+r)/2,S=p*v+f*I+(s+a)/2,k=(X,j,N,U)=>{const bt=X*N+j*U,nt=Math.sqrt((X*X+j*j)*(N*N+U*U)),B=Math.acos(Math.max(-1,Math.min(1,bt/nt)));return X*U-j*N<0?-B:B},P=k(1,0,(m-v)/h,(l-I)/d);let $=k((m-v)/h,(l-I)/d,(-m-v)/h,(-l-I)/d);!o&&$>0&&($-=2*Math.PI),o&&$<0&&($+=2*Math.PI);const C=Math.max(1,Math.ceil(Math.abs($)/(Math.PI/2))),G=$/C,R=4/3*Math.tan(G/4),Vt=X=>{const j=h*Math.cos(X),N=d*Math.sin(X);return[f*j-p*N+E,p*j+f*N+S]},Wt=X=>{const j=-h*Math.sin(X),N=d*Math.cos(X);return[f*j-p*N,p*j+f*N]},Zt=[];for(let X=0;X<C;X++){const j=P+X*G,N=j+G,[U,bt]=Vt(j),[nt,B]=X===C-1?[r,a]:Vt(N),[Dn,Hn]=Wt(j),[Qn,Rn]=Wt(N);Zt.push([U+R*Dn,bt+R*Hn,nt-R*Qn,B-R*Rn,nt,B])}return Zt}function kt(t,s,i,n,e){const c=1-e;return c*c*c*t+3*c*c*e*s+3*c*e*e*i+e*e*e*n}function V(t,s,i,n){return{subpath:0,type:"L",points:[i,n],startX:t,startY:s,endX:i,endY:n,length:Math.hypot(i-t,n-s)}}function J(t,s,i){const[n,e,c,o,r,a]=i,h=[0];let d=t,u=s,f=0;for(let p=1;p<=xt;p++){const M=p/xt,g=kt(t,n,c,r,M),m=kt(s,e,o,a,M);f+=Math.hypot(g-d,m-u),h.push(f),d=g,u=m}return{subpath:0,type:"C",points:[n,e,c,o,r,a],startX:t,startY:s,endX:r,endY:a,length:f,lengths:h}}function sn(t){const s=F.get(t);if(s)return s;const i=[];let n=0,e=0,c=0,o=0,r=null,a=null,h=-1;const d=new Set,u=g=>{h<0&&(h=0),g.subpath=h,i.push(g)};for(const{type:g,args:m}of nn(t)){const l=g.toUpperCase(),w=g!==l,A=tn[l];if(l==="Z"){(n!==c||e!==o)&&u(V(n,e,c,o)),h>=0&&d.add(h),n=c,e=o,r=a=null;continue}for(let b=0;b+A<=m.length;b+=A){const y=m.slice(b,b+A),x=w?n:0,v=w?e:0;let I=null,E=null;switch(l){case"M":b===0?(n=y[0]+x,e=y[1]+v,c=n,o=e,(h<0||i[i.length-1]?.subpath===h)&&h++):(u(V(n,e,y[0]+x,y[1]+v)),n=y[0]+x,e=y[1]+v);break;case"L":u(V(n,e,y[0]+x,y[1]+v)),n=y[0]+x,e=y[1]+v;break;case"H":u(V(n,e,y[0]+x,e)),n=y[0]+x;break;case"V":u(V(n,e,n,y[0]+v)),e=y[0]+v;break;case"C":{const S=[y[0]+x,y[1]+v,y[2]+x,y[3]+v,y[4]+x,y[5]+v];u(J(n,e,S)),I=[S[2],S[3]],n=S[4],e=S[5];break}case"S":{const[S,k]=r?[2*n-r[0],2*e-r[1]]:[n,e],P=[S,k,y[0]+x,y[1]+v,y[2]+x,y[3]+v];u(J(n,e,P)),I=[P[2],P[3]],n=P[4],e=P[5];break}case"Q":case"T":{let S=n,k=e;l==="Q"?(S=y[0]+x,k=y[1]+v):a&&(S=2*n-a[0],k=2*e-a[1]);const P=l==="Q"?y[2]+x:y[0]+x,$=l==="Q"?y[3]+v:y[1]+v;u(J(n,e,[n+2/3*(S-n),e+2/3*(k-e),P+2/3*(S-P),$+2/3*(k-$),P,$])),E=[S,k],n=P,e=$;break}case"A":{const S=y[5]+x,k=y[6]+v;let P=n,$=e;for(const C of en(n,e,y[0],y[1],y[2],y[3],y[4],S,k))u(J(P,$,C)),P=C[4],$=C[5];n=S,e=k;break}}r=I,a=E}}const f=i.reduce((g,m)=>g+m.length,0),p=[];for(let g=0;g<i.length;){const m=i[g].subpath;let l=g,w=0;for(;l<i.length&&i[l].subpath===m;)w+=i[l++].length;const A=i[g],b=i[l-1],y=d.has(m)||Math.abs(b.endX-A.startX)<1e-9&&Math.abs(b.endY-A.startY)<1e-9;p.push({start:g,end:l,length:w,closed:y}),g=l}const M={segments:i,totalLength:f,subpaths:p};return F.size>=Bt&&F.delete(F.keys().next().value),F.set(t,M),M}function Q(t){let s=0;for(let i=0;i<t.length;i++){const n=t[i],e=t[(i+1)%t.length];s+=n.x*e.y-e.x*n.y}return s}function et(t,s){let i=!1;for(let n=0,e=s.length-1;n<s.length;e=n++){const c=s[n],o=s[e];c.y>t.y!=o.y>t.y&&t.x<(o.x-c.x)*(t.y-c.y)/(o.y-c.y)+c.x&&(i=!i)}return i}const K=(t,s,i)=>(s.x-t.x)*(i.y-t.y)-(s.y-t.y)*(i.x-t.x),st=(t,s)=>t.x===s.x&&t.y===s.y;function ot(t,s,i,n){return K(s,i,t)>=0&&K(i,n,t)>=0&&K(n,s,t)>=0}function on(t,s){let i=0;for(let f=1;f<s.length;f++)s[f].x>s[i].x&&(i=f);const n=s[i];let e=-1,c=1/0;for(let f=0;f<t.length;f++){const p=t[f],M=t[(f+1)%t.length];if(p.y>n.y==M.y>n.y)continue;const g=p.x+(n.y-p.y)*(M.x-p.x)/(M.y-p.y);g>=n.x&&g<c&&(c=g,e=f)}if(e<0)return t;const o=t[e],r=t[(e+1)%t.length];let a=o.x>r.x?e:(e+1)%t.length;const h={x:c,y:n.y};let d=1/0;for(let f=0;f<t.length;f++){const p=t[f];if(f===a||p.x<n.x)continue;const M=t[a];if(!(ot(p,n,h,M)||ot(p,n,M,h)))continue;const m=Math.abs(Math.atan2(p.y-n.y,p.x-n.x));m<d&&(d=m,a=f)}const u=s.slice(i).concat(s.slice(0,i));return[...t.slice(0,a+1),...u,n,t[a],...t.slice(a+1)]}function At(t,s=[]){const i=Q(t)>=0?t:[...t].reverse(),n=s.map(u=>Q(u)<=0?u:[...u].reverse()),e=[...i,...n.flat()],c=new Map;e.forEach((u,f)=>c.set(u,f));const o=[...n].sort((u,f)=>Math.max(...f.map(p=>p.x))-Math.max(...u.map(p=>p.x)));let r=i;for(const u of o)r=on(r,u);const a=r.map(u=>c.get(u)),h=[];let d=a.length*a.length;for(;a.length>3&&d-- >0;){let u=!1;for(let f=0;f<a.length;f++){const p=a[(f+a.length-1)%a.length],M=a[f],g=a[(f+1)%a.length],[m,l,w]=[e[p],e[M],e[g]];if(K(m,l,w)<=0)continue;let A=!1;for(const b of a){const y=e[b];if(!(b===p||b===M||b===g||st(y,m)||st(y,l)||st(y,w))&&ot(y,m,l,w)){A=!0;break}}if(!A){h.push(p,M,g),a.splice(f,1),u=!0;break}}u||(h.push(a[a.length-1],a[0],a[1]),a.splice(0,1))}return a.length===3&&h.push(a[0],a[1],a[2]),{points:e,triangles:h}}function cn(t,s){const i=new Map;for(const n of sn(t).segments){i.has(n.subpath)||i.set(n.subpath,[{x:n.startX,y:-n.startY}]);const e=i.get(n.subpath);if(n.type==="L")e.push({x:n.endX,y:-n.endY});else{const[c,o,r,a,h,d]=n.points;for(let u=1;u<=s;u++){const f=u/s,p=1-f,M=p*p*p*n.startX+3*p*p*f*c+3*p*f*f*r+f*f*f*h,g=p*p*p*n.startY+3*p*p*f*o+3*p*f*f*a+f*f*f*d;e.push({x:M,y:-g})}}}return[...i.values()].map(n=>n.filter((e,c)=>c===0||e.x!==n[c-1].x||e.y!==n[c-1].y)).map(n=>n.length>1&&n[0].x===n[n.length-1].x&&n[0].y===n[n.length-1].y?n.slice(0,-1):n).filter(n=>n.length>=3&&Math.abs(Q(n))>1e-12)}function $t(t,s){const i=cn(t,Math.max(1,Math.round(s.curveSegments??12))),n=new z;if(i.length===0)return n.build();const e=i.flat(),c=Math.min(...e.map(m=>m.x)),o=Math.max(...e.map(m=>m.x)),r=Math.min(...e.map(m=>m.y)),a=Math.max(...e.map(m=>m.y)),h=(s.width??1)/Math.max(o-c,1e-9),d=(c+o)/2,u=(r+a)/2,f=i.map(m=>m.map(l=>({x:(l.x-d)*h,y:(l.y-u)*h}))),p=f.map((m,l)=>f.filter((w,A)=>A!==l&&et(m[0],w)).length),M=s.depth/2,g=-s.depth/2;return f.forEach((m,l)=>{if(p[l]%2===1)return;const w=f.filter((v,I)=>p[I]===p[l]+1&&et(v[0],m)),{points:A,triangles:b}=At(m,w),y=A.map(v=>n.vertex(v.x,v.y,M,0,0,1)),x=A.map(v=>n.vertex(v.x,v.y,g,0,0,-1));for(let v=0;v<b.length;v+=3)n.triangle(y[b[v]],y[b[v+1]],y[b[v+2]]),n.triangle(x[b[v]],x[b[v+2]],x[b[v+1]]);for(const v of[Q(m)>=0?m:[...m].reverse(),...w.map(I=>Q(I)<=0?I:[...I].reverse())])for(let I=0;I<v.length;I++){const E=v[I],S=v[(I+1)%v.length],k=S.y-E.y,P=-(S.x-E.x),$=n.vertex(E.x,E.y,g,k,P,0),C=n.vertex(S.x,S.y,g,k,P,0),G=n.vertex(S.x,S.y,M,k,P,0),R=n.vertex(E.x,E.y,M,k,P,0);n.quad($,C,G,R)}}),n.build()}const q=Math.PI*2;function It([t,s,i]){const n=new z,e=t/2,c=s/2,o=i/2,r=[[[0,0,1],[[-e,-c,o],[e,-c,o],[e,c,o],[-e,c,o]]],[[0,0,-1],[[e,-c,-o],[-e,-c,-o],[-e,c,-o],[e,c,-o]]],[[1,0,0],[[e,-c,o],[e,-c,-o],[e,c,-o],[e,c,o]]],[[-1,0,0],[[-e,-c,-o],[-e,-c,o],[-e,c,o],[-e,c,-o]]],[[0,1,0],[[-e,c,o],[e,c,o],[e,c,-o],[-e,c,-o]]],[[0,-1,0],[[-e,-c,-o],[e,-c,-o],[e,-c,o],[-e,-c,o]]]];for(const[[a,h,d],u]of r){const[f,p,M,g]=u.map(([m,l,w])=>n.vertex(m,l,w,a,h,d));n.quad(f,p,M,g)}return n.build()}function St([t,s],i=1){const n=new z,e=Math.max(1,Math.round(i)),c=[];for(let o=0;o<=e;o++){const r=s/2-s*o/e;c.push(Array.from({length:e+1},(a,h)=>n.vertex(-t/2+t*h/e,0,r,0,1,0)))}for(let o=0;o<e;o++)for(let r=0;r<e;r++)n.quad(c[o][r],c[o][r+1],c[o+1][r+1],c[o+1][r]);return n.build()}function Pt(t,s=16){const i=new z,n=Math.max(6,Math.round(s)),e=Math.max(3,Math.round(n/2)),c=[];for(let o=0;o<=e;o++){const r=o/e*Math.PI,a=[];for(let h=0;h<=n;h++){const d=h/n*q,u=Math.sin(r)*Math.sin(d),f=Math.cos(r),p=Math.sin(r)*Math.cos(d);a.push(i.vertex(u*t,f*t,p*t,u,f,p))}c.push(a)}for(let o=0;o<e;o++)for(let r=0;r<n;r++){const a=c[o][r],h=c[o+1][r],d=c[o+1][r+1],u=c[o][r+1];o>0&&i.triangle(a,h,u),o<e-1&&i.triangle(h,d,u)}return i.build()}function it(t,s,i,n,e){const c=t.vertex(0,i,0,0,n,0),o=Array.from({length:e},(r,a)=>{const h=a/e*q;return t.vertex(Math.sin(h)*s,i,Math.cos(h)*s,0,n,0)});for(let r=0;r<e;r++){const a=o[r],h=o[(r+1)%e];n===1?t.triangle(c,a,h):t.triangle(c,h,a)}}function Tt(t,s,i=24){const n=new z,e=Math.max(6,Math.round(i)),c=s/2,o=-s/2,r=d=>Array.from({length:e+1},(u,f)=>{const p=f/e*q;return n.vertex(Math.sin(p)*t,d,Math.cos(p)*t,Math.sin(p),0,Math.cos(p))}),a=r(o),h=r(c);for(let d=0;d<e;d++)n.quad(a[d],a[d+1],h[d+1],h[d]);return it(n,t,c,1,e),it(n,t,o,-1,e),n.build()}function Ct(t,s,i=24){const n=new z,e=Math.max(6,Math.round(i)),c=s/2,o=-s/2,r=t/s;for(let a=0;a<e;a++){const h=a/e*q,d=(a+1)/e*q,u=(h+d)/2,f=n.vertex(Math.sin(h)*t,o,Math.cos(h)*t,Math.sin(h),r,Math.cos(h)),p=n.vertex(Math.sin(d)*t,o,Math.cos(d)*t,Math.sin(d),r,Math.cos(d)),M=n.vertex(0,c,0,Math.sin(u),r,Math.cos(u));n.triangle(f,p,M)}return it(n,t,o,-1,e),n.build()}function Et(t,s,i=24){const n=new z,e=Math.max(6,Math.round(i)),c=Math.max(4,Math.round(e/2)),o=[];for(let r=0;r<=e;r++){const a=r/e*q,h=[];for(let d=0;d<=c;d++){const u=d/c*q,f=Math.cos(u)*Math.sin(a),p=Math.sin(u),M=Math.cos(u)*Math.cos(a),g=t+s*Math.cos(u);h.push(n.vertex(g*Math.sin(a),s*Math.sin(u),g*Math.cos(a),f,p,M))}o.push(h)}for(let r=0;r<e;r++)for(let a=0;a<c;a++)n.quad(o[r][a],o[r+1][a],o[r+1][a+1],o[r][a+1]);return n.build()}function Xt(t){switch(t.type){case"box":return It(t.size);case"plane":return St(t.size,t.segments);case"sphere":return Pt(t.radius,t.segments);case"cylinder":return Tt(t.radius,t.height,t.segments);case"cone":return Ct(t.radius,t.height,t.segments);case"torus":return Et(t.radius,t.tube,t.segments);case"extrude":return $t(t.path,{depth:t.depth,width:t.width,curveSegments:t.curveSegments})}}function Yt(t){const s=Array.from({length:t.indices.length/3},()=>[]);for(const i of vt(t))for(const n of i.faces){const e=i.faces.find(c=>c!==n)??-1;s[n].push({a:i.a,b:i.b,across:e})}return{...t,faceEdges:s}}function rn(t,s={}){const i=new Map((s.kinds??[]).map(o=>[o.kind,o])),n=wt(t);for(const o of t.objects){if(an.has(o.kind))continue;const r=i.get(o.kind);r?n.push(...(r.validate?.(o)??[]).map(a=>`"${o.id}": ${a}`)):n.push(`"${o.id}" is a ${o.kind}: load the scene with that kind (for characters: loadScene3D(scene, { kinds: [characterObjects] }), from @algorisys/tinyfly/characters)`)}if(n.length>0)throw new Error(`scene-3d: "${t.id}" is not valid:
1
+ (function(I){"use strict";const pn=[{name:"position",vector:"position",components:["x","y","z"]},{name:"rotation",vector:"quaternion",components:["rotateX","rotateY","rotateZ"]}];function Nt(t,e=[]){const o=[],n=new Map;for(const i of t.objects){if(i.id?n.has(i.id)&&o.push(`two objects share the id "${i.id}"`):o.push("an object has no id"),i.parent!==void 0&&!n.has(i.parent)&&o.push(`"${i.id}" has parent "${i.parent}", which must be an earlier object`),i.quaternion&&i.quaternion.length!==4&&o.push(`"${i.id}": a quaternion has four numbers`),i.kind==="mesh"){t.materials?.[i.material]||o.push(`"${i.id}" uses material "${i.material}", which is not in materials`);const c=i.geometry;if(c.type==="mesh"){const a=(c.positions?.length??0)/3;(!Array.isArray(c.positions)||c.positions.length%3!==0||a<3)&&o.push(`"${i.id}": a mesh needs positions as x, y, z runs for at least three vertices`),!Array.isArray(c.indices)||c.indices.length%3!==0||c.indices.length<3?o.push(`"${i.id}": a mesh needs indices in triples`):c.indices.every(l=>Number.isInteger(l)&&l>=0&&l<a)||o.push(`"${i.id}": a mesh index is out of range`),c.normals&&c.normals.length!==(c.positions?.length??0)&&o.push(`"${i.id}": a mesh's normals must match its positions`),c.colors&&c.colors.length!==(c.indices?.length??0)/3&&c.colors.length!==a&&o.push(`"${i.id}": a mesh's colors are one per face or one per vertex`)}else{const a=c.type==="box"||c.type==="plane"?c.size:c.type==="torus"?[c.radius,c.tube]:c.type==="sphere"?[c.radius]:c.type==="extrude"?[c.depth,c.width??1]:[c.radius,c.height];c.type==="extrude"&&!(typeof c.path=="string"&&/^\s*[Mm]/.test(c.path))&&o.push(`"${i.id}": an extrude needs a path that starts with M`),a.every(l=>Number.isFinite(l)&&l>0)||o.push(`"${i.id}": a ${c.type}'s sizes must be positive`)}}if(i.kind==="line"||i.kind==="trail"){i.width!==void 0&&!(i.width>0)&&o.push(`"${i.id}": width must be positive`);for(const c of["taper","fade","opacity"]){const a=i[c];a!==void 0&&!(a>=0&&a<=1)&&o.push(`"${i.id}": ${c} is between 0 and 1`)}}i.kind==="line"&&(Array.isArray(i.points)&&i.points.length>=2&&i.points.every(a=>Array.isArray(a)&&a.length===3&&a.every(Number.isFinite))||o.push(`"${i.id}": a line needs two or more points of three numbers`)),i.kind==="trail"&&(i.length>0||o.push(`"${i.id}": a trail's length (ms) must be positive`),(i.follow===i.id||!t.objects.some(c=>c.id===i.follow))&&o.push(`"${i.id}" follows "${i.follow}", which is not another object in the scene`),i.samples!==void 0&&!(i.samples>=2)&&o.push(`"${i.id}": a trail needs at least 2 samples`)),i.kind==="camera"&&(i.near>0&&i.far>i.near||o.push(`camera "${i.id}": near must be above 0 and far beyond it`),i.projection==="perspective"&&!(i.fov>0&&i.fov<180)&&o.push(`camera "${i.id}": fov is between 0 and 180 degrees`),i.projection==="orthographic"&&!(i.height>0)&&o.push(`camera "${i.id}": height must be positive`)),i.id&&n.set(i.id,i)}const s=n.get(t.camera);s?s.kind!=="camera"&&o.push(`the scene's camera "${t.camera}" is a ${s.kind}, not a camera`):o.push(`the scene's camera "${t.camera}" is not one of its objects`),t.fog&&!(t.fog.far>t.fog.near)&&o.push("fog: far must be beyond near");const r=new Map;for(const i of e){if(!i.target.startsWith(`${t.id}/`))continue;const c=i.target.slice(t.id.length+1);r.has(c)||r.set(c,new Set),r.get(c).add(i.property)}for(const[i,c]of r){n.has(i)||o.push(`a track animates "${t.id}/${i}", which is not in the scene`);for(const a of pn)c.has(a.vector)&&a.components.some(l=>c.has(l))&&o.push(`"${i}": its ${a.name} is animated both by ${a.vector} and by ${a.components.join(" / ")}; use one`)}return o}class H{positions=[];normals=[];indices=[];vertex(e,o,n,s,r,i){const c=Math.hypot(s,r,i)||1;return this.positions.push(e,o,n),this.normals.push(s/c,r/c,i/c),this.positions.length/3-1}triangle(e,o,n){this.indices.push(e,o,n)}quad(e,o,n,s){this.indices.push(e,o,n,e,n,s)}build(){return{positions:this.positions,normals:this.normals,indices:this.indices}}}function Yt(t){const e=new Map,o=[];for(let s=0;s<t.positions.length/3;s++){const r=[0,1,2].map(i=>Math.round(t.positions[s*3+i]*1e6)).join(",");e.has(r)||e.set(r,s),o.push(e.get(r))}const n=new Map;for(let s=0;s<t.indices.length/3;s++)for(let r=0;r<3;r++){const i=o[t.indices[s*3+r]],c=o[t.indices[s*3+(r+1)%3]];if(i===c)continue;const a=i<c?`${i}-${c}`:`${c}-${i}`,l=n.get(a);l?l.faces.push(s):n.set(a,{a:Math.min(i,c),b:Math.max(i,c),faces:[s]})}return[...n.values()]}const jt=32,mn=256,W=new Map,yn=/[MmLlHhVvCcSsQqTtAaZz]/,Mn=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/,bn={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};function wn(t){const e=[];let o=0,n=null;const s=()=>{for(;o<t.length&&/[\s,]/.test(t[o]);)o++};for(;o<t.length&&(s(),!(o>=t.length));){const r=t[o];if(yn.test(r)){n={type:r,args:[]},e.push(n),o++;continue}if(!n)break;const i=n.type==="A"||n.type==="a",c=n.args.length%7;if(i&&(c===3||c===4)){if(r!=="0"&&r!=="1")break;n.args.push(r==="1"?1:0),o++;continue}const a=Mn.exec(t.slice(o));if(!a)break;n.args.push(parseFloat(a[0])),o+=a[0].length}return e}function kn(t,e,o,n,s,r,i,c,a){if(t===c&&e===a)return[];let l=Math.abs(o),h=Math.abs(n);if(l===0||h===0)return[[t,e,c,a,c,a]];const d=s*Math.PI/180,f=Math.cos(d),m=Math.sin(d),y=(t-c)/2,g=(e-a)/2,p=f*y+m*g,v=-m*y+f*g,u=p*p/(l*l)+v*v/(h*h);if(u>1){const X=Math.sqrt(u);l*=X,h*=X}const k=r===i?-1:1,w=l*l*h*h-l*l*v*v-h*h*p*p,M=l*l*v*v+h*h*p*p,$=k*Math.sqrt(Math.max(0,w/M)),b=$*l*v/h,A=-$*h*p/l,E=f*b-m*A+(t+c)/2,S=m*b+f*A+(e+a)/2,P=(X,O,N,V)=>{const Ot=X*N+O*V,lt=Math.sqrt((X*X+O*O)*(N*N+V*V)),tt=Math.acos(Math.max(-1,Math.min(1,Ot/lt)));return X*V-O*N<0?-tt:tt},T=P(1,0,(p-b)/l,(v-A)/h);let x=P((p-b)/l,(v-A)/h,(-p-b)/l,(-v-A)/h);!i&&x>0&&(x-=2*Math.PI),i&&x<0&&(x+=2*Math.PI);const C=Math.max(1,Math.ceil(Math.abs(x)/(Math.PI/2))),D=x/C,j=4/3*Math.tan(D/4),G=X=>{const O=l*Math.cos(X),N=h*Math.sin(X);return[f*O-m*N+E,m*O+f*N+S]},K=X=>{const O=-l*Math.sin(X),N=h*Math.cos(X);return[f*O-m*N,m*O+f*N]},at=[];for(let X=0;X<C;X++){const O=T+X*D,N=O+D,[V,Ot]=G(O),[lt,tt]=X===C-1?[c,a]:G(N),[Qe,qe]=K(O),[Be,Ge]=K(N);at.push([V+j*Qe,Ot+j*qe,lt-j*Be,tt-j*Ge,lt,tt])}return at}function Dt(t,e,o,n,s){const r=1-s;return r*r*r*t+3*r*r*s*e+3*r*s*s*o+s*s*s*n}function U(t,e,o,n){return{subpath:0,type:"L",points:[o,n],startX:t,startY:e,endX:o,endY:n,length:Math.hypot(o-t,n-e)}}function nt(t,e,o){const[n,s,r,i,c,a]=o,l=[0];let h=t,d=e,f=0;for(let m=1;m<=jt;m++){const y=m/jt,g=Dt(t,n,r,c,y),p=Dt(e,s,i,a,y);f+=Math.hypot(g-h,p-d),l.push(f),h=g,d=p}return{subpath:0,type:"C",points:[n,s,r,i,c,a],startX:t,startY:e,endX:c,endY:a,length:f,lengths:l}}function vn(t){const e=W.get(t);if(e)return e;const o=[];let n=0,s=0,r=0,i=0,c=null,a=null,l=-1;const h=new Set,d=g=>{l<0&&(l=0),g.subpath=l,o.push(g)};for(const{type:g,args:p}of wn(t)){const v=g.toUpperCase(),u=g!==v,k=bn[v];if(v==="Z"){(n!==r||s!==i)&&d(U(n,s,r,i)),l>=0&&h.add(l),n=r,s=i,c=a=null;continue}for(let w=0;w+k<=p.length;w+=k){const M=p.slice(w,w+k),$=u?n:0,b=u?s:0;let A=null,E=null;switch(v){case"M":w===0?(n=M[0]+$,s=M[1]+b,r=n,i=s,(l<0||o[o.length-1]?.subpath===l)&&l++):(d(U(n,s,M[0]+$,M[1]+b)),n=M[0]+$,s=M[1]+b);break;case"L":d(U(n,s,M[0]+$,M[1]+b)),n=M[0]+$,s=M[1]+b;break;case"H":d(U(n,s,M[0]+$,s)),n=M[0]+$;break;case"V":d(U(n,s,n,M[0]+b)),s=M[0]+b;break;case"C":{const S=[M[0]+$,M[1]+b,M[2]+$,M[3]+b,M[4]+$,M[5]+b];d(nt(n,s,S)),A=[S[2],S[3]],n=S[4],s=S[5];break}case"S":{const[S,P]=c?[2*n-c[0],2*s-c[1]]:[n,s],T=[S,P,M[0]+$,M[1]+b,M[2]+$,M[3]+b];d(nt(n,s,T)),A=[T[2],T[3]],n=T[4],s=T[5];break}case"Q":case"T":{let S=n,P=s;v==="Q"?(S=M[0]+$,P=M[1]+b):a&&(S=2*n-a[0],P=2*s-a[1]);const T=v==="Q"?M[2]+$:M[0]+$,x=v==="Q"?M[3]+b:M[1]+b;d(nt(n,s,[n+2/3*(S-n),s+2/3*(P-s),T+2/3*(S-T),x+2/3*(P-x),T,x])),E=[S,P],n=T,s=x;break}case"A":{const S=M[5]+$,P=M[6]+b;let T=n,x=s;for(const C of kn(n,s,M[0],M[1],M[2],M[3],M[4],S,P))d(nt(T,x,C)),T=C[4],x=C[5];n=S,s=P;break}}c=A,a=E}}const f=o.reduce((g,p)=>g+p.length,0),m=[];for(let g=0;g<o.length;){const p=o[g].subpath;let v=g,u=0;for(;v<o.length&&o[v].subpath===p;)u+=o[v++].length;const k=o[g],w=o[v-1],M=h.has(p)||Math.abs(w.endX-k.startX)<1e-9&&Math.abs(w.endY-k.startY)<1e-9;m.push({start:g,end:v,length:u,closed:M}),g=v}const y={segments:o,totalLength:f,subpaths:m};return W.size>=mn&&W.delete(W.keys().next().value),W.set(t,y),y}function q(t){let e=0;for(let o=0;o<t.length;o++){const n=t[o],s=t[(o+1)%t.length];e+=n.x*s.y-s.x*n.y}return e}function ht(t,e){let o=!1;for(let n=0,s=e.length-1;n<e.length;s=n++){const r=e[n],i=e[s];r.y>t.y!=i.y>t.y&&t.x<(i.x-r.x)*(t.y-r.y)/(i.y-r.y)+r.x&&(o=!o)}return o}const et=(t,e,o)=>(e.x-t.x)*(o.y-t.y)-(e.y-t.y)*(o.x-t.x),ut=(t,e)=>t.x===e.x&&t.y===e.y;function dt(t,e,o,n){return et(e,o,t)>=0&&et(o,n,t)>=0&&et(n,e,t)>=0}function xn(t,e){let o=0;for(let f=1;f<e.length;f++)e[f].x>e[o].x&&(o=f);const n=e[o];let s=-1,r=1/0;for(let f=0;f<t.length;f++){const m=t[f],y=t[(f+1)%t.length];if(m.y>n.y==y.y>n.y)continue;const g=m.x+(n.y-m.y)*(y.x-m.x)/(y.y-m.y);g>=n.x&&g<r&&(r=g,s=f)}if(s<0)return t;const i=t[s],c=t[(s+1)%t.length];let a=i.x>c.x?s:(s+1)%t.length;const l={x:r,y:n.y};let h=1/0;for(let f=0;f<t.length;f++){const m=t[f];if(f===a||m.x<n.x)continue;const y=t[a];if(!(dt(m,n,l,y)||dt(m,n,y,l)))continue;const p=Math.abs(Math.atan2(m.y-n.y,m.x-n.x));p<h&&(h=p,a=f)}const d=e.slice(o).concat(e.slice(0,o));return[...t.slice(0,a+1),...d,n,t[a],...t.slice(a+1)]}function Lt(t,e=[]){const o=q(t)>=0?t:[...t].reverse(),n=e.map(d=>q(d)<=0?d:[...d].reverse()),s=[...o,...n.flat()],r=new Map;s.forEach((d,f)=>r.set(d,f));const i=[...n].sort((d,f)=>Math.max(...f.map(m=>m.x))-Math.max(...d.map(m=>m.x)));let c=o;for(const d of i)c=xn(c,d);const a=c.map(d=>r.get(d)),l=[];let h=a.length*a.length;for(;a.length>3&&h-- >0;){let d=!1;for(let f=0;f<a.length;f++){const m=a[(f+a.length-1)%a.length],y=a[f],g=a[(f+1)%a.length],[p,v,u]=[s[m],s[y],s[g]];if(et(p,v,u)<=0)continue;let k=!1;for(const w of a){const M=s[w];if(!(w===m||w===y||w===g||ut(M,p)||ut(M,v)||ut(M,u))&&dt(M,p,v,u)){k=!0;break}}if(!k){l.push(m,y,g),a.splice(f,1),d=!0;break}}d||(l.push(a[a.length-1],a[0],a[1]),a.splice(0,1))}return a.length===3&&l.push(a[0],a[1],a[2]),{points:s,triangles:l}}function $n(t,e){const o=new Map;for(const n of vn(t).segments){o.has(n.subpath)||o.set(n.subpath,[{x:n.startX,y:-n.startY}]);const s=o.get(n.subpath);if(n.type==="L")s.push({x:n.endX,y:-n.endY});else{const[r,i,c,a,l,h]=n.points;for(let d=1;d<=e;d++){const f=d/e,m=1-f,y=m*m*m*n.startX+3*m*m*f*r+3*m*f*f*c+f*f*f*l,g=m*m*m*n.startY+3*m*m*f*i+3*m*f*f*a+f*f*f*h;s.push({x:y,y:-g})}}}return[...o.values()].map(n=>n.filter((s,r)=>r===0||s.x!==n[r-1].x||s.y!==n[r-1].y)).map(n=>n.length>1&&n[0].x===n[n.length-1].x&&n[0].y===n[n.length-1].y?n.slice(0,-1):n).filter(n=>n.length>=3&&Math.abs(q(n))>1e-12)}function Ht(t,e){const o=$n(t,Math.max(1,Math.round(e.curveSegments??12))),n=new H;if(o.length===0)return n.build();const s=o.flat(),r=Math.min(...s.map(p=>p.x)),i=Math.max(...s.map(p=>p.x)),c=Math.min(...s.map(p=>p.y)),a=Math.max(...s.map(p=>p.y)),l=(e.width??1)/Math.max(i-r,1e-9),h=(r+i)/2,d=(c+a)/2,f=o.map(p=>p.map(v=>({x:(v.x-h)*l,y:(v.y-d)*l}))),m=f.map((p,v)=>f.filter((u,k)=>k!==v&&ht(p[0],u)).length),y=e.depth/2,g=-e.depth/2;return f.forEach((p,v)=>{if(m[v]%2===1)return;const u=f.filter((b,A)=>m[A]===m[v]+1&&ht(b[0],p)),{points:k,triangles:w}=Lt(p,u),M=k.map(b=>n.vertex(b.x,b.y,y,0,0,1)),$=k.map(b=>n.vertex(b.x,b.y,g,0,0,-1));for(let b=0;b<w.length;b+=3)n.triangle(M[w[b]],M[w[b+1]],M[w[b+2]]),n.triangle($[w[b]],$[w[b+2]],$[w[b+1]]);for(const b of[q(p)>=0?p:[...p].reverse(),...u.map(A=>q(A)<=0?A:[...A].reverse())])for(let A=0;A<b.length;A++){const E=b[A],S=b[(A+1)%b.length],P=S.y-E.y,T=-(S.x-E.x),x=n.vertex(E.x,E.y,g,P,T,0),C=n.vertex(S.x,S.y,g,P,T,0),D=n.vertex(S.x,S.y,y,P,T,0),j=n.vertex(E.x,E.y,y,P,T,0);n.quad(x,C,D,j)}}),n.build()}const F=Math.PI*2;function Rt([t,e,o]){const n=new H,s=t/2,r=e/2,i=o/2,c=[[[0,0,1],[[-s,-r,i],[s,-r,i],[s,r,i],[-s,r,i]]],[[0,0,-1],[[s,-r,-i],[-s,-r,-i],[-s,r,-i],[s,r,-i]]],[[1,0,0],[[s,-r,i],[s,-r,-i],[s,r,-i],[s,r,i]]],[[-1,0,0],[[-s,-r,-i],[-s,-r,i],[-s,r,i],[-s,r,-i]]],[[0,1,0],[[-s,r,i],[s,r,i],[s,r,-i],[-s,r,-i]]],[[0,-1,0],[[-s,-r,-i],[s,-r,-i],[s,-r,i],[-s,-r,i]]]];for(const[[a,l,h],d]of c){const[f,m,y,g]=d.map(([p,v,u])=>n.vertex(p,v,u,a,l,h));n.quad(f,m,y,g)}return n.build()}function _t([t,e],o=1){const n=new H,s=Math.max(1,Math.round(o)),r=[];for(let i=0;i<=s;i++){const c=e/2-e*i/s;r.push(Array.from({length:s+1},(a,l)=>n.vertex(-t/2+t*l/s,0,c,0,1,0)))}for(let i=0;i<s;i++)for(let c=0;c<s;c++)n.quad(r[i][c],r[i][c+1],r[i+1][c+1],r[i+1][c]);return n.build()}function Ft(t,e=16){const o=new H,n=Math.max(6,Math.round(e)),s=Math.max(3,Math.round(n/2)),r=[];for(let i=0;i<=s;i++){const c=i/s*Math.PI,a=[];for(let l=0;l<=n;l++){const h=l/n*F,d=Math.sin(c)*Math.sin(h),f=Math.cos(c),m=Math.sin(c)*Math.cos(h);a.push(o.vertex(d*t,f*t,m*t,d,f,m))}r.push(a)}for(let i=0;i<s;i++)for(let c=0;c<n;c++){const a=r[i][c],l=r[i+1][c],h=r[i+1][c+1],d=r[i][c+1];i>0&&o.triangle(a,l,d),i<s-1&&o.triangle(l,h,d)}return o.build()}function ft(t,e,o,n,s){const r=t.vertex(0,o,0,0,n,0),i=Array.from({length:s},(c,a)=>{const l=a/s*F;return t.vertex(Math.sin(l)*e,o,Math.cos(l)*e,0,n,0)});for(let c=0;c<s;c++){const a=i[c],l=i[(c+1)%s];n===1?t.triangle(r,a,l):t.triangle(r,l,a)}}function Qt(t,e,o=24){const n=new H,s=Math.max(6,Math.round(o)),r=e/2,i=-e/2,c=h=>Array.from({length:s+1},(d,f)=>{const m=f/s*F;return n.vertex(Math.sin(m)*t,h,Math.cos(m)*t,Math.sin(m),0,Math.cos(m))}),a=c(i),l=c(r);for(let h=0;h<s;h++)n.quad(a[h],a[h+1],l[h+1],l[h]);return ft(n,t,r,1,s),ft(n,t,i,-1,s),n.build()}function qt(t,e,o=24){const n=new H,s=Math.max(6,Math.round(o)),r=e/2,i=-e/2,c=t/e;for(let a=0;a<s;a++){const l=a/s*F,h=(a+1)/s*F,d=(l+h)/2,f=n.vertex(Math.sin(l)*t,i,Math.cos(l)*t,Math.sin(l),c,Math.cos(l)),m=n.vertex(Math.sin(h)*t,i,Math.cos(h)*t,Math.sin(h),c,Math.cos(h)),y=n.vertex(0,r,0,Math.sin(d),c,Math.cos(d));n.triangle(f,m,y)}return ft(n,t,i,-1,s),n.build()}function Bt(t,e,o=24){const n=new H,s=Math.max(6,Math.round(o)),r=Math.max(4,Math.round(s/2)),i=[];for(let c=0;c<=s;c++){const a=c/s*F,l=[];for(let h=0;h<=r;h++){const d=h/r*F,f=Math.cos(d)*Math.sin(a),m=Math.sin(d),y=Math.cos(d)*Math.cos(a),g=t+e*Math.cos(d);l.push(n.vertex(g*Math.sin(a),e*Math.sin(d),g*Math.cos(a),f,m,y))}i.push(l)}for(let c=0;c<s;c++)for(let a=0;a<r;a++)n.quad(i[c][a],i[c+1][a],i[c+1][a+1],i[c][a+1]);return n.build()}function Gt(t){switch(t.type){case"box":return Rt(t.size);case"plane":return _t(t.size,t.segments);case"sphere":return Ft(t.radius,t.segments);case"cylinder":return Qt(t.radius,t.height,t.segments);case"cone":return qt(t.radius,t.height,t.segments);case"torus":return Bt(t.radius,t.tube,t.segments);case"extrude":return Ht(t.path,{depth:t.depth,width:t.width,curveSegments:t.curveSegments});case"mesh":return Vt(t)}}function Vt(t){const e=[...t.positions],o=[...t.indices],n=e.length/3,s=o.length/3;let r;if(t.normals&&t.normals.length===e.length)r=[...t.normals];else{r=new Array(e.length).fill(0);for(let c=0;c<s;c++){const[a,l,h]=[o[c*3],o[c*3+1],o[c*3+2]],d=C=>[e[C*3],e[C*3+1],e[C*3+2]],[f,m,y]=d(a),[g,p,v]=d(l),[u,k,w]=d(h),M=g-f,$=p-m,b=v-y,A=u-f,E=k-m,S=w-y,P=$*S-b*E,T=b*A-M*S,x=M*E-$*A;for(const C of[a,l,h])r[C*3]+=P,r[C*3+1]+=T,r[C*3+2]+=x}for(let c=0;c<n;c++){const a=Math.hypot(r[c*3],r[c*3+1],r[c*3+2])||1;r[c*3]/=a,r[c*3+1]/=a,r[c*3+2]/=a}}let i;if(t.colors&&t.colors.length===s)i=[...t.colors];else if(t.colors&&t.colors.length===n){i=[];for(let c=0;c<s;c++){const a=[0,1,2].map(h=>An(t.colors[o[c*3+h]])),l=[0,1,2].map(h=>Math.round((a[0][h]+a[1][h]+a[2][h])/3));i.push(`#${l.map(h=>h.toString(16).padStart(2,"0")).join("")}`)}}return i?{positions:e,normals:r,indices:o,faceColors:i}:{positions:e,normals:r,indices:o}}function An(t){const e=t.trim().replace("#",""),o=e.length===3?e.split("").map(s=>s+s).join(""):e,n=parseInt(o,16);return Number.isFinite(n)&&o.length===6?[n>>16&255,n>>8&255,n&255]:[0,0,0]}function Wt(t){const e=Array.from({length:t.indices.length/3},()=>[]);for(const o of Yt(t))for(const n of o.faces){const s=o.faces.find(r=>r!==n)??-1;e[n].push({a:o.a,b:o.b,across:s})}return{...t,faceEdges:e}}function In(t,e={}){const o=new Map((e.kinds??[]).map(i=>[i.kind,i])),n=Nt(t);for(const i of t.objects){if(Sn.has(i.kind))continue;const c=o.get(i.kind);c?n.push(...(c.validate?.(i)??[]).map(a=>`"${i.id}": ${a}`)):n.push(`"${i.id}" is a ${i.kind}: load the scene with that kind (for characters: loadScene3D(scene, { kinds: [characterObjects] }), from @algorisys/tinyfly/characters)`)}if(n.length>0)throw new Error(`scene-3d: "${t.id}" is not valid:
2
2
  - ${n.join(`
3
- - `)}`);const e=new Map,c=new Map;for(const o of t.objects){o.kind==="mesh"&&e.set(o.id,Yt(Xt(o.geometry)));const r=i.get(o.kind);r?.prepare&&c.set(o.id,r.prepare(o))}return{scene:t,meshes:e,kinds:i,prepared:c}}const an=new Set(["group","mesh","camera","light","line","trail"]);function ct(t,s){return[t[0]+s[0],t[1]+s[1],t[2]+s[2]]}function L(t,s){return[t[0]-s[0],t[1]-s[1],t[2]-s[2]]}function D(t,s){return[t[0]*s,t[1]*s,t[2]*s]}function O(t,s){return t[0]*s[0]+t[1]*s[1]+t[2]*s[2]}function rt(t,s){return[t[1]*s[2]-t[2]*s[1],t[2]*s[0]-t[0]*s[2],t[0]*s[1]-t[1]*s[0]]}function W(t){return Math.hypot(t[0],t[1],t[2])}function hn(t,s){return W(L(t,s))}function _(t){const s=W(t);return s===0?[0,0,0]:D(t,1/s)}function at(t,s,i){return[t[0]+(s[0]-t[0])*i,t[1]+(s[1]-t[1])*i,t[2]+(s[2]-t[2])*i]}const ln=Math.PI/180;function ht(){return[0,0,0,1]}function lt(t,s){const i=Math.hypot(t[0],t[1],t[2]);if(i===0)return ht();const n=s*ln/2,e=Math.sin(n)/i;return[t[0]*e,t[1]*e,t[2]*e,Math.cos(n)]}function jt(t,s,i){return Nt(Nt(lt([0,1,0],s),lt([1,0,0],t)),lt([0,0,1],i))}function Nt(t,s){const[i,n,e,c]=t,[o,r,a,h]=s;return[c*o+i*h+n*a-e*r,c*r-i*a+n*h+e*o,c*a+i*r-n*o+e*h,c*h-i*o-n*r-e*a]}function dn(t){return Math.hypot(t[0],t[1],t[2],t[3])}function Lt(t){const s=dn(t);return s===0?ht():[t[0]/s,t[1]/s,t[2]/s,t[3]/s]}const un=Math.PI/180;function dt(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function zt(t,s){const i=new Array(16);for(let n=0;n<4;n++)for(let e=0;e<4;e++){let c=0;for(let o=0;o<4;o++)c+=t[o*4+e]*s[n*4+o];i[n*4+e]=c}return i}function fn(t){const[s,i,n,e]=t;return[1-2*(i*i+n*n),2*(s*i+n*e),2*(s*n-i*e),0,2*(s*i-n*e),1-2*(s*s+n*n),2*(i*n+s*e),0,2*(s*n+i*e),2*(i*n-s*e),1-2*(s*s+i*i),0,0,0,0,1]}function pn(t,s,i){const n=fn(s);for(let e=0;e<3;e++)n[e]*=i[0],n[4+e]*=i[1],n[8+e]*=i[2];return n[12]=t[0],n[13]=t[1],n[14]=t[2],n}function gn(t){const s=new Array(16);for(let i=0;i<4;i++)for(let n=0;n<4;n++)s[n*4+i]=t[i*4+n];return s}function Ot(t){const[s,i,n,e,c,o,r,a,h,d,u,f,p,M,g,m]=t,l=s*o-i*c,w=s*r-n*c,A=s*a-e*c,b=i*r-n*o,y=i*a-e*o,x=n*a-e*r,v=h*M-d*p,I=h*g-u*p,E=h*m-f*p,S=d*g-u*M,k=d*m-f*M,P=u*m-f*g,$=l*P-w*k+A*S+b*E-y*I+x*v;if(Math.abs($)<1e-12)return null;const C=1/$;return[(o*P-r*k+a*S)*C,(n*k-i*P-e*S)*C,(M*x-g*y+m*b)*C,(u*y-d*x-f*b)*C,(r*E-c*P-a*I)*C,(s*P-n*E+e*I)*C,(g*A-p*x-m*w)*C,(h*x-u*A+f*w)*C,(c*k-o*E+a*v)*C,(i*E-s*k-e*v)*C,(p*y-M*A+m*l)*C,(d*A-h*y-f*l)*C,(o*I-c*S-r*v)*C,(s*S-i*I+n*v)*C,(M*w-p*b-g*l)*C,(h*b-d*w+u*l)*C]}function Mn(t,s,i,n){const e=1/Math.tan(t*un/2),c=1/(i-n);return[e/s,0,0,0,0,e,0,0,0,0,(n+i)*c,-1,0,0,2*n*i*c,0]}function yn(t,s,i,n,e,c){const o=1/(s-t),r=1/(n-i),a=1/(c-e);return[2*o,0,0,0,0,2*r,0,0,0,0,-2*a,0,-(s+t)*o,-(n+i)*r,-(c+e)*a,1]}function mn(t,s,i=[0,1,0]){const n=_(L(t,s)),e=_(rt(i,n)),c=rt(n,e);return[e[0],c[0],n[0],0,e[1],c[1],n[1],0,e[2],c[2],n[2],0,-O(e,t),-O(c,t),-O(n,t),1]}function Z(t,s){const i=t[0]*s[0]+t[4]*s[1]+t[8]*s[2]+t[12],n=t[1]*s[0]+t[5]*s[1]+t[9]*s[2]+t[13],e=t[2]*s[0]+t[6]*s[1]+t[10]*s[2]+t[14],c=t[3]*s[0]+t[7]*s[1]+t[11]*s[2]+t[15];return c===1||c===0?[i,n,e]:[i/c,n/c,e/c]}function _t(t,s){const i=_(L(s,t)),n=Math.abs(i[1])>.9999?[0,0,-1]:[0,1,0];return mn(t,s,n)}function bn(t,s,i,n){const e=s*Math.PI/180,c=i*Math.PI/180;return[t[0]+n*Math.cos(c)*Math.sin(e),t[1]+n*Math.sin(c),t[2]+n*Math.cos(c)*Math.cos(e)]}function wn(t,s,i){const n=L(t,s),e=W(n);if(e===0)return t;const c=Math.max(.001,e-i);return ct(s,D(n,c/e))}function ut(t,s){if(t.projection==="perspective")return Mn(t.fov,s,t.near,t.far);const i=t.height/2;return yn(-i*s,i*s,-i,i,t.near,t.far)}function vn(t,s,i){const n=Math.max(2,Math.round(i.samples??32)),e=Math.max(0,i.length),c=i.since!==void 0?Math.max(s-e,i.since):s-e;if(c>=s)return[];const o=i.period,r=[];for(let a=0;a<n;a++){const h=c+(s-c)*a/(n-1),d=o&&o>0&&a<n-1?(h%o+o)%o:h;r.push({at:t(d),time:h,age:e>0?(s-h)/e:0})}return r}const xn=2.5;function kn(t){const s=[],i=[],n=t.length,e=(c,o)=>{for(let r=c+o;r>=0&&r<n;r+=o){const a=(t[r].x-t[c].x)*o,h=(t[r].y-t[c].y)*o,d=Math.hypot(a,h);if(d>1e-9)return[a/d,h/d]}return null};for(let c=0;c<n;c++){const o=t[c],r=e(c,-1),a=e(c,1),h=r??a??[1,0],d=a??r??[1,0];let u=h[0]+d[0],f=h[1]+d[1];const p=Math.hypot(u,f);p<1e-9?(u=h[0],f=h[1]):(u/=p,f/=p);const M=u*h[0]+f*h[1],g=Math.min(xn,1/Math.max(M,1e-6)),m=o.width/2*g;s.push({x:o.x-f*m,y:o.y+u*m}),i.push({x:o.x+f*m,y:o.y-u*m})}return{left:s,right:i}}function An(t){const s=t.length;if(s<2)return null;const i=t[s-1];for(let n=s-2;n>=0;n--){const e=i.x-t[n].x,c=i.y-t[n].y,o=Math.hypot(e,c);if(o>1e-9)return{x:i.x,y:i.y,radius:i.width/2,start:Math.atan2(e/o,-c/o)}}return null}const ft=new Map;function H(t){const s=ft.get(t);if(s)return s;let i=[1,1,1];const n=t.trim().replace("#","");if(t.trim().startsWith("#")&&(n.length===3||n.length===6)){const e=n.length===3?n.split("").map(c=>c+c).join(""):n;i=[0,2,4].map(c=>Number.parseInt(e.slice(c,c+2),16)/255)}else{const e=t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);e&&(i=[Number(e[1])/255,Number(e[2])/255,Number(e[3])/255])}return ft.size<512&&ft.set(t,i),i}const $n=[{id:"default-ambient",light:"ambient",color:"#ffffff",intensity:.35,position:[0,0,0],direction:[0,-1,0],angle:30},{id:"default-key",light:"directional",color:"#ffffff",intensity:.8,position:[3,5,4],direction:_([-3,-5,-4]),angle:30}],In=(t,s,i)=>{const n=Math.min(1,Math.max(0,(i-t)/(s-t)));return n*n*(3-2*n)};function pt(t,s,i){const n=[0,0,0];for(const e of i){const c=H(e.color);let o;if(e.light==="ambient")o=e.intensity;else if(e.light==="directional")o=e.intensity*Math.max(0,-O(s,e.direction));else{const r=L(e.position,t),a=W(r),h=a>0?D(r,1/a):s,d=e.range?Math.max(0,1-a/e.range)**2:1;if(o=e.intensity*Math.max(0,O(s,h))*d,e.light==="spot"){const u=Math.cos(e.angle*Math.PI/180),f=Math.cos(e.angle*.8*Math.PI/180);o*=In(u,f,-O(h,e.direction))}}n[0]+=c[0]*o,n[1]+=c[1]*o,n[2]+=c[2]*o}return n}function Sn(t,s){const i=Math.max(2,Math.round(s));return Math.min(1.2,Math.ceil(Math.min(1,t)*i-1e-9)/i)}function gt(t,s){return t?Math.min(1,Math.max(0,(s-t.near)/(t.far-t.near))):0}function qt(t,s,i,n){const e=t.material,c=H(t.color??e.color),o=e.shading??"lambert";let r;if(o==="unlit")r=[...c];else{const d=s.length>0?s:$n;let u;if(o==="lambert"){const f=[0,0,0];for(const p of t.vertexNormals){const M=pt(t.centroid,p,d);f[0]+=M[0]/3,f[1]+=M[1]/3,f[2]+=M[2]/3}u=f}else if(u=pt(t.centroid,t.normal,d),o==="toon"){const f=Math.max(u[0],u[1],u[2]),p=f>0?Sn(f,e.bands??3)/f:0;u=[u[0]*p,u[1]*p,u[2]*p]}r=[c[0]*u[0],c[1]*u[1],c[2]*u[2]]}if(e.emissive){const d=H(e.emissive);r=[r[0]+d[0],r[1]+d[1],r[2]+d[2]]}const a=gt(n,hn(t.centroid,i.position));if(n&&a>0){const d=H(n.color);r=[r[0]+(d[0]-r[0])*a,r[1]+(d[1]-r[1])*a,r[2]+(d[2]-r[2])*a]}const h=d=>Math.round(Math.min(1,Math.max(0,d))*255);return{color:`rgb(${h(r[0])}, ${h(r[1])}, ${h(r[2])})`,alpha:t.opacity}}function Pn(t,s,i,n){const{camera:e}=n,c=e.near,o=t.map(M=>Z(e.view,M)),r=e.projection[5]*n.height/2,a=(M,g)=>i.width*(1-i.taper*M)*r/(e.orthographic?1:Math.max(g,c)),h=H(i.color),d=[];let u=[];const f=M=>-M[2]>=c;for(let M=0;M<o.length;M++){const g=o[M];f(g)?(u.length===0&&M>0&&!f(o[M-1])&&u.push(Dt(o[M-1],g,s[M-1],s[M],c)),u.push({view:g,age:s[M]})):u.length>0&&(u.push(Dt(o[M-1],g,s[M-1],s[M],c)),d.push(u),u=[])}u.length>0&&d.push(u);const p=[];for(const M of d){if(M.length<2)continue;const g=M.map(b=>-b.view[2]),l=M.map(b=>n.toScreen(b.view)).map((b,y)=>({x:b.x,y:b.y,width:a(M[y].age,g[y])})),w=kn(l),A=M[M.length-1].age===0?An(l):null;for(let b=0;b+1<M.length;b++){const y=(g[b]+g[b+1])/2;if(y>e.far)continue;let x=i.opacity*(1-i.fade*((M[b].age+M[b+1].age)/2));const v=at(M[b].view,M[b+1].view,.5),I=gt(n.fog,W(v));let E=h;if(n.fog&&I>0)if(i.additive)x*=1-I;else{const $=H(n.fog.color);E=[h[0]+($[0]-h[0])*I,h[1]+($[1]-h[1])*I,h[2]+($[2]-h[2])*I]}if(x<=0)continue;const S=`rgb(${E.map($=>Math.round(Math.min(1,Math.max(0,$))*255)).join(", ")})`,k=[w.left[b],w.left[b+1],w.right[b+1],w.right[b]],P=b+2===M.length?A:null;p.push({depth:y,draw($){i.additive&&($.globalCompositeOperation="lighter"),$.globalAlpha=Math.min(1,x),$.fillStyle=S,$.beginPath(),$.moveTo(k[0].x,k[0].y),$.lineTo(k[1].x,k[1].y),P&&$.arc(P.x,P.y,P.radius,P.start,P.start-Math.PI,!0),$.lineTo(k[2].x,k[2].y),$.lineTo(k[3].x,k[3].y),$.closePath(),$.fill(),!i.additive&&x>=1&&($.strokeStyle=S,$.lineWidth=.75,$.stroke())}})}}return p}function Dt(t,s,i,n,e){const c=(-e-t[2])/(s[2]-t[2]);return{view:at(t,s,c),age:i+(n-i)*c}}const Tn=Math.cos(30*Math.PI/180),Ht=new Map,Y=t=>typeof t=="number"?t:void 0,tt=(t,s)=>Array.isArray(t)&&t.length===s?t:void 0;function Qt(t,s){const i=t.position??[0,0,0],n=tt(s.get("position"),3)??[Y(s.get("x"))??i[0],Y(s.get("y"))??i[1],Y(s.get("z"))??i[2]];let e;const c=tt(s.get("quaternion"),4),o=["rotateX","rotateY","rotateZ"].map(d=>Y(s.get(d)));if(c)e=Lt(c);else if(o.some(d=>d!==void 0)){const d=t.rotation??[0,0,0];e=jt(o[0]??d[0],o[1]??d[1],o[2]??d[2])}else t.quaternion?e=Lt(t.quaternion):e=t.rotation?jt(...t.rotation):ht();const r=typeof t.scale=="number"?[t.scale,t.scale,t.scale]:t.scale??[1,1,1],a=Y(s.get("scale")),h=[Y(s.get("scaleX"))??a??r[0],Y(s.get("scaleY"))??a??r[1],Y(s.get("scaleZ"))??a??r[2]];return pn(n,e,h)}const Mt=t=>[t[12],t[13],t[14]];function Cn(t,s,i,n){const e=Mt(s),c=tt(i.get("lookAt"),3)??t.lookAt,o=c?_t(e,c):Ot(s)??dt(),r=t.projection==="perspective"?ut({...t,fov:Y(i.get("fov"))??t.fov},n):ut({...t,height:Y(i.get("height"))??t.height},n);return{id:t.id,view:o,projection:r,position:e,forward:_([-o[2],-o[6],-o[10]]),orthographic:t.projection==="orthographic",near:t.near,far:t.far}}function Rt(t){return gn(Ot(t)??dt())}function En(t,s,i,n){return _([t[0]*s+t[4]*i+t[8]*n,t[1]*s+t[5]*i+t[9]*n,t[2]*s+t[6]*i+t[10]*n])}function Xn(t,s){const i=e=>-e[2]>=s,n=[];for(let e=0;e<t.length;e++){const c=t[e],o=t[(e+1)%t.length];if(i(c)&&n.push(c),i(c)!==i(o)){const r=(-s-c[2])/(o[2]-c[2]);n.push(at(c,o,r))}}return n}function yt(t,s=new Map,i){const{scene:n}=t,e=l=>s.get(`${n.id}/${l}`)??Ht,c=new Map,o=new Map;for(const l of n.objects){const w=e(l.id),A=Qt(l,w),b=l.parent?c.get(l.parent):void 0;c.set(l.id,b?zt(b,A):A);const y=Y(w.get("visible"))!==void 0?Y(w.get("visible"))>.5:l.visible!==!1;o.set(l.id,y&&(l.parent?o.get(l.parent)!==!1:!0))}const r=s.get(n.id)?.get("activeCamera"),a=typeof r=="string"&&n.objects.some(l=>l.id===r&&l.kind==="camera")?r:n.camera,h=n.objects.find(l=>l.id===a),d=Cn(h,c.get(a),e(a),i.width/i.height),u=l=>{const w=Z(d.projection,l);return{x:(w[0]+1)/2*i.width,y:(1-w[1])/2*i.height}},f=[];for(const l of n.objects){if(l.kind!=="light"||!o.get(l.id))continue;const w=e(l.id),A=Mt(c.get(l.id)),b=tt(w.get("target"),3)??l.target??[0,0,0],y=w.get("color");f.push({id:l.id,light:l.light,color:typeof y=="string"?y:l.color,intensity:Y(w.get("intensity"))??l.intensity,position:A,direction:_(L(b,A)),range:l.range,angle:l.angle??30})}const p=[],M=[];n.objects.forEach((l,w)=>{if(l.kind!=="mesh"||!o.get(l.id))return;const A=t.meshes.get(l.id),b=n.materials?.[l.material];if(!A||!b)return;const y=e(l.id),x=c.get(l.id),v=Rt(x),I=y.get("color"),E=(Y(y.get("opacity"))??1)*(b.opacity??1);E<=0||(M.push({objectId:l.id,objectIndex:w,mesh:A,world:x,material:b,color:typeof I=="string"?I:void 0,opacity:E}),p.push(...Ft(A,x,v,d,u,b,{objectId:l.id,objectIndex:w,layer:l.layer??0,color:typeof I=="string"?I:void 0,opacity:E})))});const g=[];n.objects.forEach((l,w)=>{const A=t.kinds.get(l.kind);if(!A||!o.get(l.id))return;const b=A.resolve({object:l,prepared:t.prepared.get(l.id),values:e(l.id),world:c.get(l.id),camera:d,lights:f,fog:n.fog,width:i.width,height:i.height,toScreen:u});if(!b)return;const y=l.layer??0;for(const x of b.drawables??[])g.push({...x,objectId:l.id,objectIndex:w,layer:y});for(const x of b.meshes??[])M.push({objectId:l.id,objectIndex:w,mesh:x.mesh,world:x.world,material:x.material,opacity:x.material.opacity??1}),p.push(...Ft(x.mesh,x.world,Rt(x.world),d,u,x.material,{objectId:l.id,objectIndex:w,layer:y,opacity:x.material.opacity??1}))});const m={camera:d,height:i.height,fog:n.fog,toScreen:u};return n.objects.forEach((l,w)=>{if(l.kind!=="line"&&l.kind!=="trail"||!o.get(l.id))return;const A=e(l.id),b=l.kind==="line"?jn(l,c.get(l.id)):Nn(l,n,s,i);if(!b)return;const y=Yn(l,A);if(y.opacity<=0||y.width<=0)return;const x=l.layer??0;for(const v of Pn(b.points,b.ages,y,m))g.push({...v,objectId:l.id,objectIndex:w,layer:x})}),g.sort((l,w)=>l.layer-w.layer||w.depth-l.depth||l.objectIndex-w.objectIndex),p.sort((l,w)=>l.layer-w.layer||w.depth-l.depth||l.objectIndex-w.objectIndex||l.face-w.face||l.part-w.part),{id:n.id,width:i.width,height:i.height,background:n.background,fog:n.fog,camera:d,lights:f,worlds:c,triangles:p,drawables:g,meshes:M,time:i.time??0}}function Yn(t,s){const i=s.get("color"),n=t.kind==="trail";return{color:typeof i=="string"?i:t.color,width:Y(s.get("width"))??t.width??.05,taper:t.taper??(n?1:0),fade:t.fade??(n?1:0),opacity:(Y(s.get("opacity"))??1)*(t.opacity??1),additive:t.blend==="add"}}function jn(t,s){const n=(t.closed?[...t.points,t.points[0]]:t.points).map(e=>Z(s,e));return{points:n,ages:n.map((e,c)=>1-c/(n.length-1))}}function Nn(t,s,i,n){if(!n.valuesAt)return null;const e=n.time??0,c=Y(i.get(`${s.id}/${t.id}`)?.get("length"))??t.length,o=vn(r=>Mt(Ut(s,t.follow,r===e?i:n.valuesAt(r))),e,{length:c,samples:t.samples??32,period:t.period});return o.length>=2?{points:o.map(r=>r.at),ages:o.map(r=>r.age)}:null}function Ut(t,s,i){const n=t.objects.find(c=>c.id===s);if(!n)return dt();const e=Qt(n,i.get(`${t.id}/${s}`)??Ht);return n.parent?zt(Ut(t,n.parent,i),e):e}function Ft(t,s,i,n,e,c,o){const r=t.positions.length/3,a=[],h=[];for(let g=0;g<r;g++){const m=Z(s,[t.positions[g*3],t.positions[g*3+1],t.positions[g*3+2]]);a.push(m),h.push(Z(n.view,m))}const d=t.indices.length/3,u=[],f=[];for(let g=0;g<d;g++){const[m,l,w]=[0,1,2].map(y=>a[t.indices[g*3+y]]),A=_(rt(L(l,m),L(w,m)));u.push(A);const b=n.orthographic?D(n.forward,-1):L(n.position,m);f.push(O(A,b)>0)}const p=g=>-h[g][2]>=n.near,M=[];for(let g=0;g<d;g++){const m=f[g];if(!m&&!c.doubleSided)continue;const l=[t.indices[g*3],t.indices[g*3+1],t.indices[g*3+2]],w=l.map(k=>h[k]);if(w.every(k=>-k[2]>n.far))continue;const A=Xn(w,n.near);if(A.length<3)continue;const b=m?1:-1,y=D(u[g],b),x=l.map(k=>D(En(i,t.normals[k*3],t.normals[k*3+1],t.normals[k*3+2]),b)),v=D(ct(ct(a[l[0]],a[l[1]]),a[l[2]]),1/3),I=-(w[0][2]+w[1][2]+w[2][2])/3,E=[];if(c.outline&&m)for(const k of t.faceEdges[g]){const P=k.across,$=P===-1||!f[P],C=c.creases!==!1&&!$&&g<P&&O(u[g],u[P])<Tn;($||C)&&p(k.a)&&p(k.b)&&E.push([e(h[k.a]),e(h[k.b])])}const S=A.map(e);for(let k=1;k+1<S.length;k++)M.push({objectId:o.objectId,objectIndex:o.objectIndex,layer:o.layer,face:g,part:k-1,screen:[S[0],S[k],S[k+1]],depth:I,centroid:v,normal:y,vertexNormals:x,material:c,color:o.color,opacity:o.opacity,outline:k===1?E:[]})}return M}class Ln{ctx;constructor(s){this.ctx=s}render(s){mt(this.ctx,s)}}function mt(t,s){t.save(),s.background&&s.background!=="transparent"&&(t.fillStyle=s.background,t.fillRect(0,0,s.width,s.height)),t.lineJoin="round",t.lineCap="round";let i=0;const n=(o,r)=>{for(;i<s.drawables.length;){const a=s.drawables[i];if(a.layer>o||a.layer===o&&a.depth<=r)break;t.save(),a.draw(t,s),t.restore(),i++}};let e=[];const c=o=>{if(e.length===0)return;const r=[];for(const a of e)o&&o.objectId===a.objectId&&o.layer===a.layer&&a.depth-o.depth<=zn*a.depth?r.push(a):On(t,a.triangle);e=r};for(const o of s.triangles){c(o),n(o.layer,o.depth);const{color:r,alpha:a}=qt(o,s.lights,s.camera,s.fog),[h,d,u]=o.screen;t.globalAlpha=a,t.beginPath(),t.moveTo(h.x,h.y),t.lineTo(d.x,d.y),t.lineTo(u.x,u.y),t.closePath(),t.fillStyle=r,t.fill(),a>=1&&(t.strokeStyle=r,t.lineWidth=.75,t.stroke()),o.material.outline&&o.outline.length>0&&e.push({objectId:o.objectId,layer:o.layer,depth:o.depth,triangle:o})}c(),n(1/0,-1/0),t.restore()}const zn=.04;function On(t,s){const i=s.material.outline;t.globalAlpha=s.opacity,t.strokeStyle=i.color,t.lineWidth=i.width,t.beginPath();for(const[n,e]of s.outline)t.moveTo(n.x,n.y),t.lineTo(e.x,e.y);t.stroke()}class _n{renderer;width;height;scenes=new Map;values=new Map;valuesAt;constructor(s,i){this.renderer=s,this.width=i.width,this.height=i.height,this.valuesAt=i.valuesAt}registerScene(s){this.scenes.set(s.scene.id,s)}unregisterScene(s){this.scenes.delete(s)}resize(s,i){this.width=s,this.height=i}applyState(s){this.values=s.values,this.time=s.currentTime??this.time}time=0;render(){for(const s of this.scenes.values())this.renderer.render(yt(s,this.values,{width:this.width,height:this.height,time:this.time,valuesAt:this.valuesAt}))}}function qn(t,s,i,n){const e=n.stateAt,c=n.valuesAt??(e&&(o=>e(o).values));mt(t,yt(s,i??new Map,{width:n.width,height:n.height,time:n.time,valuesAt:c}))}T.Canvas2DRenderer=Ln,T.MeshBuilder=z,T.Scene3DAdapter=_n,T.boxMesh=It,T.coneMesh=Ct,T.cylinderMesh=Tt,T.dollyPosition=wn,T.drawResolvedScene=mt,T.drawScene3D=qn,T.extrudeMesh=$t,T.fogAmount=gt,T.geometryMesh=Xt,T.lightAt=pt,T.loadScene3D=rn,T.lookAtView=_t,T.meshEdges=vt,T.orbitPosition=bn,T.parseColor=H,T.planeMesh=St,T.pointInPolygon=et,T.prepareMesh=Yt,T.projectionMatrix=ut,T.resolveScene3D=yt,T.shadeTriangle=qt,T.signedArea=Q,T.sphereMesh=Pt,T.torusMesh=Et,T.triangulate=At,T.validateScene3D=wt,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
3
+ - `)}`);const s=new Map,r=new Map;for(const i of t.objects){i.kind==="mesh"&&s.set(i.id,Wt(Gt(i.geometry)));const c=o.get(i.kind);c?.prepare&&r.set(i.id,c.prepare(i))}return{scene:t,meshes:s,kinds:o,prepared:r}}const Sn=new Set(["group","mesh","camera","light","line","trail"]);function gt(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function L(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]}function Q(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function R(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function pt(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Z(t){return Math.hypot(t[0],t[1],t[2])}function mt(t,e){return Z(L(t,e))}function _(t){const e=Z(t);return e===0?[0,0,0]:Q(t,1/e)}function yt(t,e,o){return[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o,t[2]+(e[2]-t[2])*o]}const Pn=Math.PI/180;function Mt(){return[0,0,0,1]}function ot(t,e){const o=Math.hypot(t[0],t[1],t[2]);if(o===0)return Mt();const n=e*Pn/2,s=Math.sin(n)/o;return[t[0]*s,t[1]*s,t[2]*s,Math.cos(n)]}function Ut(t,e,o){return Zt(Zt(ot([0,1,0],e),ot([1,0,0],t)),ot([0,0,1],o))}function Zt(t,e){const[o,n,s,r]=t,[i,c,a,l]=e;return[r*i+o*l+n*a-s*c,r*c-o*a+n*l+s*i,r*a+o*c-n*i+s*l,r*l-o*i-n*c-s*a]}function Tn(t){return Math.hypot(t[0],t[1],t[2],t[3])}function Jt(t){const e=Tn(t);return e===0?Mt():[t[0]/e,t[1]/e,t[2]/e,t[3]/e]}const Cn=Math.PI/180;function J(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function bt(t,e){const o=new Array(16);for(let n=0;n<4;n++)for(let s=0;s<4;s++){let r=0;for(let i=0;i<4;i++)r+=t[i*4+s]*e[n*4+i];o[n*4+s]=r}return o}function Kt(t){const[e,o,n,s]=t;return[1-2*(o*o+n*n),2*(e*o+n*s),2*(e*n-o*s),0,2*(e*o-n*s),1-2*(e*e+n*n),2*(o*n+e*s),0,2*(e*n+o*s),2*(o*n-e*s),1-2*(e*e+o*o),0,0,0,0,1]}function En(t,e,o){const n=Kt(e);for(let s=0;s<3;s++)n[s]*=o[0],n[4+s]*=o[1],n[8+s]*=o[2];return n[12]=t[0],n[13]=t[1],n[14]=t[2],n}function zn(t){const e=new Array(16);for(let o=0;o<4;o++)for(let n=0;n<4;n++)e[n*4+o]=t[o*4+n];return e}function tn(t){const[e,o,n,s,r,i,c,a,l,h,d,f,m,y,g,p]=t,v=e*i-o*r,u=e*c-n*r,k=e*a-s*r,w=o*c-n*i,M=o*a-s*i,$=n*a-s*c,b=l*y-h*m,A=l*g-d*m,E=l*p-f*m,S=h*g-d*y,P=h*p-f*y,T=d*p-f*g,x=v*T-u*P+k*S+w*E-M*A+$*b;if(Math.abs(x)<1e-12)return null;const C=1/x;return[(i*T-c*P+a*S)*C,(n*P-o*T-s*S)*C,(y*$-g*M+p*w)*C,(d*M-h*$-f*w)*C,(c*E-r*T-a*A)*C,(e*T-n*E+s*A)*C,(g*k-m*$-p*u)*C,(l*$-d*k+f*u)*C,(r*P-i*E+a*b)*C,(o*E-e*P-s*b)*C,(m*M-y*k+p*v)*C,(h*k-l*M-f*v)*C,(i*A-r*S-c*b)*C,(e*S-o*A+n*b)*C,(y*u-m*w-g*v)*C,(l*w-h*u+d*v)*C]}function Xn(t,e,o,n){const s=1/Math.tan(t*Cn/2),r=1/(o-n);return[s/e,0,0,0,0,s,0,0,0,0,(n+o)*r,-1,0,0,2*n*o*r,0]}function On(t,e,o,n,s,r){const i=1/(e-t),c=1/(n-o),a=1/(r-s);return[2*i,0,0,0,0,2*c,0,0,0,0,-2*a,0,-(e+t)*i,-(n+o)*c,-(r+s)*a,1]}function Nn(t,e,o=[0,1,0]){const n=_(L(t,e)),s=_(pt(o,n)),r=pt(n,s);return[s[0],r[0],n[0],0,s[1],r[1],n[1],0,s[2],r[2],n[2],0,-R(s,t),-R(r,t),-R(n,t),1]}function B(t,e){const o=t[0]*e[0]+t[4]*e[1]+t[8]*e[2]+t[12],n=t[1]*e[0]+t[5]*e[1]+t[9]*e[2]+t[13],s=t[2]*e[0]+t[6]*e[1]+t[10]*e[2]+t[14],r=t[3]*e[0]+t[7]*e[1]+t[11]*e[2]+t[15];return r===1||r===0?[o,n,s]:[o/r,n/r,s/r]}function nn(t,e,o={}){const n=_(L(e,t)),s=o.up??(Math.abs(n[1])>.9999?[0,0,-1]:[0,1,0]);return wt(Nn(t,e,s),o.roll??0)}function wt(t,e){return e?bt(Kt(ot([0,0,1],-e)),t):t}function st(t,e,o,n){const s=e*Math.PI/180,r=o*Math.PI/180;return[t[0]+n*Math.cos(r)*Math.sin(s),t[1]+n*Math.sin(r),t[2]+n*Math.cos(r)*Math.cos(s)]}function Yn(t,e,o){const n=L(t,e),s=Z(n);if(s===0)return t;const r=Math.max(.001,s-o);return gt(e,Q(n,r/s))}function kt(t,e){if(t.projection==="perspective")return Xn(t.fov,e,t.near,t.far);const o=t.height/2;return On(-o*e,o*e,-o,o,t.near,t.far)}function jn(t,e,o){const n=Math.max(2,Math.round(o.samples??32)),s=Math.max(0,o.length),r=o.since!==void 0?Math.max(e-s,o.since):e-s;if(r>=e)return[];const i=o.period,c=[];for(let a=0;a<n;a++){const l=r+(e-r)*a/(n-1),h=i&&i>0&&a<n-1?(l%i+i)%i:l;c.push({at:t(h),time:l,age:s>0?(e-l)/s:0})}return c}const Dn=2.5;function Ln(t){const e=[],o=[],n=t.length,s=(r,i)=>{for(let c=r+i;c>=0&&c<n;c+=i){const a=(t[c].x-t[r].x)*i,l=(t[c].y-t[r].y)*i,h=Math.hypot(a,l);if(h>1e-9)return[a/h,l/h]}return null};for(let r=0;r<n;r++){const i=t[r],c=s(r,-1),a=s(r,1),l=c??a??[1,0],h=a??c??[1,0];let d=l[0]+h[0],f=l[1]+h[1];const m=Math.hypot(d,f);m<1e-9?(d=l[0],f=l[1]):(d/=m,f/=m);const y=d*l[0]+f*l[1],g=Math.min(Dn,1/Math.max(y,1e-6)),p=i.width/2*g;e.push({x:i.x-f*p,y:i.y+d*p}),o.push({x:i.x+f*p,y:i.y-d*p})}return{left:e,right:o}}function Hn(t){const e=t.length;if(e<2)return null;const o=t[e-1];for(let n=e-2;n>=0;n--){const s=o.x-t[n].x,r=o.y-t[n].y,i=Math.hypot(s,r);if(i>1e-9)return{x:o.x,y:o.y,radius:o.width/2,start:Math.atan2(s/i,-r/i)}}return null}const vt=new Map;function Y(t){const e=vt.get(t);if(e)return e;let o=[1,1,1];const n=t.trim().replace("#","");if(t.trim().startsWith("#")&&(n.length===3||n.length===6)){const s=n.length===3?n.split("").map(r=>r+r).join(""):n;o=[0,2,4].map(r=>Number.parseInt(s.slice(r,r+2),16)/255)}else{const s=t.match(/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);s&&(o=[Number(s[1])/255,Number(s[2])/255,Number(s[3])/255])}return vt.size<512&&vt.set(t,o),o}const Rn=[{id:"default-ambient",light:"ambient",color:"#ffffff",intensity:.35,position:[0,0,0],direction:[0,-1,0],angle:30},{id:"default-key",light:"directional",color:"#ffffff",intensity:.8,position:[3,5,4],direction:_([-3,-5,-4]),angle:30}],_n=(t,e,o)=>{const n=Math.min(1,Math.max(0,(o-t)/(e-t)));return n*n*(3-2*n)};function xt(t,e,o){const n=[0,0,0];for(const s of o){const r=Y(s.color);let i;if(s.light==="ambient")i=s.intensity;else if(s.light==="directional")i=s.intensity*Math.max(0,-R(e,s.direction));else{const c=L(s.position,t),a=Z(c),l=a>0?Q(c,1/a):e,h=s.range?Math.max(0,1-a/s.range)**2:1;if(i=s.intensity*Math.max(0,R(e,l))*h,s.light==="spot"){const d=Math.cos(s.angle*Math.PI/180),f=Math.cos(s.angle*.8*Math.PI/180);i*=_n(d,f,-R(l,s.direction))}}n[0]+=r[0]*i,n[1]+=r[1]*i,n[2]+=r[2]*i}return n}function Fn(t,e){const o=Math.max(2,Math.round(e));return Math.min(1.2,Math.ceil(Math.min(1,t)*o-1e-9)/o)}function it(t,e){return t?Math.min(1,Math.max(0,(e-t.near)/(t.far-t.near))):0}function $t(t,e,o){const n=it(e,o);if(!e||n<=0)return t;const s=Y(t),r=Y(e.color),i=c=>Math.round(Math.min(1,Math.max(0,c))*255);return`rgb(${i(s[0]+(r[0]-s[0])*n)}, ${i(s[1]+(r[1]-s[1])*n)}, ${i(s[2]+(r[2]-s[2])*n)})`}function At(t,e,o,n){const s=t.material,r=Y(t.color??s.color),i=s.shading??"lambert";let c;if(i==="unlit")c=[...r];else{const h=e.length>0?e:Rn;let d;if(i==="lambert"){const f=[0,0,0];for(const m of t.vertexNormals){const y=xt(t.centroid,m,h);f[0]+=y[0]/3,f[1]+=y[1]/3,f[2]+=y[2]/3}d=f}else if(d=xt(t.centroid,t.normal,h),i==="toon"){const f=Math.max(d[0],d[1],d[2]),m=f>0?Fn(f,s.bands??3)/f:0;d=[d[0]*m,d[1]*m,d[2]*m]}c=[r[0]*d[0],r[1]*d[1],r[2]*d[2]]}if(s.emissive){const h=Y(s.emissive);c=[c[0]+h[0],c[1]+h[1],c[2]+h[2]]}const a=it(n,mt(t.centroid,o.position));if(n&&a>0){const h=Y(n.color);c=[c[0]+(h[0]-c[0])*a,c[1]+(h[1]-c[1])*a,c[2]+(h[2]-c[2])*a]}const l=h=>Math.round(Math.min(1,Math.max(0,h))*255);return{color:`rgb(${l(c[0])}, ${l(c[1])}, ${l(c[2])})`,alpha:t.opacity}}function Qn(t,e,o,n){const{camera:s}=n,r=s.near,i=t.map(y=>B(s.view,y)),c=s.projection[5]*n.height/2,a=(y,g)=>o.width*(1-o.taper*y)*c/(s.orthographic?1:Math.max(g,r)),l=Y(o.color),h=[];let d=[];const f=y=>-y[2]>=r;for(let y=0;y<i.length;y++){const g=i[y];f(g)?(d.length===0&&y>0&&!f(i[y-1])&&d.push(en(i[y-1],g,e[y-1],e[y],r)),d.push({view:g,age:e[y]})):d.length>0&&(d.push(en(i[y-1],g,e[y-1],e[y],r)),h.push(d),d=[])}d.length>0&&h.push(d);const m=[];for(const y of h){if(y.length<2)continue;const g=y.map(w=>-w.view[2]),v=y.map(w=>n.toScreen(w.view)).map((w,M)=>({x:w.x,y:w.y,width:a(y[M].age,g[M])})),u=Ln(v),k=y[y.length-1].age===0?Hn(v):null;for(let w=0;w+1<y.length;w++){const M=(g[w]+g[w+1])/2;if(M>s.far)continue;let $=o.opacity*(1-o.fade*((y[w].age+y[w+1].age)/2));const b=yt(y[w].view,y[w+1].view,.5),A=it(n.fog,Z(b));let E=l;if(n.fog&&A>0)if(o.additive)$*=1-A;else{const x=Y(n.fog.color);E=[l[0]+(x[0]-l[0])*A,l[1]+(x[1]-l[1])*A,l[2]+(x[2]-l[2])*A]}if($<=0)continue;const S=`rgb(${E.map(x=>Math.round(Math.min(1,Math.max(0,x))*255)).join(", ")})`,P=[u.left[w],u.left[w+1],u.right[w+1],u.right[w]],T=w+2===y.length?k:null;m.push({depth:M,draw(x){o.additive&&(x.globalCompositeOperation="lighter"),x.globalAlpha=Math.min(1,$),x.fillStyle=S,x.beginPath(),x.moveTo(P[0].x,P[0].y),x.lineTo(P[1].x,P[1].y),T&&x.arc(T.x,T.y,T.radius,T.start,T.start-Math.PI,!0),x.lineTo(P[2].x,P[2].y),x.lineTo(P[3].x,P[3].y),x.closePath(),x.fill(),!o.additive&&$>=1&&(x.strokeStyle=S,x.lineWidth=.75,x.stroke())}})}}return m}function en(t,e,o,n,s){const r=(-s-t[2])/(e[2]-t[2]);return{view:yt(t,e,r),age:o+(n-o)*r}}const qn=Math.cos(30*Math.PI/180),on=new Map,z=t=>typeof t=="number"?t:void 0,rt=(t,e)=>Array.isArray(t)&&t.length===e?t:void 0;function sn(t,e){const o=t.position??[0,0,0],n=rt(e.get("position"),3)??[z(e.get("x"))??o[0],z(e.get("y"))??o[1],z(e.get("z"))??o[2]];let s;const r=rt(e.get("quaternion"),4),i=["rotateX","rotateY","rotateZ"].map(h=>z(e.get(h)));if(r)s=Jt(r);else if(i.some(h=>h!==void 0)){const h=t.rotation??[0,0,0];s=Ut(i[0]??h[0],i[1]??h[1],i[2]??h[2])}else t.quaternion?s=Jt(t.quaternion):s=t.rotation?Ut(...t.rotation):Mt();const c=typeof t.scale=="number"?[t.scale,t.scale,t.scale]:t.scale??[1,1,1],a=z(e.get("scale")),l=[z(e.get("scaleX"))??a??c[0],z(e.get("scaleY"))??a??c[1],z(e.get("scaleZ"))??a??c[2]];return En(n,s,l)}const It=t=>[t[12],t[13],t[14]];function Bn(t,e,o,n){const s=It(e),r=rt(o.get("lookAt"),3)??t.lookAt,i=z(o.get("roll"))??t.roll??0,c=r?nn(s,r,{up:t.up,roll:i}):wt(tn(e)??J(),i),a=t.projection==="perspective"?kt({...t,fov:z(o.get("fov"))??t.fov},n):kt({...t,height:z(o.get("height"))??t.height},n);return{id:t.id,view:c,projection:a,position:s,forward:_([-c[2],-c[6],-c[10]]),orthographic:t.projection==="orthographic",near:t.near,far:t.far}}function rn(t){return zn(tn(t)??J())}function Gn(t,e,o,n){return _([t[0]*e+t[4]*o+t[8]*n,t[1]*e+t[5]*o+t[9]*n,t[2]*e+t[6]*o+t[10]*n])}function Vn(t,e){const o=s=>-s[2]>=e,n=[];for(let s=0;s<t.length;s++){const r=t[s],i=t[(s+1)%t.length];if(o(r)&&n.push(r),o(r)!==o(i)){const c=(-e-r[2])/(i[2]-r[2]);n.push(yt(r,i,c))}}return n}function Wn(t,e,o,n=16){const s=[t[0],t[1],t[2]],r=[0,1,0],i=[];for(let a=0;a<n;a++){const l=a/n*Math.PI*2;s.push(t[0]+Math.cos(l)*e,t[1],t[2]+Math.sin(l)*o),r.push(0,1,0)}for(let a=0;a<n;a++)i.push(0,1+(a+1)%n,1+a);const c=Array.from({length:n},()=>[]);return{positions:s,normals:r,indices:i,faceEdges:c}}function Un(t,e){const o=z(e.get("outlineWidth"))??t.outline?.width,n=e.get("outlineColor"),s=(typeof n=="string"?n:void 0)??t.outline?.color??"#000000";return o!==void 0&&o>0?{width:o,color:s}:void 0}function Zn(t,e){return!t||t.to<=t.from?1:Math.min(1,Math.max(0,(e-t.from)/(t.to-t.from)))}function St(t,e=new Map,o){const{scene:n}=t,s=u=>e.get(`${n.id}/${u}`)??on,r=o.nearFade??n.nearFade,i=new Map,c=new Map;for(const u of n.objects){const k=s(u.id),w=sn(u,k),M=u.parent?i.get(u.parent):void 0;i.set(u.id,M?bt(M,w):w);const $=z(k.get("visible"))!==void 0?z(k.get("visible"))>.5:u.visible!==!1;c.set(u.id,$&&(u.parent?c.get(u.parent)!==!1:!0))}const a=e.get(n.id)?.get("activeCamera"),l=typeof a=="string"&&n.objects.some(u=>u.id===a&&u.kind==="camera")?a:n.camera,h=n.objects.find(u=>u.id===l),d=Bn(h,i.get(l),s(l),o.width/o.height),f=u=>{const k=B(d.projection,u);return{x:(k[0]+1)/2*o.width,y:(1-k[1])/2*o.height}},m=[];for(const u of n.objects){if(u.kind!=="light"||!c.get(u.id))continue;const k=s(u.id),w=It(i.get(u.id)),M=rt(k.get("target"),3)??u.target??[0,0,0],$=k.get("color");m.push({id:u.id,light:u.light,color:typeof $=="string"?$:u.color,intensity:z(k.get("intensity"))??u.intensity,position:w,direction:_(L(M,w)),range:u.range,angle:u.angle??30})}const y=[],g=[];n.objects.forEach((u,k)=>{if(u.kind!=="mesh"||!c.get(u.id))return;const w=t.meshes.get(u.id),M=n.materials?.[u.material];if(!w||!M)return;const $=s(u.id),b=i.get(u.id),A=rn(b),E=$.get("color"),S=(z($.get("opacity"))??1)*(M.opacity??1);if(S<=0)return;const P=Un(M,$),T=P===M.outline||P&&M.outline&&P.width===M.outline.width&&P.color===M.outline.color?M:{...M,outline:P};g.push({objectId:u.id,objectIndex:k,mesh:w,world:b,material:T,color:typeof E=="string"?E:void 0,opacity:S}),y.push(...Pt(w,b,A,d,f,T,{objectId:u.id,objectIndex:k,layer:u.layer??0,color:typeof E=="string"?E:void 0,opacity:S,ink:P,nearFade:r}))}),n.objects.forEach((u,k)=>{if(u.kind!=="mesh"||!u.shadow||!c.get(u.id))return;const w=t.meshes.get(u.id);if(!w)return;const M=s(u.id);if((z(M.get("opacity"))??1)<=0)return;const $=i.get(u.id),b=u.shadow===!0?{}:u.shadow,A=b.ground??n.ground??0;let E=1/0,S=-1/0,P=1/0,T=1/0,x=-1/0;for(let O=0;O<w.positions.length;O+=3){const N=B($,[w.positions[O],w.positions[O+1],w.positions[O+2]]);E=Math.min(E,N[0]),S=Math.max(S,N[0]),P=Math.min(P,N[1]),T=Math.min(T,N[2]),x=Math.max(x,N[2])}const C=Math.max(S-E,x-T);if(!(C>0))return;const D=Math.max(0,P-A),j=Math.min(1,D/(2*C)),G=(b.opacity??.22)*(1-j*.8);if(G<=.01)return;const K=1.1+j*.4,at=Wn([(E+S)/2,A+.002,(T+x)/2],(S-E)/2*K,(x-T)/2*K),X={color:"#000000",shading:"unlit",opacity:G};y.push(...Pt(at,J(),J(),d,f,X,{objectId:`${u.id}:shadow`,objectIndex:k-.5,layer:u.layer??0,opacity:G,nearFade:r}))});const p=[];n.objects.forEach((u,k)=>{const w=t.kinds.get(u.kind);if(!w||!c.get(u.id))return;const M=w.resolve({object:u,prepared:t.prepared.get(u.id),values:s(u.id),world:i.get(u.id),camera:d,lights:m,fog:n.fog,width:o.width,height:o.height,toScreen:f});if(!M)return;const $=u.layer??0;for(const b of M.drawables??[])p.push({...b,objectId:u.id,objectIndex:k,layer:$});for(const b of M.meshes??[])g.push({objectId:u.id,objectIndex:k,mesh:b.mesh,world:b.world,material:b.material,opacity:b.material.opacity??1}),y.push(...Pt(b.mesh,b.world,rn(b.world),d,f,b.material,{objectId:u.id,objectIndex:k,layer:$,opacity:b.material.opacity??1,ink:b.material.outline,nearFade:r}))});const v={camera:d,height:o.height,fog:n.fog,toScreen:f};return n.objects.forEach((u,k)=>{if(u.kind!=="line"&&u.kind!=="trail"||!c.get(u.id))return;const w=s(u.id),M=u.kind==="line"?Kn(u,i.get(u.id)):te(u,n,e,o);if(!M)return;const $=Jn(u,w);if($.opacity<=0||$.width<=0)return;const b=u.layer??0;for(const A of Qn(M.points,M.ages,$,v))p.push({...A,objectId:u.id,objectIndex:k,layer:b})}),p.sort((u,k)=>u.layer-k.layer||k.depth-u.depth||u.objectIndex-k.objectIndex),y.sort((u,k)=>u.layer-k.layer||k.depth-u.depth||u.objectIndex-k.objectIndex||u.face-k.face||u.part-k.part),{id:n.id,width:o.width,height:o.height,background:n.background,fog:n.fog,camera:d,lights:m,worlds:i,triangles:y,drawables:p,meshes:g,time:o.time??0}}function Jn(t,e){const o=e.get("color"),n=t.kind==="trail";return{color:typeof o=="string"?o:t.color,width:z(e.get("width"))??t.width??.05,taper:t.taper??(n?1:0),fade:t.fade??(n?1:0),opacity:(z(e.get("opacity"))??1)*(t.opacity??1),additive:t.blend==="add"}}function Kn(t,e){const n=(t.closed?[...t.points,t.points[0]]:t.points).map(s=>B(e,s));return{points:n,ages:n.map((s,r)=>1-r/(n.length-1))}}function te(t,e,o,n){if(!n.valuesAt)return null;const s=n.time??0,r=z(o.get(`${e.id}/${t.id}`)?.get("length"))??t.length,i=jn(c=>It(cn(e,t.follow,c===s?o:n.valuesAt(c))),s,{length:r,samples:t.samples??32,period:t.period??n.period});return i.length>=2?{points:i.map(c=>c.at),ages:i.map(c=>c.age)}:null}function cn(t,e,o){const n=t.objects.find(r=>r.id===e);if(!n)return J();const s=sn(n,o.get(`${t.id}/${e}`)??on);return n.parent?bt(cn(t,n.parent,o),s):s}function Pt(t,e,o,n,s,r,i){const c=t.positions.length/3,a=[],l=[];for(let g=0;g<c;g++){const p=B(e,[t.positions[g*3],t.positions[g*3+1],t.positions[g*3+2]]);a.push(p),l.push(B(n.view,p))}const h=t.indices.length/3,d=[],f=[];for(let g=0;g<h;g++){const[p,v,u]=[0,1,2].map(M=>a[t.indices[g*3+M]]),k=_(pt(L(v,p),L(u,p)));d.push(k);const w=n.orthographic?Q(n.forward,-1):L(n.position,p);f.push(R(k,w)>0)}const m=g=>-l[g][2]>=n.near,y=[];for(let g=0;g<h;g++){const p=f[g];if(!p&&!r.doubleSided)continue;const v=[t.indices[g*3],t.indices[g*3+1],t.indices[g*3+2]],u=v.map(x=>l[x]);if(u.every(x=>-x[2]>n.far))continue;const k=Vn(u,n.near);if(k.length<3)continue;const w=p?1:-1,M=Q(d[g],w),$=v.map(x=>Q(Gn(o,t.normals[x*3],t.normals[x*3+1],t.normals[x*3+2]),w)),b=Q(gt(gt(a[v[0]],a[v[1]]),a[v[2]]),1/3),A=-(u[0][2]+u[1][2]+u[2][2])/3,E=[],S=[];if(i.ink&&p)for(const x of t.faceEdges[g]){const C=x.across,D=C===-1||!f[C],j=r.creases!==!1&&!D&&g<C&&R(d[g],d[C])<qn;(D||j)&&m(x.a)&&m(x.b)&&(E.push([s(l[x.a]),s(l[x.b])]),S.push([-l[x.a][2],-l[x.b][2]]))}const P=i.opacity*Zn(i.nearFade,A);if(P<=0)continue;const T=k.map(s);for(let x=1;x+1<T.length;x++)y.push({objectId:i.objectId,objectIndex:i.objectIndex,layer:i.layer,face:g,part:x-1,screen:[T[0],T[x],T[x+1]],depth:A,depths:[-k[0][2],-k[x][2],-k[x+1][2]],centroid:b,normal:M,vertexNormals:$,material:r,color:i.color??t.faceColors?.[g],opacity:P,outline:x===1?E:[],outlineDepths:x===1?S:[],ink:i.ink})}return y}class ne{ctx;constructor(e){this.ctx=e}render(e){Tt(this.ctx,e)}}function Tt(t,e){if(t.save(),e.background&&e.background!=="transparent"){if(typeof e.background=="string")t.fillStyle=e.background;else{const i=t.createLinearGradient(0,0,0,e.height);i.addColorStop(0,e.background.top),i.addColorStop(1,e.background.bottom),t.fillStyle=i}t.fillRect(0,0,e.width,e.height)}t.lineJoin="round",t.lineCap="round";let o=0;const n=(i,c)=>{for(;o<e.drawables.length;){const a=e.drawables[o];if(a.layer>i||a.layer===i&&a.depth<=c)break;t.save(),a.draw(t,e),t.restore(),o++}};let s=[];const r=i=>{if(s.length===0)return;const c=[];for(const a of s)i&&i.objectId===a.objectId&&i.layer===a.layer&&a.depth-i.depth<=ee*a.depth?c.push(a):oe(t,a.triangle,e);s=c};for(const i of e.triangles){r(i),n(i.layer,i.depth);const{color:c,alpha:a}=At(i,e.lights,e.camera,e.fog),[l,h,d]=i.screen;t.globalAlpha=a,t.beginPath(),t.moveTo(l.x,l.y),t.lineTo(h.x,h.y),t.lineTo(d.x,d.y),t.closePath(),t.fillStyle=c,t.fill(),a>=1&&(t.strokeStyle=c,t.lineWidth=.75,t.stroke()),i.ink&&i.outline.length>0&&s.push({objectId:i.objectId,layer:i.layer,depth:i.depth,triangle:i})}r(),n(1/0,-1/0),t.restore()}const ee=.04;function oe(t,e,o){const n=e.ink;t.globalAlpha=e.opacity,t.strokeStyle=$t(n.color,o.fog,mt(e.centroid,o.camera.position)),t.lineWidth=n.width,t.beginPath();for(const[s,r]of e.outline)t.moveTo(s.x,s.y),t.lineTo(r.x,r.y);t.stroke()}function an(t,e={}){const o=t.width,n=t.height,s=new Uint8ClampedArray(o*n*4),r=new Float32Array(o*n).fill(1/0);if(e.under&&e.under.length===s.length)s.set(e.under);else if(t.background&&t.background!=="transparent"){const h=Y(typeof t.background=="string"?t.background:t.background.top),d=Y(typeof t.background=="string"?t.background:t.background.bottom);for(let f=0;f<n;f++){const m=n>1?f/(n-1):0,y=Math.round((h[0]+(d[0]-h[0])*m)*255),g=Math.round((h[1]+(d[1]-h[1])*m)*255),p=Math.round((h[2]+(d[2]-h[2])*m)*255);for(let v=0;v<o;v++){const u=f*o+v;s[u*4]=y,s[u*4+1]=g,s[u*4+2]=p,s[u*4+3]=255}}}const i={width:o,height:n,data:s,depth:r};let c=-1/0;const a=[],l=()=>{for(const h of a)ln(i,t,h,!1);a.length=0};for(const h of t.triangles)h.layer!==c&&(l(),c=h.layer,r.fill(1/0)),h.opacity<1?a.push(h):ln(i,t,h,!0);return l(),i}function ln(t,e,o,n){const{color:s,alpha:r}=At(o,e.lights,e.camera,e.fog),i=Y(s).map(c=>Math.round(c*255));if(ie(t,o.screen,o.depths,i,r,n),o.ink&&o.outline.length>0){const c=Y($t(o.ink.color,e.fog,mt(o.centroid,e.camera.position))).map(a=>Math.round(a*255));o.outline.forEach((a,l)=>{const h=o.outlineDepths[l]??[o.depth,o.depth];re(t,a[0],a[1],h,o.ink.width,c,r)})}}function hn(t,e,o,n){const s=e*4;if(n>=1){t[s]=o[0],t[s+1]=o[1],t[s+2]=o[2],t[s+3]=255;return}const r=t[s+3]/255,i=n+r*(1-n);if(!(i<=0)){for(let c=0;c<3;c++)t[s+c]=Math.round((o[c]*n+t[s+c]*r*(1-n))/i);t[s+3]=Math.round(i*255)}}const se=.004;function ie(t,e,o,n,s,r){const[i,c,a]=e,l=(c.x-i.x)*(a.y-i.y)-(c.y-i.y)*(a.x-i.x);if(l===0)return;const h=Math.max(0,Math.floor(Math.min(i.x,c.x,a.x))),d=Math.min(t.width-1,Math.ceil(Math.max(i.x,c.x,a.x))),f=Math.max(0,Math.floor(Math.min(i.y,c.y,a.y))),m=Math.min(t.height-1,Math.ceil(Math.max(i.y,c.y,a.y)));if(h>d||f>m)return;const y=[1/Math.max(1e-9,o[0]),1/Math.max(1e-9,o[1]),1/Math.max(1e-9,o[2])],g=l>0?1:-1;for(let p=f;p<=m;p++){const v=p+.5;for(let u=h;u<=d;u++){const k=u+.5,w=((c.x-k)*(a.y-v)-(c.y-v)*(a.x-k))*g,M=((a.x-k)*(i.y-v)-(a.y-v)*(i.x-k))*g,$=((i.x-k)*(c.y-v)-(i.y-v)*(c.x-k))*g;if(w<0||M<0||$<0)continue;const A=(w+M+$)/(w*y[0]+M*y[1]+$*y[2]),E=p*t.width+u;A>=t.depth[E]||(hn(t.data,E,n,s),r&&(t.depth[E]=A))}}}function re(t,e,o,n,s,r,i){const c=Math.max(.5,s/2),a=Math.max(0,Math.floor(Math.min(e.x,o.x)-c)),l=Math.min(t.width-1,Math.ceil(Math.max(e.x,o.x)+c)),h=Math.max(0,Math.floor(Math.min(e.y,o.y)-c)),d=Math.min(t.height-1,Math.ceil(Math.max(e.y,o.y)+c)),f=o.x-e.x,m=o.y-e.y,y=f*f+m*m,g=c*c;for(let p=h;p<=d;p++){const v=p+.5;for(let u=a;u<=l;u++){const k=u+.5,w=y>0?Math.min(1,Math.max(0,((k-e.x)*f+(v-e.y)*m)/y)):0,M=e.x+f*w,$=e.y+m*w;if((k-M)**2+(v-$)**2>g)continue;const b=(n[0]+(n[1]-n[0])*w)*(1-se),A=p*t.width+u;b>t.depth[A]||hn(t.data,A,r,i)}}}function Ct(t,e){const n=!e.background||e.background==="transparent"?t.getImageData(0,0,e.width,e.height).data:void 0,s=an(e,{under:n}),r=t.createImageData(e.width,e.height);r.data.set(s.data),t.putImageData(r,0,0),t.save(),t.lineJoin="round",t.lineCap="round";for(const i of e.drawables)t.save(),i.draw(t,e),t.restore();t.restore()}class ce{ctx;constructor(e){this.ctx=e}render(e){Ct(this.ctx,e)}}class ae{renderer;width;height;scenes=new Map;values=new Map;valuesAt;constructor(e,o){this.renderer=e,this.width=o.width,this.height=o.height,this.valuesAt=o.valuesAt}registerScene(e){this.scenes.set(e.scene.id,e)}unregisterScene(e){this.scenes.delete(e)}resize(e,o){this.width=e,this.height=o}applyState(e){this.values=e.values,this.time=e.currentTime??this.time}time=0;render(){for(const e of this.scenes.values())this.renderer.render(St(e,this.values,{width:this.width,height:this.height,time:this.time,valuesAt:this.valuesAt}))}}function le(t,e,o,n){const s=n.stateAt,r=n.valuesAt??(s&&(c=>s(c).values)),i=St(e,o??new Map,{width:n.width,height:n.height,time:n.time,period:n.period,valuesAt:r});n.depthBuffer?Ct(t,i):Tt(t,i)}function he(t={}){const e=t.id??"penrose",o=t.length??4,n=t.thickness??.8,s=t.material??"penrose",[r,i,c]=t.position??[0,0,0],a=n/2,l=(y,g,p)=>({id:`${e}-${y}`,kind:"mesh",geometry:{type:"box",size:[p[0]-g[0],p[1]-g[1],p[2]-g[2]]},material:s,position:[r+(g[0]+p[0])/2,i+(g[1]+p[1])/2,c+(g[2]+p[2])/2]}),h=[l("x",[-a,-a,-a],[o-a,a,a]),l("y",[o-a,-a,-a],[o+a,o-a,a]),l("z",[o-a,o-a,-a],[o+a,o+a,o])],d=[r+2*o/3,i+o/3,c+o/3],f=(t.distance??20)/Math.sqrt(3),m={id:`${e}-camera`,kind:"camera",projection:"orthographic",height:o*1.6,near:.1,far:(t.distance??20)*3,position:[d[0]+f,d[1]+f,d[2]+f],lookAt:d};return{objects:h,camera:m}}function ue(t){return typeof t=="object"&&t!==null&&t.type==="cubic-bezier"}function de(t){return typeof t=="object"&&t!==null&&t.type!=="cubic-bezier"}const Et=t=>t,fe=t=>t*t,ge=t=>1-(1-t)*(1-t),pe=t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,un=t=>t*t*t,dn=t=>1-Math.pow(1-t,3),fn=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,me={linear:Et,"ease-in":un,"ease-out":dn,"ease-in-out":fn,"ease-in-quad":fe,"ease-out-quad":ge,"ease-in-out-quad":pe,"ease-in-cubic":un,"ease-out-cubic":dn,"ease-in-out-cubic":fn};function ye(t){const[e,o,n,s]=t,r=3*e,i=3*(n-e)-r,c=1-r-i,a=3*o,l=3*(s-o)-a,h=1-a-l,d=g=>((c*g+i)*g+r)*g,f=g=>((h*g+l)*g+a)*g,m=g=>(3*c*g+2*i)*g+r,y=g=>{let p=g;for(let k=0;k<8;k++){const w=d(p)-g;if(Math.abs(w)<1e-7)return p;const M=m(p);if(Math.abs(M)<1e-7)break;p-=w/M}let v=0,u=1;for(p=g;v<u;){const k=d(p);if(Math.abs(k-g)<1e-7)return p;g>k?v=p:u=p,p=(v+u)/2}return p};return g=>{if(g<=0)return 0;if(g>=1)return 1;const p=y(g);return f(p)}}function zt(t,e="out"){if(e==="out")return t;const o=n=>1-t(1-n);return e==="in"?o:n=>n<.5?o(n*2)/2:t(n*2-1)/2+.5}function Me(t=1,e=.3){const o=Math.max(1,t),n=e/(2*Math.PI)*Math.asin(1/o);return s=>s<=0?0:s>=1?1:o*Math.pow(2,-10*s)*Math.sin((s-n)*(2*Math.PI)/e)+1}const be=t=>{if(t<=0)return 0;if(t>=1)return 1;if(t<1/2.75)return 7.5625*t*t;if(t<2/2.75){const s=t-.5454545454545454;return 7.5625*s*s+.75}if(t<2.5/2.75){const s=t-.8181818181818182;return 7.5625*s*s+.9375}const n=t-2.625/2.75;return 7.5625*n*n+.984375};function we(t=1.70158){return e=>{if(e<=0)return 0;if(e>=1)return 1;const o=e-1;return o*o*((t+1)*o+t)+1}}function ke(t,e="end"){const o=Math.max(1,Math.floor(t));return n=>{if(n>=1)return 1;if(n<=0)return e==="start"||e==="both"?e==="start"?1/o:1/(o+1):0;const s=Math.floor(n*o);switch(e){case"start":return Math.min(1,(s+1)/o);case"both":return(s+1)/(o+1);case"none":return o===1?0:Math.min(1,s/(o-1));default:return s/o}}}function ve(t){switch(t.type){case"steps":return ke(t.count,t.position);case"elastic":return zt(Me(t.amplitude,t.period),t.mode);case"bounce":return zt(be,t.mode);case"back":return zt(we(t.overshoot),t.mode)}}function xe(t){return t===void 0?Et:ue(t)?ye(t.points):de(t)?ve(t):me[t]??Et}function $e(t){let e=2166136261;for(let o=0;o<t.length;o++)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return e>>>0}function Ae(t,e,o=1){if(!(e>0))return 0;const n=t*o/e;return n-Math.floor(n)}function Ie(t,e){const o=Se(e.seed),n=Math.max(1,Math.round(e.cycles??1)),s=(Ae(t,e.period,1)+(e.phase??0))*Math.PI*2,r=n/Math.PI;return Pe([Math.cos(s)*r+7.31,Math.sin(s)*r+3.17],o,e.octaves)}const Se=t=>typeof t=="string"?$e(t):(t??0)>>>0;function Pe(t,e,o){const n=Math.max(1,Math.min(6,Math.round(o)));let s=0,r=1,i=0;for(let c=0;c<n;c++){const a=2**c;s+=r*Te(t.map(l=>l*a),e+c*1013),i+=r,r*=.5}return s/i}function Te(t,e){const o=t.length,n=t.map(Math.floor),r=t.map((c,a)=>c-n[a]).map(c=>c*c*(3-2*c));let i=0;for(let c=0;c<1<<o;c++){let a=1;const l=[];for(let h=0;h<o;h++){const d=c>>h&1;a*=d?r[h]:1-r[h],l.push(n[h]+d)}a!==0&&(i+=a*Ce(l,e))}return i}function Ce(t,e){let o=(e^2654435769)>>>0;for(const n of t)o=Math.imul(o^(n|0),2246822507)>>>0,o=(o^o>>>13)>>>0,o=Math.imul(o,3266489909)>>>0,o=(o^o>>>16)>>>0;return o/4294967296*2-1}function Ee(t,e){let o;for(const n of[...t].sort((s,r)=>s.start-r.start))n.start<=e&&(o=n);return o}function ze(t){const e=[],o=[...t].sort((s,r)=>s.start-r.start),n=new Set;return o.forEach((s,r)=>{n.has(s.id)&&e.push(`two shots share the id "${s.id}"`),n.add(s.id),s.end>s.start||e.push(`shot "${s.id}" ends before it starts`),r>0&&s.start<o[r-1].end&&e.push(`shot "${s.id}" starts before "${o[r-1].id}" ends`),s.transition&&r===0&&e.push(`shot "${s.id}" is first: nothing to transition from`),s.transition&&s.transition.duration>s.end-s.start&&e.push(`shot "${s.id}": its transition is longer than the shot`)}),e}function Xe(t,e){const o=[...t].sort((s,r)=>s.start-r.start);if(o.length===0)return[];const n=o.map(s=>({time:s.start,value:s.camera}));return[{id:`${e}-shots`,target:e,property:"activeCamera",keyframes:n}]}function Oe(t){return[...t].sort((e,o)=>e.start-o.start).map(e=>({id:e.id,time:e.start,label:e.label??e.id}))}function Ne(t,e){const o=[...t].sort((n,s)=>n.start-s.start);for(let n=1;n<o.length;n++){const s=o[n],r=s.transition;if(!(!r||r.kind==="cut"||!(r.duration>0))&&e>=s.start&&e<s.start+r.duration)return{kind:r.kind,progress:(e-s.start)/r.duration,from:o[n-1],to:s,direction:r.direction??"left",color:r.color??"#000000"}}}function Ye(t,e){const o=6e4/e.bpm,n=r=>e.offset+Math.round((r-e.offset)/o)*o,s=[...t].sort((r,i)=>r.start-i.start).map(r=>({...r}));for(let r=1;r<s.length;r++){const i=Math.max(s[r-1].start+1,n(s[r].start));s[r-1].end=i,s[r].start=i}return s}function je(t,e,o){const n=new Map(t??[]),s=new Map(n.get(e)??[]);return s.set("activeCamera",o),n.set(e,s),n}const Xt=(t,e,o)=>[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o,t[2]+(e[2]-t[2])*o];function gn(t,e,o){const n={target:[0,0,0],yaw:0,pitch:15,distance:8,...t},s={...n,...e},r=Xt(n.target,s.target,o),i=n.position||s.position?Xt(n.position??st(n.target,n.yaw,n.pitch,n.distance),s.position??st(s.target,s.yaw,s.pitch,s.distance),o):st(r,n.yaw+(s.yaw-n.yaw)*o,n.pitch+(s.pitch-n.pitch)*o,n.distance+(s.distance-n.distance)*o),c=Xt(n.lookAt??n.target,s.lookAt??s.target,o),a=n.fov!==void 0||s.fov!==void 0?(n.fov??s.fov)+((s.fov??n.fov)-(n.fov??s.fov))*o:void 0;return{position:i,lookAt:c,fov:a}}function De(t){const e=Math.max(1,t.every??33),o=xe(t.easing??"ease-in-out"),n=`${t.scene}/${t.camera}`,s=[],r=[],i=[];for(let a=t.start;;a=Math.min(t.end,a+e)){const l=t.end>t.start?o((a-t.start)/(t.end-t.start)):1,h=gn(t.from,t.to,l);if(s.push({time:a,value:h.position}),r.push({time:a,value:h.lookAt}),h.fov!==void 0&&i.push({time:a,value:h.fov}),a>=t.end)break}const c=[{id:`${n}-move-position`,target:n,property:"position",keyframes:s},{id:`${n}-move-lookAt`,target:n,property:"lookAt",keyframes:r}];return i.length>0&&c.push({id:`${n}-move-fov`,target:n,property:"fov",keyframes:i}),c}function Le(t){const e=Math.max(1,t.every??33),o=t.offset??[0,2,6],n=t.lag??0,s=`${t.scene}/${t.camera}`,r=[],i=[];for(let c=t.start;;c=Math.min(t.end,c+e)){const a=t.subjectAt(c),l=t.subjectAt(Math.max(t.start,c-n));if(r.push({time:c,value:[l[0]+o[0],l[1]+o[1],l[2]+o[2]]}),i.push({time:c,value:a}),c>=t.end)break}return[{id:`${s}-follow-position`,target:s,property:"position",keyframes:r},{id:`${s}-follow-lookAt`,target:s,property:"lookAt",keyframes:i}]}function He(t,e){const o=`${e.scene}/${e.camera}`,n=e.amount??.04,s=e.aim??.08,r=e.rate??1.2,i=Math.max(1,e.every??33),c=e.end-e.start,a=Math.max(1,c),l=Math.max(1,Math.round(a/1e3*r)),h=typeof e.seed=="string"?e.seed:`handheld-${e.seed??0}`,d=(u,k)=>Ie(u-e.start,{period:a,seed:`${h}-${k}`,cycles:l,octaves:2}),f=t.filter(u=>u.target===o),m=t.filter(u=>u.target!==o),y=(u,k,w)=>{const M=f.find(b=>b.property===u),$=[];if(M)for(const b of M.keyframes){const A=b.value;$.push({time:b.time,value:[A[0]+d(b.time,`${u}x`)*k,A[1]+d(b.time,`${u}y`)*k,A[2]+d(b.time,`${u}z`)*k*.5],easing:b.easing})}else if(w)for(let b=e.start;$.push({time:b,value:[w[0]+d(b,`${u}x`)*k,w[1]+d(b,`${u}y`)*k,w[2]+d(b,`${u}z`)*k*.5]}),!(b>=e.end);b=Math.min(e.end,b+i));else return;return{id:M?.id??`${o}-handheld-${u}`,target:o,property:u,keyframes:$}},g=[...m,...f.filter(u=>u.property!=="position"&&u.property!=="lookAt")],p=y("position",n,e.base?.position),v=y("lookAt",s,e.base?.lookAt);return p&&g.push(p),v&&g.push(v),g}const ct={day:{lights:[{id:"key",kind:"light",light:"directional",color:"#fff6e0",intensity:.95,position:[4,8,3]},{id:"fill",kind:"light",light:"directional",color:"#cfe3ff",intensity:.3,position:[-5,3,-2]},{id:"sky",kind:"light",light:"ambient",color:"#bcd4ea",intensity:.4}],background:{top:"#5aa9e6",bottom:"#dff1ff"},fog:{color:"#dff1ff",near:14,far:40}},dusk:{lights:[{id:"key",kind:"light",light:"directional",color:"#ffb067",intensity:.8,position:[6,2.5,2]},{id:"fill",kind:"light",light:"directional",color:"#7b6bd6",intensity:.25,position:[-4,3,-3]},{id:"sky",kind:"light",light:"ambient",color:"#b58ab3",intensity:.3}],background:{top:"#4a3a7a",bottom:"#ff9a62"},fog:{color:"#d9826f",near:10,far:30}},night:{lights:[{id:"key",kind:"light",light:"directional",color:"#9db7ff",intensity:.35,position:[-3,7,2]},{id:"fill",kind:"light",light:"directional",color:"#3b4a7a",intensity:.12,position:[4,2,-3]},{id:"sky",kind:"light",light:"ambient",color:"#243357",intensity:.25}],background:{top:"#060a1c",bottom:"#1b2650"},fog:{color:"#101a3a",near:6,far:22}},stage:{lights:[{id:"key",kind:"light",light:"directional",color:"#ffffff",intensity:.15,position:[2,6,4]},{id:"fill",kind:"light",light:"directional",color:"#402040",intensity:.08,position:[-4,3,-2]},{id:"sky",kind:"light",light:"ambient",color:"#1a1020",intensity:.2},{id:"spot",kind:"light",light:"spot",color:"#ffe9b0",intensity:1.1,position:[0,7,2],target:[0,0,0],angle:22,range:16}],background:{top:"#05030a",bottom:"#120a1c"},fog:{color:"#0a0612",near:8,far:24}}};function Re(t,e={}){const o=ct[t];if(!o)throw new Error(`lightingPreset: unknown mood "${t}" (day, dusk, night, stage)`);const n=e.prefix?`${e.prefix}-`:"";return{objects:o.lights.map(s=>({...s,id:`${n}${s.id}`,position:s.position?[...s.position]:void 0,target:s.target?[...s.target]:void 0})),background:{...o.background},fog:{...o.fog}}}function _e(t,e,o){const n=ct[t],s=ct[e];if(!n||!s)throw new Error(`lightingTracks: unknown mood "${n?e:t}" (day, dusk, night, stage)`);const r=o.prefix?`${o.prefix}-`:"",i=new Set([...n.lights.map(a=>a.id),...s.lights.map(a=>a.id)]),c=[];for(const a of i){const l=n.lights.find(v=>v.id===a),h=s.lights.find(v=>v.id===a),d=`${o.scene}/${r}${a}`,f=(v,u,k)=>{const w=[{time:o.start,value:u},{time:o.end,value:k,easing:o.easing??"ease-in-out"}];c.push({id:`${d}-${v}`,target:d,property:v,keyframes:w})};f("intensity",l?.intensity??0,h?.intensity??0),f("color",l?.color??h.color,h?.color??l.color);const m=l?.position??h?.position,y=h?.position??l?.position;m&&y&&f("position",[...m],[...y]);const g=l?.target??h?.target,p=h?.target??l?.target;g&&p&&f("target",[...g],[...p])}return c}function Fe(t={}){const e=t.id??"ground",o=t.size??24;return{objects:[{id:e,kind:"mesh",layer:-1,geometry:{type:"plane",size:[o,o],segments:t.segments??24},material:e,position:[0,t.y??0,0]}],materials:{[e]:{color:t.color??"#3b4252",shading:"flat"}}}}I.Canvas2DRenderer=ne,I.LIGHTING_PRESETS=ct,I.MeshBuilder=H,I.Scene3DAdapter=ae,I.SoftwareRenderer=ce,I.boxMesh=Rt,I.cameraFollowTracks=Le,I.cameraHandheldTracks=He,I.cameraMoveTracks=De,I.cameraPoseAt=gn,I.checkShots=ze,I.coneMesh=qt,I.cylinderMesh=Qt,I.dollyPosition=Yn,I.drawResolvedScene=Tt,I.drawResolvedSceneWithDepth=Ct,I.drawScene3D=le,I.extrudeMesh=Ht,I.fogAmount=it,I.geometryMesh=Gt,I.ground=Fe,I.inkColor=$t,I.lightAt=xt,I.lightingPreset=Re,I.lightingTracks=_e,I.loadScene3D=In,I.lookAtView=nn,I.meshEdges=Yt,I.orbitPosition=st,I.parseColor=Y,I.penroseTriangle3D=he,I.planeMesh=_t,I.pointInPolygon=ht,I.prepareMesh=Wt,I.projectionMatrix=kt,I.rasterizeResolvedScene=an,I.rawMesh=Vt,I.resolveScene3D=St,I.rollView=wt,I.shadeTriangle=At,I.shotAt=Ee,I.shotMarkers=Oe,I.shotTracks=Xe,I.signedArea=q,I.snapShotsToBeats=Ye,I.sphereMesh=Ft,I.torusMesh=Bt,I.transitionAt=Ne,I.triangulate=Lt,I.validateScene3D=Nt,I.withActiveCamera=je,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});