stack3js 0.2.0 → 0.6.5

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 (74) hide show
  1. package/COMMAND.md +147 -0
  2. package/README.md +171 -4
  3. package/bin/stack3.mjs +1445 -186
  4. package/blender/import_stack.py +89 -0
  5. package/meshing/blocks.py +82 -0
  6. package/meshing/branches.py +62 -0
  7. package/meshing/dexel.py +67 -0
  8. package/meshing/field_data.py +19 -0
  9. package/meshing/finish_blender.py +203 -0
  10. package/meshing/finishing.py +155 -0
  11. package/meshing/geometry.py +71 -0
  12. package/meshing/guided.py +150 -0
  13. package/meshing/implicit.py +178 -0
  14. package/meshing/intersection.py +33 -0
  15. package/meshing/material.py +115 -0
  16. package/meshing/mesh.py +103 -0
  17. package/meshing/network.py +136 -0
  18. package/meshing/regularization.py +213 -0
  19. package/meshing/sections.py +165 -0
  20. package/meshing/signed_distance.py +93 -0
  21. package/package.json +9 -2
  22. package/references/hard-surface/README.md +40 -0
  23. package/references/hard-surface/atlas/concrete-barrier-4view.png +0 -0
  24. package/references/hard-surface/atlas/preview.pipeline.yaml +14 -0
  25. package/references/hard-surface/case-studies/benchmark/README.md +22 -0
  26. package/references/hard-surface/case-studies/benchmark/lod-bevel.pipeline.yaml +258 -0
  27. package/references/hard-surface/finishing/exports.yaml +10 -0
  28. package/references/hard-surface/finishing/finish-lod.pipeline.yaml +33 -0
  29. package/references/hard-surface/finishing/inputs/stack/stack.json +1 -0
  30. package/references/hard-surface/finishing/inputs/stack/stack.png +0 -0
  31. package/references/hard-surface/finishing/regularize.pipeline.yaml +46 -0
  32. package/references/hard-surface/measured-depth/sdf/compare.pipeline.yaml +12 -0
  33. package/references/hard-surface/measured-depth/sdf/inputs/field.npy +0 -0
  34. package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.json +1 -0
  35. package/references/hard-surface/measured-depth/sdf/inputs/stack/stack.png +0 -0
  36. package/references/hard-surface/measured-depth/sdf/inputs/truth.json +1 -0
  37. package/references/hard-surface/measured-depth/sdf/sdf.guide.json +3 -0
  38. package/references/hard-surface/measured-depth/triple-dexel/compare.pipeline.yaml +12 -0
  39. package/references/hard-surface/measured-depth/triple-dexel/dexel.guide.json +3 -0
  40. package/references/hard-surface/measured-depth/triple-dexel/inputs/fixture.json +22 -0
  41. package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.json +22 -0
  42. package/references/hard-surface/measured-depth/triple-dexel/inputs/stack/stack.png +0 -0
  43. package/references/hard-surface/measured-depth/triple-dexel/inputs/triple-dexel.npz +0 -0
  44. package/references/hard-surface/schema/pipeline-fragment.schema.json +5 -0
  45. package/references/hard-surface/schema/pipeline.schema.json +181 -0
  46. package/schema/pipeline-fragment.schema.json +5 -0
  47. package/schema/pipeline.schema.json +181 -0
  48. package/verification/acceptance.py +85 -0
  49. package/verification/assembly.py +96 -0
  50. package/verification/landmarks.py +53 -0
  51. package/verification/panels.py +147 -0
  52. package/verification/projections.py +135 -0
  53. package/verification/verify.py +115 -0
  54. package/viewer/dist/assets/{GLTFExporter--hziUXc8.js → GLTFExporter-xdVCArY-.js} +1 -1
  55. package/viewer/dist/assets/compare-Du4RoRQO.js +6 -0
  56. package/viewer/dist/assets/compare.worker-CgJq-znx.js +21 -0
  57. package/viewer/dist/assets/presets-jXE0t1fU.js +1 -0
  58. package/viewer/dist/assets/preview-cache-BKV0EZl9.js +1 -0
  59. package/viewer/dist/assets/project-DtHHhfo-.js +17 -0
  60. package/viewer/dist/assets/reconstruct.worker-ONc9GyFO.js +21 -0
  61. package/viewer/dist/assets/{script-engine-CLj7QMLe.js → script-engine-Bs3azDYZ.js} +1 -1
  62. package/viewer/dist/assets/style-D6eZHs3D.js +4004 -0
  63. package/viewer/dist/assets/viewer-DIjS0No7.js +2 -0
  64. package/viewer/dist/compare.html +4 -4
  65. package/viewer/dist/index.html +9 -8
  66. package/viewer/dist/project.html +3 -3
  67. package/viewer/dist/assets/compare-DJ8rV3Rn.js +0 -6
  68. package/viewer/dist/assets/compare.worker-DK2lJl0n.js +0 -21
  69. package/viewer/dist/assets/presets-DwdZVYhs.js +0 -1
  70. package/viewer/dist/assets/preview-cache-DRF_H5pq.js +0 -58
  71. package/viewer/dist/assets/project-D8tR6U-_.js +0 -17
  72. package/viewer/dist/assets/reconstruct.worker-Cf8iZwT3.js +0 -21
  73. package/viewer/dist/assets/style-CWGgpweN.js +0 -3947
  74. package/viewer/dist/assets/viewer-CyGodHLY.js +0 -2
@@ -1,58 +0,0 @@
1
- import{aw as an,V as Y,ax as ht,ay as rt,Q as me,as as pe,E as q,az as on,aA as rn,b as hn,aB as we,aC as Le,M as ln,aD as cn,a6 as un,aE as fn,g as An,al as dn}from"./style-CWGgpweN.js";const gn="modulepreload",mn=function(n,t){return new URL(n,t).href},Ce={},rs=function(t,e,s){let i=Promise.resolve();if(e&&e.length>0){let c=function(o){return Promise.all(o.map(u=>Promise.resolve(u).then(A=>({status:"fulfilled",value:A}),A=>({status:"rejected",reason:A}))))};const r=document.getElementsByTagName("link"),h=document.querySelector("meta[property=csp-nonce]"),l=h?.nonce||h?.getAttribute("nonce");i=c(e.map(o=>{if(o=mn(o,s),o in Ce)return;Ce[o]=!0;const u=o.endsWith(".css"),A=u?'[rel="stylesheet"]':"";if(s)for(let g=r.length-1;g>=0;g--){const p=r[g];if(p.href===o&&(!u||p.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${o}"]${A}`))return;const f=document.createElement("link");if(f.rel=u?"stylesheet":gn,u||(f.as="script"),f.crossOrigin="",f.href=o,l&&f.setAttribute("nonce",l),document.head.appendChild(f),u)return new Promise((g,p)=>{f.addEventListener("load",g),f.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${o}`)))})}))}function a(r){const h=new Event("vite:preloadError",{cancelable:!0});if(h.payload=r,window.dispatchEvent(h),!h.defaultPrevented)throw r}return i.then(r=>{for(const h of r||[])h.status==="rejected"&&a(h.reason);return t().catch(a)})},ye={type:"change"},$t={type:"start"},Ue={type:"end"},xt=new on,ve=new rn,pn=Math.cos(70*hn.DEG2RAD),K=new Y,W=2*Math.PI,D={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Ht=1e-6;class hs extends an{constructor(t,e=null){super(t,e),this.state=D.NONE,this.target=new Y,this.cursor=new Y,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:ht.ROTATE,MIDDLE:ht.DOLLY,RIGHT:ht.PAN},this.touches={ONE:rt.ROTATE,TWO:rt.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new Y,this._lastQuaternion=new me,this._lastTargetPosition=new Y,this._quat=new me().setFromUnitVectors(t.up,new Y(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new pe,this._sphericalDelta=new pe,this._scale=1,this._panOffset=new Y,this._rotateStart=new q,this._rotateEnd=new q,this._rotateDelta=new q,this._panStart=new q,this._panEnd=new q,this._panDelta=new q,this._dollyStart=new q,this._dollyEnd=new q,this._dollyDelta=new q,this._dollyDirection=new Y,this._mouse=new q,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Cn.bind(this),this._onPointerDown=wn.bind(this),this._onPointerUp=yn.bind(this),this._onContextMenu=xn.bind(this),this._onMouseWheel=_n.bind(this),this._onKeyDown=Mn.bind(this),this._onTouchStart=En.bind(this),this._onTouchMove=bn.bind(this),this._onMouseDown=vn.bind(this),this._onMouseMove=Bn.bind(this),this._interceptControlDown=Qn.bind(this),this._interceptControlUp=Dn.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(t){super.connect(t),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(ye),this.update(),this.state=D.NONE}update(t=null){const e=this.object.position;K.copy(e).sub(this.target),K.applyQuaternion(this._quat),this._spherical.setFromVector3(K),this.autoRotate&&this.state===D.NONE&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let s=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(s)&&isFinite(i)&&(s<-Math.PI?s+=W:s>Math.PI&&(s-=W),i<-Math.PI?i+=W:i>Math.PI&&(i-=W),s<=i?this._spherical.theta=Math.max(s,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(s+i)/2?Math.max(s,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let a=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const r=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),a=r!=this._spherical.radius}if(K.setFromSpherical(this._spherical),K.applyQuaternion(this._quatInverse),e.copy(this.target).add(K),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let r=null;if(this.object.isPerspectiveCamera){const h=K.length();r=this._clampDistance(h*this._scale);const l=h-r;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),a=!!l}else if(this.object.isOrthographicCamera){const h=new Y(this._mouse.x,this._mouse.y,0);h.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),a=l!==this.object.zoom;const c=new Y(this._mouse.x,this._mouse.y,0);c.unproject(this.object),this.object.position.sub(c).add(h),this.object.updateMatrixWorld(),r=K.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;r!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(r).add(this.object.position):(xt.origin.copy(this.object.position),xt.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(xt.direction))<pn?this.object.lookAt(this.target):(ve.setFromNormalAndCoplanarPoint(this.object.up,this.target),xt.intersectPlane(ve,this.target))))}else if(this.object.isOrthographicCamera){const r=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),r!==this.object.zoom&&(this.object.updateProjectionMatrix(),a=!0)}return this._scale=1,this._performCursorZoom=!1,a||this._lastPosition.distanceToSquared(this.object.position)>Ht||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Ht||this._lastTargetPosition.distanceToSquared(this.target)>Ht?(this.dispatchEvent(ye),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(t){return t!==null?W/60*this.autoRotateSpeed*t:W/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(t*.01);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){K.setFromMatrixColumn(e,0),K.multiplyScalar(-t),this._panOffset.add(K)}_panUp(t,e){this.screenSpacePanning===!0?K.setFromMatrixColumn(e,1):(K.setFromMatrixColumn(e,0),K.crossVectors(this.object.up,K)),K.multiplyScalar(t),this._panOffset.add(K)}_pan(t,e){const s=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;K.copy(i).sub(this.target);let a=K.length();a*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*a/s.clientHeight,this.object.matrix),this._panUp(2*e*a/s.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/s.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/s.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const s=this.domElement.getBoundingClientRect(),i=t-s.left,a=e-s.top,r=s.width,h=s.height;this._mouse.x=i/r*2-1,this._mouse.y=-(a/h)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(W*this._rotateDelta.x/e.clientHeight),this._rotateUp(W*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(W*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(-W*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(W*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(-W*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),e=!0;break}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(this._pointers.length===1)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._rotateStart.set(s,i)}}_handleTouchStartPan(t){if(this._pointers.length===1)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panStart.set(s,i)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,i=t.pageY-e.y,a=Math.sqrt(s*s+i*i);this._dollyStart.set(0,a)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(this._pointers.length==1)this._rotateEnd.set(t.pageX,t.pageY);else{const s=this._getSecondPointerPosition(t),i=.5*(t.pageX+s.x),a=.5*(t.pageY+s.y);this._rotateEnd.set(i,a)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(W*this._rotateDelta.x/e.clientHeight),this._rotateUp(W*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(this._pointers.length===1)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),s=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panEnd.set(s,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),s=t.pageX-e.x,i=t.pageY-e.y,a=Math.sqrt(s*s+i*i);this._dollyEnd.set(0,a),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const r=(t.pageX+e.x)*.5,h=(t.pageY+e.y)*.5;this._updateZoomParameters(r,h)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId){this._pointers.splice(e,1);return}}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];e===void 0&&(e=new q,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,s={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:s.deltaY*=16;break;case 2:s.deltaY*=100;break}return t.ctrlKey&&!this._controlActive&&(s.deltaY*=10),s}}function wn(n){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(n.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(n)&&(this._addPointer(n),n.pointerType==="touch"?this._onTouchStart(n):this._onMouseDown(n)))}function Cn(n){this.enabled!==!1&&(n.pointerType==="touch"?this._onTouchMove(n):this._onMouseMove(n))}function yn(n){switch(this._removePointer(n),this._pointers.length){case 0:this.domElement.releasePointerCapture(n.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Ue),this.state=D.NONE;break;case 1:const t=this._pointers[0],e=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:e.x,pageY:e.y});break}}function vn(n){let t;switch(n.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=-1}switch(t){case ht.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(n),this.state=D.DOLLY;break;case ht.ROTATE:if(n.ctrlKey||n.metaKey||n.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(n),this.state=D.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(n),this.state=D.ROTATE}break;case ht.PAN:if(n.ctrlKey||n.metaKey||n.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(n),this.state=D.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(n),this.state=D.PAN}break;default:this.state=D.NONE}this.state!==D.NONE&&this.dispatchEvent($t)}function Bn(n){switch(this.state){case D.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(n);break;case D.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(n);break;case D.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(n);break}}function _n(n){this.enabled===!1||this.enableZoom===!1||this.state!==D.NONE||(n.preventDefault(),this.dispatchEvent($t),this._handleMouseWheel(this._customWheelEvent(n)),this.dispatchEvent(Ue))}function Mn(n){this.enabled!==!1&&this._handleKeyDown(n)}function En(n){switch(this._trackPointer(n),this._pointers.length){case 1:switch(this.touches.ONE){case rt.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(n),this.state=D.TOUCH_ROTATE;break;case rt.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(n),this.state=D.TOUCH_PAN;break;default:this.state=D.NONE}break;case 2:switch(this.touches.TWO){case rt.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(n),this.state=D.TOUCH_DOLLY_PAN;break;case rt.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(n),this.state=D.TOUCH_DOLLY_ROTATE;break;default:this.state=D.NONE}break;default:this.state=D.NONE}this.state!==D.NONE&&this.dispatchEvent($t)}function bn(n){switch(this._trackPointer(n),this.state){case D.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(n),this.update();break;case D.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(n),this.update();break;case D.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(n),this.update();break;case D.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(n),this.update();break;default:this.state=D.NONE}}function xn(n){this.enabled!==!1&&n.preventDefault()}function Qn(n){n.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Dn(n){n.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}const zt=["top","left","front","rear","right","bottom"];function ls(n){const t=[137,80,78,71,13,10,26,10];if(n.length<33||t.some((a,r)=>n[r]!==a)||String.fromCharCode(...n.subarray(12,16))!=="IHDR")throw new Error("Expected a PNG image.");const e=new DataView(n.buffer,n.byteOffset,n.byteLength),s=e.getUint32(16),i=e.getUint32(20);if(!s||!i||s>8192||i>8192||s*i>16e6)throw new Error("PNG dimensions exceed the 8192 px or 16 MP input limit.");return{width:s,height:i}}function Be(n){const t=n.split(",").map(e=>e.trim());if(t.some(e=>!zt.includes(e)))throw new Error("Use directions top, left, front, rear, right, and bottom.");if(t.length!==4&&t.length!==6||new Set(t).size!==t.length||zt.slice(0,t.length).some(e=>!t.includes(e)))throw new Error("A layout needs the four required directions or all six, with no duplicates.");return t}var Kt={exports:{}},_e;function In(){return _e||(_e=1,(function(n){(function(){function t(h,l){var c=h.x-l.x,o=h.y-l.y;return c*c+o*o}function e(h,l,c){var o=l.x,u=l.y,A=c.x-o,f=c.y-u;if(A!==0||f!==0){var g=((h.x-o)*A+(h.y-u)*f)/(A*A+f*f);g>1?(o=c.x,u=c.y):g>0&&(o+=A*g,u+=f*g)}return A=h.x-o,f=h.y-u,A*A+f*f}function s(h,l){for(var c=h[0],o=[c],u,A=1,f=h.length;A<f;A++)u=h[A],t(u,c)>l&&(o.push(u),c=u);return c!==u&&o.push(u),o}function i(h,l,c,o,u){for(var A=o,f,g=l+1;g<c;g++){var p=e(h[g],h[l],h[c]);p>A&&(f=g,A=p)}A>o&&(f-l>1&&i(h,l,f,o,u),u.push(h[f]),c-f>1&&i(h,f,c,o,u))}function a(h,l){var c=h.length-1,o=[h[0]];return i(h,0,c,l,o),o.push(h[c]),o}function r(h,l,c){if(h.length<=2)return h;var o=l!==void 0?l*l:1;return h=c?h:s(h,o),h=a(h,o),h}n.exports=r,n.exports.default=r})()})(Kt)),Kt.exports}In();Int8Array.from(atob("/////////////////////wAIA/////////////////8AAQn/////////////////AQgDCQgB/////////////wECCv////////////////8ACAMBAgr/////////////CQIKAAIJ/////////////wIIAwIKCAoJCP////////8DCwL/////////////////AAsCCAsA/////////////wEJAAIDC/////////////8BCwIBCQsJCAv/////////AwoBCwoD/////////////wAKAQAICggLCv////////8DCQADCwkLCgn/////////CQgKCggL/////////////wQHCP////////////////8EAwAHAwT/////////////AAEJCAQH/////////////wQBCQQHAQcDAf////////8BAgoIBAf/////////////AwQHAwAEAQIK/////////wkCCgkAAggEB/////////8CCgkCCQcCBwMHCQT/////CAQHAwsC/////////////wsEBwsCBAIABP////////8JAAEIBAcCAwv/////////BAcLCQQLCQsCCQIB/////wMKAQMLCgcIBP////////8BCwoBBAsBAAQHCwT/////BAcICQALCQsKCwAD/////wQHCwQLCQkLCv////////8JBQT/////////////////CQUEAAgD/////////////wAFBAEFAP////////////8IBQQIAwUDAQX/////////AQIKCQUE/////////////wMACAECCgQJBf////////8FAgoFBAIEAAL/////////AgoFAwIFAwUEAwQI/////wkFBAIDC/////////////8ACwIACAsECQX/////////AAUEAAEFAgML/////////wIBBQIFCAIICwQIBf////8KAwsKAQMJBQT/////////BAkFAAgBCAoBCAsK/////wUEAAUACwULCgsAA/////8FBAgFCAoKCAv/////////CQcIBQcJ/////////////wkDAAkFAwUHA/////////8ABwgAAQcBBQf/////////AQUDAwUH/////////////wkHCAkFBwoBAv////////8KAQIJBQAFAwAFBwP/////CAACCAIFCAUHCgUC/////wIKBQIFAwMFB/////////8HCQUHCAkDCwL/////////CQUHCQcCCQIAAgcL/////wIDCwABCAEHCAEFB/////8LAgELAQcHAQX/////////CQUICAUHCgEDCgML/////wUHAAUACQcLAAEACgsKAP8LCgALAAMKBQAIAAcFBwD/CwoFBwsF/////////////woGBf////////////////8ACAMFCgb/////////////CQABBQoG/////////////wEIAwEJCAUKBv////////8BBgUCBgH/////////////AQYFAQIGAwAI/////////wkGBQkABgACBv////////8FCQgFCAIFAgYDAgj/////AgMLCgYF/////////////wsACAsCAAoGBf////////8AAQkCAwsFCgb/////////BQoGAQkCCQsCCQgL/////wYDCwYFAwUBA/////////8ACAsACwUABQEFCwb/////AwsGAAMGAAYFAAUJ/////wYFCQYJCwsJCP////////8FCgYEBwj/////////////BAMABAcDBgUK/////////wEJAAUKBggEB/////////8KBgUBCQcBBwMHCQT/////BgECBgUBBAcI/////////wECBQUCBgMABAMEB/////8IBAcJAAUABgUAAgb/////BwMJBwkEAwIJBQkGAgYJ/wMLAgcIBAoGBf////////8FCgYEBwIEAgACBwv/////AAEJBAcIAgMLBQoG/////wkCAQkLAgkECwcLBAUKBv8IBAcDCwUDBQEFCwb/////BQELBQsGAQALBwsEAAQL/wAFCQAGBQADBgsGAwgEB/8GBQkGCQsEBwkHCwn/////CgQJBgQK/////////////wQKBgQJCgAIA/////////8KAAEKBgAGBAD/////////CAMBCAEGCAYEBgEK/////wEECQECBAIGBP////////8DAAgBAgkCBAkCBgT/////AAIEBAIG/////////////wgDAggCBAQCBv////////8KBAkKBgQLAgP/////////AAgCAggLBAkKBAoG/////wMLAgABBgAGBAYBCv////8GBAEGAQoECAECAQsICwH/CQYECQMGCQEDCwYD/////wgLAQgBAAsGAQkBBAYEAf8DCwYDBgAABgT/////////BgQICwYI/////////////wcKBgcICggJCv////////8ABwMACgcACQoGBwr/////CgYHAQoHAQcIAQgA/////woGBwoHAQEHA/////////8BAgYBBggBCAkIBgf/////AgYJAgkBBgcJAAkDBwMJ/wcIAAcABgYAAv////////8HAwIGBwL/////////////AgMLCgYICggJCAYH/////wIABwIHCwAJBwYHCgkKB/8BCAABBwgBCgcGBwoCAwv/CwIBCwEHCgYBBgcB/////wgJBggGBwkBBgsGAwEDBv8ACQELBgf/////////////BwgABwAGAwsACwYA/////wcLBv////////////////8HBgv/////////////////AwAICwcG/////////////wABCQsHBv////////////8IAQkIAwELBwb/////////CgECBgsH/////////////wECCgMACAYLB/////////8CCQACCgkGCwf/////////BgsHAgoDCggDCgkI/////wcCAwYCB/////////////8HAAgHBgAGAgD/////////AgcGAgMHAAEJ/////////wEGAgEIBgEJCAgHBv////8KBwYKAQcBAwf/////////CgcGAQcKAQgHAQAI/////wADBwAHCgAKCQYKB/////8HBgoHCggICgn/////////BggECwgG/////////////wMGCwMABgAEBv////////8IBgsIBAYJAAH/////////CQQGCQYDCQMBCwMG/////wYIBAYLCAIKAf////////8BAgoDAAsABgsABAb/////BAsIBAYLAAIJAgoJ/////woJAwoDAgkEAwsDBgQGA/8IAgMIBAIEBgL/////////AAQCBAYC/////////////wEJAAIDBAIEBgQDCP////8BCQQBBAICBAb/////////CAEDCAYBCAQGBgoB/////woBAAoABgYABP////////8EBgMEAwgGCgMAAwkKCQP/CgkEBgoE/////////////wQJBQcGC/////////////8ACAMECQULBwb/////////BQABBQQABwYL/////////wsHBggDBAMFBAMBBf////8JBQQKAQIHBgv/////////BgsHAQIKAAgDBAkF/////wcGCwUECgQCCgQAAv////8DBAgDBQQDAgUKBQILBwb/BwIDBwYCBQQJ/////////wkFBAAIBgAGAgYIB/////8DBgIDBwYBBQAFBAD/////BgIIBggHAgEIBAgFAQUI/wkFBAoBBgEHBgEDB/////8BBgoBBwYBAAcIBwAJBQT/BAAKBAoFAAMKBgoHAwcK/wcGCgcKCAUECgQICv////8GCQUGCwkLCAn/////////AwYLAAYDAAUGAAkF/////wALCAAFCwABBQUGC/////8GCwMGAwUFAwH/////////AQIKCQULCQsICwUG/////wALAwAGCwAJBgUGCQECCv8LCAULBQYIAAUKBQIAAgX/BgsDBgMFAgoDCgUD/////wUICQUCCAUGAgMIAv////8JBQYJBgAABgL/////////AQUIAQgABQYIAwgCBgII/wEFBgIBBv////////////8BAwYBBgoDCAYFBgkICQb/CgEACgAGCQUABQYA/////wADCAUGCv////////////8KBQb/////////////////CwUKBwUL/////////////wsFCgsHBQgDAP////////8FCwcFCgsBCQD/////////CgcFCgsHCQgBCAMB/////wsBAgsHAQcFAf////////8ACAMBAgcBBwUHAgv/////CQcFCQIHCQACAgsH/////wcFAgcCCwUJAgMCCAkIAv8CBQoCAwUDBwX/////////CAIACAUCCAcFCgIF/////wkAAQUKAwUDBwMKAv////8JCAIJAgEIBwIKAgUHBQL/AQMFAwcF/////////////wAIBwAHAQEHBf////////8JAAMJAwUFAwf/////////CQgHBQkH/////////////wUIBAUKCAoLCP////////8FAAQFCwAFCgsLAwD/////AAEJCAQKCAoLCgQF/////woLBAoEBQsDBAkEAQMBBP8CBQECCAUCCwgEBQj/////AAQLAAsDBAULAgsBBQEL/wACBQAFCQILBQQFCAsIBf8JBAUCCwP/////////////AgUKAwUCAwQFAwgE/////wUKAgUCBAQCAP////////8DCgIDBQoDCAUEBQgAAQn/BQoCBQIEAQkCCQQC/////wgEBQgFAwMFAf////////8ABAUBAAX/////////////CAQFCAUDCQAFAAMF/////wkEBf////////////////8ECwcECQsJCgv/////////AAgDBAkHCQsHCQoL/////wEKCwELBAEEAAcEC/////8DAQQDBAgBCgQHBAsKCwT/BAsHCQsECQILCQEC/////wkHBAkLBwkBCwILAQAIA/8LBwQLBAICBAD/////////CwcECwQCCAMEAwIE/////wIJCgIHCQIDBwcECf////8JCgcJBwQKAgcIBwACAAf/AwcKAwoCBwQKAQoABAAK/wEKAggHBP////////////8ECQEEAQcHAQP/////////BAkBBAEHAAgBCAcB/////wQAAwcEA/////////////8ECAf/////////////////CQoICgsI/////////////wMACQMJCwsJCv////////8AAQoACggICgv/////////AwEKCwMK/////////////wECCwELCQkLCP////////8DAAkDCQsBAgkCCwn/////AAILCAAL/////////////wMCC/////////////////8CAwgCCAoKCAn/////////CQoCAAkC/////////////wIDCAIICgABCAEKCP////8BCgL/////////////////AQMICQEI/////////////wAJAf////////////////8AAwj//////////////////////////////////////w=="),n=>n.charCodeAt(0));var z=Uint8Array,V=Uint16Array,te=Int32Array,ee=new z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ne=new z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Me=new z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fe=function(n,t){for(var e=new V(31),s=0;s<31;++s)e[s]=t+=1<<n[s-1];for(var i=new te(e[30]),s=1;s<30;++s)for(var a=e[s];a<e[s+1];++a)i[a]=a-e[s]<<5|s;return{b:e,r:i}},Ye=Fe(ee,2),Sn=Ye.b,Gt=Ye.r;Sn[28]=258,Gt[258]=28;var Pn=Fe(ne,0),Ee=Pn.r,Jt=new V(32768);for(var P=0;P<32768;++P){var et=(P&43690)>>1|(P&21845)<<1;et=(et&52428)>>2|(et&13107)<<2,et=(et&61680)>>4|(et&3855)<<4,Jt[P]=((et&65280)>>8|(et&255)<<8)>>1}var mt=(function(n,t,e){for(var s=n.length,i=0,a=new V(t);i<s;++i)n[i]&&++a[n[i]-1];var r=new V(t);for(i=1;i<t;++i)r[i]=r[i-1]+a[i-1]<<1;var h;if(e){h=new V(1<<t);var l=15-t;for(i=0;i<s;++i)if(n[i])for(var c=i<<4|n[i],o=t-n[i],u=r[n[i]-1]++<<o,A=u|(1<<o)-1;u<=A;++u)h[Jt[u]>>l]=c}else for(h=new V(s),i=0;i<s;++i)n[i]&&(h[i]=Jt[r[n[i]-1]++]>>15-n[i]);return h}),at=new z(288);for(var P=0;P<144;++P)at[P]=8;for(var P=144;P<256;++P)at[P]=9;for(var P=256;P<280;++P)at[P]=7;for(var P=280;P<288;++P)at[P]=8;var Dt=new z(32);for(var P=0;P<32;++P)Dt[P]=5;var kn=mt(at,9,0),Tn=mt(Dt,5,0),He=function(n){return(n+7)/8|0},Ke=function(n,t,e){return(e==null||e>n.length)&&(e=n.length),new z(n.subarray(t,e))},Ln=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],It=function(n,t,e){var s=new Error(t||Ln[n]);if(s.code=n,Error.captureStackTrace&&Error.captureStackTrace(s,It),!e)throw s;return s},tt=function(n,t,e){e<<=t&7;var s=t/8|0;n[s]|=e,n[s+1]|=e>>8},dt=function(n,t,e){e<<=t&7;var s=t/8|0;n[s]|=e,n[s+1]|=e>>8,n[s+2]|=e>>16},Ot=function(n,t){for(var e=[],s=0;s<n.length;++s)n[s]&&e.push({s,f:n[s]});var i=e.length,a=e.slice();if(!i)return{t:Re,l:0};if(i==1){var r=new z(e[0].s+1);return r[e[0].s]=1,{t:r,l:1}}e.sort(function(x,Q){return x.f-Q.f}),e.push({s:-1,f:25001});var h=e[0],l=e[1],c=0,o=1,u=2;for(e[0]={s:-1,f:h.f+l.f,l:h,r:l};o!=i-1;)h=e[e[c].f<e[u].f?c++:u++],l=e[c!=o&&e[c].f<e[u].f?c++:u++],e[o++]={s:-1,f:h.f+l.f,l:h,r:l};for(var A=a[0].s,s=1;s<i;++s)a[s].s>A&&(A=a[s].s);var f=new V(A+1),g=Xt(e[o-1],f,0);if(g>t){var s=0,p=0,d=g-t,C=1<<d;for(a.sort(function(Q,b){return f[b.s]-f[Q.s]||Q.f-b.f});s<i;++s){var w=a[s].s;if(f[w]>t)p+=C-(1<<g-f[w]),f[w]=t;else break}for(p>>=d;p>0;){var m=a[s].s;f[m]<t?p-=1<<t-f[m]++-1:++s}for(;s>=0&&p;--s){var B=a[s].s;f[B]==t&&(--f[B],++p)}g=t}return{t:new z(f),l:g}},Xt=function(n,t,e){return n.s==-1?Math.max(Xt(n.l,t,e+1),Xt(n.r,t,e+1)):t[n.s]=e},be=function(n){for(var t=n.length;t&&!n[--t];);for(var e=new V(++t),s=0,i=n[0],a=1,r=function(l){e[s++]=l},h=1;h<=t;++h)if(n[h]==i&&h!=t)++a;else{if(!i&&a>2){for(;a>138;a-=138)r(32754);a>2&&(r(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(r(i),--a;a>6;a-=6)r(8304);a>2&&(r(a-3<<5|8208),a=0)}for(;a--;)r(i);a=1,i=n[h]}return{c:e.subarray(0,s),n:t}},gt=function(n,t){for(var e=0,s=0;s<t.length;++s)e+=n[s]*t[s];return e},Oe=function(n,t,e){var s=e.length,i=He(t+2);n[i]=s&255,n[i+1]=s>>8,n[i+2]=n[i]^255,n[i+3]=n[i+1]^255;for(var a=0;a<s;++a)n[i+a+4]=e[a];return(i+4+s)*8},xe=function(n,t,e,s,i,a,r,h,l,c,o){tt(t,o++,e),++i[256];for(var u=Ot(i,15),A=u.t,f=u.l,g=Ot(a,15),p=g.t,d=g.l,C=be(A),w=C.c,m=C.n,B=be(p),x=B.c,Q=B.n,b=new V(19),y=0;y<w.length;++y)++b[w[y]&31];for(var y=0;y<x.length;++y)++b[x[y]&31];for(var v=Ot(b,7),U=v.t,G=v.l,_=19;_>4&&!U[Me[_-1]];--_);var I=c+5<<3,M=gt(i,at)+gt(a,Dt)+r,T=gt(i,A)+gt(a,p)+r+14+3*_+gt(b,U)+2*b[16]+3*b[17]+7*b[18];if(l>=0&&I<=M&&I<=T)return Oe(t,o,n.subarray(l,l+c));var k,E,S,F;if(tt(t,o,1+(T<M)),o+=2,T<M){k=mt(A,f,0),E=A,S=mt(p,d,0),F=p;var Z=mt(U,G,0);tt(t,o,m-257),tt(t,o+5,Q-1),tt(t,o+10,_-4),o+=14;for(var y=0;y<_;++y)tt(t,o+3*y,U[Me[y]]);o+=3*_;for(var N=[w,x],R=0;R<2;++R)for(var j=N[R],y=0;y<j.length;++y){var H=j[y]&31;tt(t,o,Z[H]),o+=U[H],H>15&&(tt(t,o,j[y]>>5&127),o+=j[y]>>12)}}else k=kn,E=at,S=Tn,F=Dt;for(var y=0;y<h;++y){var L=s[y];if(L>255){var H=L>>18&31;dt(t,o,k[H+257]),o+=E[H+257],H>7&&(tt(t,o,L>>23&31),o+=ee[H]);var J=L&31;dt(t,o,S[J]),o+=F[J],J>3&&(dt(t,o,L>>5&8191),o+=ne[J])}else dt(t,o,k[L]),o+=E[L]}return dt(t,o,k[256]),o+E[256]},Un=new te([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Re=new z(0),Fn=function(n,t,e,s,i,a){var r=a.z||n.length,h=new z(s+r+5*(1+Math.ceil(r/7e3))+i),l=h.subarray(s,h.length-i),c=a.l,o=(a.r||0)&7;if(t){o&&(l[0]=a.r>>3);for(var u=Un[t-1],A=u>>13,f=u&8191,g=(1<<e)-1,p=a.p||new V(32768),d=a.h||new V(g+1),C=Math.ceil(e/3),w=2*C,m=function(nt){return(n[nt]^n[nt+1]<<C^n[nt+2]<<w)&g},B=new te(25e3),x=new V(288),Q=new V(32),b=0,y=0,v=a.i||0,U=0,G=a.w||0,_=0;v+2<r;++v){var I=m(v),M=v&32767,T=d[I];if(p[M]=T,d[I]=M,G<=v){var k=r-v;if((b>7e3||U>24576)&&(k>423||!c)){o=xe(n,l,0,B,x,Q,y,U,_,v-_,o),U=b=y=0,_=v;for(var E=0;E<286;++E)x[E]=0;for(var E=0;E<30;++E)Q[E]=0}var S=2,F=0,Z=f,N=M-T&32767;if(k>2&&I==m(v-N))for(var R=Math.min(A,k)-1,j=Math.min(32767,v),H=Math.min(258,k);N<=j&&--Z&&M!=T;){if(n[v+S]==n[v+S-N]){for(var L=0;L<H&&n[v+L]==n[v+L-N];++L);if(L>S){if(S=L,F=N,L>R)break;for(var J=Math.min(N,L-2),$=0,E=0;E<J;++E){var X=v-N+E&32767,pt=p[X],wt=X-pt&32767;wt>$&&($=wt,T=X)}}}M=T,T=p[M],N+=M-T&32767}if(F){B[U++]=268435456|Gt[S]<<18|Ee[F];var Ct=Gt[S]&31,yt=Ee[F]&31;y+=ee[Ct]+ne[yt],++x[257+Ct],++Q[yt],G=v+S,++b}else B[U++]=n[v],++x[n[v]]}}for(v=Math.max(v,G);v<r;++v)B[U++]=n[v],++x[n[v]];o=xe(n,l,c,B,x,Q,y,U,_,v-_,o),c||(a.r=o&7|l[o/8|0]<<3,o-=7,a.h=d,a.p=p,a.i=v,a.w=G)}else{for(var v=a.w||0;v<r+c;v+=65535){var lt=v+65535;lt>=r&&(l[o/8|0]=c,lt=r),o=Oe(l,o+1,n.subarray(v,lt))}a.i=r}return Ke(h,0,s+He(o)+i)},Yn=(function(){for(var n=new Int32Array(256),t=0;t<256;++t){for(var e=t,s=9;--s;)e=(e&1&&-306674912)^e>>>1;n[t]=e}return n})(),Hn=function(){var n=-1;return{p:function(t){for(var e=n,s=0;s<t.length;++s)e=Yn[e&255^t[s]]^e>>>8;n=e},d:function(){return~n}}},Ne=function(){var n=1,t=0;return{p:function(e){for(var s=n,i=t,a=e.length|0,r=0;r!=a;){for(var h=Math.min(r+2655,a);r<h;++r)i+=s+=e[r];s=(s&65535)+15*(s>>16),i=(i&65535)+15*(i>>16)}n=s,t=i},d:function(){return n%=65521,t%=65521,(n&255)<<24|(n&65280)<<8|(t&255)<<8|t>>8}}},je=function(n,t,e,s,i){if(!i&&(i={l:1},t.dictionary)){var a=t.dictionary.subarray(-32768),r=new z(a.length+n.length);r.set(a),r.set(n,a.length),n=r,i.w=a.length}return Fn(n,t.level==null?6:t.level,t.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(n.length)))*1.5):20:12+t.mem,e,s,i)},ze=function(n,t){var e={};for(var s in n)e[s]=n[s];for(var s in t)e[s]=t[s];return e},O=function(n,t,e){for(;e;++t)n[t]=e,e>>>=8},Kn=function(n,t){var e=t.level,s=e==0?0:e<6?1:e==9?3:2;if(n[0]=120,n[1]=s<<6|(t.dictionary&&32),n[1]|=31-(n[0]<<8|n[1])%31,t.dictionary){var i=Ne();i.p(t.dictionary),O(n,2,i.d())}};function On(n,t){return je(n,t||{},0,0)}function Rn(n,t){t||(t={});var e=Ne();e.p(n);var s=je(n,t,t.dictionary?6:2,4);return Kn(s,t),O(s,s.length-4,e.d()),s}var Ge=function(n,t,e,s){for(var i in n){var a=n[i],r=t+i,h=s;Array.isArray(a)&&(h=ze(s,a[1]),a=a[0]),ArrayBuffer.isView(a)?e[r]=[a,h]:(e[r+="/"]=[new z(0),h],Ge(a,r,e,s))}},Qe=typeof TextEncoder<"u"&&new TextEncoder,Nn=typeof TextDecoder<"u"&&new TextDecoder,jn=0;try{Nn.decode(Re,{stream:!0}),jn=1}catch{}function De(n,t){var e;if(Qe)return Qe.encode(n);for(var s=n.length,i=new z(n.length+(n.length>>1)),a=0,r=function(c){i[a++]=c},e=0;e<s;++e){if(a+5>i.length){var h=new z(a+8+(s-e<<1));h.set(i),i=h}var l=n.charCodeAt(e);l<128||t?r(l):l<2048?(r(192|l>>6),r(128|l&63)):l>55295&&l<57344?(l=65536+(l&1047552)|n.charCodeAt(++e)&1023,r(240|l>>18),r(128|l>>12&63),r(128|l>>6&63),r(128|l&63)):(r(224|l>>12),r(128|l>>6&63),r(128|l&63))}return Ke(i,0,a)}var Wt=function(n){var t=0;if(n)for(var e in n){var s=n[e].length;s>65535&&It(9),t+=s+4}return t},Ie=function(n,t,e,s,i,a,r,h){var l=s.length,c=e.extra,o=h&&h.length,u=Wt(c);O(n,t,r!=null?33639248:67324752),t+=4,r!=null&&(n[t++]=20,n[t++]=e.os),n[t]=20,t+=2,n[t++]=e.flag<<1|(a<0&&8),n[t++]=i&&8,n[t++]=e.compression&255,n[t++]=e.compression>>8;var A=new Date(e.mtime==null?Date.now():e.mtime),f=A.getFullYear()-1980;if((f<0||f>119)&&It(10),O(n,t,f<<25|A.getMonth()+1<<21|A.getDate()<<16|A.getHours()<<11|A.getMinutes()<<5|A.getSeconds()>>1),t+=4,a!=-1&&(O(n,t,e.crc),O(n,t+4,a<0?-a-2:a),O(n,t+8,e.size)),O(n,t+12,l),O(n,t+14,u),t+=16,r!=null&&(O(n,t,o),O(n,t+6,e.attrs),O(n,t+10,r),t+=14),n.set(s,t),t+=l,u)for(var g in c){var p=c[g],d=p.length;O(n,t,+g),O(n,t+2,d),n.set(p,t+4),t+=4+d}return o&&(n.set(h,t),t+=o),t},zn=function(n,t,e,s,i){O(n,t,101010256),O(n,t+8,e),O(n,t+10,e),O(n,t+12,s),O(n,t+16,i)};function Gn(n,t){t||(t={});var e={},s=[];Ge(n,"",e,t);var i=0,a=0;for(var r in e){var h=e[r],l=h[0],c=h[1],o=c.level==0?0:8,u=De(r),A=u.length,f=c.comment,g=f&&De(f),p=g&&g.length,d=Wt(c.extra);A>65535&&It(11);var C=o?On(l,c):l,w=C.length,m=Hn();m.p(l),s.push(ze(c,{size:l.length,crc:m.d(),c:C,f:u,m:g,u:A!=r.length||g&&f.length!=p,o:i,compression:o})),i+=30+A+d+w,a+=76+2*(A+d)+(p||0)+w}for(var B=new z(a+22),x=i,Q=a-i,b=0;b<s.length;++b){var u=s[b];Ie(B,u.o,u,u.f,u.u,u.c.length);var y=30+u.f.length+Wt(u.extra);B.set(u.c,u.o+y),Ie(B,i,u,u.f,u.u,u.c.length,u.o,u.m),i+=16+y+(u.m?u.m.length:0)}return zn(B,i,s.length,Q,x),B}const se=new TextEncoder;function Zt(n){const t=new Uint8Array(n.reduce((s,i)=>s+i.length,0));let e=0;for(const s of n)t.set(s,e),e+=s.length;return t}const Jn=Uint32Array.from({length:256},(n,t)=>{let e=t;for(let s=0;s<8;s++)e=e>>>1^(e&1?3988292384:0);return e});function Rt(n,t){const e=new Uint8Array(t.length+12),s=new DataView(e.buffer);s.setUint32(0,t.length),e.set(se.encode(n),4),e.set(t,8);let i=4294967295;for(let a=4;a<e.length-4;a++)i=i>>>8^Jn[(i^e[a])&255];return s.setUint32(e.length-4,i^4294967295),e}function Je({width:n,height:t,data:e}){const s=new Uint8Array(13),i=new DataView(s.buffer);i.setUint32(0,n),i.setUint32(4,t),s[8]=8,s[9]=6;const a=n*4,r=new Uint8Array((a+1)*t);for(let h=0;h<t;h++)r.set(e.subarray(h*a,(h+1)*a),h*(a+1)+1);return Zt([Uint8Array.of(137,80,78,71,13,10,26,10),Rt("IHDR",s),Rt("IDAT",Rn(r)),Rt("IEND",new Uint8Array(0))])}const Xe=n=>n+3&-4;function Se(n,t=0){const e=new Uint8Array(Xe(n.length)).fill(t);return e.set(n),e}function Qt(n){return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}function cs(n){const t=[Qt(n.positions),Qt(n.normals),Qt(n.uvs),Qt(n.indices),Je(n.texture)];let e=0;const s=t.map((f,g)=>{const p=g<3?34962:g===3?34963:void 0,d={buffer:0,byteOffset:e,byteLength:f.length,target:p};return e+=Xe(f.length),d}),i=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let f=0;f<n.positions.length;f++)i[f%3]=Math.min(i[f%3],n.positions[f]),a[f%3]=Math.max(a[f%3],n.positions[f]);const r=n.positions.length/3,h=Se(se.encode(JSON.stringify({asset:{version:"2.0",generator:"stack3.js"},extensionsUsed:["KHR_materials_unlit"],scene:0,scenes:[{nodes:[0]}],nodes:[{mesh:0,extras:{size:n.size,pivot:n.pivot}}],meshes:[{primitives:[{attributes:{POSITION:0,NORMAL:1,TEXCOORD_0:2},indices:3,material:0}]}],materials:[{extensions:{KHR_materials_unlit:{}},pbrMetallicRoughness:{baseColorTexture:{index:0}}}],textures:[{source:0,sampler:0}],samplers:[{magFilter:9729,minFilter:9729,wrapS:33071,wrapT:33071}],images:[{mimeType:"image/png",bufferView:4}],accessors:[{bufferView:0,componentType:5126,count:r,type:"VEC3",min:i,max:a},{bufferView:1,componentType:5126,count:r,type:"VEC3"},{bufferView:2,componentType:5126,count:r,type:"VEC2"},{bufferView:3,componentType:5125,count:n.indices.length,type:"SCALAR"}],bufferViews:s,buffers:[{byteLength:e}]})),32),l=Zt(t.map(f=>Se(f))),c=new Uint8Array(20),o=new DataView(c.buffer);o.setUint32(0,1179937895,!0),o.setUint32(4,2,!0),o.setUint32(8,28+h.length+l.length,!0),o.setUint32(12,h.length,!0),o.setUint32(16,1313821514,!0);const u=new Uint8Array(8),A=new DataView(u.buffer);return A.setUint32(0,l.length,!0),A.setUint32(4,5130562,!0),Zt([c,h,u,l])}function Xn(n){const{width:t,depth:e,layers:s,columns:i,spacing:a,size:r,pivot:h}=n;return{png:Je(n.texture),manifest:{version:1,atlas:"stack.png",width:t,depth:e,layers:s,columns:i,spacing:a,size:r,pivot:h,layerOrder:"bottom-to-top",layout:"row-major",axes:"xy-ground-z-up-y-forward"}}}function us(n,t){if(!n||typeof n!="object")throw new Error("Expected a stack3 stack manifest.");const{version:e,atlas:s,layout:i,layerOrder:a,axes:r,width:h,depth:l,layers:c,columns:o,spacing:u,size:A,pivot:f}=n,g=d=>typeof d=="number"&&Number.isSafeInteger(d)&&d>0,p=d=>Array.isArray(d)&&d.length===3&&d.every(Number.isFinite);if(e!==1||s!=="stack.png"||i!=="row-major"||a!=="bottom-to-top"||r!=="xy-ground-z-up-y-forward"||!g(h)||!g(l)||!g(c)||!g(o)||o>c||c>128||!p(A)||A.some(d=>d<=0)||!p(f)||typeof u!="number"||!Number.isFinite(u)||u<=0||t.width!==h*o||t.height!==l*Math.ceil(c/o)||t.data.length!==t.width*t.height*4)throw new Error("The stack manifest does not match the PNG or uses an unsupported layout.");return{target:"stack",texture:t,width:h,depth:l,layers:c,columns:o,spacing:u,size:A,pivot:f}}function fs(n){const t=Xn(n);return Gn({"stack.png":t.png,"stack.json":se.encode(JSON.stringify(t.manifest,null,2)+`
2
- `)})}const Wn={name:"Sprite Stack Wheel",enabled:!0,fields:[{name:"rollScale",label:"Roll multiplier",value:1,min:-4,max:4,step:.1},{name:"steeringScale",label:"Steering multiplier",value:1,min:-4,max:4,step:.1}],source:`function update({ fields }) {
3
- return { stackWheel: { rollScale: fields.rollScale, steeringScale: fields.steeringScale } };
4
- }`};function ie(n){return`function update({ dt, keys, fields, state, rotation, children }) {
5
- const pressed = (...codes) => codes.some(code => keys.includes(code));
6
- const throttle = Number(pressed('KeyW', 'ArrowUp')) - Number(pressed('KeyS', 'ArrowDown'));
7
- const steer = Number(pressed('KeyA', 'ArrowLeft')) - Number(pressed('KeyD', 'ArrowRight'));
8
- const radians = Math.PI / 180;
9
- const target = throttle * (throttle < 0 ? fields.reverseSpeed : fields.forwardSpeed);
10
- const speed = state.speed || 0;
11
- const change = fields.acceleration * dt;
12
- const nextSpeed = speed + Math.max(-change, Math.min(change, target - speed));
13
- const distance = (speed + nextSpeed) * .5 * dt;
14
- const steering = steer * fields.steeringAngle;
15
- const turn = distance / fields.wheelbase * Math.tan(steering * radians) / radians;
16
- const yaw = ((state.yaw || 0) + turn) % 360;
17
- const heading = (rotation[1] + yaw - turn * .5) * radians;
18
- const x = (state.x || 0) - Math.sin(heading) * distance;
19
- const z = (state.z || 0) - Math.cos(heading) * distance;
20
- const spin = ((state.spin || 0) - distance / fields.wheelRadius / radians) % 360;
21
- const wheelRotations = {};
22
- ${n?` const wheels = ${JSON.stringify(n)};
23
- for (let i = 0; i < wheels.length; i++) {
24
- wheelRotations[wheels[i]] = [spin, i < 2 ? steering : 0, 0];
25
- }`:` for (const child of children) {
26
- if (/wheel/i.test(child.name)) {
27
- wheelRotations[child.id] = [spin, /^front/i.test(child.name) ? steering : 0, 0];
28
- }
29
- }`}
30
- return { state: { speed: nextSpeed, x, z, yaw, spin }, translation: [x, 0, z],
31
- rotation: [0, yaw, 0], childRotations: wheelRotations };
32
- }`}const Vt={name:"WASD Vehicle",enabled:!0,fields:[{name:"forwardSpeed",label:"Forward speed",value:1.25,min:0,max:8,step:.05},{name:"reverseSpeed",label:"Reverse speed",value:.65,min:0,max:5,step:.05},{name:"acceleration",label:"Acceleration",value:2.8,min:.1,max:15,step:.1},{name:"steeringAngle",label:"Steering angle (°)",value:32,min:0,max:65,step:1},{name:"wheelbase",label:"Wheelbase",value:.73,min:.05,max:10,step:.01},{name:"wheelRadius",label:"Wheel radius",value:.16,min:.01,max:5,step:.01}],source:ie()};function As(n,t,e){return{...Vt,source:ie(n),fields:Vt.fields.map(s=>{const i=s.name==="wheelbase"?t:s.name==="wheelRadius"?e:s.value;return{...s,value:i,min:Math.min(s.min,i),max:Math.max(s.max,i)}})}}function ds(n){if(n===Vt.source)return!0;const t=/^ const wheels = (\[.*\]);$/m.exec(n);if(!t)return!1;try{const e=JSON.parse(t[1]);return Array.isArray(e)&&e.length===4&&e.every(s=>typeof s=="string")&&ie(e)===n}catch{return!1}}function ae(n){return`function update({ dt, keys, fields, state, rotation }) {
33
- const tracks = ${JSON.stringify(n)};
34
- const held = (...codes) => codes.some(code => keys.includes(code));
35
- const throttle = Number(held('KeyW', 'ArrowUp')) - Number(held('KeyS', 'ArrowDown'));
36
- const direction = Number(held('KeyA', 'ArrowLeft')) - Number(held('KeyD', 'ArrowRight'));
37
- const target = throttle * (throttle < 0 ? fields.reverseSpeed : fields.forwardSpeed);
38
- const oldSpeed = state.speed ?? 0;
39
- const speed = oldSpeed + (target - oldSpeed) * (1 - Math.exp(-fields.response * dt));
40
- const distance = (oldSpeed + speed) * .5 * dt;
41
- const turn = direction * fields.turnRate * dt;
42
- const radians = Math.PI / 180;
43
- const previous = state.yaw ?? 0;
44
- const heading = (rotation[1] + previous + turn * .5) * radians;
45
- const yaw = (previous + turn) % 360;
46
- const x = (state.x ?? 0) - Math.sin(heading) * distance;
47
- const z = (state.z ?? 0) - Math.cos(heading) * distance;
48
- const travel = tracks.map((track, i) => (state.travel?.[i] ?? 0) + distance + turn * radians * track[1]);
49
- return { translation: [x, 0, z], rotation: [0, yaw, 0],
50
- childTrackTravel: Object.fromEntries(tracks.map((track, i) => [track[0], travel[i]])),
51
- state: { speed, yaw, x, z, travel } };
52
- }`}const Zn={name:"Tracked Drive",enabled:!0,fields:[{name:"forwardSpeed",label:"Forward speed",value:.74,min:0,max:3,step:.01},{name:"reverseSpeed",label:"Reverse speed",value:.39,min:0,max:2,step:.01},{name:"turnRate",label:"Hull turn (°/s)",value:83,min:0,max:180,step:1},{name:"response",label:"Throttle response",value:9,min:.1,max:24,step:.1}],source:ae([])};function gs(n,t){return{...Zn,source:ae(n.map((e,s)=>[e,t[s]]))}}function ms(n){const t=/^ const tracks = (\[.*\]);$/m.exec(n);if(!t)return!1;try{const e=JSON.parse(t[1]);return Array.isArray(e)&&e.every(s=>Array.isArray(s)&&s.length===2&&typeof s[0]=="string"&&Number.isFinite(s[1]))&&ae(e)===n}catch{return!1}}const Vn={name:"Turret Control",enabled:!0,fields:[{name:"turnRate",label:"Turret turn (°/s)",value:85,min:0,max:180,step:1}],source:`function update({ dt, keys, fields, state }) {
53
- const input = Number(keys.includes('KeyQ')) - Number(keys.includes('KeyE'));
54
- const yaw = ((state.yaw ?? 0) + input * fields.turnRate * dt) % 360;
55
- return { rotation: [0, yaw, 0], state: { yaw } };
56
- }`},qn={name:"Track Belt",enabled:!0,fields:[{name:"travelScale",label:"Belt travel multiplier",value:1,min:-4,max:4,step:.1}],source:`function update({ fields }) {
57
- return { trackBelt: fields.travelScale };
58
- }`},ps={"sprite-stack-wheel":{script:Wn},"turret-control":{script:Vn},"track-belt":{script:qn}},$n=(n,t,e="number")=>({type:e,minimum:n,maximum:t}),st=(...n)=>({...$n(...n),type:"array"});st(-1e4,1e4),st(-360,360),st(.01,100),st(-100,100),st(-720,720);st(-100,100),st(-360,360);function ws(n,t=Date.now()){return n.time+(n.startedAt===null?0:Math.max(0,(t-n.startedAt)/1e3))}const Pe=new WeakMap;function ts(n){const t=Pe.get(n);if(t)return t;const{width:e,depth:s,layers:i,texture:a,columns:r,size:h}=n,l=e*s,c=l*i,o=new Uint8Array(c),u=new Int8Array(c*3),A=new Uint8Array(c);for(let d=0;d<i;d++){const C=d%r*e,w=Math.floor(d/r)*s;for(let m=0;m<s;m++)for(let B=0;B<e;B++)o[d*l+m*e+B]=+(a.data[((w+m)*a.width+C+B)*4+3]>=128)}const f=(d,C,w,m)=>{const B=w>0?o[d-C]:0,x=w+1<m?o[d+C]:0,Q=w>1?o[d-C*2]:0,b=w+2<m?o[d+C*2]:0;return 2*(B-x)+Q-b};for(let d=0;d<i;d++)for(let C=0;C<s;C++)for(let w=0;w<e;w++){const m=d*l+C*e+w;if(!o[m]||w>0&&w+1<e&&C>0&&C+1<s&&d>0&&d+1<i&&o[m-1]&&o[m+1]&&o[m-e]&&o[m+e]&&o[m-l]&&o[m+l])continue;const B=f(m,1,w,e)*e/h[0],x=f(m,l,d,i)*i/h[2],Q=-f(m,e,C,s)*s/h[1],b=127/(Math.hypot(B,x,Q)||1);u[m*3]=Math.round(B*b),u[m*3+1]=Math.round(x*b),u[m*3+2]=Math.round(Q*b)}const g=new Int32Array(6);for(let d=0;d<i;d++)for(let C=0;C<s;C++)for(let w=0;w<e;w++){const m=d*l+C*e+w,B=m*3,x=u[B],Q=u[B+1],b=u[B+2];if(!(x||Q||b))continue;g[0]=w>0?m-1:-1,g[1]=w+1<e?m+1:-1,g[2]=C>0?m-e:-1,g[3]=C+1<s?m+e:-1,g[4]=d>0?m-l:-1,g[5]=d+1<i?m+l:-1;let y=0,v=0;for(const U of g){if(U<0)continue;const G=U*3,_=(x*u[G]+Q*u[G+1]+b*u[G+2])/16129;_<.18||(y+=Math.max(0,1-_),v++)}A[m]=v?Math.min(255,Math.round(y/v*680)):0}const p={normals:u,variance:A};return Pe.set(n,p),p}const ke=new Y(.45,.7,.5).normalize();function es(n,t,e){const s=Math.min(1,n**4+e),i=t*t*(s-1)+1;return Math.min(2.4/(1+4*e),s/(i*i)*.63)}class ns{normalMatrix=new we;worldMatrix=new we;half=new Y;n=new Y;tangent=new Y;bitangent=new Y;uEdge=new Y;vEdge=new Y;normal=new Y;normals=new Float32Array(0);variance=0;detail=!1;specularAA=!1;minX=0;minY=0;maxX=0;maxY=0;slice;camera(t){t.getWorldDirection(this.half).negate().add(ke).normalize()}mesh(t,e,s,i,a){this.detail=!!a.detailNormals,this.specularAA=!!a.specularAA;const r=Le(t);this.slice=r?{width:r.stack.width,row:r.layer*r.stack.depth,roll:r.roll,spacing:t.parent?.scale.y??1,lighting:ts(r.roll?.source??r.stack)}:void 0,this.normals.length<e.count*3&&(this.normals=new Float32Array(e.count*3)),this.normalMatrix.getNormalMatrix(t.matrixWorld),this.worldMatrix.setFromMatrix4(t.matrixWorld);for(let c=0;c<e.count;c++)this.n.fromBufferAttribute(e,c).applyNormalMatrix(this.normalMatrix).toArray(this.normals,c*3);this.minX=Math.max(0,Math.round(s.offset.x*i.width-.5)),this.maxX=Math.min(i.width-1,Math.round((s.offset.x+s.repeat.x)*i.width-.5));const h=s.offset.y,l=h+s.repeat.y;this.minY=Math.max(0,Math.round((s.flipY?1-l:h)*i.height-.5)),this.maxY=Math.min(i.height-1,Math.round((s.flipY?1-h:l)*i.height-.5))}triangle(t,e,s,i,a,r,h){if(this.detail){const l=e.getX(i)-e.getX(s),c=e.getY(i)-e.getY(s),o=e.getX(a)-e.getX(s),u=e.getY(a)-e.getY(s),A=l*u-o*c;this.tangent.set(0,0,0),this.bitangent.set(0,0,0),Math.abs(A)>1e-12&&(this.n.fromBufferAttribute(t,s),this.uEdge.fromBufferAttribute(t,i).sub(this.n).applyMatrix3(this.worldMatrix),this.vEdge.fromBufferAttribute(t,a).sub(this.n).applyMatrix3(this.worldMatrix),this.tangent.copy(this.uEdge).multiplyScalar(u/A).addScaledVector(this.vEdge,-c/A).normalize(),this.bitangent.copy(this.uEdge).multiplyScalar(-o/A).addScaledVector(this.vEdge,l/A).normalize().multiplyScalar(h?-1:1))}if(this.variance=0,this.specularAA&&!this.slice){const l=this.normals,c=s*3,o=i*3,u=a*3,A=(f,g)=>l[f]*l[g]+l[f+1]*l[g+1]+l[f+2]*l[g+2];this.variance=Math.min(.14,Math.max(0,3-A(c,o)-A(o,u)-A(u,c))/Math.max(3,Math.sqrt(Math.abs(r))*3))}}shade(t,e,s,i,a,r,h,l,c,o,u){const A=a*3,f=r*3,g=h*3,p=this.normals,d=this.normal.set(p[A]*l+p[f]*c+p[g]*o,p[A+1]*l+p[f+1]*c+p[g+1]*o,p[A+2]*l+p[f+2]*c+p[g+2]*o).normalize();u&&d.negate();const C=(t[0]*.2126+t[1]*.7152+t[2]*.0722)/255;let w=this.variance;if(this.detail||this.slice){const y=Math.min(this.maxX,Math.max(this.minX,Math.floor(s*e.width))),v=Math.min(this.maxY,Math.max(this.minY,Math.floor(i*e.height)));if(this.slice){const{row:U,width:G,roll:_,spacing:I,lighting:M}=this.slice,T=U+v-this.minY,k=_?_.rows[T]:T;if(k>=0){const E=k*G+y-this.minX,S=M.normals[E*3],F=M.normals[E*3+1],Z=M.normals[E*3+2];(S||F||Z)&&(d.set(S,F,Z),_&&d.set(S,F*_.cos-Z*_.sin*I,F*_.sin/I+Z*_.cos),d.applyNormalMatrix(this.normalMatrix)),this.specularAA&&(w=M.variance[E]/255*.24)}}this.detail&&(w=this.perturb(d,e,y,v,C,w))}const m=Math.max(0,d.dot(ke)),B=.38+.23*(1-C),x=es(B,Math.max(0,d.dot(this.half)),w)*m,Q=.68+.31*m+.06*Math.max(0,d.y),b=(12+22*C)*x;for(let y=0;y<3;y++){const v=t[y]*Q;t[y]=v+b*(1-v/340)}}perturb(t,e,s,i,a,r){const h=this.luma(e,s,i,a),l=this.luma(e,s-1,i,h),c=this.luma(e,s+1,i,h),o=this.luma(e,s,i-1,h),u=this.luma(e,s,i+1,h),A=.76*(c-l)+.12*(this.luma(e,s+2,i,c)-this.luma(e,s-2,i,l)),f=.76*(u-o)+.12*(this.luma(e,s,i+2,u)-this.luma(e,s,i-2,o)),g=Math.min(1.7,.38/Math.max(.001,Math.hypot(A,f)));if(this.n.copy(this.tangent).multiplyScalar(A).addScaledVector(this.bitangent,f),this.n.addScaledVector(t,-this.n.dot(t)),t.addScaledVector(this.n,-g).normalize(),!this.specularAA)return r;const p=l+c-2*h,d=o+u-2*h;return Math.min(.24,r+.45*(p*p+d*d))}luma(t,e,s,i){if(e<this.minX||e>this.maxX||s<this.minY||s>this.maxY)return i;const a=(s*t.width+e)*4,r=t.data;return r[a+3]>=128?(r[a]*.2126+r[a+1]*.7152+r[a+2]*.0722)/255:i}}const Nt=(n,t,e,s,i,a)=>(e-n)*(a-t)-(s-t)*(i-n);class Cs{canvas=document.createElement("canvas");ctx=this.canvas.getContext("2d");textures=new WeakMap;transform=new ln;vertex=new cn;lighting=new ns;frame;sampleColors=new Uint8ClampedArray(0);depth=new Float32Array(0);pixels(t){const e=t.image;if(!e?.width||!e.height)return;if("data"in e)return e;const s=this.textures.get(e);if(s)return s;try{const a=new OffscreenCanvas(e.width,e.height).getContext("2d");a.drawImage(e,0,0);const r=a.getImageData(0,0,e.width,e.height);return this.textures.set(e,r),r}catch{return}}render(t,e,s,i,a,r,h){const l=Math.min(1,512/Math.max(this.canvas.clientWidth,this.canvas.clientHeight,1))*(s?2:1),c=Math.max(1,Math.round(this.canvas.clientWidth*l)),o=Math.max(1,Math.round(this.canvas.clientHeight*l));(!this.frame||this.frame.width!==c||this.frame.height!==o)&&(this.canvas.width=c,this.canvas.height=o,this.frame=this.ctx.createImageData(c,o));const{data:u}=this.frame,A=h?.subpixelAA?4:1,f=c*o*A;this.depth.length!==f&&(this.depth=new Float32Array(f));const g=A===4?f*4:0;this.sampleColors.length!==g&&(this.sampleColors=new Uint8ClampedArray(g));const p=A===4?this.sampleColors:u;p.fill(0),this.depth.fill(1/0),e.updateMatrixWorld(),h&&this.lighting.camera(e),t?.updateMatrixWorld(!0);const d=[],C=e.matrixWorldInverse.elements;t?.traverseVisible(w=>{if(!(w instanceof un)||!w.visible||Array.isArray(w.material))return;const m=w.material;if(!m.map)return;const B=w.matrixWorld.elements,x=C[2]*B[12]+C[6]*B[13]+C[10]*B[14];d.push({mesh:w,material:m,viewZ:x})}),h&&d.sort((w,m)=>m.viewZ-w.viewZ);for(const{mesh:w,material:m}of d)this.draw(w,m,e,c,o,p,r||m instanceof fn,A,h);A===4&&this.resolveSubpixels(u),this.ctx.putImageData(this.frame,0,0),this.ctx.save(),this.ctx.globalCompositeOperation="destination-over",i&&t&&this.drawGrid(e,c,o,a),this.ctx.fillStyle="#121923",this.ctx.fillRect(0,0,c,o),this.ctx.restore()}resolveSubpixels(t){const e=this.sampleColors;for(let s=0,i=0;s<t.length;s+=4,i+=16){const a=e[i+3],r=e[i+7],h=e[i+11],l=e[i+15],c=a+r+h+l;if(t[s+3]=c*.25,!c){t[s]=t[s+1]=t[s+2]=0;continue}for(let o=0;o<3;o++)t[s+o]=(e[i+o]*a+e[i+4+o]*r+e[i+8+o]*h+e[i+12+o]*l)/c}}drawGrid(t,e,s,i){const a=new Y,r=new Y;this.ctx.strokeStyle="#29394b",this.ctx.beginPath();for(let h=-12;h<=12;h++)for(let l=0;l<2;l++){const c=h*.25;a.set(l?c:-3,i,l?-3:c).project(t),r.set(l?c:3,i,l?3:c).project(t),!(a.z<-1||a.z>1||r.z<-1||r.z>1)&&(this.ctx.moveTo((a.x+1)*e/2,(1-a.y)*s/2),this.ctx.lineTo((r.x+1)*e/2,(1-r.y)*s/2))}this.ctx.stroke()}draw(t,e,s,i,a,r,h,l,c){const o=e.map,u=this.pixels(o),A=t.geometry.getAttribute("position"),f=t.geometry.getAttribute("uv");if(!u||!A||!f)return;this.transform.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(t.matrixWorld);const g=c&&Le(t);let p=0,d=i-1,C=0,w=a-1;if(g){if(!g.bounds)return;const[_,I,M,T]=g.bounds;let k=1/0,E=-1/0,S=1/0,F=-1/0;for(const Z of[_,M])for(const N of[I,T]){const R=this.vertex.set((Z-.5)*g.stack.size[0],0,(.5-N)*g.stack.size[1],1).applyMatrix4(this.transform),j=(1+R.x/R.w)*i*.5,H=(1-R.y/R.w)*a*.5;k=Math.min(k,j),E=Math.max(E,j),S=Math.min(S,H),F=Math.max(F,H)}if(p=Math.max(p,Math.floor(k)),d=Math.min(d,Math.ceil(E)),C=Math.max(C,Math.floor(S)),w=Math.min(w,Math.ceil(F)),p>d||C>w)return}const m=new Float32Array(A.count*4);for(let _=0;_<A.count;_++){const I=_*4,M=this.vertex.set(A.getX(_),A.getY(_),A.getZ(_),1).applyMatrix4(this.transform);m[I]=(1+M.x/M.w)*i*.5,m[I+1]=(1-M.y/M.w)*a*.5,m[I+2]=M.z/M.w,m[I+3]=M.w>0?1/M.w:0}const B=t.geometry.getAttribute("normal"),x=!!(h&&B&&c);h&&B&&c&&this.lighting.mesh(t,B,o,u,c);const Q=t.geometry.index,b=Q?.count??A.count,y=new Float32Array(4),v=o.magFilter===An,U=t.matrixWorld.determinant()<0,G=Math.max(1,e.alphaTest*255);for(let _=0;_<b;_+=3){const I=Q?.getX(_)??_,M=Q?.getX(_+1)??_+1,T=Q?.getX(_+2)??_+2,k=I*4,E=M*4,S=T*4,F=m[k+2],Z=m[E+2],N=m[S+2];if(!m[k+3]||!m[E+3]||!m[S+3]||Math.min(F,Z,N)>1)continue;const R=m[k],j=m[k+1],H=m[E],L=m[E+1],J=m[S],$=m[S+1],X=Nt(R,j,H,L,J,$),pt=U?X<0:X>0;if(!X||pt&&e.side===dn)continue;const wt=Math.max(p,Math.floor(Math.min(R,H,J))),Ct=Math.min(d,Math.ceil(Math.max(R,H,J))),yt=Math.max(C,Math.floor(Math.min(j,L,$))),lt=Math.min(w,Math.ceil(Math.max(j,L,$))),nt=h&&B&&!x?.65+.35*Math.max(0,B.getY(I)*.7+B.getZ(I)*.5+B.getX(I)*.45):1;x&&this.lighting.triangle(A,f,I,M,T,X,o.flipY);const St=(L-$)/X,Pt=(J-H)/X,kt=($-j)/X,Tt=(R-J)/X,Lt=l===4?.25:0,We=(Math.abs(St)+Math.abs(Pt))*Lt,Ze=(Math.abs(kt)+Math.abs(Tt))*Lt,Ve=(Math.abs(St+kt)+Math.abs(Pt+Tt))*Lt,qe=f.getX(I),$e=f.getX(M),tn=f.getX(T),en=f.getY(I),nn=f.getY(M),sn=f.getY(T);for(let ct=yt;ct<=lt;ct++)for(let ut=wt;ut<=Ct;ut++){const Ut=Nt(H,L,J,$,ut+.5,ct+.5)/X,Ft=Nt(J,$,R,j,ut+.5,ct+.5)/X;if(Ut<-We||Ft<-Ze||1-Ut-Ft<-Ve)continue;let re=!1,he=0,le=0,ce=0;for(let ft=0;ft<l;ft++){const ue=l===1?0:ft&1?.25:-.25,fe=l===1?0:ft&2?.25:-.25,vt=Ut+ue*St+fe*Pt,Bt=Ft+ue*kt+fe*Tt,Yt=1-vt-Bt;if(vt<0||Bt<0||Yt<0)continue;const _t=vt*F+Bt*Z+Yt*N,ot=(ct*i+ut)*l+ft;if(_t<-1||_t>1||_t>=this.depth[ot])continue;const Mt=vt*m[k+3],Et=Bt*m[E+3],bt=Yt*m[S+3],At=1/(Mt+Et+bt),Ae=(qe*Mt+$e*Et+tn*bt)*At*o.repeat.x+o.offset.x,de=(en*Mt+nn*Et+sn*bt)*At*o.repeat.y+o.offset.y,ge=o.flipY?1-de:de;this.sample(u,Ae,ge,v,y),!(y[3]<G)&&(re||(x&&this.lighting.shade(y,u,Ae,ge,I,M,T,Mt*At,Et*At,bt*At,pt),he=y[0]*nt,le=y[1]*nt,ce=y[2]*nt,re=!0),this.depth[ot]=_t,r[ot*4]=he,r[ot*4+1]=le,r[ot*4+2]=ce,r[ot*4+3]=e.alphaToCoverage?y[3]:255)}}}}sample(t,e,s,i,a){const{width:r,height:h,data:l}=t,c=Math.min(r-1,Math.max(0,e*r-.5)),o=Math.min(h-1,Math.max(0,s*h-.5));if(i){const C=(Math.round(o)*r+Math.round(c))*4;for(let w=0;w<4;w++)a[w]=l[C+w];return}const u=Math.floor(c),A=Math.floor(o),f=Math.min(r-1,u+1),g=Math.min(h-1,A+1),p=c-u,d=o-A;for(let C=0;C<4;C++)a[C]=(l[(A*r+u)*4+C]*(1-p)+l[(A*r+f)*4+C]*p)*(1-d)+(l[(g*r+u)*4+C]*(1-p)+l[(g*r+f)*4+C]*p)*d}}const ss="stack3-preview-4",Te=new WeakMap;let is=0;function jt(n){let t=Te.get(n);return t||(t=crypto.subtle?n.arrayBuffer().then(e=>crypto.subtle.digest("SHA-256",e)).then(e=>Array.from(new Uint8Array(e),s=>s.toString(16).padStart(2,"0")).join("")):Promise.resolve("session:"+is++),Te.set(n,t),t)}async function ys(n){return"parts"in n?JSON.stringify(await Promise.all(n.parts.map(async t=>[Be(t.layout),t.size??null,await jt(t.atlas)]))):"atlas"in n?JSON.stringify([Be(n.layout),await jt(n.atlas)]):JSON.stringify(await Promise.all(zt.map(t=>{const e=n.files[t];return e?jt(e):null})))}const it=new Map;let as;function oe(){return as??=new Promise(n=>{try{const t=indexedDB.open(ss,1);t.onupgradeneeded=()=>t.result.createObjectStore("results",{keyPath:"key"}).createIndex("savedAt","savedAt"),t.onsuccess=()=>n(t.result),t.onerror=t.onblocked=()=>n(null)}catch{n(null)}})}function qt(n,t){it.delete(n),it.set(n,t),it.size>4&&it.delete(it.keys().next().value)}async function vs(n,t){const e=it.get(n);if(e)return qt(n,e),{value:e,origin:"Memory cache"};if(!t||!crypto.subtle)return null;const s=await oe();return s?new Promise(i=>{const a=s.transaction("results").objectStore("results").get(n);a.onsuccess=()=>{const r=a.result;r&&qt(n,r.value),i(r?{value:r.value,origin:"Disk cache"}:null)},a.onerror=()=>i(null)}).catch(()=>null):null}async function Bs(n,t,e){if(qt(n,t),!e||!crypto.subtle)return;const s=await oe();if(s)try{const a=s.transaction("results","readwrite").objectStore("results");a.put({key:n,value:t,savedAt:Date.now()});let r=0;const h=a.index("savedAt").openKeyCursor(null,"prev");h.onsuccess=()=>{const l=h.result;l&&(++r>12&&a.delete(l.primaryKey),l.continue())}}catch{}}async function _s(){it.clear();const n=await oe();n&&await new Promise((t,e)=>{const s=n.transaction("results","readwrite");s.objectStore("results").clear(),s.oncomplete=()=>t(),s.onabort=()=>e(s.error)})}export{Cs as C,zt as D,hs as O,rs as _,us as a,Bs as b,_s as c,cs as d,fs as e,vs as f,As as g,gs as h,ds as i,ms as j,ps as k,ws as l,Wn as m,Be as p,ls as r,ys as s,Vt as v};
@@ -1,17 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./script-engine-CLj7QMLe.js","./preview-cache-DRF_H5pq.js","./style-CWGgpweN.js","./style-CMUT8CmM.css"])))=>i.map(i=>d[i]);
2
- import{V as ke,e as He,G as Ne,ao as Je,A as je,s as Ge,O as Ve,as as Le,at as _e,au as Ze,Q as $e,av as Qe,ap as Te,p as Ye,ar as Xe,aq as et,q as tt,a6 as nt,an as ot,W as st}from"./style-CWGgpweN.js";import{g as it,h as rt,i as Oe,j as at,k as Me,_ as ct,O as lt,C as dt,l as ut,f as pt,b as ft,v as mt,m as ht,p as gt}from"./preview-cache-DRF_H5pq.js";function vt(t,l,d){const o=new Set(t.atlases.map(A=>A.id)),g=t.nodes.filter(A=>A.parentId===l.id&&A.atlasId&&o.has(A.atlasId)),y=g.filter(A=>/wheel|tire|tyre|바퀴|타이어/i.test(A.name+" "+A.id)),c=new Map;for(const A of g){const i=c.get(A.atlasId)??[];i.push(A),c.set(A.atlasId,i)}const p=[...c.values()].filter(A=>A.length===4&&y.every(i=>A.includes(i))),P=y.length===4?y:g.length===4?g:p.length===1?p[0]:null;if(!P)throw new Error("Cannot identify four wheels under "+l.id+". Supply --wheels <front-left,front-right,rear-left,rear-right>.");const K=[...P].sort((A,i)=>A.position[2]-i.position[2]),D=(A,i)=>A.position[0]-i.position[0];return[...K.slice(0,2).sort(D),...K.slice(2).sort(D)]}function ve(t,l,d,o){const g=(l.scripts??[]).filter(c=>c.id===d||c.name===o.name||(d==="wasd-vehicle"?Oe(c.source):c.source===o.source));if(g.length>1)throw new Error("Multiple "+o.name+" components on node "+l.id+".");const y=g[0];if(!y)return t.push({action:"script.set",nodeId:l.id,id:d,patch:o}),d;if(y.source!==o.source){if(!(d==="wasd-vehicle"&&Oe(y.source)||d==="tracked-drive"&&at(y.source)))throw new Error("Cannot replace customized "+o.name+" source on node "+l.id+".");t.push({action:"script.set",nodeId:l.id,id:y.id,patch:{source:o.source}})}return y.id}function wt(t,l,d){const o=t.nodes.find(w=>w.id===l);if(!o)throw new Error("Unknown vehicle root: "+l);const g=vt(t,o),[y,c,p,P]=g;if(Math.max(y.position[2],c.position[2])>=Math.min(p.position[2],P.position[2])||Math.max(y.position[0],p.position[0])>=Math.min(c.position[0],P.position[0]))throw new Error("Wheel positions must form two axles facing local −Z, with left wheels at smaller local X.");const K=(p.position[2]+P.position[2]-(y.position[2]+c.position[2]))/2*o.scale[2],D=g.reduce((w,h)=>{const{format:I,height:R,spacing:b}=h.settings;return w+R*h.scale[1]*(I==="stack"?b:1)/2},0)/4*o.scale[1];if(![K,D].every(w=>w>0&&w<=1e5))throw new Error("Vehicle wheelbase and radius must be positive and at most 100000 scene units.");const A=[],i=ve(A,o,"wasd-vehicle",it(g.map(w=>w.id),K,D)),x=g.map((w,h)=>({role:["front-left","front-right","rear-left","rear-right"][h],node:w.id,component:ve(A,w,"sprite-stack-wheel",Me["sprite-stack-wheel"].script)}));return{actions:A,root:o.id,component:i,wheels:x}}function yt(t,l){const d=t.nodes.find(i=>i.id===l);if(!d)throw new Error("Unknown tank root: "+l);const o=t.nodes.filter(i=>i.parentId===d.id),g=new Map(t.atlases.map(i=>[i.id,i])),y=i=>i.atlasId?g.get(i.atlasId):void 0,c=o.filter(i=>{const x=y(i);return x&&/track|tread|트랙|궤도/i.test([i.name,i.id,x.name].join(" "))}).sort((i,x)=>i.position[0]-x.position[0]);if(c.length!==2||c[0].position[0]>=0||c[1].position[0]<=0)throw new Error("Provide two atlas-backed track children with track or tread in their names, one on each side of the root.");const p=o.filter(i=>{const x=y(i);return/turret|포탑/i.test([i.name,i.id,x?.name].join(" "))?x||t.nodes.some(w=>w.parentId===i.id&&y(w)):!1});if(p.length!==1)throw new Error("Provide one turret child or a named turret pivot with an atlas-backed child.");const P=[],K=ve(P,d,"tracked-drive",rt(c.map(i=>i.id),c.map(i=>i.position[0]*d.scale[0]))),D=ve(P,p[0],"turret-control",Me["turret-control"].script),A=c.map((i,x)=>{if(i.settings.format!=="stack")throw new Error(i.name+" must use Sprite stack to animate its belt.");return{role:x===0?"left":"right",node:i.id,component:ve(P,i,"track-belt",Me["track-belt"].script)}});return{actions:P,root:d.id,component:K,turret:{node:p[0].id,component:D},tracks:A}}const bt=[0,0,0],Ee=(t,l)=>t+"/"+l;function kt(t,l){const d=t.newRuntime();d.setMemoryLimit(4*1024*1024),d.setMaxStackSize(256*1024);let o=performance.now()+30;d.setInterruptHandler(()=>performance.now()>=o);const g=d.newContext();try{const y=g.unwrapResult(g.evalCode(`(() => {
3
- "use strict";
4
- const parse = JSON.parse, stringify = JSON.stringify;
5
- const callback = (() => {
6
- ${l}
7
- if (typeof update !== 'function') throw new Error('Define function update(input).');
8
- return update;
9
- })();
10
- return json => {
11
- const output = stringify(callback(parse(json)) ?? {});
12
- if (!output || output.length > 16384) throw new Error('Script output must be JSON of 16 KB or less.');
13
- return output;
14
- };
15
- })()`,"component.js"));return{runtime:d,context:g,update:y,limit:c=>{o=c}}}catch(y){throw g.dispose(),d.dispose(),y}}function Re(t){t&&(t.update.dispose(),t.context.dispose(),t.runtime.dispose())}function Ae(t){return Array.isArray(t)&&t.length===3&&t.every(l=>typeof l=="number"&&Number.isFinite(l)&&Math.abs(l)<=1e4)}function St(t){if(!t||typeof t!="object")return!1;const{rollScale:l,steeringScale:d}=t;return[l,d].every(o=>Number.isFinite(o)&&Math.abs(o)<=4)}function De(t,l){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(l)}function Et(t,l,d){t.limit(d);const{context:o,update:g}=t,y=o.newString(l);try{const p=o.unwrapResult(o.callFunction(g,o.undefined,y)).consume(P=>JSON.parse(o.getString(P)));if(!p||typeof p!="object"||Array.isArray(p)||p.translation!==void 0&&!Ae(p.translation)||p.rotation!==void 0&&!Ae(p.rotation)||p.stackWheel!==void 0&&!St(p.stackWheel)||p.childRotations!==void 0&&!De(p.childRotations,Ae)||p.trackBelt!==void 0&&(!Number.isFinite(p.trackBelt)||Math.abs(p.trackBelt)>4)||p.childTrackTravel!==void 0&&!De(p.childTrackTravel,P=>typeof P=="number"&&Number.isFinite(P)&&Math.abs(P)<=1e9))throw new Error("Return valid finite transform, wheel, and track outputs.");return p}finally{y.dispose()}}function At(t){const l=new Set,d=new Map,o=new Map,g=new Map;let y,c,p;function P(i,x){const{node:w,script:h}=i;g.set(Ee(w.id,h.id),x),t(w.id,h.id,x)}function K(i){const x=c&&c.play.resetCount!==i.play.resetCount;c=i;const w=new Set;for(const h of i.nodes)for(const I of h.scripts??[]){const R=Ee(h.id,I.id);if(!I.enabled)continue;w.add(R);const b=d.get(R);if(!x&&b&&b.script.source===I.source){b.node=h,b.script=I;continue}Re(b?.vm);const q={node:h,script:I};d.set(R,q),P(q,"Loading script…"),y??=ct(()=>import("./script-engine-CLj7QMLe.js"),__vite__mapDeps([0,1,2,3]),import.meta.url).then(L=>L.createScriptEngine()).catch(L=>{throw y=void 0,L}),y.then(L=>{d.get(R)===q&&(q.vm=kt(L,I.source),P(q,"Ready"))}).catch(L=>{d.get(R)===q&&(q.failed=!0,P(q,String(L).slice(0,500)))})}for(const[h,I]of d)w.has(h)||(Re(I.vm),d.delete(h),g.delete(h));(x||!d.size)&&(l.clear(),o.clear(),p=void 0)}function D(i,x,w){if(!w)return;const h=o.get(i)??{},I=h[x]??bt;h[x]=[I[0]+w[0],I[1]+w[1],I[2]+w[2]],o.set(i,h)}function A(i){const x=p===void 0?0:Math.min(.05,Math.max(0,i-p));if(p=i,!c||!d.size)return o;o.clear();const w=c.play.startedAt!==null&&x>0&&!document.hidden,h=performance.now()+8;for(const I of d.values()){const{node:R,script:b,vm:q}=I;if(!q||I.failed)continue;const L=c.nodes.filter(B=>B.parentId===R.id);if(w&&performance.now()<h)try{I.output=Et(q,JSON.stringify({dt:x,time:i,keys:[...l],fields:Object.fromEntries(b.fields.map(B=>[B.name,B.value])),state:I.output?.state??{},position:R.position,rotation:R.rotation,children:L.map(({id:B,name:_,position:oe})=>({id:B,name:_,position:oe}))}),Math.min(h,performance.now()+4))}catch(B){I.failed=!0,P(I,String(B).slice(0,500))}const U=I.output;if(U){if(D(R.id,"translation",U.translation),D(R.id,"rotation",U.rotation),U.stackWheel||U.trackBelt!==void 0){const B=o.get(R.id)??{};U.stackWheel&&(B.stackWheel=U.stackWheel),U.trackBelt!==void 0&&(B.trackBelt=U.trackBelt),o.set(R.id,B)}for(const B of L)if(U.childRotations&&Object.hasOwn(U.childRotations,B.id)&&D(B.id,"wheelRotation",U.childRotations[B.id]),U.childTrackTravel&&Object.hasOwn(U.childTrackTravel,B.id)){const _=o.get(B.id)??{};_.trackTravel=(_.trackTravel??0)+U.childTrackTravel[B.id],o.set(B.id,_)}}}return o}return{sync:K,tick:A,hasScripts:()=>d.size>0,keyDown:i=>l.add(i),keyUp:i=>l.delete(i),clearKeys:()=>l.clear(),status:(i,x)=>g.get(Ee(i,x))??""}}const Be=new ke;function It(t,l,d){const o=d*t.scale.y;t.position.add(Be.set(0,o,0).applyQuaternion(t.quaternion)),t.quaternion.multiply(l),t.position.sub(Be.set(0,o,0).applyQuaternion(t.quaternion))}const me=Math.PI/180;function Mt(t,l,d,o,g){const y=new He,c=new Ne,p=o?At(g):void 0,P=new Qe(0,0,0,"YXZ"),K=new $e;let D=null;const A=new ke,i=new ke,x=new Je(24,48,5334392,3227985);y.add(c,x,new je(16777215,.85));const w=new Ge(16777215,1.5);w.position.set(2,3,2),y.add(w);const h=new Ve(-2,2,2,-2,.01,1e4);h.position.set(3,3,4);const I=new lt(h,t);I.enablePan=!1,I.minZoom=.1,I.maxZoom=10,I.maxPolarAngle=Math.acos(.2);const R=new dt;t.append(R.canvas);let b,q=!1,L,U,B=new Map,_=2,oe=6,e=0,n=!1,r="";const s=new Map,u=new Map,T=new Map,F=new Map,f=new Worker(new URL(""+new URL("reconstruct.worker-Cf8iZwT3.js",import.meta.url).href,import.meta.url),{type:"module"});let W=Promise.resolve(),J=0;function M(){const a=t.clientWidth,E=t.clientHeight;if(!a||!E)return;const O=a/E;if(h.left=-_*Math.max(1,O),h.right=-h.left,h.bottom=-_*Math.max(1,1/O),h.top=-h.bottom,h.updateProjectionMatrix(),!b)return;const z=Math.min(window.devicePixelRatio||1,2)*(L?.view.supersampling?2:1);e!==z&&(e=z,b.setPixelRatio(z)),b.setSize(a,E,!1)}function m(){const a=L?.view.backend==="gpu"&&!q;if(a&&!b)try{b=new st({antialias:!0}),b.setClearColor(1186083),b.domElement.addEventListener("webglcontextlost",O=>{O.preventDefault(),q=!0,m(),H()}),b.domElement.addEventListener("webglcontextrestored",()=>{q=!1,m(),H()}),t.append(b.domElement)}catch{q=!0}const E=a&&!q&&!!b;R.canvas.hidden=E,b&&(b.domElement.hidden=!E),t.dataset.backend=E?"gpu":"cpu",M()}function S(){const a=L?.view;if(!a)return;const E=Math.acos(Math.min(.99999,a.squash)),O=new ke().setFromSpherical(new Le(oe,E,a.yaw*me));h.position.copy(I.target).add(O),h.zoom=a.scale,h.updateProjectionMatrix(),I.update()}I.addEventListener("end",()=>{const a=new Le().setFromVector3(h.position.clone().sub(I.target));l({yaw:a.theta/me,squash:Math.max(.2,Math.min(1,Math.cos(a.phi))),scale:h.zoom})}),new ResizeObserver(M).observe(t);function ee(){const a=new tt;if(c.updateMatrixWorld(!0),c.traverseVisible(O=>{O instanceof nt&&a.expandByObject(O)}),a.isEmpty())return;const E=a.getBoundingSphere(new ot);_=Math.max(.05,E.radius)*1.12,oe=Math.max(6,_*3),I.target.copy(E.center),M(),S()}function H(){const a=L?.nodes.filter(k=>k.atlasId)??[],E=a.filter(k=>$(k.id)).length,O=[...u.values()][0],z=E<a.length?`${E}/${a.length} assets ready`:`${E} assets ready`;d(O||(q&&L?.view.backend==="gpu"?"WebGL unavailable · CPU preview":z),E)}function $(a){const E=s.get(a);return!!E?.content&&E.key===E.renderedKey}function V(a){const E=a.fingerprint??a.id;let O=T.get(E);if(!O){const z=t.dataset.endpoint+"/atlas/"+a.id+(a.fingerprint?"?fingerprint="+a.fingerprint:"");O=fetch(z).then(k=>{if(!k.ok)throw new Error("Could not read the embedded atlas.");return k.blob()}).catch(k=>{throw T.delete(E),k}),T.set(E,O)}return O}function de(a,E,O,z){const k=F.get(a);if(k)return k;const v=W.then(async()=>{const C=await pt(a,!0);if(C)return C.value;const j={atlas:await V(E),layout:E.layout},te=++J,G=await new Promise((re,ae)=>{f.onmessage=({data:ne})=>{ne.id===te&&("error"in ne?ae(new Error(ne.error)):ne.preview||re(ne))},f.onerror=()=>ae(new Error("Failed to run the reconstruction worker.")),f.postMessage({id:te,sourceKey:"project:"+(E.fingerprint??E.id),source:j,target:z,settings:O,keepTop:z==="stack"})});return ft(a,G,!0),G});return F.set(a,v),W=v.then(()=>{},()=>{}),v.then(()=>F.delete(a),()=>F.delete(a)),v}function fe(a,E){if(!a.content)return;const{spacing:O,pixelArt:z,smoothEdges:k,lighting:v,format:C}=E.settings,j=JSON.stringify([O,z,k,v,C]);a.display!==j&&(a.display=j,a.content.scale.y=C==="stack"?O:1,Xe(a.content,v),C==="stack"&&et(a.content,z,k))}function Se(a,E){a.content&&(a.group.remove(a.content),Te(a.content)),a.content=E,a.display=void 0,a.group.add(E)}function Ke(a){const E=!L||a.view.backend!==L.view.backend||a.view.supersampling!==L.view.supersampling;n||=!L||a.view.frame!==L.view.frame,L=a,p?.sync(a),U=void 0,B=new Map(a.play.offsets?.map(k=>[k.id,k]));const O=new Map(a.nodes.map(k=>[k.id,k]));for(const[k,v]of s)O.has(k)||(v.group.removeFromParent(),v.content&&Te(v.content),u.delete(k),s.delete(k));for(const k of a.nodes)s.has(k.id)||s.set(k.id,{group:new Ne});for(const k of a.nodes){const v=s.get(k.id),C=k.parentId?s.get(k.parentId)?.group??c:c;v.group.parent!==C&&C.add(v.group),v.group.name=k.name,v.group.visible=k.visible,v.group.scale.set(...k.scale);const j=a.atlases.find(Y=>Y.id===k.atlasId);if(!j)continue;const{format:te,layers:G,resolution:re,threshold:ae,height:ne,pivot:he,profile:ue}=k.settings,Q={layers:G,resolution:re,threshold:ae,height:ne,pivot:he,profile:ue,textureProjection:k.settings.textureProjection,meshMethod:k.settings.meshMethod,contourHub:k.settings.contourHub},ce=JSON.stringify(["project-v2",j.fingerprint??j.id,j.layout,te,Q]);fe(v,k),v.key!==ce&&(v.key=ce,u.delete(k.id),de(ce,j,Q,te==="glb"?"mesh":"stack").then(({result:Y,top:we})=>{if(s.get(k.id)!==v||v.key!==ce)return;v.asset=Y,v.top=we,v.rolling=void 0,v.belt=void 0,Se(v,Ye(Y)),v.centerY=Y.size[2]*.5-Y.pivot[2],v.renderedKey=ce;const Ce=L?.nodes.find(ze=>ze.id===k.id);Ce&&fe(v,Ce),n||=!c.userData.framed,H()}).catch(Y=>{s.get(k.id)!==v||v.key!==ce||(u.set(k.id,k.name+" · "+Y.message),H())}))}E&&m();const z=JSON.stringify([a.view.yaw,a.view.squash,a.view.scale]);z!==r&&(r=z,S()),x.visible=a.view.grid,H()}const We=document.getElementById("playTime");function qe(a,E){const O={id:a,patch:E};return U=O,()=>{U===O&&(U=void 0)}}let Pe="";function xe(){if(requestAnimationFrame(xe),!L)return;const a=ut(L.play),E=p?.tick(a),O=a.toFixed(1)+" s";O!==Pe&&(We.value=O,Pe=O);for(const v of L.nodes){const C=s.get(v.id),{group:j}=C,te=B.get(v.id),G=E?.get(v.id),re=G?.stackWheel,ae=G?.trackBelt;if(C.asset?.target==="stack"&&(ae!==void 0&&C.top?C.belt||(C.belt=_e(C.asset,C.top),C.rolling=void 0,Se(C,C.belt.object),fe(C,v)):re&&!C.rolling&&(C.rolling=Ze(C.asset),C.belt=void 0,Se(C,C.rolling.object),fe(C,v)),C.belt)){const ue=ae!==void 0&&G?.trackTravel!==void 0?ae*G.trackTravel:void 0,Q=j.parent?.scale;C.belt.setTravel(ue,C.asset.size[1]*v.scale[2]*(Q?.z??1),C.asset.size[2]*v.settings.spacing*v.scale[1]*(Q?.y??1))}const ne=U?.id===v.id?U.patch:void 0,he=ne?.position??v.position;if(j.position.set(he[0]+a*v.velocity[0]+(te?.translation[0]??0)+(G?.translation?.[0]??0),he[1]+a*v.velocity[1]+(te?.translation[1]??0)+(G?.translation?.[1]??0),he[2]+a*v.velocity[2]+(te?.translation[2]??0)+(G?.translation?.[2]??0)),j.rotation.set(...(ne?.rotation??v.rotation).map((ue,Q)=>(ue+a*v.angularVelocity[Q]+(te?.rotation[Q]??0)+(G?.rotation?.[Q]??0))*me)),G?.wheelRotation){const[ue,Q,ce]=G.wheelRotation,Y=ue*(re?.rollScale??1),we=!!(re&&C.rolling);C.rolling?.setRoll(we?Y:0,v.settings.spacing),K.setFromEuler(P.set(we?0:Y*me,Q*(re?.steeringScale??1)*me,ce*me)),It(j,K,(C.centerY??0)*(C.content?.scale.y??1))}else C.rolling?.setRoll(0,v.settings.spacing)}const z=o?L.view.follow??null:null,k=z&&s.get(z)?.group;k&&(k.getWorldPosition(i),z===D?(i.sub(A),I.target.add(i),h.position.add(i),A.add(i)):A.copy(i)),D=z,n&&L.nodes.every(v=>!v.atlasId||$(v.id)||u.has(v.id))&&(ee(),n=!1,c.userData.framed=!0),t.dataset.backend==="gpu"?b?.render(y,h):R.render(c,h,L.view.supersampling,L.view.grid,0,!1,L.view)}return requestAnimationFrame(xe),{sync:Ke,previewTransform:qe,scripts:p}}function N(t){return document.getElementById(t)}const Ue=new URLSearchParams(location.search),Ie=Ue.get("session"),pe=Ue.get("playground")==="1";Ie&&/^[a-f0-9-]{36}$/.test(Ie)?Pt(Ie):(pe&&N("openInstruction").append(" --playground"),N("disconnected").hidden=!1);function Pt(t){const l=new URL("./__stack3_project/"+t,location.href).pathname,d=N("viewport");d.dataset.endpoint=l;const o=N("status"),g=N("editorMode"),y=N("playMode");N("compareMode").href="./compare.html?session="+t,g.href="./project.html?session="+t,y.href=g.href+"&playground=1",g.hidden=y.hidden=!1,(pe?y:g).setAttribute("aria-current","page"),N("workspace").hidden=!1,N("stageTitle").textContent=pe?"Playground":"Scene",o.value="Connecting…";let c,p="",P="",K="",D,A=Promise.resolve();const i=Mt(d,e=>b([{action:"view.set",patch:e}]),(e,n)=>{N("buildStatus").value=e,d.dataset.readyCount=String(n)},pe,(e,n,r)=>{const s=document.getElementById(Fe(e,n));s&&(s.textContent=r)}),x=[N("objectTab"),N("renderingTab")];function w(e){for(const[r,s]of x.entries())s.setAttribute("aria-selected",String(r===e)),s.tabIndex=r===e?0:-1,N(s.getAttribute("aria-controls")).hidden=r!==e;const n=e===1?"#rendering":"";g.hash=n,y.hash=n}w(location.hash==="#rendering"?1:0);for(const[e,n]of x.entries())n.addEventListener("click",()=>w(e)),n.addEventListener("keydown",r=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(r.key))return;r.preventDefault(),r.stopPropagation();const s=r.key==="Home"?0:r.key==="End"?x.length-1:(e+1)%x.length;w(s),x[s].focus()});function h(e){const n=e.nodes.filter(f=>f.atlasId),r=n.find(f=>f.id===D)??n[0];D=r?.id;const s=JSON.stringify([r?.id,r?.settings,n.map(({id:f,name:W})=>[f,W])]);if(s===P)return;P=s;const u=N("assetProperties"),T=u.querySelector("details")?.open,F=u.contains(document.activeElement)?document.activeElement?.id:void 0;if(!r){u.replaceChildren(ye("Import an atlas to configure asset rendering."));return}u.replaceChildren(le("Part",r.id,n.map(({id:f,name:W})=>[f,W]),f=>{D=f,c&&h(c)}),...U(r)),T&&(u.querySelector("details").open=!0),F&&document.getElementById(F)?.focus({preventScroll:!0})}function I(e){if(c&&e.revision<=c.revision)return;c?.view.selected!==e.view.selected&&e.nodes.some(M=>M.id===e.view.selected&&M.atlasId)&&(D=e.view.selected),c=e,document.documentElement.dataset.revision=String(e.revision),i.sync(e),N("projectName").textContent=e.name,document.title=e.name+" · "+(pe?"Playground":"Scene editor")+" · stack3.js",N("emptyStage").hidden=e.nodes.some(M=>M.atlasId),N("hierarchy").replaceChildren(q(e,null)),N("atlasLibrary").replaceChildren(...e.atlases.map(M=>{const m=document.createElement("div");m.className="atlas-row";const S=document.createElement("span");S.textContent=M.name;const ee=Z("Instance",()=>{const H=crypto.randomUUID();b([{action:"node.add",id:H,name:M.name,atlasId:M.id,parentId:c?.view.selected??null},{action:"view.set",patch:{selected:H}},{action:"view.frame"}])});return m.append(S,ee),e.nodes.some(H=>H.atlasId===M.id)||m.append(Z("Remove atlas",()=>b([{action:"atlas.remove",id:M.id}]))),m}));const n=e.nodes.find(M=>M.id===e.view.selected),r=i.scripts?.hasScripts();N("playTarget").textContent=r?e.play.startedAt===null?"Press Play to run script components.":"Script components running. Keyboard input is active.":n?n.name+" · Nudge with WASD":"Select an object to nudge it with WASD.",N("moveButtons").hidden=!!r;for(const M of N("moveButtons").querySelectorAll("button"))M.disabled=!n;const s=N("properties"),u=document.activeElement,T=u instanceof HTMLInputElement&&u.dataset.transformNode===n?.id?u.id:"",F=JSON.stringify([n,e.nodes.map(({id:M,name:m,parentId:S})=>[M,m,S])]);if(F!==p){const M=new Set(Array.from(s.querySelectorAll("details[open]")).map(m=>m.dataset.scriptEditor));p=F,s.replaceChildren(...n?L(n,e):[ye("Select an object to edit its properties.")]);for(const m of s.querySelectorAll("details[data-script-editor]"))m.open=M.has(m.dataset.scriptEditor);T&&document.getElementById(T)?.focus({preventScroll:!0})}h(e);const f=N("viewProperties"),W=JSON.stringify([e.view,e.nodes.filter(M=>M.scripts?.length).map(({id:M,name:m})=>[M,m])]);if(K!==W){K=W;const M=f.contains(document.activeElement)?document.activeElement?.id:void 0;f.replaceChildren(..._(e)),M&&document.getElementById(M)?.focus({preventScroll:!0})}const J=N("togglePlay");J.textContent=e.play.startedAt===null?"Play":"Pause",J.setAttribute("aria-pressed",String(e.play.startedAt!==null))}async function R(){try{const e=c?"?after="+c.revision:"",n=await fetch(l+"/state"+e);if(!n.ok)throw new Error("The live project server is unavailable.");n.status!==204&&(I(await n.json()),o.value="")}catch(e){o.value=e.message}}function b(e){return A=A.then(async()=>{if(c)try{const n=typeof e=="function"?e(c):e;if(!n.length){o.value="";return}const r=await fetch(l+"/actions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({revision:c.revision,actions:n})}),s=await r.json();if(r.status===409&&await R(),!r.ok)throw new Error(s.error||"Could not apply the edit.");I(s),o.value=""}catch(n){o.value=n.message}}),A}function q(e,n){const r=document.createElement("ul");r.className="scene-tree";for(const s of e.nodes.filter(u=>u.parentId===n)){const u=document.createElement("li"),T=Z(s.name,()=>b([{action:"view.set",patch:{selected:s.id}}])),F=document.createElement("small");F.textContent=s.atlasId?s.settings.format==="glb"?"3D":"2D":"Group",T.prepend(F),T.dataset.node=s.id,T.setAttribute("aria-pressed",String(s.id===e.view.selected)),u.append(T,q(e,s.id)),r.append(u)}return r}function L(e,n){const r=m=>b([{action:"node.set",id:e.id,patch:m}]),s=new Map(n.nodes.map(m=>[m.id,m.parentId])),u=n.nodes.filter(m=>{for(let S=m.id;S;S=s.get(S))if(S===e.id)return!1;return!0}),T=!e.parentId&&!e.atlasId,F=(m,S)=>{if(!T)return be(m,e[S],H=>r({[S]:H}));const ee=(H,$,V)=>{const de=[...H];return de[$]=V,de};return Nt(m,e.id,e[S],S==="position",(H,$)=>i.previewTransform(e.id,{[S]:ee(e[S],H,$)}),(H,$)=>b(V=>{const de=V.nodes.find(fe=>fe.id===e.id);return de?[{action:"node.set",id:e.id,patch:{[S]:ee(de[S],H,$)}}]:[]}))},f=[Ct("Name",e.name,m=>r({name:m})),le("Parent",e.parentId??"",[["","Scene root"],...u.map(m=>[m.id,m.name])],m=>b([{action:"node.move",id:e.id,parentId:m||null}])),X("Visible",e.visible,m=>r({visible:m})),F("Position","position"),F("Rotation (degrees)","rotation"),be("Scale",e.scale,m=>r({scale:m}))];if(T||n.nodes.some(m=>m.parentId===e.id)){const m=document.createElement("div");m.className="toolbar",m.append(Z("Apply Four-wheel",()=>b(S=>wt(S,e.id).actions)),Z("Apply Tracked Tank",()=>b(S=>yt(S,e.id).actions))),f.push(ge("Presets"),m)}f.push(ge("Motion"),be("Velocity (units/s)",e.velocity,m=>r({velocity:m})),be("Angular velocity (degrees/s)",e.angularVelocity,m=>r({angularVelocity:m}))),f.push(ge("Script components"));for(const m of e.scripts??[])f.push(B(e,m));const W=(m,S=crypto.randomUUID())=>b([{action:"script.set",nodeId:e.id,id:S,patch:m}]),J=document.createElement("div");J.className="toolbar",J.append(Z("Add script",()=>W({name:"Script",enabled:!1,fields:[],source:`function update({ dt, time, keys, fields, state, position, rotation, children }) {
16
- return {};
17
- }`})),Z("Add WASD vehicle",()=>W(mt))),e.atlasId&&!e.scripts?.some(m=>m.id==="sprite-stack-wheel")&&J.append(Z("Add Sprite Stack Wheel",()=>W(ht,"sprite-stack-wheel"))),f.push(J);const M=Z("Remove subtree",()=>b([{action:"node.remove",id:e.id}]));return M.className="danger",f.push(M),f}function U(e){const n=e.settings,r=f=>b([{action:"node.set",id:e.id,patch:{settings:f}}]),s=n.format==="stack",u=!s&&n.meshMethod==="contour",T=document.createElement("details"),F=document.createElement("summary");return F.textContent="Reconstruction settings",T.append(F,...u?[]:[se("Layers",n.layers,8,128,1,f=>r({layers:f}))],...!u||n.contourHub?[se(u?"Hub segments":"Texture resolution",n.resolution,16,192,1,f=>r({resolution:f}))]:[],...s?[se("Spacing",n.spacing,.05,20,.05,f=>r({spacing:f}))]:[],se("Height",n.height,.01,100,.01,f=>r({height:f})),se("Background threshold",n.threshold,0,255,1,f=>r({threshold:f})),le("Pivot",n.pivot,[["ground","Ground"],["center","Center"]],f=>r({pivot:f})),...u?[]:[le("Cross-section",n.profile,[["silhouette","From silhouettes"],["round","Round"],["round-base","Round above square base"]],f=>r({profile:f}))]),[le("Asset type",u?"contour":n.format,[["stack","Sprite stack"],["glb","Marching Cubes (3D mesh)"],["contour","Contour extrusion (3D mesh)"]],f=>r({format:f==="stack"?"stack":"glb",meshMethod:f==="contour"?"contour":"marching-cubes"})),...s?[]:[le("Texture projection",n.textureProjection??"auto",[["auto","Automatic (multi-view)"],["top-contour","Upper contour from TOP"]],f=>r({textureProjection:f}))],...u?[X("Centered round hub",n.contourHub??!1,f=>r({contourHub:f}))]:[],ye(s?"Multi-view texturing blends colors from the atlas views.":"Multi-view texturing projects atlas views onto the mesh."),X("Material lighting",n.lighting,f=>r({lighting:f})),...s?[X("Pixel art",n.pixelArt,f=>r({pixelArt:f})),X("Smooth edges",n.smoothEdges,f=>r({smoothEdges:f}))]:[],T]}function B(e,n){const r=document.createElement("section");r.className="script-component";const s=S=>b([{action:"script.set",nodeId:e.id,id:n.id,patch:S}]),u=document.createElement("output");u.id=Fe(e.id,n.id);const T=u.id;u.textContent=n.enabled&&i.scripts?.status(e.id,n.id)||"",r.append(ge(n.name),X("Enabled",n.enabled,S=>s({enabled:S}),T+"-enabled"),u);for(const S of n.fields)r.append(se(S.label,S.value,S.min,S.max,S.step,ee=>{ee<S.min||ee>S.max||b(H=>{const $=H.nodes.find(V=>V.id===e.id)?.scripts?.find(V=>V.id===n.id);return $?[{action:"script.set",nodeId:e.id,id:n.id,patch:{fields:$.fields.map(V=>V.name===S.name?{...V,value:ee}:V)}}]:[]})},T+"-field-"+S.name));const F=document.createElement("details");F.dataset.scriptEditor=T;const f=document.createElement("summary");f.textContent="Edit script";const W=document.createElement("input");W.type="text",W.value=n.name;const J=document.createElement("textarea");J.value=n.source,J.rows=9,J.spellcheck=!1;const M=document.createElement("textarea");M.value=JSON.stringify(n.fields,null,2),M.rows=6,M.spellcheck=!1,W.id=T+"-name",J.id=T+"-source",M.id=T+"-fields";const m=document.createElement("output");return m.setAttribute("role","status"),F.append(f,ie("Name",W),ie("JavaScript",J),ie("Inspector fields (JSON)",M),m,Z("Save script",()=>{try{const S=JSON.parse(M.value);if(!Array.isArray(S))throw new Error("Use a JSON array for inspector fields.");s({name:W.value,source:J.value,fields:S}),m.textContent=""}catch(S){m.textContent=S.message}})),r.append(F,Z("Remove script",()=>b([{action:"script.remove",nodeId:e.id,id:n.id}]))),r}function _(e){const n=e.view,r=u=>b([{action:"view.set",patch:u}]),s=e.nodes.filter(u=>u.scripts?.length||u.id===n.follow);return[le("Renderer",n.backend,[["cpu","CPU"],["gpu","GPU"]],u=>r({backend:u})),X("Grid",n.grid,u=>r({grid:u})),X("Supersampling",n.supersampling,u=>r({supersampling:u})),ge("CPU rendering"),X("Detail Normals",!!n.detailNormals,u=>r({detailNormals:u,backend:"cpu"})),X("Subpixel AA",!!n.subpixelAA,u=>r({subpixelAA:u,backend:"cpu"})),X("Specular AA",!!n.specularAA,u=>r({specularAA:u,backend:"cpu"})),ye("Detail Normals and Specular AA use each part’s Material lighting setting."),...pe&&s.length?[le("Follow object",n.follow??"",[["","None"],...s.map(u=>[u.id,u.name])],u=>r({follow:u||null}))]:[],se("Squash",n.squash,.2,1,.01,u=>r({squash:u})),se("Zoom",n.scale,.1,10,.05,u=>r({scale:u})),se("Heading",n.yaw,-360,360,1,u=>r({yaw:u}))]}if(N("newGroup").addEventListener("click",()=>{const e=crypto.randomUUID();b([{action:"node.add",id:e,name:"Group",parentId:c?.view.selected??null},{action:"view.set",patch:{selected:e}}])}),N("frameScene").addEventListener("click",()=>b([{action:"view.frame"}])),N("stepTime").addEventListener("click",()=>b([{action:"play.step",seconds:1}])),N("resetTime").addEventListener("click",()=>b([{action:"play.reset"}])),N("togglePlay").addEventListener("click",()=>{b([{action:c?.play.startedAt===null?"play.start":"play.pause"}])}),pe){N("playControls").hidden=!1;const e={KeyA:[-.25,0,0],KeyD:[.25,0,0],KeyW:[0,0,-.25],KeyS:[0,0,.25]},n=s=>{const u=c?.view.selected;u&&e[s]&&b([{action:"play.nudge",id:u,translation:e[s]}])};for(const[s,u]of[["KeyA","Left"],["KeyW","Forward"],["KeyS","Back"],["KeyD","Right"]])N("moveButtons").append(Z(u,()=>n(s)));const r=s=>s instanceof Element&&!!s.closest('input:not([type="checkbox"]),select,textarea,[contenteditable]');document.addEventListener("keydown",s=>{if(!(s.altKey||s.ctrlKey||s.metaKey||r(s.target))&&!(s.code==="Space"&&s.target instanceof HTMLInputElement&&s.target.type==="checkbox")){if(i.scripts?.hasScripts()){if(c?.play.startedAt==null)return;(Object.hasOwn(e,s.code)||s.code.startsWith("Arrow")||s.code==="Space")&&s.preventDefault(),i.scripts.keyDown(s.code);return}s.repeat||!Object.hasOwn(e,s.code)||(s.preventDefault(),n(s.code))}}),document.addEventListener("keyup",s=>i.scripts?.keyUp(s.code)),document.addEventListener("focusin",s=>{r(s.target)&&i.scripts?.clearKeys()}),window.addEventListener("blur",()=>i.scripts?.clearKeys()),document.addEventListener("visibilitychange",()=>i.scripts?.clearKeys())}const oe=N("atlasFiles");N("importAtlases").addEventListener("click",()=>oe.click()),oe.addEventListener("change",async()=>{const e=[...oe.files??[]];if(oe.value="",!e.length||!c)return;const n=c.view.selected;try{const r=gt(N("importLayout").value).join(","),s=[];let u;for(const T of e){if(T.size>16*1024*1024)throw new Error("Use PNGs of up to 16 MB per file.");const{png:F,hash:f}=await xt(T,r),W=crypto.randomUUID(),J=T.name.replace(/\.png$/i,"");s.push({action:"atlas.embed",id:f,name:J,png:F,layout:r},{action:"node.add",id:W,name:J,parentId:n,atlasId:f}),u=W}s.push({action:"view.set",patch:{selected:u}},{action:"view.frame"}),b(s)}catch(r){o.value=r.message}}),R(),window.setInterval(()=>{R()},650)}function Fe(t,l){return"script-status-"+t+":"+l}async function xt(t,l){const d=new Uint8Array(await t.arrayBuffer()),o=new TextEncoder().encode(l),g=new Uint8Array(o.length+d.length);g.set(o),g.set(d,o.length);const y=Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256",g)),p=>p.toString(16).padStart(2,"0")).join("");let c="";for(let p=0;p<d.length;p+=8192)c+=String.fromCharCode(...d.subarray(p,p+8192));return{hash:y,png:btoa(c)}}function Z(t,l){const d=document.createElement("button");return d.type="button",d.textContent=t,d.addEventListener("click",l),d}function ge(t){const l=document.createElement("h3");return l.textContent=t,l}function ye(t){const l=document.createElement("p");return l.className="muted",l.textContent=t,l}function ie(t,l){const d=document.createElement("div");d.className="field";const o=document.createElement("label");return o.append(t),l.id||="field-"+t.toLowerCase().replaceAll(/[^a-z0-9]/g,"-"),l.tagName==="DIV"?o.id=l.id+"-label":o.htmlFor=l.id,d.append(o,l),d}function Ct(t,l,d){const o=document.createElement("input");return o.type="text",o.value=l,o.addEventListener("change",()=>d(o.value)),ie(t,o)}function se(t,l,d,o,g,y,c=""){const p=document.createElement("input");return p.type="number",p.value=String(Number(l.toFixed(4))),p.min=String(d),p.max=String(o),p.step=String(g),p.id=c,p.addEventListener("change",()=>{Number.isFinite(p.valueAsNumber)&&y(p.valueAsNumber)}),ie(t,p)}function X(t,l,d,o=""){const g=document.createElement("input");return g.type="checkbox",g.checked=l,g.id=o,g.addEventListener("change",()=>d(g.checked)),ie(t,g)}function le(t,l,d,o){const g=document.createElement("select");for(const[y,c]of d)g.add(new Option(c,y,!1,y===l));return g.addEventListener("change",()=>o(g.value)),ie(t,g)}function Nt(t,l,d,o,g,y){const c=document.createElement("div");c.className="transform-sliders",c.setAttribute("role","group");const p=ie(t,c);c.setAttribute("aria-labelledby",c.id+"-label");const P=o?1e4:360;return d.forEach((K,D)=>{const A=["X","Y","Z"][D],i=document.createElement("div"),x=document.createElement("label"),w=document.createElement("input"),h=document.createElement("input"),I=o?Math.max(5,Math.ceil(Math.abs(K))):P;x.textContent=A,w.type="range",w.id=c.id+"-"+D,x.htmlFor=w.id,w.dataset.transformNode=l,w.setAttribute("aria-label",t+" "+A+" slider"),w.min=String(-I),w.max=String(I),w.step=o?"0.01":"1",w.value=String(K),h.type="number",h.setAttribute("aria-label",t+" "+A),h.min=String(-P),h.max=String(P),h.step="any",h.value=String(K);let R;w.addEventListener("input",()=>{h.value=w.value,R=g(D,w.valueAsNumber)}),w.addEventListener("change",()=>{const b=R;R=void 0,y(D,w.valueAsNumber).finally(b)}),w.addEventListener("pointercancel",()=>{R?.(),R=void 0,w.value=h.value=String(K)}),h.addEventListener("change",()=>{h.validity.valid&&Number.isFinite(h.valueAsNumber)&&y(D,h.valueAsNumber)}),i.append(x,w,h),c.append(i)}),p}function be(t,l,d){const o=document.createElement("div");o.className="field-vector",o.setAttribute("role","group");const g=l.map((c,p)=>{const P=document.createElement("input");return P.type="number",P.step="any",P.value=String(c),P.setAttribute("aria-label",t+" "+["X","Y","Z"][p]),P.addEventListener("change",()=>{const K=g.map(D=>D.valueAsNumber);K.every(Number.isFinite)&&d(K)}),P});o.append(...g);const y=ie(t,o);return o.setAttribute("aria-labelledby",o.id+"-label"),y}
@@ -1,21 +0,0 @@
1
- (function(){"use strict";const R=["top","left","front","rear","right","bottom"];function hn(t){const e=[137,80,78,71,13,10,26,10];if(t.length<33||e.some((i,a)=>t[a]!==i)||String.fromCharCode(...t.subarray(12,16))!=="IHDR")throw new Error("Expected a PNG image.");const n=new DataView(t.buffer,t.byteOffset,t.byteLength),r=n.getUint32(16),o=n.getUint32(20);if(!r||!o||r>8192||o>8192||r*o>16e6)throw new Error("PNG dimensions exceed the 8192 px or 16 MP input limit.");return{width:r,height:o}}function ut(t){const e=t.split(",").map(n=>n.trim());if(e.some(n=>!R.includes(n)))throw new Error("Use directions top, left, front, rear, right, and bottom.");if(e.length!==4&&e.length!==6||new Set(e).size!==e.length||R.slice(0,e.length).some(n=>!e.includes(n)))throw new Error("A layout needs the four required directions or all six, with no duplicates.");return e}function Gt(t,e){const{width:n,height:r}=t,o=new Uint8Array(t.data),i=n*r;for(let l=3;l<o.length;l+=4)if(o[l]<128)return{width:n,height:r,data:o};const a=new Uint8Array(i),s=new Uint32Array(i);let c=0,f=0;function h(l){if(a[l])return;a[l]=1;const A=l*4;Math.min(o[A],o[A+1],o[A+2])>=e&&(s[f++]=l)}for(let l=0;l<n;l++)h(l),h((r-1)*n+l);for(let l=1;l<r-1;l++)h(l*n),h(l*n+n-1);for(;c<f;){const l=s[c++];o[l*4+3]=0;const A=l%n;A&&h(l-1),A+1<n&&h(l+1),l>=n&&h(l-n),l+n<i&&h(l+n)}return{width:n,height:r,data:o}}function Yt(t,e){const{left:n,top:r,width:o,height:i}=e,a=new Uint8Array(o*i*4);for(let s=0;s<i;s++){const c=((r+s)*t.width+n)*4;a.set(t.data.subarray(c,c+o*4),s*o*4)}return{width:o,height:i,data:a}}function Jt(t,e){const{left:n,top:r,width:o,height:i}=e;let a=n+o,s=-1,c=r+i,f=-1;for(let h=r;h<r+i;h++)for(let l=n;l<n+o;l++)t.data[(h*t.width+l)*4+3]<128||(a=Math.min(a,l),s=Math.max(s,l),c=Math.min(c,h),f=Math.max(f,h));return s<0?null:{left:a,top:c,width:s-a+1,height:f-c+1}}function Pt(t){const e=[];let n=-1;for(let r=0;r<=t.length;r++)t[r]?n<0&&(n=r):n>=0&&(e.push([n,r]),n=-1);return e}function Nt(t,e,n){const r=new Uint8Array(t.width);for(let o=e;o<n;o++)for(let i=0;i<t.width;i++)t.data[(o*t.width+i)*4+3]>=128&&(r[i]=1);return Pt(r)}function ln(t,e){ut(e.join(","));let n=Nt(t,0,t.height).map(([r,o])=>({left:r,top:0,width:o-r,height:t.height}));if(n.length!==e.length){const r=new Uint8Array(t.height);for(let o=0;o<t.height;o++)for(let i=0;i<t.width;i++)if(t.data[(o*t.width+i)*4+3]>=128){r[o]=1;break}n=Pt(r).flatMap(([o,i])=>Nt(t,o,i).map(([a,s])=>({left:a,top:o,width:s-a,height:i-o})))}if(n.length!==e.length)throw new Error(`Expected ${e.length} separated views, found ${n.length}. Use clear gutters or individual PNGs.`);return n.map(r=>Jt(t,r))}function An(t,e,n=238){const r=Gt(t,n);return Object.fromEntries(ln(r,e).map((o,i)=>{const a=Yt(r,o),s=a.width+2,c=a.height+2,f=new Uint8Array(s*c*4);for(let h=0;h<a.height;h++)f.set(a.data.subarray(h*a.width*4,(h+1)*a.width*4),((h+1)*s+1)*4);return[e[i],{width:s,height:c,data:f}]}))}function un(t,e=238){ut(Object.keys(t).join(","));const n=Object.entries(t);return Object.fromEntries(n.map(([r,o])=>{const i=Gt(o,e),a=Jt(i,{left:0,top:0,width:i.width,height:i.height});if(!a)throw new Error(`The ${r} view has an empty silhouette.`);return[r,Yt(i,a)]}))}function gn(t){const{top:e,left:n,front:r,rear:o}=t,i=n.width/n.height*e.width/e.height,a=r.width/r.height,s=[];return Math.abs(i/a-1)>.2&&s.push("Top, left, and front proportions differ by more than 20%. Check alignment."),Math.abs(o.width/o.height/a-1)>.2&&s.push("Front and rear proportions differ by more than 20%."),{views:Object.entries(t).map(([f,h])=>({direction:f,width:h.width,height:h.height})),warnings:s}}const et=t=>Math.max(0,Math.min(1,t));function wn(t,e){const{positions:n,indices:r,size:o}=t,i=Math.max(o[0],o[1]),a=Math.max(1,Math.round(e*o[0]/i)),s=Math.max(1,Math.round(e*o[1]/i)),c=A=>Math.min(a-1,Math.floor(et(A/o[0]+.5)*a)),f=A=>Math.min(s-1,Math.floor(et(A/o[1]+.5)*s)),h=Array.from({length:a*s},()=>[]),l=new Uint8Array(r.length/3);for(let A=0;A<r.length;A+=3){const g=r[A]*3,u=r[A+1]*3,B=r[A+2]*3;if((n[u+2]-n[g+2])*(n[B]-n[g])-(n[u]-n[g])*(n[B+2]-n[g+2])<=0)continue;l[A/3]=1;const x=c(Math.min(n[g],n[u],n[B])),d=c(Math.max(n[g],n[u],n[B])),w=f(Math.min(n[g+2],n[u+2],n[B+2])),y=f(Math.max(n[g+2],n[u+2],n[B+2]));for(let I=w;I<=y;I++)for(let F=x;F<=d;F++)h[I*a+F].push(A)}for(let A=0;A<r.length;A+=3){if(!l[A/3])continue;const g=r[A]*3,u=r[A+1]*3,B=r[A+2]*3,C=(n[g]+n[u]+n[B])/3,x=(n[g+2]+n[u+2]+n[B+2])/3,d=(n[g+1]+n[u+1]+n[B+1])/3;for(const w of h[f(x)*a+c(C)]){if(w===A)continue;const y=r[w]*3,I=r[w+1]*3,F=r[w+2]*3,Q=n[I]-n[y],m=n[I+2]-n[y+2],p=n[F]-n[y],M=n[F+2]-n[y+2],E=Q*M-m*p,v=((C-n[y])*M-(x-n[y+2])*p)/E,b=(Q*(x-n[y+2])-m*(C-n[y]))/E;if(v<0||b<0||v+b>1)continue;if(n[y+1]+v*(n[I+1]-n[y+1])+b*(n[F+1]-n[y+1])>d+o[2]*1e-6){l[A/3]=0;break}}}return l}function dn(t,e,n,r){const{positions:o,normals:i,uvs:a,indices:s,texture:c,size:f}=t;n=Math.max(1,Math.min(192,Math.round(n)||96));const h=wn(t,n),l=f[1]>=f[0]?2:0,A=l===2?f[1]:f[0],g=m=>Math.min(n-1,Math.floor(et(m/A+.5)*n)),u=new Float32Array(n).fill(-1/0);for(let m=0;m<o.length;m+=3){const p=g(o[m+l]);u[p]=Math.max(u[p],o[m+1])}const B=f[2]*Math.max(.1,1.5/r),C=new Map;let x=0;for(let m=0;m<s.length;m+=3){const p=s[m]*3,M=s[m+1]*3,E=s[m+2]*3,v=(o[p+l]+o[M+l]+o[E+l])/3,b=(o[p+1]+o[M+1]+o[E+1])/3>=u[g(v)]-B,k=o[M]-o[p],U=o[M+1]-o[p+1],D=o[M+2]-o[p+2],L=o[E]-o[p],Y=o[E+1]-o[p+1],S=o[E+2]-o[p+2],N=D*L-k*S,J=Math.abs(U*S-D*Y),K=Math.abs(k*Y-U*L),T=b&&N===0&&Math.abs(v)<A*.46&&(l===2?K>J:J>K);if(!(!h[m/3]&&!T)){x++;for(let H=m;H<m+3;H++){const z=s[H];C.has(z)||C.set(z,o.length/3+C.size),s[H]=C.get(z)}}}if(!x)return 0;const d=Math.min(1,512/Math.max(e.width,e.height)),w=Math.max(1,Math.round(e.width*d)),y=Math.max(1,Math.round(e.height*d));for(let m=-1;m<=y;m++){const p=Math.min(y-1,Math.max(0,m)),M=Math.floor((p+.5)*e.height/y)*e.width,E=k=>(M+Math.floor((k+.5)*e.width/w))*4;let v=0,b=w-1;for(;v<=b&&e.data[E(v)+3]<128;)v++;for(;b>=v&&e.data[E(b)+3]<128;)b--;if(!(v>b))for(let k=-1;k<=w;k++){if(k>=v&&k<=b)continue;const U=E(k<v?v:b);c.data.set(e.data.subarray(U,U+3),((m+1)*c.width+k+1)*4)}}const I=new Float32Array(o.length+C.size*3),F=new Float32Array(I.length),Q=new Float32Array(a.length+C.size*2);I.set(o),F.set(i),Q.set(a);for(const[m,p]of C)I.set(o.subarray(m*3,m*3+3),p*3),F.set(i.subarray(m*3,m*3+3),p*3),Q[p*2]=(1.5+et(o[m*3]/f[0]+.5)*(w-1))/c.width,Q[p*2+1]=(1.5+et(.5-o[m*3+2]/f[1])*(y-1))/c.height;return Object.assign(t,{positions:I,normals:F,uvs:Q}),x}function gt(t,e){return t==null||e==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function xn(t,e){return t==null||e==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function zt(t){let e,n,r;t.length!==2?(e=gt,n=(s,c)=>gt(t(s),c),r=(s,c)=>t(s)-c):(e=t===gt||t===xn?t:Cn,n=t,r=t);function o(s,c,f=0,h=s.length){if(f<h){if(e(c,c)!==0)return h;do{const l=f+h>>>1;n(s[l],c)<0?f=l+1:h=l}while(f<h)}return f}function i(s,c,f=0,h=s.length){if(f<h){if(e(c,c)!==0)return h;do{const l=f+h>>>1;n(s[l],c)<=0?f=l+1:h=l}while(f<h)}return f}function a(s,c,f=0,h=s.length){const l=o(s,c,f,h-1);return l>f&&r(s[l-1],c)>-r(s[l],c)?l-1:l}return{left:o,center:a,right:i}}function Cn(){return 0}function Bn(t){return t===null?NaN:+t}zt(gt),zt(Bn).center;function Mn(t,e){let n=0;for(let r of t)r!=null&&(r=+r)>=r&&++n;return n}function yn(t,e){let n,r;if(e===void 0)for(const o of t)o!=null&&(n===void 0?o>=o&&(n=r=o):(n>o&&(n=o),r<o&&(r=o)));else{let o=-1;for(let i of t)(i=e(i,++o,t))!=null&&(n===void 0?i>=i&&(n=r=i):(n>i&&(n=i),r<i&&(r=i)))}return[n,r]}const mn=Math.sqrt(50),pn=Math.sqrt(10),Qn=Math.sqrt(2);function wt(t,e,n){const r=(e-t)/Math.max(0,n),o=Math.floor(Math.log10(r)),i=r/Math.pow(10,o),a=i>=mn?10:i>=pn?5:i>=Qn?2:1;let s,c,f;return o<0?(f=Math.pow(10,-o)/a,s=Math.round(t*f),c=Math.round(e*f),s/f<t&&++s,c/f>e&&--c,f=-f):(f=Math.pow(10,o)*a,s=Math.round(t/f),c=Math.round(e/f),s*f<t&&++s,c*f>e&&--c),c<s&&.5<=n&&n<2?wt(t,e,n*2):[s,c,f]}function vn(t,e,n){if(e=+e,t=+t,n=+n,!(n>0))return[];if(t===e)return[t];const r=e<t,[o,i,a]=r?wt(e,t,n):wt(t,e,n);if(!(i>=o))return[];const s=i-o+1,c=new Array(s);if(r)if(a<0)for(let f=0;f<s;++f)c[f]=(i-f)/-a;else for(let f=0;f<s;++f)c[f]=(i-f)*a;else if(a<0)for(let f=0;f<s;++f)c[f]=(o+f)/-a;else for(let f=0;f<s;++f)c[f]=(o+f)*a;return c}function En(t,e,n){return e=+e,t=+t,n=+n,wt(t,e,n)[2]}function In(t,e,n){let r;for(;;){const o=En(t,e,n);if(o===r||o===0||!isFinite(o))return[t,e];if(o>0){const i=Math.ceil(t/o),a=Math.floor(e/o);t=(i-(i*o>t))*o,e=(a+(a*o<e))*o}else if(o<0){const i=-o,a=Math.ceil(t*i),s=Math.floor(e*i);t=(a-(a/i>t))/i,e=(s+(s/i<e))/i}r=o}}function Fn(t){return Math.max(1,Math.ceil(Math.log(Mn(t))/Math.LN2)+1)}var bn=Array.prototype,kn=bn.slice;function Un(t,e){return t-e}function Dn(t){for(var e=0,n=t.length,r=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];++e<n;)r+=t[e-1][1]*t[e][0]-t[e-1][0]*t[e][1];return r}var St=t=>()=>t;function Ln(t,e){for(var n=-1,r=e.length,o;++n<r;)if(o=Hn(t,e[n]))return o;return 0}function Hn(t,e){for(var n=e[0],r=e[1],o=-1,i=0,a=t.length,s=a-1;i<a;s=i++){var c=t[i],f=c[0],h=c[1],l=t[s],A=l[0],g=l[1];if(Kn(c,l,e))return 0;h>r!=g>r&&n<(A-f)*(r-h)/(g-h)+f&&(o=-o)}return o}function Kn(t,e,n){var r;return Gn(t,e,n)&&Yn(t[r=+(t[0]===e[0])],n[r],e[r])}function Gn(t,e,n){return(e[0]-t[0])*(n[1]-t[1])===(n[0]-t[0])*(e[1]-t[1])}function Yn(t,e,n){return t<=e&&e<=n||n<=e&&e<=t}function Jn(){}var X=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function Pn(){var t=1,e=1,n=Fn,r=c;function o(f){var h=n(f);if(Array.isArray(h))h=h.slice().sort(Un);else{const l=yn(f,Nn);for(h=vn(...In(l[0],l[1],h),h);h[h.length-1]>=l[1];)h.pop();for(;h[1]<l[0];)h.shift()}return h.map(l=>i(f,l))}function i(f,h){const l=h==null?NaN:+h;if(isNaN(l))throw new Error(`invalid value: ${h}`);var A=[],g=[];return a(f,l,function(u){r(u,f,l),Dn(u)>0?A.push([u]):g.push(u)}),g.forEach(function(u){for(var B=0,C=A.length,x;B<C;++B)if(Ln((x=A[B])[0],u)!==-1){x.push(u);return}}),{type:"MultiPolygon",value:h,coordinates:A}}function a(f,h,l){var A=new Array,g=new Array,u,B,C,x,d,w;for(u=B=-1,x=_(f[0],h),X[x<<1].forEach(y);++u<t-1;)C=x,x=_(f[u+1],h),X[C|x<<1].forEach(y);for(X[x<<0].forEach(y);++B<e-1;){for(u=-1,x=_(f[B*t+t],h),d=_(f[B*t],h),X[x<<1|d<<2].forEach(y);++u<t-1;)C=x,x=_(f[B*t+t+u+1],h),w=d,d=_(f[B*t+u+1],h),X[C|x<<1|d<<2|w<<3].forEach(y);X[x|d<<3].forEach(y)}for(u=-1,d=f[B*t]>=h,X[d<<2].forEach(y);++u<t-1;)w=d,d=_(f[B*t+u+1],h),X[d<<2|w<<3].forEach(y);X[d<<3].forEach(y);function y(I){var F=[I[0][0]+u,I[0][1]+B],Q=[I[1][0]+u,I[1][1]+B],m=s(F),p=s(Q),M,E;(M=g[m])?(E=A[p])?(delete g[M.end],delete A[E.start],M===E?(M.ring.push(Q),l(M.ring)):A[M.start]=g[E.end]={start:M.start,end:E.end,ring:M.ring.concat(E.ring)}):(delete g[M.end],M.ring.push(Q),g[M.end=p]=M):(M=A[p])?(E=g[m])?(delete A[M.start],delete g[E.end],M===E?(M.ring.push(Q),l(M.ring)):A[E.start]=g[M.end]={start:E.start,end:M.end,ring:E.ring.concat(M.ring)}):(delete A[M.start],M.ring.unshift(F),A[M.start=m]=M):A[m]=g[p]={start:m,end:p,ring:[F,Q]}}}function s(f){return f[0]*2+f[1]*(t+1)*4}function c(f,h,l){f.forEach(function(A){var g=A[0],u=A[1],B=g|0,C=u|0,x=vt(h[C*t+B]);g>0&&g<t&&B===g&&(A[0]=Ot(g,vt(h[C*t+B-1]),x,l)),u>0&&u<e&&C===u&&(A[1]=Ot(u,vt(h[(C-1)*t+B]),x,l))})}return o.contour=i,o.size=function(f){if(!arguments.length)return[t,e];var h=Math.floor(f[0]),l=Math.floor(f[1]);if(!(h>=0&&l>=0))throw new Error("invalid size");return t=h,e=l,o},o.thresholds=function(f){return arguments.length?(n=typeof f=="function"?f:Array.isArray(f)?St(kn.call(f)):St(f),o):n},o.smooth=function(f){return arguments.length?(r=f?c:Jn,o):r===c},o}function Nn(t){return isFinite(t)?t:NaN}function _(t,e){return t==null?!1:+t>=e}function vt(t){return t==null||isNaN(t=+t)?-1/0:t}function Ot(t,e,n,r){const o=r-e,i=n-e,a=isFinite(o)||isFinite(i)?o/i:Math.sign(o)/Math.sign(i);return isNaN(a)?t:t+a-.5}const ot=new Set;let Et=!1;function zn(t,e,n=2){const r=e&&e.length,o=r?e[0]*n:t.length;ot.size&&ot.clear();let i=jt(t,0,o,n,!0);const a=[];if(!i||i.next===i.prev)return a;let s=0,c=0,f=0;if(r&&(i=Zn(t,e,i,n)),t.length>80*n){s=t[0],c=t[1];let h=s,l=c;for(let A=n;A<o;A+=n){const g=t[A],u=t[A+1];g<s&&(s=g),u<c&&(c=u),g>h&&(h=g),u>l&&(l=u)}f=Math.max(h-s,l-c),f=f!==0?32767/f:0}return It(i,a,s,c,f),a}function jt(t,e,n,r,o){let i=null;if(o===ie(t,e,n,r)>0)for(let a=e;a<n;a+=r)i=_t(a/r|0,t[a],t[a+1],i);else for(let a=n-r;a>=e;a-=r)i=_t(a/r|0,t[a],t[a+1],i);return i&&st(i,i.next)&&(at(i),i=i.next),i}function W(t,e=t){const n=e===t;let r=t,o;do o=!1,r!==r.next&&(ot.size===0||!ot.has(r))&&(st(r,r.next)||P(r.prev,r,r.next)===0)?((n||r===e)&&(e=r.prev),Et=!0,at(r),r=r.prev,o=!0):(n||r!==e)&&(r=r.next,o=!n);while(o||r!==e);return e}function It(t,e,n,r,o){o&&qn(t,n,r,o);let i=t,a=!1;for(;t.prev!==t.next;){const s=t.prev,c=t.next;if(P(s,t,c)<0&&(o?On(t,n,r,o):Sn(t))){e.push(s.i,t.i,c.i),at(t),t=c,i=c;continue}if(t=c,t===i){if(Et=!1,t=W(t),Et){i=t;continue}if(!a){t=jn(t,e),i=t,a=!0;continue}Tn(t,e,n,r,o);break}}}function Sn(t){const e=t.prev,n=t,r=t.next,o=e.x,i=n.x,a=r.x,s=e.y,c=n.y,f=r.y,h=Math.min(o,i,a),l=Math.min(s,c,f),A=Math.max(o,i,a),g=Math.max(s,c,f);let u=r.next;for(;u!==e;){if(u.x>=h&&u.x<=A&&u.y>=l&&u.y<=g&&!(o===u.x&&s===u.y)&&Ct(o,s,i,c,a,f,u.x,u.y)&&P(u.prev,u,u.next)>=0)return!1;u=u.next}return!0}function On(t,e,n,r){const o=t.prev,i=t,a=t.next,s=o.x,c=i.x,f=a.x,h=o.y,l=i.y,A=a.y,g=Math.min(s,c,f),u=Math.min(h,l,A),B=Math.max(s,c,f),C=Math.max(h,l,A),x=Ut(g,u,e,n,r),d=Ut(B,C,e,n,r);let w=t.prevZ;for(;w&&w.z>=x;){if(w.x>=g&&w.x<=B&&w.y>=u&&w.y<=C&&w!==a&&!(s===w.x&&h===w.y)&&Ct(s,h,c,l,f,A,w.x,w.y)&&P(w.prev,w,w.next)>=0)return!1;w=w.prevZ}let y=t.nextZ;for(;y&&y.z<=d;){if(y.x>=g&&y.x<=B&&y.y>=u&&y.y<=C&&y!==a&&!(s===y.x&&h===y.y)&&Ct(s,h,c,l,f,A,y.x,y.y)&&P(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function jn(t,e){let n=t,r=!1;do{const o=n.prev,i=n.next.next;Vt(o,n,n.next,i,!1)&&ct(o,i)&&ct(i,o)&&(e.push(o.i,n.i,i.i),at(n),at(n.next),n=t=i,r=!0),n=n.next}while(n!==t);return r?W(n):n}function Tn(t,e,n,r,o){let i=t;do{let a=i.next.next;for(;a!==i.prev;){if(i.i!==a.i&&ee(i,a)){let s=$t(i,a);i=W(i,i.next),s=W(s,s.next),It(i,e,n,r,o),It(s,e,n,r,o);return}a=a.next}i=i.next}while(i!==t)}let Ft=!1;function Zn(t,e,n,r){const o=[];for(let i=0,a=e.length;i<a;i++){const s=e[i]*r,c=i<a-1?e[i+1]*r:t.length,f=jt(t,s,c,r,!1);f===f.next&&ot.add(f),o.push(ne(f))}o.sort(Rn),Vn(t.length/r,e.length),Zt(n,n),Ft=!0;for(let i=0;i<o.length;i++)n=Xn(o[i],n);return Ft=!1,W(n)}function Rn(t,e){return t.x-e.x||t.y-e.y||(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}function Xn(t,e){const n=_n(t,e);if(!n)return e;const r=$t(n,t),o=r.next;return Zt(n,o.next),W(r,r.next),W(n,n.next)}const Tt=16;let G=new Float64Array(0),dt=0;const bt=[],kt=[];function Vn(t,e){const n=Math.ceil((t+2*e)/Tt)+e+2;G.length<n*4&&(G=new Float64Array(n*4)),dt=0}function Zt(t,e){let n=t;do{const r=dt++;bt[r]=n;let o=n.x,i=n.y,a=n.x,s=n.y,c=0;do{const h=n.next;n.z=r,h.x<o&&(o=h.x),h.x>a&&(a=h.x),h.y<i&&(i=h.y),h.y>s&&(s=h.y),n=h}while(++c<Tt&&n!==e);kt[r]=n;const f=r*4;G[f]=o,G[f+1]=i,G[f+2]=a,G[f+3]=s}while(n!==e)}function $n(t,e){const n=t.z*4;e.x<G[n]&&(G[n]=e.x),e.y<G[n+1]&&(G[n+1]=e.y),e.x>G[n+2]&&(G[n+2]=e.x),e.y>G[n+3]&&(G[n+3]=e.y)}function Rt(t){let e=kt[t];for(;e.prev.next!==e;)e=e.next;return kt[t]=e,e}function Xt(t){let e=bt[t];for(;e.prev.next!==e;)e=e.next;return bt[t]=e,e}function _n(t,e){let n=e;const r=t.x,o=t.y;let i=-1/0,a;if(st(t,n))return n;for(let A=0,g=0;A<dt;A++,g+=4){if(o<G[g+1]||o>G[g+3]||G[g]>r||G[g+2]<=i)continue;const u=Rt(A);n=Xt(A);do{if(n.prev.next===n){if(st(t,n.next))return n.next;if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){const B=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(B<=r&&B>i&&(i=B,a=n.x<n.next.x?n:n.next,B===r))return a}}n=n.next}while(n!==u)}if(!a)return null;const s=a.x,c=a.y,f=Math.min(o,c),h=Math.max(o,c);let l=1/0;for(let A=0,g=0;A<dt;A++,g+=4){if(G[g+2]<s||G[g]>r||G[g+3]<f||G[g+1]>h)continue;const u=Rt(A);n=Xt(A);do{if(n.prev.next===n&&r>=n.x&&n.x>=s&&r!==n.x&&Ct(o<c?r:i,o,s,c,o<c?i:r,o,n.x,n.y)){const B=Math.abs(o-n.y)/(r-n.x);(ct(n,t)||n.y===o&&n.next.y===o&&n.next.x>r)&&(B<l||B===l&&(n.x>a.x||n.x===a.x&&Wn(a,n)))&&(a=n,l=B)}n=n.next}while(n!==u)}return a}function Wn(t,e){return P(t.prev,t,e.prev)<0&&P(e.next,t,t.next)<0}const j=[];let nt=[],q=new Uint32Array(0),rt=new Uint32Array(0);const it=new Uint32Array(256);function qn(t,e,n,r){let o=t,i=0;do o.z=Ut(o.x,o.y,e,n,r),j[i++]=o,o=o.next;while(o!==t);te(i);let a=null;for(let s=0;s<i;s++){const c=j[s];c.prevZ=a,a&&(a.nextZ=c),a=c}a.nextZ=null,j.fill(null,0,i),nt.fill(null,0,i)}function te(t){if(t<=32){for(let e=1;e<t;e++){const n=j[e],r=n.z;let o=e-1;for(;o>=0&&j[o].z>r;)j[o+1]=j[o],o--;j[o+1]=n}return}q.length<t&&(q=new Uint32Array(t),rt=new Uint32Array(t),nt=new Array(t));for(let e=0;e<t;e++)q[e]=j[e].z;xt(t,j,q,nt,rt,0),xt(t,nt,rt,j,q,8),xt(t,j,q,nt,rt,16),xt(t,nt,rt,j,q,24)}function xt(t,e,n,r,o,i){it.fill(0);for(let s=0;s<t;s++)it[n[s]>>>i&255]++;let a=0;for(let s=0;s<256;s++){const c=it[s];it[s]=a,a+=c}for(let s=0;s<t;s++){const c=n[s],f=it[c>>>i&255]++;r[f]=e[s],o[f]=c}}function Ut(t,e,n,r,o){return t=(t-n)*o|0,e=(e-r)*o|0,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t|e<<1}function ne(t){let e=t,n=t;do(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next;while(e!==t);return n}function Ct(t,e,n,r,o,i,a,s){return(o-a)*(e-s)>=(t-a)*(i-s)&&(t-a)*(r-s)>=(n-a)*(e-s)&&(n-a)*(i-s)>=(o-a)*(r-s)}function ee(t,e){const n=st(t,e)&&P(t.prev,t,t.next)>0&&P(e.prev,e,e.next)>0;return t.next.i!==e.i&&(n||ct(t,e)&&ct(e,t)&&(P(t.prev,t,e.prev)!==0||P(t,e.prev,e)!==0))&&!oe(t,e)&&(n||re(t,e))}function P(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function st(t,e){return t.x===e.x&&t.y===e.y}function Vt(t,e,n,r,o=!0){const i=P(t,e,n),a=P(t,e,r),s=P(n,r,t),c=P(n,r,e);return(i>0&&a<0||i<0&&a>0)&&(s>0&&c<0||s<0&&c>0)?!0:o?!!(i===0&&Bt(t,n,e)||a===0&&Bt(t,r,e)||s===0&&Bt(n,t,r)||c===0&&Bt(n,e,r)):!1}function Bt(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function oe(t,e){const n=Math.min(t.x,e.x),r=Math.max(t.x,e.x),o=Math.min(t.y,e.y),i=Math.max(t.y,e.y);let a=t;do{const s=a.next;if(a.x>r&&s.x>r||a.x<n&&s.x<n||a.y>i&&s.y>i||a.y<o&&s.y<o){a=s;continue}if(a.i!==t.i&&s.i!==t.i&&a.i!==e.i&&s.i!==e.i&&Vt(a,s,t,e))return!0;a=s}while(a!==t);return!1}function ct(t,e){return P(t.prev,t,t.next)<0?P(t,e,t.next)>=0&&P(t,t.prev,e)>=0:P(t,e,t.prev)<0||P(t,t.next,e)<0}function re(t,e){let n=t,r=!1;const o=(t.x+e.x)/2,i=(t.y+e.y)/2;do{const a=n.next;n.y>i!=a.y>i&&o<(a.x-n.x)*(i-n.y)/(a.y-n.y)+n.x&&(r=!r),n=a}while(n!==t);return r}function $t(t,e){const n=Dt(t.i,t.x,t.y),r=Dt(e.i,e.x,e.y),o=t.next,i=e.prev;return t.next=e,e.prev=t,n.next=o,o.prev=n,r.next=n,n.prev=r,i.next=r,r.prev=i,r}function _t(t,e,n,r){const o=Dt(t,e,n);return r?(o.next=r.next,o.prev=r,r.next.prev=o,r.next=o):(o.prev=o,o.next=o),o}function at(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ),Ft&&$n(t.prev,t.next)}function Dt(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function ie(t,e,n,r){let o=0;for(let i=e,a=n-r;i<n;i+=r)o+=(t[a]-t[i])*(t[i+1]+t[a+1]),a=i;return o}function se(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Lt={exports:{}},Wt;function ce(){return Wt||(Wt=1,(function(t){(function(){function e(s,c){var f=s.x-c.x,h=s.y-c.y;return f*f+h*h}function n(s,c,f){var h=c.x,l=c.y,A=f.x-h,g=f.y-l;if(A!==0||g!==0){var u=((s.x-h)*A+(s.y-l)*g)/(A*A+g*g);u>1?(h=f.x,l=f.y):u>0&&(h+=A*u,l+=g*u)}return A=s.x-h,g=s.y-l,A*A+g*g}function r(s,c){for(var f=s[0],h=[f],l,A=1,g=s.length;A<g;A++)l=s[A],e(l,f)>c&&(h.push(l),f=l);return f!==l&&h.push(l),h}function o(s,c,f,h,l){for(var A=h,g,u=c+1;u<f;u++){var B=n(s[u],s[c],s[f]);B>A&&(g=u,A=B)}A>h&&(g-c>1&&o(s,c,g,h,l),l.push(s[g]),f-g>1&&o(s,g,f,h,l))}function i(s,c){var f=s.length-1,h=[s[0]];return o(s,0,f,c,h),h.push(s[f]),h}function a(s,c,f){if(s.length<=2)return s;var h=c!==void 0?c*c:1;return s=f?s:r(s,h),s=i(s,h),s}t.exports=a,t.exports.default=a})()})(Lt)),Lt.exports}var ae=ce(),fe=se(ae);function he(t){const{width:e,height:n}=t,r=t.data.slice(),o=new Int32Array(e*n);let i=0,a=0;for(let c=0;c<o.length;c++)r[c*4+3]>=128&&(o[a++]=c);function s(c,f){r[f*4+3]>=128||(r.set(r.subarray(c*4,c*4+3),f*4),r[f*4+3]=255,o[a++]=f)}for(;i<a;){const c=o[i++],f=c%e;f&&s(c,c-1),f+1<e&&s(c,c+1),c>=e&&s(c,c-e),c+e<o.length&&s(c,c+e)}return{width:e,height:n,data:r}}function le(t){const{width:e,height:n,data:r}=t,o=new Array(e*n);for(let i=0;i<o.length;i++)o[i]=r[i*4+3];return Pn().size([e,n]).contour(o,127.5).coordinates.map(i=>i.map((a,s)=>{const c=a.map(([A,g])=>({x:A,y:g})),f=fe(c,.75,!0),h=(f.length>=4?f:c).slice(0,-1);return h.reduce((A,g,u)=>{const B=h[(u+1)%h.length];return A+g.x*B.y-B.x*g.y},0)>0!=(s===0)&&h.reverse(),h.map(A=>({x:A.x/e,y:A.y/n}))}))}function qt(t){let e=!1;for(let n=0;n<t.length;n++){const r=t[n],o=t[(n+1)%t.length];r.y>.5!=o.y>.5&&.5<r.x+(.5-r.y)*(o.x-r.x)/(o.y-r.y)&&(e=!e)}return e}function tn(t,e){let n=t.height,r=-1;for(let o=0;o<t.height;o++)t.data[4*(o*t.width+e)+3]>=128&&(n=Math.min(n,o),r=o);if(r>=n)return[n/t.height,(r+1)/t.height]}function Ae(t,e,[n,,r]){const o=t.top,i=t.left,a=[];for(let l=0;l<o.width;l++){const A=tn(o,l);A&&a.push(A[1]-A[0])}a.sort((l,A)=>l-A);const s=a[Math.floor(a.length/2)];if(!(s>0&&s<1))throw new Error("Contour hub needs a projecting axle in TOP.");let c=1/0;for(const l of e)for(let A=0;A<l.length;A++){const g=l[A],u=l[(A+1)%l.length],B=(g.x-.5)*n,C=(g.y-.5)*r,x=(u.x-g.x)*n,d=(u.y-g.y)*r,w=Math.max(0,Math.min(1,-(B*x+C*d)/(x*x+d*d||1)));c=Math.min(c,Math.hypot(B+w*x,C+w*d))}const f=[.12,.88].map(l=>tn(i,Math.floor(l*i.width)));if(f.some(l=>!l))throw new Error("Contour hub needs a centered collar in LEFT.");const h=f.map(l=>Math.min((l[1]-l[0])*r/2,c*.95));return{plate:s,radii:h}}function ue(t,e,n,r,o,i,a,s){const[c,f,h]=e,l=le(r);if(!l.length)throw new Error("Empty FRONT contour.");const A=a?l.find(Q=>qt(Q[0])&&!Q.slice(1).some(qt)):void 0;if(a&&!A)throw new Error("Contour hub needs solid material at the center of FRONT.");const g=A&&Ae(t,A,e),u=f*(g?.plate??1)/2,B=[],C=[],x=[],d=[];function w(Q,m,p,M){const E=B.length/3;B.push((Q.x-.5)*c,(1-Q.y)*h-n[2],m),C.push(...p);const v=m/f+.5;let b=Q.x,k=Q.y;M==="rear"&&(b=1-b),M==="top"&&(k=1-v),M==="bottom"&&(k=v),M==="left"&&(b=v),M==="right"&&(b=1-v);const U=o.get(M);return x.push((U.left+.5+b*(U.image.width-1))/i.width,(1.5+k*(U.image.height-1))/i.height),E}function y(Q){return Array.from({length:s},(m,p)=>{const M=-2*Math.PI*p/s;return{x:.5+Q*Math.cos(M)/c,y:.5+Q*Math.sin(M)/h}})}function I(Q,m,p){const M=[],E=[],v=B.length/3;for(const[k,U]of Q.entries()){k&&M.push(E.length/2);for(const D of U)E.push(D.x,D.y),w(D,m,[0,0,p],p<0?"front":"rear")}const b=zn(E,M);for(let k=0;k<b.length;k+=3){const U=v+b[k],D=v+b[k+1],L=v+b[k+2];p<0?d.push(U,D,L):d.push(U,L,D)}}function F(Q,m,p){const M=f/2-u,E=[[0,1],[.38,1],[.44,.93],[.87,.93],[1,.82]];let v=p;for(let b=1;b<E.length;b++){const[k,U]=E[b],[D,L]=E[b-1],Y=y(Q*U),S=(L-U)*Q/((k-D)*M),N=Math.hypot(1,S),J=B.length/3;for(let K=0;K<s;K++){const T=-2*Math.PI*K/s,H=[Math.cos(T)/N,-Math.sin(T)/N,m*S/N];w(v[K],m*(u+D*M),H,"left"),w(Y[K],m*(u+k*M),H,"left")}for(let K=0;K<s;K++){const T=J+K*2,H=J+(K+1)%s*2;m>0?d.push(T,H,H+1,T,H+1,T+1):d.push(T,H+1,H,T,T+1,H+1)}v=Y}I([v],m*f/2,m)}for(const Q of l){for(const m of[-1,1])if(Q===A&&g){const p=g.radii[m<0?0:1],M=y(p);I([...Q,M],m*u,m),F(p,m,M)}else I(Q,m*u,m);for(const m of Q)for(let p=0;p<m.length;p++){const M=m[p],E=m[(p+1)%m.length],v=(E.x-M.x)*c,b=(E.y-M.y)*h,k=Math.hypot(v,b);if(!k)continue;const U=[b/k,v/k,0],D=Math.abs(U[1])>=Math.abs(U[0])?U[1]<0&&t.bottom?"bottom":"top":U[0]>0&&t.right?"right":"left",L=w(M,-u,U,D);w(E,-u,U,D),w(E,u,U,D),w(M,u,U,D),d.push(L,L+2,L+1,L,L+3,L+2)}}return{target:"mesh",positions:Float32Array.from(B),normals:Float32Array.from(C),indices:Uint32Array.from(d),uvs:Float32Array.from(x),texture:i,size:e,pivot:n}}const nn={top:[2,!0],bottom:[2,!1],left:[0,!1],right:[0,!0],front:[1,!0],rear:[1,!1]},ge=[0,1,2];function we(t,e){const n=t[e],r=t[e+1],o=t[e+2];return t[e+3]<128?0:n>145&&n-o>70&&r-o>20&&n-r>22?1:r>95&&o>105&&Math.min(r,o)-n>46&&o-r>-20?2:0}function de(t){const e={},n={},r=new Map,o=new Map;for(const[i,a]of Object.entries(t)){let s=function(d,w){!l[w]||A[w]>=0||(A[w]=A[d]+1,u.set(u.subarray(d*4,d*4+3),w*4),g[x++]=w)};const{width:c,height:f,data:h}=a,l=new Uint8Array(c*f),A=new Int32Array(l.length).fill(-1),g=new Int32Array(l.length),u=new Uint8Array(h),B=[0,0,0];for(let d=0;d<l.length;d++){const w=l[d]=we(h,d*4);w&&B[w]++}const C=l.slice();for(let d=0;d<C.length;d++){const w=C[d];if(!w)continue;const y=d%c,I=Math.floor(d/c);for(let F=-3;F<=3;F++)for(let Q=-3;Q<=3;Q++){if(Q*Q+F*F>9||y+Q<0||y+Q>=c||I+F<0||I+F>=f)continue;const m=d+F*c+Q,p=m*4;if(l[m]||h[p+3]<128)continue;const M=h[p],E=h[p+1],v=h[p+2];(w===1?M-v>12&&E-v>5&&M>=E-8:Math.min(E,v)-M>12)&&(l[m]=w)}}let x=0;for(let d=0;d<l.length;d++)l[d]||h[d*4+3]<128||(A[d]=0,g[x++]=d);for(let d=0;d<x;d++){const w=g[d],y=w%c;y>0&&s(w,w-1),y+1<c&&s(w,w+1),w>=c&&s(w,w-c),w+c<l.length&&s(w,w+c)}for(const d of[1,2]){const w=B[d]/(c*f)*(i==="front"?1.35:1);w<=(o.get(d)??0)||(o.set(d,w),r.set(d,i))}n[i]=l,e[i]={width:c,height:f,data:u}}return{clean:e,masks:n,owner:r}}function xe(t,e,n){const r={};for(const s of n){const[c,f]=nn[s],h=ge.filter(B=>B!==c),l=e[h[0]],A=e[h[1]],g=new Int16Array(l*A).fill(-1),u=[0,0,0];for(let B=0;B<A;B++)for(let C=0;C<l;C++){u[h[0]]=C,u[h[1]]=B;for(let x=0;x<e[c];x++)if(u[c]=f?e[c]-1-x:x,!!t[(u[2]*e[1]+u[1])*e[0]+u[0]]){g[B*l+C]=u[c]+Number(f);break}}r[s]={axis:c,axes:h,width:l,height:A,values:g}}function o(s,c){return[Math.max(0,Math.min(s.width-1,Math.floor(c[s.axes[0]]))),Math.max(0,Math.min(s.height-1,Math.floor(c[s.axes[1]])))]}function i(s,c){const f=r[s];if(!f)return-1;const[h,l]=o(f,c);return f.values[l*f.width+h]}function a(s,c,f=1.5){const h=i(s,c);return h>=0&&Math.abs(h-c[nn[s][0]])<=f}return{visible:a,firstHit:i}}function Ce(t,e,n,r,o,i){const{width:a,height:s,data:c}=t,f=new Uint8Array(e.length),h=new Uint8Array(e.length),l=new Uint8Array(c.length),A=[],g=[],u=[],B=[];for(let x=0;x<e.length;x++){if(e[x]!==1||h[x])continue;const d=[x],w=new Map;let y=a,I=0,F=s,Q=0;h[x]=1;for(const p of d){const M=p%a,E=Math.floor(p/a);y=Math.min(y,M),I=Math.max(I,M),F=Math.min(F,E),Q=Math.max(Q,E);const v=w.get(E)??[M,M];w.set(E,[Math.min(v[0],M),Math.max(v[1],M)]);for(const b of[M>0?p-1:-1,M+1<a?p+1:-1,p-a,p+a])e[b]!==1||h[b]||(h[b]=1,d.push(b))}if(d.length<5||I-y>a/4||Q-F>s/4)continue;const m=new Map;for(const[p,[M,E]]of w){let v=-1;for(let b=M;b<=E;b++){const k=[(b+.5)/a*n[0],0,(1-(p+.5)/s)*n[2]];v=Math.max(v,i("front",k))}v>=0&&m.set(p,v)}if(!(m.size<2)){for(const p of d)m.has(Math.floor(p/a))&&(f[p]=1,l.set(c.subarray(p*4,p*4+4),p*4));for(const[p,M]of m){const[E,v]=w.get(p),b=E/a,k=(v+1)/a,U=p/s,D=(p+1)/s,L=(b-.5)*r[0],Y=(k-.5)*r[0],S=(1-U)*r[2]-o[2],N=(1-D)*r[2]-o[2],J=(.5-(M+.65)/n[1])*r[1],K=A.length/3;A.push(L,S,J,Y,S,J,Y,N,J,L,N,J),g.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1),u.push(K,K+1,K+2,K,K+2,K+3),B.push(b,U,k,U,k,D,b,D)}}}return{mesh:u.length?{target:"mesh",size:r,pivot:o,texture:{width:a,height:s,data:l},positions:Float32Array.from(A),normals:Float32Array.from(g),indices:Uint32Array.from(u),uvs:Float32Array.from(B)}:void 0,marked:f}}const en=Int8Array.from(atob("/////////////////////wAIA/////////////////8AAQn/////////////////AQgDCQgB/////////////wECCv////////////////8ACAMBAgr/////////////CQIKAAIJ/////////////wIIAwIKCAoJCP////////8DCwL/////////////////AAsCCAsA/////////////wEJAAIDC/////////////8BCwIBCQsJCAv/////////AwoBCwoD/////////////wAKAQAICggLCv////////8DCQADCwkLCgn/////////CQgKCggL/////////////wQHCP////////////////8EAwAHAwT/////////////AAEJCAQH/////////////wQBCQQHAQcDAf////////8BAgoIBAf/////////////AwQHAwAEAQIK/////////wkCCgkAAggEB/////////8CCgkCCQcCBwMHCQT/////CAQHAwsC/////////////wsEBwsCBAIABP////////8JAAEIBAcCAwv/////////BAcLCQQLCQsCCQIB/////wMKAQMLCgcIBP////////8BCwoBBAsBAAQHCwT/////BAcICQALCQsKCwAD/////wQHCwQLCQkLCv////////8JBQT/////////////////CQUEAAgD/////////////wAFBAEFAP////////////8IBQQIAwUDAQX/////////AQIKCQUE/////////////wMACAECCgQJBf////////8FAgoFBAIEAAL/////////AgoFAwIFAwUEAwQI/////wkFBAIDC/////////////8ACwIACAsECQX/////////AAUEAAEFAgML/////////wIBBQIFCAIICwQIBf////8KAwsKAQMJBQT/////////BAkFAAgBCAoBCAsK/////wUEAAUACwULCgsAA/////8FBAgFCAoKCAv/////////CQcIBQcJ/////////////wkDAAkFAwUHA/////////8ABwgAAQcBBQf/////////AQUDAwUH/////////////wkHCAkFBwoBAv////////8KAQIJBQAFAwAFBwP/////CAACCAIFCAUHCgUC/////wIKBQIFAwMFB/////////8HCQUHCAkDCwL/////////CQUHCQcCCQIAAgcL/////wIDCwABCAEHCAEFB/////8LAgELAQcHAQX/////////CQUICAUHCgEDCgML/////wUHAAUACQcLAAEACgsKAP8LCgALAAMKBQAIAAcFBwD/CwoFBwsF/////////////woGBf////////////////8ACAMFCgb/////////////CQABBQoG/////////////wEIAwEJCAUKBv////////8BBgUCBgH/////////////AQYFAQIGAwAI/////////wkGBQkABgACBv////////8FCQgFCAIFAgYDAgj/////AgMLCgYF/////////////wsACAsCAAoGBf////////8AAQkCAwsFCgb/////////BQoGAQkCCQsCCQgL/////wYDCwYFAwUBA/////////8ACAsACwUABQEFCwb/////AwsGAAMGAAYFAAUJ/////wYFCQYJCwsJCP////////8FCgYEBwj/////////////BAMABAcDBgUK/////////wEJAAUKBggEB/////////8KBgUBCQcBBwMHCQT/////BgECBgUBBAcI/////////wECBQUCBgMABAMEB/////8IBAcJAAUABgUAAgb/////BwMJBwkEAwIJBQkGAgYJ/wMLAgcIBAoGBf////////8FCgYEBwIEAgACBwv/////AAEJBAcIAgMLBQoG/////wkCAQkLAgkECwcLBAUKBv8IBAcDCwUDBQEFCwb/////BQELBQsGAQALBwsEAAQL/wAFCQAGBQADBgsGAwgEB/8GBQkGCQsEBwkHCwn/////CgQJBgQK/////////////wQKBgQJCgAIA/////////8KAAEKBgAGBAD/////////CAMBCAEGCAYEBgEK/////wEECQECBAIGBP////////8DAAgBAgkCBAkCBgT/////AAIEBAIG/////////////wgDAggCBAQCBv////////8KBAkKBgQLAgP/////////AAgCAggLBAkKBAoG/////wMLAgABBgAGBAYBCv////8GBAEGAQoECAECAQsICwH/CQYECQMGCQEDCwYD/////wgLAQgBAAsGAQkBBAYEAf8DCwYDBgAABgT/////////BgQICwYI/////////////wcKBgcICggJCv////////8ABwMACgcACQoGBwr/////CgYHAQoHAQcIAQgA/////woGBwoHAQEHA/////////8BAgYBBggBCAkIBgf/////AgYJAgkBBgcJAAkDBwMJ/wcIAAcABgYAAv////////8HAwIGBwL/////////////AgMLCgYICggJCAYH/////wIABwIHCwAJBwYHCgkKB/8BCAABBwgBCgcGBwoCAwv/CwIBCwEHCgYBBgcB/////wgJBggGBwkBBgsGAwEDBv8ACQELBgf/////////////BwgABwAGAwsACwYA/////wcLBv////////////////8HBgv/////////////////AwAICwcG/////////////wABCQsHBv////////////8IAQkIAwELBwb/////////CgECBgsH/////////////wECCgMACAYLB/////////8CCQACCgkGCwf/////////BgsHAgoDCggDCgkI/////wcCAwYCB/////////////8HAAgHBgAGAgD/////////AgcGAgMHAAEJ/////////wEGAgEIBgEJCAgHBv////8KBwYKAQcBAwf/////////CgcGAQcKAQgHAQAI/////wADBwAHCgAKCQYKB/////8HBgoHCggICgn/////////BggECwgG/////////////wMGCwMABgAEBv////////8IBgsIBAYJAAH/////////CQQGCQYDCQMBCwMG/////wYIBAYLCAIKAf////////8BAgoDAAsABgsABAb/////BAsIBAYLAAIJAgoJ/////woJAwoDAgkEAwsDBgQGA/8IAgMIBAIEBgL/////////AAQCBAYC/////////////wEJAAIDBAIEBgQDCP////8BCQQBBAICBAb/////////CAEDCAYBCAQGBgoB/////woBAAoABgYABP////////8EBgMEAwgGCgMAAwkKCQP/CgkEBgoE/////////////wQJBQcGC/////////////8ACAMECQULBwb/////////BQABBQQABwYL/////////wsHBggDBAMFBAMBBf////8JBQQKAQIHBgv/////////BgsHAQIKAAgDBAkF/////wcGCwUECgQCCgQAAv////8DBAgDBQQDAgUKBQILBwb/BwIDBwYCBQQJ/////////wkFBAAIBgAGAgYIB/////8DBgIDBwYBBQAFBAD/////BgIIBggHAgEIBAgFAQUI/wkFBAoBBgEHBgEDB/////8BBgoBBwYBAAcIBwAJBQT/BAAKBAoFAAMKBgoHAwcK/wcGCgcKCAUECgQICv////8GCQUGCwkLCAn/////////AwYLAAYDAAUGAAkF/////wALCAAFCwABBQUGC/////8GCwMGAwUFAwH/////////AQIKCQULCQsICwUG/////wALAwAGCwAJBgUGCQECCv8LCAULBQYIAAUKBQIAAgX/BgsDBgMFAgoDCgUD/////wUICQUCCAUGAgMIAv////8JBQYJBgAABgL/////////AQUIAQgABQYIAwgCBgII/wEFBgIBBv////////////8BAwYBBgoDCAYFBgkICQb/CgEACgAGCQUABQYA/////wADCAUGCv////////////8KBQb/////////////////CwUKBwUL/////////////wsFCgsHBQgDAP////////8FCwcFCgsBCQD/////////CgcFCgsHCQgBCAMB/////wsBAgsHAQcFAf////////8ACAMBAgcBBwUHAgv/////CQcFCQIHCQACAgsH/////wcFAgcCCwUJAgMCCAkIAv8CBQoCAwUDBwX/////////CAIACAUCCAcFCgIF/////wkAAQUKAwUDBwMKAv////8JCAIJAgEIBwIKAgUHBQL/AQMFAwcF/////////////wAIBwAHAQEHBf////////8JAAMJAwUFAwf/////////CQgHBQkH/////////////wUIBAUKCAoLCP////////8FAAQFCwAFCgsLAwD/////AAEJCAQKCAoLCgQF/////woLBAoEBQsDBAkEAQMBBP8CBQECCAUCCwgEBQj/////AAQLAAsDBAULAgsBBQEL/wACBQAFCQILBQQFCAsIBf8JBAUCCwP/////////////AgUKAwUCAwQFAwgE/////wUKAgUCBAQCAP////////8DCgIDBQoDCAUEBQgAAQn/BQoCBQIEAQkCCQQC/////wgEBQgFAwMFAf////////8ABAUBAAX/////////////CAQFCAUDCQAFAAMF/////wkEBf////////////////8ECwcECQsJCgv/////////AAgDBAkHCQsHCQoL/////wEKCwELBAEEAAcEC/////8DAQQDBAgBCgQHBAsKCwT/BAsHCQsECQILCQEC/////wkHBAkLBwkBCwILAQAIA/8LBwQLBAICBAD/////////CwcECwQCCAMEAwIE/////wIJCgIHCQIDBwcECf////8JCgcJBwQKAgcIBwACAAf/AwcKAwoCBwQKAQoABAAK/wEKAggHBP////////////8ECQEEAQcHAQP/////////BAkBBAEHAAgBCAcB/////wQAAwcEA/////////////8ECAf/////////////////CQoICgsI/////////////wMACQMJCwsJCv////////8AAQoACggICgv/////////AwEKCwMK/////////////wECCwELCQkLCP////////8DAAkDCQsBAgkCCwn/////AAILCAAL/////////////wMCC/////////////////8CAwgCCAoKCAn/////////CQoCAAkC/////////////wIDCAIICgABCAEKCP////8BCgL/////////////////AQMICQEI/////////////wAJAf////////////////8AAwj//////////////////////////////////////w=="),t=>t.charCodeAt(0)),on=[[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]],Be=[[0,1],[1,2],[2,3],[3,0],[4,5],[5,6],[6,7],[7,4],[0,4],[1,5],[2,6],[3,7]];function Me(t,e,n){const r=Math.min(n[2]*(e[2]-2)*.042,Math.max(n[0],n[1])*1.65),o=[1,e[0],e[0]*e[1]];let i=Float32Array.from(t),a=new Float32Array(i.length);for(let s=0;s<e.length;s++){const c=Math.max(.6,Math.min(5,r/n[s])),f=Math.ceil(c*2.5),h=Array.from({length:f+1},(B,C)=>Math.exp(-C*C/(2*c*c))),l=h[0]+2*h.slice(1).reduce((B,C)=>B+C,0),A=o[s],g=e[s],u=A*g;for(let B=0;B<i.length;B+=u)for(let C=0;C<A;C++)for(let x=0;x<g;x++){const d=B+C+x*A;let w=h[0]*i[d];for(let y=1;y<=f;y++)x>=y&&(w+=h[y]*i[d-y*A]),x+y<g&&(w+=h[y]*i[d+y*A]);a[d]=w/l}[i,a]=[a,i]}return i}function ye(t,e,n,r,o){const i=e+2,a=n+2,s=r+2,c=i*a,f=c*s,h=new Uint8Array(f);for(let w=0;w<r;w++)for(let y=0;y<n;y++){const I=(w*n+y)*e;h.set(t.subarray(I,I+e),(w+1)*c+(y+1)*i+1)}const l=o?Me(h,[i,a,s],[o[0]/e,o[1]/n,o[2]/r]):new Float32Array(f);for(let w=0;w<s;w++)for(let y=0;y<a;y++)for(let I=0;I<i;I++){const F=w*c+y*i+I,Q=(I>0?h[F-1]:0)+(I+1<i?h[F+1]:0)+(y>0?h[F-i]:0)+(y+1<a?h[F+i]:0)+(w>0?h[F-c]:0)+(w+1<s?h[F+c]:0),m=h[F]*.64+Q*.06;l[F]=o?l[F]*.92+m*.08:m}const A=[0,1,i+1,i,c,c+1,c+i+1,c+i],g=new Int32Array(f*3).fill(-1),u=[],B=[],C=[];function x(w,y){return(l[w-y]??0)-(l[w+y]??0)}function d(w,y,I,F,Q){const[m,p]=Be[Q],M=on[m],E=on[p],v=F+A[m],b=F+A[p],k=M[0]!==E[0]?0:M[1]!==E[1]?1:2,U=Math.min(v,b)*3+k;if(g[U]>=0)return g[U];const D=u.length/3,L=(.5-l[v])/(l[b]-l[v]);return u.push(w-.5+M[0]+(E[0]-M[0])*L,y-.5+M[1]+(E[1]-M[1])*L,I-.5+M[2]+(E[2]-M[2])*L),B.push(...[1,i,c].map(Y=>x(v,Y)*(1-L)+x(b,Y)*L)),g[U]=D,D}for(let w=0;w<s-1;w++)for(let y=0;y<a-1;y++)for(let I=0;I<i-1;I++){const F=w*c+y*i+I;let Q=0;for(let m=0;m<8;m++)l[F+A[m]]<.5&&(Q|=1<<m);if(!(Q===0||Q===255))for(let m=Q*16;en[m]>=0;m++)C.push(d(I,y,w,F,en[m]))}return{positions:u,gradients:B,indices:C}}const $=(t,e,n)=>Math.min(n,Math.max(e,t));function ft(t,e,n,r){switch(t){case"top":return[e,n];case"bottom":return[e,1-n];case"left":return[1-n,1-r];case"right":return[n,1-r];case"front":return[e,1-r];case"rear":return[1-e,1-r]}}function ht(t,e,n){return($(Math.floor(n*t.height),0,t.height-1)*t.width+$(Math.floor(e*t.width),0,t.width-1))*4}function Ht(t,e,n){if(t.width===e&&t.height===n)return t;const r=new Uint8Array(e*n*4);for(let o=0;o<n;o++)for(let i=0;i<e;i++){const a=ht(t,(i+.5)/e,(o+.5)/n),s=(o*e+i)*4;for(let c=0;c<4;c++)r[s+c]=t.data[a+c]}return{width:e,height:n,data:r}}function lt(t,e,n,r){const o=[Math.max(0,r),Math.max(0,-e),Math.max(0,n),Math.max(0,-n),Math.max(0,e),Math.max(0,-r)];return t.right||(o[1]=Math.abs(e)),t.bottom||(o[0]=Math.abs(r)),[...R].filter(i=>t[i]).sort((i,a)=>o[R.indexOf(a)]-o[R.indexOf(i)])}function rn(t,e){const n=t.top,r=t.front,o=t.left,i=e.layers??48,a=e.resolution??96,s=e.height??1;if(!Number.isInteger(i)||i<8||i>128)throw new Error("Layers must be an integer from 8 to 128.");if(!Number.isInteger(a)||a<16||a>192)throw new Error("Resolution must be an integer from 16 to 192.");if(!Number.isFinite(s)||s<=0)throw new Error("Height must be positive.");if(e.pivot&&e.pivot!=="center"&&e.pivot!=="ground")throw new Error("Pivot must be ground or center.");const c=o.width/o.height*s,[f,h,l]=e.size??[(r.width/r.height*s+c*n.width/n.height)/2,c,s];if(![f,h,l].every(C=>Number.isFinite(C)&&C>0))throw new Error("Part dimensions must be positive.");const A=Math.max(2,Math.round(f/Math.max(f,h)*a)),g=Math.max(2,Math.round(h/Math.max(f,h)*a)),u=[f,h,l],B=[0,0,e.pivot==="center"?l/2:0];return{width:A,depth:g,layers:i,size:u,pivot:B}}function me(t,e,n){const{width:r,depth:o,layers:i,size:a,pivot:s}=rn(t,e);if(r*o*i>3e6)throw new Error("The grid is too large. Reduce layers or XY resolution.");const c={};for(const u of R){const B=t[u];if(!B)continue;const C=u!=="top"&&u!=="bottom";c[u]=Ht(B,u==="left"||u==="right"?o:r,C?i:o)}const f=Object.entries(c),h=(u,B,C,x,d)=>B.data[ht(B,...ft(u,C,x,d))+3]>=128,l=new Uint8Array(r*o*i);let A=0;const g=e.profile==="round"||e.profile==="round-base";for(let u=0;u<i;u++)for(let B=0;B<o;B++)for(let C=0;C<r;C++){const x=(C+.5)/r,d=(B+.5)/o,w=(u+.5)/i;(t.right?f.every(([I,F])=>h(I,F,x,d,w)):h("top",c.top,x,d,w)&&h("left",c.left,x,d,w)&&(h("front",c.front,x,d,w)||h("rear",c.rear,x,d,w)))&&(l[(u*o+B)*r+C]=1,A++)}if(g){const u=r*o;for(let B=0;B<i;B++){if(e.profile==="round-base"&&(B+.5)/i<.03)continue;let C=r,x=-1,d=o,w=-1;const y=B*u;for(let I=0;I<o;I++)for(let F=0;F<r;F++)l[y+I*r+F]&&(C=Math.min(C,F),x=Math.max(x,F),d=Math.min(d,I),w=Math.max(w,I));if(!(x<C))for(let I=d;I<=w;I++)for(let F=C;F<=x;F++){if(((2*F-C-x)/(x-C+1))**2+((2*I-d-w)/(w-d+1))**2<=1)continue;const Q=y+I*r+F;A-=l[Q],l[Q]=0}}}if(!A)throw new Error("The aligned views have no common volume.");return{width:r,depth:o,layers:i,size:a,pivot:s,volume:l,aligned:c}}function sn(t,e={},n=!1){const r=new Map,o=new Map(r);let i=0,a=0;for(const[c,f]of[[t,r],[e,o]])for(const h of R){const l=c[h];if(!l)continue;const A=Math.min(1,512/Math.max(l.width,l.height)),g=Ht(l,Math.max(1,Math.round(l.width*A)),Math.max(1,Math.round(l.height*A)));f.set(h,{image:n?he(g):g,left:i+1}),i+=g.width+2,a=Math.max(a,g.height+2)}const s=new Uint8Array(i*a*4).fill(255);for(const{image:c,left:f}of[...r.values(),...o.values()])for(let h=-1;h<=c.height;h++)for(let l=-1;l<=c.width;l++){const A=($(h,0,c.height-1)*c.width+$(l,0,c.width-1))*4,g=((h+1)*i+f+l)*4;for(let u=0;u<3;u++)s[g+u]=c.data[A+3]>=128?c.data[A+u]:137}return{tiles:r,accents:o,texture:{width:i,height:a,data:s}}}function cn(t,e,n="rgb"){const{width:r,depth:o,layers:i,size:a,pivot:s,volume:c}=t,f=ye(c,r,o,i,n==="depth"?a:void 0);if(!f.indices.length&&n==="depth")return cn(t,e,"id");const h=new Int16Array(r*o).fill(-1),l=new Int16Array(r*o).fill(i),A=r*o;for(let M=0;M<i;M++)for(let E=0;E<A;E++)c[M*A+E]&&(h[E]=M,l[E]=Math.min(l[E],M));function g(M,E,v,b){const k=$(Math.floor(E*r),0,r-1),U=$(Math.floor(v*o),0,o-1),D=M[U*r+k];if(Math.abs(D+.5-b*i)>2)return!1;let L=0;for(const[Y,S]of[[2,0],[-2,0],[0,2],[0,-2]]){const N=k+Y,J=U+S;if(!(N<0||N>=r||J<0||J>=o)){if(Math.abs(M[J*r+N]-D)>(e.bottom?2:1))return!1;L++}}return L>=(e.bottom?2:3)}const u=n==="rgb"?void 0:de(e),B={};for(const M of u?.owner.values()??[])B[M]=e[M];const C=u?xe(c,[r,o,i],R):void 0,x=u?.owner.get(1)==="front"&&C&&e.front&&u.masks.front?Ce(e.front,u.masks.front,[r,o,i],a,s,C.firstHit):void 0,{texture:d,tiles:w,accents:y}=sn(u?.clean??e,B),I=[],F=[],Q=[],m=[],p=new Map;for(let M=0;M<f.indices.length;M+=3){const E=f.indices.slice(M,M+3),v=[0,1,2].map(H=>E.reduce((z,Z)=>z+f.gradients[Z*3+H],0)),b=[0,1,2].map(H=>E.reduce((z,Z)=>z+f.positions[Z*3+H],0)),k=[b[0]/(3*r),b[1]/(3*o),b[2]/(3*i)];let U=lt(e,v[0],v[1],v[2]);const D=v[2]<0&&e.bottom?"bottom":"top",L=v[2]<0?l:h,Y=n==="depth"&&C&&Math.abs(v[2])*i/a[2]>1.55*Math.max(Math.abs(v[0])*r/a[0],Math.abs(v[1])*o/a[1])&&C.visible(D,b.map(H=>H/3),3);if(!Y&&!g(L,k[0],k[1],k[2])){const H=v[0],z=v[1];U=Math.hypot(H,z)>.1?lt(e,H,z,0):lt(e,k[0]-.5,k[1]-.5,0),U=[...U.filter(Z=>Z!=="top"&&Z!=="bottom"),D]}const S=H=>{const z=e[H];return z.data[ht(z,...ft(H,...k))+3]>=128};let N=Y&&S(D)?D:U.find(S)??U[0],J=!1;if(u&&C){const H=b.map(O=>O/3),z=n==="depth"?3:1.5,Z=lt(e,v[0],v[1],v[2]),V=[Math.max(0,v[2]),Math.max(0,-v[0]),Math.max(0,v[1]),Math.max(0,-v[1]),Math.max(0,v[0]),Math.max(0,-v[2])],mt=Math.max(...V);for(const O of Z){if(!B[O]||V[R.indexOf(O)]<=mt*.45||!C.visible(O,H,z))continue;const pt=B[O],At=ht(pt,...ft(O,...k))/4,Qt=u.masks[O][At];if(!(u.owner.get(Qt)!==O||O==="front"&&x?.marked[At])){N=O,J=!0;break}}}const{image:K,left:T}=(J?y:w).get(N);for(const H of E){const z=H*12+R.indexOf(N)+(J?6:0);let Z=p.get(z);if(Z===void 0){Z=I.length/3,p.set(z,Z);const V=H*3,mt=f.positions[V]/r,O=f.positions[V+1]/o,pt=f.positions[V+2]/i;I.push((mt-.5)*a[0],pt*a[2]-s[2],(.5-O)*a[1]);const At=f.gradients[V]*r/a[0],Qt=f.gradients[V+1]*o/a[1],fn=f.gradients[V+2]*i/a[2],Kt=Math.hypot(At,Qt,fn)||1;F.push(At/Kt,fn/Kt,-Qt/Kt);const[be,ke]=ft(N,mt,O,pt);m.push((T+.5+$(be,0,1)*(K.width-1))/d.width,(1.5+$(ke,0,1)*(K.height-1))/d.height)}Q.push(Z)}}return{target:"mesh",size:a,pivot:s,texture:d,positions:Float32Array.from(I),normals:Float32Array.from(F),indices:Uint32Array.from(Q),uvs:Float32Array.from(m),...x?.mesh&&{frontAccents:x.mesh}}}function pe(t,e){const{width:n,depth:r,layers:o,size:i,pivot:a,volume:s}=t,c=Math.min(o,Math.max(1,Math.floor(4096/n))),f=n*c,h=r*Math.ceil(o/c),l=new Uint8Array(f*h*4),A=(C,x,d)=>+(C>=0&&C<n&&x>=0&&x<r&&d>=0&&d<o&&s[(d*r+x)*n+C]>0),g=new Int16Array(n*r).fill(-1);for(let C=0;C<o;C++)for(let x=0;x<g.length;x++)s[C*g.length+x]&&(g[x]=C);const u=Array.from({length:27},(C,x)=>lt(e,x%3-1,Math.floor(x/3)%3-1,Math.floor(x/9)-1)),B=(C,x,d)=>C<0||C>=n||x<0||x>=r||Math.abs(g[x*n+C]-d)<=1;for(let C=0;C<o;C++)for(let x=0;x<r;x++)for(let d=0;d<n;d++){if(!A(d,x,C))continue;const w=A(d-1,x,C)-A(d+1,x,C),y=A(d,x-1,C)-A(d,x+1,C),I=A(d,x,C-1)-A(d,x,C+1),F=w+1+(y+1)*3+(I+1)*9,Q=((Math.floor(C/c)*r+x)*f+C%c*n+d)*4,m=g[x*n+d],p=C===m&&B(d-2,x,C)&&B(d+2,x,C)&&B(d,x-2,C)&&B(d,x+2,C),M=u[F],E=p||I<0&&e.bottom?M:u[F-I*9];let v=0,b=0,k=0,U=0;for(const D of E){if(!p&&D==="top")continue;const L=e[D],Y=ht(L,...ft(D,(d+.5)/n,(x+.5)/r,(C+.5)/o));if(L.data[Y+3]<128)continue;const S=L.data[Y],N=L.data[Y+1],J=L.data[Y+2];if(v&&Math.max(Math.abs(S-b/v),Math.abs(N-k/v),Math.abs(J-U/v))>66)continue;const K=D==="front"||D==="rear"?.1+Math.abs(y):D==="left"||D==="right"?.1+Math.abs(w):.1+Math.abs(I);b+=S*K,k+=N*K,U+=J*K,v+=K}v&&(l[Q]=Math.round(b/v),l[Q+1]=Math.round(k/v),l[Q+2]=Math.round(U/v),l[Q+3]=255)}return{target:"stack",size:i,pivot:a,width:n,depth:r,layers:o,columns:c,spacing:i[2]/o,texture:{width:f,height:h,data:l}}}function Qe(t,e,n){let r;if(e==="mesh"&&n.meshMethod==="contour"){const{size:o,pivot:i}=rn(t,n),{tiles:a,texture:s}=sn(t,{},!0),c=t.front,f=Math.min(1,1024/Math.max(c.width,c.height)),h=Ht(c,Math.max(1,Math.round(c.width*f)),Math.max(1,Math.round(c.height*f)));r=ue(t,o,i,h,a,s,n.contourHub??!1,n.resolution??96)}else{const o=me(t,n);if(e==="stack")return pe(o,o.aligned);r=cn(o,t)}return n.textureProjection==="top-contour"&&dn(r,t.top,n.resolution??96,n.layers??48),r}new TextEncoder,Uint32Array.from({length:256},(t,e)=>{let n=e;for(let r=0;r<8;r++)n=n>>>1^(n&1?3988292384:0);return n});function ve(t){return`function update({ dt, keys, fields, state, rotation }) {
2
- const tracks = ${JSON.stringify(t)};
3
- const held = (...codes) => codes.some(code => keys.includes(code));
4
- const throttle = Number(held('KeyW', 'ArrowUp')) - Number(held('KeyS', 'ArrowDown'));
5
- const direction = Number(held('KeyA', 'ArrowLeft')) - Number(held('KeyD', 'ArrowRight'));
6
- const target = throttle * (throttle < 0 ? fields.reverseSpeed : fields.forwardSpeed);
7
- const oldSpeed = state.speed ?? 0;
8
- const speed = oldSpeed + (target - oldSpeed) * (1 - Math.exp(-fields.response * dt));
9
- const distance = (oldSpeed + speed) * .5 * dt;
10
- const turn = direction * fields.turnRate * dt;
11
- const radians = Math.PI / 180;
12
- const previous = state.yaw ?? 0;
13
- const heading = (rotation[1] + previous + turn * .5) * radians;
14
- const yaw = (previous + turn) % 360;
15
- const x = (state.x ?? 0) - Math.sin(heading) * distance;
16
- const z = (state.z ?? 0) - Math.cos(heading) * distance;
17
- const travel = tracks.map((track, i) => (state.travel?.[i] ?? 0) + distance + turn * radians * track[1]);
18
- return { translation: [x, 0, z], rotation: [0, yaw, 0],
19
- childTrackTravel: Object.fromEntries(tracks.map((track, i) => [track[0], travel[i]])),
20
- state: { speed, yaw, x, z, travel } };
21
- }`}ve([]);const Ee=(t,e,n="number")=>({type:n,minimum:t,maximum:e}),tt=(...t)=>({...Ee(...t),type:"array"});tt(-1e4,1e4),tt(-360,360),tt(.01,100),tt(-100,100),tt(-720,720),tt(-100,100),tt(-360,360);async function an(t,e=!1){hn(new Uint8Array(await t.slice(0,33).arrayBuffer()));const n=await createImageBitmap(t,{colorSpaceConversion:e?"none":"default"});try{const r=new OffscreenCanvas(n.width,n.height),o=r.getContext("2d",{willReadFrequently:!0});if(!o)throw new Error("Could not decode the PNG.");o.drawImage(n,0,0);const i=o.getImageData(0,0,r.width,r.height);return{width:r.width,height:r.height,data:new Uint8Array(i.data.buffer)}}finally{n.close()}}let Mt,yt=0;async function Ie(t,e){if("atlas"in t)return An(await an(t.atlas),ut(t.layout),e);const n=Object.entries(t.files);return ut(n.map(([r])=>r).join(",")),Object.fromEntries(await Promise.all(n.map(async([r,o])=>[r,await an(o)])))}function Fe(t){const e=Math.min(1,256/Math.max(t.width,t.height)),n=Math.max(1,Math.round(t.width*e)),r=Math.max(1,Math.round(t.height*e)),o=new Uint8Array(n*r*4);for(let i=0;i<r;i++)for(let a=0;a<n;a++){const s=(Math.floor((i+.5)*t.height/r)*t.width+Math.floor((a+.5)*t.width/n))*4;o.set(t.data.subarray(s,s+4),(i*n+a)*4)}return{width:n,height:r,data:o}}self.onmessage=async({data:t})=>{yt=t.id;const e=performance.now();try{let n=function(g,u){const B="parts"in i?i.parts:void 0,C=B?.map(Q=>Q.size),x=Math.max(1,...(C??[]).map(Q=>Q?.[2]??1)),d=Math.max(1,...(C??[]).map(Q=>Q?Math.max(Q[0],Q[1]):1)),w=h.map((Q,m)=>{const p=C?.[m];return Qe(Q,a,p?{...g,size:p,pivot:"ground",layers:Math.max(8,Math.round((g.layers??48)*p[2]/x)),resolution:Math.max(16,Math.round((g.resolution??96)*Math.max(p[0],p[1])/d))}:g)}),y=w.flatMap(Q=>(Q.target==="mesh"?[Q.texture.data,Q.positions,Q.normals,Q.indices,Q.uvs]:[Q.texture.data]).map(m=>m.buffer)),I=t.keepTop&&h[0].top?Fe(h[0].top):void 0;I&&y.push(I.data.buffer);const F={id:r,result:w[0],parts:B?w:void 0,top:I,inspection:A,preview:u,elapsed:performance.now()-e};self.postMessage(F,y)};const{id:r,sourceKey:o,source:i,target:a,settings:s,preview:c}=t,f=JSON.stringify([o,s.threshold]);if(Mt?.key!==f){const g="parts"in i?i.parts:[i],u=Promise.all(g.map(async B=>un(await Ie(B,s.threshold),s.threshold)));Mt={key:f,views:u}}const h=await Mt.views;if(r!==yt)return;const l=h.map(gn),A={views:l[0].views,warnings:[...new Set(l.flatMap(g=>g.warnings))]};if(c){try{n(c,!0)}catch{}await new Promise(g=>setTimeout(g,0))}r===yt&&n(s,!1)}catch(n){t.id===yt&&(Mt=void 0,self.postMessage({id:t.id,error:n instanceof Error?n.message:String(n)}))}}})();