@fleox/agent3d 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/changelog.json +21 -0
- package/dist/agent/agent3d.mjs +36 -18
- package/dist/agent/chunks/{depth-Dih8jLqx.mjs → depth-BZT4gseQ.mjs} +1 -1
- package/dist/agent/chunks/{depth-0bZsQn6N.mjs → depth-CD_ql3QJ.mjs} +1 -1
- package/dist/agent/chunks/{export-Cdqt3mt_.mjs → export-CEX5DFLo.mjs} +83 -5
- package/dist/agent/chunks/{package-d5e08XSG.mjs → package-DjRnLzcU.mjs} +2 -2
- package/dist/agent/chunks/{tools-Cv6N_YBI.mjs → tools-CZyIc4zw.mjs} +16 -6
- package/dist/runtime/agent3d-photo.js +31 -0
- package/dist/runtime/agent3d-runtime.js +41 -41
- package/dist/runtime/agent3d-runtime.single.js +252 -247
- package/dist/runtime/chunks/assets-kC2Z1Xy_.js +1 -0
- package/dist/runtime/chunks/game-CbQaEB4q.js +20 -0
- package/dist/runtime/chunks/materials-jwhXlLYl.js +107 -0
- package/dist/runtime/chunks/model-CG5T_jcB.js +1 -0
- package/dist/runtime/chunks/num-CQNAlL82.js +1 -0
- package/dist/runtime/chunks/{photo-BlDYgYFM.js → photo-w6dwHX7j.js} +27 -22
- package/dist/runtime/chunks/physicsHost-BU-2V-CZ.js +1 -0
- package/dist/runtime/chunks/{postfx-Cbf_vvOr.js → postfx-DnIeKXAh.js} +1 -1
- package/dist/runtime/chunks/postfx-ylpcQcVK.js +1 -0
- package/dist/runtime/chunks/svg-fYjsY-rV.js +1 -0
- package/dist/runtime/chunks/{text-rSo_2Luk.js → text-CySfj5sH.js} +1 -1
- package/dist/runtime/chunks/util-BEflQURG.js +1 -0
- package/dist/studio/assets/assets--ehPZf8R.js +1 -0
- package/dist/studio/assets/camera-C0sxfRxy.js +2 -0
- package/dist/studio/assets/{editor-BjgHj9g8.js → editor-DzyukvQl.js} +1 -1
- package/dist/studio/assets/game-DNpTN_Ga.js +19 -0
- package/dist/studio/assets/{generators-DqkPMEzm.js → generators-BuVeRXnC.js} +5 -5
- package/dist/studio/assets/index-C2nMYSoW.js +479 -0
- package/dist/studio/assets/model-DQgOrTs4.js +2 -0
- package/dist/studio/assets/num-CQNAlL82.js +1 -0
- package/dist/studio/assets/{params-gVpEEiSK.js → params-D-Ul6GSt.js} +1 -1
- package/dist/studio/assets/{photo-DRoVO5iZ.js → photo-Dx2IBJ11.js} +27 -22
- package/dist/studio/assets/physicsHost-z9qn_mpg.js +1 -0
- package/dist/studio/assets/{postfx-JFUGdY0d.js → postfx-B3jDEaEK.js} +13 -13
- package/dist/studio/assets/runtime-rd9RW3WH.js +572 -0
- package/dist/studio/assets/{shaders-C7u6rN_6.js → shaders-bFhELLmD.js} +1 -1
- package/dist/studio/assets/svg-BkV9LeqP.js +2 -0
- package/dist/studio/assets/{text-LISSAism.js → text-Dp8gdjSA.js} +1 -1
- package/dist/studio/index.html +1 -1
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/skills/agent3d-assets/SKILL.md +27 -27
- package/plugin/skills/agent3d-create/SKILL.md +28 -27
- package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
- package/plugin/skills/agent3d-create/references/recipes.md +6 -6
- package/plugin/skills/agent3d-edit/SKILL.md +22 -22
- package/plugin/skills/agent3d-edit/references/patch-ops.md +2 -2
- package/plugin/skills/agent3d-game/SKILL.md +7 -7
- package/plugin/skills/agent3d-publish/SKILL.md +24 -22
- package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
- package/templates/hero-photo-3d/assets/depth/street-depth.png +0 -0
- package/templates/hero-photo-3d/assets/manifest.json +3 -3
- package/templates/hero-photo-3d/assets/textures/street.webp +0 -0
- package/templates/hero-photo-3d/scene.json +1 -1
- package/dist/runtime/chunks/assets-qnxDnVkj.js +0 -1
- package/dist/runtime/chunks/game-BoEiyZrL.js +0 -20
- package/dist/runtime/chunks/materials-dC4vDNHh.js +0 -107
- package/dist/runtime/chunks/model-BCAl_NRl.js +0 -1
- package/dist/runtime/chunks/physicsHost-ChPgysMQ.js +0 -1
- package/dist/runtime/chunks/postfx-CFucYRev.js +0 -1
- package/dist/runtime/chunks/svg-CLUxY6Zy.js +0 -1
- package/dist/runtime/chunks/util-CyaW1fcW.js +0 -1
- package/dist/studio/assets/assets-BFJsr9Oo.js +0 -1
- package/dist/studio/assets/camera-DT0xHipx.js +0 -2
- package/dist/studio/assets/game-BXZEc9HN.js +0 -19
- package/dist/studio/assets/index-DVTzVcBD.js +0 -479
- package/dist/studio/assets/model-BqQW4Dg-.js +0 -2
- package/dist/studio/assets/physicsHost-DNdZ7AsT.js +0 -1
- package/dist/studio/assets/runtime-CMAP4azF.js +0 -572
- package/dist/studio/assets/svg-DkIOJjzS.js +0 -2
- package/templates/hero-photo-3d/assets/textures/street.jpg +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var e=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i,t=e=>Array.isArray(e)?e.length>0:e!=null&&e!==!1;function n(n){let r=[],i=(e,t)=>{e&&r.push(t)},a=n??{};i((a.target??{}).kind===`game`,`target.kind is game`),i(t(a.timeline),`timeline`),i(t(a.interactions),`interactions`),i(t(a.postfx),`post effects (postfx)`),i(t(a.physics),`physics`),i(t(a.scripts),`scripts`),i(a.ui?.elements?.length,`ui (HUD)`),i(t(a.audio),`audio`),i(/\{data\./.test(JSON.stringify(n??{})),`data bindings ({data.*} placeholders)`);let o=a.camera;!o||o.type!==`perspective`?r.push(`camera is not perspective`):(i(o.controls&&o.controls!==`none`,`camera.controls "${o.controls}"`),i(o.autoRotate,`camera.autoRotate`),i(t(o.shots),`camera.shots`),i(o.shake,`camera.shake`),i(o.lookAt,`camera.lookAt`),i(o.follow,`camera.follow`));let s=a.environment,c=s?.background;i(c!==void 0&&(typeof c!=`string`||c!==`transparent`&&!e.test(c)),`environment.background is not a #hex colour or transparent`),i(s?.ground,`environment.ground`),i(s?.contactShadows,`environment.contactShadows`),i(s?.rig,`environment.rig (light rig)`);for(let e of a.lights??[])i(e.type===`rect`,`rect lights (visible panels)`),i(e.type===`spot`&&e.volumetric,`volumetric spot lights`);let l=a.objects??[];l.length!==1&&r.push(`${l.length} objects (the lite runtime shows exactly one photo)`);let u=l[0];if(u&&u.kind!==`photo`)r.push(`object "${u.id}" is a ${u.kind}, not a photo`);else if(u){let n=u;i(!!n.depth&&n.mode&&n.mode!==`parallax`,`photo mode "${n.mode}" (lite: parallax or a flat photo)`),i(t(n.children),`photo has children`),i(n.visible===!1,`photo is hidden`),i(t(n.behaviours),`photo behaviours`),i(n.body,`photo physics body`),i(n.href,`photo link (href)`),i(n.attach,`photo attached to the camera`),i(Array.isArray(n.rotation)&&n.rotation.some(e=>e!==0),`photo is rotated`);let r=n.scale;i(r!==void 0&&(typeof r==`number`?!(r>0):!Array.isArray(r)||!(r[0]>0&&r[1]>0)),`photo scale is not positive`),i(n.material?.color!==void 0&&!(typeof n.material.color==`string`&&e.test(n.material.color)),`photo material.color is not a #hex colour`),i(typeof n.src!=`string`||!n.src,`photo has no src`)}return r.length?{ok:!1,reasons:r}:{ok:!0}}var r=/\{data\.([a-zA-Z_$][\w$-]*(?:\.[a-zA-Z_$][\w$-]*)*)(?:\|([^}]*))?\}/g;function i(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return n}function a(e){return typeof e!=`string`||!e.includes(`{data.`)?!1:(r.lastIndex=0,r.test(e))}function o(e,t){return e.includes(`{data.`)?e.replace(r,(e,n,r)=>{let a=i(t,n);return a==null||a===``?r??``:typeof a==`object`?JSON.stringify(a):String(a)}):e}var s=/^\{data\.([a-zA-Z_$][\w$-]*(?:\.[a-zA-Z_$][\w$-]*)*)(?:\|([^}]*))?\}$/;function c(e,t){if(typeof e!=`string`||!e.includes(`{data.`))return e;let n=s.exec(e.trim());if(!n)return o(e,t);let r=i(t,n[1]);if(r!=null&&r!==``)return r;if(n[2]!==void 0)try{return JSON.parse(n[2])}catch{return n[2]}}function l(e,t=e.data){let n=!1,r=e=>a(e)?(n=!0,o(e,t)):e,i=e=>{if(typeof e==`string`)return a(e)?(n=!0,c(e,t)):e;if(Array.isArray(e)){let t=e.map(i);return t.every((t,n)=>t===e[n])?e:t}if(e&&typeof e==`object`){let t=!1,n={};for(let[r,a]of Object.entries(e)){let e=i(a);e!==a&&(t=!0),e!==void 0&&(n[r]=e)}return t?n:e}return e},s=e=>{let t=e,n=t.kind===`text`?r(t.text):t.text,a=r(t.href),o=t.kind===`generator`&&t.params?i(t.params):t.params,c=e.children?.map(s);return n===t.text&&a===t.href&&o===t.params&&(!c||c.every((t,n)=>t===e.children[n]))?e:{...e,...t.kind===`text`?{text:n}:{},...t.href===void 0?{}:{href:a},...o===t.params?{}:{params:o},...c?{children:c}:{}}},l=e.interactions?.map(e=>{let t=e.do;if(!Array.isArray(t))return e;let n=t.map(e=>{let t=e;return!t||typeof t!=`object`||!a(t.openUrl)?e:{...t,openUrl:r(t.openUrl)}});return n.every((e,n)=>e===t[n])?e:{...e,do:n}}),u=(e.objects??[]).map(s),d=r(e.title),f=r(e.ariaLabel),p=e.ui?.elements?.map(e=>{let t=e,n=r(t.text);return n===t.text?e:{...e,text:n}});return n?{...e,title:d,...e.ariaLabel===void 0?{}:{ariaLabel:f},objects:u,...e.ui&&p?{ui:{...e.ui,elements:p}}:{},...l?{interactions:l}:{}}:e}function u(e){let t={};for(let[n,r]of Object.entries(e))if(r!==void 0){if(n===`json`)try{let e=JSON.parse(r);e&&typeof e==`object`&&!Array.isArray(e)&&Object.assign(t,e)}catch{}else t[n]=r}return t}var d=typeof HTMLElement<`u`?HTMLElement:class{},f=`
|
|
2
|
+
:host{display:block;position:relative;width:100%;overflow:hidden;background:var(--agent3d-background,transparent);contain:layout paint;-webkit-tap-highlight-color:transparent}
|
|
3
|
+
:host([hidden]){display:none}
|
|
4
|
+
:host([interactive="false"]) ::slotted(*){pointer-events:none}
|
|
5
|
+
::slotted(script){display:none}
|
|
6
|
+
.poster,.print{position:absolute;inset:0;width:100%;height:100%;z-index:1;pointer-events:none;transition:opacity var(--agent3d-fade,.4s) ease;border:0;overflow:hidden}
|
|
7
|
+
.poster img,::slotted([slot="poster"]),.print{object-fit:var(--agent3d-poster-fit,cover);display:block;width:100%;height:100%}
|
|
8
|
+
.poster[hidden],.print{display:none}
|
|
9
|
+
:host([status="ready"]) .poster{opacity:0}
|
|
10
|
+
.loading{position:absolute;left:0;right:0;bottom:0;height:3px;z-index:2;pointer-events:none;opacity:0;transition:opacity .3s ease .4s;overflow:hidden}
|
|
11
|
+
:host([status="loading"]) .loading{opacity:1}
|
|
12
|
+
.bar{height:100%;width:30%;background:var(--agent3d-loading-color,currentColor);opacity:.55;border-radius:0 2px 2px 0;transition:width .25s ease}
|
|
13
|
+
.loading.indeterminate .bar{animation:a3d-slide 1.2s ease-in-out infinite}
|
|
14
|
+
@keyframes a3d-slide{0%{transform:translateX(-100%)}100%{transform:translateX(340%)}}
|
|
15
|
+
.fallback{position:absolute;inset:0;z-index:1;display:none;align-items:center;justify-content:center;text-align:center;padding:12px;font:14px/1.4 system-ui,sans-serif;color:inherit;opacity:.75}
|
|
16
|
+
:host([status="unsupported"]) .fallback.show,:host([status="error"]) .fallback.show{display:flex}
|
|
17
|
+
:host([status="unsupported"]) .poster,:host([status="error"]) .poster{opacity:1}
|
|
18
|
+
@media (prefers-reduced-motion:reduce){.loading.indeterminate .bar{animation:none;width:100%;opacity:.3}.poster{transition:none}}
|
|
19
|
+
@media print{::slotted(canvas),::slotted(img){visibility:hidden}.print{display:block}.loading{display:none}.poster{opacity:1}}
|
|
20
|
+
`,p=null;function m(e){try{return`adoptedStyleSheets`in e&&typeof CSSStyleSheet<`u`&&typeof CSSStyleSheet.prototype.replaceSync==`function`}catch{return!1}}function h(e){let t=/^\s*([\d.]+)\s*[:/x]\s*([\d.]+)\s*$/.exec(e??``);return!t||!(Number(t[1])>0)||!(Number(t[2])>0)?null:`${t[1]} / ${t[2]}`}function g(){let e=typeof navigator<`u`?navigator:{};if(e.connection?.saveData)return`low`;let t=e.hardwareConcurrency??8,n=e.deviceMemory??8;return t<=2||n<=2?`low`:t<=4||n<=4?`medium`:`high`}function _(e,t){let n=e;if(t.data&&Object.keys(t.data).length&&(n={...n,data:{...n.data??{},...t.data}}),t.loop!=null&&n.timeline){let e=t.loop.trim().toLowerCase(),r=e===`pingpong`?`pingpong`:e!==`false`&&e!==`0`&&e!==`no`;n={...n,timeline:{...n.timeline,loop:r}}}let r=t.quality?t.quality===`auto`?g():t.quality:null;if((t.quality===`low`||t.quality===`medium`||t.quality===`high`||t.quality===`ultra`)&&(n={...n,target:{...n.target,quality:t.quality}}),r===`low`||r===`medium`||r===`high`){let e=r===`low`?1:r===`medium`?1.5:2,t={...n.target,maxDpr:Math.min(n.target?.maxDpr??2,e)};r===`low`&&Object.assign(t,{antialias:!1,shadows:!1}),n={...n,target:t,...r===`low`?{postfx:void 0}:{}}}return l(n)}var v=class extends d{static get observedAttributes(){return[`src`,`poster`,`aspect`,`alt`,`paused`,`loop`,`quality`,`library-base`]}player=null;ready;resolveReady;root=null;posterEl=null;posterBox=null;printEl=null;loadingEl=null;barEl=null;fallbackEl=null;sizeStyle=null;sizeSheet=null;sizeCssText=``;loadToken=0;connected=!1;source=null;dataOverrides={};dataObserver=null;interObs=null;inView=!0;lostTimer=null;wantPlay=null;autoAriaLabel=null;constructor(){super(),this.resetReady()}readySettled=!1;resetReady(){this.readySettled=!1,this.ready=new Promise(e=>this.resolveReady=e)}connectedCallback(){this.connected=!0,this.ensureShadow(),this.updatePoster(),this.applyAspect(null),this.ownerDocument.defaultView?.addEventListener(`beforeprint`,this.onBeforePrint),this.addEventListener(`webglcontextlost`,this.onContextLost,!0),this.addEventListener(`webglcontextrestored`,this.onContextRestored,!0),typeof MutationObserver<`u`&&(this.dataObserver=new MutationObserver(e=>{e.some(e=>e.attributeName?.startsWith(`data-`))&&this.refreshData()}),this.dataObserver.observe(this,{attributes:!0})),typeof IntersectionObserver<`u`&&(this.interObs=new IntersectionObserver(e=>this.inView=e.some(e=>e.isIntersecting)),this.interObs.observe(this)),this.load()}disconnectedCallback(){this.connected=!1,this.loadToken++,this.ownerDocument.defaultView?.removeEventListener(`beforeprint`,this.onBeforePrint),this.removeEventListener(`webglcontextlost`,this.onContextLost,!0),this.removeEventListener(`webglcontextrestored`,this.onContextRestored,!0),this.dataObserver?.disconnect(),this.dataObserver=null,this.interObs?.disconnect(),this.interObs=null,this.lostTimer&&clearTimeout(this.lostTimer),this.lostTimer=null,this.player?.dispose(),this.player=null,this.setStatus(`idle`)}attributeChangedCallback(e,t,n){this.connected&&t!==n&&(e===`poster`||e===`alt`?this.updatePoster():e===`aspect`?this.applyAspect(this.source):e===`paused`?n===null?this.getAttribute(`status`)===`ready`&&this.player?.play():this.player?.pause():e===`src`?(this.source=null,this.load()):this.rebuild())}play(){this.wantPlay=!0,this.hasAttribute(`paused`)&&this.removeAttribute(`paused`),this.player?.play()}pause(){this.wantPlay=!1,this.player?.pause()}async seek(e){await(this.player??await this.ready).seek(e)}get data(){return{...this.source?.data??{},...this.attrData(),...this.dataOverrides}}async setData(e,t={}){this.dataOverrides=t.replace?{...e}:{...this.dataOverrides,...e},await this.rebuild()}trigger(e,t){this.player?.emit?this.player.emit(e,t):this.ready.then(n=>n.emit?.(e,t))}reload(){return this.source=null,this.load()}ensureShadow(){if(this.root||typeof this.attachShadow!=`function`)return;let e=this.ownerDocument;this.root=this.shadowRoot??this.attachShadow({mode:`open`});let t=[];if(m(this.root))p||(p=new CSSStyleSheet,p.replaceSync(f)),this.sizeSheet=new CSSStyleSheet,this.root.adoptedStyleSheets=[p,this.sizeSheet];else{let n=e.createElement(`style`);n.textContent=f,this.sizeStyle=e.createElement(`style`),t=[n,this.sizeStyle]}let n=e.createElement(`slot`);this.posterBox=e.createElement(`div`),this.posterBox.className=`poster`,this.posterBox.setAttribute(`part`,`poster`);let r=e.createElement(`slot`);r.name=`poster`,this.posterEl=e.createElement(`img`),this.posterEl.setAttribute(`part`,`poster-image`),this.posterEl.decoding=`async`,r.appendChild(this.posterEl),this.posterBox.appendChild(r),this.printEl=e.createElement(`img`),this.printEl.className=`print`,this.printEl.alt=``,this.loadingEl=e.createElement(`div`),this.loadingEl.className=`loading indeterminate`,this.loadingEl.setAttribute(`part`,`loading`),this.loadingEl.setAttribute(`aria-hidden`,`true`),this.barEl=e.createElement(`div`),this.barEl.className=`bar`,this.barEl.setAttribute(`part`,`loading-bar`),this.loadingEl.appendChild(this.barEl),this.fallbackEl=e.createElement(`div`),this.fallbackEl.className=`fallback`,this.fallbackEl.setAttribute(`part`,`fallback`);let i=e.createElement(`slot`);i.name=`fallback`,this.fallbackEl.appendChild(i),this.root.append(...t,n,this.posterBox,this.printEl,this.loadingEl,this.fallbackEl)}updatePoster(){let e=this.posterEl;if(!e)return;let t=this.getAttribute(`poster`);e.alt=this.getAttribute(`alt`)??this.getAttribute(`aria-label`)??``,t?e.getAttribute(`src`)!==t&&(e.src=t):e.removeAttribute(`src`),this.posterBox&&(this.posterBox.hidden=!this.posterSrc()),this.updateFallbackText()}posterSrc(){let e=this.querySelector(`[slot="poster"]`),t=e?.tagName===`IMG`?e:e?.querySelector(`img`);return t?.currentSrc||t?.getAttribute(`src`)||this.getAttribute(`poster`)}updateFallbackText(){let e=this.fallbackEl;if(!e)return;let t=e.querySelector(`slot`),n=!!this.querySelector(`[slot="fallback"]`),r=!!this.posterSrc();e.classList.toggle(`show`,n||!r),t&&!n&&(t.textContent=this.getAttribute(`alt`)??this.getAttribute(`aria-label`)??``)}setStatus(e){e===`idle`?this.removeAttribute(`status`):this.setAttribute(`status`,e),(e===`unsupported`||e===`error`)&&this.updateFallbackText()}progress(e,t){this.loadingEl&&this.barEl&&t>0&&(this.loadingEl.classList.remove(`indeterminate`),this.barEl.style.width=`${Math.round(Math.min(e,t)/t*100)}%`),this.emit(`agent3d:progress`,{loaded:e,total:t})}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}fail(e){this.emit(`agent3d:error`,e),this.emit(`agent3d-error`,e)}onBeforePrint=()=>{let e=this.printEl;if(!e)return;let t=``;try{this.player&&this.getAttribute(`status`)===`ready`&&(t=this.player.snapshot(`image/png`))}catch{}(!t||t.length<32)&&(t=this.posterSrc()??``),t?e.src=t:e.removeAttribute(`src`)};onContextLost=e=>{this.player&&this.inView&&this.getAttribute(`status`)===`ready`&&(e.preventDefault(),this.fail({code:`context-lost`,message:`The WebGL context was lost; restoring.`}),this.setStatus(`loading`),this.lostTimer&&clearTimeout(this.lostTimer),this.lostTimer=setTimeout(()=>{this.lostTimer=null,this.rebuild(!0)},3e3))};onContextRestored=()=>{this.lostTimer&&clearTimeout(this.lostTimer),this.lostTimer=null;let e=this.player;e&&e.update(e.scene).then(()=>this.setStatus(`ready`),()=>void this.rebuild(!0))};childJson(e){let t=this.querySelector(e);if(t?.textContent)try{return JSON.parse(t.textContent)}catch(e){this.fail({code:`invalid-scene`,message:`Invalid inline JSON: ${e.message}`});return}}attrData(){return u(this.dataset??{})}refreshData(){this.source&&this.rebuild()}base(){let e=this.getAttribute(`src`);return e?new URL(`.`,new URL(e,this.ownerDocument.baseURI)).href:this.ownerDocument.baseURI}async fetchScene(){let e=this.childJson(`script[type="application/json"]:not([data-assets])`);if(e)return e;let t=this.getAttribute(`src`);if(!t)return;let n=new URL(t,this.ownerDocument.baseURI).href,r=await fetch(n);if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()}async load(){let e=++this.loadToken;if(!this.source){this.setStatus(`loading`);let t;try{if(t=await this.fetchScene(),!t&&this.ownerDocument.readyState===`loading`){if(await new Promise(e=>this.ownerDocument.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0})),e!==this.loadToken)return;t=await this.fetchScene()}}catch(t){if(e!==this.loadToken)return;this.setStatus(`error`),this.fail({code:`scene-load`,message:`Cannot load ${this.getAttribute(`src`)}: ${t.message}`,path:this.getAttribute(`src`)??void 0});return}if(e!==this.loadToken)return;if(!t){this.setStatus(`idle`);return}this.source=t}await this.mount(e)}async rebuild(e=!1){if(!this.connected||!this.source)return;let t=this.player;if(t&&!e&&this.getAttribute(`status`)===`ready`&&this.getAttribute(`library-base`)===this.mountedLibraryBase){let e=this.sceneForMount();this.applySizing(e),await t.update(e)}else await this.mount(++this.loadToken)}sceneForMount(){return _(this.source,{data:{...this.attrData(),...this.dataOverrides},loop:this.getAttribute(`loop`),quality:this.getAttribute(`quality`)})}mountedLibraryBase=null;async mount(e){this.player?.dispose(),this.player=null,this.readySettled&&this.resetReady(),this.setStatus(`loading`);let t=this.sceneForMount();this.applySizing(t);let n=this.childJson(`script[data-assets]`),r={};this.querySelectorAll(`script[type="text/agent3d-script"][data-path]`).forEach(e=>{r[e.getAttribute(`data-path`)]=e.textContent??``});let i=this.getAttribute(`library-base`);this.mountedLibraryBase=i;let a=this.mountPlayer(this,t,{assetBase:this.base(),libraryBase:i?new URL(i,this.ownerDocument.baseURI).href:void 0,assetUrls:n,scriptSources:Object.keys(r).length?r:void 0,onError:t=>{e===this.loadToken&&(t.code===`webgl-unavailable`&&this.setStatus(`unsupported`),this.fail(t))},onEvent:(t,n)=>e===this.loadToken&&this.emit(`agent3d:event`,{name:t,payload:n}),onClick:(t,n)=>e===this.loadToken&&this.emit(`agent3d:click`,{id:t,x:n.x,y:n.y}),onProgress:(t,n)=>e===this.loadToken&&this.progress(t,n)});this.player=a;try{await a.ready}catch{e===this.loadToken&&this.getAttribute(`status`)!==`unsupported`&&this.setStatus(`error`);return}if(e!==this.loadToken)return;let o=(this.getAttribute(`autoplay`)??``).toLowerCase();(this.hasAttribute(`paused`)||this.wantPlay===!1||this.wantPlay!==!0&&(o===`false`||o===`0`||o===`no`))&&a.pause(),this.setStatus(`ready`),this.readySettled=!0,this.resolveReady(a),this.emit(`agent3d:ready`,{player:a}),this.emit(`agent3d-ready`,{player:a})}applyAspect(e){if(!this.sizeStyle&&!this.sizeSheet)return;let t=e?.target,n;n=t?.height?`:host{height:${t.height}}`:t?.kind===`fullscreen`?`:host{height:100vh;height:100dvh}`:`:host{aspect-ratio:${h(e?t?.aspect??this.getAttribute(`aspect`):this.getAttribute(`aspect`)??`16:9`)??`16 / 9`}}`,this.sizeCssText!==n&&(this.sizeCssText=n,this.sizeSheet?this.sizeSheet.replaceSync(n):this.sizeStyle&&(this.sizeStyle.textContent=n))}applySizing(e){if(this.sizeStyle||this.sizeSheet)this.applyAspect(e);else{this.style.display||(this.style.display=`block`),this.style.width||(this.style.width=`100%`),this.style.position||(this.style.position=`relative`);let t=h(e.target?.aspect)??`16 / 9`;e.target?.height?this.style.height=e.target.height:this.style.aspectRatio=t}let t=e.target?.kind===`game`;this.setAttribute(`role`,t?`application`:`img`);let n=this.getAttribute(`aria-label`);(n===null||n===this.autoAriaLabel)&&(this.autoAriaLabel=e.ariaLabel||e.title||`3D scene`,this.setAttribute(`aria-label`,this.autoAriaLabel)),t&&!this.hasAttribute(`tabindex`)&&(this.tabIndex=0),this.updatePoster()}};function y(e,t=`agent3d-scene`){typeof customElements<`u`&&(customElements.get(t)||customElements.define(t,e))}var ee={low:1,medium:1.5,high:2,ultra:3};function b(e,t={}){return e&&e!==`auto`?e:t.deterministic?`high`:t.gpu&&/swiftshader|llvmpipe|softpipe|software|microsoft basic render/i.test(t.gpu)?`low`:t.mobile?(t.memoryGb??4)<=2||(t.cores??8)<=4?`low`:`medium`:t.cores!==void 0&&t.cores<=2||t.memoryGb!==void 0&&t.memoryGb<=2?`low`:t.cores!==void 0&&t.cores<=4||t.memoryGb!==void 0&&t.memoryGb<=4||t.gpu&&/intel|mali|adreno|powervr/i.test(t.gpu)?`medium`:`high`}function x(e){return e.endsWith(`/`)?e:e+`/`}function te(e){let t=x(e.assetBase??`./`),n=x(e.libraryBase??t+`assets/library/`),r=e.assetUrls??{};return e=>{if(r[e])return r[e];if(/^(https?:|data:|blob:|\/)/.test(e))return e;if(e.startsWith(`library:`)){let t=e.slice(8);return t.startsWith(`fonts/`)&&!/\.json$/.test(t)&&(t+=`.typeface.json`),r[`library:`+t]?r[`library:`+t]:n+t}return t+e.replace(/^\.\//,``)}}var S=Math.PI/180;function C(e,t,n){return e<t?t:e>n?n:e}function w(e,t){return typeof e==`number`&&Number.isFinite(e)?e:t}function T(e,t){return!t||!(e>0)||e>=t?1:Math.min(t/e,3)}function E(e,t){return t<=1?e:Math.min(100,2*Math.atan(Math.tan(e*S/2)*t)/S)}function ne(e){let t=/^\s*([\d.]+)\s*[:/x]\s*([\d.]+)\s*$/.exec(e??``),n=t?Number(t[1])/Number(t[2]):void 0;return n&&Number.isFinite(n)&&n>0?n:void 0}function D(e,t){let n=t.x-e.x,r=t.y-e.y,i=t.z-e.z,a=Math.hypot(n,r,i);if(a<1e-9)return;let o=-1e-4/a;e.set(e.x+n*o,e.y+r*o,e.z+i*o)}var O={width:4,strength:.5,focus:.5,segments:256,layers:6,edgeCut:.08,speed:1,smoothing:.9};function re(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??O.width;return{width:o,height:o/r}}function k(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 ie(e){let t=C(w(e?.pointer,1),0,1);return{pointer:t,scroll:C(w(e?.scroll,0),0,1),gyro:typeof e?.gyro==`boolean`?e.gyro:t>0,auto:e?.auto??`sway`,speed:Math.max(0,w(e?.speed,O.speed)),smoothing:C(w(e?.smoothing,O.smoothing),0,.99)}}function A(e,t){let n=t.reduced?{x:0,y:0,zoom:0}:k(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=C(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+=(C(t.scroll,0,1)*2-1)*e.scroll),{x:C(s,-1,1),y:C(c,-1,1),zoom:n.zoom*(1-o)}}function j(e,t,n,r){if(r<=0||n<=0)return n<=0&&r>0?e:t;let i=1-C(r,0,.99)**(n*60),a=e+(t-e)*i;return Math.abs(t-a)<1e-4?t:a}function ae(e,t,n){let r=C(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 M(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:C(i/20,-1,1),y:C(-a/20,-1,1)}}function oe(e,t){return Math.max(8,Math.round((e===`low`?12:e===`medium`?20:e===`ultra`?48:32)*(.5+.5*Math.min(1,Math.max(0,t)/.6))))}function se(e,t){let{live:n}=t,r={x:0,y:0,weight:0,init:!1},i=null,a=null,o=null;if(n&&e.gyro&&e.pointer>0&&!t.flat&&typeof window<`u`&&typeof window.addEventListener==`function`){let e=e=>{if(e.beta===null||e.gamma===null)return;a??={beta:e.beta,gamma:e.gamma};let t=typeof screen<`u`&&screen.orientation?.angle||0;i=M(e.beta,e.gamma,a,t)};window.addEventListener(`deviceorientation`,e),o=()=>window.removeEventListener(`deviceorientation`,e)}return{offset(t,a,o){let s=o.pointer,c=s.inside?C(s.x,-1,1):0,l=s.inside?C(s.y,-1,1):0,u=+!!s.inside;return!n||!r.init?(r.x=c,r.y=l,r.weight=u,r.init=n):(r.x=j(r.x,c,a,e.smoothing),r.y=j(r.y,l,a,e.smoothing),r.weight=j(r.weight,u,a,e.smoothing)),A(e,{t,pointer:r,gyro:n?i:null,scroll:o.scroll,reduced:o.reduced})},dispose(){o?.(),o=null}}}var N=`uniform sampler2D uMap;uniform vec3 uTint;uniform float uOpacity;uniform float uIntensity;vec4 shade(vec4 c,float a){return vec4(c.rgb*uTint*uIntensity,c.a*a*uOpacity);}
|
|
21
|
+
`,P=`uniform sampler2D uDepth;uniform vec2 uView;uniform float uZoom;uniform vec2 uMaxOffset;uniform vec2 uInset;uniform float uFocus;uniform float uWallSlope;const int STEPS=__STEPS__;vec4 parallaxTexel(vec2 vUv){vec2 base=0.5+(vUv-0.5)*uInset*(1.0-0.06*uZoom);vec2 v=uView-(vUv-0.5)*2.0*uZoom;vec2 dir=v*uMaxOffset;vec2 uv=base;if(dot(dir,dir)>1e-10){float stepH=1.0/float(STEPS);float h=1.0;float prevH=1.0+stepH;bool hit=false;for(int i=0;i<=STEPS;i++){h=1.0-float(i)*stepH;float d=textureLod(uDepth,base+(h-uFocus)*dir,0.0).r;if(d>=h){hit=true;break;}prevH=h;}float lo=h,hi=min(prevH,1.0);if(hit){for(int j=0;j<6;j++){float mid=0.5*(lo+hi);float d=textureLod(uDepth,base+(mid-uFocus)*dir,0.0).r;if(d>=mid)lo=mid;else hi=mid;}}uv=base+(lo-uFocus)*dir;vec2 texel=1.0/vec2(textureSize(uDepth,0));vec4 dh=textureLod(uDepth,uv,0.0);vec2 grad=vec2(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,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;float g=length(grad);vec2 toNear=grad/max(g,1e-6);float dNear=textureLod(uDepth,uv+toNear*texel*3.0,0.0).r;if(hit&&(g>uWallSlope||dh.a<0.5)&&dNear>lo+0.04){vec2 away=-toNear;vec2 probe=uv;for(int k=1;k<=6;k++){vec2 q=uv+away*texel*float(k*2);probe=q;if(textureLod(uDepth,q,0.0).r<lo-0.05)break;}uv=probe+away*texel*2.0;}}return textureGrad(uMap,uv,dFdx(base),dFdy(base));}
|
|
22
|
+
`,ce=.02,le=`#version 300 es
|
|
23
|
+
in vec2 aPos;out vec2 vNdc;void main(){vNdc=aPos;gl_Position=vec4(aPos,0.0,1.0);}
|
|
24
|
+
`,F=`#version 300 es
|
|
25
|
+
precision highp float;precision highp int;precision highp sampler2D;
|
|
26
|
+
`,I=`vec4 photoTexel(vec2 uv){return texture(uMap,uv);}
|
|
27
|
+
`,L=`vec4 photoTexel(vec2 uv){return parallaxTexel(uv);}
|
|
28
|
+
`,R=`uniform vec3 uO;uniform vec3 uF;uniform vec3 uR;uniform vec3 uU;uniform vec2 uClip;uniform vec4 uBg;uniform float uBlend;in vec2 vNdc;out vec4 fragColor;vec3 toSrgb(vec3 v){return mix(pow(v,vec3(0.41666))*1.055-vec3(0.055),v*12.92,vec3(lessThanEqual(v,vec3(0.0031308))));}void main(){vec3 d=uF+uR*vNdc.x+uU*vNdc.y;float t=d.z<0.0?-uO.z/d.z:-1.0;vec2 uv=uO.xy+t*d.xy+0.5;vec2 fw=max(fwidth(uv),vec2(1e-7));vec4 c=photoTexel(uv);vec2 e=min(uv,1.0-uv)/fw;float cover=uO.z>0.0&&t>=uClip.x&&t<=uClip.y?clamp(min(e.x,e.y)+0.5,0.0,1.0):0.0;vec4 s=shade(c,1.0);float a=c.a*uOpacity<0.004?0.0:uBlend>0.5?s.a:1.0;vec4 photo=vec4(toSrgb(s.rgb)*a,a)+uBg*(1.0-a);fragColor=mix(uBg,photo,cover);}
|
|
29
|
+
`,ue=(e,t)=>F+N+(e?I:P.replace(`__STEPS__`,String(t))+L)+R,de=[`uMap`,`uDepth`,`uTint`,`uOpacity`,`uIntensity`,`uView`,`uZoom`,`uMaxOffset`,`uInset`,`uFocus`,`uWallSlope`,`uO`,`uF`,`uR`,`uU`,`uClip`,`uBg`,`uBlend`],z=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],B=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],V=e=>{let t=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/t,e[1]/t,e[2]/t]};function fe(e,t){let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e??``);if(!n)return t;let r=n[1].length===3?n[1].replace(/./g,`$&$&`):n[1];return[0,2,4].map(e=>parseInt(r.slice(e,e+2),16)/255)}var pe=e=>e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4;function me(e,t){let n=e.camera,r=n.target??[0,0,0],i={x:n.position[0],y:n.position[1],z:n.position[2],set(e,t,n){this.x=e,this.y=t,this.z=n}};D(i,{x:r[0],y:r[1],z:r[2]});let a=[i.x,i.y,i.z],o=z(a,r);Math.hypot(...o)===0&&(o=[0,0,1]),o=V(o);let s=B([0,1,0],o);Math.hypot(...s)===0&&(o=V([o[0],o[1],o[2]+1e-4]),s=B([0,1,0],o)),s=V(s);let c=B(o,s),l=E(w(n.fov,45),T(t,ne(e.target?.aspect)));return{pos:a,right:s,up:c,fwd:[-o[0],-o[1],-o[2]],tanY:Math.tan(l*S/2),near:w(n.near,.1),far:w(n.far,1e3)}}function he(e){return new Promise((t,n)=>{let r=new Image;r.crossOrigin=`anonymous`,r.onload=()=>t(r),r.onerror=()=>n(/* @__PURE__ */ Error(`Cannot load texture ${e}`)),r.src=e})}function H(e,t,n={}){let r=t,i=!!n.deterministic,a=te(n),o,s,c=new Promise((e,t)=>(o=e,s=t));c.catch(()=>void 0);let l=e.ownerDocument,u=l.defaultView,d=l.createElement(`canvas`);d.style.cssText=`display:block;width:100%;height:100%;outline:none;touch-action:manipulation;`;let f=u.getComputedStyle(e).position;f&&f!==`static`||(e.style.position=`relative`),e.appendChild(d);let p=null,m=null,h={},g=[],_=null,v=null,y=[1,1],x=`high`,S=!1,T=1,E={x:0,y:0,inside:!1},D=null,k=0,A=0,j=0,M=0,N=0,P=0,F=!1,I=!0,L=!1,R=!1,z=!1,B=!1,V=1,H=1,U=1,W=null,G=[],K=/* @__PURE__ */ new Map,q=()=>r.target??{},ge=()=>r.objects[0],_e=e=>{try{n.onError?.(e)}catch{}n.onError||console.warn(`[agent3d] ${e.code}: ${e.message}`)},J=(e,t,n,r)=>{e.addEventListener(t,n,r),G.push(()=>e.removeEventListener(t,n,r))},ve=()=>{let t=Math.max(1,e.clientWidth||d.clientWidth||300);H=t,U=Math.max(1,e.clientHeight||Math.round(t/(ne(r.target?.aspect)??16/9))),d.width=Math.floor(H*T),d.height=Math.floor(U*T)},ye=()=>{if(D!==null)return D;if(i||B)return C(k/4,0,1);let t=e.getBoundingClientRect(),n=u.innerHeight||1;return C((n-t.top)/(n+t.height),0,1)},be=e=>{if(!p)return;let t=h,n=r.environment?.background,i=q().transparent?[0,0,0,0]:[...fe(typeof n==`string`?n:void 0,[0,0,0]),1];if(p.viewport(0,0,d.width,d.height),!m){p.clearColor(...i),p.clear(p.COLOR_BUFFER_BIT);return}p.useProgram(m),e&&(p.uniform2f(t.uView,e.x,e.y),p.uniform1f(t.uZoom,e.zoom));let a=ge(),o=H/Math.max(U,1),s=me(r,o),c=a.position??[0,0,0],l=a.scale??1,u=y[0]*(typeof l==`number`?l:l[0]),f=y[1]*(typeof l==`number`?l:l[1]),g=(e,t)=>[e[0]*t/u,e[1]*t/f,e[2]*t];p.uniform3f(t.uO,(s.pos[0]-c[0])/u,(s.pos[1]-c[1])/f,s.pos[2]-c[2]),p.uniform3f(t.uF,...g(s.fwd,1)),p.uniform3f(t.uR,...g(s.right,s.tanY*o)),p.uniform3f(t.uU,...g(s.up,s.tanY)),p.uniform2f(t.uClip,s.near,s.far),p.uniform4f(t.uBg,...i),p.drawArrays(p.TRIANGLES,0,3)},Y=e=>{p&&v&&be(v.offset(k,e,{pointer:E,scroll:ye(),reduced:B}))},X=()=>{p&&(ve(),(!A||i)&&be())},xe=e=>{N+=e,N<2||(M<40?P+=e:P=Math.max(0,P-e),P<3||(P=N=0,n.pixelRatio===void 0&&T>1.01?(T=Math.max(1,T*.75),X()):S=!1))},Z=()=>{let e=l.visibilityState===`hidden`,t=F&&!R&&!e&&(I||q().pauseOffscreen===!1)&&!!v;if(t&&!A){j=performance.now();let e=t=>{A=requestAnimationFrame(e);let n=Math.min(Math.max((t-j)/1e3,0),.1);j=t,n>.002&&(M=M?M*.9+1/n*.1:1/n),S&&xe(n),k=Math.max(k+n*V,0),Y(n*V)};A=requestAnimationFrame(e)}else!t&&A&&(cancelAnimationFrame(A),A=0)},Se=e=>{let t=q(),r=globalThis.navigator??{},a;try{let t=e.getExtension(`WEBGL_debug_renderer_info`);a=String(e.getParameter(t?t.UNMASKED_RENDERER_WEBGL:e.RENDERER)??``)}catch{}x=b(t.quality,{deterministic:i,mobile:r.userAgentData?.mobile??/Mobi|Android|iPhone|iPad|iPod/i.test(r.userAgent??``),cores:r.hardwareConcurrency,memoryGb:r.deviceMemory,gpu:a}),S=(t.quality??`auto`)===`auto`&&!i,N=P=0,T=n.pixelRatio??Math.min(globalThis.devicePixelRatio||1,t.maxDpr??2,ee[x]),ve()},Ce=async()=>{let e=ge(),t=0,r=0,i=(i,o,s)=>{let c=he(a(i));if(n.onProgress){t++;let e=()=>{try{n.onProgress?.(++r,t)}catch{}};c.then(e,e)}return c.catch(t=>(_e({code:`asset-load`,message:`${e.id}: ${o}${t.message}${s?` — showing the photo flat`:``}`,path:`objects#${e.id}${s}`}),null))},[o,s]=await Promise.all([i(e.src,``,``),e.depth?i(e.depth,`depth map: `,`.depth`):null]);return{map:o,depth:s}},we=()=>{if(p){for(let e of g)p.deleteTexture(e);g=[],m&&p.deleteProgram(m),m=null}},Te=async()=>{if(_??=await Ce(),R||!p)return;let e=p;Se(e),v?.dispose();let t=ge(),{map:n,depth:r}=_,a=!r;if(v=se(ie(t.motion),{live:!i,flat:a}),!n)return;let o=C(w(t.strength,O.strength),0,1),s=e.createProgram(),c=(t,n)=>{let r=e.createShader(t);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)&&!e.isContextLost())throw Error(`photo shader: ${e.getShaderInfoLog(r)}`);e.attachShader(s,r)};if(c(e.VERTEX_SHADER,le),c(e.FRAGMENT_SHADER,ue(a,oe(x,o))),e.bindAttribLocation(s,0,`aPos`),e.linkProgram(s),!e.getProgramParameter(s,e.LINK_STATUS)&&!e.isContextLost())throw Error(`photo shader: ${e.getProgramInfoLog(s)}`);m=s;for(let t of de)h[t]=e.getUniformLocation(s,t);e.bindBuffer(e.ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),e.STATIC_DRAW),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE);let l=(t,n,r)=>{let i=e.createTexture();if(g.push(i),e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,r?e.SRGB8_ALPHA8:e.RGBA8,e.RGBA,e.UNSIGNED_BYTE,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.MIRRORED_REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.MIRRORED_REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r?e.LINEAR_MIPMAP_LINEAR:e.LINEAR),r){e.generateMipmap(e.TEXTURE_2D);let t=e.getExtension(`EXT_texture_filter_anisotropic`);t&&e.texParameterf(e.TEXTURE_2D,t.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(4,e.getParameter(t.MAX_TEXTURE_MAX_ANISOTROPY_EXT)))}};l(0,n,!0),r&&l(1,r,!1),e.useProgram(s);let u=h;e.uniform1i(u.uMap,0),e.uniform1i(u.uDepth,1);let d=t.material??{},f=fe(d.color,[1,1,1]).map(pe);e.uniform3f(u.uTint,f[0],f[1],f[2]);let ee=C(w(d.opacity,1),0,1);e.uniform1f(u.uOpacity,ee),e.uniform1f(u.uIntensity,Math.max(0,w(d.emissiveIntensity,1))),e.uniform1f(u.uBlend,ee<1||/\.(png|webp)$/i.test(t.src)?1:0);let b=re(t,n.naturalWidth||n.width||1,n.naturalHeight||n.height||1),te=ae(o,b.width,b.height);e.uniform2f(u.uMaxOffset,...te.maxOffset),e.uniform2f(u.uInset,...te.inset),e.uniform1f(u.uFocus,C(w(t.focus,O.focus),0,1)),e.uniform1f(u.uWallSlope,ce),y=[b.width,b.height]},Q=()=>{if(L||R)return;L=!0;let e=q();p=d.getContext(`webgl2`,{alpha:!!e.transparent,antialias:!1,depth:!1,stencil:!1,premultipliedAlpha:!0,powerPreference:`high-performance`,preserveDrawingBuffer:i}),p?W=Te().then(()=>{R||(k=i?0:B?e.posterTime??0:k,Y(0),!i&&!B&&(F=!0,Z()),o(),z||n.onReady?.(Oe),z=!0)}).catch(e=>{_e({code:`build-error`,message:e.message}),s(e)}):(_e({code:`webgl-unavailable`,message:`WebGL is not available: no WebGL2 context`}),s(/* @__PURE__ */ Error(`webgl-unavailable`)))},Ee=e=>{D=e===null||!Number.isFinite(e)?null:C(e,0,1)},$=(e,t)=>{e!==void 0&&t!==void 0&&(E.x=e,E.y=t),E.inside=!0},De=()=>void 0,Oe={get scene(){return r},canvas:d,ready:c,input:{pointer:$,key:De,click:$,down:$,up:De,swipe:De,scroll:Ee},play(){F=!0,Q(),Z()},pause(){F=!1,Z()},async seek(e){if(L||Q(),await W,!p||!v)return;let t=Math.max(0,e);t<k-1e-9&&(k=0,v.offset(0,0,{pointer:E,scroll:0,reduced:B}));let n=t-k;k=t,Y(n)},time:()=>k,async update(e){await W,JSON.stringify(e.objects[0])!==JSON.stringify(r.objects[0])&&(_=null),r=e,p&&(we(),W=Te(),await W,Y(0))},resize:X,stats:()=>({triangles:+!!m,drawCalls:+!!m,geometries:+!!m,textures:g.length,fps:i?void 0:Math.round(M)||void 0}),inspect:()=>({objects:[],camera:{position:[...r.camera.position],target:[...r.camera.target??[0,0,0]]}}),snapshot(e=`image/png`,t){return be(),d.toDataURL(e,t)},state:()=>({}),pick:()=>null,emit(e,t){for(let n of[...K.get(e)??[]])try{n(t)}catch{}try{n.onEvent?.(e,t)}catch{}},on(e,t){let n=K.get(e);return n||K.set(e,n=/* @__PURE__ */ new Set),n.add(t),()=>n.delete(t)},setScrollProgress:Ee,dispose(){if(!R){R=!0,A&&cancelAnimationFrame(A),A=0;for(let e of G)e();G=[],v?.dispose(),we(),p?.getExtension(`WEBGL_lose_context`)?.loseContext(),p=null,d.remove()}}};if(J(e,`pointermove`,t=>{let n=e.getBoundingClientRect(),r=t;$((r.clientX-n.left)/Math.max(n.width,1)*2-1,-((r.clientY-n.top)/Math.max(n.height,1)*2-1))}),J(e,`pointerenter`,()=>E.inside=!0),J(e,`pointerleave`,()=>E.inside=!1),J(l,`visibilitychange`,Z),ve(),typeof ResizeObserver<`u`){let t=new ResizeObserver(X);t.observe(e),G.push(()=>t.disconnect())}let ke=q(),Ae=n.reducedMotion??(typeof matchMedia<`u`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches),je=ke.reducedMotion??`static`;if(Ae&&!i&&(je===`static`?B=!0:je===`slow`&&(V=.5)),i||ke.lazy===!1||typeof IntersectionObserver>`u`)Q();else{I=!1;let t=new IntersectionObserver(e=>{I=e.some(e=>e.isIntersecting),I&&Q(),Z()},{rootMargin:`200px 0px`});t.observe(e);let n=()=>{if(L||R||l.visibilityState===`hidden`||!e.isConnected)return;let t=e.getBoundingClientRect(),n=u.innerHeight||l.documentElement.clientHeight,r=u.innerWidth||l.documentElement.clientWidth;t.bottom>=-200&&t.top<=n+200&&t.right>=0&&t.left<=r&&(t.width>0||t.height>0)&&(I=!0,Q(),Z())},r=[setTimeout(n,500),setTimeout(n,2e3)],i=u.requestAnimationFrame(()=>i=u.requestAnimationFrame(n));J(u,`load`,n),J(u,`scroll`,n,{passive:!0}),J(l,`visibilitychange`,n),G.push(()=>{t.disconnect();for(let e of r)clearTimeout(e);u.cancelAnimationFrame(i)})}return d.isConnected&&X(),Oe}function U(e,t,n){let r=null,i=!1,a=!1,o=import.meta.url.replace(/[^/?#]*([?#].*)?$/,`agent3d-runtime.js`),s=import(
|
|
30
|
+
/* @vite-ignore */
|
|
31
|
+
o).then(o=>{if(a)throw Error(`disposed`);return r=o.mountScene(e,t,n),i&&r.pause(),r.ready},e=>{throw n.onError?.({code:`runtime-load`,message:`This scene needs the full runtime (${o}): ${e.message}`}),e});s.catch(()=>void 0);let c={ready:s,play:()=>(i=!1,r?.play()),pause:()=>(i=!0,r?.pause()),seek:async e=>(await s,r.seek(e)),dispose:()=>(a=!0,r?.dispose())};return new Proxy(c,{get(e,t){if(t in c)return c[t];let n=r?.[t];return typeof n==`function`?n.bind(r):n}})}var W=class extends v{mountPlayer(e,t,r){return n(t).ok?H(e,t,r):U(e,t,r)}};y(W);export{W as Agent3DPhotoElement,H as mountPhotoScene};
|