@fleox/agent3d 0.3.1 → 0.5.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 (122) hide show
  1. package/README.md +16 -14
  2. package/changelog.json +25 -0
  3. package/dist/agent/agent3d.mjs +802 -90
  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-bJwh2SqG.mjs → export-BSOqVfPT.mjs} +87 -7
  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-fMbw9UGh.mjs → package-DzXqX5Oe.mjs} +2 -2
  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-Cm4BqDkO.mjs → tools-Vs74Xopx.mjs} +153 -14
  22. package/dist/runtime/agent3d-photo.js +72 -0
  23. package/dist/runtime/agent3d-runtime.js +41 -41
  24. package/dist/runtime/agent3d-runtime.single.js +526 -250
  25. package/dist/runtime/chunks/assets-kC2Z1Xy_.js +1 -0
  26. package/dist/runtime/chunks/game-CbQaEB4q.js +20 -0
  27. package/dist/runtime/chunks/materials-jwhXlLYl.js +107 -0
  28. package/dist/runtime/chunks/model-CG5T_jcB.js +1 -0
  29. package/dist/runtime/chunks/num-CQNAlL82.js +1 -0
  30. package/dist/runtime/chunks/photo-Dq-AKlfw.js +526 -0
  31. package/dist/runtime/chunks/physicsHost-BU-2V-CZ.js +1 -0
  32. package/dist/runtime/chunks/{postfx-Cbf_vvOr.js → postfx-DnIeKXAh.js} +1 -1
  33. package/dist/runtime/chunks/postfx-ylpcQcVK.js +1 -0
  34. package/dist/runtime/chunks/svg-fYjsY-rV.js +1 -0
  35. package/dist/runtime/chunks/{text-rSo_2Luk.js → text-CySfj5sH.js} +1 -1
  36. package/dist/runtime/chunks/util-BEflQURG.js +1 -0
  37. package/dist/studio/assets/BufferGeometryUtils-BbzK4rCj.js +1 -0
  38. package/dist/studio/assets/{EXRLoader-BKkzlNd8.js → EXRLoader-CuDOo1xG.js} +1 -1
  39. package/dist/studio/assets/{FontLoader-Bzjx8mXt.js → FontLoader-DlBfss5q.js} +1 -1
  40. package/dist/studio/assets/{GLTFLoader-1Zd9N406.js → GLTFLoader-bl1eymL4.js} +1 -1
  41. package/dist/studio/assets/{GroundedSkybox-BEMqNCBD.js → GroundedSkybox-cLn9JVlt.js} +1 -1
  42. package/dist/studio/assets/{HDRLoader-DxB0kxPH.js → HDRLoader-8EiZoQQP.js} +1 -1
  43. package/dist/studio/assets/{OrbitControls-MlE9XiCg.js → OrbitControls-1xEm394I.js} +1 -1
  44. package/dist/studio/assets/{RectAreaLightUniformsLib-ClHrtYY6.js → RectAreaLightUniformsLib-S0AelTmO.js} +1 -1
  45. package/dist/studio/assets/{RoomEnvironment-MJ-jIEC8.js → RoomEnvironment-v4QurKxu.js} +1 -1
  46. package/dist/studio/assets/{SVGLoader-CIYl0nEy.js → SVGLoader-KDBVv02P.js} +1 -1
  47. package/dist/studio/assets/{Sky-DNMfpp92.js → Sky-D8Lp9Zh3.js} +1 -1
  48. package/dist/studio/assets/assets-DnOt59SU.js +2 -0
  49. package/dist/studio/assets/camera-DrubOxWu.js +2 -0
  50. package/dist/studio/assets/catalog-DDg904x2.js +1 -0
  51. package/dist/studio/assets/{editor-NkBUKsDB.js → editor-V--luWVq.js} +1 -1
  52. package/dist/studio/assets/{extrude-9bG8hr2C.js → extrude-BpJda0hq.js} +1 -1
  53. package/dist/studio/assets/game-43BhY_EE.js +19 -0
  54. package/dist/studio/assets/{generators-BjIs-kHx.js → generators-lG93qWTO.js} +5 -5
  55. package/dist/studio/assets/index-BPVRhKVV.js +479 -0
  56. package/dist/studio/assets/index-D-TPNQMQ.css +1 -0
  57. package/dist/studio/assets/model-D8-inS_D.js +2 -0
  58. package/dist/studio/assets/num-CQNAlL82.js +1 -0
  59. package/dist/studio/assets/params-BZqUA__U.js +1 -0
  60. package/dist/studio/assets/photo-BuVK-UvQ.js +526 -0
  61. package/dist/studio/assets/physicsHost-EkPuIy04.js +1 -0
  62. package/dist/studio/assets/{postfx-BGu30OJK.js → postfx-Bcnem9ci.js} +13 -13
  63. package/dist/studio/assets/rolldown-runtime-4tVxZq34.js +1 -0
  64. package/dist/studio/assets/runtime-5Ti8UJJR.js +572 -0
  65. package/dist/studio/assets/{shaders-Dt6FGXH_.js → shaders-WM5brr9C.js} +1 -1
  66. package/dist/studio/assets/svg-CJ_RtiER.js +2 -0
  67. package/dist/studio/assets/text-NO7lyCoH.js +3 -0
  68. package/dist/studio/assets/three.module-B9FlcKtd.js +4225 -0
  69. package/dist/studio/index.html +5 -3
  70. package/package.json +2 -2
  71. package/plugin/.claude-plugin/plugin.json +1 -1
  72. package/plugin/skills/agent3d-assets/SKILL.md +42 -27
  73. package/plugin/skills/agent3d-create/SKILL.md +77 -29
  74. package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
  75. package/plugin/skills/agent3d-create/references/recipes.md +6 -6
  76. package/plugin/skills/agent3d-edit/SKILL.md +22 -22
  77. package/plugin/skills/agent3d-edit/references/patch-ops.md +3 -3
  78. package/plugin/skills/agent3d-game/SKILL.md +7 -7
  79. package/plugin/skills/agent3d-publish/SKILL.md +32 -23
  80. package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
  81. package/templates/hero-scroll-story/README.md +1 -1
  82. package/templates/photo-scroll-story/README.md +29 -0
  83. package/templates/photo-scroll-story/agent3d.json +8 -0
  84. package/templates/photo-scroll-story/assets/depth/lake-depth.png +0 -0
  85. package/templates/photo-scroll-story/assets/depth/street-depth.png +0 -0
  86. package/templates/photo-scroll-story/assets/manifest.json +46 -0
  87. package/templates/photo-scroll-story/assets/textures/lake.webp +0 -0
  88. package/templates/photo-scroll-story/assets/textures/street.webp +0 -0
  89. package/templates/photo-scroll-story/preview.png +0 -0
  90. package/templates/photo-scroll-story/scene.json +112 -0
  91. package/templates/photo-scroll-story/template.json +8 -0
  92. package/templates/photo-title-inside/README.md +31 -0
  93. package/templates/photo-title-inside/agent3d.json +8 -0
  94. package/templates/photo-title-inside/assets/depth/street-depth.png +0 -0
  95. package/templates/photo-title-inside/assets/manifest.json +25 -0
  96. package/templates/photo-title-inside/assets/textures/street.webp +0 -0
  97. package/templates/photo-title-inside/preview.png +0 -0
  98. package/templates/photo-title-inside/scene.json +80 -0
  99. package/templates/photo-title-inside/template.json +8 -0
  100. package/dist/runtime/chunks/assets-qnxDnVkj.js +0 -1
  101. package/dist/runtime/chunks/game-BoEiyZrL.js +0 -20
  102. package/dist/runtime/chunks/materials-dC4vDNHh.js +0 -107
  103. package/dist/runtime/chunks/model-BCAl_NRl.js +0 -1
  104. package/dist/runtime/chunks/photo-DNf14X7B.js +0 -250
  105. package/dist/runtime/chunks/physicsHost-ChPgysMQ.js +0 -1
  106. package/dist/runtime/chunks/postfx-CFucYRev.js +0 -1
  107. package/dist/runtime/chunks/svg-CLUxY6Zy.js +0 -1
  108. package/dist/runtime/chunks/util-CyaW1fcW.js +0 -1
  109. package/dist/studio/assets/BufferGeometryUtils-CAlXAboW.js +0 -1
  110. package/dist/studio/assets/assets-BW5lQkYR.js +0 -1
  111. package/dist/studio/assets/camera-BgzPVnn-.js +0 -2
  112. package/dist/studio/assets/game-DARpu0ah.js +0 -19
  113. package/dist/studio/assets/index-BQT0otii.css +0 -1
  114. package/dist/studio/assets/index-L-N-e2KM.js +0 -479
  115. package/dist/studio/assets/model-CqI8j03Z.js +0 -2
  116. package/dist/studio/assets/params-DhsDKSDs.js +0 -1
  117. package/dist/studio/assets/photo-DAHd1yNF.js +0 -250
  118. package/dist/studio/assets/physicsHost-tEUto2-_.js +0 -1
  119. package/dist/studio/assets/runtime-C_qkIpAK.js +0 -572
  120. package/dist/studio/assets/svg-ZZt5MdNf.js +0 -2
  121. package/dist/studio/assets/text-B-HM422i.js +0 -3
  122. package/dist/studio/assets/three.module-CnI50X0U.js +0 -4225
@@ -1,20 +0,0 @@
1
- import{Lt as e,Mn as t,Nn as n,Yt as r}from"./three.module-DnaBiDAJ.js";import{t as i}from"./random-eeej60NW.js";import{d as a,s as o,t as s}from"./util-CyaW1fcW.js";function c(e,t,n){let r=null,i=null,a=!!e?.muted,o=null,s=/* @__PURE__ */ new Map,c=null,l=!!e?.music,u=()=>import(`./audio-DbVNbf-r.js`).then(e=>o=e.SOUND_IMPLS).catch(()=>o={}),d=e=>{let i=s.get(e);if(!i&&r){let a=r;i=fetch(t(e)).then(e=>e.arrayBuffer()).then(e=>a.decodeAudioData(e)).catch(t=>(n(t.message,e),null)),s.set(e,i)}return i??Promise.resolve(null)},f=(e,t=!1)=>{if(!r||!i)return null;let n=e.volume??1;if(e.preset){let t=o?.[e.preset];return t?t.play(r,i,n):null}if(e.src){let a=r,o=i,s=null,c=!1;return d(e.src).then(e=>{if(!e||c)return;s=a.createBufferSource(),s.buffer=e,s.loop=t;let r=a.createGain();r.gain.value=n,s.connect(r).connect(o),s.start()}),{stop(){c=!0;try{s?.stop()}catch{}}}}return null},p=()=>{!c&&e?.music&&!a&&r&&(c=f(e.music,e.music.loop!==!1))};return u(),{play(t){if(a||!r)return;let n=e?.sounds?.[t];n?f(n):o?.[t]&&o[t].play(r,i,1)},music(e){l=e,e?p():(c?.stop(),c=null)},muted:()=>a,setMuted(t){a=t,i&&r&&i.gain.setTargetAtTime(+!t,r.currentTime,.02),t?(c?.stop(),c=null):(l||e?.music)&&(l=!0,p())},unlock(){if(r){r.state===`suspended`&&r.resume();return}let e=globalThis.AudioContext??globalThis.webkitAudioContext;if(e)try{r=new e,i=r.createGain(),i.gain.value=+!a,i.connect(r.destination),l&&p()}catch(e){n(e.message)}},dispose(){c?.stop(),r?.close().catch(()=>void 0),r=null}}}var l={aliceblue:`f0f8ff`,antiquewhite:`faebd7`,aqua:`00ffff`,aquamarine:`7fffd4`,azure:`f0ffff`,beige:`f5f5dc`,bisque:`ffe4c4`,black:`000000`,blanchedalmond:`ffebcd`,blue:`0000ff`,blueviolet:`8a2be2`,brown:`a52a2a`,burlywood:`deb887`,cadetblue:`5f9ea0`,chartreuse:`7fff00`,chocolate:`d2691e`,coral:`ff7f50`,cornflowerblue:`6495ed`,cornsilk:`fff8dc`,crimson:`dc143c`,cyan:`00ffff`,darkblue:`00008b`,darkcyan:`008b8b`,darkgoldenrod:`b8860b`,darkgray:`a9a9a9`,darkgreen:`006400`,darkgrey:`a9a9a9`,darkkhaki:`bdb76b`,darkmagenta:`8b008b`,darkolivegreen:`556b2f`,darkorange:`ff8c00`,darkorchid:`9932cc`,darkred:`8b0000`,darksalmon:`e9967a`,darkseagreen:`8fbc8f`,darkslateblue:`483d8b`,darkslategray:`2f4f4f`,darkslategrey:`2f4f4f`,darkturquoise:`00ced1`,darkviolet:`9400d3`,deeppink:`ff1493`,deepskyblue:`00bfff`,dimgray:`696969`,dimgrey:`696969`,dodgerblue:`1e90ff`,firebrick:`b22222`,floralwhite:`fffaf0`,forestgreen:`228b22`,fuchsia:`ff00ff`,gainsboro:`dcdcdc`,ghostwhite:`f8f8ff`,gold:`ffd700`,goldenrod:`daa520`,gray:`808080`,green:`008000`,greenyellow:`adff2f`,grey:`808080`,honeydew:`f0fff0`,hotpink:`ff69b4`,indianred:`cd5c5c`,indigo:`4b0082`,ivory:`fffff0`,khaki:`f0e68c`,lavender:`e6e6fa`,lavenderblush:`fff0f5`,lawngreen:`7cfc00`,lemonchiffon:`fffacd`,lightblue:`add8e6`,lightcoral:`f08080`,lightcyan:`e0ffff`,lightgoldenrodyellow:`fafad2`,lightgray:`d3d3d3`,lightgreen:`90ee90`,lightgrey:`d3d3d3`,lightpink:`ffb6c1`,lightsalmon:`ffa07a`,lightseagreen:`20b2aa`,lightskyblue:`87cefa`,lightslategray:`778899`,lightslategrey:`778899`,lightsteelblue:`b0c4de`,lightyellow:`ffffe0`,lime:`00ff00`,limegreen:`32cd32`,linen:`faf0e6`,magenta:`ff00ff`,maroon:`800000`,mediumaquamarine:`66cdaa`,mediumblue:`0000cd`,mediumorchid:`ba55d3`,mediumpurple:`9370db`,mediumseagreen:`3cb371`,mediumslateblue:`7b68ee`,mediumspringgreen:`00fa9a`,mediumturquoise:`48d1cc`,mediumvioletred:`c71585`,midnightblue:`191970`,mintcream:`f5fffa`,mistyrose:`ffe4e1`,moccasin:`ffe4b5`,navajowhite:`ffdead`,navy:`000080`,oldlace:`fdf5e6`,olive:`808000`,olivedrab:`6b8e23`,orange:`ffa500`,orangered:`ff4500`,orchid:`da70d6`,palegoldenrod:`eee8aa`,palegreen:`98fb98`,paleturquoise:`afeeee`,palevioletred:`db7093`,papayawhip:`ffefd5`,peachpuff:`ffdab9`,peru:`cd853f`,pink:`ffc0cb`,plum:`dda0dd`,powderblue:`b0e0e6`,purple:`800080`,rebeccapurple:`663399`,red:`ff0000`,rosybrown:`bc8f8f`,royalblue:`4169e1`,saddlebrown:`8b4513`,salmon:`fa8072`,sandybrown:`f4a460`,seagreen:`2e8b57`,seashell:`fff5ee`,sienna:`a0522d`,silver:`c0c0c0`,skyblue:`87ceeb`,slateblue:`6a5acd`,slategray:`708090`,slategrey:`708090`,snow:`fffafa`,springgreen:`00ff7f`,steelblue:`4682b4`,tan:`d2b48c`,teal:`008080`,thistle:`d8bfd8`,tomato:`ff6347`,turquoise:`40e0d0`,violet:`ee82ee`,wheat:`f5deb3`,white:`ffffff`,whitesmoke:`f5f5f5`,yellow:`ffff00`,yellowgreen:`9acd32`},u=(e,t,n)=>Math.min(n,Math.max(t,e));function d(e){if(!/^[0-9a-f]+$/i.test(e)||((e.length===3||e.length===4)&&(e=[...e].map(e=>e+e).join(``)),e.length!==6&&e.length!==8))return null;let t=t=>parseInt(e.slice(t,t+2),16);return{r:t(0),g:t(2),b:t(4),a:e.length===8?t(6)/255:1}}function f(e,t){let n=/^(-?\d*\.?\d+(?:e-?\d+)?)(%?)$/i.exec(e.trim());if(!n)return null;let r=Number(n[1]);return n[2]?r/100*t:r}function p(e){let t=/^(-?\d*\.?\d+)(deg|rad|turn|grad)?$/i.exec(e.trim());if(!t)return null;let n=Number(t[1]);switch((t[2]??`deg`).toLowerCase()){case`rad`:return n*180/Math.PI;case`turn`:return n*360;case`grad`:return n*.9;default:return n}}function m(e){let t=e.split(`/`);if(t.length>2)return null;let n=(t[0].includes(`,`)?t[0].split(`,`):t[0].trim().split(/\s+/)).map(e=>e.trim()).filter(e=>e!==``);return t.length===2&&n.push(t[1].trim()),n}function h(e,t,n){e=(e%360+360)%360;let r=(1-Math.abs(2*n-1))*t,i=r*(1-Math.abs(e/60%2-1)),a=n-r/2,[o,s,c]=e<60?[r,i,0]:e<120?[i,r,0]:e<180?[0,r,i]:e<240?[0,i,r]:e<300?[i,0,r]:[r,0,i];return[(o+a)*255,(s+a)*255,(c+a)*255]}function g(e){if(typeof e!=`string`)return null;let t=e.trim().toLowerCase();if(!t)return null;if(t.startsWith(`#`))return d(t.slice(1));if(t===`transparent`)return{r:0,g:0,b:0,a:0};let n=l[t];if(n)return d(n);let r=/^(rgba?|hsla?)\((.*)\)$/.exec(t);if(!r)return null;let i=m(r[2]);if(!i||i.length!==3&&i.length!==4)return null;let a=i.length===4?f(i[3],1):1;if(a===null)return null;if(r[1].startsWith(`rgb`)){let[e,t,n]=i.slice(0,3).map(e=>f(e,255));return e===null||t===null||n===null?null:{r:u(e,0,255),g:u(t,0,255),b:u(n,0,255),a:u(a,0,1)}}let o=p(i[0]),s=f(i[1],1),c=f(i[2],1);if(o===null||s===null||c===null||!i[1].trim().endsWith(`%`)||!i[2].trim().endsWith(`%`))return null;let[g,_,v]=h(o,u(s,0,1),u(c,0,1));return{r:g,g:_,b:v,a:u(a,0,1)}}function _(e){let t=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return .2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}function v(e,t){let n=_(e),r=_(t);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)}function y(e){let t=g(e);return t?v(t,{r:255,g:255,b:255,a:1})>=v(t,{r:17,g:19,b:24,a:1})?`#ffffff`:`#111318`:`#ffffff`}function b(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(/\s/.test(r)){n++;continue}if(/[0-9]/.test(r)||r===`-`&&/[0-9]/.test(e[n+1]??``)&&(t.length===0||t[t.length-1].t===`op`)){let r=n+1;for(;r<e.length&&/[0-9.]/.test(e[r]);)r++;t.push({t:`num`,v:Number(e.slice(n,r))}),n=r;continue}if(r===`'`||r===`"`){let i=n+1,a=``;for(;i<e.length&&e[i]!==r;)e[i]===`\\`&&i+1<e.length&&i++,a+=e[i++];if(i>=e.length)throw Error(`Unterminated string`);t.push({t:`str`,v:a}),n=i+1;continue}if(/[A-Za-z_$]/.test(r)){let r=n+1;for(;r<e.length&&/[A-Za-z0-9_$.]/.test(e[r]);)r++;t.push({t:`id`,v:e.slice(n,r)}),n=r;continue}let i=e.slice(n,n+3),a=e.slice(n,n+2);if(i===`===`||i===`!==`)t.push({t:`op`,v:i.slice(0,2)}),n+=3;else if([`==`,`!=`,`>=`,`<=`,`&&`,`||`].includes(a))t.push({t:`op`,v:a}),n+=2;else if(`!<>()`.includes(r))t.push({t:`op`,v:r}),n++;else throw Error(`Unexpected "${r}"`)}return t}var x=/* @__PURE__ */ new Set([`__proto__`,`prototype`,`constructor`]);function S(e,t){let n=t.split(`.`);n[0]===`state`&&n.shift();let r=e;for(let e of n){if(x.has(e)||typeof r!=`object`||!r||!Object.prototype.hasOwnProperty.call(r,e))return;r=r[e]}return r}function C(e,t){let n=b(e),r=0,i=()=>n[r],a=e=>i()?.t===`op`&&i().v===e;function o(){let e=n[r++];if(!e)throw Error(`Unexpected end`);if(e.t===`num`||e.t===`str`)return e.v;if(e.t===`id`)return e.v===`true`?!0:e.v===`false`?!1:e.v===`null`||e.v===`undefined`?null:S(t,e.v);if(e.v===`(`){let e=u();if(!a(`)`))throw Error(`Missing )`);return r++,e}throw Error(`Unexpected "${e.v}"`)}function s(){let e=o(),t=i();if(t?.t===`op`&&[`==`,`!=`,`>`,`<`,`>=`,`<=`].includes(t.v)){r++;let n=o(),i=e,a=n;switch(t.v){case`==`:return e==n||e==null&&n==null;case`!=`:return e!=n;case`>`:return i>a;case`<`:return i<a;case`>=`:return i>=a;default:return i<=a}}return e}function c(){return a(`!`)?(r++,!c()):s()}function l(){let e=c();for(;a(`&&`);){r++;let t=c();e&&=t}return e}function u(){let e=l();for(;a(`||`);){r++;let t=l();e||=t}return e}let d=u();if(r<n.length)throw Error(`Unexpected "${n[r].v}"`);return d}function w(e,t){if(e===void 0)return!0;if(typeof e==`boolean`)return e;try{return!!C(e,t)}catch{return!1}}function T(e,t){return e.replace(/\{([^{}]+)\}/g,(e,n)=>{let r=n.trim(),i;try{i=/^[A-Za-z_$][A-Za-z0-9_$.]*$/.test(r)?S(t,r):C(r,t)}catch{i=void 0}return i==null?``:String(typeof i==`number`?Number.isInteger(i)?i:Math.round(i*100)/100:i)})}var E={"top-left":`grid-row:1;grid-column:1;align-items:flex-start;align-self:start;`,top:`grid-row:1;grid-column:2;align-items:center;align-self:start;text-align:center;`,"top-right":`grid-row:1;grid-column:3;align-items:flex-end;align-self:start;text-align:right;`,left:`grid-row:2;grid-column:1;align-items:flex-start;align-self:center;`,center:`grid-row:2;grid-column:2;align-items:center;align-self:center;text-align:center;`,right:`grid-row:2;grid-column:3;align-items:flex-end;align-self:center;text-align:right;`,"bottom-left":`grid-row:3;grid-column:1;align-items:flex-start;align-self:end;`,bottom:`grid-row:3;grid-column:2;align-items:center;align-self:end;text-align:center;`,"bottom-right":`grid-row:3;grid-column:3;align-items:flex-end;align-self:end;text-align:right;`},D=(e,t,n)=>`font-size:${n}px;font-size:clamp(${e}px,min(${t}cqw,${(t*1.6).toFixed(1)}cqh),${n}px)`,O=(e,t,n,r)=>`
2
- .a3d-hud{position:absolute;inset:0;pointer-events:none;font-family:${e};color:${t};z-index:2;overflow:hidden;user-select:none;-webkit-user-select:none;container-type:size;display:grid;grid-template-columns:minmax(min-content,1fr) fit-content(56%) minmax(min-content,1fr);grid-template-rows:auto minmax(0,1fr) auto}
3
- .a3d-zone{display:flex;flex-direction:column;gap:8px;gap:clamp(4px,1.6cqw,8px);padding:14px;padding:clamp(8px,2.6cqw,14px);min-width:0;max-width:100%;box-sizing:border-box}
4
- .a3d-el{line-height:1.2;text-shadow:0 1px 3px rgba(0,0,0,.45);white-space:pre-line;overflow-wrap:break-word}
5
- .a3d-plain{${D(11,3.2,15)};font-weight:600}
6
- .a3d-pill{${D(11,3,14)};font-weight:700;padding:.43em 1em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;box-sizing:border-box;flex:none;border-radius:999px;background:rgba(0,0,0,.42);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);text-shadow:none}
7
- .a3d-title{${D(20,7,44)};font-weight:800;letter-spacing:-.01em}
8
- .a3d-subtitle{${D(12,3.6,18)};font-weight:500;opacity:.9}
9
- .a3d-panel{${D(13,3.6,18)};font-weight:600;line-height:1.45;padding:1.1em 1.6em;border-radius:18px;background:rgba(10,12,20,.72);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);box-shadow:0 10px 34px rgba(0,0,0,.35);text-shadow:none;max-width:100%;box-sizing:border-box}
10
- .a3d-panel::first-line{font-size:1.45em;font-weight:800}
11
- .a3d-btn{pointer-events:auto;cursor:pointer;border:0;font:inherit;${D(12,3.4,15)};font-weight:700;color:${r};background:${n};padding:.67em 1.47em;border-radius:999px;box-shadow:0 4px 14px rgba(0,0,0,.25);transition:transform .12s ease,filter .12s ease;text-shadow:none;min-height:36px}
12
- .a3d-btn:hover{transform:translateY(-1px);filter:brightness(1.08)}.a3d-btn:active{transform:translateY(1px)}
13
- .a3d-bar{width:160px;width:clamp(80px,30cqw,160px);height:10px;height:clamp(7px,2cqw,10px);border-radius:999px;background:rgba(0,0,0,.35);overflow:hidden}
14
- .a3d-bar>i{display:block;height:100%;width:0;background:${n};border-radius:inherit}
15
- .a3d-toast{position:absolute;left:50%;bottom:18%;transform:translateX(-50%);max-width:86%;box-sizing:border-box;text-align:center;padding:.53em 1.2em;border-radius:999px;background:rgba(0,0,0,.6);color:#fff;font-weight:700;${D(12,3.4,15)};transition:opacity .25s ease;text-shadow:none}
16
- .a3d-mute{pointer-events:auto;width:34px;height:34px;width:clamp(28px,8cqw,34px);height:clamp(28px,8cqw,34px);border-radius:50%;border:0;background:rgba(0,0,0,.4);color:#fff;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0;flex:none}
17
- .a3d-mute svg{width:55%;height:55%}
18
- `,k=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H2v6h4l5 4V5z"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/><path d="M19 5a10 10 0 0 1 0 14"/></svg>`,A=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5 6 9H2v6h4l5 4V5z"/><path d="m23 9-6 6"/><path d="m17 9 6 6"/></svg>`;function j(e,t,n){let r=e.ownerDocument,i=r.createElement(`div`);i.className=`a3d-hud`,i.setAttribute(`aria-live`,`polite`);let a=r.createElement(`style`),o=t?.accent??`#ff006e`;a.textContent=O(t?.font??`system-ui,-apple-system,'Segoe UI',Roboto,sans-serif`,t?.color??`#ffffff`,o,t?.buttonText??y(o)),i.appendChild(a);let s=/* @__PURE__ */ new Map,c=e=>{let t=s.get(e);return t||(t=r.createElement(`div`),t.className=`a3d-zone`,t.style.cssText=E[e]??E[`top-left`],t.dataset.anchor=e,i.appendChild(t),s.set(e,t)),t},l=[[`top-left`,`top`,`top-right`],[`left`,`center`,`right`],[`bottom-left`,`bottom`,`bottom-right`]],u=()=>{for(let[e,t,n]of l){let r=s.get(t);r&&(r.style.gridColumn=s.has(e)||s.has(n)?`2`:`1 / -1`)}},d=/* @__PURE__ */ new Map;for(let e of t?.elements??[]){let t,i;if(e.type===`button`){let i=r.createElement(`button`);i.type=`button`,i.className=`a3d-btn`,i.addEventListener(`click`,t=>{t.stopPropagation(),e.action&&n(e.action)}),i.addEventListener(`pointerdown`,e=>e.stopPropagation()),t=i}else e.type===`bar`?(t=r.createElement(`div`),t.className=`a3d-bar`,i=r.createElement(`i`),t.appendChild(i)):(t=r.createElement(`div`),t.className=`a3d-el a3d-${e.style??`plain`}`);e.color&&(t.style.color=e.color,e.type===`bar`&&i&&(i.style.background=e.color)),e.background&&(t.style.background=e.background),e.type===`button`&&e.background&&!e.color&&(t.style.color=y(e.background)),t.dataset.id=e.id,c(e.anchor??`top-left`).appendChild(t),d.set(e.id,{def:e,node:t,fill:i,override:{},last:``})}u(),e.appendChild(i);let f=null,p=0,m=null,h=null,g=null;return{root:i,setTimeline(e){g=e},set(e,t){let n=d.get(e);n&&Object.assign(n.override,t)},toast(e,t=2){m={text:e,seconds:t}},update(e,t){let n=g&&!Object.prototype.hasOwnProperty.call(e,`timeline`)?{...e,timeline:g}:e;for(let e of d.values()){let t=e.override.visible??w(e.def.visible,n);if(e.node.style.display=t?``:`none`,!t)continue;if(e.def.type===`bar`){let t=e.override.value??Number(e.def.value?S(n,e.def.value):0),r=Math.max(0,Math.min(1,Number.isFinite(t)?t:0));e.fill.style.width=`${(r*100).toFixed(1)}%`;continue}let r=e.override.text??T(e.def.text??``,n);r!==e.last&&(e.node.textContent=r,e.last=r)}m&&=(f||(f=r.createElement(`div`),f.className=`a3d-toast`,i.appendChild(f)),f.textContent=m.text,f.style.opacity=`1`,p=t+m.seconds,null),f&&t>p&&(f.style.opacity=`0`)},setMuteButton(e,t){e===null?(h?.remove(),h=null):(h||(h=r.createElement(`button`),h.type=`button`,h.className=`a3d-mute`,h.addEventListener(`pointerdown`,e=>e.stopPropagation()),h.addEventListener(`click`,e=>{e.stopPropagation(),t?.()}),c(`bottom-right`).appendChild(h),u()),h.innerHTML=e?A:k,h.setAttribute(`aria-label`,e?`Unmute sound`:`Mute sound`))},dispose(){i.remove()}}}var M=null,N=()=>M??=import(`./physicsHost-ChPgysMQ.js`);function P(e,t=1,n){return{get x(){return e().x/t},set x(r){e().x=r*t,n?.()},get y(){return e().y/t},set y(r){e().y=r*t,n?.()},get z(){return e().z/t},set z(r){e().z=r*t,n?.()},set(r,i,a){e().set(r*t,i*t,a*t),n?.()}}}var F=/* @__PURE__ */ new Map,I=class l{opts;world;physics=null;state={};hud=null;audio;instances=[];factories=[];objCache=/* @__PURE__ */ new Map;handlers=/* @__PURE__ */ new Map;collisionHandlers=[];collisionEndHandlers=[];triggerEnterHandlers=[];triggerExitHandlers=[];rng;simTime=0;acc=0;stepDt;pendingPressed=/* @__PURE__ */ new Set;pendingJust=!1;pendingSwipe=null;stepPressed=/* @__PURE__ */ new Set;stepJust=!1;stepSwipe=null;shake={intensity:0,duration:0,until:0};restartRequested=!1;cloneCounter=0;unlockListeners=null;api;constructor(e){this.opts=e,this.stepDt=Math.min(Math.max(e.scene.physics?.step??1/60,1/480),1/10),this.rng=i(e.scene.seed??1),this.audio=c(e.scene.audio,e.resolveAsset,(t,n)=>e.issue({code:`asset-load`,message:t,path:n})),this.api=this.createApi()}static async create(e,t){let n=new l(e);if(n.hud=e.scene.ui?.elements?.length||e.scene.audio?j(e.container,e.scene.ui,e=>n.emit(e)):null,e.scene.audio&&n.hud){let e=()=>n.hud.setMuteButton(n.audio.muted(),()=>{n.audio.unlock(),n.audio.setMuted(!n.audio.muted()),e()});e()}if(!e.deterministic){let t=()=>n.audio.unlock();e.container.addEventListener(`pointerdown`,t),e.container.addEventListener(`keydown`,t),n.unlockListeners=()=>{e.container.removeEventListener(`pointerdown`,t),e.container.removeEventListener(`keydown`,t)}}return await n.loadScripts(),await n.attach(t),n}async loadScripts(){let{scene:e,scriptSources:t,resolveAsset:n,issue:r}=this.opts;for(let i of e.scripts??[]){let e=t?.[i],a=e===void 0?n(i):`src:${i}:${e.length}:${e.slice(0,64)}`,o=F.get(a);o||(o=(async()=>{let t,r=null;e===void 0?t=n(i):(t=URL.createObjectURL(new Blob([e],{type:`text/javascript`})),r=t);try{let e=await import(
19
- /* @vite-ignore */
20
- t);if(typeof e.default!=`function`)throw Error(`the default export must be a function (api) => ({ start, update })`);return e.default}finally{r&&URL.revokeObjectURL(r)}})(),o.catch(()=>F.delete(a)),F.set(a,o));try{let e=await o;e&&this.factories.push({path:i,factory:e})}catch(e){r({code:`script-error`,message:`${i}: ${e.message}`,path:i})}}}async attach(e){this.world=e,this.objCache.clear(),this.physics?.dispose(),this.physics=null,e.scene.updateMatrixWorld(!0),this.needsPhysics(e)&&await this.ensurePhysics(),this.instances=[];for(let{path:e,factory:t}of this.factories)try{this.instances.push({path:e,inst:t(this.api)??{},failed:!1})}catch(t){this.opts.issue({code:`script-error`,message:`${e}: ${t.message}`,path:e})}for(let e of this.instances)try{await e.inst.start?.()}catch(t){e.failed=!0,this.opts.issue({code:`script-error`,message:`${e.path} start(): ${t.message}`,path:e.path})}this.hud?.update(this.state,0)}needsPhysics(e){if(this.opts.scene.physics?.joints?.length)return!0;for(let t of e.entries.values())if(t.kind!==`light`&&(t.def.body||Array.isArray(t.object.userData.bodies)))return!0;return!1}async ensurePhysics(){if(this.physics)return this.physics;let{PhysicsBridge:e}=await N(),t=new e(this.opts.scene.physics,this.world,e=>this.opts.issue(e));return t.engine.onCollision((e,t,n)=>this.dispatchContact(e.id,t.id,n)),t.engine.onCollisionEnd((e,t)=>this.dispatchContact(e.id,t.id,null)),this.physics=t,t.attachAll(),t}dispatchContact(e,t,n){let r=this.api.get(e),i=this.api.get(t);if(!r||!i||!this.physics)return;let a=this.physics.engine.get(e)?.type===`trigger`,o=this.physics.engine.get(t)?.type===`trigger`;if(n){for(let e of this.collisionHandlers)this.safe(()=>e(r,i,n),`onCollision`);for(let e of this.triggerEnterHandlers)a&&this.safe(()=>e(r,i),`onTriggerEnter`),o&&this.safe(()=>e(i,r),`onTriggerEnter`)}else{for(let e of this.collisionEndHandlers)this.safe(()=>e(r,i),`onCollisionEnd`);for(let e of this.triggerExitHandlers)a&&this.safe(()=>e(r,i),`onTriggerExit`),o&&this.safe(()=>e(i,r),`onTriggerExit`)}}async addBodies(e,t){let n=[];e.object.traverse(e=>{let t=e.userData.a3dId;t&&!n.includes(t)&&n.push(t)});let r=n.map(e=>this.world.entries.get(e)).filter(e=>!!e).filter(n=>n===e&&t||n.def.body);if(!r.length)return;let i=await this.ensurePhysics();for(let n of r)i.has(n.id)||i.addEntry(n,n===e?t:void 0)}requestRestart(){this.restartRequested=!0}get pendingRestart(){return this.restartRequested}async restart(){this.restartRequested=!1;for(let e of this.instances)this.safe(()=>e.inst.dispose?.(),`dispose`);for(let e of Object.keys(this.state))delete this.state[e];this.handlers.clear(),this.collisionHandlers=[],this.collisionEndHandlers=[],this.triggerEnterHandlers=[],this.triggerExitHandlers=[],this.rng=i(this.opts.scene.seed??1),this.simTime=0,this.acc=0,this.shake={intensity:0,duration:0,until:0};let e=await this.opts.rebuild();return await this.attach(e),e}time(){return this.simTime}advance(e){let t=this.opts.input;for(let e of t.pressed)this.pendingPressed.add(e);t.pointer.justPressed&&(this.pendingJust=!0),t.swipe&&(this.pendingSwipe=t.swipe),this.acc+=Math.min(e,.25);let n=0;for(;this.acc>=this.stepDt-1e-9&&n<30;)this.fixedStep(),this.acc-=this.stepDt,n++}advanceTo(e){let t=this.opts.input;for(let e of t.pressed)this.pendingPressed.add(e);for(t.pointer.justPressed&&(this.pendingJust=!0),t.swipe&&(this.pendingSwipe=t.swipe);this.simTime+this.stepDt<=e+1e-9;)this.fixedStep()}fixedStep(){this.stepPressed=this.pendingPressed,this.pendingPressed=/* @__PURE__ */ new Set,this.stepJust=this.pendingJust,this.pendingJust=!1,this.stepSwipe=this.pendingSwipe,this.pendingSwipe=null;let e=this.stepDt;this.simTime+=e;for(let t of this.instances)if(!t.failed&&t.inst.update)try{t.inst.update(e,this.simTime)}catch(e){t.failed=!0,this.opts.issue({code:`script-error`,message:`${t.path} update(): ${e.message}`,path:t.path})}this.physics?.step(e),this.stepPressed=/* @__PURE__ */ new Set,this.stepJust=!1,this.stepSwipe=null}afterFrame(){let e=this.world.rig,t=this.simTime;if(t<this.shake.until&&this.shake.duration>0){let n=(this.shake.until-t)/this.shake.duration*this.shake.intensity;e.shake.set((this.rng.next()-.5)*2*n,(this.rng.next()-.5)*2*n,(this.rng.next()-.5)*n)}else e.shake.set(0,0,0);this.hud?.update(this.state,t)}emit(e,t){for(let n of this.handlers.get(e)??[])this.safe(()=>n(t),`on(${e})`);for(let n of this.instances)!n.failed&&n.inst.onEvent&&this.safe(()=>n.inst.onEvent(e,t),`onEvent`)}safe(e,t){try{e()}catch(e){this.opts.issue({code:`script-error`,message:`${t}: ${e.message}`})}}dispose(){for(let e of this.instances)this.safe(()=>e.inst.dispose?.(),`dispose`);this.instances=[],this.physics?.dispose(),this.hud?.dispose(),this.audio.dispose(),this.unlockListeners?.()}wrap(e){let t=this.objCache.get(e.id);if(t)return t;let r=this,i=e.id,c=()=>r.world.entries.get(i)??e,l=()=>{let e=c();e.animated&&(e.rest.position.copy(e.object.position),e.rest.quaternion.copy(e.object.quaternion),e.rest.scale.copy(e.object.scale)),r.physics?.moved(i)},u=()=>r.physics?.engine.get(i)?.velocity??[0,0,0],d=(e,t)=>{let n=u();n[e]=t,r.physics?.engine.setVelocity(i,n)},f={id:i,position:P(()=>c().object.position,1,l),rotation:P(()=>c().object.rotation,s,l),scale:P(()=>c().object.scale,1,l),get visible(){return c().object.visible},set visible(e){let t=c();t.object.visible=e,t.rest.visible=e},velocity:{get x(){return u()[0]},set x(e){d(0,e)},get y(){return u()[1]},set y(e){d(1,e)},get z(){return u()[2]},set z(e){d(2,e)},set(e,t,n){r.physics?.engine.setVelocity(i,[e,t,n])}},get userData(){return c().object.userData},get tags(){return c().object.userData.tags??[]},setColor(e){let t=a(e);for(let e of o(c().object))e.color?.copy(t)},setOpacity(e){for(let t of o(c().object))t.opacity=e,e<1&&!t.transparent&&(t.transparent=!0,t.needsUpdate=!0)},playAnimation(e,t){c().animator?.play(e,t)},distanceTo(e){let t=c().object.getWorldPosition(new n),i=r.world.entries.get(e.id);return i?t.distanceTo(i.object.getWorldPosition(new n)):1/0},remove(){r.world.entries.get(i)?.object.traverse(e=>{let t=e.userData.a3dId;t&&r.physics?.remove(t)}),r.physics?.remove(i),r.world.removeEntry(i),r.objCache.delete(i)}};return this.objCache.set(i,f),f}idOf(e){return typeof e==`string`?e:e.id}createApi(){let i=this,a=()=>i.opts.input,o={id:`camera`,position:P(()=>i.world.rig.rest.position),rotation:P(()=>i.world.camera.rotation,s),scale:P(()=>i.world.camera.scale),visible:!0,velocity:P(()=>new n),userData:{},tags:[],setColor(){},setOpacity(){},playAnimation(){},distanceTo(e){let t=i.world.entries.get(e.id);return t?i.world.camera.position.distanceTo(t.object.getWorldPosition(new n)):1/0},remove(){},lookAt(e,t,n){i.world.rig.rest.target.set(e,t,n)},shake(e,t){i.shake={intensity:e,duration:t,until:i.simTime+t}}},c=new r,l={get:e=>{let t=i.world.entries.get(e);return t&&t.kind!==`light`?i.wrap(t):null},findByTag:e=>{let t=[];for(let n of i.world.entries.values())n.kind!==`light`&&(n.object.userData.tags??[]).includes(e)&&t.push(i.wrap(n));return t},spawn:async(e,t)=>{let n=t?i.world.entries.get(t):void 0,r=await i.world.addObject(e,n?.object??i.world.scene,n?.id,/* @__PURE__ */ new Map);if(!r)throw Error(`spawn(${e.id}) failed`);return i.world.scene.updateMatrixWorld(!0),await i.addBodies(r),i.wrap(r)},clone:(e,t)=>{let n=i.world.entries.get(e);if(!n||n.kind===`light`)throw Error(`clone: unknown object "${e}"`);let r=t?.id;for(;!r||i.world.entries.has(r);)r=`${e}_${++i.cloneCounter}`;let a=n.object.clone(!0);a.traverse(e=>{let t=e;t.isMesh&&t.material&&(t.material=Array.isArray(t.material)?t.material.map(e=>e.clone()):t.material.clone()),e.userData.a3dId&&(e.userData={...e.userData})}),a.userData.a3dId=r,t?.position&&a.position.set(...t.position),(n.object.parent??i.world.scene).add(a);let o={...n.def,id:r,children:void 0},s={...n,id:r,def:o,object:a,rest:{position:a.position.clone(),quaternion:a.quaternion.clone(),scale:a.scale.clone(),visible:a.visible},runners:[],animator:void 0};return i.world.entries.set(r,s),i.world.scene.updateMatrixWorld(!0),o.body&&i.physics&&i.physics.addEntry(s),i.wrap(s)},camera:o,time:()=>i.simTime,random:()=>i.rng.next(),randomRange:(e,t)=>i.rng.range(e,t),input:{isDown:e=>a().keys.has(e),pressed:e=>i.stepPressed.has(e),get pointer(){let e=a().pointer;return{x:e.x,y:e.y,down:e.down,justPressed:i.stepJust}},swipe:()=>i.stepSwipe,pointerWorld:()=>{let r=a().pointer;c.setFromCamera(new t(r.x,r.y),i.world.camera);let o=[];for(let e of i.physics?.engine.bodies??[]){let t=i.world.entries.get(e.id);t&&o.push(t.object)}let s=o.length?c.intersectObjects(o,!0)[0]:void 0;if(s){let e=i.world.idsFor(s.object);return{x:s.point.x,y:s.point.y,z:s.point.z,objectId:e[0]}}let l=new n;return c.ray.intersectPlane(new e(new n(0,1,0),0),l)?{x:l.x,y:l.y,z:l.z}:null}},physics:{overlaps:(e,t)=>i.physics?.engine.overlaps(i.idOf(e),i.idOf(t))??!1,contacts:e=>(i.physics?.engine.contactsOf(i.idOf(e))??[]).map(e=>l.get(e.id)).filter(e=>!!e),raycast:(e,t,n,r)=>{let a=i.physics?.engine;if(!a)return null;let o=new Set((r?.ignore??[]).map(e=>i.idOf(e))),s=a.raycast(e,t,n??1/0,{ignore:o.size?e=>o.has(e.id):void 0,mask:r?.layers?a.layerMask(r.layers):void 0,triggers:r?.triggers});return s?{objectId:s.body.id,distance:s.distance,point:s.point,normal:s.normal}:null},applyImpulse:(e,t,n)=>i.physics?.engine.applyImpulse(i.idOf(e),t,n),applyForce:(e,t,n)=>i.physics?.engine.applyForce(i.idOf(e),t,n),applyTorque:(e,t)=>i.physics?.engine.applyTorque(i.idOf(e),t),setVelocity:(e,t)=>i.physics?.engine.setVelocity(i.idOf(e),t),getVelocity:e=>i.physics?.engine.get(i.idOf(e))?.velocity??[0,0,0],setAngularVelocity:(e,t)=>i.physics?.engine.setAngularVelocity(i.idOf(e),[t[0]*s,t[1]*s,t[2]*s]),getAngularVelocity:e=>{let t=i.physics?.engine.get(i.idOf(e))?.angularVelocity??[0,0,0];return[t[0]/s,t[1]/s,t[2]/s]},grounded:e=>i.physics?.engine.grounded(i.idOf(e))??!1,moveCharacter:(e,t,n)=>{let r=Array.isArray(t)?[t[0],t[1]]:[t.x,t.z];i.physics?.engine.moveCharacter(i.idOf(e),r,n)},jump:(e,t)=>i.physics?.engine.jump(i.idOf(e),t)??!1,wake:e=>i.physics?.engine.wake(i.idOf(e)),setMotorSpeed:(e,t)=>i.physics?.engine.setMotorSpeed(e,t*s),onCollision:e=>void i.collisionHandlers.push(e),onCollisionEnd:e=>void i.collisionEndHandlers.push(e),onTriggerEnter:e=>void i.triggerEnterHandlers.push(e),onTriggerExit:e=>void i.triggerExitHandlers.push(e)},state:i.state,ui:{set:(e,t)=>i.hud?.set(e,t),toast:(e,t)=>i.hud?.toast(e,t)},audio:{play:e=>i.audio.play(e),music:e=>i.audio.music(e)},on:(e,t)=>{let n=i.handlers.get(e)??[];n.push(t),i.handlers.set(e,n)},emit:(e,t)=>i.emit(e,t),storage:{get(e){try{let t=globalThis.localStorage?.getItem(`agent3d:${i.opts.scene.id}:${e}`);return t==null?void 0:JSON.parse(t)}catch{return}},set(e,t){try{globalThis.localStorage?.setItem(`agent3d:${i.opts.scene.id}:${e}`,JSON.stringify(t))}catch{}}},data:i.opts.scene.data??{},restart:()=>i.requestRestart(),log:(...e)=>console.log(`[agent3d]`,...e)};return l}};export{I as GameHost};
@@ -1,107 +0,0 @@
1
- import{Ct as e,Et as t,Gt as n,Mn as r,Qt as i,St as a,T as o,Tt as s,b as c,bt as l,en as u,h as d,ht as f,kn as p,n as m,ot as h,st as g,wt as _}from"./three.module-DnaBiDAJ.js";import{a as v,c as y}from"./catalog--OTp4gjy.js";import{i as b}from"./assets-qnxDnVkj.js";import{c as x,d as S,i as ee,t as C}from"./util-CyaW1fcW.js";import{n as w}from"./params-BCNrVCYZ.js";import{t as T}from"./random-eeej60NW.js";import{t as E}from"./toon-BsvVk_nK.js";var D={map:`color`,emissiveMap:`color`,normalMap:`normal`,roughnessMap:`data`,metalnessMap:`data`,aoMap:`data`,bumpMap:`data`,displacementMap:`data`,alphaMap:`data`},O=class{perm=/* @__PURE__ */ new Uint16Array(512);grads=/* @__PURE__ */ new Float32Array(512);constructor(e){let t=T(e),n=Array.from({length:256},(e,t)=>t);for(let e=255;e>0;e--){let r=Math.floor(t.next()*(e+1));[n[e],n[r]]=[n[r],n[e]]}for(let e=0;e<512;e++)this.perm[e]=n[e&255];for(let e=0;e<256;e++){let n=t.next()*Math.PI*2;this.grads[e*2]=Math.cos(n),this.grads[e*2+1]=Math.sin(n)}}g(e,t,n,r,i,a){let o=(e%n+n)%n,s=(t%r+r)%r,c=this.perm[this.perm[o&255]+s&511]&255;return this.grads[c*2]*i+this.grads[c*2+1]*a}noise(e,t,n,r){let i=Math.floor(e),a=Math.floor(t),o=e-i,s=t-a,c=o*o*o*(o*(o*6-15)+10),l=s*s*s*(s*(s*6-15)+10),u=this.g(i,a,n,r,o,s),d=this.g(i+1,a,n,r,o-1,s),f=this.g(i,a+1,n,r,o,s-1),p=this.g(i+1,a+1,n,r,o-1,s-1);return(u+(d-u)*c+(f-u)*l+(u-d-f+p)*c*l)*1.4}fbm(e,t,n,r,i=n){let a=0,o=.5,s=0,c=n,l=i;for(let n=0;n<r;n++)a+=o*this.noise(e*c,t*l,c,l),s+=o,o*=.5,c*=2,l*=2;return a/s}},k=(e,t,n)=>{let r=Math.imul(e|0,374761393)+Math.imul(t|0,668265263)+Math.imul(n|0,2246822519)|0;return r=Math.imul(r^r>>>13,1274126177),r^=r>>>16,(r>>>0)/4294967296},A=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e||1e-6)));return r*r*(3-2*r)},j=e=>e-Math.floor(e);function M(e,t,n,r,i){let a=e*n,o=t*n,s=Math.floor(a),c=Math.floor(o),l=9,u=9,d=0,f=0;for(let e=-1;e<=1;e++)for(let t=-1;t<=1;t++){let p=s+t,m=c+e,h=(p%n+n)%n,g=(m%n+n)%n,_=p+.5+(k(h,g,i)-.5)*r,v=m+.5+(k(h,g,i+17)-.5)*r,y=Math.hypot(_-a,v-o);y<l?(u=l,l=y,d=h,f=g):y<u&&(u=y)}return{f1:l,f2:u,cx:d,cy:f}}var N={marble(e,t){let n=e.num(`scale`),r=Math.max(1,Math.round(2*n)),i=2+e.num(`veins`)*22,a=e.num(`turbulence`);return{h(e,n){let o=t.fbm(e,n,r*2,5),s=t.fbm(e+.37,n+.71,r*2,5),c=t.fbm(e+o*.12*a,n+s*.12*a,r*3,6),l=(e*.6+n)*r+a*2.6*c,u=(1-Math.abs(Math.sin(Math.PI*l)))**i,d=t.fbm(e+.5,n,r*6,5),f=(1-Math.abs(Math.sin(Math.PI*(l*2.3+d*3))))**(i*2.5)*.45,p=(t.fbm(e,n+.3,r*2,4)*.5+.5)*.18;return Math.min(1,u*.9+f+p)}}},wood(e,t){let n=e.num(`scale`),r=e.num(`rings`),i=e.num(`grain`),a=Math.max(1,Math.round(n));return{h(e,o){let s=t.fbm(e,o,2*a,4,1*a),c=j(e*Math.round(r*n)+s*1.8),l=A(0,.7,c)*(1-A(.85,1,c)),u=t.noise(e*64*a,o*3*a,64*a,3*a)*.5+.5;return Math.min(1,Math.max(0,l*.75+u*i*.35+(s*.5+.5)*.15))}}},terrazzo(e,t,n){let r=Math.max(2,Math.round(10*e.num(`scale`)/e.num(`chipSize`))),i=e.num(`density`),a=Math.max(1,e.colors(`colors`).length-1),o=(e,o)=>{let s=M(e,o,r,1,n);if(k(s.cx,s.cy,n+5)>i)return{m:0,idx:-1};let c=.18+k(s.cx,s.cy,n+9)*.3,l=s.f1+t.noise(e*r*4,o*r*4,r*4,r*4)*.08;return{m:1-A(c-.03,c+.01,l),idx:1+Math.floor(k(s.cx,s.cy,n+3)*a)}};return{h(e,t){return o(e,t).m},pick(e,t){let n=o(e,t);return n.m>.5?n.idx:-1}}},carbon(e,t){let n=Math.max(2,Math.round(8*e.num(`scale`)));return{h(e,r){let i=e*n,a=r*n,o=Math.floor(i),s=Math.floor(a),c=i-o,l=a-s,u=((o+s)%4+4)%4<2,d=u?l:c,f=u?e:r,p=Math.sin(Math.PI*d),m=t.noise(f*n*2,d*40,n*2,40)*.5+.5;return Math.min(1,p*(u?.85:.45)*(.75+m*.25))}}},noise(e,t){let n=Math.max(1,Math.round(4*e.num(`scale`))),r=e.int(`octaves`),i=e.num(`contrast`);return{h:(e,a)=>Math.min(1,Math.max(0,.5+t.fbm(e,a,n,r)*.5*i*1.6))}},voronoi(e,t,n){let r=Math.max(1,Math.round(8*e.num(`scale`))),i=e.num(`jitter`);return{h(e,t){let a=M(e,t,r,i,n);return A(0,.25,a.f2-a.f1)}}},flakes(e,t,n){let r=Math.max(4,Math.round(64*e.num(`scale`))),i=e.num(`strength`);return{h(e,t){return k(Math.floor(e*r),Math.floor(t*r),n)},normal(e,t,a){let o=M(e,t,r,1,n),s=k(o.cx,o.cy,n+1)*Math.PI*2,c=Math.sqrt(k(o.cx,o.cy,n+2))*i,l=Math.cos(s)*c,u=Math.sin(s)*c;a[0]=l,a[1]=u,a[2]=Math.sqrt(Math.max(0,1-l*l-u*u))}}},brushed(e,t){let n=Math.max(1,Math.round(e.num(`scale`))),r=e.num(`streaks`),i=Math.max(8,Math.round(300*r*n));return{h(e,r){let a=t.noise(e*2*n,r*i,2*n,i)*.5+.5,o=t.noise(e*6*n,r*i*2.5,6*n,Math.round(i*2.5))*.5+.5,s=t.fbm(e,r,3*n,3)*.5+.5;return Math.min(1,Math.max(0,a*.5+o*.3+s*.2))}}},grid(e,t,n,r){let i=Math.max(1,Math.round(e.int(`cells`)*e.num(`scale`))),a=i/r,o=Math.max(e.num(`lineWidth`)*.5,a*.75);return{h(e,t){let n=j(e*i),r=j(t*i),s=Math.min(n,1-n,r,1-r);return 1-A(o-a*.5,o+a*.5,s)}}},checker(e){let t=Math.max(1,Math.round(e.int(`cells`)*e.num(`scale`)));return{h:(e,n)=>Math.floor(e*t)+Math.floor(n*t)&1?1:0}},stripes(e){let t=Math.max(1,Math.round(e.int(`count`)*e.num(`scale`))),n=e.num(`angle`)*Math.PI/180,r=Math.round(Math.cos(n)*t),i=Math.round(Math.sin(n)*t),a=Math.max(.002,e.num(`softness`));return{h(e,t){let n=Math.abs(j(e*r+t*i)-.5)*2;return A(.5-a*2,.5+a*2,n)}}},dots(e){let t=Math.max(1,Math.round(e.int(`cells`)*e.num(`scale`))),n=e.num(`radius`);return{h(e,r){let i=j(e*t)-.5,a=j(r*t)-.5;return 1-A(n-.02,n+.01,Math.hypot(i,a))}}}};Object.keys(N);var P=e=>{let t=e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;return Math.max(0,Math.min(255,Math.round(t*255)))},F=/* @__PURE__ */ new Map;function I(e){return 2**Math.round(Math.log2(Math.max(32,Math.min(2048,e))))}function L(e,t){let n=t+`:`+JSON.stringify(e),r=F.get(n);if(r)return r;let i=y.find(t=>t.id===e.procedural),a=N[e.procedural];if(!i||!a)throw Error(`Unknown procedural texture "${e.procedural}"`);let o=w(i,e),s=o.int(`seed`),c=I(o.int(`resolution`)),l=a(o,new O(s),s,c),u=new Uint8Array(c*c*4),d=new Float32Array(c*c);for(let e=0;e<c;e++){let t=(e+.5)/c;for(let n=0;n<c;n++)d[e*c+n]=l.h((n+.5)/c,t)}if(t===`color`){let e=o.colors(`colors`).map(e=>[e.r,e.g,e.b]),t=e.length;for(let n=0;n<c;n++)for(let r=0;r<c;r++){let i=n*c+r,a,o,s,f=l.pick?l.pick((r+.5)/c,(n+.5)/c):-1;if(f>=0)[a,o,s]=e[Math.min(f,t-1)];else if(l.pick)[a,o,s]=e[0];else{let n=Math.min(1,Math.max(0,d[i]))*(t-1),r=Math.min(t-2,Math.floor(n)),c=t>1?n-r:0,l=e[Math.max(0,r)],u=e[Math.min(t-1,r+1)];a=l[0]+(u[0]-l[0])*c,o=l[1]+(u[1]-l[1])*c,s=l[2]+(u[2]-l[2])*c}u[i*4]=P(a),u[i*4+1]=P(o),u[i*4+2]=P(s),u[i*4+3]=255}}else if(t===`normal`){let e=[0,0,1],t=c/256*2;for(let n=0;n<c;n++)for(let r=0;r<c;r++){let i=n*c+r,a,o,s;if(l.normal)l.normal((r+.5)/c,(n+.5)/c,e),[a,o,s]=e;else{let e=(e,t)=>d[(t+c)%c*c+(e+c)%c],i=(e(r+1,n-1)+2*e(r+1,n)+e(r+1,n+1)-e(r-1,n-1)-2*e(r-1,n)-e(r-1,n+1))/8,l=(e(r-1,n+1)+2*e(r,n+1)+e(r+1,n+1)-e(r-1,n-1)-2*e(r,n-1)-e(r+1,n-1))/8;a=-i*t,o=-l*t,s=1;let u=Math.hypot(a,o,s);a/=u,o/=u,s/=u}u[i*4]=Math.round((a*.5+.5)*255),u[i*4+1]=Math.round((o*.5+.5)*255),u[i*4+2]=Math.round((s*.5+.5)*255),u[i*4+3]=255}}else for(let e=0;e<c*c;e++){let t=Math.round(Math.min(1,Math.max(0,d[e]))*255);u[e*4]=u[e*4+1]=u[e*4+2]=t,u[e*4+3]=255}let f={data:u,size:c};return F.size>64&&F.clear(),F.set(n,f),f}function R(e,t){let r=L(e,t),a=new o(r.data,r.size,r.size,n,p);return a.colorSpace=t===`color`?u:``,a.wrapS=a.wrapT=i,a.magFilter=h,a.minFilter=g,a.generateMipmaps=!0,a.anisotropy=4,a.needsUpdate=!0,a.name=`procedural:${e.procedural}`,a}v.map(e=>e.id);function z(e){let t=e??{},n={...(t.preset?v.find(e=>e.id===t.preset):void 0)?.props??{}};for(let[e,r]of Object.entries(t))r!==void 0&&e!==`preset`&&(n[e]=r);return n.type||=n.shader?`shader`:n.gradient?`gradient`:`standard`,n}function B(e,t,n){let r=e.userData.a3dPatches;if(!r){r=e.userData.a3dPatches=[];let t=e.onBeforeCompile;if(t!==f.prototype.onBeforeCompile){let n=e.customProgramCacheKey.call(e);r.push({key:`own(${n})`,patch:(n,r)=>t.call(e,n,r)})}}if(r.some(e=>e.key===t))return;r.push({key:t,patch:n});let i=r;e.onBeforeCompile=(e,t)=>{for(let n of i)n.patch(e,t)},e.customProgramCacheKey=()=>`agent3d:`+i.map(e=>e.key).join(`+`),e.needsUpdate=!0}var V=null;function H(){if(V)return V;if(typeof document>`u`)return null;let e=document.createElement(`canvas`);e.width=e.height=256;let t=e.getContext(`2d`);if(!t)return null;let n=t.createRadialGradient(97.28,81.92,5.12,128,128,133.12);n.addColorStop(0,`#ffffff`),n.addColorStop(.25,`#e6e6ea`),n.addColorStop(.7,`#7d7f88`),n.addColorStop(1,`#2a2b30`),t.fillStyle=n,t.fillRect(0,0,256,256);let r=t.createRadialGradient(128,128,102.4,128,128,128);return r.addColorStop(0,`rgba(255,255,255,0)`),r.addColorStop(1,`rgba(200,210,255,0.35)`),t.fillStyle=r,t.fillRect(0,0,256,256),V=new d(e),V.colorSpace=u,V}var U={front:0,back:1,double:2},W=8;function G(e,t,n=!1){let r=t.slice(0,W).map(e=>S(e));for(;r.length<W;)r.push(r[r.length-1].clone());let i={uGradColors:{value:r},uGradCount:{value:Math.min(Math.max(t.length,1),W)},uGradMin:{value:-.5},uGradMax:{value:.5}};return B(e,n?`gradient-emissive`:`gradient`,e=>{Object.assign(e.uniforms,i),e.vertexShader=`varying float vGradY;
2
- `+e.vertexShader.replace(`#include <begin_vertex>`,`#include <begin_vertex>
3
- vGradY = position.y;`);let t=`varying float vGradY;\nuniform vec3 uGradColors[${W}];\nuniform int uGradCount;\nuniform float uGradMin;\nuniform float uGradMax;\n`+e.fragmentShader.replace(`vec4 diffuseColor = vec4( diffuse, opacity );`,`float gT = clamp((vGradY - uGradMin) / max(uGradMax - uGradMin, 1e-5), 0.0, 1.0);
4
- vec3 gCol = uGradColors[0];
5
- if (uGradCount > 1) {
6
- float f = gT * float(uGradCount - 1);
7
- for (int i = 0; i < 7; i++) {
8
- if (i < uGradCount - 1) gCol = mix(gCol, uGradColors[i + 1], clamp(f - float(i), 0.0, 1.0));
9
- }
10
- }
11
- vec4 diffuseColor = vec4( diffuse * gCol, opacity );`);n&&(t=t.replace(`#include <emissivemap_fragment>`,`#include <emissivemap_fragment>
12
- totalEmissiveRadiance *= gCol;`)),e.fragmentShader=t}),e.userData.gradient=i,i}function K(e,t){for(let n of Array.isArray(e)?e:[e]){let e=n.userData.gradient;if(!e)continue;t.boundingBox||t.computeBoundingBox();let r=t.boundingBox;e.uGradMin.value=r.min.y,e.uGradMax.value=r.max.y}}var q=`
13
- varying vec3 vTriPos;
14
- varying vec3 vTriNormal;
15
- uniform vec2 uTriScale;
16
- vec3 triW() {
17
- vec3 w = pow(abs(normalize(vTriNormal)), vec3(4.0));
18
- return w / max(w.x + w.y + w.z, 1e-5);
19
- }
20
- vec4 triSample(sampler2D tex) {
21
- vec3 w = triW();
22
- vec3 p = vTriPos;
23
- return texture2D(tex, p.zy * uTriScale) * w.x + texture2D(tex, p.xz * uTriScale) * w.y + texture2D(tex, p.xy * uTriScale) * w.z;
24
- }
25
- `;function te(e,t,n){let i={value:new r(t*(n?.[0]??1),t*(n?.[1]??n?.[0]??1))};B(e,`triplanar`,e=>{e.uniforms.uTriScale=i,e.vertexShader=`varying vec3 vTriPos;
26
- varying vec3 vTriNormal;
27
- `+e.vertexShader.replace(`#include <begin_vertex>`,`#include <begin_vertex>
28
- vTriPos = position;
29
- vTriNormal = normal;`);let t=e.fragmentShader;t=t.replace(`#include <common>`,`#include <common>
30
- `+q+`
31
- #if defined( USE_NORMALMAP_TANGENTSPACE ) && !defined( USE_NORMALMAP_OBJECTSPACE )
32
- uniform mat3 normalMatrix;
33
- #endif
34
- `),t=t.replace(`#include <map_fragment>`,`#ifdef USE_MAP
35
- diffuseColor *= triSample( map );
36
- #endif`),t=t.replace(`#include <roughnessmap_fragment>`,`float roughnessFactor = roughness;
37
- #ifdef USE_ROUGHNESSMAP
38
- roughnessFactor *= triSample( roughnessMap ).g;
39
- #endif`),t=t.replace(`#include <metalnessmap_fragment>`,`float metalnessFactor = metalness;
40
- #ifdef USE_METALNESSMAP
41
- metalnessFactor *= triSample( metalnessMap ).b;
42
- #endif`),t=t.replace(`#include <emissivemap_fragment>`,`#ifdef USE_EMISSIVEMAP
43
- totalEmissiveRadiance *= triSample( emissiveMap ).rgb;
44
- #endif`),t=t.replace(`#include <normal_fragment_maps>`,`#if defined( USE_NORMALMAP_TANGENTSPACE )
45
- {
46
- vec3 tw = triW();
47
- vec3 on = normalize( vTriNormal );
48
- vec3 p = vTriPos;
49
- vec3 tx = texture2D( normalMap, p.zy * uTriScale ).xyz * 2.0 - 1.0;
50
- vec3 ty = texture2D( normalMap, p.xz * uTriScale ).xyz * 2.0 - 1.0;
51
- vec3 tz = texture2D( normalMap, p.xy * uTriScale ).xyz * 2.0 - 1.0;
52
- tx.xy *= normalScale; ty.xy *= normalScale; tz.xy *= normalScale;
53
- tx = vec3( tx.xy + on.zy, abs( tx.z ) * on.x );
54
- ty = vec3( ty.xy + on.xz, abs( ty.z ) * on.y );
55
- tz = vec3( tz.xy + on.xy, abs( tz.z ) * on.z );
56
- vec3 objN = normalize( tx.zyx * tw.x + ty.xzy * tw.y + tz.xyz * tw.z );
57
- normal = normalize( normalMatrix * objN ) * faceDirection;
58
- }
59
- #else
60
- #include <normal_fragment_maps>
61
- #endif`),e.fragmentShader=t})}var ne=Object.keys(D);function J(e,t,n){e.colorSpace=n?u:``,(t.repeat||t.triplanar)&&(e.wrapS=e.wrapT=i,t.repeat&&!t.triplanar&&e.repeat.set(t.repeat[0],t.repeat[1])),e.anisotropy=Math.max(e.anisotropy,4)}function Y(e,t,n,r){let i=e;i[t]=n,t===`map`&&!r.color&&e.color?.set(16777215),t===`emissiveMap`&&!r.emissive&&e.emissive?.set(16777215),t===`alphaMap`&&(e.transparent=r.transparent??!0),e.needsUpdate=!0}function re(e,t,n){for(let r of ne){let a=t[r];if(!a||!(r in e))continue;let o=D[r];if(typeof a==`object`){try{let n=R(a,o);J(n,t,o===`color`),n.wrapS=n.wrapT=i,Y(e,r,n,t)}catch(e){n.issue(`unknown-catalog-id`,e.message,`material.${String(r)}`)}continue}let s=n.resolveAsset(a);n.track(b(s).then(n=>{J(n,t,o===`color`),Y(e,r,n,t)}).catch(e=>n.issue(`asset-load`,e.message,a)))}}function X(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}async function Z(n,i,o={}){let u=z(n),d=u.type??`standard`,f=u.color??(n?.preset?void 0:o.defaultColor);if(d===`shader`){let e=await i.shaders().catch(()=>({})),t=u.shader??`plasma`,n=e[t];if(n){let e={...u.uniforms??{}};u.color&&e.color===void 0&&(e.color=u.color),u.gradient&&e.colors===void 0&&(e.colors=u.gradient),u.opacity!==void 0&&e.opacity===void 0&&(e.opacity=u.opacity);let t=n.create(e,i);if(t.update){let e=t.update.bind(t);i.onUpdate(t=>e(t))}return u.side&&(t.material.side=U[u.side]),t.material}i.issue(`unknown-catalog-id`,`Unknown shader "${t}"`,`material.shader`)}let p={};f&&(p.color=S(f)),u.opacity!==void 0&&(p.opacity=u.opacity),(u.transparent!==void 0||u.opacity!==void 0&&u.opacity<1)&&(p.transparent=u.transparent??!0),u.wireframe&&(p.wireframe=!0),u.side&&(p.side=U[u.side]),o.vertexColors&&(p.vertexColors=!0);let m={...p};u.emissive&&(m.emissive=S(u.emissive)),u.emissiveIntensity!==void 0&&(m.emissiveIntensity=u.emissiveIntensity),u.flatShading&&(m.flatShading=!0),u.bumpScale!==void 0&&(m.bumpScale=u.bumpScale),u.normalScale!==void 0&&(m.normalScale=new r(u.normalScale,u.normalScale)),u.aoMapIntensity!==void 0&&(m.aoMapIntensity=u.aoMapIntensity),u.displacementScale!==void 0&&(m.displacementScale=u.displacementScale);let h={...m};u.metalness!==void 0&&(h.metalness=u.metalness),h.roughness=x(u.roughness,.5),u.envMapIntensity!==void 0&&(h.envMapIntensity=u.envMapIntensity);let g;switch(d){case`physical`:{let e={...h};if(u.transmission!==void 0&&(e.transmission=u.transmission),u.thickness!==void 0&&(e.thickness=u.thickness),u.ior!==void 0&&(e.ior=u.ior),u.clearcoat!==void 0&&(e.clearcoat=u.clearcoat,e.clearcoatRoughness=x(u.clearcoatRoughness,.1)),u.iridescence!==void 0){e.iridescence=u.iridescence,e.iridescenceIOR=x(u.iridescenceIOR,1.6);let[t,n]=u.iridescenceThicknessRange??[180,600];e.iridescenceThicknessMinimum=t,e.iridescenceThicknessMaximum=n}u.sheen!==void 0&&(e.sheen=u.sheen,e.sheenRoughness=x(u.sheenRoughness,.6),e.sheenColor=u.sheenColor?S(u.sheenColor):S(f??`#ffffff`).lerp(new c(1,1,1),.5)),u.anisotropy!==void 0&&(e.anisotropy=u.anisotropy,e.anisotropyRotation=x(u.anisotropyRotation,0)*C),u.attenuationColor!==void 0&&(e.attenuationColor=S(u.attenuationColor)),u.attenuationDistance!==void 0&&(e.attenuationDistance=u.attenuationDistance),u.specularIntensity!==void 0&&(e.specularIntensity=u.specularIntensity),u.specularColor!==void 0&&(e.specularColor=S(u.specularColor)),u.dispersion!==void 0&&(e.dispersion=u.dispersion),g=new s(e),u.transmission&&!$(u)&&oe(g);break}case`basic`:g=new l(p);break;case`lambert`:g=new a(m);break;case`toon`:g=E({...h,roughness:x(u.roughness,.75)});break;case`normal`:g=new _(X({flatShading:!!u.flatShading,wireframe:!!u.wireframe,side:p.side,transparent:p.transparent,opacity:u.opacity??1}));break;case`matcap`:g=new e(X({...p,flatShading:!!u.flatShading,matcap:H()??void 0}));break;case`gradient`:g=new t({...h,color:S(u.color??`#ffffff`)}),G(g,ee(u.gradient,[`#3a86ff`,`#ff006e`]),!!u.gradientEmissive);break;default:g=new t(h)}return u.envMapIntensity!==void 0&&g instanceof t&&u.envMapIntensity!==1&&(Q(g).value=u.envMapIntensity),g instanceof s&&$(u)&&se(g,u),u.triplanar&&g instanceof t&&te(g,typeof u.triplanar==`number`?u.triplanar:1,u.repeat),re(g,u,i),g}async function ie(e,t,n){let r=await Z(t,n);e.traverse(e=>{let t=e;t.isMesh&&(t.material=r,K(r,t.geometry))})}function Q(e){let t=e.userData.envScale;if(t)return t;let n={value:1};return e.userData.envScale=n,B(e,`env-scale`,e=>{e.uniforms.uA3dEnvScale=n,e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
62
- uniform float uA3dEnvScale;`).replace(`#include <lights_fragment_maps>`,`#include <lights_fragment_maps>
63
- #if defined( RE_IndirectSpecular ) && defined( RE_IndirectDiffuse )
64
- radiance *= uA3dEnvScale;
65
- clearcoatRadiance *= uA3dEnvScale;
66
- iblIrradiance *= uA3dEnvScale;
67
- #endif`)}),n}var ae=`vec3 a3dSoftClip(vec3 c) { vec3 e = max(c - 1.0, 0.0); return min(c, 1.0) + e / (1.0 + e); }`;function oe(e){B(e,`transmission-clamp`,e=>{e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>\n${ae}`).replace(`#include <transmission_fragment>`,m.transmission_fragment.replace(`material.transmissionAlpha = mix(`,`transmitted.rgb = a3dSoftClip( transmitted.rgb );
68
- material.transmissionAlpha = mix(`))})}function $(e){return(e.transmission??0)>=.5&&(e.ior??1.5)>=1.7&&(e.roughness??.5)<=.15}function se(e,t){let n={uA3dGemIor:{value:t.ior??2},uA3dGemDisp:{value:Math.min(.12,(t.dispersion??0)*.012)},uA3dGemTint:{value:t.attenuationColor?S(t.attenuationColor):new c(1,1,1)},uA3dGemEnv:Q(e),uA3dGemAmount:{value:Math.min(.85,.45+Math.max(0,(t.ior??2)-1.5)*.45)}};e.userData.gemSparkle=n,B(e,`gem-sparkle`,e=>{Object.assign(e.uniforms,n),e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
69
- varying vec3 vA3dJ0; varying vec3 vA3dJ1; varying vec3 vA3dJ2;
70
- vec3 a3dGemHash(vec3 p) { p = fract(p * vec3(0.1031, 0.1030, 0.0973)); p += dot(p, p.yxz + 33.33); return fract((p.xxy + p.yxx) * p.zyx); }`).replace(`#include <beginnormal_vertex>`,`#include <beginnormal_vertex>
71
- vec3 a3dOn = floor(objectNormal * 64.0 + 0.5);
72
- vA3dJ0 = normalMatrix * (a3dGemHash(a3dOn + 1.7) - 0.5);
73
- vA3dJ1 = normalMatrix * (a3dGemHash(a3dOn + 9.3) - 0.5);
74
- vA3dJ2 = normalMatrix * (a3dGemHash(a3dOn + 23.1) - 0.5);`),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
75
- varying vec3 vA3dJ0; varying vec3 vA3dJ1; varying vec3 vA3dJ2;
76
- uniform float uA3dGemIor; uniform float uA3dGemDisp; uniform vec3 uA3dGemTint; uniform float uA3dGemEnv; uniform float uA3dGemAmount;`).replace(`#include <opaque_fragment>`,`#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_PMREM )
77
- {
78
- vec3 gV = normalize(geometryViewDir);
79
- vec3 gN = normalize(normal);
80
- vec3 sp = vec3(0.0);
81
- vec3 iors = vec3(uA3dGemIor - uA3dGemDisp, uA3dGemIor, uA3dGemIor + uA3dGemDisp);
82
- for (int k = 0; k < 3; k++) {
83
- vec3 J = k == 0 ? vA3dJ0 : (k == 1 ? vA3dJ1 : vA3dJ2);
84
- vec3 fn = normalize(-gN + J * 1.6);
85
- for (int c = 0; c < 3; c++) {
86
- vec3 rd = refract(-gV, gN, 1.0 / iors[c]);
87
- vec3 d = normalize(reflect(rd, fn));
88
- // A second inner bounce off the next fake facet: the exit ray swings a
89
- // lot with the view angle, so faces break into light / dark areas.
90
- vec3 J2 = k == 0 ? vA3dJ1 : (k == 1 ? vA3dJ2 : vA3dJ0);
91
- d = normalize(reflect(d, normalize(d * -0.5 + J2 * 2.0 + gN * 0.3)));
92
- sp[c] += getIBLRadiance(d, d, 0.0)[c];
93
- }
94
- }
95
- sp *= uA3dGemEnv / 3.0;
96
- // Contrast: facets catching bright light flash, the others go dark.
97
- // Relative to the environment's average brightness (its irradiance), so it
98
- // works on a uniformly light softbox as well as on a dark studio.
99
- vec3 avgEnv = (getIBLIrradiance(gN) + getIBLIrradiance(-gN)) / (2.0 * PI) * uA3dGemEnv / max(envMapIntensity, 1e-3);
100
- float la = max(dot(avgEnv, vec3(0.2126, 0.7152, 0.0722)), 1e-3);
101
- float l = dot(sp, vec3(0.2126, 0.7152, 0.0722));
102
- sp *= smoothstep(0.7 * la, 1.6 * la, l) * 1.6;
103
- float F = pow(1.0 - saturate(dot(gN, gV)), 5.0);
104
- outgoingLight = mix(outgoingLight, sp * uA3dGemTint + outgoingLight * 0.25, uA3dGemAmount * (1.0 - F));
105
- }
106
- #endif
107
- #include <opaque_fragment>`)})}export{ie as a,K as i,Z as n,z as o,Q as r,B as t};
@@ -1 +0,0 @@
1
- import{H as e,Nn as t,c as n,d as r,ft as i,pt as a}from"./three.module-DnaBiDAJ.js";import{c as o}from"./util-CyaW1fcW.js";import{a as s}from"./materials-dC4vDNHh.js";var c=/* @__PURE__ */ new Map;function l(e){let t=new Uint8Array(e),n;if(t.byteLength>=20&&new DataView(e).getUint32(0,!0)===1179937895){let r=new DataView(e).getUint32(12,!0);n=new TextDecoder().decode(t.subarray(20,20+r))}else n=new TextDecoder().decode(t);try{let e=JSON.parse(n);return Array.isArray(e.extensionsUsed)?e.extensionsUsed.filter(e=>typeof e==`string`):[]}catch{return[]}}async function u(e){let t=c.get(e);return t||(t=(async()=>{let[{GLTFLoader:t},n]=await Promise.all([import(`./GLTFLoader-Z9Inv-Xm.js`),fetch(e)]);if(!n.ok)throw Error(`HTTP ${n.status} for ${e}`);let r=await n.arrayBuffer(),i=l(r);if(i.includes(`KHR_draco_mesh_compression`))throw Error(`${e} uses Draco compression (KHR_draco_mesh_compression), which the Agent3D runtime does not decode. Re-export it without Draco (Blender: uncheck "Compression"), or convert it to meshopt with gltfpack (\`gltfpack -i in.glb -o out.glb -cc\`), then run \`agent3d assets optimize\`.`);let a=new t;if(i.includes(`EXT_meshopt_compression`)){let{MeshoptDecoder:e}=await import(`./meshopt_decoder.module-DXTYc6wn.js`);await e.ready,a.setMeshoptDecoder(e)}let o=e.slice(0,e.lastIndexOf(`/`)+1);return a.parseAsync(r,/^data:/.test(e)?``:o)})(),t.catch(()=>c.delete(e)),c.set(e,t)),t}function d(e,t){e.traverse(e=>{let n=e;if(n.isMesh&&n.morphTargetDictionary&&n.morphTargetInfluences)for(let[e,r]of Object.entries(t)){let t=n.morphTargetDictionary[e];t!==void 0&&typeof r==`number`&&(n.morphTargetInfluences[t]=r)}})}async function f(c,l){let f=await u(l.resolveAsset(c.src)),{clone:p}=await import(`./SkeletonUtils-DHlReJx3.js`),m=p(f.scene),h=new e;h.add(m),m.updateMatrixWorld(!0);let g=new r().setFromObject(m);if(!g.isEmpty()){let e=g.getSize(new t),n=Math.max(e.x,e.y,e.z),r=c.fit&&n>0?c.fit/n:1;if(m.scale.multiplyScalar(r),c.center!==!1){let e=g.getCenter(new t);m.position.set(-e.x*r,-g.min.y*r,-e.z*r)}}m.traverse(e=>{let t=e;t.isMesh&&(t.castShadow=c.castShadow??!0,t.receiveShadow=c.receiveShadow??!1)}),c.material&&await s(m,c.material,l),c.morph&&d(m,c.morph);let _;if(f.animations.length){let e=new n(m),t=null,r=e=>typeof e==`number`||/^\d+$/.test(String(e))?f.animations[Number(e)]:f.animations.find(t=>t.name===e)??f.animations.find(t=>t.name.toLowerCase().includes(String(e).toLowerCase())),s=/* @__PURE__ */ new Set,u=e=>{let t=r(e);return!t&&!s.has(String(e))&&(s.add(String(e)),l.issue(`asset-load`,`Model ${c.id} has no animation clip "${e}" (clips: ${f.animations.map(e=>e.name).join(`, `)})`,`objects#${c.id}.animation.clip`)),t},d=(n,r={})=>{let s=u(n);if(!s)return;let c=e.clipAction(s);c.setLoop(r.loop===!1?i:a,1/0),c.clampWhenFinished=r.loop===!1,c.timeScale=o(r.speed,1),c.enabled=!0,t&&t!==c?(c.reset().setEffectiveWeight(1).play(),t.crossFadeTo(c,o(r.crossfade,.3),!1)):c.setEffectiveWeight(1).play(),t=c},p=t=>{let n=u(t);if(!n)return null;let r=e.clipAction(n);return r.isRunning()||(r.enabled=!0,r.setLoop(a,1/0),r.play()),r},h={weight(e,t){p(e)?.setEffectiveWeight(Math.max(0,t))},speed(e,t){let n=p(e);n&&(n.timeScale=t)},time(e,t){let n=p(e);n&&(n.paused=!0,n.time=Math.max(0,t))}},g=c.animation??{},v=()=>{e.stopAllAction(),t=null,d(g.clip??0,g),g.offset&&t&&(t.time=Math.max(0,g.offset));for(let[e,t]of Object.entries(g.blend??{}))h.weight(e,t);e.update(0)};_={mixer:e,clips:f.animations,play:d,control:h,reset:v},v()}return{object:h,animator:_}}export{f as buildModel};
@@ -1,250 +0,0 @@
1
- import{Dt as e,H as t,Mn as n,Nn as r,Rt as i,b as a,bt as o,d as s,dn as c,en as l,m as u,ot as d,p as f,rn as p,yt as m}from"./three.module-DnaBiDAJ.js";import{i as h}from"./assets-qnxDnVkj.js";import{c as g,r as _,t as v}from"./util-CyaW1fcW.js";var y={width:4,strength:.5,focus:.5,segments:256,layers:6,edgeCut:.08,speed:1,smoothing:.9};function ee(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}}function b(e,t,n){let r=2*Math.PI*Math.max(0,t)/10*n;switch(e??`sway`){case`sway`:return{x:.9*Math.sin(r),y:.35*Math.sin(2*r),zoom:0};case`orbit`:{let e=Math.min(1,r/Math.PI),t=.8*e*e*(3-2*e);return{x:t*Math.sin(r),y:t*Math.cos(r),zoom:0}}case`zoom`:return{x:0,y:0,zoom:.5-.5*Math.cos(r)};default:return{x:0,y:0,zoom:0}}}function te(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,g(e?.speed,y.speed)),smoothing:_(g(e?.smoothing,y.smoothing),0,.99)}}function x(e,t){let n=t.reduced?{x:0,y:0,zoom:0}:b(e.auto,e.speed,t.t),r=e.pointer*(t.reduced?.5:1),i=0,a=0,o=0;t.gyro&&e.gyro&&t.pointer.weight<.5?(i=t.gyro.x,a=t.gyro.y,o=+(r>0)):r>0&&(i=t.pointer.x,a=t.pointer.y,o=_(t.pointer.weight,0,1));let s=n.x*(1-o)+i*r*o,c=n.y*(1-o)+a*r*o;return e.scroll>0&&(c+=(_(t.scroll,0,1)*2-1)*e.scroll),{x:_(s,-1,1),y:_(c,-1,1),zoom:n.zoom*(1-o)}}function S(e,t,n,r){if(r<=0||n<=0)return n<=0&&r>0?e:t;let i=1-_(r,0,.99)**(n*60),a=e+(t-e)*i;return Math.abs(t-a)<1e-4?t:a}function C(e,t,n){let r=_(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 ne(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 w(e,t){return _(e,0,1)*t*.25}function re(e,t,n,r){let i=Math.round(_(g(e,y.layers),2,16)),a=[],o=_(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}function ie(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:_(i/20,-1,1),y:_(-a/20,-1,1)}}var T=`
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
- `,E=`
10
- varying vec2 vUv;
11
- void main() {
12
- vUv = uv;
13
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
14
- }
15
- `,D=`
16
- ${T}
17
- uniform sampler2D uDepth;
18
- uniform vec2 uView;
19
- uniform float uZoom;
20
- uniform vec2 uMaxOffset;
21
- uniform vec2 uInset;
22
- uniform float uFocus;
23
- uniform float uWallSlope;
24
- varying vec2 vUv;
25
- const int STEPS = __STEPS__;
26
- void main() {
27
- // the zoom drift also pushes in slightly (stays inside the inset margin)
28
- vec2 base = 0.5 + (vUv - 0.5) * uInset * (1.0 - 0.06 * uZoom);
29
- vec2 v = uView - (vUv - 0.5) * 2.0 * uZoom;
30
- vec2 dir = v * uMaxOffset;
31
- vec2 uv = base;
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) {
64
- vec2 away = -toNear;
65
- vec2 probe = uv;
66
- for (int k = 1; k <= 6; k++) {
67
- vec2 q = uv + away * texel * float(k * 2);
68
- probe = q;
69
- if (textureLod(uDepth, q, 0.0).r < lo - 0.05) break;
70
- }
71
- uv = probe + away * texel * 2.0;
72
- }
73
- }
74
- vec4 c = textureGrad(uMap, uv, dFdx(base), dFdy(base));
75
- if (c.a * uOpacity < 0.004) discard;
76
- gl_FragColor = shade(c, 1.0);
77
- #include <tonemapping_fragment>
78
- #include <colorspace_fragment>
79
- }
80
- `,ae=`
81
- uniform sampler2D uDepth;
82
- uniform float uRange;
83
- uniform float uFocus;
84
- uniform float uEdgeCut;
85
- uniform vec3 uCam;
86
- uniform float uPerspective;
87
- attribute vec4 uvOther;
88
- varying vec2 vUv;
89
- varying float vDepth;
90
- varying float vCut;
91
- varying float vMotion;
92
- vec3 displaced(vec3 p, float z) {
93
- if (uPerspective > 0.5 && uCam.z > z + 1e-3) p.xy = mix(p.xy, uCam.xy, z / uCam.z);
94
- p.z = z;
95
- return p;
96
- }
97
- void main() {
98
- vUv = uv;
99
- vec4 d0 = textureLod(uDepth, uv, 0.0);
100
- vec4 d1 = textureLod(uDepth, uvOther.xy, 0.0);
101
- vec4 d2 = textureLod(uDepth, uvOther.zw, 0.0);
102
- float jump = max(max(abs(d0.r - d1.r), abs(d1.r - d2.r)), abs(d0.r - d2.r));
103
- bool cut = min(d0.a, min(d1.a, d2.a)) < 0.5 || (uEdgeCut > 0.0 && jump > uEdgeCut);
104
- vCut = cut ? 1.0 : 0.0;
105
- vDepth = d0.r;
106
- vec4 c = projectionMatrix * modelViewMatrix * vec4(displaced(position, (d0.r - uFocus) * uRange), 1.0);
107
- vMotion = 0.0;
108
- if (cut) {
109
- vec4 a = projectionMatrix * modelViewMatrix * vec4(displaced(position, -uFocus * uRange), 1.0);
110
- vec4 b = projectionMatrix * modelViewMatrix * vec4(displaced(position, (1.0 - uFocus) * uRange), 1.0);
111
- vMotion = length(b.xy / b.w - a.xy / a.w);
112
- }
113
- gl_Position = c;
114
- }
115
- `,oe=`
116
- ${T}
117
- uniform sampler2D uDepth;
118
- varying vec2 vUv;
119
- varying float vDepth;
120
- varying float vCut;
121
- varying float vMotion;
122
- void main() {
123
- if (vCut > 0.5) {
124
- float d = textureLod(uDepth, vUv, 0.0).r;
125
- if (abs(d - vDepth) * vMotion > 0.004) discard;
126
- }
127
- vec4 c = texture2D(uMap, vUv);
128
- if (c.a * uOpacity < 0.004) discard;
129
- gl_FragColor = shade(c, 1.0);
130
- #include <tonemapping_fragment>
131
- #include <colorspace_fragment>
132
- }
133
- `,se=`
134
- uniform sampler2D uDepth;
135
- uniform float uRange;
136
- uniform float uFocus;
137
- uniform vec3 uCam;
138
- uniform float uPerspective;
139
- uniform vec2 uReach;
140
- varying vec2 vUv;
141
- varying float vDepth;
142
- void main() {
143
- vUv = uv;
144
- float d = textureLod(uDepth, uv, 0.0).r;
145
- for (int i = 1; i <= 2; i++) {
146
- vec2 r = uReach * float(i) * 0.5;
147
- d = min(d, textureLod(uDepth, uv + vec2(r.x, 0.0), 0.0).r);
148
- d = min(d, textureLod(uDepth, uv - vec2(r.x, 0.0), 0.0).r);
149
- d = min(d, textureLod(uDepth, uv + vec2(0.0, r.y), 0.0).r);
150
- d = min(d, textureLod(uDepth, uv - vec2(0.0, r.y), 0.0).r);
151
- d = min(d, textureLod(uDepth, uv + r, 0.0).r);
152
- d = min(d, textureLod(uDepth, uv - r, 0.0).r);
153
- d = min(d, textureLod(uDepth, uv + vec2(r.x, -r.y), 0.0).r);
154
- d = min(d, textureLod(uDepth, uv + vec2(-r.x, r.y), 0.0).r);
155
- }
156
- vDepth = d;
157
- float z = (d - uFocus) * uRange - uRange * 0.02;
158
- vec3 p = position;
159
- if (uPerspective > 0.5 && uCam.z > z + 1e-3) p.xy = mix(p.xy, uCam.xy, z / uCam.z);
160
- p.z = z;
161
- gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
162
- }
163
- `,O=`
164
- ${T}
165
- uniform sampler2D uDepth;
166
- varying vec2 vUv;
167
- varying float vDepth;
168
- void main() {
169
- vec2 uv = vUv;
170
- float d = textureLod(uDepth, uv, 0.0).r;
171
- if (d > vDepth + 0.04) {
172
- vec2 texel = 1.0 / vec2(textureSize(uDepth, 0));
173
- vec2 grad = vec2(
174
- 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,
175
- 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);
176
- vec2 away = length(grad) > 1e-5 ? -normalize(grad) : vec2(0.0);
177
- // walk towards the background until the depth reaches this surface's
178
- for (int k = 1; k <= 24; k++) {
179
- uv = vUv + away * texel * float(k * 3);
180
- if (textureLod(uDepth, uv, 0.0).r <= vDepth + 0.04) break;
181
- }
182
- uv += away * texel * 2.0;
183
- }
184
- vec4 c = texture2D(uMap, uv);
185
- if (c.a * uOpacity < 0.004) discard;
186
- gl_FragColor = shade(c, 1.0);
187
- #include <tonemapping_fragment>
188
- #include <colorspace_fragment>
189
- }
190
- `,ce=`
191
- ${T}
192
- uniform sampler2D uDepth;
193
- uniform vec2 uView;
194
- uniform float uZoom;
195
- uniform vec2 uMaxOffset;
196
- uniform vec2 uInset;
197
- uniform float uFocus;
198
- uniform float uCenter;
199
- uniform float uLo;
200
- uniform float uHi;
201
- uniform float uFeather;
202
- uniform float uBackground;
203
- varying vec2 vUv;
204
- void main() {
205
- // the zoom drift also pushes in slightly (stays inside the inset margin)
206
- vec2 base = 0.5 + (vUv - 0.5) * uInset * (1.0 - 0.06 * uZoom);
207
- vec2 v = uView - (vUv - 0.5) * 2.0 * uZoom;
208
- // Each layer moves with the depth it shows, clamped to its band: a smooth
209
- // surface crossing two bands stays continuous (no tear at the band edge);
210
- // only real depth jumps separate the layers. Fixed-point solve, from the
211
- // band centre.
212
- vec2 dir = v * uMaxOffset;
213
- vec2 uv = base + (uCenter - uFocus) * dir;
214
- for (int i = 0; i < 3; i++) {
215
- float di = clamp(textureLod(uDepth, uv, 0.0).r, uLo, uHi);
216
- uv = base + (di - uFocus) * dir;
217
- }
218
- vec4 dd = textureLod(uDepth, uv, 0.0);
219
- float d = dd.r;
220
- // soft slice edges, but hard on marked depth edges (alpha 0): a blend of
221
- // two layers there would draw a thin double outline
222
- float a = uBackground > 0.5 ? 1.0 : dd.a < 0.5 ? step(uLo, d) : smoothstep(uLo - uFeather, uLo + uFeather, d);
223
- if (a < 0.004) discard;
224
- vec2 cuv = uv;
225
- // covered by nearer content
226
- if (d > uHi + uFeather) {
227
- bool found = false;
228
- vec2 reach = v * uMaxOffset * 1.25;
229
- for (int k = 1; k <= 16; k++) {
230
- vec2 q = uv + reach * (float(k) / 16.0);
231
- vec4 dq = textureLod(uDepth, q, 0.0);
232
- if (dq.r <= uHi && dq.a >= 0.5 && (uBackground > 0.5 || dq.r >= uLo - uFeather)) {
233
- // step past the edge's blended texels
234
- vec2 texel = 1.0 / vec2(textureSize(uMap, 0));
235
- cuv = q + normalize(reach) * texel * 3.0;
236
- found = true;
237
- break;
238
- }
239
- }
240
- // Nothing of this band to extend: let the layers below show (the
241
- // background keeps the source texel).
242
- if (!found && uBackground < 0.5) discard;
243
- }
244
- vec4 c = textureGrad(uMap, cuv, dFdx(base), dFdy(base));
245
- gl_FragColor = shade(c, a);
246
- if (gl_FragColor.a < 0.004) discard;
247
- #include <tonemapping_fragment>
248
- #include <colorspace_fragment>
249
- }
250
- `;function le(e){let t=e.image;return{w:t?.naturalWidth||t?.width||1,h:t?.naturalHeight||t?.height||1}}function k(e,t,n){let r=t.material??{};return{uMap:{value:e},uTint:{value:r.color?n.color(r.color):new a(1,1,1)},uOpacity:{value:_(g(r.opacity,1),0,1)},uIntensity:{value:Math.max(0,g(r.emissiveIntensity,1))}}}function A(e,t,n,r){let i=new p({vertexShader:e,fragmentShader:t,uniforms:n,transparent:r,toneMapped:!1,fog:!1,side:0});return i.depthWrite=!r,i}function ue(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 d=new u;return d.setAttribute(`position`,new f(a,3)),d.setAttribute(`uv`,new f(o,2)),d.setAttribute(`uvOther`,new f(s,4)),d}function de(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))))}async function j(a,u){let[f,p]=await Promise.all([h(u.resolveAsset(a.src)),a.depth?h(u.resolveAsset(a.depth)).catch(e=>(u.issue(`asset-load`,`${a.id}: depth map: ${e.message} — showing the photo flat`,`objects#${a.id}.depth`),null)):Promise.resolve(null)]);f.colorSpace=l,f.wrapS=f.wrapT=e,f.anisotropy=4,f.needsUpdate=!0,p&&(p.colorSpace=``,p.premultiplyAlpha=!1,p.wrapS=p.wrapT=e,p.generateMipmaps=!1,p.minFilter=d,p.magFilter=d,p.needsUpdate=!0);let b=le(f),{width:T,height:j}=ee(a,b.w,b.h),M=_(g(a.strength,y.strength),0,1),N=_(g(a.focus,y.focus),0,1),P=_(g(a.material?.opacity,1),0,1),F=P<1||/\.(png|webp)$/i.test(a.src),I=te(a.motion),L=p?a.mode??`parallax`:`flat`,R=new t,z=new t;R.add(z);let B=[],V=[],H=[],U=[],W=null,G=()=>{let e=new i(T,j);return V.push(e),e};if(L===`flat`){let e=a.material??{},t=new o({map:f,transparent:F,opacity:P,toneMapped:!1,fog:!1});e.color&&t.color.copy(u.color(e.color)),t.color.multiplyScalar(Math.max(0,g(e.emissiveIntensity,1))),F&&(t.alphaTest=P<1?0:.004),B.push(t),z.add(new m(G(),t))}else if(L===`parallax`){let e=C(M,T,j),t={...k(f,a,u),uDepth:{value:p},uView:{value:new n},uZoom:{value:0},uMaxOffset:{value:new n(...e.maxOffset)},uInset:{value:new n(...e.inset)},uFocus:{value:N},uWallSlope:{value:.02}},r=A(E,D.replace(`__STEPS__`,String(de(u.quality,M))),t,F);B.push(r),H.push(r),z.add(new m(G(),r))}else if(L===`mesh`){let[e,t]=ne(g(a.segments,y.segments),T,j),o=w(M,T),l=ue(T,j,e,t);l.boundingBox=new s(new r(-T/2,-j/2,-N*o),new r(T/2,j/2,(1-N)*o)),l.boundingSphere=l.boundingBox.getBoundingSphere(new c),V.push(l);let d={...k(f,a,u),uDepth:{value:p},uRange:{value:o},uFocus:{value:N},uEdgeCut:{value:_(g(a.edgeCut,y.edgeCut),0,1)},uCam:{value:new r(0,0,1e6)},uPerspective:{value:0}};W=d;let h=A(ae,oe,d,P<1);h.side=2,B.push(h);let v=new m(l,h);v.renderOrder=1,z.add(v);{let r=new i(T,j,Math.max(1,Math.round(e/2)),Math.max(1,Math.round(t/2)));r.boundingBox=l.boundingBox.clone(),r.boundingSphere=l.boundingSphere.clone(),V.push(r);let a=new n(6/e,6/t),o=A(se,O,{...d,uReach:{value:a}},P<1);o.side=2,B.push(o);let s=new m(r,o);s.renderOrder=0,s.raycast=()=>void 0,z.add(s)}}else{let e=C(M,T,j),t=G(),r=re(g(a.layers,y.layers),N,M,T),i=_(g(a.edgeCut,y.edgeCut),0,1);r.forEach((r,o)=>{let s=A(E,ce,{...k(f,a,u),uDepth:{value:p},uView:{value:new n},uZoom:{value:0},uMaxOffset:{value:new n(...e.maxOffset)},uInset:{value:new n(...e.inset)},uFocus:{value:N},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}},!r.background||F);B.push(s),H.push(s);let c=new m(t,s);c.position.z=r.z,c.renderOrder=o,c.userData.a3dPhotoLayer=o,z.add(c),U.push({mesh:c,band:r})})}let K=!u.deterministic,q={x:0,y:0,weight:0,init:!1},J=null,Y=null,X=null;if(K&&I.gyro&&I.pointer>0&&L!==`flat`&&typeof window<`u`&&typeof window.addEventListener==`function`){let e=e=>{if(e.beta===null||e.gamma===null)return;Y??={beta:e.beta,gamma:e.gamma};let t=typeof screen<`u`&&screen.orientation?.angle||0;J=ie(e.beta,e.gamma,Y,t)};window.addEventListener(`deviceorientation`,e),X=()=>window.removeEventListener(`deviceorientation`,e)}let Z=new r,Q=!1,$=M*8*v;return{object:R,update:(e,t,n)=>{if(L===`flat`)return;let r=n.pointer,i=r.inside?_(r.x,-1,1):0,a=r.inside?_(r.y,-1,1):0,o=+!!r.inside;!K||!q.init?(q.x=i,q.y=a,q.weight=o,q.init=K):(q.x=S(q.x,i,t,I.smoothing),q.y=S(q.y,a,t,I.smoothing),q.weight=S(q.weight,o,t,I.smoothing));let s=x(I,{t:e,pointer:q,gyro:K?J:null,scroll:n.scroll,reduced:n.reduced});for(let e of H)e.uniforms.uView.value.set(s.x,s.y),e.uniforms.uZoom.value=s.zoom;let c=!!n.camera&&!!n.camera.isPerspectiveCamera;if(n.camera&&!Q&&L!==`parallax`&&(n.camera.updateMatrixWorld(),R.updateWorldMatrix(!0,!1),Z.setFromMatrixPosition(n.camera.matrixWorld),R.worldToLocal(Z),Q=!0),L===`mesh`)z.rotation.set(s.y*$,-s.x*$,0),z.position.z=s.zoom*w(M,T)*.5,W&&(W.uCam.value.copy(Z),W.uPerspective.value=c&&Z.z>0?1:0);else if(L===`layers`&&Q){let e=Z.z;for(let{mesh:t,band:n}of U)if(c&&e>n.z+.001){let r=(e-n.z)/e;t.scale.set(r,r,1),t.position.set(Z.x*n.z/e,Z.y*n.z/e,n.z)}else t.scale.set(1,1,1),t.position.set(0,0,n.z)}},dispose(){X?.(),X=null;for(let e of B)e.dispose();for(let e of V)e.dispose();f.dispose(),p?.dispose()}}}export{j as buildPhoto};