@fleox/agent3d 0.4.0 → 0.5.2

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 (101) hide show
  1. package/README.md +45 -14
  2. package/changelog.json +24 -0
  3. package/dist/agent/agent3d.mjs +779 -85
  4. package/dist/agent/chunks/{assets-YBkgdfgy.mjs → assets-DdzHgVcn.mjs} +2 -2
  5. package/dist/agent/chunks/{browser-Dil7VM5m.mjs → browser-nFaRUETt.mjs} +1 -1
  6. package/dist/agent/chunks/{cdp-DLEis_Z3.mjs → cdp-6vF_gP-H.mjs} +1 -1
  7. package/dist/agent/chunks/{check-DP9fRYbK.mjs → check-E7GdPxTt.mjs} +14 -2
  8. package/dist/agent/chunks/{depth-CD_ql3QJ.mjs → depth-Bf7cHwod.mjs} +4 -4
  9. package/dist/agent/chunks/{depth-BZT4gseQ.mjs → depth-DEaogEAi.mjs} +4 -114
  10. package/dist/agent/chunks/{export-CEX5DFLo.mjs → export-BSOqVfPT.mjs} +8 -4
  11. package/dist/agent/chunks/{imageCodec-DeGfmBp3.mjs → imageCodec-DXxqkEQA.mjs} +53 -4
  12. package/dist/agent/chunks/{objects-DuytRxiC.mjs → objects-DvzrcVmK.mjs} +2 -2
  13. package/dist/agent/chunks/{optimizeSizing-B-BBiUkD.mjs → optimizeSizing-Dd8vaSnE.mjs} +24 -1
  14. package/dist/agent/chunks/{package-DjRnLzcU.mjs → package-Bn7PKfXn.mjs} +1 -1
  15. package/dist/agent/chunks/photoPlacement-D-k3mD0T.mjs +138 -0
  16. package/dist/agent/chunks/plate-Cwl35I2T.mjs +604 -0
  17. package/dist/agent/chunks/pngEncode-BMc3U9QC.mjs +119 -0
  18. package/dist/agent/chunks/{render-B05DU4Q5.mjs → render-CCKciCgu.mjs} +76 -11
  19. package/dist/agent/chunks/{scene-DWgXH6As.mjs → scene-DSjsun-3.mjs} +22 -5
  20. package/dist/agent/chunks/{server-Dt_YFvN7.mjs → server-CLvLORgA.mjs} +1 -1
  21. package/dist/agent/chunks/{tools-CZyIc4zw.mjs → tools-Vs74Xopx.mjs} +142 -13
  22. package/dist/runtime/agent3d-photo.js +51 -10
  23. package/dist/runtime/agent3d-runtime.js +23 -23
  24. package/dist/runtime/agent3d-runtime.single.js +405 -134
  25. package/dist/runtime/chunks/photo-Dq-AKlfw.js +526 -0
  26. package/dist/studio/assets/BufferGeometryUtils-BbzK4rCj.js +1 -0
  27. package/dist/studio/assets/{EXRLoader-BKkzlNd8.js → EXRLoader-CuDOo1xG.js} +1 -1
  28. package/dist/studio/assets/{FontLoader-Bzjx8mXt.js → FontLoader-DlBfss5q.js} +1 -1
  29. package/dist/studio/assets/{GLTFLoader-1Zd9N406.js → GLTFLoader-bl1eymL4.js} +1 -1
  30. package/dist/studio/assets/{GroundedSkybox-BEMqNCBD.js → GroundedSkybox-cLn9JVlt.js} +1 -1
  31. package/dist/studio/assets/{HDRLoader-DxB0kxPH.js → HDRLoader-8EiZoQQP.js} +1 -1
  32. package/dist/studio/assets/{OrbitControls-MlE9XiCg.js → OrbitControls-1xEm394I.js} +1 -1
  33. package/dist/studio/assets/{RectAreaLightUniformsLib-ClHrtYY6.js → RectAreaLightUniformsLib-S0AelTmO.js} +1 -1
  34. package/dist/studio/assets/{RoomEnvironment-MJ-jIEC8.js → RoomEnvironment-v4QurKxu.js} +1 -1
  35. package/dist/studio/assets/{SVGLoader-CIYl0nEy.js → SVGLoader-KDBVv02P.js} +1 -1
  36. package/dist/studio/assets/{Sky-DNMfpp92.js → Sky-D8Lp9Zh3.js} +1 -1
  37. package/dist/studio/assets/assets-DICv7P37.js +2 -0
  38. package/dist/studio/assets/camera-HsMeC1mn.js +2 -0
  39. package/dist/studio/assets/catalog-DDg904x2.js +1 -0
  40. package/dist/studio/assets/{editor-DzyukvQl.js → editor-BZLIZJC8.js} +1 -1
  41. package/dist/studio/assets/{extrude-9bG8hr2C.js → extrude-BpJda0hq.js} +1 -1
  42. package/dist/studio/assets/game-DnnuBk26.js +19 -0
  43. package/dist/studio/assets/{generators-BuVeRXnC.js → generators-C4n9MsXd.js} +1 -1
  44. package/dist/studio/assets/index-D-TPNQMQ.css +1 -0
  45. package/dist/studio/assets/index-cDbmaVDl.js +479 -0
  46. package/dist/studio/assets/model-CkPfLOl0.js +2 -0
  47. package/dist/studio/assets/params-BZqUA__U.js +1 -0
  48. package/dist/studio/assets/photo-CPGGCRa-.js +526 -0
  49. package/dist/studio/assets/{physicsHost-z9qn_mpg.js → physicsHost-EkPuIy04.js} +1 -1
  50. package/dist/studio/assets/{postfx-B3jDEaEK.js → postfx-Dp7mgfGJ.js} +2 -2
  51. package/dist/studio/assets/rolldown-runtime-4tVxZq34.js +1 -0
  52. package/dist/studio/assets/runtime-ByR4qfyV.js +572 -0
  53. package/dist/studio/assets/{shaders-bFhELLmD.js → shaders-DoRMwJE_.js} +1 -1
  54. package/dist/studio/assets/svg-n3rkKAm5.js +2 -0
  55. package/dist/studio/assets/text-BkPPDghK.js +3 -0
  56. package/dist/studio/assets/three.module-B9FlcKtd.js +4225 -0
  57. package/dist/studio/index.html +5 -3
  58. package/package.json +1 -1
  59. package/plugin/.claude-plugin/plugin.json +1 -1
  60. package/plugin/skills/agent3d-assets/SKILL.md +42 -27
  61. package/plugin/skills/agent3d-create/SKILL.md +77 -29
  62. package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
  63. package/plugin/skills/agent3d-create/references/recipes.md +6 -6
  64. package/plugin/skills/agent3d-edit/SKILL.md +22 -22
  65. package/plugin/skills/agent3d-edit/references/patch-ops.md +3 -3
  66. package/plugin/skills/agent3d-game/SKILL.md +7 -7
  67. package/plugin/skills/agent3d-publish/SKILL.md +30 -23
  68. package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
  69. package/templates/hero-scroll-story/README.md +1 -1
  70. package/templates/photo-scroll-story/README.md +29 -0
  71. package/templates/photo-scroll-story/agent3d.json +8 -0
  72. package/templates/photo-scroll-story/assets/depth/lake-depth.png +0 -0
  73. package/templates/photo-scroll-story/assets/depth/street-depth.png +0 -0
  74. package/templates/photo-scroll-story/assets/manifest.json +46 -0
  75. package/templates/photo-scroll-story/assets/textures/lake.webp +0 -0
  76. package/templates/photo-scroll-story/assets/textures/street.webp +0 -0
  77. package/templates/photo-scroll-story/preview.png +0 -0
  78. package/templates/photo-scroll-story/scene.json +112 -0
  79. package/templates/photo-scroll-story/template.json +8 -0
  80. package/templates/photo-title-inside/README.md +31 -0
  81. package/templates/photo-title-inside/agent3d.json +8 -0
  82. package/templates/photo-title-inside/assets/depth/street-depth.png +0 -0
  83. package/templates/photo-title-inside/assets/manifest.json +25 -0
  84. package/templates/photo-title-inside/assets/textures/street.webp +0 -0
  85. package/templates/photo-title-inside/preview.png +0 -0
  86. package/templates/photo-title-inside/scene.json +80 -0
  87. package/templates/photo-title-inside/template.json +8 -0
  88. package/dist/runtime/chunks/photo-w6dwHX7j.js +0 -255
  89. package/dist/studio/assets/BufferGeometryUtils-CAlXAboW.js +0 -1
  90. package/dist/studio/assets/assets--ehPZf8R.js +0 -1
  91. package/dist/studio/assets/camera-C0sxfRxy.js +0 -2
  92. package/dist/studio/assets/game-DNpTN_Ga.js +0 -19
  93. package/dist/studio/assets/index-BQT0otii.css +0 -1
  94. package/dist/studio/assets/index-C2nMYSoW.js +0 -479
  95. package/dist/studio/assets/model-DQgOrTs4.js +0 -2
  96. package/dist/studio/assets/params-D-Ul6GSt.js +0 -1
  97. package/dist/studio/assets/photo-Dx2IBJ11.js +0 -255
  98. package/dist/studio/assets/runtime-rd9RW3WH.js +0 -572
  99. package/dist/studio/assets/svg-BkV9LeqP.js +0 -2
  100. package/dist/studio/assets/text-Dp8gdjSA.js +0 -3
  101. package/dist/studio/assets/three.module-CnI50X0U.js +0 -4225
@@ -0,0 +1,526 @@
1
+ import{Dt as e,H as t,Mn as n,Nn as r,Pn as i,Rt as a,_t as o,b as s,bt as c,d as l,dn as u,en as d,m as f,ot as p,p as m,rn as ee,st as te,vt as ne,yt as h}from"./three.module-DnaBiDAJ.js";import{r as re}from"./assets-kC2Z1Xy_.js";import{n as g,r as _,t as ie}from"./num-CQNAlL82.js";function v(e,t){return Math.min(1,Math.max(0,e))*t*.25}var y={width:4,strength:.5,focus:.5,segments:256,layers:6,edgeCut:.08,speed:1,smoothing:.9};function ae(e,t,n){let r=t>0&&n>0?t/n:1,i=typeof e.width==`number`&&e.width>0?e.width:void 0,a=typeof e.height==`number`&&e.height>0?e.height:void 0;if(i!==void 0&&a!==void 0)return{width:i,height:a};if(a!==void 0)return{width:a*r,height:a};let o=i??y.width;return{width:o,height:o/r}}var b=[`zoom`,`dolly`,`pan`,`rise`,`vertigo`],x=[`pan`,`rise`];function S(e,t){let n=g(t,0,1),r=2*Math.PI*n;switch(e??`sway`){case`sway`:return{x:.9*Math.sin(r),y:.35*Math.sin(2*r),zoom:0};case`orbit`:return{x:.8*Math.sin(r),y:.8*Math.cos(r),zoom:0};case`zoom`:return{x:0,y:0,zoom:n};case`dolly`:return{x:0,y:.12*n,zoom:1.1*n,push:.12*n};case`pan`:return{x:.85*(2*n-1),y:0,zoom:.15,push:.03};case`rise`:return{x:0,y:.8*(2*n-1),zoom:.2+.25*n,push:.03+.03*n};case`vertigo`:return{x:0,y:0,zoom:0,push:.03*n,vertigo:n};default:return{x:0,y:0,zoom:0}}}function C(e,t,n,r={}){let i=e??`sway`;if(i===`none`)return{x:0,y:0,zoom:0};let a=Math.max(0,t);if(r.loop===!1){let e=r.duration&&r.duration>0?r.duration:a>0?10/a:0,t=e>0?g(n/e,0,1):0;return S(i,.5-.5*Math.cos(Math.PI*t))}let o=2*Math.PI*a/10*n;if(i===`orbit`){let e=Math.min(1,o/Math.PI),t=.8*e*e*(3-2*e);return{x:t*Math.sin(o),y:t*Math.cos(o),zoom:0}}return b.includes(i)?S(i,x.includes(i)?.5+.5*Math.sin(o):.5-.5*Math.cos(o)):S(i,o/(2*Math.PI)%1)}function oe(e){let t=g(_(e?.pointer,1),0,1);return{pointer:t,scroll:g(_(e?.scroll,0),0,1),gyro:typeof e?.gyro==`boolean`?e.gyro:t>0,auto:e?.auto??`sway`,speed:Math.max(0,_(e?.speed,y.speed)),smoothing:g(_(e?.smoothing,y.smoothing),0,.99),loop:e?.loop!==!1,duration:Math.max(0,_(e?.duration,0)),progress:typeof e?.progress==`number`&&Number.isFinite(e.progress)?g(e.progress,0,1):null}}function w(e,t){let n=t.progress??e.progress,r=n!==null,i=t.reduced?{x:0,y:0,zoom:0}:r?S(e.auto,n):C(e.auto,e.speed,t.t,e),a=e.pointer*(t.reduced?.5:1),o=0,s=0,c=0;t.gyro&&e.gyro&&t.pointer.weight<.5?(o=t.gyro.x,s=t.gyro.y,c=+(a>0)):a>0&&(o=t.pointer.x,s=t.pointer.y,c=g(t.pointer.weight,0,1));let l=i.x*(1-c)+o*a*c,u=i.y*(1-c)+s*a*c;e.scroll>0&&(u+=(g(t.scroll,0,1)*2-1)*e.scroll);let d=r?1:1-c,f={x:g(l,-1,1),y:g(u,-1,1),zoom:i.zoom*d};return i.push&&(f.push=i.push*d),i.vertigo&&(f.vertigo=i.vertigo*d),f}var se=1.5;function ce(e,t){let n=e.zoom-se*(e.vertigo??0),r=(1-.06*e.zoom)/((1+(e.push??0))*(1-.06*n));return{zoom:n,inset:[t[0]*r,t[1]*r]}}function T(e,t,n,r){if(r<=0||n<=0)return n<=0&&r>0?e:t;let i=1-g(r,0,.99)**(n*60),a=e+(t-e)*i;return Math.abs(t-a)<1e-4?t:a}function E(e,t,n){let r=g(e,0,1),i=Math.min(t,n),a=i/t,o=i/n;return{maxOffset:[r*.06*a,r*.06*o],inset:[1/(1+r*.1*a),1/(1+r*.1*o)]}}function D(e,t,n,r){let i=t-n.gamma,a=e-n.beta,o=(Math.round(r/90)%4+4)%4;return o===1?[i,a]=[a,-i]:o===2?[i,a]=[-i,-a]:o===3&&([i,a]=[-a,i]),{x:g(i/20,-1,1),y:g(-a/20,-1,1)}}function le(e,t){return Math.max(8,Math.round((e===`low`?12:e===`medium`?20:e===`ultra`?48:32)*(.5+.5*Math.min(1,Math.max(0,t)/.6))))}function ue(e,t){let{live:n}=t,r={x:0,y:0,weight:0,init:!1},i=null,a=null,o=null;if(n&&e.gyro&&e.pointer>0&&!t.flat&&typeof window<`u`&&typeof window.addEventListener==`function`){let e=e=>{if(e.beta===null||e.gamma===null)return;a??={beta:e.beta,gamma:e.gamma};let t=typeof screen<`u`&&screen.orientation?.angle||0;i=D(e.beta,e.gamma,a,t)};window.addEventListener(`deviceorientation`,e),o=()=>window.removeEventListener(`deviceorientation`,e)}return{offset(t,a,o){let s=o.pointer,c=s.inside?g(s.x,-1,1):0,l=s.inside?g(s.y,-1,1):0,u=+!!s.inside;return!n||!r.init?(r.x=c,r.y=l,r.weight=u,r.init=n):(r.x=T(r.x,c,a,e.smoothing),r.y=T(r.y,l,a,e.smoothing),r.weight=T(r.weight,u,a,e.smoothing)),w(e,{t,pointer:r,gyro:n?i:null,scroll:o.scroll,reduced:o.reduced,progress:o.progress})},dispose(){o?.(),o=null}}}var O=`
2
+ uniform sampler2D uMap;
3
+ uniform vec3 uTint;
4
+ uniform float uOpacity;
5
+ uniform float uIntensity;
6
+ vec4 shade(vec4 c, float a) {
7
+ return vec4(c.rgb * uTint * uIntensity, c.a * a * uOpacity);
8
+ }
9
+ `,k=`
10
+ uniform sampler2D uDepth;
11
+ uniform sampler2D uPlate;
12
+ uniform sampler2D uPlateDepth;
13
+ uniform float uPlateOn;
14
+ uniform vec2 uView;
15
+ uniform float uZoom;
16
+ uniform vec2 uMaxOffset;
17
+ uniform vec2 uInset;
18
+ uniform float uFocus;
19
+ uniform float uWallSlope;
20
+ const int STEPS = __STEPS__;
21
+ vec2 pxUv;
22
+ // Depth-map value of the texel parallaxTexel() returned (read by occluding
23
+ // photos to write their true depth, ./photo.ts PHOTO_OCCLUDE).
24
+ float photoHitDepth = 0.0;
25
+ vec4 parallaxTexel(vec2 vUv) {
26
+ // the zoom drift also pushes in slightly (stays inside the inset margin)
27
+ vec2 base = 0.5 + (vUv - 0.5) * uInset * (1.0 - 0.06 * uZoom);
28
+ vec2 v = uView - (vUv - 0.5) * 2.0 * uZoom;
29
+ vec2 dir = v * uMaxOffset;
30
+ vec2 uv = base;
31
+ bool onPlate = false;
32
+ if (dot(dir, dir) > 1e-10) {
33
+ float stepH = 1.0 / float(STEPS);
34
+ float h = 1.0;
35
+ float prevH = 1.0 + stepH;
36
+ bool hit = false;
37
+ for (int i = 0; i <= STEPS; i++) {
38
+ h = 1.0 - float(i) * stepH;
39
+ float d = textureLod(uDepth, base + (h - uFocus) * dir, 0.0).r;
40
+ if (d >= h) { hit = true; break; }
41
+ prevH = h;
42
+ }
43
+ float lo = h, hi = min(prevH, 1.0);
44
+ if (hit) {
45
+ for (int j = 0; j < 6; j++) {
46
+ float mid = 0.5 * (lo + hi);
47
+ float d = textureLod(uDepth, base + (mid - uFocus) * dir, 0.0).r;
48
+ if (d >= mid) lo = mid; else hi = mid;
49
+ }
50
+ }
51
+ uv = base + (lo - uFocus) * dir;
52
+ // Disocclusion: the ray hit the steep "wall" of a depth edge. Stretching
53
+ // the foreground edge colour reads as a smear: take the colour from just
54
+ // past the edge on the far side instead (the background continues).
55
+ vec2 texel = 1.0 / vec2(textureSize(uDepth, 0));
56
+ vec4 dh = textureLod(uDepth, uv, 0.0);
57
+ vec2 grad = vec2(
58
+ textureLod(uDepth, uv + vec2(texel.x * 1.5, 0.0), 0.0).r - textureLod(uDepth, uv - vec2(texel.x * 1.5, 0.0), 0.0).r,
59
+ textureLod(uDepth, uv + vec2(0.0, texel.y * 1.5), 0.0).r - textureLod(uDepth, uv - vec2(0.0, texel.y * 1.5), 0.0).r) / 3.0;
60
+ float g = length(grad);
61
+ vec2 toNear = grad / max(g, 1e-6);
62
+ float dNear = textureLod(uDepth, uv + toNear * texel * 3.0, 0.0).r;
63
+ if (hit && (g > uWallSlope || dh.a < 0.5) && dNear > lo + 0.04 && uPlateOn > 0.5) {
64
+ // continue the march below the wall against the plate (background) depth
65
+ float ph = lo, pprev = lo;
66
+ bool phit = false;
67
+ for (int i = 0; i <= STEPS; i++) {
68
+ ph = lo - float(i) * stepH;
69
+ if (textureLod(uPlateDepth, base + (ph - uFocus) * dir, 0.0).r >= ph) { phit = true; break; }
70
+ pprev = ph;
71
+ }
72
+ float plo = max(ph, 0.0), phi = pprev;
73
+ if (phit) {
74
+ for (int j = 0; j < 5; j++) {
75
+ float mid = 0.5 * (plo + phi);
76
+ if (textureLod(uPlateDepth, base + (mid - uFocus) * dir, 0.0).r >= mid) plo = mid; else phi = mid;
77
+ }
78
+ }
79
+ uv = base + (plo - uFocus) * dir;
80
+ onPlate = true;
81
+ } else if (hit && (g > uWallSlope || dh.a < 0.5) && dNear > lo + 0.04) {
82
+ vec2 away = -toNear;
83
+ vec2 probe = uv;
84
+ for (int k = 1; k <= 6; k++) {
85
+ vec2 q = uv + away * texel * float(k * 2);
86
+ probe = q;
87
+ if (textureLod(uDepth, q, 0.0).r < lo - 0.05) break;
88
+ }
89
+ uv = probe + away * texel * 2.0;
90
+ }
91
+ }
92
+ pxUv = uv;
93
+ photoHitDepth = onPlate ? textureLod(uPlateDepth, uv, 0.0).r : textureLod(uDepth, uv, 0.0).r;
94
+ vec2 gx = dFdx(base), gy = dFdy(base);
95
+ return onPlate ? textureGrad(uPlate, uv, gx, gy) : textureGrad(uMap, uv, gx, gy);
96
+ }
97
+ `,de=.02,A=(e,t,n)=>({type:`number`,default:e,min:t,max:n}),j={fog:{needsDepth:!0,params:{color:{type:`color`,default:`#ffffff`},amount:A(.6,0,1),start:A(.7,0,1),end:A(0,0,1),drift:A(.3,0)}},light:{needsDepth:!1,params:{color:{type:`color`,default:`#ffffff`},intensity:A(1,0),ambient:A(.75,0,1),position:{type:`vec2`,default:[.4,.4],min:-1,max:1},height:A(.6,0),radius:A(.8,0),relief:A(1,0),specular:A(.25,0,1),follow:{type:`enum`,default:`pointer`,options:[`pointer`,`auto`,`none`],animatable:!1}}},reveal:{needsDepth:!0,alpha:!0,params:{progress:A(1,0,1),from:{type:`enum`,default:`far`,options:[`near`,`far`],animatable:!1},softness:A(.15,0,1),duration:A(void 0,0),delay:A(0,0)}},blur:{needsDepth:!1,params:{focus:A(void 0,0,1),amount:A(.6,0,5),range:A(.1,0,1),to:A(void 0,0,1),duration:A(void 0,0),delay:A(0,0)}},frame:{needsDepth:!1,alpha:!0,params:{inset:{type:`vec2`,default:[.12,.12],min:0,max:.45,scalar:!0},threshold:A(.6,0,1),softness:A(.04,0,1),border:A(.015,0,.2),color:{type:`color`,default:`#ffffff`},shadow:A(.35,0,1)}}},M=Object.keys(j);function N(e,t){let n={};for(let r of M){let i=e?.[r],a=j[r];if(!i||typeof i!=`object`||a.needsDepth&&!t.depth)continue;let o={};for(let[e,n]of Object.entries(a.params)){let r=i[e]??n.default;r!==void 0&&(o[e]=n.type===`color`?t.color(typeof r==`string`?r:String(n.default)):n.type===`vec2`?Array.isArray(r)?[_(r[0],0),_(r[1],0)]:typeof r==`number`?[r,r]:[...n.default]:n.type===`enum`?typeof r==`string`&&n.options?.includes(r)?r:n.default:_(r,_(n.default,0)))}r===`blur`&&(o.focus??=g(_(t.focus,.5),0,1)),n[r]=o}return n}var P=`
98
+ uniform float uFxTime;
99
+ uniform float uFxAspect;
100
+ `,F=`
101
+ uniform vec3 uLightColor;
102
+ uniform vec3 uLightPos;
103
+ uniform vec4 uLight;
104
+ `,I=`
105
+ float fxZ(vec2 p, float lod) { return (textureLod(uDepth, p, lod).r - 1.0) * 0.5 * uLight.z; }
106
+ // normal samples: a nearer object next to this point is an occluder, not a
107
+ // slope of this surface (no halo on a wall around the subjects)
108
+ float fxN(vec2 p, float lod, float zc) {
109
+ float z = fxZ(p, lod);
110
+ return mix(z, zc, smoothstep(0.01, 0.04, (z - zc) / max(uLight.z, 1e-3)));
111
+ }
112
+ `,L=e=>`
113
+ {
114
+ vec3 L = vec3(uLightPos.xy * vec2(uFxAspect, 1.0), uLightPos.z);
115
+ vec3 n = vec3(0.0, 0.0, 1.0);
116
+ vec3 S = vec3(q, 0.0);
117
+ float sh = 0.0;
118
+ ${e?R:``}
119
+ vec3 tl = L - S;
120
+ vec3 l = normalize(tl);
121
+ float att = 1.0 / (1.0 + max(dot(tl, tl) - L.z * L.z, 0.0) / max(uLight.y * uLight.y, 1e-4));
122
+ att *= att * 1.6;
123
+ float df = max(dot(n, l), 0.0) * (1.0 - 0.6 * sh);
124
+ float sp = pow(max(dot(n, normalize(l + vec3(0.0, 0.0, 1.0))), 0.0), 40.0) * uLight.w * (1.0 - sh);
125
+ vec3 lit = c.rgb * (uLight.x + df * att * uLightColor) + uLightColor * sp * att * 0.35;
126
+ vec3 k = vec3(0.78);
127
+ c.rgb = mix(lit, k + (1.0 - k) * (1.0 - exp((k - lit) / (1.0 - k))), step(k, lit));
128
+ }
129
+ `,R=`
130
+ // Normals from a smoothed depth: a Sobel gradient on the mip level whose
131
+ // texels are ~1/160 of the image (estimated depth maps carry fine noise
132
+ // that would light up as ripples on flat walls), below a noise floor the
133
+ // surface stays flat; real curvature (round bodies, silhouettes) remains.
134
+ vec2 ts = vec2(textureSize(uDepth, 0));
135
+ float lod = max(log2(max(ts.x, ts.y) / 160.0), 0.0);
136
+ vec2 e = exp2(lod) * 1.5 / ts;
137
+ S.z = fxZ(uv, lod);
138
+ float z0 = fxN(uv + vec2(-e.x, e.y), lod, S.z), z1 = fxN(uv + vec2(0.0, e.y), lod, S.z), z2 = fxN(uv + e, lod, S.z);
139
+ float z3 = fxN(uv - vec2(e.x, 0.0), lod, S.z), z5 = fxN(uv + vec2(e.x, 0.0), lod, S.z);
140
+ float z6 = fxN(uv - e, lod, S.z), z7 = fxN(uv - vec2(0.0, e.y), lod, S.z), z8 = fxN(uv + vec2(e.x, -e.y), lod, S.z);
141
+ vec2 sl = vec2(z2 + 2.0 * z5 + z8 - z0 - 2.0 * z3 - z6, z0 + 2.0 * z1 + z2 - z6 - 2.0 * z7 - z8) / (16.0 * e * vec2(uFxAspect, 1.0));
142
+ sl *= smoothstep(0.015, 0.05, length(sl));
143
+ // exaggerated 3× over the true slope: depth maps are smooth
144
+ n = normalize(vec3(-3.0 * sl, 1.0));
145
+ vec3 sd = normalize(L - S);
146
+ for (int i = 1; i <= 8; i++) {
147
+ vec3 P = S + sd * (float(i) * 0.035);
148
+ // local relief only: an occluder well above this surface is another
149
+ // object (a doll before the wall, a facade before the sky), no shadow
150
+ float zo = fxZ(P.xy / vec2(uFxAspect, 1.0) * 0.5 + 0.5, lod);
151
+ sh = max(sh, clamp((zo - P.z) * 24.0, 0.0, 1.0) * (1.0 - smoothstep(0.01, 0.03, (zo - S.z) / max(uLight.z, 1e-3))));
152
+ }
153
+ `,z=`
154
+ uniform vec3 uFogColor;
155
+ uniform vec4 uFog;
156
+ float fxHash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
157
+ float fxNoise(vec2 p) {
158
+ vec2 i = floor(p);
159
+ vec2 f = fract(p);
160
+ f = f * f * (3.0 - 2.0 * f);
161
+ return mix(mix(fxHash(i), fxHash(i + vec2(1.0, 0.0)), f.x), mix(fxHash(i + vec2(0.0, 1.0)), fxHash(i + 1.0), f.x), f.y);
162
+ }
163
+ `,B=`
164
+ {
165
+ float k = clamp((uFog.y - d) * uFog.z, 0.0, 1.0);
166
+ float s = uFxTime * uFog.w;
167
+ float w = 0.65 * fxNoise(q * vec2(1.4, 2.6) + vec2(s * 0.4, s * 0.06)) + 0.35 * fxNoise(q * vec2(3.6, 6.0) - vec2(s * 0.7, -s * 0.1));
168
+ c.rgb = mix(c.rgb, uFogColor, clamp(uFog.x * k * k * (3.0 - 2.0 * k) * (0.6 + 0.8 * w), 0.0, 1.0));
169
+ }
170
+ `,V=`
171
+ uniform vec3 uReveal;
172
+ `,H=`
173
+ c.a *= 1.0 - smoothstep(uReveal.x - uReveal.z, uReveal.x + uReveal.z, uReveal.y > 0.5 ? 1.0 - d : d);
174
+ `,U=`
175
+ uniform vec4 uBlur;
176
+ float fxCoc(float z) { return clamp((abs(z - uBlur.x) - uBlur.y) * uBlur.w, 0.0, 1.0); }
177
+ `,fe=`
178
+ vec2 gc = 0.5 + (s - 0.5) * uInset * (1.0 - 0.06 * uZoom) + (d - uFocus) * (uView - (s - 0.5) * 2.0 * uZoom) * uMaxOffset;
179
+ `,W=`
180
+ if (textureLod(uDepth, uv, 0.0).a < 0.5) {
181
+ vec2 de = 2.0 / vec2(textureSize(uDepth, 0));
182
+ dc = max(max(textureLod(uDepth, uv + vec2(de.x, 0.0), 0.0).r, textureLod(uDepth, uv - vec2(de.x, 0.0), 0.0).r), max(textureLod(uDepth, uv + vec2(0.0, de.y), 0.0).r, textureLod(uDepth, uv - vec2(0.0, de.y), 0.0).r));
183
+ }
184
+ `,pe=(e,t,n)=>`
185
+ {
186
+ ${n?fe:`vec2 gc = uv;`}
187
+ float dc = d;
188
+ ${e?W:``}
189
+ float cc = fxCoc(dc);
190
+ vec2 R = vec2(uBlur.z, uBlur.z * uFxAspect);
191
+ float rs = max(cc, 0.35);
192
+ float lod = log2(max(rs * uBlur.z * float(textureSize(uMap, 0).x) * ${(.6*(3.14159265/t)**.5).toFixed(3)}, 1.0));
193
+ vec3 acc = mix(c.rgb, textureLod(uMap, gc, lod * cc).rgb, cc);
194
+ float ws = 1.0;
195
+ for (int i = 0; i < ${t}; i++) {
196
+ float fi = float(i) + 0.5;
197
+ float r = sqrt(fi / ${t}.0) * rs;
198
+ vec2 p = gc + vec2(cos(fi * 2.39996), sin(fi * 2.39996)) * r * R;
199
+ vec2 dt = ${e?`textureLod(uDepth, p, 0.0).ra`:`vec2(d, 1.0)`};
200
+ float ct = fxCoc(dt.x);
201
+ float w = clamp(((dt.x < dc - 0.03 ? min(ct, cc) : ct) - r) * 20.0 + 0.5, 0.0, 1.0) * step(0.5, dt.y);
202
+ vec3 sc = textureLod(uMap, p, lod).rgb;
203
+ w *= 1.0 + 3.0 * max(dot(sc, vec3(0.2126, 0.7152, 0.0722)) - 0.7, 0.0);
204
+ acc += sc * w;
205
+ ws += w;
206
+ }
207
+ c.rgb = acc / ws;
208
+ }
209
+ `,me=`
210
+ uniform vec4 uFrame;
211
+ uniform vec4 uFrameB;
212
+ uniform vec3 uFrameColor;
213
+ float fxBox(vec2 p, vec2 h) { vec2 e = abs(p) - h; return length(max(e, 0.0)) + min(max(e.x, e.y), 0.0); }
214
+ // popped content fades out near the photo's own edges (no hard photo cut on the page)
215
+ float fxEdge(vec2 p, float w) { return smoothstep(0.0, w, -fxBox(p, vec2(uFxAspect, 1.0))); }
216
+ `,G=`
217
+ float ks = 0.0;
218
+ // per-pixel rotation (interleaved gradient noise): grain, not banded copies
219
+ float jr = 6.2832 * fract(52.9829 * fract(dot(gl_FragCoord.xy, vec2(0.06711, 0.00584))));
220
+ for (int i = 0; i < 8; i++) {
221
+ float fi = float(i) + 0.5;
222
+ vec2 o = so + 0.04 * sqrt(fi / 8.0) * vec2(cos(fi * 2.39996 + jr), sin(fi * 2.39996 + jr));
223
+ ks += fxEdge(qs - o, 0.25) * smoothstep(uFrameB.x - uFrame.w, uFrameB.x + uFrame.w, textureLod(uDepth, 0.5 + (s - 0.5 - o / vec2(2.0 * uFxAspect, 2.0)) * uFrameB.zw, 0.0).r);
224
+ }
225
+ sh = max(sh, 0.1 * ks);
226
+ `,he=`
227
+ vec2 et = 3.0 / vec2(textureSize(uDepth, 0));
228
+ dp = min(dp, min(min(textureLod(uDepth, uv + vec2(et.x, 0.0), 0.0).r, textureLod(uDepth, uv - vec2(et.x, 0.0), 0.0).r), min(textureLod(uDepth, uv + vec2(0.0, et.y), 0.0).r, textureLod(uDepth, uv - vec2(0.0, et.y), 0.0).r)));
229
+ `,ge=e=>`
230
+ {
231
+ vec2 qs = (s * 2.0 - 1.0) * vec2(uFxAspect, 1.0);
232
+ float aa = max(length(fwidth(qs)), 1e-5);
233
+ float din = fxBox(qs, uFrame.xy);
234
+ float inner = clamp(0.5 - din / aa, 0.0, 1.0);
235
+ float outer = clamp(0.5 - (din - uFrame.z) / aa, 0.0, 1.0);
236
+ float dp = d;
237
+ ${e?he:``}
238
+ float pop = smoothstep(uFrameB.x - uFrame.w, uFrameB.x + uFrame.w, dp) * fxEdge(qs, 0.08);
239
+ vec2 so = vec2(0.03, -0.045);
240
+ float sh = 1.0 - smoothstep(-0.03, 0.1, fxBox(qs - so, uFrame.xy + uFrame.z));
241
+ ${e?G:``}
242
+ vec4 o = mix(vec4(0.0, 0.0, 0.0, uFrameB.y * sh * fxEdge(qs, 0.25)), vec4(uFrameColor, 1.0), outer);
243
+ // composed premultiplied (coverage cross-fades), back to straight alpha
244
+ vec4 cp = vec4(c.rgb * c.a, c.a);
245
+ o = mix(mix(o, cp, inner), cp, pop);
246
+ c = vec4(o.rgb / max(o.a, 1e-4), o.a);
247
+ }
248
+ `,K=e=>e===`low`?8:e===`medium`?12:16;function q(e,t,n,r=!1){if(!J(e))return``;let i=P,a=``;return e.blur&&(i+=U,a+=pe(t,K(n),r&&t)),e.light&&(i+=F+(t?I:``),a+=L(t)),e.fog&&(i+=z,a+=B),e.reveal&&(i+=V,a+=H),e.frame&&(i+=me,a+=ge(t)),`${i}vec4 photoFx(vec4 c, vec2 uv, float d, vec2 s) {
249
+ vec2 q = (uv * 2.0 - 1.0) * vec2(uFxAspect, 1.0);
250
+ ${a} return c;
251
+ }
252
+ `}var J=e=>M.some(t=>e[t]),Y=.3;function _e(e,t,n){let r=2*Math.PI*Math.max(0,t)/10*n;return[g(e[0]-.7*Math.sin(r),-1,1),g(e[1]-.35*(1-Math.cos(2*r)),-1,1)]}function ve(e,t){let n=Math.max(t,.001);return-n+g(e,0,1)*(1+2*n)}function X(e,t,n,r,i,a=!1){if(typeof t!=`number`||typeof n!=`number`||n<=0||a)return e;let o=Math.max(0,i-r)/n;return e+(t-e)*(.5-.5*Math.cos(Math.PI*o))}function ye(e,t){let n=N(e,t),r=J(n),i=!!t.live,a={x:0,y:0,w:0,init:!1},o=0,s=!1;return{state:n,glsl:q(n,t.depth,t.quality,t.parallax),alpha:M.some(e=>n[e]&&j[e].alpha),depthMips:!!n.light&&t.depth,call:(e,n,i=e)=>r?`c = photoFx(c, ${e}, ${t.depth?n:`0.5`}, ${i});`:``,frame:(e,n,r)=>{o=e,s=r.reduced;let c=r.pointer,l=c.inside?g(c.x,-1,1):a.x,u=c.inside?g(c.y,-1,1):a.y,d=+!!c.inside;if(!i||!a.init)a.x=l,a.y=u,a.w=d,a.init=i;else{let e=g(_(t.smoothing,.9),0,.99);a.x=T(a.x,l,n,e),a.y=T(a.y,u,n,e),a.w=T(a.w,d,n,e)}},uniforms:()=>{let e={uFxTime:[o],uFxAspect:[t.aspect]},r=n.light;if(r){let n=r.color,i=r.intensity,c=r.position,l=c;if(!s&&r.follow!==`none`){let e=_e(c,_(t.speed,1),o);l=r.follow===`auto`?e:[e[0]+(a.x-e[0])*a.w,e[1]+(a.y-e[1])*a.w]}e.uLightColor=[n[0]*i,n[1]*i,n[2]*i],e.uLightPos=[l[0],l[1],Math.max(.02,r.height)],e.uLight=[g(r.ambient,0,1),Math.max(.001,r.radius),r.relief,g(r.specular,0,1)]}let i=n.fog;if(i){let t=i.start,n=t-i.end;e.uFogColor=i.color.slice(0,3),e.uFog=[g(i.amount,0,1),t,1/(Math.abs(n)<.001?n<0?-.001:.001:n),Math.max(0,i.drift)]}let c=n.reveal;if(c){let t=c.duration,n=c.progress;if(typeof t==`number`){let e=s||t<=0?1:g((o-c.delay)/t,0,1);n=e*e*(3-2*e)}let r=Math.max(.001,c.softness);e.uReveal=[ve(n,r),+(c.from===`near`),r]}let l=n.blur;if(l){let t=g(l.range,0,1);e.uBlur=[X(l.focus,l.to,l.duration,l.delay,o,s),t,Math.max(0,l.amount)/100,1/Y]}let u=n.frame;if(u){let n=u.inset,r=t.aspect;e.uFrame=[Math.max(0,1-2*g(n[0],0,.5))*r,Math.max(0,1-2*g(n[1],0,.5)),Math.max(0,u.border)*2*r,Math.max(.001,u.softness)],e.uFrameB=[u.threshold,g(u.shadow,0,1),...t.inset??[1,1]],e.uFrameColor=u.color.slice(0,3)}return e},get(e,t){let r=n[e],[i,a]=t.split(`.`),o=r?.[i];return a&&Array.isArray(o)?o[+(a===`y`)]:Array.isArray(o)?[...o]:o},set(e,t,r){let i=n[e],[a,o]=t.split(`.`);if(!i||!(a in i)&&!(a in(j[e]?.params??{})))return!1;let s=i[a];if(o&&Array.isArray(s)&&typeof r==`number`)s[+(o===`y`)]=r;else if(Array.isArray(s)&&typeof r==`number`)i[a]=s.map(()=>r);else if(Array.isArray(r))i[a]=r.slice(0,Array.isArray(s)?s.length:r.length);else if(typeof r==`number`&&Number.isFinite(r))i[a]=r;else return!1;return!0}}}function be(e,t,n){let r=Math.round(g(_(e,y.segments),2,1024));return t>=n?[r,Math.max(1,Math.round(r*n/t))]:[Math.max(1,Math.round(r*t/n)),r]}function xe(e,t){return v(e,t)}function Se(e,t,n){let r=n.distance,i=xe(n.strength,n.width);if(!(r>0)||i<=0)return{x:0,y:0,dolly:0,magnify:1};if(e===`mesh`){let e=r*Math.tan(g(n.strength,0,1)*8*ie);return{x:t.x*e,y:t.y*e,dolly:t.zoom*i*.5,magnify:NaN}}let a=E(n.strength,n.width,n.height),o=a.maxOffset[0]/a.inset[0]*n.width,s=a.maxOffset[1]/a.inset[1]*n.height,c=.5*(a.maxOffset[0]/a.inset[0]+a.maxOffset[1]/a.inset[1]),l=2*t.zoom*c*r/i;return{x:t.x*o*r/i,y:t.y*s*r/i,dolly:l*r/(1+l),magnify:1/(1-.06*t.zoom)}}function Ce(e,t,n,r){let i=Math.round(g(_(e,y.layers),2,16)),a=[],o=g(n,0,1)*r*.1;for(let e=0;e<i;e++){let n=e/i,s=(e+1)/i,c=(n+s)/2;a.push({lo:n,hi:s,center:c,feather:.35/i,z:(c-t)*o+e*.001*r,background:e===0})}return a}var Z=O,we=`
253
+ varying vec2 vUv;
254
+ #ifdef PHOTO_OCCLUDE
255
+ varying vec3 vLocal;
256
+ varying vec3 vRay;
257
+ #endif
258
+ void main() {
259
+ vUv = uv;
260
+ #ifdef PHOTO_OCCLUDE
261
+ // camera ray through this vertex, in the object's space
262
+ mat4 inv = inverse(modelViewMatrix);
263
+ vLocal = position;
264
+ vRay = isOrthographic ? (inv * vec4(0.0, 0.0, -1.0, 0.0)).xyz : position - (inv * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
265
+ #endif
266
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
267
+ }
268
+ `,Q=`
269
+ #ifdef PHOTO_OCCLUDE
270
+ uniform mat4 projectionMatrix;
271
+ uniform mat4 modelViewMatrix;
272
+ uniform float uZRange;
273
+ uniform float uZDist;
274
+ varying vec3 vLocal;
275
+ varying vec3 vRay;
276
+ void photoDepthOut(float d) {
277
+ float lin = (d - uFocus) * uZRange;
278
+ float z = lin * uZDist / (uZDist + lin);
279
+ float rz = abs(vRay.z) > 1e-6 ? vRay.z : 1e-6;
280
+ vec3 p = vLocal + vRay * ((z - vLocal.z) / rz);
281
+ vec4 clip = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
282
+ gl_FragDepth = clamp(0.5 + 0.5 * clip.z / clip.w, 0.0, 1.0);
283
+ }
284
+ #endif
285
+ `,Te=e=>`
286
+ ${Z}
287
+ ${k}
288
+ ${e.glsl}
289
+ ${Q}
290
+ varying vec2 vUv;
291
+ void main() {
292
+ vec4 c = parallaxTexel(vUv);
293
+ ${e.call(`pxUv`,`photoHitDepth`,`vUv`)}
294
+ if (c.a * uOpacity < 0.004) discard;
295
+ #ifdef PHOTO_OCCLUDE
296
+ if (c.a < 0.5) discard;
297
+ photoDepthOut(photoHitDepth);
298
+ #endif
299
+ gl_FragColor = shade(c, 1.0);
300
+ #include <tonemapping_fragment>
301
+ #include <colorspace_fragment>
302
+ }
303
+ `,Ee=`
304
+ uniform sampler2D uDepth;
305
+ uniform float uRange;
306
+ uniform float uFocus;
307
+ uniform float uEdgeCut;
308
+ uniform vec3 uCam;
309
+ uniform float uPerspective;
310
+ attribute vec4 uvOther;
311
+ varying vec2 vUv;
312
+ varying float vDepth;
313
+ varying float vCut;
314
+ varying float vMotion;
315
+ vec3 displaced(vec3 p, float z) {
316
+ if (uPerspective > 0.5 && uCam.z > z + 1e-3) p.xy = mix(p.xy, uCam.xy, z / uCam.z);
317
+ p.z = z;
318
+ return p;
319
+ }
320
+ void main() {
321
+ vUv = uv;
322
+ vec4 d0 = textureLod(uDepth, uv, 0.0);
323
+ vec4 d1 = textureLod(uDepth, uvOther.xy, 0.0);
324
+ vec4 d2 = textureLod(uDepth, uvOther.zw, 0.0);
325
+ float jump = max(max(abs(d0.r - d1.r), abs(d1.r - d2.r)), abs(d0.r - d2.r));
326
+ bool cut = min(d0.a, min(d1.a, d2.a)) < 0.5 || (uEdgeCut > 0.0 && jump > uEdgeCut);
327
+ vCut = cut ? 1.0 : 0.0;
328
+ vDepth = d0.r;
329
+ vec4 c = projectionMatrix * modelViewMatrix * vec4(displaced(position, (d0.r - uFocus) * uRange), 1.0);
330
+ vMotion = 0.0;
331
+ if (cut) {
332
+ vec4 a = projectionMatrix * modelViewMatrix * vec4(displaced(position, -uFocus * uRange), 1.0);
333
+ vec4 b = projectionMatrix * modelViewMatrix * vec4(displaced(position, (1.0 - uFocus) * uRange), 1.0);
334
+ vMotion = length(b.xy / b.w - a.xy / a.w);
335
+ }
336
+ gl_Position = c;
337
+ }
338
+ `,De=e=>`
339
+ ${Z}
340
+ uniform sampler2D uDepth;
341
+ ${e.glsl}
342
+ varying vec2 vUv;
343
+ varying float vDepth;
344
+ varying float vCut;
345
+ varying float vMotion;
346
+ void main() {
347
+ if (vCut > 0.5) {
348
+ float d = textureLod(uDepth, vUv, 0.0).r;
349
+ if (abs(d - vDepth) * vMotion > 0.004) discard;
350
+ }
351
+ vec4 c = texture2D(uMap, vUv);
352
+ ${e.call(`vUv`,`textureLod(uDepth, vUv, 0.0).r`)}
353
+ if (c.a * uOpacity < 0.004) discard;
354
+ gl_FragColor = shade(c, 1.0);
355
+ #include <tonemapping_fragment>
356
+ #include <colorspace_fragment>
357
+ }
358
+ `,Oe=`
359
+ uniform sampler2D uDepth;
360
+ uniform sampler2D uPlateDepth;
361
+ uniform float uPlateOn;
362
+ uniform float uRange;
363
+ uniform float uFocus;
364
+ uniform vec3 uCam;
365
+ uniform float uPerspective;
366
+ uniform vec2 uReach;
367
+ varying vec2 vUv;
368
+ varying float vDepth;
369
+ void main() {
370
+ vUv = uv;
371
+ float d = textureLod(uDepth, uv, 0.0).r;
372
+ // with a plate: its depth is the background behind the foreground
373
+ if (uPlateOn > 0.5) d = min(d, textureLod(uPlateDepth, uv, 0.0).r);
374
+ else for (int i = 1; i <= 2; i++) {
375
+ vec2 r = uReach * float(i) * 0.5;
376
+ d = min(d, textureLod(uDepth, uv + vec2(r.x, 0.0), 0.0).r);
377
+ d = min(d, textureLod(uDepth, uv - vec2(r.x, 0.0), 0.0).r);
378
+ d = min(d, textureLod(uDepth, uv + vec2(0.0, r.y), 0.0).r);
379
+ d = min(d, textureLod(uDepth, uv - vec2(0.0, r.y), 0.0).r);
380
+ d = min(d, textureLod(uDepth, uv + r, 0.0).r);
381
+ d = min(d, textureLod(uDepth, uv - r, 0.0).r);
382
+ d = min(d, textureLod(uDepth, uv + vec2(r.x, -r.y), 0.0).r);
383
+ d = min(d, textureLod(uDepth, uv + vec2(-r.x, r.y), 0.0).r);
384
+ }
385
+ vDepth = d;
386
+ float z = (d - uFocus) * uRange - uRange * 0.02;
387
+ vec3 p = position;
388
+ if (uPerspective > 0.5 && uCam.z > z + 1e-3) p.xy = mix(p.xy, uCam.xy, z / uCam.z);
389
+ p.z = z;
390
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
391
+ }
392
+ `,ke=e=>`
393
+ ${Z}
394
+ uniform sampler2D uDepth;
395
+ ${e.glsl}
396
+ uniform sampler2D uPlate;
397
+ uniform float uPlateOn;
398
+ varying vec2 vUv;
399
+ varying float vDepth;
400
+ void main() {
401
+ vec2 uv = vUv;
402
+ float d = textureLod(uDepth, uv, 0.0).r;
403
+ if (uPlateOn > 0.5) {
404
+ vec4 pc = texture2D(uPlate, uv);
405
+ if (pc.a * uOpacity < 0.004) discard;
406
+ gl_FragColor = shade(pc, 1.0);
407
+ #include <tonemapping_fragment>
408
+ #include <colorspace_fragment>
409
+ return;
410
+ }
411
+ if (d > vDepth + 0.04) {
412
+ vec2 texel = 1.0 / vec2(textureSize(uDepth, 0));
413
+ vec2 grad = vec2(
414
+ textureLod(uDepth, uv + vec2(texel.x * 2.0, 0.0), 0.0).r - textureLod(uDepth, uv - vec2(texel.x * 2.0, 0.0), 0.0).r,
415
+ textureLod(uDepth, uv + vec2(0.0, texel.y * 2.0), 0.0).r - textureLod(uDepth, uv - vec2(0.0, texel.y * 2.0), 0.0).r);
416
+ vec2 away = length(grad) > 1e-5 ? -normalize(grad) : vec2(0.0);
417
+ // walk towards the background until the depth reaches this surface's
418
+ for (int k = 1; k <= 24; k++) {
419
+ uv = vUv + away * texel * float(k * 3);
420
+ if (textureLod(uDepth, uv, 0.0).r <= vDepth + 0.04) break;
421
+ }
422
+ uv += away * texel * 2.0;
423
+ }
424
+ vec4 c = texture2D(uMap, uv);
425
+ ${e.call(`uv`,`textureLod(uDepth, uv, 0.0).r`,`vUv`)}
426
+ if (c.a * uOpacity < 0.004) discard;
427
+ gl_FragColor = shade(c, 1.0);
428
+ #include <tonemapping_fragment>
429
+ #include <colorspace_fragment>
430
+ }
431
+ `,Ae=e=>`
432
+ ${Z}
433
+ uniform sampler2D uDepth;
434
+ ${e.glsl}
435
+ uniform vec2 uView;
436
+ uniform float uZoom;
437
+ uniform vec2 uMaxOffset;
438
+ uniform vec2 uInset;
439
+ uniform float uFocus;
440
+ uniform float uCenter;
441
+ uniform float uLo;
442
+ uniform float uHi;
443
+ uniform float uFeather;
444
+ uniform float uBackground;
445
+ ${Q}
446
+ uniform sampler2D uPlate;
447
+ uniform sampler2D uPlateDepth;
448
+ uniform float uPlateOn;
449
+ varying vec2 vUv;
450
+ void main() {
451
+ // the zoom drift also pushes in slightly (stays inside the inset margin)
452
+ vec2 base = 0.5 + (vUv - 0.5) * uInset * (1.0 - 0.06 * uZoom);
453
+ vec2 v = uView - (vUv - 0.5) * 2.0 * uZoom;
454
+ // Each layer moves with the depth it shows, clamped to its band: a smooth
455
+ // surface crossing two bands stays continuous (no tear at the band edge);
456
+ // only real depth jumps separate the layers. Fixed-point solve, from the
457
+ // band centre.
458
+ vec2 dir = v * uMaxOffset;
459
+ vec2 uv = base + (uCenter - uFocus) * dir;
460
+ for (int i = 0; i < 3; i++) {
461
+ float di = clamp(textureLod(uDepth, uv, 0.0).r, uLo, uHi);
462
+ uv = base + (di - uFocus) * dir;
463
+ }
464
+ vec4 dd = textureLod(uDepth, uv, 0.0);
465
+ float d = dd.r;
466
+ // soft slice edges, but hard on marked depth edges (alpha 0): a blend of
467
+ // two layers there would draw a thin double outline
468
+ float a = uBackground > 0.5 ? 1.0 : dd.a < 0.5 ? step(uLo, d) : smoothstep(uLo - uFeather, uLo + uFeather, d);
469
+ if (a < 0.004) discard;
470
+ vec2 cuv = uv;
471
+ bool onPlate = false;
472
+ // covered by nearer content
473
+ if (d > uHi + uFeather && uPlateOn > 0.5) {
474
+ // the plate holds what is behind the foreground: this layer's surface
475
+ // continues there when the plate depth falls in its band
476
+ vec2 puv = base + (uCenter - uFocus) * dir;
477
+ for (int i = 0; i < 3; i++) puv = base + (clamp(textureLod(uPlateDepth, puv, 0.0).r, uLo, uHi) - uFocus) * dir;
478
+ float pd = textureLod(uPlateDepth, puv, 0.0).r;
479
+ // (the background layer always takes the plate: its best guess)
480
+ if (uBackground > 0.5 || (pd <= uHi + uFeather && pd >= uLo - uFeather)) {
481
+ cuv = puv;
482
+ onPlate = true;
483
+ } else discard;
484
+ } else if (d > uHi + uFeather) {
485
+ bool found = false;
486
+ vec2 reach = v * uMaxOffset * 1.25;
487
+ for (int k = 1; k <= 16; k++) {
488
+ vec2 q = uv + reach * (float(k) / 16.0);
489
+ vec4 dq = textureLod(uDepth, q, 0.0);
490
+ if (dq.r <= uHi && dq.a >= 0.5 && (uBackground > 0.5 || dq.r >= uLo - uFeather)) {
491
+ // step past the edge's blended texels
492
+ vec2 texel = 1.0 / vec2(textureSize(uMap, 0));
493
+ cuv = q + normalize(reach) * texel * 3.0;
494
+ found = true;
495
+ break;
496
+ }
497
+ }
498
+ // Nothing of this band to extend: let the layers below show (the
499
+ // background keeps the source texel).
500
+ if (!found && uBackground < 0.5) discard;
501
+ }
502
+ vec2 gx = dFdx(base), gy = dFdy(base);
503
+ vec4 c = onPlate ? textureGrad(uPlate, cuv, gx, gy) : textureGrad(uMap, cuv, gx, gy);
504
+ ${e.call(`cuv`,`textureLod(uDepth, cuv, 0.0).r`,`vUv`)}
505
+ gl_FragColor = shade(c, a);
506
+ if (gl_FragColor.a < 0.004) discard;
507
+ #ifdef PHOTO_OCCLUDE
508
+ // the depth this layer's surface moves with
509
+ photoDepthOut(uBackground > 0.5 ? textureLod(uDepth, cuv, 0.0).r : clamp(textureLod(uDepth, cuv, 0.0).r, uLo, uHi));
510
+ #endif
511
+ #include <tonemapping_fragment>
512
+ #include <colorspace_fragment>
513
+ }
514
+ `,je=e=>`
515
+ ${Z}
516
+ ${e.glsl}
517
+ varying vec2 vUv;
518
+ void main() {
519
+ vec4 c = texture2D(uMap, vUv);
520
+ ${e.call(`vUv`,`0.5`)}
521
+ if (c.a * uOpacity < 0.004) discard;
522
+ gl_FragColor = shade(c, 1.0);
523
+ #include <tonemapping_fragment>
524
+ #include <colorspace_fragment>
525
+ }
526
+ `;function Me(e){let t=e.image;return{w:t?.naturalWidth||t?.width||1,h:t?.naturalHeight||t?.height||1}}function Ne(e,t,n){let r=t.material??{};return{uMap:{value:e},uTint:{value:r.color?n.color(r.color):new s(1,1,1)},uOpacity:{value:g(_(r.opacity,1),0,1)},uIntensity:{value:Math.max(0,_(r.emissiveIntensity,1))}}}function $(e,t,n,r){let i=new ee({vertexShader:e,fragmentShader:t,uniforms:n,transparent:r,toneMapped:!1,fog:!1,side:0});return i.depthWrite=!r,typeof n.uOpacity?.value==`number`&&(i.opacity=n.uOpacity.value),i}function Pe(e,t,n,r){let i=n*r*2,a=new Float32Array(i*9),o=new Float32Array(i*6),s=new Float32Array(i*12),c=0,l=(n,r,i)=>{let l=[n,r,i];for(let n=0;n<3;n++){let[r,i]=l[n],u=l[(n+1)%3],d=l[(n+2)%3];a.set([(r-.5)*e,(i-.5)*t,0],c*3),o.set([r,i],c*2),s.set([u[0],u[1],d[0],d[1]],c*4),c++}};for(let e=0;e<r;e++)for(let t=0;t<n;t++){let i=t/n,a=(t+1)/n,o=e/r,s=(e+1)/r;l([i,o],[a,o],[a,s]),l([i,o],[a,s],[i,s])}let u=new f;return u.setAttribute(`position`,new m(a,3)),u.setAttribute(`uv`,new m(o,2)),u.setAttribute(`uvOther`,new m(s,4)),u}async function Fe(s,f){let m=(e,t,n,r)=>e?re(f.resolveAsset(e)).catch(e=>(f.issue(`asset-load`,`${s.id}: ${t}: ${e.message} — ${r}`,`objects#${s.id}.${n}`),null)):Promise.resolve(null),ee=!!(s.depth&&s.plate&&s.plateDepth),[v,b,x,S]=await Promise.all([re(f.resolveAsset(s.src)),m(s.depth,`depth map`,`depth`,`showing the photo flat`),m(ee?s.plate:void 0,`plate`,`plate`,`edges use the photo`),m(ee?s.plateDepth:void 0,`plate depth`,`plateDepth`,`edges use the photo`)]);v.colorSpace=d,v.wrapS=v.wrapT=e,v.anisotropy=4,v.needsUpdate=!0,b&&(b.colorSpace=``,b.premultiplyAlpha=!1,b.wrapS=b.wrapT=e,b.generateMipmaps=!1,b.minFilter=p,b.magFilter=p,b.needsUpdate=!0);let C=b&&x&&S?{map:x,depth:S}:null;if(!C)x?.dispose(),S?.dispose();else for(let[t,n]of[[C.map,!1],[C.depth,!0]])t.wrapS=t.wrapT=e,n?(t.colorSpace=``,t.premultiplyAlpha=!1,t.generateMipmaps=!1,t.minFilter=p,t.magFilter=p):(t.colorSpace=d,t.anisotropy=4),t.needsUpdate=!0;let w=()=>({uPlate:{value:C?.map??v},uPlateDepth:{value:C?.depth??b},uPlateOn:{value:+!!C}}),se=Me(v),{width:T,height:D}=ae(s,se.w,se.h),O=g(_(s.strength,y.strength),0,1),k=g(_(s.focus,y.focus),0,1),A=g(_(s.material?.opacity,1),0,1),j=oe(s.motion),M=b?s.mode??`parallax`:`flat`,N=s.occlude===!0&&M!==`flat`,P=A<1||!N&&/\.(png|webp)$/i.test(s.src),F=ye(s.effects,{depth:!!b,color:e=>f.color(e).toArray(),aspect:T/D,live:!f.deterministic,smoothing:j.smoothing,speed:j.speed,focus:k,quality:f.quality,parallax:M===`parallax`,inset:M===`parallax`||M===`layers`?E(O,T,D).inset:void 0}),I={},L=()=>{for(let[e,t]of Object.entries(F.uniforms())){let a=I[e]??={value:t.length===1?0:t.length===2?new n:t.length===3?new r:new i};t.length===1?a.value=t[0]:a.value.fromArray(t)}};L(),b&&F.depthMips&&(b.generateMipmaps=!0,b.minFilter=te,b.needsUpdate=!0);let R=P||F.alpha,z=new t,B=new t;z.add(B);let V=[],H=[],U=[],fe=[],W=null,pe=[],me=(e,t)=>{let n={uZRange:{value:xe(O,T)},uZDist:{value:1e6}};Object.assign(t,n),e.uniforms=t,pe.push(n),e.defines={...e.defines,PHOTO_OCCLUDE:``},e.depthWrite=!0},G=()=>{let e=new a(T,D);return H.push(e),e};if(M===`flat`&&F.glsl){let e=$(we,je(F),{...Ne(v,s,f),...I},R);V.push(e),B.add(new h(G(),e))}else if(M===`flat`){let e=s.material??{},t=new c({map:v,transparent:P,opacity:A,toneMapped:!1,fog:!1});e.color&&t.color.copy(f.color(e.color)),t.color.multiplyScalar(Math.max(0,_(e.emissiveIntensity,1))),P&&(t.alphaTest=A<1?0:.004),V.push(t),B.add(new h(G(),t))}else if(M===`parallax`){let e=E(O,T,D),t={...Ne(v,s,f),uDepth:{value:b},uView:{value:new n},uZoom:{value:0},uMaxOffset:{value:new n(...e.maxOffset)},uInset:{value:new n(...e.inset)},uFocus:{value:k},uWallSlope:{value:de},...I,...w()},r=$(we,Te(F).replace(`__STEPS__`,String(le(f.quality,O))),t,R);N&&me(r,t),V.push(r),U.push(r),B.add(new h(G(),r))}else if(M===`mesh`){let[e,t]=be(_(s.segments,y.segments),T,D),i=xe(O,T),o=Pe(T,D,e,t);o.boundingBox=new l(new r(-T/2,-D/2,-k*i),new r(T/2,D/2,(1-k)*i)),o.boundingSphere=o.boundingBox.getBoundingSphere(new u),H.push(o);let c={...Ne(v,s,f),uDepth:{value:b},uRange:{value:i},uFocus:{value:k},uEdgeCut:{value:g(_(s.edgeCut,y.edgeCut),0,1)},uCam:{value:new r(0,0,1e6)},uPerspective:{value:0},...I};W=c;let d=$(Ee,De(F),c,A<1||F.alpha);N&&(d.depthWrite=!0),d.side=2,V.push(d);let p=new h(o,d);p.renderOrder=1,B.add(p);{let r=new a(T,D,Math.max(1,Math.round(e/2)),Math.max(1,Math.round(t/2)));r.boundingBox=o.boundingBox.clone(),r.boundingSphere=o.boundingSphere.clone(),H.push(r);let i=new n(6/e,6/t),s=$(Oe,ke(F),{...c,uReach:{value:i},...w()},A<1||F.alpha);N&&(s.depthWrite=!0),s.side=2,V.push(s);let l=new h(r,s);l.renderOrder=0,l.raycast=()=>void 0,B.add(l)}}else{let e=E(O,T,D),t=G(),r=Ce(_(s.layers,y.layers),k,O,T),i=g(_(s.edgeCut,y.edgeCut),0,1);r.forEach((r,a)=>{let o={...Ne(v,s,f),uDepth:{value:b},uView:{value:new n},uZoom:{value:0},uMaxOffset:{value:new n(...e.maxOffset)},uInset:{value:new n(...e.inset)},uFocus:{value:k},uCenter:{value:r.center},uLo:{value:r.lo},uHi:{value:r.hi},uFeather:{value:i>0?Math.min(r.feather,i):.002},uBackground:{value:+!!r.background},...I,...w()},c=$(we,Ae(F),o,!r.background||R);N&&me(c,o),V.push(c),U.push(c);let l=new h(t,c);l.position.z=N?0:r.z,l.renderOrder=N?a-1e3:a,l.userData.a3dPhotoLayer=a,B.add(l),fe.push({mesh:l,band:r})})}let he={x:0,y:0,zoom:0},ge=ue(j,{live:!f.deterministic,flat:M===`flat`}),K=new r,q=!1,J=O*8*ie,Y={progress:j.progress};z.userData.a3dPhotoMotion=Y;let _e=E(O,T,D).inset,ve=(e,t,n)=>{F.glsl&&(F.frame(e,t,n),L());for(let e of V){let t=e.uniforms?.uOpacity;t&&(t.value=e.opacity)}if(M===`flat`)return;let r=ge.offset(e,t,{...n,progress:typeof Y.progress==`number`?g(Y.progress,0,1):null});he=r;let i=ce(r,_e);for(let e of U)e.uniforms.uView.value.set(r.x,r.y),e.uniforms.uZoom.value=i.zoom,e.uniforms.uInset.value.set(i.inset[0],i.inset[1]);let a=!!n.camera&&!!n.camera.isPerspectiveCamera;n.camera&&!q&&M!==`parallax`&&(n.camera.updateMatrixWorld(),z.updateWorldMatrix(!0,!1),K.setFromMatrixPosition(n.camera.matrixWorld),z.worldToLocal(K),q=!0);let o=0;if(!(M===`mesh`&&N)&&M===`mesh`){B.rotation.set(r.y*J,-r.x*J,0);let e=a&&q?K.z:0,t=e>0?(r.vertigo??0)*.6*e:0;o=t;let n=(1+(r.push??0))*(e>0?(e+t)/e:1);B.scale.set(n,n,1),B.position.set(K.x*(1-n),K.y*(1-n),r.zoom*xe(O,T)*.5-t)}if(M===`mesh`&&W)W.uCam.value.set(K.x,K.y,K.z+o),W.uPerspective.value=a&&K.z>0?1:0;else if(M===`layers`&&q&&!N){let e=K.z;for(let{mesh:t,band:n}of fe)if(a&&e>n.z+.001){let r=(e-n.z)/e;t.scale.set(r,r,1),t.position.set(K.x*n.z/e,K.y*n.z/e,n.z)}else t.scale.set(1,1,1),t.position.set(0,0,n.z)}},X=new r,Z=new r,Q=new o,Fe=new ne;return{object:z,update:ve,effects:{get:(e,t)=>F.get(e,t),set(e,t,n){F.set(e,t,n)&&L()}},...N?{applyCamera:(e,t)=>{let n=!!e.isPerspectiveCamera;z.updateWorldMatrix(!0,!1),e.updateMatrixWorld(),X.setFromMatrixPosition(e.matrixWorld),z.worldToLocal(X);let i=n&&X.z>.001?X.z:0,a=i>0?i:1e6;for(let e of pe)e.uZDist.value=a;if(B.scale.set(1,1,1),!t||!i)return;let o=e;o.updateProjectionMatrix();let s=Se(M===`mesh`?`mesh`:M===`layers`?`layers`:`parallax`,he,{strength:O,width:T,height:D,distance:i});if(!s.x&&!s.y&&!s.dolly&&s.magnify===1)return;Q.setFromMatrix4(z.matrixWorld);let c=Z.set(s.x,s.y,-s.dolly).applyMatrix3(Q),l=-new r().setFromMatrixPosition(z.matrixWorld).applyMatrix4(e.matrixWorldInverse).z,u=c.clone().applyMatrix3(Q.setFromMatrix4(e.matrixWorldInverse));if(e.position.add(c),e.updateMatrixWorld(),!(l>.001))return;let d=l+u.z;if(!(d>.001))return;let f=(Number.isNaN(s.magnify)?l/d:s.magnify)*d/l;Fe.set(f,0,-f*u.x/d,0,0,f,-f*u.y/d,0,0,0,1,0,0,0,0,1),o.projectionMatrix.multiply(Fe),o.projectionMatrixInverse.copy(o.projectionMatrix).invert(),!Number.isNaN(s.magnify)&&s.magnify!==1&&B.scale.set(1/s.magnify,1/s.magnify,1)}}:{},dispose(){ge.dispose();for(let e of V)e.dispose();for(let e of H)e.dispose();v.dispose(),b?.dispose(),C?.map.dispose(),C?.depth.dispose()}}}export{Fe as buildPhoto};
@@ -0,0 +1 @@
1
+ import{n as e}from"./rolldown-runtime-4tVxZq34.js";import{I as t,J as n,Ln as r,X as i,Z as a,h as o,m as s,vt as c}from"./three.module-B9FlcKtd.js";var l=e({computeMikkTSpaceTangents:()=>u,computeMorphedAttributes:()=>b,deepCloneAttribute:()=>p,deinterleaveAttribute:()=>h,deinterleaveGeometry:()=>g,estimateBytesUsed:()=>_,interleaveAttributes:()=>m,mergeAttributes:()=>f,mergeGeometries:()=>d,mergeGroups:()=>x,mergeVertices:()=>v,remapAttribute:()=>C,toCreasedNormals:()=>S,toTrianglesDrawMode:()=>y});function u(e,t,n=!0){if(!t||!t.isReady)throw Error(`THREE.BufferGeometryUtils: Initialized MikkTSpace library required.`);if(!e.hasAttribute(`position`)||!e.hasAttribute(`normal`)||!e.hasAttribute(`uv`))throw Error(`THREE.BufferGeometryUtils: Tangents require "position", "normal", and "uv" attributes.`);function r(e){if(e.normalized||e.isInterleavedBufferAttribute){let t=new Float32Array(e.count*e.itemSize);for(let n=0,r=0;n<e.count;n++)t[r++]=e.getX(n),t[r++]=e.getY(n),e.itemSize>2&&(t[r++]=e.getZ(n));return t}return e.array instanceof Float32Array?e.array:new Float32Array(e.array)}let i=e.index?e.toNonIndexed():e,a=t.generateTangents(r(i.attributes.position),r(i.attributes.normal),r(i.attributes.uv));if(n)for(let e=3;e<a.length;e+=4)a[e]*=-1;let o=i.attributes.normal,l=o.array;if(o.normalized&&(l instanceof Int8Array||l instanceof Int16Array)){let e=new l.constructor(a.length);for(let t=0;t<a.length;t++)e[t]=c.normalize(a[t],e);i.setAttribute(`tangent`,new s(e,4,!0))}else i.setAttribute(`tangent`,new s(a,4));return e!==i&&e.copy(i),e}function d(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},s={},c=e[0].morphTargetsRelative,l=new o;l.morphTargetsRelative=c;let u=0;for(let o=0;o<e.length;++o){let d=e[o],f=0,p=0;if(n!==(d.index!==null))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`),null;for(let e in d.attributes){if(!r.has(e))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`),null;a[e]===void 0&&(a[e]=[]),a[e].push(d.attributes[e]),f++}if(f!==r.size)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. Make sure all geometries have the same number of attributes.`),null;if(c!==d.morphTargetsRelative)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. .morphTargetsRelative must be consistent throughout all geometries.`),null;for(let t in d.morphAttributes){if(!i.has(t))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. .morphAttributes must be consistent throughout all geometries.`),null;if(d.morphAttributes[t].length!==e[0].morphAttributes[t].length)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. All geometries must have the same number of morph targets for the "`+t+`" morph attribute.`),null;s[t]===void 0&&(s[t]=[]),s[t].push(d.morphAttributes[t]),p++}if(p!==i.size)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. Make sure all geometries have the same number of morph attributes.`),null;if(t){let e;if(n)e=d.index.count;else if(d.attributes.position!==void 0)e=d.attributes.position.count;else return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+o+`. The geometry must have either an index or a position attribute`),null;l.addGroup(u,e,o),u+=e}}if(n){let t=0,n=[];for(let r=0;r<e.length;++r){let i=e[r].index;for(let e=0;e<i.count;++e)n.push(i.getX(e)+t);t+=e[r].attributes.position.count}l.setIndex(n)}for(let e in a){let t=f(a[e]);if(!t)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` attribute.`),null;l.setAttribute(e,t)}for(let e in s){let t=s[e][0].length;if(t!==0){l.morphAttributes=l.morphAttributes||{},l.morphAttributes[e]=[];for(let n=0;n<t;++n){let t=[];for(let r=0;r<s[e].length;++r)t.push(s[e][r][n]);let r=f(t);if(!r)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` morphAttribute.`),null;l.morphAttributes[e].push(r)}}}return l}function f(e){let t,n,r,i=-1,a=0;for(let o=0;o<e.length;++o){let s=e[o];if(t===void 0&&(t=s.array.constructor),t!==s.array.constructor)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.`),null;if(n===void 0&&(n=s.itemSize),n!==s.itemSize)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.`),null;if(r===void 0&&(r=s.normalized),r!==s.normalized)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.`),null;if(i===-1&&(i=s.gpuType),i!==s.gpuType)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.`),null;a+=s.count*n}let o=new t(a),c=new s(o,n,r),l=0;for(let t=0;t<e.length;++t){let r=e[t];if(r.isInterleavedBufferAttribute){let e=l/n;for(let t=0,i=r.count;t<i;t++)for(let i=0;i<n;i++){let n=r.getComponent(t,i);c.setComponent(t+e,i,n)}}else o.set(r.array,l);l+=r.count*n}return i!==void 0&&(c.gpuType=i),c}function p(e){return e.isInstancedInterleavedBufferAttribute||e.isInterleavedBufferAttribute?h(e):e.isInstancedBufferAttribute?new n().copy(e):new s().copy(e)}function m(e){let t,n=0,r=0;for(let i=0,a=e.length;i<a;++i){let a=e[i];if(t===void 0&&(t=a.array.constructor),t!==a.array.constructor)return console.error(`AttributeBuffers of different types cannot be interleaved`),null;n+=a.array.length,r+=a.itemSize}let o=new i(new t(n),r),s=0,c=[],l=[`getX`,`getY`,`getZ`,`getW`],u=[`setX`,`setY`,`setZ`,`setW`];for(let t=0,n=e.length;t<n;t++){let n=e[t],r=n.itemSize,i=n.count,d=new a(o,r,s,n.normalized);c.push(d),s+=r;for(let e=0;e<i;e++)for(let t=0;t<r;t++)d[u[t]](e,n[l[t]](e))}return c}function h(e){let t=e.data.array.constructor,r=e.count,i=e.itemSize,a=e.normalized,o=new t(r*i),c;c=e.isInstancedInterleavedBufferAttribute?new n(o,i,a,e.meshPerAttribute):new s(o,i,a);for(let t=0;t<r;t++)c.setX(t,e.getX(t)),i>=2&&c.setY(t,e.getY(t)),i>=3&&c.setZ(t,e.getZ(t)),i>=4&&c.setW(t,e.getW(t));return c}function g(e){let t=e.attributes,n=e.morphAttributes,r=new Map;for(let e in t){let n=t[e];n.isInterleavedBufferAttribute&&(r.has(n)||r.set(n,h(n)),t[e]=r.get(n))}for(let e in n){let t=n[e];for(let e=0,n=t.length;e<n;e++){let n=t[e];n.isInterleavedBufferAttribute&&(r.has(n)||r.set(n,h(n)),t[e]=r.get(n))}}}function _(e){let t=0;for(let n in e.attributes){let r=e.getAttribute(n);t+=r.count*r.itemSize*r.array.BYTES_PER_ELEMENT}let n=e.getIndex();return t+=n?n.count*n.itemSize*n.array.BYTES_PER_ELEMENT:0,t}function v(e,t=1e-4){t=Math.max(t,2**-52);let n={},r=e.getIndex(),i=e.getAttribute(`position`),a=r?r.count:i.count,o=0,s=Object.keys(e.attributes),c=[],l=new Map,u=[],d=[`getX`,`getY`,`getZ`,`getW`],f=t*.5,p=10**Math.log10(1/t),m=f*p;for(let t=0;t<a;t++){let i=r?r.getX(t):t,a=``;for(let t=0,n=s.length;t<n;t++){let n=s[t],r=e.getAttribute(n),o=r.itemSize;for(let e=0;e<o;e++)a+=`${Math.trunc(r[d[e]](i)*p+m)},`}a in n?u.push(n[a]):(c.push(i),n[a]=o,u.push(o),o++)}let h=e.clone();for(let t in e.attributes)h.setAttribute(t,C(e.attributes[t],c,l));for(let t in e.morphAttributes)h.morphAttributes[t]=e.morphAttributes[t].map(e=>C(e,c,l));return h.setIndex(u),h}function y(e,t){if(t===0)return console.warn(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.`),e;if(t===2||t===1){let n=e.getIndex();if(n===null){let t=[],r=e.getAttribute(`position`);if(r!==void 0){for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.`),e}let r=n.count-2,i=[];if(t===2)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));return i.length/3!==r&&console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.`),e.setIndex(i),e.clearGroups(),e}return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:`,t),e}function b(e){let n=new r,i=new r,a=new r,o=new r,s=new r,c=new r,l=new r,u=new r,d=new r;function f(e,t,r,f,p,m,h,g){n.fromBufferAttribute(t,p),i.fromBufferAttribute(t,m),a.fromBufferAttribute(t,h);let _=e.morphTargetInfluences;if(r&&_){l.set(0,0,0),u.set(0,0,0),d.set(0,0,0);for(let e=0,t=r.length;e<t;e++){let t=_[e],g=r[e];t!==0&&(o.fromBufferAttribute(g,p),s.fromBufferAttribute(g,m),c.fromBufferAttribute(g,h),f?(l.addScaledVector(o,t),u.addScaledVector(s,t),d.addScaledVector(c,t)):(l.addScaledVector(o.sub(n),t),u.addScaledVector(s.sub(i),t),d.addScaledVector(c.sub(a),t)))}n.add(l),i.add(u),a.add(d)}e.isSkinnedMesh&&(e.applyBoneTransform(p,n),e.applyBoneTransform(m,i),e.applyBoneTransform(h,a)),g[p*3+0]=n.x,g[p*3+1]=n.y,g[p*3+2]=n.z,g[m*3+0]=i.x,g[m*3+1]=i.y,g[m*3+2]=i.z,g[h*3+0]=a.x,g[h*3+1]=a.y,g[h*3+2]=a.z}let p=e.geometry,m=e.material,h,g,_,v=p.index,y=p.attributes.position,b=p.morphAttributes.position,x=p.morphTargetsRelative,S=p.attributes.normal,C=p.morphAttributes.normal,w=p.groups,T=p.drawRange,E,D,O,k,A,j,M,N=new Float32Array(y.count*y.itemSize),P=new Float32Array(S.count*S.itemSize);if(v!==null){if(Array.isArray(m))for(E=0,O=w.length;E<O;E++)for(A=w[E],j=Math.max(A.start,T.start),M=Math.min(A.start+A.count,T.start+T.count),D=j,k=M;D<k;D+=3)h=v.getX(D),g=v.getX(D+1),_=v.getX(D+2),f(e,y,b,x,h,g,_,N),f(e,S,C,x,h,g,_,P);else for(j=Math.max(0,T.start),M=Math.min(v.count,T.start+T.count),E=j,O=M;E<O;E+=3)h=v.getX(E),g=v.getX(E+1),_=v.getX(E+2),f(e,y,b,x,h,g,_,N),f(e,S,C,x,h,g,_,P)}else if(Array.isArray(m))for(E=0,O=w.length;E<O;E++)for(A=w[E],j=Math.max(A.start,T.start),M=Math.min(A.start+A.count,T.start+T.count),D=j,k=M;D<k;D+=3)h=D,g=D+1,_=D+2,f(e,y,b,x,h,g,_,N),f(e,S,C,x,h,g,_,P);else for(j=Math.max(0,T.start),M=Math.min(y.count,T.start+T.count),E=j,O=M;E<O;E+=3)h=E,g=E+1,_=E+2,f(e,y,b,x,h,g,_,N),f(e,S,C,x,h,g,_,P);return{positionAttribute:y,normalAttribute:S,morphedPositionAttribute:new t(N,3),morphedNormalAttribute:new t(P,3)}}function x(e){if(e.groups.length===0)return console.warn(`THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge.`),e;let t=e.groups;if(t=t.sort((e,t)=>e.materialIndex===t.materialIndex?e.start-t.start:e.materialIndex-t.materialIndex),e.getIndex()===null){let t=e.getAttribute(`position`),n=[];for(let e=0;e<t.count;e+=3)n.push(e,e+1,e+2);e.setIndex(n)}let n=e.getIndex(),r=[];for(let e=0;e<t.length;e++){let i=t[e];i.count===1/0&&(i.count=n.count-i.start);let a=i.start,o=a+i.count;for(let e=a;e<o;e++)r.push(n.getX(e))}e.dispose(),e.setIndex(r);let i=0;for(let e=0;e<t.length;e++){let n=t[e];n.start=i,i+=n.count}let a=t[0];e.groups=[a];for(let n=1;n<t.length;n++){let r=t[n];a.materialIndex===r.materialIndex?a.count+=r.count:(a=r,e.groups.push(a))}return e}function S(e,t=Math.PI/3){let n=e.index?e.toNonIndexed():e,r=n.attributes.position,i=r.count,a;if(r.isBufferAttribute===!0&&r.itemSize===3&&r.normalized===!1)a=r.array;else{a=new Float64Array(i*3);for(let e=0;e<i;e++)a[3*e+0]=r.getX(e),a[3*e+1]=r.getY(e),a[3*e+2]=r.getZ(e)}let o=Math.cos(t),c=(1+1e-10)*100,l=i/3,u=new Float64Array(l*3);for(let e=0;e<l;e++){let t=9*e,n=a[t+0],r=a[t+1],i=a[t+2],o=a[t+3],s=a[t+4],c=a[t+5],l=a[t+6],d=a[t+7],f=a[t+8],p=l-o,m=d-s,h=f-c,g=n-o,_=r-s,v=i-c,y=m*v-h*_,b=h*g-p*v,x=p*_-m*g,S=1/(Math.sqrt(y*y+b*b+x*x)||1);u[3*e+0]=y*S,u[3*e+1]=b*S,u[3*e+2]=x*S}let d=new Int32Array(i),f=new Float64Array(i*3),p=1;for(;p<i*2;)p<<=1;let m=p-1,h=new Int32Array(p),g=0;for(let e=0;e<i;e++){let t=3*e,n=Math.trunc(a[t+0]*c),r=Math.trunc(a[t+1]*c),i=Math.trunc(a[t+2]*c),o=(Math.imul(n,73856093)^Math.imul(r,19349663)^Math.imul(i,83492791))&m;for(;;){let t=h[o];if(t===0){let t=3*g;f[t+0]=n,f[t+1]=r,f[t+2]=i,h[o]=g+1,d[e]=g++;break}let a=3*(t-1);if(f[a+0]===n&&f[a+1]===r&&f[a+2]===i){d[e]=t-1;break}o=o+1&m}}let _=new Int32Array(g+1);for(let e=0;e<i;e++)_[d[e]+1]++;for(let e=0;e<g;e++)_[e+1]+=_[e];let v=new Int32Array(i),y=_.slice(0,g);for(let e=0;e<l;e++){let t=3*e;v[y[d[t+0]]++]=e,v[y[d[t+1]]++]=e,v[y[d[t+2]]++]=e}let b=new Float32Array(i*3);for(let e=0;e<l;e++){let t=3*e,n=u[t+0],r=u[t+1],i=u[t+2];for(let e=0;e<3;e++){let a=t+e,s=d[a],c=0,l=0,f=0;for(let e=_[s],t=_[s+1];e<t;e++){let t=3*v[e],a=u[t+0],s=u[t+1],d=u[t+2];n*a+r*s+i*d>o&&(c+=a,l+=s,f+=d)}let p=1/(Math.sqrt(c*c+l*l+f*f)||1);b[3*a+0]=c*p,b[3*a+1]=l*p,b[3*a+2]=f*p}}return n.setAttribute(`normal`,new s(b,3,!1)),n}function C(e,t,n=new Map){let r=e.isInterleavedBufferAttribute,i=r?e.data:e,a=r?i.stride:e.itemSize,o=r?n.get(i):void 0;if(o===void 0){let s=new i.array.constructor(t.length*a);for(let e=0;e<t.length;e++)for(let n=0;n<a;n++)s[e*a+n]=i.array[t[e]*a+n];o=r?new i.constructor(s,a,i.meshPerAttribute):new e.constructor(s,e.itemSize,e.normalized,e.meshPerAttribute),o.setUsage(i.usage),r&&n.set(i,o)}let s=r?new e.constructor(o,e.itemSize,e.offset,e.normalized):o;return s.name=e.name,r||(s.gpuType=e.gpuType),s}export{v as n,y as r,l as t};