@fleox/agent3d 0.2.1 → 0.2.3

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 (47) hide show
  1. package/README.md +11 -10
  2. package/changelog.json +22 -0
  3. package/dist/agent/agent3d.mjs +58 -47
  4. package/dist/agent/chunks/{browser-t_JL_B82.mjs → browser-Br1tURgt.mjs} +21 -2
  5. package/dist/agent/chunks/{check-CBO3Ekx1.mjs → check-CfZcfaPs.mjs} +12 -0
  6. package/dist/agent/chunks/{export-BCI8vKw8.mjs → export-BHugc2H7.mjs} +1 -1
  7. package/dist/agent/chunks/{imageCodec-Dz9PFxi9.mjs → imageCodec-QM0EXQDJ.mjs} +1 -1
  8. package/dist/agent/chunks/{package-BOIyp_2B.mjs → package-fw4h5vsh.mjs} +2 -2
  9. package/dist/agent/chunks/{render-CN4mgGLQ.mjs → render-EHb40avl.mjs} +1 -1
  10. package/dist/agent/chunks/{tools-DT2tetIK.mjs → tools-DKxgjQSJ.mjs} +2 -2
  11. package/dist/runtime/agent3d-runtime.js +2 -2
  12. package/dist/runtime/agent3d-runtime.single.js +2 -2
  13. package/dist/runtime/chunks/catalog--OTp4gjy.js +1 -0
  14. package/dist/runtime/chunks/{generators-D5JUo0jp.js → generators--kOFg1G_.js} +1 -1
  15. package/dist/runtime/chunks/{materials-Dn-bYrZd.js → materials-w3EW0g-7.js} +1 -1
  16. package/dist/runtime/chunks/{model-BCVF3QzB.js → model-DbfZaLni.js} +1 -1
  17. package/dist/runtime/chunks/{params-C2uoUDJ0.js → params-BCNrVCYZ.js} +1 -1
  18. package/dist/runtime/chunks/{postfx-i_J5Vf-l.js → postfx-CFucYRev.js} +1 -1
  19. package/dist/runtime/chunks/{postfx-UgKCbmZs.js → postfx-Cbf_vvOr.js} +1 -1
  20. package/dist/runtime/chunks/{shaders-Dw6zHdu_.js → shaders-Ba3v6Xnj.js} +1 -1
  21. package/dist/runtime/chunks/{svg-CmlFY_8O.js → svg-CfPIQnDG.js} +1 -1
  22. package/dist/runtime/chunks/{text-D1EQpdSU.js → text-BaON-ISS.js} +1 -1
  23. package/dist/studio/assets/{camera-7sEn13L-.js → camera-Be6lnp3k.js} +1 -1
  24. package/dist/studio/assets/{editor-CnbvVkhU.js → editor-Mpnz-b2E.js} +1 -1
  25. package/dist/studio/assets/{game-B04KGAK0.js → game-WMgRSJUD.js} +3 -3
  26. package/dist/studio/assets/{generators-LSni1Yfc.js → generators-DozXE7ta.js} +1 -1
  27. package/dist/studio/assets/{index-3LL5NEIH.js → index-tSGZFEt5.js} +5 -5
  28. package/dist/studio/assets/{model-CNddhwmA.js → model-C2bZTK7-.js} +1 -1
  29. package/dist/studio/assets/{physicsHost-hMU_SDiX.js → physicsHost-CTRsIvfu.js} +1 -1
  30. package/dist/studio/assets/{postfx-BcCZS0Bq.js → postfx-DQtp0JIy.js} +1 -1
  31. package/dist/studio/assets/{runtime-DY_KqD1x.js → runtime-NGp1VdnH.js} +4 -4
  32. package/dist/studio/assets/{shaders-BhMCstyv.js → shaders-BOb6Uter.js} +1 -1
  33. package/dist/studio/assets/{svg-CNKK-h7H.js → svg-CnUMpv_N.js} +1 -1
  34. package/dist/studio/assets/{text-BSPI7dk1.js → text-CGIZs8HE.js} +1 -1
  35. package/dist/studio/index.html +1 -1
  36. package/package.json +2 -2
  37. package/plugin/.claude-plugin/plugin.json +1 -1
  38. package/plugin/skills/agent3d-assets/SKILL.md +24 -24
  39. package/plugin/skills/agent3d-create/SKILL.md +20 -20
  40. package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
  41. package/plugin/skills/agent3d-create/references/recipes.md +6 -6
  42. package/plugin/skills/agent3d-edit/SKILL.md +22 -22
  43. package/plugin/skills/agent3d-edit/references/patch-ops.md +2 -2
  44. package/plugin/skills/agent3d-game/SKILL.md +7 -7
  45. package/plugin/skills/agent3d-publish/SKILL.md +21 -21
  46. package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
  47. package/dist/runtime/chunks/catalog-DL6sgPay.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./physicsHost-hMU_SDiX.js","./camera-7sEn13L-.js","./three.module-CnI50X0U.js","./index-3LL5NEIH.js","./index-BQT0otii.css"])))=>i.map(i=>d[i]);
2
- import{In as e,Ln as t,Qt as n,zt as r}from"./three.module-CnI50X0U.js";import{_ as i,d as a,i as o,x as s}from"./camera-7sEn13L-.js";import{S as c,h as l}from"./index-3LL5NEIH.js";function u(e,t,n){let r=null,i=null,a=!!e?.muted,o=null,s=new Map,c=null,u=!!e?.music,d=()=>l(()=>import(`./audio-JD1kyX0A.js`).then(e=>o=e.SOUND_IMPLS),[],import.meta.url).catch(()=>o={}),f=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)},p=(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 f(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},m=()=>{!c&&e?.music&&!a&&r&&(c=p(e.music,e.music.loop!==!1))};return d(),{play(t){if(a||!r)return;let n=e?.sounds?.[t];n?p(n):o?.[t]&&o[t].play(r,i,1)},music(e){u=e,e?m():(c?.stop(),c=null)},muted:()=>a,setMuted(t){a=t,i&&r&&i.gain.setTargetAtTime(+!t,r.currentTime,.02),t?(c?.stop(),c=null):(u||e?.music)&&(u=!0,m())},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),u&&m()}catch(e){n(e.message)}},dispose(){c?.stop(),r?.close().catch(()=>void 0),r=null}}}function d(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 f=new Set([`__proto__`,`prototype`,`constructor`]);function p(e,t){let n=t.split(`.`);n[0]===`state`&&n.shift();let r=e;for(let e of n){if(f.has(e)||typeof r!=`object`||!r||!Object.prototype.hasOwnProperty.call(r,e))return;r=r[e]}return r}function m(e,t){let n=d(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:p(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 f=u();if(r<n.length)throw Error(`Unexpected "${n[r].v}"`);return f}function h(e,t){if(e===void 0)return!0;if(typeof e==`boolean`)return e;try{return!!m(e,t)}catch{return!1}}function g(e,t){return e.replace(/\{([^{}]+)\}/g,(e,n)=>{let r=n.trim(),i;try{i=/^[A-Za-z_$][A-Za-z0-9_$.]*$/.test(r)?p(t,r):m(r,t)}catch{i=void 0}return i==null?``:String(typeof i==`number`?Number.isInteger(i)?i:Math.round(i*100)/100:i)})}var _={"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;`},v=(e,t,n)=>`font-size:${n}px;font-size:clamp(${e}px,min(${t}cqw,${(t*1.6).toFixed(1)}cqh),${n}px)`,y=(e,t,n,r)=>`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./physicsHost-CTRsIvfu.js","./camera-Be6lnp3k.js","./three.module-CnI50X0U.js","./index-tSGZFEt5.js","./index-BQT0otii.css"])))=>i.map(i=>d[i]);
2
+ import{In as e,Ln as t,Qt as n,zt as r}from"./three.module-CnI50X0U.js";import{_ as i,d as a,i as o,x as s}from"./camera-Be6lnp3k.js";import{S as c,h as l}from"./index-tSGZFEt5.js";function u(e,t,n){let r=null,i=null,a=!!e?.muted,o=null,s=new Map,c=null,u=!!e?.music,d=()=>l(()=>import(`./audio-JD1kyX0A.js`).then(e=>o=e.SOUND_IMPLS),[],import.meta.url).catch(()=>o={}),f=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)},p=(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 f(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},m=()=>{!c&&e?.music&&!a&&r&&(c=p(e.music,e.music.loop!==!1))};return d(),{play(t){if(a||!r)return;let n=e?.sounds?.[t];n?p(n):o?.[t]&&o[t].play(r,i,1)},music(e){u=e,e?m():(c?.stop(),c=null)},muted:()=>a,setMuted(t){a=t,i&&r&&i.gain.setTargetAtTime(+!t,r.currentTime,.02),t?(c?.stop(),c=null):(u||e?.music)&&(u=!0,m())},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),u&&m()}catch(e){n(e.message)}},dispose(){c?.stop(),r?.close().catch(()=>void 0),r=null}}}function d(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 f=new Set([`__proto__`,`prototype`,`constructor`]);function p(e,t){let n=t.split(`.`);n[0]===`state`&&n.shift();let r=e;for(let e of n){if(f.has(e)||typeof r!=`object`||!r||!Object.prototype.hasOwnProperty.call(r,e))return;r=r[e]}return r}function m(e,t){let n=d(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:p(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 f=u();if(r<n.length)throw Error(`Unexpected "${n[r].v}"`);return f}function h(e,t){if(e===void 0)return!0;if(typeof e==`boolean`)return e;try{return!!m(e,t)}catch{return!1}}function g(e,t){return e.replace(/\{([^{}]+)\}/g,(e,n)=>{let r=n.trim(),i;try{i=/^[A-Za-z_$][A-Za-z0-9_$.]*$/.test(r)?p(t,r):m(r,t)}catch{i=void 0}return i==null?``:String(typeof i==`number`?Number.isInteger(i)?i:Math.round(i*100)/100:i)})}var _={"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;`},v=(e,t,n)=>`font-size:${n}px;font-size:clamp(${e}px,min(${t}cqw,${(t*1.6).toFixed(1)}cqh),${n}px)`,y=(e,t,n,r)=>`
3
3
  .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}
4
4
  .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}
5
5
  .a3d-el{line-height:1.2;text-shadow:0 1px 3px rgba(0,0,0,.45);white-space:pre-line;overflow-wrap:break-word}
@@ -16,4 +16,4 @@ import{In as e,Ln as t,Qt as n,zt as r}from"./three.module-CnI50X0U.js";import{_
16
16
  .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;${v(12,3.4,15)};transition:opacity .25s ease;text-shadow:none}
17
17
  .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}
18
18
  .a3d-mute svg{width:55%;height:55%}
19
- `,b=`<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>`,x=`<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 S(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=y(t?.font??`system-ui,-apple-system,'Segoe UI',Roboto,sans-serif`,t?.color??`#ffffff`,o,t?.buttonText??c(o)),i.appendChild(a);let s=new Map,l=e=>{let t=s.get(e);return t||(t=r.createElement(`div`),t.className=`a3d-zone`,t.style.cssText=_[e]??_[`top-left`],t.dataset.anchor=e,i.appendChild(t),s.set(e,t)),t},u=[[`top-left`,`top`,`top-right`],[`left`,`center`,`right`],[`bottom-left`,`bottom`,`bottom-right`]],d=()=>{for(let[e,t,n]of u){let r=s.get(t);r&&(r.style.gridColumn=s.has(e)||s.has(n)?`2`:`1 / -1`)}},f=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=c(e.background)),t.dataset.id=e.id,l(e.anchor??`top-left`).appendChild(t),f.set(e.id,{def:e,node:t,fill:i,override:{},last:``})}d(),e.appendChild(i);let m=null,v=0,S=null,C=null,w=null;return{root:i,setTimeline(e){w=e},set(e,t){let n=f.get(e);n&&Object.assign(n.override,t)},toast(e,t=2){S={text:e,seconds:t}},update(e,t){let n=w&&!Object.prototype.hasOwnProperty.call(e,`timeline`)?{...e,timeline:w}:e;for(let e of f.values()){let t=e.override.visible??h(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?p(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??g(e.def.text??``,n);r!==e.last&&(e.node.textContent=r,e.last=r)}S&&=(m||(m=r.createElement(`div`),m.className=`a3d-toast`,i.appendChild(m)),m.textContent=S.text,m.style.opacity=`1`,v=t+S.seconds,null),m&&t>v&&(m.style.opacity=`0`)},setMuteButton(e,t){e===null?(C?.remove(),C=null):(C||(C=r.createElement(`button`),C.type=`button`,C.className=`a3d-mute`,C.addEventListener(`pointerdown`,e=>e.stopPropagation()),C.addEventListener(`click`,e=>{e.stopPropagation(),t?.()}),l(`bottom-right`).appendChild(C),d()),C.innerHTML=e?x:b,C.setAttribute(`aria-label`,e?`Unmute sound`:`Mute sound`))},dispose(){i.remove()}}}var C=null,w=()=>C??=l(()=>import(`./physicsHost-hMU_SDiX.js`),__vite__mapDeps([0,1,2,3,4]),import.meta.url);function T(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 E=new Map,D=class c{opts;world;physics=null;state={};hud=null;audio;instances=[];factories=[];objCache=new Map;handlers=new Map;collisionHandlers=[];collisionEndHandlers=[];triggerEnterHandlers=[];triggerExitHandlers=[];rng;simTime=0;acc=0;stepDt;pendingPressed=new Set;pendingJust=!1;pendingSwipe=null;stepPressed=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=o(e.scene.seed??1),this.audio=u(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 c(e);if(n.hud=e.scene.ui?.elements?.length||e.scene.audio?S(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=E.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(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(()=>E.delete(a)),E.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 w(),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=o(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=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=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 n=this.objCache.get(e.id);if(n)return n;let r=this,o=e.id,c=()=>r.world.entries.get(o)??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(o)},u=()=>r.physics?.engine.get(o)?.velocity??[0,0,0],d=(e,t)=>{let n=u();n[e]=t,r.physics?.engine.setVelocity(o,n)},f={id:o,position:T(()=>c().object.position,1,l),rotation:T(()=>c().object.rotation,a,l),scale:T(()=>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(o,[e,t,n])}},get userData(){return c().object.userData},get tags(){return c().object.userData.tags??[]},setColor(e){let t=s(e);for(let e of i(c().object))e.color?.copy(t)},setOpacity(e){for(let t of i(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 n=c().object.getWorldPosition(new t),i=r.world.entries.get(e.id);return i?n.distanceTo(i.object.getWorldPosition(new t)):1/0},remove(){r.world.entries.get(o)?.object.traverse(e=>{let t=e.userData.a3dId;t&&r.physics?.remove(t)}),r.physics?.remove(o),r.world.removeEntry(o),r.objCache.delete(o)}};return this.objCache.set(o,f),f}idOf(e){return typeof e==`string`?e:e.id}createApi(){let i=this,o=()=>i.opts.input,s={id:`camera`,position:T(()=>i.world.rig.rest.position),rotation:T(()=>i.world.camera.rotation,a),scale:T(()=>i.world.camera.scale),visible:!0,velocity:T(()=>new t),userData:{},tags:[],setColor(){},setOpacity(){},playAnimation(){},distanceTo(e){let n=i.world.entries.get(e.id);return n?i.world.camera.position.distanceTo(n.object.getWorldPosition(new t)):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 n,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,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:s,time:()=>i.simTime,random:()=>i.rng.next(),randomRange:(e,t)=>i.rng.range(e,t),input:{isDown:e=>o().keys.has(e),pressed:e=>i.stepPressed.has(e),get pointer(){let e=o().pointer;return{x:e.x,y:e.y,down:e.down,justPressed:i.stepJust}},swipe:()=>i.stepSwipe,pointerWorld:()=>{let n=o().pointer;c.setFromCamera(new e(n.x,n.y),i.world.camera);let a=[];for(let e of i.physics?.engine.bodies??[]){let t=i.world.entries.get(e.id);t&&a.push(t.object)}let s=a.length?c.intersectObjects(a,!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 t;return c.ray.intersectPlane(new r(new t(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]*a,t[1]*a,t[2]*a]),getAngularVelocity:e=>{let t=i.physics?.engine.get(i.idOf(e))?.angularVelocity??[0,0,0];return[t[0]/a,t[1]/a,t[2]/a]},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*a),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{D as GameHost};
19
+ `,b=`<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>`,x=`<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 S(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=y(t?.font??`system-ui,-apple-system,'Segoe UI',Roboto,sans-serif`,t?.color??`#ffffff`,o,t?.buttonText??c(o)),i.appendChild(a);let s=new Map,l=e=>{let t=s.get(e);return t||(t=r.createElement(`div`),t.className=`a3d-zone`,t.style.cssText=_[e]??_[`top-left`],t.dataset.anchor=e,i.appendChild(t),s.set(e,t)),t},u=[[`top-left`,`top`,`top-right`],[`left`,`center`,`right`],[`bottom-left`,`bottom`,`bottom-right`]],d=()=>{for(let[e,t,n]of u){let r=s.get(t);r&&(r.style.gridColumn=s.has(e)||s.has(n)?`2`:`1 / -1`)}},f=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=c(e.background)),t.dataset.id=e.id,l(e.anchor??`top-left`).appendChild(t),f.set(e.id,{def:e,node:t,fill:i,override:{},last:``})}d(),e.appendChild(i);let m=null,v=0,S=null,C=null,w=null;return{root:i,setTimeline(e){w=e},set(e,t){let n=f.get(e);n&&Object.assign(n.override,t)},toast(e,t=2){S={text:e,seconds:t}},update(e,t){let n=w&&!Object.prototype.hasOwnProperty.call(e,`timeline`)?{...e,timeline:w}:e;for(let e of f.values()){let t=e.override.visible??h(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?p(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??g(e.def.text??``,n);r!==e.last&&(e.node.textContent=r,e.last=r)}S&&=(m||(m=r.createElement(`div`),m.className=`a3d-toast`,i.appendChild(m)),m.textContent=S.text,m.style.opacity=`1`,v=t+S.seconds,null),m&&t>v&&(m.style.opacity=`0`)},setMuteButton(e,t){e===null?(C?.remove(),C=null):(C||(C=r.createElement(`button`),C.type=`button`,C.className=`a3d-mute`,C.addEventListener(`pointerdown`,e=>e.stopPropagation()),C.addEventListener(`click`,e=>{e.stopPropagation(),t?.()}),l(`bottom-right`).appendChild(C),d()),C.innerHTML=e?x:b,C.setAttribute(`aria-label`,e?`Unmute sound`:`Mute sound`))},dispose(){i.remove()}}}var C=null,w=()=>C??=l(()=>import(`./physicsHost-CTRsIvfu.js`),__vite__mapDeps([0,1,2,3,4]),import.meta.url);function T(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 E=new Map,D=class c{opts;world;physics=null;state={};hud=null;audio;instances=[];factories=[];objCache=new Map;handlers=new Map;collisionHandlers=[];collisionEndHandlers=[];triggerEnterHandlers=[];triggerExitHandlers=[];rng;simTime=0;acc=0;stepDt;pendingPressed=new Set;pendingJust=!1;pendingSwipe=null;stepPressed=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=o(e.scene.seed??1),this.audio=u(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 c(e);if(n.hud=e.scene.ui?.elements?.length||e.scene.audio?S(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=E.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(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(()=>E.delete(a)),E.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 w(),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=o(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=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=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 n=this.objCache.get(e.id);if(n)return n;let r=this,o=e.id,c=()=>r.world.entries.get(o)??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(o)},u=()=>r.physics?.engine.get(o)?.velocity??[0,0,0],d=(e,t)=>{let n=u();n[e]=t,r.physics?.engine.setVelocity(o,n)},f={id:o,position:T(()=>c().object.position,1,l),rotation:T(()=>c().object.rotation,a,l),scale:T(()=>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(o,[e,t,n])}},get userData(){return c().object.userData},get tags(){return c().object.userData.tags??[]},setColor(e){let t=s(e);for(let e of i(c().object))e.color?.copy(t)},setOpacity(e){for(let t of i(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 n=c().object.getWorldPosition(new t),i=r.world.entries.get(e.id);return i?n.distanceTo(i.object.getWorldPosition(new t)):1/0},remove(){r.world.entries.get(o)?.object.traverse(e=>{let t=e.userData.a3dId;t&&r.physics?.remove(t)}),r.physics?.remove(o),r.world.removeEntry(o),r.objCache.delete(o)}};return this.objCache.set(o,f),f}idOf(e){return typeof e==`string`?e:e.id}createApi(){let i=this,o=()=>i.opts.input,s={id:`camera`,position:T(()=>i.world.rig.rest.position),rotation:T(()=>i.world.camera.rotation,a),scale:T(()=>i.world.camera.scale),visible:!0,velocity:T(()=>new t),userData:{},tags:[],setColor(){},setOpacity(){},playAnimation(){},distanceTo(e){let n=i.world.entries.get(e.id);return n?i.world.camera.position.distanceTo(n.object.getWorldPosition(new t)):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 n,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,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:s,time:()=>i.simTime,random:()=>i.rng.next(),randomRange:(e,t)=>i.rng.range(e,t),input:{isDown:e=>o().keys.has(e),pressed:e=>i.stepPressed.has(e),get pointer(){let e=o().pointer;return{x:e.x,y:e.y,down:e.down,justPressed:i.stepJust}},swipe:()=>i.stepSwipe,pointerWorld:()=>{let n=o().pointer;c.setFromCamera(new e(n.x,n.y),i.world.camera);let a=[];for(let e of i.physics?.engine.bodies??[]){let t=i.world.entries.get(e.id);t&&a.push(t.object)}let s=a.length?c.intersectObjects(a,!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 t;return c.ray.intersectPlane(new r(new t(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]*a,t[1]*a,t[2]*a]),getAngularVelocity:e=>{let t=i.physics?.engine.get(i.idOf(e))?.angularVelocity??[0,0,0];return[t[0]/a,t[1]/a,t[2]/a]},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*a),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{D as GameHost};
@@ -1,4 +1,4 @@
1
- import{c as e,i as t,l as n}from"./runtime-DY_KqD1x.js";import{a as r,c as i,l as a,o,u as s}from"./camera-7sEn13L-.js";import{n as c}from"./BufferGeometryUtils-CAlXAboW.js";import{An as l,Bn as u,Bt as d,C as f,Dt as p,E as m,En as h,I as g,In as _,J as v,Jt as y,K as b,Kt as x,Ln as S,M as C,Mn as w,N as T,Ot as E,P as D,Rn as O,St as k,T as A,U as j,Ut as M,W as N,Y as P,_ as F,_n as I,bn as L,bt as R,cn as z,ct as B,d as ee,fn as te,h as ne,hn as re,it as ie,jn as ae,kn as oe,lt as se,m as V,mn as ce,nn as le,on as ue,p as de,pn as fe,rn as pe,st as me,tn as he,tt as ge,v as _e,wn as ve,x as H,xn as ye,xt as U,y as be,yt as xe,zt as Se}from"./three.module-CnI50X0U.js";var Ce=class{pos=[];col=[];uv=[];wind=[];useUv=!1;useWind=!1;windFn=null;pushVertex(e,t,n,r,i=0,a=0){if(this.pos.push(e,t,n),this.col.push(r.r,r.g,r.b),this.useUv&&this.uv.push(i,a),this.useWind){let r=this.windFn?this.windFn(e,t,n):[0,0];this.wind.push(r[0],r[1])}}tri(e,t,n,r,i){this.pushVertex(e[0],e[1],e[2],r,i?.[0],i?.[1]),this.pushVertex(t[0],t[1],t[2],r,i?.[2],i?.[3]),this.pushVertex(n[0],n[1],n[2],r,i?.[4],i?.[5])}quad(e,t,n,r,i,a){this.tri(e,t,n,i,a?[a[0],a[1],a[2],a[3],a[4],a[5]]:void 0),this.tri(e,n,r,i,a?[a[0],a[1],a[4],a[5],a[6],a[7]]:void 0)}box(e,t,n,r=n,i={}){let[a,o,s]=e,[c,l,u]=t,d=(e,t,n)=>{if(!i.uv)return;let[r,a,o,s]=i.uv(e,t,n);return[r,a,o,a,o,s,r,s]},f=c-a,p=l-o,m=u-s;this.quad([a,o,u],[c,o,u],[c,l,u],[a,l,u],n,d(`z`,f,p)),this.quad([c,o,s],[a,o,s],[a,l,s],[c,l,s],n,d(`z`,f,p)),this.quad([c,o,u],[c,o,s],[c,l,s],[c,l,u],n,d(`x`,m,p)),this.quad([a,o,s],[a,o,u],[a,l,u],[a,l,s],n,d(`x`,m,p)),this.quad([a,l,u],[c,l,u],[c,l,s],[a,l,s],r,d(`y`,f,m)),i.bottom&&this.quad([a,o,s],[c,o,s],[c,o,u],[a,o,u],n,d(`y`,f,m))}add(e,t,n){let r=e.index?e.toNonIndexed():e,i=r.getAttribute(`position`),a=new S,o=[[0,0,0],[0,0,0],[0,0,0]],s=[[0,0,0],[0,0,0],[0,0,0]];for(let e=0;e<i.count/3;e++){for(let n=0;n<3;n++)a.fromBufferAttribute(i,e*3+n),s[n]=[a.x,a.y,a.z],a.applyMatrix4(t),o[n]=[a.x,a.y,a.z];let r=typeof n==`function`?n((s[0][0]+s[1][0]+s[2][0])/3,(s[0][1]+s[1][1]+s[2][1])/3,(s[0][2]+s[1][2]+s[2][2])/3,e):n;this.tri(o[0],o[1],o[2],r)}r!==e&&r.dispose()}get triangles(){return this.pos.length/9}build(){let e=new ne;return e.setAttribute(`position`,new g(this.pos,3)),e.setAttribute(`color`,new g(this.col,3)),this.useUv&&e.setAttribute(`uv`,new g(this.uv,2)),this.useWind&&e.setAttribute(`aWind`,new g(this.wind,2)),e.computeVertexNormals(),e.computeBoundingBox(),e.computeBoundingSphere(),e}};function we(e,t,n){let r=e.getAttribute(`position`),i=new Map;for(let e=0;e<r.count;e++){let a=`${r.getX(e).toFixed(4)},${r.getY(e).toFixed(4)},${r.getZ(e).toFixed(4)}`,o=i.get(a);o||(o=[(n()-.5)*t,(n()-.5)*t,(n()-.5)*t],i.set(a,o)),r.setXYZ(e,r.getX(e)+o[0],r.getY(e)+o[1],r.getZ(e)+o[2])}return r.needsUpdate=!0,e}var Te=(e,t,n,r=1,i=r,a=r,o=0,s=0,c=0)=>new R().compose(new S(e,t,n),new x().setFromEuler(new T(o,s,c)),new S(r,i,a)),Ee=(e,t)=>e.clone().multiplyScalar(t);function De(e,t,n=new H){if(e.length===1)return n.copy(e[0]);let r=Math.min(1,Math.max(0,t))*(e.length-1),i=Math.min(e.length-2,Math.floor(r));return n.copy(e[i]).lerp(e[i+1],r-i)}var W=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)};function Oe(e){let t=[...e.siblings.values()].filter(e=>e.heightAt&&e.object.userData.surface!==`water`),n=e.placement?.position??[0,0,0],r=e=>{let t=e.object.userData.size;if(typeof t!=`number`)return 1/0;let r=e.object.position,i=e.object.scale,a=t/2*Math.abs(i.x||1),o=t/2*Math.abs(i.z||1);return Math.abs(n[0]-r.x)<=a&&Math.abs(n[2]-r.z)<=o?a*o:-1},i=e=>{let t=r(e);return(t<0?2:0)+(e.object.userData.surface===`terrain`?0:1)+(t>0&&Number.isFinite(t)?t/1e9:.5)};t.sort((e,t)=>i(e)-i(t));for(let n of t){if(!n.heightAt)continue;let t=n.object.position,r=n.object.scale,i=e.placement?.position??[0,0,0],a=e.placement?.scale??[1,1,1],o=n.heightAt.bind(n),s=e=>(e-i[1])/(a[1]||1),c=typeof n.object.userData.waterLevel==`number`?s(n.object.userData.waterLevel*r.y+t.y):null;return{snow:typeof n.object.userData.snowLevel==`number`?s(n.object.userData.snowLevel*r.y+t.y):null,height:(e,n)=>{let c=i[0]+e*a[0],l=i[2]+n*a[2];return s(o((c-t.x)/(r.x||1),(l-t.z)/(r.z||1))*r.y+t.y)},water:c}}return null}function ke(e,t,n,r=.15,i=!0){let a=null,o={x:0,y:0,z:0};for(let s=0;s<12;s++){let c=(e.next()-.5)*t[0],l=(e.next()-.5)*t[2],u=n?n.height(c,l):(e.next()-.5)*t[1];if(s===0&&(o={x:c,y:u,z:l}),!n)return{x:c,y:u,z:l};let d=n.water===null||u>n.water+r,f=!i||n.snow===null||n.snow===void 0||u<n.snow;if(d&&f)return{x:c,y:u,z:l};d&&(!a||u<a.y)&&(a={x:c,y:u,z:l})}return a??o}function Ae(e={}){return new E({vertexColors:!0,flatShading:e.flat??!0,roughness:e.roughness??.9,metalness:e.metalness??0,side:e.side??0})}function je(e){e.traverse(e=>{let t=e;t.geometry&&t.geometry.dispose();let n=t.material?Array.isArray(t.material)?t.material:[t.material]:[];for(let e of n){for(let t of Object.values(e))t instanceof ve&&t.dispose();e.dispose()}})}function G(e,t={}){return{object:e,dispose:()=>je(e),...t}}var Me=[`sphere`,`torus`,`ring`,`pill`,`cone`,`cube`,`halfDisc`,`squiggle`,`triangle`,`star`];function Ne(e){switch(e){case`sphere`:return new re(.5,40,28);case`torus`:return new h(.38,.14,24,64);case`ring`:return new h(.42,.045,12,64);case`pill`:return new F(.2,.6,10,24).rotateZ(Math.PI/2);case`cone`:return new f(.4,.8,40);case`cube`:return new t(.7,.7,.7,4,.08);case`halfDisc`:{let e=new A(.5,.5,.18,40,1,!1,0,Math.PI);return e.rotateX(Math.PI/2),e}case`squiggle`:{let e=Array.from({length:9},(e,t)=>new S((t/8-.5)*1.3,Math.sin(t*1.4)*.16,0));return new oe(new _e(e),80,.06,12,!1)}case`triangle`:{let e=new z;for(let t=0;t<3;t++){let n=Math.PI/2+t/3*Math.PI*2;t===0?e.moveTo(Math.cos(n)*.5,Math.sin(n)*.5):e.lineTo(Math.cos(n)*.5,Math.sin(n)*.5)}let t=new D(e,{depth:.16,bevelEnabled:!0,bevelThickness:.04,bevelSize:.04,bevelSegments:4});return t.center(),t}case`star`:{let e=new z;for(let t=0;t<10;t++){let n=Math.PI/2+t/10*Math.PI*2,r=t%2?.22:.5;t===0?e.moveTo(Math.cos(n)*r,Math.sin(n)*r):e.lineTo(Math.cos(n)*r,Math.sin(n)*r)}let t=new D(e,{depth:.14,bevelEnabled:!0,bevelThickness:.04,bevelSize:.03,bevelSegments:3});return t.center(),t}}}var Pe=(t,r)=>{let i=n(`abstractShapes`,t,r),a=i.int(`count`),o=i.vec3(`area`),s=i.colors(`colors`),c=i.num(`minSize`),l=Math.max(c,i.num(`maxSize`)),u=i.str(`style`),d=i.num(`motion`),f=i.raw(`shapes`),m=Array.isArray(f)?f.filter(e=>Me.includes(e)):[],h=m.length?m:[...Me],g=r.rng,_=[];for(let e=0;e<a;e++){let t=new S,n=-1;for(let e=0;e<14;e++){let e=new S((g.next()-.5)*o[0],(g.next()-.5)*o[1],(g.next()-.5)*o[2]),r=1/0;for(let t of _)r=Math.min(r,e.distanceTo(t.pos)-t.s*.6);r>n&&(n=r,t=e)}let r=c+(l-c)*(1-e/Math.max(1,a))**1.5*g.range(.7,1);_.push({pos:t,s:r,kind:h[e%h.length],color:s[e%s.length],rot:new T(g.range(-.6,.6),g.next()*Math.PI*2,g.range(-.8,.8)),spin:new S(g.range(-.25,.25),g.range(-.35,.35),g.range(-.2,.2)),ph:g.next()*Math.PI*2})}for(let e=_.length-1;e>0;e--){let t=Math.floor(g.next()*(e+1)),n=_[e].color;_[e].color=_[t].color,_[t].color=n}let v=u===`toon`?e({color:16777215}):u===`glossy`?new p({color:16777215,roughness:.18,clearcoat:1,clearcoatRoughness:.08}):new E({color:16777215,roughness:.62,metalness:0}),y=new j;y.name=`abstractShapes`;let b=[];for(let e of h){let t=_.filter(t=>t.kind===e);if(!t.length)continue;let n=new P(Ne(e),v,t.length);n.name=`shapes-${e}`,n.castShadow=!0,n.receiveShadow=!0,n.userData.materialTarget=!0,t.forEach((e,t)=>n.setColorAt(t,e.color)),n.frustumCulled=!1,y.add(n),b.push({mesh:n,list:t})}let C=new R,w=new x,D=new T,O=new S,k=new S,A=e=>{for(let{mesh:t,list:n}of b)n.forEach((n,r)=>{O.copy(n.pos),O.y+=Math.sin(e*.8+n.ph)*.12*d*(.5+n.s*.5),D.set(n.rot.x+n.spin.x*e*d,n.rot.y+n.spin.y*e*d,n.rot.z+n.spin.z*e*d),w.setFromEuler(D),k.setScalar(n.s),t.setMatrixAt(r,C.compose(O,w,k))}),t.instanceMatrix.needsUpdate=!0};return A(0),G(y,{update:e=>A(e)})},Fe=e=>1+2.4*(e-1)**3+1.4*(e-1)**2;function Ie(e){if(!Array.isArray(e)||e.length===0)return[[3,5,4,7,6,9,8]];let t=e=>typeof e==`number`&&Number.isFinite(e)?e:e&&typeof e==`object`&&typeof e.value==`number`?e.value:0;return e.every(e=>Array.isArray(e))?e.map(e=>e.map(t)):[e.map(t)]}var Le=(e,r)=>{let i=n(`bars3d`,e,r),a=Ie(i.raw(`data`)),o=a.length,s=Math.max(...a.map(e=>e.length),1),c=i.num(`barWidth`),l=i.num(`gap`),u=i.num(`maxHeight`),d=i.colors(`colors`),f=i.str(`colorBy`),m=i.str(`shape`),h=i.str(`animation`),g=i.num(`duration`),_=Math.max(1e-6,...a.flat().map(e=>Math.abs(e))),v=c+l,y;y=m===`cylinder`?new A(.5,.5,1,32):m===`box`?new de(1,1,1):new t(1,1,1,4,.12),y.translate(0,.5,0);let b=o*s,C=new p({roughness:.32,metalness:0,clearcoat:.6,clearcoatRoughness:.25}),w=new P(y,C,b);w.name=`bars`,w.castShadow=!0,w.receiveShadow=!0,w.userData.materialTarget=!0;let T=[],D=new H,O=0;for(let e=0;e<o;e++)for(let t=0;t<s;t++){let n=a[e][t]??0,r=Math.max(1e-4,Math.abs(n)/_*u),i=(t-(s-1)/2)*v,c=(e-(o-1)/2)*v,l=f===`row`?o>1?e/(o-1):0:f===`column`?s>1?t/(s-1):0:Math.abs(n)/_;f===`value`?De(d,l,D):D.copy(d[(f===`row`?e:t)%d.length]),w.setColorAt(O,D),T.push({x:i,z:c,h:r,i:O,delay:(t+e*.6)/Math.max(1,s+o*.6)}),O++}let k=new R,M=new x,N=new S,F=new S,I=e=>{for(let t of T){let n=1;if(h===`grow`){let r=(e-t.delay*g*.6)/(g*.5);n=r<=0?1e-4:r>=1?1:Fe(Math.min(1,r)),r>0&&r<1&&(n=Math.max(1e-4,n))}else h===`wave`&&(n=.55+.45*(.5+.5*Math.sin(e*1.6-t.x*.9-t.z*.7)));N.set(t.x,0,t.z),F.set(c,t.h*n,c),w.setMatrixAt(t.i,k.compose(N,M,F))}w.instanceMatrix.needsUpdate=!0};I(0),w.computeBoundingSphere(),w.frustumCulled=!1;let L=new j;if(L.name=`bars3d`,L.add(w),i.bool(`base`)){let e=s*v+l,n=o*v+l,r=new U(new t(e,.12,n,3,.05),new E({color:i.color(`baseColor`),roughness:.6}));r.position.y=-.06,r.receiveShadow=!0,r.castShadow=!0,r.name=`bars-base`,L.add(r)}return G(L,{update:e=>I(e)})};function Re(){let e=[],t=[],n=(n,r,i,a)=>{e.push(...n,...r,...i),t.push(a,a,a)},r=[0,0,.42],i=[0,.01,-.34],a=[0,.07,.04],o=[0,-.06,.02],s=[-.075,0,.04],c=[.075,0,.04];for(let[e,t]of[[s,a],[a,c],[c,o],[o,s]])n(r,e,t,0),n(i,t,e,0);n([0,.01,-.3],[-.14,.02,-.58],[.14,.02,-.58],0);for(let e of[-1,1]){let t=[e*.05,.01,.14],r=[e*.05,.01,-.12],i=[e*.48,0,.1],a=[e*.48,0,-.14],o=[e*1,-.01,-.26];n(t,i,a,1),n(t,a,r,1),n(i,o,a,1)}let l=new ne;return l.setAttribute(`position`,new g(e,3)),l.setAttribute(`aWing`,new g(t,1)),l.computeVertexNormals(),l}var ze=(e,t)=>{let r=n(`birds`,e,t),a=r.int(`count`),o=r.str(`mode`),s=r.vec3(`area`),c=r.num(`speed`),l=r.num(`size`),u=r.num(`spread`),d=r.str(`formation`),f=r.num(`flapSpeed`),p=r.num(`heading`)*Math.PI/180,m=r.color(`color`),h=t.rng,g=Re();g.scale(l/2,l/2,l/2);let _=new Float32Array(a),y=new Float32Array(a);for(let e=0;e<a;e++)_[e]=h.next()*Math.PI*2,y[e]=f*h.range(.82,1.18);g.setAttribute(`aPhase`,new v(_,1)),g.setAttribute(`aRate`,new v(y,1));let b=new E({color:16777215,roughness:.9,metalness:0,flatShading:!0,side:2}),C={uTime:{value:0}};b.onBeforeCompile=e=>{Object.assign(e.uniforms,C),e.vertexShader=`uniform float uTime;
1
+ import{c as e,i as t,l as n}from"./runtime-NGp1VdnH.js";import{a as r,c as i,l as a,o,u as s}from"./camera-Be6lnp3k.js";import{n as c}from"./BufferGeometryUtils-CAlXAboW.js";import{An as l,Bn as u,Bt as d,C as f,Dt as p,E as m,En as h,I as g,In as _,J as v,Jt as y,K as b,Kt as x,Ln as S,M as C,Mn as w,N as T,Ot as E,P as D,Rn as O,St as k,T as A,U as j,Ut as M,W as N,Y as P,_ as F,_n as I,bn as L,bt as R,cn as z,ct as B,d as ee,fn as te,h as ne,hn as re,it as ie,jn as ae,kn as oe,lt as se,m as V,mn as ce,nn as le,on as ue,p as de,pn as fe,rn as pe,st as me,tn as he,tt as ge,v as _e,wn as ve,x as H,xn as ye,xt as U,y as be,yt as xe,zt as Se}from"./three.module-CnI50X0U.js";var Ce=class{pos=[];col=[];uv=[];wind=[];useUv=!1;useWind=!1;windFn=null;pushVertex(e,t,n,r,i=0,a=0){if(this.pos.push(e,t,n),this.col.push(r.r,r.g,r.b),this.useUv&&this.uv.push(i,a),this.useWind){let r=this.windFn?this.windFn(e,t,n):[0,0];this.wind.push(r[0],r[1])}}tri(e,t,n,r,i){this.pushVertex(e[0],e[1],e[2],r,i?.[0],i?.[1]),this.pushVertex(t[0],t[1],t[2],r,i?.[2],i?.[3]),this.pushVertex(n[0],n[1],n[2],r,i?.[4],i?.[5])}quad(e,t,n,r,i,a){this.tri(e,t,n,i,a?[a[0],a[1],a[2],a[3],a[4],a[5]]:void 0),this.tri(e,n,r,i,a?[a[0],a[1],a[4],a[5],a[6],a[7]]:void 0)}box(e,t,n,r=n,i={}){let[a,o,s]=e,[c,l,u]=t,d=(e,t,n)=>{if(!i.uv)return;let[r,a,o,s]=i.uv(e,t,n);return[r,a,o,a,o,s,r,s]},f=c-a,p=l-o,m=u-s;this.quad([a,o,u],[c,o,u],[c,l,u],[a,l,u],n,d(`z`,f,p)),this.quad([c,o,s],[a,o,s],[a,l,s],[c,l,s],n,d(`z`,f,p)),this.quad([c,o,u],[c,o,s],[c,l,s],[c,l,u],n,d(`x`,m,p)),this.quad([a,o,s],[a,o,u],[a,l,u],[a,l,s],n,d(`x`,m,p)),this.quad([a,l,u],[c,l,u],[c,l,s],[a,l,s],r,d(`y`,f,m)),i.bottom&&this.quad([a,o,s],[c,o,s],[c,o,u],[a,o,u],n,d(`y`,f,m))}add(e,t,n){let r=e.index?e.toNonIndexed():e,i=r.getAttribute(`position`),a=new S,o=[[0,0,0],[0,0,0],[0,0,0]],s=[[0,0,0],[0,0,0],[0,0,0]];for(let e=0;e<i.count/3;e++){for(let n=0;n<3;n++)a.fromBufferAttribute(i,e*3+n),s[n]=[a.x,a.y,a.z],a.applyMatrix4(t),o[n]=[a.x,a.y,a.z];let r=typeof n==`function`?n((s[0][0]+s[1][0]+s[2][0])/3,(s[0][1]+s[1][1]+s[2][1])/3,(s[0][2]+s[1][2]+s[2][2])/3,e):n;this.tri(o[0],o[1],o[2],r)}r!==e&&r.dispose()}get triangles(){return this.pos.length/9}build(){let e=new ne;return e.setAttribute(`position`,new g(this.pos,3)),e.setAttribute(`color`,new g(this.col,3)),this.useUv&&e.setAttribute(`uv`,new g(this.uv,2)),this.useWind&&e.setAttribute(`aWind`,new g(this.wind,2)),e.computeVertexNormals(),e.computeBoundingBox(),e.computeBoundingSphere(),e}};function we(e,t,n){let r=e.getAttribute(`position`),i=new Map;for(let e=0;e<r.count;e++){let a=`${r.getX(e).toFixed(4)},${r.getY(e).toFixed(4)},${r.getZ(e).toFixed(4)}`,o=i.get(a);o||(o=[(n()-.5)*t,(n()-.5)*t,(n()-.5)*t],i.set(a,o)),r.setXYZ(e,r.getX(e)+o[0],r.getY(e)+o[1],r.getZ(e)+o[2])}return r.needsUpdate=!0,e}var Te=(e,t,n,r=1,i=r,a=r,o=0,s=0,c=0)=>new R().compose(new S(e,t,n),new x().setFromEuler(new T(o,s,c)),new S(r,i,a)),Ee=(e,t)=>e.clone().multiplyScalar(t);function De(e,t,n=new H){if(e.length===1)return n.copy(e[0]);let r=Math.min(1,Math.max(0,t))*(e.length-1),i=Math.min(e.length-2,Math.floor(r));return n.copy(e[i]).lerp(e[i+1],r-i)}var W=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)};function Oe(e){let t=[...e.siblings.values()].filter(e=>e.heightAt&&e.object.userData.surface!==`water`),n=e.placement?.position??[0,0,0],r=e=>{let t=e.object.userData.size;if(typeof t!=`number`)return 1/0;let r=e.object.position,i=e.object.scale,a=t/2*Math.abs(i.x||1),o=t/2*Math.abs(i.z||1);return Math.abs(n[0]-r.x)<=a&&Math.abs(n[2]-r.z)<=o?a*o:-1},i=e=>{let t=r(e);return(t<0?2:0)+(e.object.userData.surface===`terrain`?0:1)+(t>0&&Number.isFinite(t)?t/1e9:.5)};t.sort((e,t)=>i(e)-i(t));for(let n of t){if(!n.heightAt)continue;let t=n.object.position,r=n.object.scale,i=e.placement?.position??[0,0,0],a=e.placement?.scale??[1,1,1],o=n.heightAt.bind(n),s=e=>(e-i[1])/(a[1]||1),c=typeof n.object.userData.waterLevel==`number`?s(n.object.userData.waterLevel*r.y+t.y):null;return{snow:typeof n.object.userData.snowLevel==`number`?s(n.object.userData.snowLevel*r.y+t.y):null,height:(e,n)=>{let c=i[0]+e*a[0],l=i[2]+n*a[2];return s(o((c-t.x)/(r.x||1),(l-t.z)/(r.z||1))*r.y+t.y)},water:c}}return null}function ke(e,t,n,r=.15,i=!0){let a=null,o={x:0,y:0,z:0};for(let s=0;s<12;s++){let c=(e.next()-.5)*t[0],l=(e.next()-.5)*t[2],u=n?n.height(c,l):(e.next()-.5)*t[1];if(s===0&&(o={x:c,y:u,z:l}),!n)return{x:c,y:u,z:l};let d=n.water===null||u>n.water+r,f=!i||n.snow===null||n.snow===void 0||u<n.snow;if(d&&f)return{x:c,y:u,z:l};d&&(!a||u<a.y)&&(a={x:c,y:u,z:l})}return a??o}function Ae(e={}){return new E({vertexColors:!0,flatShading:e.flat??!0,roughness:e.roughness??.9,metalness:e.metalness??0,side:e.side??0})}function je(e){e.traverse(e=>{let t=e;t.geometry&&t.geometry.dispose();let n=t.material?Array.isArray(t.material)?t.material:[t.material]:[];for(let e of n){for(let t of Object.values(e))t instanceof ve&&t.dispose();e.dispose()}})}function G(e,t={}){return{object:e,dispose:()=>je(e),...t}}var Me=[`sphere`,`torus`,`ring`,`pill`,`cone`,`cube`,`halfDisc`,`squiggle`,`triangle`,`star`];function Ne(e){switch(e){case`sphere`:return new re(.5,40,28);case`torus`:return new h(.38,.14,24,64);case`ring`:return new h(.42,.045,12,64);case`pill`:return new F(.2,.6,10,24).rotateZ(Math.PI/2);case`cone`:return new f(.4,.8,40);case`cube`:return new t(.7,.7,.7,4,.08);case`halfDisc`:{let e=new A(.5,.5,.18,40,1,!1,0,Math.PI);return e.rotateX(Math.PI/2),e}case`squiggle`:{let e=Array.from({length:9},(e,t)=>new S((t/8-.5)*1.3,Math.sin(t*1.4)*.16,0));return new oe(new _e(e),80,.06,12,!1)}case`triangle`:{let e=new z;for(let t=0;t<3;t++){let n=Math.PI/2+t/3*Math.PI*2;t===0?e.moveTo(Math.cos(n)*.5,Math.sin(n)*.5):e.lineTo(Math.cos(n)*.5,Math.sin(n)*.5)}let t=new D(e,{depth:.16,bevelEnabled:!0,bevelThickness:.04,bevelSize:.04,bevelSegments:4});return t.center(),t}case`star`:{let e=new z;for(let t=0;t<10;t++){let n=Math.PI/2+t/10*Math.PI*2,r=t%2?.22:.5;t===0?e.moveTo(Math.cos(n)*r,Math.sin(n)*r):e.lineTo(Math.cos(n)*r,Math.sin(n)*r)}let t=new D(e,{depth:.14,bevelEnabled:!0,bevelThickness:.04,bevelSize:.03,bevelSegments:3});return t.center(),t}}}var Pe=(t,r)=>{let i=n(`abstractShapes`,t,r),a=i.int(`count`),o=i.vec3(`area`),s=i.colors(`colors`),c=i.num(`minSize`),l=Math.max(c,i.num(`maxSize`)),u=i.str(`style`),d=i.num(`motion`),f=i.raw(`shapes`),m=Array.isArray(f)?f.filter(e=>Me.includes(e)):[],h=m.length?m:[...Me],g=r.rng,_=[];for(let e=0;e<a;e++){let t=new S,n=-1;for(let e=0;e<14;e++){let e=new S((g.next()-.5)*o[0],(g.next()-.5)*o[1],(g.next()-.5)*o[2]),r=1/0;for(let t of _)r=Math.min(r,e.distanceTo(t.pos)-t.s*.6);r>n&&(n=r,t=e)}let r=c+(l-c)*(1-e/Math.max(1,a))**1.5*g.range(.7,1);_.push({pos:t,s:r,kind:h[e%h.length],color:s[e%s.length],rot:new T(g.range(-.6,.6),g.next()*Math.PI*2,g.range(-.8,.8)),spin:new S(g.range(-.25,.25),g.range(-.35,.35),g.range(-.2,.2)),ph:g.next()*Math.PI*2})}for(let e=_.length-1;e>0;e--){let t=Math.floor(g.next()*(e+1)),n=_[e].color;_[e].color=_[t].color,_[t].color=n}let v=u===`toon`?e({color:16777215}):u===`glossy`?new p({color:16777215,roughness:.18,clearcoat:1,clearcoatRoughness:.08}):new E({color:16777215,roughness:.62,metalness:0}),y=new j;y.name=`abstractShapes`;let b=[];for(let e of h){let t=_.filter(t=>t.kind===e);if(!t.length)continue;let n=new P(Ne(e),v,t.length);n.name=`shapes-${e}`,n.castShadow=!0,n.receiveShadow=!0,n.userData.materialTarget=!0,t.forEach((e,t)=>n.setColorAt(t,e.color)),n.frustumCulled=!1,y.add(n),b.push({mesh:n,list:t})}let C=new R,w=new x,D=new T,O=new S,k=new S,A=e=>{for(let{mesh:t,list:n}of b)n.forEach((n,r)=>{O.copy(n.pos),O.y+=Math.sin(e*.8+n.ph)*.12*d*(.5+n.s*.5),D.set(n.rot.x+n.spin.x*e*d,n.rot.y+n.spin.y*e*d,n.rot.z+n.spin.z*e*d),w.setFromEuler(D),k.setScalar(n.s),t.setMatrixAt(r,C.compose(O,w,k))}),t.instanceMatrix.needsUpdate=!0};return A(0),G(y,{update:e=>A(e)})},Fe=e=>1+2.4*(e-1)**3+1.4*(e-1)**2;function Ie(e){if(!Array.isArray(e)||e.length===0)return[[3,5,4,7,6,9,8]];let t=e=>typeof e==`number`&&Number.isFinite(e)?e:e&&typeof e==`object`&&typeof e.value==`number`?e.value:0;return e.every(e=>Array.isArray(e))?e.map(e=>e.map(t)):[e.map(t)]}var Le=(e,r)=>{let i=n(`bars3d`,e,r),a=Ie(i.raw(`data`)),o=a.length,s=Math.max(...a.map(e=>e.length),1),c=i.num(`barWidth`),l=i.num(`gap`),u=i.num(`maxHeight`),d=i.colors(`colors`),f=i.str(`colorBy`),m=i.str(`shape`),h=i.str(`animation`),g=i.num(`duration`),_=Math.max(1e-6,...a.flat().map(e=>Math.abs(e))),v=c+l,y;y=m===`cylinder`?new A(.5,.5,1,32):m===`box`?new de(1,1,1):new t(1,1,1,4,.12),y.translate(0,.5,0);let b=o*s,C=new p({roughness:.32,metalness:0,clearcoat:.6,clearcoatRoughness:.25}),w=new P(y,C,b);w.name=`bars`,w.castShadow=!0,w.receiveShadow=!0,w.userData.materialTarget=!0;let T=[],D=new H,O=0;for(let e=0;e<o;e++)for(let t=0;t<s;t++){let n=a[e][t]??0,r=Math.max(1e-4,Math.abs(n)/_*u),i=(t-(s-1)/2)*v,c=(e-(o-1)/2)*v,l=f===`row`?o>1?e/(o-1):0:f===`column`?s>1?t/(s-1):0:Math.abs(n)/_;f===`value`?De(d,l,D):D.copy(d[(f===`row`?e:t)%d.length]),w.setColorAt(O,D),T.push({x:i,z:c,h:r,i:O,delay:(t+e*.6)/Math.max(1,s+o*.6)}),O++}let k=new R,M=new x,N=new S,F=new S,I=e=>{for(let t of T){let n=1;if(h===`grow`){let r=(e-t.delay*g*.6)/(g*.5);n=r<=0?1e-4:r>=1?1:Fe(Math.min(1,r)),r>0&&r<1&&(n=Math.max(1e-4,n))}else h===`wave`&&(n=.55+.45*(.5+.5*Math.sin(e*1.6-t.x*.9-t.z*.7)));N.set(t.x,0,t.z),F.set(c,t.h*n,c),w.setMatrixAt(t.i,k.compose(N,M,F))}w.instanceMatrix.needsUpdate=!0};I(0),w.computeBoundingSphere(),w.frustumCulled=!1;let L=new j;if(L.name=`bars3d`,L.add(w),i.bool(`base`)){let e=s*v+l,n=o*v+l,r=new U(new t(e,.12,n,3,.05),new E({color:i.color(`baseColor`),roughness:.6}));r.position.y=-.06,r.receiveShadow=!0,r.castShadow=!0,r.name=`bars-base`,L.add(r)}return G(L,{update:e=>I(e)})};function Re(){let e=[],t=[],n=(n,r,i,a)=>{e.push(...n,...r,...i),t.push(a,a,a)},r=[0,0,.42],i=[0,.01,-.34],a=[0,.07,.04],o=[0,-.06,.02],s=[-.075,0,.04],c=[.075,0,.04];for(let[e,t]of[[s,a],[a,c],[c,o],[o,s]])n(r,e,t,0),n(i,t,e,0);n([0,.01,-.3],[-.14,.02,-.58],[.14,.02,-.58],0);for(let e of[-1,1]){let t=[e*.05,.01,.14],r=[e*.05,.01,-.12],i=[e*.48,0,.1],a=[e*.48,0,-.14],o=[e*1,-.01,-.26];n(t,i,a,1),n(t,a,r,1),n(i,o,a,1)}let l=new ne;return l.setAttribute(`position`,new g(e,3)),l.setAttribute(`aWing`,new g(t,1)),l.computeVertexNormals(),l}var ze=(e,t)=>{let r=n(`birds`,e,t),a=r.int(`count`),o=r.str(`mode`),s=r.vec3(`area`),c=r.num(`speed`),l=r.num(`size`),u=r.num(`spread`),d=r.str(`formation`),f=r.num(`flapSpeed`),p=r.num(`heading`)*Math.PI/180,m=r.color(`color`),h=t.rng,g=Re();g.scale(l/2,l/2,l/2);let _=new Float32Array(a),y=new Float32Array(a);for(let e=0;e<a;e++)_[e]=h.next()*Math.PI*2,y[e]=f*h.range(.82,1.18);g.setAttribute(`aPhase`,new v(_,1)),g.setAttribute(`aRate`,new v(y,1));let b=new E({color:16777215,roughness:.9,metalness:0,flatShading:!0,side:2}),C={uTime:{value:0}};b.onBeforeCompile=e=>{Object.assign(e.uniforms,C),e.vertexShader=`uniform float uTime;
2
2
  attribute float aWing;
3
3
  attribute float aPhase;
4
4
  attribute float aRate;