@fleox/agent3d 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +20 -13
  2. package/changelog.json +15 -0
  3. package/dist/agent/agent3d.mjs +228 -53
  4. package/dist/agent/chunks/{assets-BUUM9TUB.mjs → assets-YBkgdfgy.mjs} +27 -8
  5. package/dist/agent/chunks/{browser-Br1tURgt.mjs → browser-Dil7VM5m.mjs} +1 -1
  6. package/dist/agent/chunks/{cdp-Bdtm4fBN.mjs → cdp-DLEis_Z3.mjs} +1 -1
  7. package/dist/agent/chunks/{check-CfZcfaPs.mjs → check-DP9fRYbK.mjs} +64 -4
  8. package/dist/agent/chunks/depth-0bZsQn6N.mjs +190 -0
  9. package/dist/agent/chunks/depth-Dih8jLqx.mjs +483 -0
  10. package/dist/agent/chunks/{export-BHugc2H7.mjs → export-Cdqt3mt_.mjs} +8 -4
  11. package/dist/agent/chunks/{imageCodec-QM0EXQDJ.mjs → imageCodec-DeGfmBp3.mjs} +3 -3
  12. package/dist/agent/chunks/{objects-DBAws7uf.mjs → objects-DuytRxiC.mjs} +3 -3
  13. package/dist/agent/chunks/{optimizeSizing-CkZ3fZRp.mjs → optimizeSizing-B-BBiUkD.mjs} +51 -3
  14. package/dist/agent/chunks/{package-fw4h5vsh.mjs → package-d5e08XSG.mjs} +2 -1
  15. package/dist/agent/chunks/{render-EHb40avl.mjs → render-B05DU4Q5.mjs} +4 -4
  16. package/dist/agent/chunks/{scene-BgajNvBf.mjs → scene-DWgXH6As.mjs} +2 -2
  17. package/dist/agent/chunks/{server-CACCerkZ.mjs → server-Dt_YFvN7.mjs} +6 -2
  18. package/dist/agent/chunks/{tools-DKxgjQSJ.mjs → tools-Cv6N_YBI.mjs} +60 -6
  19. package/dist/agent/chunks/{tree-BrNYGui2.mjs → tree-CqSj-o8T.mjs} +1 -0
  20. package/dist/agent/ort/LICENSE.txt +9 -0
  21. package/dist/agent/ort/ort-wasm-simd-threaded.wasm +0 -0
  22. package/dist/agent/ort/ort.wasm.bundle.min.mjs +9 -0
  23. package/dist/runtime/agent3d-runtime.js +6 -6
  24. package/dist/runtime/agent3d-runtime.single.js +311 -62
  25. package/dist/runtime/chunks/assets-qnxDnVkj.js +1 -0
  26. package/dist/runtime/chunks/materials-dC4vDNHh.js +107 -0
  27. package/dist/runtime/chunks/{model-DbfZaLni.js → model-BCAl_NRl.js} +1 -1
  28. package/dist/runtime/chunks/photo-BlDYgYFM.js +250 -0
  29. package/dist/runtime/chunks/svg-CLUxY6Zy.js +1 -0
  30. package/dist/runtime/chunks/{text-BaON-ISS.js → text-rSo_2Luk.js} +2 -2
  31. package/dist/studio/assets/assets-BFJsr9Oo.js +1 -0
  32. package/dist/studio/assets/{camera-Be6lnp3k.js → camera-DT0xHipx.js} +1 -1
  33. package/dist/studio/assets/{editor-Mpnz-b2E.js → editor-BjgHj9g8.js} +1 -1
  34. package/dist/studio/assets/{game-WMgRSJUD.js → game-BXZEc9HN.js} +3 -3
  35. package/dist/studio/assets/{generators-DozXE7ta.js → generators-DqkPMEzm.js} +1 -1
  36. package/dist/studio/assets/index-DVTzVcBD.js +479 -0
  37. package/dist/studio/assets/{model-C2bZTK7-.js → model-BqQW4Dg-.js} +1 -1
  38. package/dist/studio/assets/params-gVpEEiSK.js +1 -0
  39. package/dist/studio/assets/photo-DRoVO5iZ.js +250 -0
  40. package/dist/studio/assets/{physicsHost-CTRsIvfu.js → physicsHost-DNdZ7AsT.js} +1 -1
  41. package/dist/studio/assets/{postfx-DQtp0JIy.js → postfx-JFUGdY0d.js} +1 -1
  42. package/dist/studio/assets/runtime-CMAP4azF.js +572 -0
  43. package/dist/studio/assets/{shaders-BOb6Uter.js → shaders-C7u6rN_6.js} +12 -12
  44. package/dist/studio/assets/svg-DkIOJjzS.js +2 -0
  45. package/dist/studio/assets/{text-CGIZs8HE.js → text-LISSAism.js} +2 -2
  46. package/dist/studio/index.html +1 -1
  47. package/package.json +2 -1
  48. package/plugin/.claude-plugin/plugin.json +1 -1
  49. package/plugin/skills/agent3d-assets/SKILL.md +40 -25
  50. package/plugin/skills/agent3d-create/SKILL.md +56 -21
  51. package/plugin/skills/agent3d-create/references/art-direction.md +3 -3
  52. package/plugin/skills/agent3d-create/references/recipes.md +71 -6
  53. package/plugin/skills/agent3d-edit/SKILL.md +22 -22
  54. package/plugin/skills/agent3d-edit/references/patch-ops.md +11 -3
  55. package/plugin/skills/agent3d-game/SKILL.md +7 -7
  56. package/plugin/skills/agent3d-publish/SKILL.md +23 -21
  57. package/plugin/skills/agent3d-publish/references/integrations.md +1 -1
  58. package/templates/hero-photo-3d/README.md +28 -0
  59. package/templates/hero-photo-3d/agent3d.json +8 -0
  60. package/templates/hero-photo-3d/assets/depth/street-depth.png +0 -0
  61. package/templates/hero-photo-3d/assets/manifest.json +25 -0
  62. package/templates/hero-photo-3d/assets/textures/street.jpg +0 -0
  63. package/templates/hero-photo-3d/preview.png +0 -0
  64. package/templates/hero-photo-3d/scene.json +120 -0
  65. package/templates/hero-photo-3d/template.json +8 -0
  66. package/dist/runtime/chunks/materials-w3EW0g-7.js +0 -107
  67. package/dist/runtime/chunks/svg-CfPIQnDG.js +0 -1
  68. package/dist/studio/assets/index-tSGZFEt5.js +0 -479
  69. package/dist/studio/assets/runtime-NGp1VdnH.js +0 -572
  70. package/dist/studio/assets/svg-CnUMpv_N.js +0 -2
@@ -1,4 +1,4 @@
1
- import{OrbitControls as e}from"./OrbitControls-MlE9XiCg.js";import{Bt as t,En as n,Ft as r,Ht as i,I as a,In as o,It as s,Kt as c,Ln as l,N as u,Pt as d,Qt as f,Rt as p,St as m,T as h,an as g,at as _,bt as v,d as y,f as b,h as x,hn as ee,it as te,m as S,mn as C,nt as w,on as T,p as E,st as D,vt as O,w as ne,x as k,xt as A,yn as re,zt as ie}from"./three.module-CnI50X0U.js";import{r as ae}from"./camera-Be6lnp3k.js";import{a as j,i as M,n as N,o as oe}from"./index-tSGZFEt5.js";var P=new f,F=new l,I=new l,L=new c,se={X:new l(1,0,0),Y:new l(0,1,0),Z:new l(0,0,1)},R={type:`change`},z={type:`mouseDown`,mode:null},ce={type:`mouseUp`,mode:null},le={type:`objectChange`},ue=class extends ne{constructor(e,t=null){super(void 0,t);let n=new ve(this);this._root=n;let r=new ye;this._gizmo=r,n.add(r);let i=new be;this._plane=i,n.add(i);let a=this;function o(e,t){let n=t;Object.defineProperty(a,e,{get:function(){return n===void 0?t:n},set:function(t){n!==t&&(n=t,i[e]=t,r[e]=t,a.dispatchEvent({type:e+`-changed`,value:t}),a.dispatchEvent(R))}}),a[e]=t,i[e]=t,r[e]=t}o(`camera`,e),o(`object`,void 0),o(`enabled`,!0),o(`axis`,null),o(`mode`,`translate`),o(`translationSnap`,null),o(`rotationSnap`,null),o(`scaleSnap`,null),o(`space`,`world`),o(`size`,1),this.viewport=null,o(`dragging`,!1),o(`showX`,!0),o(`showY`,!0),o(`showZ`,!0),o(`showXY`,!0),o(`showYZ`,!0),o(`showXZ`,!0),o(`showXYZE`,!0),o(`showE`,!0),o(`minX`,-1/0),o(`maxX`,1/0),o(`minY`,-1/0),o(`maxY`,1/0),o(`minZ`,-1/0),o(`maxZ`,1/0);let s=new l,u=new l,d=new c,f=new c,p=new l,m=new c,h=new l,g=new l,_=new l,v=new l;o(`worldPosition`,s),o(`worldPositionStart`,u),o(`worldQuaternion`,d),o(`worldQuaternionStart`,f),o(`cameraPosition`,p),o(`cameraQuaternion`,m),o(`pointStart`,h),o(`pointEnd`,g),o(`rotationAxis`,_),o(`rotationAngle`,0),o(`eye`,v),this._offset=new l,this._startNorm=new l,this._endNorm=new l,this._cameraScale=new l,this._parentPosition=new l,this._parentQuaternion=new c,this._parentQuaternionInv=new c,this._parentScale=new l,this._worldScaleStart=new l,this._worldQuaternionInv=new c,this._worldScale=new l,this._positionStart=new l,this._quaternionStart=new c,this._scaleStart=new l,this._getPointer=de.bind(this),this._onPointerDown=pe.bind(this),this._onPointerHover=fe.bind(this),this._onPointerMove=me.bind(this),this._onPointerUp=he.bind(this),t!==null&&this.connect(t)}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointermove`,this._onPointerHover),this.domElement.addEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.removeEventListener(`pointermove`,this._onPointerHover),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=``}getHelper(){return this._root}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;e!==null&&P.setFromCamera(e,this.camera);let t=B(this._gizmo.picker[this.mode],P);this.axis=t?t.object.name:null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e!=null&&e.button!==0)&&this.axis!==null){e!==null&&P.setFromCamera(e,this.camera);let t=B(this._plane,P,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,z.mode=this.mode,this.dispatchEvent(z)}}pointerMove(e){let t=this.axis,n=this.mode,r=this.object,i=this.space;if(n===`scale`?i=`local`:(t===`E`||t===`XYZE`||t===`XYZ`)&&(i=`world`),r===void 0||t===null||this.dragging===!1||e!==null&&e.button!==-1)return;e!==null&&P.setFromCamera(e,this.camera);let a=B(this._plane,P,!0);if(a){if(this.pointEnd.copy(a.point).sub(this.worldPositionStart),n===`translate`)this._offset.copy(this.pointEnd).sub(this.pointStart),i===`local`&&t!==`XYZ`&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf(`X`)===-1&&(this._offset.x=0),t.indexOf(`Y`)===-1&&(this._offset.y=0),t.indexOf(`Z`)===-1&&(this._offset.z=0),i===`local`&&t!==`XYZ`?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),r.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(i===`local`&&(r.position.applyQuaternion(L.copy(this._quaternionStart).invert()),t.search(`X`)!==-1&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.position.applyQuaternion(this._quaternionStart)),i===`world`&&(r.getWorldPosition(F),t.search(`X`)!==-1&&(F.x=Math.round(F.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(F.y=Math.round(F.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(F.z=Math.round(F.z/this.translationSnap)*this.translationSnap),r.position.copy(r.parent.worldToLocal(F)))),r.position.x=Math.max(this.minX,Math.min(this.maxX,r.position.x)),r.position.y=Math.max(this.minY,Math.min(this.maxY,r.position.y)),r.position.z=Math.max(this.minZ,Math.min(this.maxZ,r.position.z));else if(n===`scale`){if(t.search(`XYZ`)!==-1){let e=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(e*=-1),I.set(e,e,e)}else F.copy(this.pointStart),I.copy(this.pointEnd),F.applyQuaternion(this._worldQuaternionInv),I.applyQuaternion(this._worldQuaternionInv),I.divide(F),t.search(`X`)===-1&&(I.x=1),t.search(`Y`)===-1&&(I.y=1),t.search(`Z`)===-1&&(I.z=1);r.scale.copy(this._scaleStart).multiply(I),this.scaleSnap&&(t.search(`X`)!==-1&&(r.scale.x=Math.round(r.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Y`)!==-1&&(r.scale.y=Math.round(r.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Z`)!==-1&&(r.scale.z=Math.round(r.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(n===`rotate`){this._offset.copy(this.pointEnd).sub(this.pointStart);let e=20/this.worldPosition.distanceTo(F.setFromMatrixPosition(this.camera.matrixWorld)),n=!1;t===`XYZE`?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(F.copy(this.rotationAxis).cross(this.eye))*e):(t===`X`||t===`Y`||t===`Z`)&&(this.rotationAxis.copy(se[t]),F.copy(se[t]),i===`local`&&F.applyQuaternion(this.worldQuaternion),F.cross(this.eye),F.length()===0?n=!0:this.rotationAngle=this._offset.dot(F.normalize())*e),(t===`E`||n)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),i===`local`&&t!==`E`&&t!==`XYZE`?(r.quaternion.copy(this._quaternionStart),r.quaternion.multiply(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),r.quaternion.copy(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),r.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(R),this.dispatchEvent(le)}}pointerUp(e){(e===null||e.button===0)&&(this.dragging&&this.axis!==null&&(ce.mode=this.mode,this.dispatchEvent(ce)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(e){return this.object=e,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(R),this.dispatchEvent(le),this.pointStart.copy(this.pointEnd))}getRaycaster(){return P}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}setColors(e,t,n,r){let i=this._gizmo.materialLib;i.xAxis.color.set(e),i.yAxis.color.set(t),i.zAxis.color.set(n),i.active.color.set(r),i.xAxisTransparent.color.set(e),i.yAxisTransparent.color.set(t),i.zAxisTransparent.color.set(n),i.activeTransparent.color.set(r),i.xAxis._color&&i.xAxis._color.set(e),i.yAxis._color&&i.yAxis._color.set(t),i.zAxis._color&&i.zAxis._color.set(n),i.active._color&&i.active._color.set(r),i.xAxisTransparent._color&&i.xAxisTransparent._color.set(e),i.yAxisTransparent._color&&i.yAxisTransparent._color.set(t),i.zAxisTransparent._color&&i.zAxisTransparent._color.set(n),i.activeTransparent._color&&i.activeTransparent._color.set(r)}};function de(e){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:e.button};{let t=this.domElement.getBoundingClientRect(),n=this.viewport,r,i,a,o;return n===null?(r=0,i=0,a=t.width,o=t.height):(r=n.x,i=t.height-n.y-n.w,a=n.z,o=n.w),{x:(e.clientX-t.left-r)/a*2-1,y:-(e.clientY-t.top-i)/o*2+1,button:e.button}}}function fe(e){if(this.enabled)switch(e.pointerType){case`mouse`:case`pen`:this.pointerHover(this._getPointer(e))}}function pe(e){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener(`pointermove`,this._onPointerMove),this.pointerHover(this._getPointer(e)),this.pointerDown(this._getPointer(e)))}function me(e){this.enabled&&this.pointerMove(this._getPointer(e))}function he(e){this.enabled&&(this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.pointerUp(this._getPointer(e)))}function B(e,t,n){let r=t.intersectObject(e,!0);for(let e=0;e<r.length;e++)if(r[e].object.visible||n)return r[e];return!1}var V=new u,H=new l(0,1,0),ge=new l(0,0,0),_e=new v,U=new c,W=new c,G=new l,K=new v,q=new l(1,0,0),J=new l(0,1,0),Y=new l(0,0,1),X=new l,Z=new l,Q=new l,ve=class extends d{constructor(e){super(),this.isTransformControlsRoot=!0,this.controls=e,this.visible=!1}updateMatrixWorld(e){let t=this.controls;t.object!==void 0&&(t.object.updateMatrixWorld(),t.object.parent===null?console.error(`TransformControls: The attached 3D object must be a part of the scene graph.`):t.object.parent.matrixWorld.decompose(t._parentPosition,t._parentQuaternion,t._parentScale),t.object.matrixWorld.decompose(t.worldPosition,t.worldQuaternion,t._worldScale),t._parentQuaternionInv.copy(t._parentQuaternion).invert(),t._worldQuaternionInv.copy(t.worldQuaternion).invert()),t.camera.updateMatrixWorld(),t.camera.matrixWorld.decompose(t.cameraPosition,t.cameraQuaternion,t._cameraScale),t.camera.isOrthographicCamera?t.camera.getWorldDirection(t.eye).negate():t.eye.copy(t.cameraPosition).sub(t.worldPosition).normalize(),this.parent&&(K.copy(this.parent.matrixWorld).invert(),K.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(e)}dispose(){this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}},ye=class extends d{constructor(){super(),this.isTransformControlsGizmo=!0,this.type=`TransformControlsGizmo`;let e=new m({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new te({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=e.clone();i.opacity=.15;let o=t.clone();o.opacity=.5;let s=e.clone();s.color.setHex(16711680);let c=e.clone();c.color.setHex(65280);let l=e.clone();l.color.setHex(255);let u=e.clone();u.color.setHex(16711680),u.opacity=.5;let f=e.clone();f.color.setHex(65280),f.opacity=.5;let p=e.clone();p.color.setHex(255),p.opacity=.5;let g=e.clone();g.opacity=.25;let _=e.clone();_.color.setHex(16776960),_.opacity=.25;let v=e.clone();v.color.setHex(16776960);let y=e.clone();y.color.setHex(7895160),this.materialLib={xAxis:s,yAxis:c,zAxis:l,active:v,xAxisTransparent:u,yAxisTransparent:f,zAxisTransparent:p,activeTransparent:_};let b=new h(0,.04,.1,12);b.translate(0,.05,0);let S=new E(.08,.08,.08);S.translate(0,.04,0);let C=new x;C.setAttribute(`position`,new a([0,0,0,1,0,0],3));let T=new h(.0075,.0075,.5,3);T.translate(0,.25,0);function D(e,t){let r=new n(e,.0075,3,64,t*Math.PI*2);return r.rotateY(Math.PI/2),r.rotateX(Math.PI/2),r}function O(){let e=new x;return e.setAttribute(`position`,new a([0,0,0,1,1,1],3)),e}let ne={X:[[new A(b,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(b,s),[-.5,0,0],[0,0,Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new A(b,c),[0,.5,0]],[new A(b,c),[0,-.5,0],[Math.PI,0,0]],[new A(T,c)]],Z:[[new A(b,l),[0,0,.5],[Math.PI/2,0,0]],[new A(b,l),[0,0,-.5],[-Math.PI/2,0,0]],[new A(T,l),null,[Math.PI/2,0,0]]],XYZ:[[new A(new r(.1,0),g),[0,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]]},k={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new A(new r(.2,0),i)]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},re={START:[[new A(new r(.01,2),o),null,null,null,`helper`]],END:[[new A(new r(.01,2),o),null,null,null,`helper`]],DELTA:[[new w(O(),o),null,null,null,`helper`]],X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]},ie={XYZE:[[new A(D(.5,1),y),null,[0,Math.PI/2,0]]],X:[[new A(D(.5,.5),s)]],Y:[[new A(D(.5,.5),c),null,[0,0,-Math.PI/2]]],Z:[[new A(D(.5,.5),l),null,[0,Math.PI/2,0]]],E:[[new A(D(.75,1),_),null,[0,Math.PI/2,0]]]},ae={AXIS:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]]},j={XYZE:[[new A(new ee(.25,10,8),i)]],X:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new A(new n(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new A(new n(.75,.1,2,24),i)]]},M={X:[[new A(S,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]],[new A(S,s),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new A(S,c),[0,.5,0]],[new A(T,c)],[new A(S,c),[0,-.5,0],[0,0,Math.PI]]],Z:[[new A(S,l),[0,0,.5],[Math.PI/2,0,0]],[new A(T,l),[0,0,0],[Math.PI/2,0,0]],[new A(S,l),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.1,.1,.1),g)]]},N={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.2,.2,.2),i),[0,0,0]]]},oe={X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]};function P(e){let t=new d;for(let n in e)for(let r=e[n].length;r--;){let i=e[n][r][0].clone(),a=e[n][r][1],o=e[n][r][2],s=e[n][r][3],c=e[n][r][4];i.name=n,i.tag=c,a&&i.position.set(a[0],a[1],a[2]),o&&i.rotation.set(o[0],o[1],o[2]),s&&i.scale.set(s[0],s[1],s[2]),i.updateMatrix();let l=i.geometry.clone();l.applyMatrix4(i.matrix),i.geometry=l,i.renderOrder=1/0,i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),t.add(i)}return t}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=P(ne)),this.add(this.gizmo.rotate=P(ie)),this.add(this.gizmo.scale=P(M)),this.add(this.picker.translate=P(k)),this.add(this.picker.rotate=P(j)),this.add(this.picker.scale=P(N)),this.add(this.helper.translate=P(re)),this.add(this.helper.rotate=P(ae)),this.add(this.helper.scale=P(oe)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){let t=(this.mode===`scale`?`local`:this.space)===`local`?this.worldQuaternion:W;this.gizmo.translate.visible=this.mode===`translate`,this.gizmo.rotate.visible=this.mode===`rotate`,this.gizmo.scale.visible=this.mode===`scale`,this.helper.translate.visible=this.mode===`translate`,this.helper.rotate.visible=this.mode===`rotate`,this.helper.scale.visible=this.mode===`scale`;let n=[];n=n.concat(this.picker[this.mode].children),n=n.concat(this.gizmo[this.mode].children),n=n.concat(this.helper[this.mode].children);for(let e=0;e<n.length;e++){let r=n[e];r.visible=!0,r.rotation.set(0,0,0),r.position.copy(this.worldPosition);let i;if(i=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),r.scale.set(1,1,1).multiplyScalar(i*this.size/4),r.tag===`helper`)r.visible=!1,r.name===`AXIS`?(r.visible=!!this.axis,this.axis===`X`&&(L.setFromEuler(V.set(0,0,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Y`&&(L.setFromEuler(V.set(0,0,Math.PI/2)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Z`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`XYZE`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),H.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(_e.lookAt(ge,H,J)),r.quaternion.multiply(L),r.visible=this.dragging),this.axis===`E`&&(r.visible=!1)):r.name===`START`?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):r.name===`END`?(r.position.copy(this.worldPosition),r.visible=this.dragging):r.name===`DELTA`?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),F.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),F.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(F),r.visible=this.dragging):(r.quaternion.copy(t),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=this.axis.search(r.name)!==-1));else{if(r.quaternion.copy(t),this.mode===`translate`||this.mode===`scale`){let e=.99,n=.2;r.name===`X`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Y`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Z`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XY`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`YZ`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XZ`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1)}else this.mode===`rotate`&&(U.copy(t),H.copy(this.eye).applyQuaternion(L.copy(t).invert()),r.name.search(`E`)!==-1&&r.quaternion.setFromRotationMatrix(_e.lookAt(this.eye,ge,J)),r.name===`X`&&(L.setFromAxisAngle(q,Math.atan2(-H.y,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Y`&&(L.setFromAxisAngle(J,Math.atan2(H.x,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Z`&&(L.setFromAxisAngle(Y,Math.atan2(H.y,H.x)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)));r.visible=r.visible&&(r.name.indexOf(`X`)===-1||this.showX),r.visible=r.visible&&(r.name.indexOf(`Y`)===-1||this.showY),r.visible=r.visible&&(r.name.indexOf(`Z`)===-1||this.showZ),r.visible=r.visible&&(r.name.indexOf(`E`)===-1||this.showX&&this.showY&&this.showZ),r.visible=r.visible&&(r.name.indexOf(`XY`)===-1||this.showXY),r.visible=r.visible&&(r.name.indexOf(`YZ`)===-1||this.showYZ),r.visible=r.visible&&(r.name.indexOf(`XZ`)===-1||this.showXZ),r.visible=r.visible&&(r.name!==`E`||this.showE),r.visible=r.visible&&(r.name!==`XYZE`||this.showXYZE),r.material._color=r.material._color||r.material.color.clone(),r.material._opacity=r.material._opacity||r.material.opacity,r.material.color.copy(r.material._color),r.material.opacity=r.material._opacity,this.enabled&&this.axis&&(r.name===this.axis||this.axis.split(``).some(function(e){return r.name===e}))&&(r.material.color.copy(this.materialLib.active.color),r.material.opacity=1)}}super.updateMatrixWorld(e)}},be=class extends A{constructor(){super(new t(1e5,1e5,2,2),new m({visible:!1,wireframe:!0,side:2,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type=`TransformControlsPlane`}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode===`scale`&&(t=`local`),X.copy(q).applyQuaternion(t===`local`?this.worldQuaternion:W),Z.copy(J).applyQuaternion(t===`local`?this.worldQuaternion:W),Q.copy(Y).applyQuaternion(t===`local`?this.worldQuaternion:W),H.copy(Z),this.mode){case`translate`:case`scale`:switch(this.axis){case`X`:H.copy(this.eye).cross(X),G.copy(X).cross(H);break;case`Y`:H.copy(this.eye).cross(Z),G.copy(Z).cross(H);break;case`Z`:H.copy(this.eye).cross(Q),G.copy(Q).cross(H);break;case`XY`:G.copy(Q);break;case`YZ`:G.copy(X);break;case`XZ`:H.copy(Q),G.copy(Z);break;case`XYZ`:case`E`:G.set(0,0,0)}break;default:G.set(0,0,0)}G.length()===0?this.quaternion.copy(this.cameraQuaternion):(K.lookAt(F.set(0,0,0),G,H),this.quaternion.setFromRotationMatrix(K)),super.updateMatrixWorld(e)}},xe=`
1
+ import{OrbitControls as e}from"./OrbitControls-MlE9XiCg.js";import{Bt as t,En as n,Ft as r,Ht as i,I as a,In as o,It as s,Kt as c,Ln as l,N as u,Pt as d,Qt as f,Rt as p,St as m,T as h,an as g,at as _,bt as v,d as y,f as b,h as x,hn as ee,it as te,m as S,mn as C,nt as w,on as T,p as E,st as D,vt as O,w as ne,x as k,xt as A,yn as re,zt as ie}from"./three.module-CnI50X0U.js";import{r as ae}from"./camera-DT0xHipx.js";import{a as j,i as M,n as N,o as oe}from"./index-DVTzVcBD.js";var P=new f,F=new l,I=new l,L=new c,se={X:new l(1,0,0),Y:new l(0,1,0),Z:new l(0,0,1)},R={type:`change`},z={type:`mouseDown`,mode:null},ce={type:`mouseUp`,mode:null},le={type:`objectChange`},ue=class extends ne{constructor(e,t=null){super(void 0,t);let n=new ve(this);this._root=n;let r=new ye;this._gizmo=r,n.add(r);let i=new be;this._plane=i,n.add(i);let a=this;function o(e,t){let n=t;Object.defineProperty(a,e,{get:function(){return n===void 0?t:n},set:function(t){n!==t&&(n=t,i[e]=t,r[e]=t,a.dispatchEvent({type:e+`-changed`,value:t}),a.dispatchEvent(R))}}),a[e]=t,i[e]=t,r[e]=t}o(`camera`,e),o(`object`,void 0),o(`enabled`,!0),o(`axis`,null),o(`mode`,`translate`),o(`translationSnap`,null),o(`rotationSnap`,null),o(`scaleSnap`,null),o(`space`,`world`),o(`size`,1),this.viewport=null,o(`dragging`,!1),o(`showX`,!0),o(`showY`,!0),o(`showZ`,!0),o(`showXY`,!0),o(`showYZ`,!0),o(`showXZ`,!0),o(`showXYZE`,!0),o(`showE`,!0),o(`minX`,-1/0),o(`maxX`,1/0),o(`minY`,-1/0),o(`maxY`,1/0),o(`minZ`,-1/0),o(`maxZ`,1/0);let s=new l,u=new l,d=new c,f=new c,p=new l,m=new c,h=new l,g=new l,_=new l,v=new l;o(`worldPosition`,s),o(`worldPositionStart`,u),o(`worldQuaternion`,d),o(`worldQuaternionStart`,f),o(`cameraPosition`,p),o(`cameraQuaternion`,m),o(`pointStart`,h),o(`pointEnd`,g),o(`rotationAxis`,_),o(`rotationAngle`,0),o(`eye`,v),this._offset=new l,this._startNorm=new l,this._endNorm=new l,this._cameraScale=new l,this._parentPosition=new l,this._parentQuaternion=new c,this._parentQuaternionInv=new c,this._parentScale=new l,this._worldScaleStart=new l,this._worldQuaternionInv=new c,this._worldScale=new l,this._positionStart=new l,this._quaternionStart=new c,this._scaleStart=new l,this._getPointer=de.bind(this),this._onPointerDown=pe.bind(this),this._onPointerHover=fe.bind(this),this._onPointerMove=me.bind(this),this._onPointerUp=he.bind(this),t!==null&&this.connect(t)}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointermove`,this._onPointerHover),this.domElement.addEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.removeEventListener(`pointermove`,this._onPointerHover),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.style.touchAction=``}getHelper(){return this._root}pointerHover(e){if(this.object===void 0||this.dragging===!0)return;e!==null&&P.setFromCamera(e,this.camera);let t=B(this._gizmo.picker[this.mode],P);this.axis=t?t.object.name:null}pointerDown(e){if(!(this.object===void 0||this.dragging===!0||e!=null&&e.button!==0)&&this.axis!==null){e!==null&&P.setFromCamera(e,this.camera);let t=B(this._plane,P,!0);t&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(t.point).sub(this.worldPositionStart)),this.dragging=!0,z.mode=this.mode,this.dispatchEvent(z)}}pointerMove(e){let t=this.axis,n=this.mode,r=this.object,i=this.space;if(n===`scale`?i=`local`:(t===`E`||t===`XYZE`||t===`XYZ`)&&(i=`world`),r===void 0||t===null||this.dragging===!1||e!==null&&e.button!==-1)return;e!==null&&P.setFromCamera(e,this.camera);let a=B(this._plane,P,!0);if(a){if(this.pointEnd.copy(a.point).sub(this.worldPositionStart),n===`translate`)this._offset.copy(this.pointEnd).sub(this.pointStart),i===`local`&&t!==`XYZ`&&this._offset.applyQuaternion(this._worldQuaternionInv),t.indexOf(`X`)===-1&&(this._offset.x=0),t.indexOf(`Y`)===-1&&(this._offset.y=0),t.indexOf(`Z`)===-1&&(this._offset.z=0),i===`local`&&t!==`XYZ`?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),r.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(i===`local`&&(r.position.applyQuaternion(L.copy(this._quaternionStart).invert()),t.search(`X`)!==-1&&(r.position.x=Math.round(r.position.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(r.position.y=Math.round(r.position.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(r.position.z=Math.round(r.position.z/this.translationSnap)*this.translationSnap),r.position.applyQuaternion(this._quaternionStart)),i===`world`&&(r.getWorldPosition(F),t.search(`X`)!==-1&&(F.x=Math.round(F.x/this.translationSnap)*this.translationSnap),t.search(`Y`)!==-1&&(F.y=Math.round(F.y/this.translationSnap)*this.translationSnap),t.search(`Z`)!==-1&&(F.z=Math.round(F.z/this.translationSnap)*this.translationSnap),r.position.copy(r.parent.worldToLocal(F)))),r.position.x=Math.max(this.minX,Math.min(this.maxX,r.position.x)),r.position.y=Math.max(this.minY,Math.min(this.maxY,r.position.y)),r.position.z=Math.max(this.minZ,Math.min(this.maxZ,r.position.z));else if(n===`scale`){if(t.search(`XYZ`)!==-1){let e=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(e*=-1),I.set(e,e,e)}else F.copy(this.pointStart),I.copy(this.pointEnd),F.applyQuaternion(this._worldQuaternionInv),I.applyQuaternion(this._worldQuaternionInv),I.divide(F),t.search(`X`)===-1&&(I.x=1),t.search(`Y`)===-1&&(I.y=1),t.search(`Z`)===-1&&(I.z=1);r.scale.copy(this._scaleStart).multiply(I),this.scaleSnap&&(t.search(`X`)!==-1&&(r.scale.x=Math.round(r.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Y`)!==-1&&(r.scale.y=Math.round(r.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),t.search(`Z`)!==-1&&(r.scale.z=Math.round(r.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(n===`rotate`){this._offset.copy(this.pointEnd).sub(this.pointStart);let e=20/this.worldPosition.distanceTo(F.setFromMatrixPosition(this.camera.matrixWorld)),n=!1;t===`XYZE`?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(F.copy(this.rotationAxis).cross(this.eye))*e):(t===`X`||t===`Y`||t===`Z`)&&(this.rotationAxis.copy(se[t]),F.copy(se[t]),i===`local`&&F.applyQuaternion(this.worldQuaternion),F.cross(this.eye),F.length()===0?n=!0:this.rotationAngle=this._offset.dot(F.normalize())*e),(t===`E`||n)&&(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),i===`local`&&t!==`E`&&t!==`XYZE`?(r.quaternion.copy(this._quaternionStart),r.quaternion.multiply(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),r.quaternion.copy(L.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),r.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(R),this.dispatchEvent(le)}}pointerUp(e){(e===null||e.button===0)&&(this.dragging&&this.axis!==null&&(ce.mode=this.mode,this.dispatchEvent(ce)),this.dragging=!1,this.axis=null)}dispose(){this.disconnect(),this._root.dispose()}attach(e){return this.object=e,this._root.visible=!0,this}detach(){return this.object=void 0,this.axis=null,this._root.visible=!1,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(R),this.dispatchEvent(le),this.pointStart.copy(this.pointEnd))}getRaycaster(){return P}getMode(){return this.mode}setMode(e){this.mode=e}setTranslationSnap(e){this.translationSnap=e}setRotationSnap(e){this.rotationSnap=e}setScaleSnap(e){this.scaleSnap=e}setSize(e){this.size=e}setSpace(e){this.space=e}setColors(e,t,n,r){let i=this._gizmo.materialLib;i.xAxis.color.set(e),i.yAxis.color.set(t),i.zAxis.color.set(n),i.active.color.set(r),i.xAxisTransparent.color.set(e),i.yAxisTransparent.color.set(t),i.zAxisTransparent.color.set(n),i.activeTransparent.color.set(r),i.xAxis._color&&i.xAxis._color.set(e),i.yAxis._color&&i.yAxis._color.set(t),i.zAxis._color&&i.zAxis._color.set(n),i.active._color&&i.active._color.set(r),i.xAxisTransparent._color&&i.xAxisTransparent._color.set(e),i.yAxisTransparent._color&&i.yAxisTransparent._color.set(t),i.zAxisTransparent._color&&i.zAxisTransparent._color.set(n),i.activeTransparent._color&&i.activeTransparent._color.set(r)}};function de(e){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:e.button};{let t=this.domElement.getBoundingClientRect(),n=this.viewport,r,i,a,o;return n===null?(r=0,i=0,a=t.width,o=t.height):(r=n.x,i=t.height-n.y-n.w,a=n.z,o=n.w),{x:(e.clientX-t.left-r)/a*2-1,y:-(e.clientY-t.top-i)/o*2+1,button:e.button}}}function fe(e){if(this.enabled)switch(e.pointerType){case`mouse`:case`pen`:this.pointerHover(this._getPointer(e))}}function pe(e){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(e.pointerId),this.domElement.addEventListener(`pointermove`,this._onPointerMove),this.pointerHover(this._getPointer(e)),this.pointerDown(this._getPointer(e)))}function me(e){this.enabled&&this.pointerMove(this._getPointer(e))}function he(e){this.enabled&&(this.domElement.releasePointerCapture(e.pointerId),this.domElement.removeEventListener(`pointermove`,this._onPointerMove),this.pointerUp(this._getPointer(e)))}function B(e,t,n){let r=t.intersectObject(e,!0);for(let e=0;e<r.length;e++)if(r[e].object.visible||n)return r[e];return!1}var V=new u,H=new l(0,1,0),ge=new l(0,0,0),_e=new v,U=new c,W=new c,G=new l,K=new v,q=new l(1,0,0),J=new l(0,1,0),Y=new l(0,0,1),X=new l,Z=new l,Q=new l,ve=class extends d{constructor(e){super(),this.isTransformControlsRoot=!0,this.controls=e,this.visible=!1}updateMatrixWorld(e){let t=this.controls;t.object!==void 0&&(t.object.updateMatrixWorld(),t.object.parent===null?console.error(`TransformControls: The attached 3D object must be a part of the scene graph.`):t.object.parent.matrixWorld.decompose(t._parentPosition,t._parentQuaternion,t._parentScale),t.object.matrixWorld.decompose(t.worldPosition,t.worldQuaternion,t._worldScale),t._parentQuaternionInv.copy(t._parentQuaternion).invert(),t._worldQuaternionInv.copy(t.worldQuaternion).invert()),t.camera.updateMatrixWorld(),t.camera.matrixWorld.decompose(t.cameraPosition,t.cameraQuaternion,t._cameraScale),t.camera.isOrthographicCamera?t.camera.getWorldDirection(t.eye).negate():t.eye.copy(t.cameraPosition).sub(t.worldPosition).normalize(),this.parent&&(K.copy(this.parent.matrixWorld).invert(),K.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(e)}dispose(){this.traverse(function(e){e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose()})}},ye=class extends d{constructor(){super(),this.isTransformControlsGizmo=!0,this.type=`TransformControlsGizmo`;let e=new m({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),t=new te({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),i=e.clone();i.opacity=.15;let o=t.clone();o.opacity=.5;let s=e.clone();s.color.setHex(16711680);let c=e.clone();c.color.setHex(65280);let l=e.clone();l.color.setHex(255);let u=e.clone();u.color.setHex(16711680),u.opacity=.5;let f=e.clone();f.color.setHex(65280),f.opacity=.5;let p=e.clone();p.color.setHex(255),p.opacity=.5;let g=e.clone();g.opacity=.25;let _=e.clone();_.color.setHex(16776960),_.opacity=.25;let v=e.clone();v.color.setHex(16776960);let y=e.clone();y.color.setHex(7895160),this.materialLib={xAxis:s,yAxis:c,zAxis:l,active:v,xAxisTransparent:u,yAxisTransparent:f,zAxisTransparent:p,activeTransparent:_};let b=new h(0,.04,.1,12);b.translate(0,.05,0);let S=new E(.08,.08,.08);S.translate(0,.04,0);let C=new x;C.setAttribute(`position`,new a([0,0,0,1,0,0],3));let T=new h(.0075,.0075,.5,3);T.translate(0,.25,0);function D(e,t){let r=new n(e,.0075,3,64,t*Math.PI*2);return r.rotateY(Math.PI/2),r.rotateX(Math.PI/2),r}function O(){let e=new x;return e.setAttribute(`position`,new a([0,0,0,1,1,1],3)),e}let ne={X:[[new A(b,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(b,s),[-.5,0,0],[0,0,Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new A(b,c),[0,.5,0]],[new A(b,c),[0,-.5,0],[Math.PI,0,0]],[new A(T,c)]],Z:[[new A(b,l),[0,0,.5],[Math.PI/2,0,0]],[new A(b,l),[0,0,-.5],[-Math.PI/2,0,0]],[new A(T,l),null,[Math.PI/2,0,0]]],XYZ:[[new A(new r(.1,0),g),[0,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]]},k={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new A(new r(.2,0),i)]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]]},re={START:[[new A(new r(.01,2),o),null,null,null,`helper`]],END:[[new A(new r(.01,2),o),null,null,null,`helper`]],DELTA:[[new w(O(),o),null,null,null,`helper`]],X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]},ie={XYZE:[[new A(D(.5,1),y),null,[0,Math.PI/2,0]]],X:[[new A(D(.5,.5),s)]],Y:[[new A(D(.5,.5),c),null,[0,0,-Math.PI/2]]],Z:[[new A(D(.5,.5),l),null,[0,Math.PI/2,0]]],E:[[new A(D(.75,1),_),null,[0,Math.PI/2,0]]]},ae={AXIS:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]]},j={XYZE:[[new A(new ee(.25,10,8),i)]],X:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new A(new n(.5,.1,4,24),i),[0,0,0],[Math.PI/2,0,0]]],Z:[[new A(new n(.5,.1,4,24),i),[0,0,0],[0,0,-Math.PI/2]]],E:[[new A(new n(.75,.1,2,24),i)]]},M={X:[[new A(S,s),[.5,0,0],[0,0,-Math.PI/2]],[new A(T,s),[0,0,0],[0,0,-Math.PI/2]],[new A(S,s),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new A(S,c),[0,.5,0]],[new A(T,c)],[new A(S,c),[0,-.5,0],[0,0,Math.PI]]],Z:[[new A(S,l),[0,0,.5],[Math.PI/2,0,0]],[new A(T,l),[0,0,0],[Math.PI/2,0,0]],[new A(S,l),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new A(new E(.15,.15,.01),p),[.15,.15,0]]],YZ:[[new A(new E(.15,.15,.01),u),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.15,.15,.01),f),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.1,.1,.1),g)]]},N={X:[[new A(new h(.2,0,.6,4),i),[.3,0,0],[0,0,-Math.PI/2]],[new A(new h(.2,0,.6,4),i),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new A(new h(.2,0,.6,4),i),[0,.3,0]],[new A(new h(.2,0,.6,4),i),[0,-.3,0],[0,0,Math.PI]]],Z:[[new A(new h(.2,0,.6,4),i),[0,0,.3],[Math.PI/2,0,0]],[new A(new h(.2,0,.6,4),i),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new A(new E(.2,.2,.01),i),[.15,.15,0]]],YZ:[[new A(new E(.2,.2,.01),i),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new A(new E(.2,.2,.01),i),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new A(new E(.2,.2,.2),i),[0,0,0]]]},oe={X:[[new w(C,o),[-1e3,0,0],null,[1e6,1,1],`helper`]],Y:[[new w(C,o),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],`helper`]],Z:[[new w(C,o),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],`helper`]]};function P(e){let t=new d;for(let n in e)for(let r=e[n].length;r--;){let i=e[n][r][0].clone(),a=e[n][r][1],o=e[n][r][2],s=e[n][r][3],c=e[n][r][4];i.name=n,i.tag=c,a&&i.position.set(a[0],a[1],a[2]),o&&i.rotation.set(o[0],o[1],o[2]),s&&i.scale.set(s[0],s[1],s[2]),i.updateMatrix();let l=i.geometry.clone();l.applyMatrix4(i.matrix),i.geometry=l,i.renderOrder=1/0,i.position.set(0,0,0),i.rotation.set(0,0,0),i.scale.set(1,1,1),t.add(i)}return t}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=P(ne)),this.add(this.gizmo.rotate=P(ie)),this.add(this.gizmo.scale=P(M)),this.add(this.picker.translate=P(k)),this.add(this.picker.rotate=P(j)),this.add(this.picker.scale=P(N)),this.add(this.helper.translate=P(re)),this.add(this.helper.rotate=P(ae)),this.add(this.helper.scale=P(oe)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(e){let t=(this.mode===`scale`?`local`:this.space)===`local`?this.worldQuaternion:W;this.gizmo.translate.visible=this.mode===`translate`,this.gizmo.rotate.visible=this.mode===`rotate`,this.gizmo.scale.visible=this.mode===`scale`,this.helper.translate.visible=this.mode===`translate`,this.helper.rotate.visible=this.mode===`rotate`,this.helper.scale.visible=this.mode===`scale`;let n=[];n=n.concat(this.picker[this.mode].children),n=n.concat(this.gizmo[this.mode].children),n=n.concat(this.helper[this.mode].children);for(let e=0;e<n.length;e++){let r=n[e];r.visible=!0,r.rotation.set(0,0,0),r.position.copy(this.worldPosition);let i;if(i=this.camera.isOrthographicCamera?(this.camera.top-this.camera.bottom)/this.camera.zoom:this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),r.scale.set(1,1,1).multiplyScalar(i*this.size/4),r.tag===`helper`)r.visible=!1,r.name===`AXIS`?(r.visible=!!this.axis,this.axis===`X`&&(L.setFromEuler(V.set(0,0,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Y`&&(L.setFromEuler(V.set(0,0,Math.PI/2)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Z`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),r.quaternion.copy(t).multiply(L),Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`XYZE`&&(L.setFromEuler(V.set(0,Math.PI/2,0)),H.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(_e.lookAt(ge,H,J)),r.quaternion.multiply(L),r.visible=this.dragging),this.axis===`E`&&(r.visible=!1)):r.name===`START`?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):r.name===`END`?(r.position.copy(this.worldPosition),r.visible=this.dragging):r.name===`DELTA`?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),F.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),F.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(F),r.visible=this.dragging):(r.quaternion.copy(t),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=this.axis.search(r.name)!==-1));else{if(r.quaternion.copy(t),this.mode===`translate`||this.mode===`scale`){let e=.99,n=.2;r.name===`X`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Y`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Z`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XY`&&Math.abs(H.copy(Y).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`YZ`&&Math.abs(H.copy(q).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XZ`&&Math.abs(H.copy(J).applyQuaternion(t).dot(this.eye))<n&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1)}else this.mode===`rotate`&&(U.copy(t),H.copy(this.eye).applyQuaternion(L.copy(t).invert()),r.name.search(`E`)!==-1&&r.quaternion.setFromRotationMatrix(_e.lookAt(this.eye,ge,J)),r.name===`X`&&(L.setFromAxisAngle(q,Math.atan2(-H.y,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Y`&&(L.setFromAxisAngle(J,Math.atan2(H.x,H.z)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)),r.name===`Z`&&(L.setFromAxisAngle(Y,Math.atan2(H.y,H.x)),L.multiplyQuaternions(U,L),r.quaternion.copy(L)));r.visible=r.visible&&(r.name.indexOf(`X`)===-1||this.showX),r.visible=r.visible&&(r.name.indexOf(`Y`)===-1||this.showY),r.visible=r.visible&&(r.name.indexOf(`Z`)===-1||this.showZ),r.visible=r.visible&&(r.name.indexOf(`E`)===-1||this.showX&&this.showY&&this.showZ),r.visible=r.visible&&(r.name.indexOf(`XY`)===-1||this.showXY),r.visible=r.visible&&(r.name.indexOf(`YZ`)===-1||this.showYZ),r.visible=r.visible&&(r.name.indexOf(`XZ`)===-1||this.showXZ),r.visible=r.visible&&(r.name!==`E`||this.showE),r.visible=r.visible&&(r.name!==`XYZE`||this.showXYZE),r.material._color=r.material._color||r.material.color.clone(),r.material._opacity=r.material._opacity||r.material.opacity,r.material.color.copy(r.material._color),r.material.opacity=r.material._opacity,this.enabled&&this.axis&&(r.name===this.axis||this.axis.split(``).some(function(e){return r.name===e}))&&(r.material.color.copy(this.materialLib.active.color),r.material.opacity=1)}}super.updateMatrixWorld(e)}},be=class extends A{constructor(){super(new t(1e5,1e5,2,2),new m({visible:!1,wireframe:!0,side:2,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type=`TransformControlsPlane`}updateMatrixWorld(e){let t=this.space;switch(this.position.copy(this.worldPosition),this.mode===`scale`&&(t=`local`),X.copy(q).applyQuaternion(t===`local`?this.worldQuaternion:W),Z.copy(J).applyQuaternion(t===`local`?this.worldQuaternion:W),Q.copy(Y).applyQuaternion(t===`local`?this.worldQuaternion:W),H.copy(Z),this.mode){case`translate`:case`scale`:switch(this.axis){case`X`:H.copy(this.eye).cross(X),G.copy(X).cross(H);break;case`Y`:H.copy(this.eye).cross(Z),G.copy(Z).cross(H);break;case`Z`:H.copy(this.eye).cross(Q),G.copy(Q).cross(H);break;case`XY`:G.copy(Q);break;case`YZ`:G.copy(X);break;case`XZ`:H.copy(Q),G.copy(Z);break;case`XYZ`:case`E`:G.set(0,0,0)}break;default:G.set(0,0,0)}G.length()===0?this.quaternion.copy(this.cameraQuaternion):(K.lookAt(F.set(0,0,0),G,H),this.quaternion.setFromRotationMatrix(K)),super.updateMatrixWorld(e)}},xe=`
2
2
  varying vec3 vWorld;
3
3
  void main() {
4
4
  vec4 w = modelMatrix * vec4(position, 1.0);
@@ -1,5 +1,5 @@
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)=>`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./physicsHost-DNdZ7AsT.js","./camera-DT0xHipx.js","./three.module-CnI50X0U.js","./index-DVTzVcBD.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-DT0xHipx.js";import{S as c,h as l}from"./index-DVTzVcBD.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-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};
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-DNdZ7AsT.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-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;
1
+ import{c as e,i as t}from"./runtime-CMAP4azF.js";import{t as n}from"./params-gVpEEiSK.js";import{a as r,c as i,l as a,o,u as s}from"./camera-DT0xHipx.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;