@needle-tools/engine 4.4.5 → 4.4.6-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/{assets/generateMeshBVH.worker-b7788939.js → generateMeshBVH.worker-2bb9524d.js} +1 -1
- package/dist/{gltf-progressive.light.umd.cjs → gltf-progressive-10ca5f84.umd.cjs} +1 -1
- package/dist/{gltf-progressive.light.js → gltf-progressive-13de1400.light.js} +2 -2
- package/dist/{gltf-progressive.js → gltf-progressive-1e91190e.js} +2 -2
- package/dist/{gltf-progressive.umd.cjs → gltf-progressive-9f7cc7b2.light.umd.cjs} +1 -1
- package/dist/{gltf-progressive.light.min.js → gltf-progressive-b5ae121f.light.min.js} +1 -1
- package/dist/{gltf-progressive.min.js → gltf-progressive-c7497194.min.js} +1 -1
- package/dist/{needle-engine.bundle.js → needle-engine.bundle-07e0eaf0.js} +751 -750
- package/dist/{needle-engine.bundle.min.js → needle-engine.bundle-71861947.min.js} +73 -73
- package/dist/{needle-engine.bundle.umd.cjs → needle-engine.bundle-73459623.umd.cjs} +87 -87
- package/dist/{needle-engine.bundle.light.min.js → needle-engine.bundle-9def7e8b.light.min.js} +73 -73
- package/dist/{needle-engine.bundle.light.js → needle-engine.bundle-ad489836.light.js} +751 -750
- package/dist/{needle-engine.bundle.light.umd.cjs → needle-engine.bundle-cb5d2462.light.umd.cjs} +82 -82
- package/dist/needle-engine.js +7 -7
- package/dist/needle-engine.light.js +7 -7
- package/dist/needle-engine.light.min.js +1 -1
- package/dist/needle-engine.light.umd.cjs +1 -1
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing.js → postprocessing-1f7b0484.light.js} +2 -2
- package/dist/{postprocessing.light.min.js → postprocessing-3a475b1f.light.min.js} +1 -1
- package/dist/{postprocessing.light.umd.cjs → postprocessing-3a5c88ab.light.umd.cjs} +1 -1
- package/dist/{postprocessing.light.js → postprocessing-7f24854b.js} +2 -2
- package/dist/{postprocessing.min.js → postprocessing-992c1d00.min.js} +1 -1
- package/dist/{postprocessing.umd.cjs → postprocessing-a77d707a.umd.cjs} +1 -1
- package/dist/{three.light.umd.cjs → three-67c59991.umd.cjs} +1 -1
- package/dist/{three.umd.cjs → three-ed3e16aa.light.umd.cjs} +1 -1
- package/dist/{three-examples.light.umd.cjs → three-examples-609de8cf.light.umd.cjs} +1 -1
- package/dist/{three-examples.min.js → three-examples-84a86d3a.min.js} +1 -1
- package/dist/{three-examples.js → three-examples-9070776e.js} +1 -1
- package/dist/{three-examples.umd.cjs → three-examples-a36ec195.umd.cjs} +1 -1
- package/dist/{three-examples.light.js → three-examples-ae5d9997.light.js} +1 -1
- package/dist/{three-examples.light.min.js → three-examples-e915b453.light.min.js} +1 -1
- package/dist/{three-mesh-ui.light.umd.cjs → three-mesh-ui-0f43a7e0.umd.cjs} +1 -1
- package/dist/{three-mesh-ui.min.js → three-mesh-ui-34f3b06e.min.js} +1 -1
- package/dist/{three-mesh-ui.js → three-mesh-ui-3dd2ba28.js} +1 -1
- package/dist/{three-mesh-ui.light.min.js → three-mesh-ui-6c3bb6f5.light.min.js} +1 -1
- package/dist/{three-mesh-ui.light.js → three-mesh-ui-a93a09fb.light.js} +1 -1
- package/dist/{three-mesh-ui.umd.cjs → three-mesh-ui-c6a7f37c.light.umd.cjs} +1 -1
- package/dist/{vendor.umd.cjs → vendor-017686ea.light.umd.cjs} +1 -1
- package/dist/{vendor.light.umd.cjs → vendor-2a57f283.umd.cjs} +1 -1
- package/dist/{vendor.light.js → vendor-3f0ec7ec.light.js} +1 -1
- package/dist/{vendor.js → vendor-804f80f4.js} +1 -1
- package/dist/{vendor.min.js → vendor-e7e3da93.min.js} +1 -1
- package/dist/{vendor.light.min.js → vendor-ec47e3c4.light.min.js} +1 -1
- package/lib/engine/engine_networking.d.ts +1 -1
- package/lib/engine/engine_networking.js +13 -2
- package/lib/engine/engine_networking.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_networking.ts +13 -2
- /package/dist/{rapier.light.umd.cjs → rapier-32f37222.light.umd.cjs} +0 -0
- /package/dist/{rapier.umd.cjs → rapier-32f37222.umd.cjs} +0 -0
- /package/dist/{rapier.light.min.js → rapier-461dfeff.light.min.js} +0 -0
- /package/dist/{rapier.min.js → rapier-461dfeff.min.js} +0 -0
- /package/dist/{rapier.js → rapier-ef0b93e2.js} +0 -0
- /package/dist/{rapier.light.js → rapier-ef0b93e2.light.js} +0 -0
- /package/dist/{three.js → three-3fd45ef1.js} +0 -0
- /package/dist/{three.light.js → three-3fd45ef1.light.js} +0 -0
- /package/dist/{three.light.min.js → three-41cc41b9.light.min.js} +0 -0
- /package/dist/{three.min.js → three-41cc41b9.min.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,10 @@ All notable changes to this package will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [4.4.6-beta] - 2025-05-05
|
|
8
|
+
- Change: Networking disconnect() should reset state + leaveRoom does now reset allowEditing to true
|
|
9
|
+
- Fix Vite prebundle engine with mesh bvh worker
|
|
10
|
+
|
|
7
11
|
## [4.4.5] - 2025-04-30
|
|
8
12
|
- Add: Support for easily adding an Animation component to the root object of a loaded glTF to automatically play animations.
|
|
9
13
|
- Add: `loadAsset` function
|
package/dist/{assets/generateMeshBVH.worker-b7788939.js → generateMeshBVH.worker-2bb9524d.js}
RENAMED
|
@@ -22,4 +22,4 @@ ${t.tab}if ( ${h} ) {
|
|
|
22
22
|
`+t.tab+i);for(let a=0,c=this.params.length-1;a<c;a++)t.addFlowCode((a===0?"":t.tab)+`}
|
|
23
23
|
|
|
24
24
|
`).removeFlowTab();return t.addFlowTab(),o}}const Oe=(...r)=>v(new Au(Fe(r,"int"))).append();let ls,ds;class et extends U{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===et.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=Q.NONE;return(this.scope===et.SIZE||this.scope===et.VIEWPORT)&&(t=Q.RENDER),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===et.VIEWPORT?e!==null?ds.copy(e.viewport):(t.getViewport(ds),ds.multiplyScalar(t.getPixelRatio())):e!==null?(ls.width=e.width,ls.height=e.height):t.getDrawingBufferSize(ls)}setup(){const t=this.scope;let e=null;return t===et.SIZE?e=xt(ls||(ls=new J)):t===et.VIEWPORT?e=xt(ds||(ds=new Ft)):e=D(Qs.div(ro)),e}generate(t){if(this.scope===et.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties(ro).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${s}.y - ${e}.y )`}return e}return super.generate(t)}}et.COORDINATE="coordinate",et.VIEWPORT="viewport",et.SIZE="size",et.UV="uv";const pi=O(et,et.UV),ro=O(et,et.SIZE),Qs=O(et,et.COORDINATE),oo=O(et,et.VIEWPORT);oo.zw,oo.xy;const fs=new J;class Mu extends Js{static get type(){return"ViewportTextureNode"}constructor(t=pi,e=null,s=null){s===null&&(s=new Aa,s.minFilter=Gi),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=Q.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(fs);const s=this.value;(s.image.width!==fs.width||s.image.height!==fs.height)&&(s.image.width=fs.width,s.image.height=fs.height,s.needsUpdate=!0);const n=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=n}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}let mi=null;class Su extends Mu{static get type(){return"ViewportDepthTextureNode"}constructor(t=pi,e=null){mi===null&&(mi=new xr),super(t,e,mi)}}const _u=C(Su);class ft extends U{static get type(){return"ViewportDepthNode"}constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===ft.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let n=null;if(e===ft.DEPTH_BASE)s!==null&&(n=co().assign(s));else if(e===ft.DEPTH)t.isPerspectiveCamera?n=zu(Mt.z,cs,hs):n=Ks(Mt.z,cs,hs);else if(e===ft.LINEAR_DEPTH)if(s!==null)if(t.isPerspectiveCamera){const i=ao(s,cs,hs);n=Ks(i,cs,hs)}else n=s;else n=Ks(Mt.z,cs,hs);return n}}ft.DEPTH_BASE="depthBase",ft.DEPTH="depth",ft.LINEAR_DEPTH="linearDepth";const Ks=(r,t,e)=>r.add(t).div(t.sub(e)),zu=(r,t,e)=>t.add(r).mul(e).div(e.sub(t).mul(r)),ao=(r,t,e)=>t.mul(e).div(e.sub(t).mul(r).sub(e)),co=C(ft,ft.DEPTH_BASE),bu=O(ft,ft.DEPTH),Eu=C(ft,ft.LINEAR_DEPTH);_u(),bu.assign=r=>co(r);class ps extends U{static get type(){return"ClippingNode"}constructor(t=ps.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:n,globalClippingCount:i}=e,o=i+n,a=s?o-n:o;return this.scope===ps.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,o,a):this.setupDefault(e.planes,o,a)}setupAlphaToCoverage(t,e,s){return tt(()=>{const n=fi(t),i=ve("float","distanceToPlane"),o=ve("float","distanceToGradient"),a=ve("float","clipOpacity");a.assign(1);let c;if(Oe(s,({i:u})=>{c=n.element(u),i.assign(Mt.dot(c.xyz).negate().add(c.w)),o.assign(i.fwidth().div(2)),a.mulAssign(hi(o.negate(),o,i)),a.equal(0).discard()}),s<e){const u=ve("float","unionclipOpacity");u.assign(1),Oe({start:s,end:e},({i:h})=>{c=n.element(h),i.assign(Mt.dot(c.xyz).negate().add(c.w)),o.assign(i.fwidth().div(2)),u.mulAssign(hi(o.negate(),o,i).oneMinus())}),a.mulAssign(u.oneMinus())}vr.a.mulAssign(a),vr.a.equal(0).discard()})()}setupDefault(t,e,s){return tt(()=>{const n=fi(t);let i;if(Oe(s,({i:o})=>{i=n.element(o),Mt.dot(i.xyz).greaterThan(i.w).discard()}),s<e){const o=ve("bool","clipped");o.assign(!0),Oe({start:s,end:e},({i:a})=>{i=n.element(a),o.assign(Mt.dot(i.xyz).greaterThan(i.w).and(o))}),o.discard()}})()}}ps.ALPHA_TO_COVERAGE="alphaToCoverage",ps.DEFAULT="default",k(.04),q(1);const Cu=tt(([r,t])=>{const e=r.toVar();e.assign(Gs(2,e).sub(1));const s=k(e,1).toVar();return ni(t.equal(0),()=>{s.assign(s.zyx)}).ElseIf(t.equal(1),()=>{s.assign(s.xzy),s.xz.mulAssign(-1)}).ElseIf(t.equal(2),()=>{s.x.mulAssign(-1)}).ElseIf(t.equal(3),()=>{s.assign(s.zyx),s.xz.mulAssign(-1)}).ElseIf(t.equal(4),()=>{s.assign(s.xzy),s.xy.mulAssign(-1)}).ElseIf(t.equal(5),()=>{s.z.mulAssign(-1)}),s}).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]});tt(({texture:r,uv:t})=>{const s=k().toVar();return ni(t.x.lessThan(1e-4),()=>{s.assign(k(1,0,0))}).ElseIf(t.y.lessThan(1e-4),()=>{s.assign(k(0,1,0))}).ElseIf(t.z.lessThan(1e-4),()=>{s.assign(k(0,0,1))}).ElseIf(t.x.greaterThan(1-1e-4),()=>{s.assign(k(-1,0,0))}).ElseIf(t.y.greaterThan(1-1e-4),()=>{s.assign(k(0,-1,0))}).ElseIf(t.z.greaterThan(1-1e-4),()=>{s.assign(k(0,0,-1))}).Else(()=>{const i=r.uv(t.add(k(-.01,0,0))).r.sub(r.uv(t.add(k(.01,0,0))).r),o=r.uv(t.add(k(0,-.01,0))).r.sub(r.uv(t.add(k(0,.01,0))).r),a=r.uv(t.add(k(0,0,-.01))).r.sub(r.uv(t.add(k(0,0,.01))).r);s.assign(k(i,o,a))}),s.normalize()});const yi=Cu(Zs(),os("faceIndex")).normalize();k(yi.x,yi.y.negate(),yi.z);class Pt extends Ie{static get type(){return"TimerNode"}constructor(t=Pt.LOCAL,e=1,s=0){super(s),this.scope=t,this.scale=e,this.updateType=Q.FRAME}update(t){const e=this.scope,s=this.scale;e===Pt.LOCAL?this.value+=t.deltaTime*s:e===Pt.DELTA?this.value=t.deltaTime*s:e===Pt.FRAME?this.value=t.frameId:this.value=t.time*s}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}Pt.LOCAL="local",Pt.GLOBAL="global",Pt.DELTA="delta",Pt.FRAME="frame";const Fu=(r,t=0)=>v(new Pt(Pt.LOCAL,r,t));class rt extends U{static get type(){return"OscNode"}constructor(t=rt.SINE,e=Fu()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=v(this.timeNode);let s=null;return t===rt.SINE?s=e.add(.75).mul(Math.PI*2).sin().mul(.5).add(.5):t===rt.SQUARE?s=e.fract().round():t===rt.TRIANGLE?s=e.add(.5).fract().mul(2).sub(1).abs():t===rt.SAWTOOTH&&(s=e.fract()),s}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}rt.SINE="sine",rt.SQUARE="square",rt.TRIANGLE="triangle",rt.SAWTOOTH="sawtooth",rt.SINE,rt.SQUARE,rt.TRIANGLE,rt.SAWTOOTH,new Xn,new A,new A,new A,new nt,new A(0,0,-1),new Ft,new A,new A,new Ft,new J,new or,pi.flipX();class Ut extends U{static get type(){return"SceneNode"}constructor(t=Ut.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=this.scene!==null?this.scene:t.scene;let n;return e===Ut.BACKGROUND_BLURRINESS?n=pe("backgroundBlurriness","float",s):e===Ut.BACKGROUND_INTENSITY?n=pe("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),n}}Ut.BACKGROUND_BLURRINESS="backgroundBlurriness",Ut.BACKGROUND_INTENSITY="backgroundIntensity",Ut.BACKGROUND_BLURRINESS,Ut.BACKGROUND_INTENSITY;const Ru=new J;class Bu extends Js{static get type(){return"PassTextureNode"}constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return t.object.isQuadMesh&&this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class ho extends Bu{static get type(){return"PassMultipleTextureNode"}constructor(t,e,s=!1){super(t,null),this.textureName=e,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(t){return this.updateTexture(),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class tn extends dt{static get type(){return"PassNode"}constructor(t,e,s,n={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=n,this._pixelRatio=1,this._width=1,this._height=1;const i=new xr;i.isRenderTargetTexture=!0,i.name="depth";const o=new or(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:vo,...n});o.texture.name="output",o.depthTexture=i,this.renderTarget=o,this.updateBeforeType=Q.FRAME,this._textures={output:o.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=xt(0),this._cameraFar=xt(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];return e===void 0&&(e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)),e}getPreviousTexture(t){let e=this._previousTextures[t];return e===void 0&&(e=this.getTexture(t).clone(),e.isRenderTargetTexture=!0,this._previousTextures[t]=e),e}toggleTexture(t){const e=this._previousTextures[t];if(e!==void 0){const s=this._textures[t],n=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[n]=e,this._textures[t]=e,this._previousTextures[t]=s,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return e===void 0&&(this._textureNodes[t]=e=v(new ho(this,t)),this._textureNodes[t].updateTexture()),e}getPreviousTextureNode(t="output"){let e=this._previousTextureNodes[t];return e===void 0&&(this._textureNodes[t]===void 0&&this.getTextureNode(t),this._previousTextureNodes[t]=e=v(new ho(this,t,!0)),this._previousTextureNodes[t].updateTexture()),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(e===void 0){const s=this._cameraNear,n=this._cameraFar;this._viewZNodes[t]=e=ao(this.getTextureNode(t),s,n)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(e===void 0){const s=this._cameraNear,n=this._cameraFar,i=this.getViewZNode(t);this._linearDepthNodes[t]=e=Ks(i,s,n)}return e}setup({renderer:t}){return this.renderTarget.samples=this.options.samples===void 0?t.samples:this.options.samples,t.backend.isWebGLBackend===!0&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===tn.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:n}=this;this._pixelRatio=e.getPixelRatio();const i=e.getSize(Ru);this.setSize(i.width,i.height);const o=e.getRenderTarget(),a=e.getMRT();this._cameraNear.value=n.near,this._cameraFar.value=n.far;for(const c in this._previousTextures)this.toggleTexture(c);e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(s,n),e.setRenderTarget(o),e.setMRT(a)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,n=this._height*this._pixelRatio;this.renderTarget.setSize(s,n)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}tn.COLOR="color",tn.DEPTH="depth",tt(({depthTexture:r,shadowCoord:t})=>as(r,t.xy).compare(t.z)),tt(({depthTexture:r,shadowCoord:t,shadow:e})=>{const s=(m,g)=>as(r,m).compare(g),n=pe("mapSize","vec2",e).setGroup(de),i=pe("radius","float",e).setGroup(de),o=D(1).div(n),a=o.x.negate().mul(i),c=o.y.negate().mul(i),u=o.x.mul(i),h=o.y.mul(i),l=a.div(2),d=c.div(2),f=u.div(2),p=h.div(2);return fe(s(t.xy.add(D(a,c)),t.z),s(t.xy.add(D(0,c)),t.z),s(t.xy.add(D(u,c)),t.z),s(t.xy.add(D(l,d)),t.z),s(t.xy.add(D(0,d)),t.z),s(t.xy.add(D(f,d)),t.z),s(t.xy.add(D(a,0)),t.z),s(t.xy.add(D(l,0)),t.z),s(t.xy,t.z),s(t.xy.add(D(f,0)),t.z),s(t.xy.add(D(u,0)),t.z),s(t.xy.add(D(l,p)),t.z),s(t.xy.add(D(0,p)),t.z),s(t.xy.add(D(f,p)),t.z),s(t.xy.add(D(a,h)),t.z),s(t.xy.add(D(0,h)),t.z),s(t.xy.add(D(u,h)),t.z)).mul(1/17)}),tt(({depthTexture:r,shadowCoord:t,shadow:e})=>{const s=(h,l)=>as(r,h).compare(l),n=pe("mapSize","vec2",e).setGroup(de),i=D(1).div(n),o=i.x,a=i.y,c=t.xy,u=ri(c.mul(n).add(.5));return c.subAssign(u.mul(i)),fe(s(c,t.z),s(c.add(D(o,0)),t.z),s(c.add(D(0,a)),t.z),s(c.add(i),t.z),re(s(c.add(D(o.negate(),0)),t.z),s(c.add(D(o.mul(2),0)),t.z),u.x),re(s(c.add(D(o.negate(),a)),t.z),s(c.add(D(o.mul(2),a)),t.z),u.x),re(s(c.add(D(0,a.negate())),t.z),s(c.add(D(0,a.mul(2))),t.z),u.y),re(s(c.add(D(o,a.negate())),t.z),s(c.add(D(o,a.mul(2))),t.z),u.y),re(re(s(c.add(D(o.negate(),a.negate())),t.z),s(c.add(D(o.mul(2),a.negate())),t.z),u.x),re(s(c.add(D(o.negate(),a.mul(2))),t.z),s(c.add(D(o.mul(2),a.mul(2))),t.z),u.x),u.y)).mul(1/9)}),tt(({depthTexture:r,shadowCoord:t})=>{const e=q(1).toVar(),s=as(r).uv(t.xy).rg,n=kr(t.z,s.x);return ni(n.notEqual(q(1)),()=>{const i=t.z.sub(s.x),o=ai(0,s.y.mul(s.y));let a=o.div(o.add(i.mul(i)));a=Ws($s(a,.3).div(.95-.3)),e.assign(Ws(ai(n,a)))}),e}),tt(({samples:r,radius:t,size:e,shadowPass:s})=>{const n=q(0).toVar(),i=q(0).toVar(),o=r.lessThanEqual(q(1)).select(q(0),q(2).div(r.sub(1))),a=r.lessThanEqual(q(1)).select(q(0),q(-1));Oe({start:Re(0),end:Re(r),type:"int",condition:"<"},({i:u})=>{const h=a.add(q(u).mul(o)),l=s.uv(fe(Qs.xy,D(0,h).mul(t)).div(e)).x;n.addAssign(l),i.addAssign(l.mul(l))}),n.divAssign(r),i.divAssign(r);const c=ii(i.sub(n.mul(n)));return D(n,c)}),tt(({samples:r,radius:t,size:e,shadowPass:s})=>{const n=q(0).toVar(),i=q(0).toVar(),o=r.lessThanEqual(q(1)).select(q(0),q(2).div(r.sub(1))),a=r.lessThanEqual(q(1)).select(q(0),q(-1));Oe({start:Re(0),end:Re(r),type:"int",condition:"<"},({i:u})=>{const h=a.add(q(u).mul(o)),l=s.uv(fe(Qs.xy,D(h,0).mul(t)).div(e));n.addAssign(l.x),i.addAssign(fe(l.y.mul(l.y),l.x.mul(l.x)))}),n.divAssign(r),i.divAssign(r);const c=ii(i.sub(n.mul(n)));return D(n,c)}),k(1.6605,-.1246,-.0182),k(-.5876,1.1329,-.1006),k(-.0728,-.0083,1.1187),k(.6274,.0691,.0164),k(.3293,.9195,.088),k(.0433,.0113,.8956);class Iu extends U{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:s}=t;s.backend.isWebGLBackend===!0?t.addFlowCode(` // ${e}Barrier
|
|
25
|
-
`):t.addLineFlowCode(`${e}Barrier()`,this)}}C(Iu);class kt extends dt{static get type(){return"AtomicFunctionNode"}constructor(t,e,s,n=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=s,this.storeNode=n}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,s=this.getNodeType(t),n=this.getInputType(t),i=this.pointerNode,o=this.valueNode,a=[];a.push(`&${i.build(t,n)}`),a.push(o.build(t,n));const c=`${t.getMethod(e,s)}( ${a.join(", ")} )`;if(this.storeNode!==null){const u=this.storeNode.build(t,n);t.addLineFlowCode(`${u} = ${c}`,this)}else t.addLineFlowCode(c,this)}}if(kt.ATOMIC_LOAD="atomicLoad",kt.ATOMIC_STORE="atomicStore",kt.ATOMIC_ADD="atomicAdd",kt.ATOMIC_SUB="atomicSub",kt.ATOMIC_MAX="atomicMax",kt.ATOMIC_MIN="atomicMin",kt.ATOMIC_AND="atomicAnd",kt.ATOMIC_OR="atomicOr",kt.ATOMIC_XOR="atomicXor",C(kt),typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Xe}})),typeof window<"u"){try{An&&An.tagName.toUpperCase()==="SCRIPT"&&An.src||new URL("assets/generateMeshBVH.worker-b7788939.js",document.baseURI).href,window.__THREE__IMPORTS__||(window.__THREE__IMPORTS__=[]),window.__THREE__IMPORTS__.push({url:self.location.href,revision:Xe})}catch{}window.__THREE__?(console.warn("WARNING: Multiple instances of Three.js being imported. Existing: "+window.__THREE__+", new: "+Xe),console.warn(window.__THREE__IMPORTS__)):window.__THREE__=Xe}const uo=0,vu=1,Pu=2,lo=2,gi=1.25,fo=1,ms=6*4+4+4,en=65535,Lu=Math.pow(2,-24),xi=Symbol("SKIP_GENERATION");function Ou(r){return r.index?r.index.count:r.attributes.position.count}function De(r){return Ou(r)/3}function Du(r,t=ArrayBuffer){return r>65535?new Uint32Array(new t(4*r)):new Uint16Array(new t(2*r))}function Vu(r,t){if(!r.index){const e=r.attributes.position.count,s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=Du(e,s);r.setIndex(new vt(n,1));for(let i=0;i<e;i++)n[i]=i}}function po(r,t){const e=De(r),s=t||r.drawRange,n=s.start/3,i=(s.start+s.count)/3,o=Math.max(0,n),a=Math.min(e,i)-o;return[{offset:Math.floor(o),count:Math.floor(a)}]}function mo(r,t){if(!r.groups||!r.groups.length)return po(r,t);const e=[],s=new Set,n=t||r.drawRange,i=n.start/3,o=(n.start+n.count)/3;for(const c of r.groups){const u=c.start/3,h=(c.start+c.count)/3;s.add(Math.max(i,u)),s.add(Math.min(o,h))}const a=Array.from(s.values()).sort((c,u)=>c-u);for(let c=0;c<a.length-1;c++){const u=a[c],h=a[c+1];e.push({offset:Math.floor(u),count:Math.floor(h-u)})}return e}function Uu(r,t){const e=De(r),s=mo(r,t).sort((o,a)=>o.offset-a.offset),n=s[s.length-1];n.count=Math.min(e-n.offset,n.count);let i=0;return s.forEach(({count:o})=>i+=o),e!==i}function Ti(r,t,e,s,n){let i=1/0,o=1/0,a=1/0,c=-1/0,u=-1/0,h=-1/0,l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,g=-1/0;for(let y=t*6,T=(t+e)*6;y<T;y+=6){const w=r[y+0],M=r[y+1],N=w-M,_=w+M;N<i&&(i=N),_>c&&(c=_),w<l&&(l=w),w>p&&(p=w);const S=r[y+2],E=r[y+3],F=S-E,R=S+E;F<o&&(o=F),R>u&&(u=R),S<d&&(d=S),S>m&&(m=S);const I=r[y+4],B=r[y+5],P=I-B,L=I+B;P<a&&(a=P),L>h&&(h=L),I<f&&(f=I),I>g&&(g=I)}s[0]=i,s[1]=o,s[2]=a,s[3]=c,s[4]=u,s[5]=h,n[0]=l,n[1]=d,n[2]=f,n[3]=p,n[4]=m,n[5]=g}function ku(r,t=null,e=null,s=null){const n=r.attributes.position,i=r.index?r.index.array:null,o=De(r),a=n.normalized;let c;t===null?(c=new Float32Array(o*6),e=0,s=o):(c=t,e=e||0,s=s||o);const u=n.array,h=n.offset||0;let l=3;n.isInterleavedBufferAttribute&&(l=n.data.stride);const d=["getX","getY","getZ"];for(let f=e;f<e+s;f++){const p=f*3,m=f*6;let g=p+0,y=p+1,T=p+2;i&&(g=i[g],y=i[y],T=i[T]),a||(g=g*l+h,y=y*l+h,T=T*l+h);for(let w=0;w<3;w++){let M,N,_;a?(M=n[d[w]](g),N=n[d[w]](y),_=n[d[w]](T)):(M=u[g+w],N=u[y+w],_=u[T+w]);let S=M;N<S&&(S=N),_<S&&(S=_);let E=M;N>E&&(E=N),_>E&&(E=_);const F=(E-S)/2,R=w*2;c[m+R+0]=S+F,c[m+R+1]=F+(Math.abs(S)+F)*Lu}}return c}function Z(r,t,e){return e.min.x=t[r],e.min.y=t[r+1],e.min.z=t[r+2],e.max.x=t[r+3],e.max.y=t[r+4],e.max.z=t[r+5],e}function yo(r){let t=-1,e=-1/0;for(let s=0;s<3;s++){const n=r[s+3]-r[s];n>e&&(e=n,t=s)}return t}function go(r,t){t.set(r)}function xo(r,t,e){let s,n;for(let i=0;i<3;i++){const o=i+3;s=r[i],n=t[i],e[i]=s<n?s:n,s=r[o],n=t[o],e[o]=s>n?s:n}}function sn(r,t,e){for(let s=0;s<3;s++){const n=t[r+2*s],i=t[r+2*s+1],o=n-i,a=n+i;o<e[s]&&(e[s]=o),a>e[s+3]&&(e[s+3]=a)}}function ys(r){const t=r[3]-r[0],e=r[4]-r[1],s=r[5]-r[2];return 2*(t*e+e*s+s*t)}const jt=32,Hu=(r,t)=>r.candidate-t.candidate,oe=new Array(jt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),nn=new Float32Array(6);function qu(r,t,e,s,n,i){let o=-1,a=0;if(i===uo)o=yo(t),o!==-1&&(a=(t[o]+t[o+3])/2);else if(i===vu)o=yo(r),o!==-1&&(a=$u(e,s,n,o));else if(i===Pu){const c=ys(r);let u=gi*n;const h=s*6,l=(s+n)*6;for(let d=0;d<3;d++){const f=t[d],g=(t[d+3]-f)/jt;if(n<jt/4){const y=[...oe];y.length=n;let T=0;for(let M=h;M<l;M+=6,T++){const N=y[T];N.candidate=e[M+2*d],N.count=0;const{bounds:_,leftCacheBounds:S,rightCacheBounds:E}=N;for(let F=0;F<3;F++)E[F]=1/0,E[F+3]=-1/0,S[F]=1/0,S[F+3]=-1/0,_[F]=1/0,_[F+3]=-1/0;sn(M,e,_)}y.sort(Hu);let w=n;for(let M=0;M<w;M++){const N=y[M];for(;M+1<w&&y[M+1].candidate===N.candidate;)y.splice(M+1,1),w--}for(let M=h;M<l;M+=6){const N=e[M+2*d];for(let _=0;_<w;_++){const S=y[_];N>=S.candidate?sn(M,e,S.rightCacheBounds):(sn(M,e,S.leftCacheBounds),S.count++)}}for(let M=0;M<w;M++){const N=y[M],_=N.count,S=n-N.count,E=N.leftCacheBounds,F=N.rightCacheBounds;let R=0;_!==0&&(R=ys(E)/c);let I=0;S!==0&&(I=ys(F)/c);const B=fo+gi*(R*_+I*S);B<u&&(o=d,u=B,a=N.candidate)}}else{for(let w=0;w<jt;w++){const M=oe[w];M.count=0,M.candidate=f+g+w*g;const N=M.bounds;for(let _=0;_<3;_++)N[_]=1/0,N[_+3]=-1/0}for(let w=h;w<l;w+=6){let _=~~((e[w+2*d]-f)/g);_>=jt&&(_=jt-1);const S=oe[_];S.count++,sn(w,e,S.bounds)}const y=oe[jt-1];go(y.bounds,y.rightCacheBounds);for(let w=jt-2;w>=0;w--){const M=oe[w],N=oe[w+1];xo(M.bounds,N.rightCacheBounds,M.rightCacheBounds)}let T=0;for(let w=0;w<jt-1;w++){const M=oe[w],N=M.count,_=M.bounds,E=oe[w+1].rightCacheBounds;N!==0&&(T===0?go(_,nn):xo(_,nn,nn)),T+=N;let F=0,R=0;T!==0&&(F=ys(nn)/c);const I=n-T;I!==0&&(R=ys(E)/c);const B=fo+gi*(F*T+R*I);B<u&&(o=d,u=B,a=M.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${i} used.`);return{axis:o,pos:a}}function $u(r,t,e,s){let n=0;for(let i=t,o=t+e;i<o;i++)n+=r[i*6+s*2];return n/e}class Ni{constructor(){this.boundingData=new Float32Array(6)}}function Gu(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2;for(;;){for(;o<=a&&e[o*6+u]<c;)o++;for(;o<=a&&e[a*6+u]>=c;)a--;if(o<a){for(let h=0;h<3;h++){let l=t[o*3+h];t[o*3+h]=t[a*3+h],t[a*3+h]=l}for(let h=0;h<6;h++){let l=e[o*6+h];e[o*6+h]=e[a*6+h],e[a*6+h]=l}o++,a--}else return o}}function Wu(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2;for(;;){for(;o<=a&&e[o*6+u]<c;)o++;for(;o<=a&&e[a*6+u]>=c;)a--;if(o<a){let h=r[o];r[o]=r[a],r[a]=h;for(let l=0;l<6;l++){let d=e[o*6+l];e[o*6+l]=e[a*6+l],e[a*6+l]=d}o++,a--}else return o}}function pt(r,t){return t[r+15]===65535}function Tt(r,t){return t[r+6]}function St(r,t){return t[r+14]}function _t(r){return r+8}function zt(r,t){return t[r+6]}function To(r,t){return t[r+7]}function jl(r){return r}let No,gs,rn,wo;const Xu=Math.pow(2,32);function wi(r){return"count"in r?1:1+wi(r.left)+wi(r.right)}function Yu(r,t,e){return No=new Float32Array(e),gs=new Uint32Array(e),rn=new Uint16Array(e),wo=new Uint8Array(e),Ai(r,t)}function Ai(r,t){const e=r/4,s=r/2,n="count"in t,i=t.boundingData;for(let o=0;o<6;o++)No[e+o]=i[o];if(n)if(t.buffer){const o=t.buffer;wo.set(new Uint8Array(o),r);for(let a=r,c=r+o.byteLength;a<c;a+=ms){const u=a/2;pt(u,rn)||(gs[a/4+6]+=e)}return r+o.byteLength}else{const o=t.offset,a=t.count;return gs[e+6]=o,rn[s+14]=a,rn[s+15]=en,r+ms}else{const o=t.left,a=t.right,c=t.splitAxis;let u;if(u=Ai(r+ms,o),u/4>Xu)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return gs[e+6]=u/4,u=Ai(u,a),gs[e+7]=c,u}}function Zu(r,t){const e=(r.index?r.index.count:r.attributes.position.count)/3,s=e>2**16,n=s?4:2,i=t?new SharedArrayBuffer(e*n):new ArrayBuffer(e*n),o=s?new Uint32Array(i):new Uint16Array(i);for(let a=0,c=o.length;a<c;a++)o[a]=a;return o}function Ju(r,t,e,s,n){const{maxDepth:i,verbose:o,maxLeafTris:a,strategy:c,onProgress:u,indirect:h}=n,l=r._indirectBuffer,d=r.geometry,f=d.index?d.index.array:null,p=h?Wu:Gu,m=De(d),g=new Float32Array(6);let y=!1;const T=new Ni;return Ti(t,e,s,T.boundingData,g),M(T,e,s,g),T;function w(N){u&&u(N/m)}function M(N,_,S,E=null,F=0){if(!y&&F>=i&&(y=!0,o&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),S<=a||F>=i)return w(_+S),N.offset=_,N.count=S,N;const R=qu(N.boundingData,E,t,_,S,c);if(R.axis===-1)return w(_+S),N.offset=_,N.count=S,N;const I=p(l,f,t,_,S,R);if(I===_||I===_+S)w(_+S),N.offset=_,N.count=S;else{N.splitAxis=R.axis;const B=new Ni,P=_,L=I-_;N.left=B,Ti(t,P,L,B.boundingData,g),M(B,P,L,g,F+1);const V=new Ni,G=I,Nt=S-L;N.right=V,Ti(t,G,Nt,V.boundingData,g),M(V,G,Nt,g,F+1)}return N}}function ju(r,t){const e=r.geometry;t.indirect&&(r._indirectBuffer=Zu(e,t.useSharedArrayBuffer),Uu(e,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),r._indirectBuffer||Vu(e,t);const s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=ku(e),i=t.indirect?po(e,t.range):mo(e,t.range);r._roots=i.map(o=>{const a=Ju(r,n,o.offset,o.count,t),c=wi(a),u=new s(ms*c);return Yu(0,a,u),u})}class Qt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let s=1/0,n=-1/0;for(let i=0,o=t.length;i<o;i++){const c=t[i][e];s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}setFromPoints(t,e){let s=1/0,n=-1/0;for(let i=0,o=e.length;i<o;i++){const a=e[i],c=t.dot(a);s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}Qt.prototype.setFromBox=function(){const r=new A;return function(e,s){const n=s.min,i=s.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){r.x=n.x*c+i.x*(1-c),r.y=n.y*u+i.y*(1-u),r.z=n.z*h+i.z*(1-h);const l=e.dot(r);o=Math.min(l,o),a=Math.max(l,a)}this.min=o,this.max=a}}();const Qu=function(){const r=new A,t=new A,e=new A;return function(n,i,o){const a=n.start,c=r,u=i.start,h=t;e.subVectors(a,u),r.subVectors(n.end,n.start),t.subVectors(i.end,i.start);const l=e.dot(h),d=h.dot(c),f=h.dot(h),p=e.dot(c),g=c.dot(c)*f-d*d;let y,T;g!==0?y=(l*d-p*f)/g:y=0,T=(l+y*d)/f,o.x=y,o.y=T}}(),Mi=function(){const r=new J,t=new A,e=new A;return function(n,i,o,a){Qu(n,i,r);let c=r.x,u=r.y;if(c>=0&&c<=1&&u>=0&&u<=1){n.at(c,o),i.at(u,a);return}else if(c>=0&&c<=1){u<0?i.at(0,a):i.at(1,a),n.closestPointToPoint(a,!0,o);return}else if(u>=0&&u<=1){c<0?n.at(0,o):n.at(1,o),i.closestPointToPoint(o,!0,a);return}else{let h;c<0?h=n.start:h=n.end;let l;u<0?l=i.start:l=i.end;const d=t,f=e;if(n.closestPointToPoint(l,!0,t),i.closestPointToPoint(h,!0,e),d.distanceToSquared(l)<=f.distanceToSquared(h)){o.copy(d),a.copy(l);return}else{o.copy(h),a.copy(f);return}}}}(),Ku=function(){const r=new A,t=new A,e=new Xn,s=new Zt;return function(i,o){const{radius:a,center:c}=i,{a:u,b:h,c:l}=o;if(s.start=u,s.end=h,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a||(s.start=u,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a)||(s.start=h,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a))return!0;const m=o.getPlane(e);if(Math.abs(m.distanceToPoint(c))<=a){const y=m.projectPoint(c,t);if(o.containsPoint(y))return!0}return!1}}(),tl=1e-15;function Si(r){return Math.abs(r)<tl}class Lt extends wt{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new A),this.satBounds=new Array(4).fill().map(()=>new Qt),this.points=[this.a,this.b,this.c],this.sphere=new cr,this.plane=new Xn,this.needsUpdate=!0}intersectsSphere(t){return Ku(t,this)}update(){const t=this.a,e=this.b,s=this.c,n=this.points,i=this.satAxes,o=this.satBounds,a=i[0],c=o[0];this.getNormal(a),c.setFromPoints(a,n);const u=i[1],h=o[1];u.subVectors(t,e),h.setFromPoints(u,n);const l=i[2],d=o[2];l.subVectors(e,s),d.setFromPoints(l,n);const f=i[3],p=o[3];f.subVectors(s,t),p.setFromPoints(f,n),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}Lt.prototype.closestPointToSegment=function(){const r=new A,t=new A,e=new Zt;return function(n,i=null,o=null){const{start:a,end:c}=n,u=this.points;let h,l=1/0;for(let d=0;d<3;d++){const f=(d+1)%3;e.start.copy(u[d]),e.end.copy(u[f]),Mi(e,n,r,t),h=r.distanceToSquared(t),h<l&&(l=h,i&&i.copy(r),o&&o.copy(t))}return this.closestPointToPoint(a,r),h=a.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(a)),this.closestPointToPoint(c,r),h=c.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(c)),Math.sqrt(l)}}(),Lt.prototype.intersectsTriangle=function(){const r=new Lt,t=new Array(3),e=new Array(3),s=new Qt,n=new Qt,i=new A,o=new A,a=new A,c=new A,u=new A,h=new Zt,l=new Zt,d=new Zt,f=new A;function p(m,g,y){const T=m.points;let w=0,M=-1;for(let N=0;N<3;N++){const{start:_,end:S}=h;_.copy(T[N]),S.copy(T[(N+1)%3]),h.delta(o);const E=Si(g.distanceToPoint(_));if(Si(g.normal.dot(o))&&E){y.copy(h),w=2;break}const F=g.intersectLine(h,f);if(!F&&E&&f.copy(_),(F||E)&&!Si(f.distanceTo(S))){if(w<=1)(w===1?y.start:y.end).copy(f),E&&(M=w);else if(w>=2){(M===1?y.start:y.end).copy(f),w=2;break}if(w++,w===2&&M===-1)break}}return w}return function(g,y=null,T=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(r.copy(g),r.update(),g=r);const w=this.plane,M=g.plane;if(Math.abs(w.normal.dot(M.normal))>1-1e-10){const N=this.satBounds,_=this.satAxes;e[0]=g.a,e[1]=g.b,e[2]=g.c;for(let F=0;F<4;F++){const R=N[F],I=_[F];if(s.setFromPoints(I,e),R.isSeparated(s))return!1}const S=g.satBounds,E=g.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let F=0;F<4;F++){const R=S[F],I=E[F];if(s.setFromPoints(I,t),R.isSeparated(s))return!1}for(let F=0;F<4;F++){const R=_[F];for(let I=0;I<4;I++){const B=E[I];if(i.crossVectors(R,B),s.setFromPoints(i,t),n.setFromPoints(i,e),s.isSeparated(n))return!1}}return y&&(T||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),y.start.set(0,0,0),y.end.set(0,0,0)),!0}else{const N=p(this,M,l);if(N===1&&g.containsPoint(l.end))return y&&(y.start.copy(l.end),y.end.copy(l.end)),!0;if(N!==2)return!1;const _=p(g,w,d);if(_===1&&this.containsPoint(d.end))return y&&(y.start.copy(d.end),y.end.copy(d.end)),!0;if(_!==2)return!1;if(l.delta(a),d.delta(c),a.dot(c)<0){let P=d.start;d.start=d.end,d.end=P}const S=l.start.dot(a),E=l.end.dot(a),F=d.start.dot(a),R=d.end.dot(a),I=E<F,B=S<R;return S!==R&&F!==E&&I===B?!1:(y&&(u.subVectors(l.start,d.start),u.dot(a)>0?y.start.copy(l.start):y.start.copy(d.start),u.subVectors(l.end,d.end),u.dot(a)<0?y.end.copy(l.end):y.end.copy(d.end)),!0)}}}(),Lt.prototype.distanceToPoint=function(){const r=new A;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),Lt.prototype.distanceToTriangle=function(){const r=new A,t=new A,e=["a","b","c"],s=new Zt,n=new Zt;return function(o,a=null,c=null){const u=a||c?s:null;if(this.intersectsTriangle(o,u))return(a||c)&&(a&&u.getCenter(a),c&&u.getCenter(c)),0;let h=1/0;for(let l=0;l<3;l++){let d;const f=e[l],p=o[f];this.closestPointToPoint(p,r),d=p.distanceToSquared(r),d<h&&(h=d,a&&a.copy(r),c&&c.copy(p));const m=this[f];o.closestPointToPoint(m,r),d=m.distanceToSquared(r),d<h&&(h=d,a&&a.copy(m),c&&c.copy(r))}for(let l=0;l<3;l++){const d=e[l],f=e[(l+1)%3];s.set(this[d],this[f]);for(let p=0;p<3;p++){const m=e[p],g=e[(p+1)%3];n.set(o[m],o[g]),Mi(s,n,r,t);const y=r.distanceToSquared(t);y<h&&(h=y,a&&a.copy(r),c&&c.copy(t))}}return Math.sqrt(h)}}();class lt{constructor(t,e,s){this.isOrientedBox=!0,this.min=new A,this.max=new A,this.matrix=new nt,this.invMatrix=new nt,this.points=new Array(8).fill().map(()=>new A),this.satAxes=new Array(3).fill().map(()=>new A),this.satBounds=new Array(3).fill().map(()=>new Qt),this.alignedSatBounds=new Array(3).fill().map(()=>new Qt),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),s&&this.matrix.copy(s)}set(t,e,s){this.min.copy(t),this.max.copy(e),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}lt.prototype.update=function(){return function(){const t=this.matrix,e=this.min,s=this.max,n=this.points;for(let u=0;u<=1;u++)for(let h=0;h<=1;h++)for(let l=0;l<=1;l++){const d=1*u|2*h|4*l,f=n[d];f.x=u?s.x:e.x,f.y=h?s.y:e.y,f.z=l?s.z:e.z,f.applyMatrix4(t)}const i=this.satBounds,o=this.satAxes,a=n[0];for(let u=0;u<3;u++){const h=o[u],l=i[u],d=1<<u,f=n[d];h.subVectors(a,f),l.setFromPoints(h,n)}const c=this.alignedSatBounds;c[0].setFromPointsField(n,"x"),c[1].setFromPointsField(n,"y"),c[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),lt.prototype.intersectsBox=function(){const r=new Qt;return function(e){this.needsUpdate&&this.update();const s=e.min,n=e.max,i=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(r.min=s.x,r.max=n.x,a[0].isSeparated(r)||(r.min=s.y,r.max=n.y,a[1].isSeparated(r))||(r.min=s.z,r.max=n.z,a[2].isSeparated(r)))return!1;for(let c=0;c<3;c++){const u=o[c],h=i[c];if(r.setFromBox(u,e),h.isSeparated(r))return!1}return!0}}(),lt.prototype.intersectsTriangle=function(){const r=new Lt,t=new Array(3),e=new Qt,s=new Qt,n=new A;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(r.copy(o),r.update(),o=r);const a=this.satBounds,c=this.satAxes;t[0]=o.a,t[1]=o.b,t[2]=o.c;for(let d=0;d<3;d++){const f=a[d],p=c[d];if(e.setFromPoints(p,t),f.isSeparated(e))return!1}const u=o.satBounds,h=o.satAxes,l=this.points;for(let d=0;d<3;d++){const f=u[d],p=h[d];if(e.setFromPoints(p,l),f.isSeparated(e))return!1}for(let d=0;d<3;d++){const f=c[d];for(let p=0;p<4;p++){const m=h[p];if(n.crossVectors(f,m),e.setFromPoints(n,t),s.setFromPoints(n,l),e.isSeparated(s))return!1}}return!0}}(),lt.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),lt.prototype.distanceToPoint=function(){const r=new A;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),lt.prototype.distanceToBox=function(){const r=["x","y","z"],t=new Array(12).fill().map(()=>new Zt),e=new Array(12).fill().map(()=>new Zt),s=new A,n=new A;return function(o,a=0,c=null,u=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||u)&&(o.getCenter(n),this.closestPointToPoint(n,s),o.closestPointToPoint(s,n),c&&c.copy(s),u&&u.copy(n)),0;const h=a*a,l=o.min,d=o.max,f=this.points;let p=1/0;for(let g=0;g<8;g++){const y=f[g];n.copy(y).clamp(l,d);const T=y.distanceToSquared(n);if(T<p&&(p=T,c&&c.copy(y),u&&u.copy(n),T<h))return Math.sqrt(T)}let m=0;for(let g=0;g<3;g++)for(let y=0;y<=1;y++)for(let T=0;T<=1;T++){const w=(g+1)%3,M=(g+2)%3,N=y<<w|T<<M,_=1<<g|y<<w|T<<M,S=f[N],E=f[_];t[m].set(S,E);const R=r[g],I=r[w],B=r[M],P=e[m],L=P.start,V=P.end;L[R]=l[R],L[I]=y?l[I]:d[I],L[B]=T?l[B]:d[I],V[R]=d[R],V[I]=y?l[I]:d[I],V[B]=T?l[B]:d[I],m++}for(let g=0;g<=1;g++)for(let y=0;y<=1;y++)for(let T=0;T<=1;T++){n.x=g?d.x:l.x,n.y=y?d.y:l.y,n.z=T?d.z:l.z,this.closestPointToPoint(n,s);const w=n.distanceToSquared(s);if(w<p&&(p=w,c&&c.copy(s),u&&u.copy(n),w<h))return Math.sqrt(w)}for(let g=0;g<12;g++){const y=t[g];for(let T=0;T<12;T++){const w=e[T];Mi(y,w,s,n);const M=s.distanceToSquared(n);if(M<p&&(p=M,c&&c.copy(s),u&&u.copy(n),M<h))return Math.sqrt(M)}}return Math.sqrt(p)}}();class _i{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class el extends _i{constructor(){super(()=>new Lt)}}const bt=new el;class sl{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=s=>{e&&t.push(e),e=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const X=new sl;let ae,Ve;const Ue=[],on=new _i(()=>new ht);function nl(r,t,e,s,n,i){ae=on.getPrimitive(),Ve=on.getPrimitive(),Ue.push(ae,Ve),X.setBuffer(r._roots[t]);const o=zi(0,r.geometry,e,s,n,i);X.clearBuffer(),on.releasePrimitive(ae),on.releasePrimitive(Ve),Ue.pop(),Ue.pop();const a=Ue.length;return a>0&&(Ve=Ue[a-1],ae=Ue[a-2]),o}function zi(r,t,e,s,n=null,i=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:u}=X;let h=r*2;if(pt(h,c)){const d=Tt(r,u),f=St(h,c);return Z(r,a,ae),s(d,f,!1,o,i+r,ae)}else{let R=function(B){const{uint16Array:P,uint32Array:L}=X;let V=B*2;for(;!pt(V,P);)B=_t(B),V=B*2;return Tt(B,L)},I=function(B){const{uint16Array:P,uint32Array:L}=X;let V=B*2;for(;!pt(V,P);)B=zt(B,L),V=B*2;return Tt(B,L)+St(V,P)};const d=_t(r),f=zt(r,u);let p=d,m=f,g,y,T,w;if(n&&(T=ae,w=Ve,Z(p,a,T),Z(m,a,w),g=n(T),y=n(w),y<g)){p=f,m=d;const B=g;g=y,y=B,T=w}T||(T=ae,Z(p,a,T));const M=pt(p*2,c),N=e(T,M,g,o+1,i+p);let _;if(N===lo){const B=R(p),L=I(p)-B;_=s(B,L,!0,o+1,i+p,T)}else _=N&&zi(p,t,e,s,n,i,o+1);if(_)return!0;w=Ve,Z(m,a,w);const S=pt(m*2,c),E=e(w,S,y,o+1,i+m);let F;if(E===lo){const B=R(m),L=I(m)-B;F=s(B,L,!0,o+1,i+m,w)}else F=E&&zi(m,t,e,s,n,i,o+1);return!!F}}const xs=new A,bi=new A;function il(r,t,e={},s=0,n=1/0){const i=s*s,o=n*n;let a=1/0,c=null;if(r.shapecast({boundsTraverseOrder:h=>(xs.copy(t).clamp(h.min,h.max),xs.distanceToSquared(t)),intersectsBounds:(h,l,d)=>d<a&&d<o,intersectsTriangle:(h,l)=>{h.closestPointToPoint(t,xs);const d=t.distanceToSquared(xs);return d<a&&(bi.copy(xs),a=d,c=l),d<i}}),a===1/0)return null;const u=Math.sqrt(a);return e.point?e.point.copy(bi):e.point=bi.clone(),e.distance=u,e.faceIndex=c,e}const rl=parseInt(Xe)>=169,me=new A,ye=new A,ge=new A,an=new J,cn=new J,hn=new J,Ao=new A,Mo=new A,So=new A,Ts=new A;function ol(r,t,e,s,n,i,o,a){let c;if(i===Ui?c=r.intersectTriangle(s,e,t,!0,n):c=r.intersectTriangle(t,e,s,i!==Eo,n),c===null)return null;const u=r.origin.distanceTo(n);return u<o||u>a?null:{distance:u,point:n.clone()}}function al(r,t,e,s,n,i,o,a,c,u,h){me.fromBufferAttribute(t,i),ye.fromBufferAttribute(t,o),ge.fromBufferAttribute(t,a);const l=ol(r,me,ye,ge,Ts,c,u,h);if(l){const d=new A;wt.getBarycoord(Ts,me,ye,ge,d),s&&(an.fromBufferAttribute(s,i),cn.fromBufferAttribute(s,o),hn.fromBufferAttribute(s,a),l.uv=wt.getInterpolation(Ts,me,ye,ge,an,cn,hn,new J)),n&&(an.fromBufferAttribute(n,i),cn.fromBufferAttribute(n,o),hn.fromBufferAttribute(n,a),l.uv1=wt.getInterpolation(Ts,me,ye,ge,an,cn,hn,new J)),e&&(Ao.fromBufferAttribute(e,i),Mo.fromBufferAttribute(e,o),So.fromBufferAttribute(e,a),l.normal=wt.getInterpolation(Ts,me,ye,ge,Ao,Mo,So,new A),l.normal.dot(r.direction)>0&&l.normal.multiplyScalar(-1));const f={a:i,b:o,c:a,normal:new A,materialIndex:0};wt.getNormal(me,ye,ge,f.normal),l.face=f,l.faceIndex=i,rl&&(l.barycoord=d)}return l}function un(r,t,e,s,n,i,o){const a=s*3;let c=a+0,u=a+1,h=a+2;const l=r.index;r.index&&(c=l.getX(c),u=l.getX(u),h=l.getX(h));const{position:d,normal:f,uv:p,uv1:m}=r.attributes,g=al(e,d,f,p,m,c,u,h,t,i,o);return g?(g.faceIndex=s,n&&n.push(g),g):null}function st(r,t,e,s){const n=r.a,i=r.b,o=r.c;let a=t,c=t+1,u=t+2;e&&(a=e.getX(a),c=e.getX(c),u=e.getX(u)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),i.x=s.getX(c),i.y=s.getY(c),i.z=s.getZ(c),o.x=s.getX(u),o.y=s.getY(u),o.z=s.getZ(u)}function cl(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++)un(c,t,e,h,i,o,a)}function hl(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let f;f=un(a,t,e,l,null,i,o),f&&f.distance<u&&(h=f,u=f.distance)}return h}function ul(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=h,st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function ll(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,f=h.length;d<f;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,f,p=!1){const m=d*2;if(a[m+15]===en){const y=o[d+6],T=a[m+14];let w=1/0,M=1/0,N=1/0,_=-1/0,S=-1/0,E=-1/0;for(let F=3*y,R=3*(y+T);F<R;F++){let I=s[F];const B=n.getX(I),P=n.getY(I),L=n.getZ(I);B<w&&(w=B),B>_&&(_=B),P<M&&(M=P),P>S&&(S=P),L<N&&(N=L),L>E&&(E=L)}return c[d+0]!==w||c[d+1]!==M||c[d+2]!==N||c[d+3]!==_||c[d+4]!==S||c[d+5]!==E?(c[d+0]=w,c[d+1]=M,c[d+2]=N,c[d+3]=_,c[d+4]=S,c[d+5]=E,!0):!1}else{const y=d+8,T=o[d+6],w=y+f,M=T+f;let N=p,_=!1,S=!1;t?N||(_=t.has(w),S=t.has(M),N=!_&&!S):(_=!0,S=!0);const E=N||_,F=N||S;let R=!1;E&&(R=l(y,f,N));let I=!1;F&&(I=l(T,f,N));const B=R||I;if(B)for(let P=0;P<3;P++){const L=y+P,V=T+P,G=c[L],Nt=c[L+3],Ht=c[V],qt=c[V+3];c[d+P]=G<Ht?G:Ht,c[d+P+3]=Nt>qt?Nt:qt}return B}}}function ce(r,t,e,s,n){let i,o,a,c,u,h;const l=1/e.direction.x,d=1/e.direction.y,f=1/e.direction.z,p=e.origin.x,m=e.origin.y,g=e.origin.z;let y=t[r],T=t[r+3],w=t[r+1],M=t[r+3+1],N=t[r+2],_=t[r+3+2];return l>=0?(i=(y-p)*l,o=(T-p)*l):(i=(T-p)*l,o=(y-p)*l),d>=0?(a=(w-m)*d,c=(M-m)*d):(a=(M-m)*d,c=(w-m)*d),i>c||a>o||((a>i||isNaN(i))&&(i=a),(c<o||isNaN(o))&&(o=c),f>=0?(u=(N-g)*f,h=(_-g)*f):(u=(_-g)*f,h=(N-g)*f),i>h||u>o)?!1:((u>i||i!==i)&&(i=u),(h<o||o!==o)&&(o=h),i<=n&&o>=s)}function dl(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++){let d=u?u[h]:h;un(c,t,e,d,i,o,a)}}function fl(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let f;f=un(a,t,e,c?c[l]:l,null,i,o),f&&f.distance<u&&(h=f,u=f.distance)}return h}function pl(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=e.resolveTriangleIndex(h),st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function ml(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),Ei(0,r,e,s,n,i,o),X.clearBuffer()}function Ei(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(pt(h,c)){const d=Tt(r,u),f=St(h,c);cl(t,e,s,d,f,n,i,o)}else{const d=_t(r);ce(d,a,s,i,o)&&Ei(d,t,e,s,n,i,o);const f=zt(r,u);ce(f,a,s,i,o)&&Ei(f,t,e,s,n,i,o)}}const yl=["x","y","z"];function gl(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=Ci(0,r,e,s,n,i);return X.clearBuffer(),o}function Ci(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(pt(u,a)){const l=Tt(r,c),d=St(u,a);return hl(t,e,s,l,d,n,i)}else{const l=To(r,c),d=yl[l],p=s.direction[d]>=0;let m,g;p?(m=_t(r),g=zt(r,c)):(m=zt(r,c),g=_t(r));const T=ce(m,o,s,n,i)?Ci(m,t,e,s,n,i):null;if(T){const N=T.point[d];if(p?N<=o[g+l]:N>=o[g+l+3])return T}const M=ce(g,o,s,n,i)?Ci(g,t,e,s,n,i):null;return T&&M?T.distance<=M.distance?T:M:T||M||null}}const ln=new ht,ke=new Lt,He=new Lt,Ns=new nt,_o=new lt,dn=new lt;function xl(r,t,e,s){X.setBuffer(r._roots[t]);const n=Fi(0,r,e,s);return X.clearBuffer(),n}function Fi(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),_o.set(e.boundingBox.min,e.boundingBox.max,s),n=_o),pt(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,f=e.index,p=e.attributes.position,m=Tt(r,a),g=St(c,o);if(Ns.copy(s).invert(),e.boundsTree)return Z(r,i,dn),dn.matrix.copy(Ns),dn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:T=>dn.intersectsBox(T),intersectsTriangle:T=>{T.a.applyMatrix4(s),T.b.applyMatrix4(s),T.c.applyMatrix4(s),T.needsUpdate=!0;for(let w=m*3,M=(g+m)*3;w<M;w+=3)if(st(He,w,l,d),He.needsUpdate=!0,T.intersectsTriangle(He))return!0;return!1}});for(let y=m*3,T=(g+m)*3;y<T;y+=3){st(ke,y,l,d),ke.a.applyMatrix4(Ns),ke.b.applyMatrix4(Ns),ke.c.applyMatrix4(Ns),ke.needsUpdate=!0;for(let w=0,M=f.count;w<M;w+=3)if(st(He,w,f,p),He.needsUpdate=!0,ke.intersectsTriangle(He))return!0}}else{const h=r+8,l=a[r+6];return Z(h,i,ln),!!(n.intersectsBox(ln)&&Fi(h,t,e,s,n)||(Z(l,i,ln),n.intersectsBox(ln)&&Fi(l,t,e,s,n)))}}const fn=new nt,Ri=new lt,ws=new lt,Tl=new A,Nl=new A,wl=new A,Al=new A;function Ml(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Ri.set(t.boundingBox.min,t.boundingBox.max,e),Ri.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=bt.getPrimitive(),f=bt.getPrimitive();let p=Tl,m=Nl,g=null,y=null;n&&(g=wl,y=Al);let T=1/0,w=null,M=null;return fn.copy(e).invert(),ws.matrix.copy(fn),r.shapecast({boundsTraverseOrder:N=>Ri.distanceToBox(N),intersectsBounds:(N,_,S)=>S<T&&S<o?(_&&(ws.min.copy(N.min),ws.max.copy(N.max),ws.needsUpdate=!0),!0):!1,intersectsRange:(N,_)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:E=>ws.distanceToBox(E),intersectsBounds:(E,F,R)=>R<T&&R<o,intersectsRange:(E,F)=>{for(let R=E,I=E+F;R<I;R++){st(f,3*R,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let B=N,P=N+_;B<P;B++){st(d,3*B,u,c),d.needsUpdate=!0;const L=d.distanceToTriangle(f,p,g);if(L<T&&(m.copy(p),y&&y.copy(g),T=L,w=B,M=R),L<i)return!0}}}});{const S=De(t);for(let E=0,F=S;E<F;E++){st(f,3*E,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let R=N,I=N+_;R<I;R++){st(d,3*R,u,c),d.needsUpdate=!0;const B=d.distanceToTriangle(f,p,g);if(B<T&&(m.copy(p),y&&y.copy(g),T=B,w=R,M=E),B<i)return!0}}}}}),bt.releasePrimitive(d),bt.releasePrimitive(f),T===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=T,s.faceIndex=w,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(fn),m.applyMatrix4(fn),n.distance=m.sub(n.point).length(),n.faceIndex=M),s)}function Sl(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,f=h.length;d<f;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,f,p=!1){const m=d*2;if(a[m+15]===en){const y=o[d+6],T=a[m+14];let w=1/0,M=1/0,N=1/0,_=-1/0,S=-1/0,E=-1/0;for(let F=y,R=y+T;F<R;F++){const I=3*r.resolveTriangleIndex(F);for(let B=0;B<3;B++){let P=I+B;P=s?s[P]:P;const L=n.getX(P),V=n.getY(P),G=n.getZ(P);L<w&&(w=L),L>_&&(_=L),V<M&&(M=V),V>S&&(S=V),G<N&&(N=G),G>E&&(E=G)}}return c[d+0]!==w||c[d+1]!==M||c[d+2]!==N||c[d+3]!==_||c[d+4]!==S||c[d+5]!==E?(c[d+0]=w,c[d+1]=M,c[d+2]=N,c[d+3]=_,c[d+4]=S,c[d+5]=E,!0):!1}else{const y=d+8,T=o[d+6],w=y+f,M=T+f;let N=p,_=!1,S=!1;t?N||(_=t.has(w),S=t.has(M),N=!_&&!S):(_=!0,S=!0);const E=N||_,F=N||S;let R=!1;E&&(R=l(y,f,N));let I=!1;F&&(I=l(T,f,N));const B=R||I;if(B)for(let P=0;P<3;P++){const L=y+P,V=T+P,G=c[L],Nt=c[L+3],Ht=c[V],qt=c[V+3];c[d+P]=G<Ht?G:Ht,c[d+P+3]=Nt>qt?Nt:qt}return B}}}function _l(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),Bi(0,r,e,s,n,i,o),X.clearBuffer()}function Bi(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(pt(h,c)){const d=Tt(r,u),f=St(h,c);dl(t,e,s,d,f,n,i,o)}else{const d=_t(r);ce(d,a,s,i,o)&&Bi(d,t,e,s,n,i,o);const f=zt(r,u);ce(f,a,s,i,o)&&Bi(f,t,e,s,n,i,o)}}const zl=["x","y","z"];function bl(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=Ii(0,r,e,s,n,i);return X.clearBuffer(),o}function Ii(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(pt(u,a)){const l=Tt(r,c),d=St(u,a);return fl(t,e,s,l,d,n,i)}else{const l=To(r,c),d=zl[l],p=s.direction[d]>=0;let m,g;p?(m=_t(r),g=zt(r,c)):(m=zt(r,c),g=_t(r));const T=ce(m,o,s,n,i)?Ii(m,t,e,s,n,i):null;if(T){const N=T.point[d];if(p?N<=o[g+l]:N>=o[g+l+3])return T}const M=ce(g,o,s,n,i)?Ii(g,t,e,s,n,i):null;return T&&M?T.distance<=M.distance?T:M:T||M||null}}const pn=new ht,qe=new Lt,$e=new Lt,As=new nt,zo=new lt,mn=new lt;function El(r,t,e,s){X.setBuffer(r._roots[t]);const n=vi(0,r,e,s);return X.clearBuffer(),n}function vi(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),zo.set(e.boundingBox.min,e.boundingBox.max,s),n=zo),pt(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,f=e.index,p=e.attributes.position,m=Tt(r,a),g=St(c,o);if(As.copy(s).invert(),e.boundsTree)return Z(r,i,mn),mn.matrix.copy(As),mn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:T=>mn.intersectsBox(T),intersectsTriangle:T=>{T.a.applyMatrix4(s),T.b.applyMatrix4(s),T.c.applyMatrix4(s),T.needsUpdate=!0;for(let w=m,M=g+m;w<M;w++)if(st($e,3*t.resolveTriangleIndex(w),l,d),$e.needsUpdate=!0,T.intersectsTriangle($e))return!0;return!1}});for(let y=m,T=g+m;y<T;y++){const w=t.resolveTriangleIndex(y);st(qe,3*w,l,d),qe.a.applyMatrix4(As),qe.b.applyMatrix4(As),qe.c.applyMatrix4(As),qe.needsUpdate=!0;for(let M=0,N=f.count;M<N;M+=3)if(st($e,M,f,p),$e.needsUpdate=!0,qe.intersectsTriangle($e))return!0}}else{const h=r+8,l=a[r+6];return Z(h,i,pn),!!(n.intersectsBox(pn)&&vi(h,t,e,s,n)||(Z(l,i,pn),n.intersectsBox(pn)&&vi(l,t,e,s,n)))}}const yn=new nt,Pi=new lt,Ms=new lt,Cl=new A,Fl=new A,Rl=new A,Bl=new A;function Il(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Pi.set(t.boundingBox.min,t.boundingBox.max,e),Pi.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=bt.getPrimitive(),f=bt.getPrimitive();let p=Cl,m=Fl,g=null,y=null;n&&(g=Rl,y=Bl);let T=1/0,w=null,M=null;return yn.copy(e).invert(),Ms.matrix.copy(yn),r.shapecast({boundsTraverseOrder:N=>Pi.distanceToBox(N),intersectsBounds:(N,_,S)=>S<T&&S<o?(_&&(Ms.min.copy(N.min),Ms.max.copy(N.max),Ms.needsUpdate=!0),!0):!1,intersectsRange:(N,_)=>{if(t.boundsTree){const S=t.boundsTree;return S.shapecast({boundsTraverseOrder:E=>Ms.distanceToBox(E),intersectsBounds:(E,F,R)=>R<T&&R<o,intersectsRange:(E,F)=>{for(let R=E,I=E+F;R<I;R++){const B=S.resolveTriangleIndex(R);st(f,3*B,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let P=N,L=N+_;P<L;P++){const V=r.resolveTriangleIndex(P);st(d,3*V,u,c),d.needsUpdate=!0;const G=d.distanceToTriangle(f,p,g);if(G<T&&(m.copy(p),y&&y.copy(g),T=G,w=P,M=R),G<i)return!0}}}})}else{const S=De(t);for(let E=0,F=S;E<F;E++){st(f,3*E,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let R=N,I=N+_;R<I;R++){const B=r.resolveTriangleIndex(R);st(d,3*B,u,c),d.needsUpdate=!0;const P=d.distanceToTriangle(f,p,g);if(P<T&&(m.copy(p),y&&y.copy(g),T=P,w=R,M=E),P<i)return!0}}}}}),bt.releasePrimitive(d),bt.releasePrimitive(f),T===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=T,s.faceIndex=w,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(yn),m.applyMatrix4(yn),n.distance=m.sub(n.point).length(),n.faceIndex=M),s)}function vl(){return typeof SharedArrayBuffer<"u"}const Ss=new X.constructor,gn=new X.constructor,he=new _i(()=>new ht),Ge=new ht,We=new ht,Li=new ht,Oi=new ht;let Di=!1;function Pl(r,t,e,s){if(Di)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Di=!0;const n=r._roots,i=t._roots;let o,a=0,c=0;const u=new nt().copy(e).invert();for(let h=0,l=n.length;h<l;h++){Ss.setBuffer(n[h]),c=0;const d=he.getPrimitive();Z(0,Ss.float32Array,d),d.applyMatrix4(u);for(let f=0,p=i.length;f<p&&(gn.setBuffer(i[f]),o=Ot(0,0,e,u,s,a,c,0,0,d),gn.clearBuffer(),c+=i[f].length,!o);f++);if(he.releasePrimitive(d),Ss.clearBuffer(),a+=n[h].length,o)break}return Di=!1,o}function Ot(r,t,e,s,n,i=0,o=0,a=0,c=0,u=null,h=!1){let l,d;h?(l=gn,d=Ss):(l=Ss,d=gn);const f=l.float32Array,p=l.uint32Array,m=l.uint16Array,g=d.float32Array,y=d.uint32Array,T=d.uint16Array,w=r*2,M=t*2,N=pt(w,m),_=pt(M,T);let S=!1;if(_&&N)h?S=n(Tt(t,y),St(t*2,T),Tt(r,p),St(r*2,m),c,o+t,a,i+r):S=n(Tt(r,p),St(r*2,m),Tt(t,y),St(t*2,T),a,i+r,c,o+t);else if(_){const E=he.getPrimitive();Z(t,g,E),E.applyMatrix4(e);const F=_t(r),R=zt(r,p);Z(F,f,Ge),Z(R,f,We);const I=E.intersectsBox(Ge),B=E.intersectsBox(We);S=I&&Ot(t,F,s,e,n,o,i,c,a+1,E,!h)||B&&Ot(t,R,s,e,n,o,i,c,a+1,E,!h),he.releasePrimitive(E)}else{const E=_t(t),F=zt(t,y);Z(E,g,Li),Z(F,g,Oi);const R=u.intersectsBox(Li),I=u.intersectsBox(Oi);if(R&&I)S=Ot(r,E,e,s,n,i,o,a,c+1,u,h)||Ot(r,F,e,s,n,i,o,a,c+1,u,h);else if(R)if(N)S=Ot(r,E,e,s,n,i,o,a,c+1,u,h);else{const B=he.getPrimitive();B.copy(Li).applyMatrix4(e);const P=_t(r),L=zt(r,p);Z(P,f,Ge),Z(L,f,We);const V=B.intersectsBox(Ge),G=B.intersectsBox(We);S=V&&Ot(E,P,s,e,n,o,i,c,a+1,B,!h)||G&&Ot(E,L,s,e,n,o,i,c,a+1,B,!h),he.releasePrimitive(B)}else if(I)if(N)S=Ot(r,F,e,s,n,i,o,a,c+1,u,h);else{const B=he.getPrimitive();B.copy(Oi).applyMatrix4(e);const P=_t(r),L=zt(r,p);Z(P,f,Ge),Z(L,f,We);const V=B.intersectsBox(Ge),G=B.intersectsBox(We);S=V&&Ot(F,P,s,e,n,o,i,c,a+1,B,!h)||G&&Ot(F,L,s,e,n,o,i,c,a+1,B,!h),he.releasePrimitive(B)}}return S}const xn=new lt,bo=new ht,Ll={strategy:uo,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Tn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const s=t.geometry,n=t._roots,i=t._indirectBuffer,o=s.getIndex();let a;return e.cloneBuffers?a={roots:n.map(c=>c.slice()),index:o?o.array.slice():null,indirectBuffer:i?i.slice():null}:a={roots:n,index:o?o.array:null,indirectBuffer:i},a}static deserialize(t,e,s={}){s={setIndex:!0,indirect:!!t.indirectBuffer,...s};const{index:n,roots:i,indirectBuffer:o}=t,a=new Tn(e,{...s,[xi]:!0});if(a._roots=i,a._indirectBuffer=o||null,s.setIndex){const c=e.getIndex();if(c===null){const u=new vt(t.index,1,!1);e.setIndex(u)}else c.array!==n&&(c.array.set(n),c.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...Ll,[xi]:!1},e),e.useSharedArrayBuffer&&!vl())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[xi]||(ju(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new ht))),this.resolveTriangleIndex=e.indirect?s=>this._indirectBuffer[s]:s=>s}refit(t=null){return(this.indirect?Sl:ll)(this,t)}traverse(t,e=0){const s=this._roots[e],n=new Uint32Array(s),i=new Uint16Array(s);o(0);function o(a,c=0){const u=a*2,h=i[u+15]===en;if(h){const l=n[a+6],d=i[u+14];t(c,h,new Float32Array(s,a*4,6),l,d)}else{const l=a+ms/4,d=n[a+6],f=n[a+7];t(c,h,new Float32Array(s,a*4,6),f)||(o(l,c+1),o(d,c+1))}}}raycast(t,e=Vi,s=0,n=1/0){const i=this._roots,o=this.geometry,a=[],c=e.isMaterial,u=Array.isArray(e),h=o.groups,l=c?e.side:e,d=this.indirect?_l:ml;for(let f=0,p=i.length;f<p;f++){const m=u?e[h[f].materialIndex].side:l,g=a.length;if(d(this,f,m,t,a,s,n),u){const y=h[f].materialIndex;for(let T=g,w=a.length;T<w;T++)a[T].face.materialIndex=y}}return a}raycastFirst(t,e=Vi,s=0,n=1/0){const i=this._roots,o=this.geometry,a=e.isMaterial,c=Array.isArray(e);let u=null;const h=o.groups,l=a?e.side:e,d=this.indirect?bl:gl;for(let f=0,p=i.length;f<p;f++){const m=c?e[h[f].materialIndex].side:l,g=d(this,f,m,t,s,n);g!=null&&(u==null||g.distance<u.distance)&&(u=g,c&&(g.face.materialIndex=h[f].materialIndex))}return u}intersectsGeometry(t,e){let s=!1;const n=this._roots,i=this.indirect?El:xl;for(let o=0,a=n.length;o<a&&(s=i(this,o,t,e),!s);o++);return s}shapecast(t){const e=bt.getPrimitive(),s=this.indirect?pl:ul;let{boundsTraverseOrder:n,intersectsBounds:i,intersectsRange:o,intersectsTriangle:a}=t;if(o&&a){const l=o;o=(d,f,p,m,g)=>l(d,f,p,m,g)?!0:s(d,f,this,a,p,m,e)}else o||(a?o=(l,d,f,p)=>s(l,d,this,a,f,p,e):o=(l,d,f)=>f);let c=!1,u=0;const h=this._roots;for(let l=0,d=h.length;l<d;l++){const f=h[l];if(c=nl(this,l,i,o,n,u),c)break;u+=f.byteLength}return bt.releasePrimitive(e),c}bvhcast(t,e,s){let{intersectsRanges:n,intersectsTriangles:i}=s;const o=bt.getPrimitive(),a=this.geometry.index,c=this.geometry.attributes.position,u=this.indirect?p=>{const m=this.resolveTriangleIndex(p);st(o,m*3,a,c)}:p=>{st(o,p*3,a,c)},h=bt.getPrimitive(),l=t.geometry.index,d=t.geometry.attributes.position,f=t.indirect?p=>{const m=t.resolveTriangleIndex(p);st(h,m*3,l,d)}:p=>{st(h,p*3,l,d)};if(i){const p=(m,g,y,T,w,M,N,_)=>{for(let S=y,E=y+T;S<E;S++){f(S),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let F=m,R=m+g;F<R;F++)if(u(F),o.needsUpdate=!0,i(o,h,F,S,w,M,N,_))return!0}return!1};if(n){const m=n;n=function(g,y,T,w,M,N,_,S){return m(g,y,T,w,M,N,_,S)?!0:p(g,y,T,w,M,N,_,S)}}else n=p}return Pl(this,t,e,n)}intersectsBox(t,e){return xn.set(t.min,t.max,e),xn.needsUpdate=!0,this.shapecast({intersectsBounds:s=>xn.intersectsBox(s),intersectsTriangle:s=>xn.intersectsTriangle(s)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,s={},n={},i=0,o=1/0){return(this.indirect?Il:Ml)(this,t,e,s,n,i,o)}closestPointToPoint(t,e={},s=0,n=1/0){return il(this,t,e,s,n)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(s=>{Z(0,new Float32Array(s),bo),t.union(bo)}),t}}onmessage=({data:r})=>{let t=performance.now();function e(o){o=Math.min(o,1);const a=performance.now();a-t>=10&&o!==1&&(postMessage({error:null,serialized:null,position:null,progress:o}),t=a)}const{index:s,position:n,options:i}=r;try{const o=new Gn;if(o.setAttribute("position",new vt(n,3,!1)),s&&o.setIndex(new vt(s,1,!1)),i.includedProgressCallback&&(i.onProgress=e),i.groups){const h=i.groups;for(const l in h){const d=h[l];o.addGroup(d.start,d.count,d.materialIndex)}}const a=new Tn(o,i),c=Tn.serialize(a,{copyIndexBuffer:!1});let u=[n.buffer,...c.roots];c.index&&u.push(c.index.buffer),u=u.filter(h=>typeof SharedArrayBuffer>"u"||!(h instanceof SharedArrayBuffer)),a._indirectBuffer&&u.push(c.indirectBuffer.buffer),postMessage({error:null,serialized:c,position:n,progress:1},u)}catch(o){postMessage({error:o,serialized:null,position:null,progress:1})}}})();
|
|
25
|
+
`):t.addLineFlowCode(`${e}Barrier()`,this)}}C(Iu);class kt extends dt{static get type(){return"AtomicFunctionNode"}constructor(t,e,s,n=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=s,this.storeNode=n}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,s=this.getNodeType(t),n=this.getInputType(t),i=this.pointerNode,o=this.valueNode,a=[];a.push(`&${i.build(t,n)}`),a.push(o.build(t,n));const c=`${t.getMethod(e,s)}( ${a.join(", ")} )`;if(this.storeNode!==null){const u=this.storeNode.build(t,n);t.addLineFlowCode(`${u} = ${c}`,this)}else t.addLineFlowCode(c,this)}}if(kt.ATOMIC_LOAD="atomicLoad",kt.ATOMIC_STORE="atomicStore",kt.ATOMIC_ADD="atomicAdd",kt.ATOMIC_SUB="atomicSub",kt.ATOMIC_MAX="atomicMax",kt.ATOMIC_MIN="atomicMin",kt.ATOMIC_AND="atomicAnd",kt.ATOMIC_OR="atomicOr",kt.ATOMIC_XOR="atomicXor",C(kt),typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Xe}})),typeof window<"u"){try{An&&An.tagName.toUpperCase()==="SCRIPT"&&An.src||new URL("generateMeshBVH.worker-2bb9524d.js",document.baseURI).href,window.__THREE__IMPORTS__||(window.__THREE__IMPORTS__=[]),window.__THREE__IMPORTS__.push({url:self.location.href,revision:Xe})}catch{}window.__THREE__?(console.warn("WARNING: Multiple instances of Three.js being imported. Existing: "+window.__THREE__+", new: "+Xe),console.warn(window.__THREE__IMPORTS__)):window.__THREE__=Xe}const uo=0,vu=1,Pu=2,lo=2,gi=1.25,fo=1,ms=6*4+4+4,en=65535,Lu=Math.pow(2,-24),xi=Symbol("SKIP_GENERATION");function Ou(r){return r.index?r.index.count:r.attributes.position.count}function De(r){return Ou(r)/3}function Du(r,t=ArrayBuffer){return r>65535?new Uint32Array(new t(4*r)):new Uint16Array(new t(2*r))}function Vu(r,t){if(!r.index){const e=r.attributes.position.count,s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=Du(e,s);r.setIndex(new vt(n,1));for(let i=0;i<e;i++)n[i]=i}}function po(r,t){const e=De(r),s=t||r.drawRange,n=s.start/3,i=(s.start+s.count)/3,o=Math.max(0,n),a=Math.min(e,i)-o;return[{offset:Math.floor(o),count:Math.floor(a)}]}function mo(r,t){if(!r.groups||!r.groups.length)return po(r,t);const e=[],s=new Set,n=t||r.drawRange,i=n.start/3,o=(n.start+n.count)/3;for(const c of r.groups){const u=c.start/3,h=(c.start+c.count)/3;s.add(Math.max(i,u)),s.add(Math.min(o,h))}const a=Array.from(s.values()).sort((c,u)=>c-u);for(let c=0;c<a.length-1;c++){const u=a[c],h=a[c+1];e.push({offset:Math.floor(u),count:Math.floor(h-u)})}return e}function Uu(r,t){const e=De(r),s=mo(r,t).sort((o,a)=>o.offset-a.offset),n=s[s.length-1];n.count=Math.min(e-n.offset,n.count);let i=0;return s.forEach(({count:o})=>i+=o),e!==i}function Ti(r,t,e,s,n){let i=1/0,o=1/0,a=1/0,c=-1/0,u=-1/0,h=-1/0,l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,g=-1/0;for(let y=t*6,T=(t+e)*6;y<T;y+=6){const w=r[y+0],M=r[y+1],N=w-M,_=w+M;N<i&&(i=N),_>c&&(c=_),w<l&&(l=w),w>p&&(p=w);const S=r[y+2],E=r[y+3],F=S-E,R=S+E;F<o&&(o=F),R>u&&(u=R),S<d&&(d=S),S>m&&(m=S);const I=r[y+4],B=r[y+5],P=I-B,L=I+B;P<a&&(a=P),L>h&&(h=L),I<f&&(f=I),I>g&&(g=I)}s[0]=i,s[1]=o,s[2]=a,s[3]=c,s[4]=u,s[5]=h,n[0]=l,n[1]=d,n[2]=f,n[3]=p,n[4]=m,n[5]=g}function ku(r,t=null,e=null,s=null){const n=r.attributes.position,i=r.index?r.index.array:null,o=De(r),a=n.normalized;let c;t===null?(c=new Float32Array(o*6),e=0,s=o):(c=t,e=e||0,s=s||o);const u=n.array,h=n.offset||0;let l=3;n.isInterleavedBufferAttribute&&(l=n.data.stride);const d=["getX","getY","getZ"];for(let f=e;f<e+s;f++){const p=f*3,m=f*6;let g=p+0,y=p+1,T=p+2;i&&(g=i[g],y=i[y],T=i[T]),a||(g=g*l+h,y=y*l+h,T=T*l+h);for(let w=0;w<3;w++){let M,N,_;a?(M=n[d[w]](g),N=n[d[w]](y),_=n[d[w]](T)):(M=u[g+w],N=u[y+w],_=u[T+w]);let S=M;N<S&&(S=N),_<S&&(S=_);let E=M;N>E&&(E=N),_>E&&(E=_);const F=(E-S)/2,R=w*2;c[m+R+0]=S+F,c[m+R+1]=F+(Math.abs(S)+F)*Lu}}return c}function Z(r,t,e){return e.min.x=t[r],e.min.y=t[r+1],e.min.z=t[r+2],e.max.x=t[r+3],e.max.y=t[r+4],e.max.z=t[r+5],e}function yo(r){let t=-1,e=-1/0;for(let s=0;s<3;s++){const n=r[s+3]-r[s];n>e&&(e=n,t=s)}return t}function go(r,t){t.set(r)}function xo(r,t,e){let s,n;for(let i=0;i<3;i++){const o=i+3;s=r[i],n=t[i],e[i]=s<n?s:n,s=r[o],n=t[o],e[o]=s>n?s:n}}function sn(r,t,e){for(let s=0;s<3;s++){const n=t[r+2*s],i=t[r+2*s+1],o=n-i,a=n+i;o<e[s]&&(e[s]=o),a>e[s+3]&&(e[s+3]=a)}}function ys(r){const t=r[3]-r[0],e=r[4]-r[1],s=r[5]-r[2];return 2*(t*e+e*s+s*t)}const jt=32,Hu=(r,t)=>r.candidate-t.candidate,oe=new Array(jt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),nn=new Float32Array(6);function qu(r,t,e,s,n,i){let o=-1,a=0;if(i===uo)o=yo(t),o!==-1&&(a=(t[o]+t[o+3])/2);else if(i===vu)o=yo(r),o!==-1&&(a=$u(e,s,n,o));else if(i===Pu){const c=ys(r);let u=gi*n;const h=s*6,l=(s+n)*6;for(let d=0;d<3;d++){const f=t[d],g=(t[d+3]-f)/jt;if(n<jt/4){const y=[...oe];y.length=n;let T=0;for(let M=h;M<l;M+=6,T++){const N=y[T];N.candidate=e[M+2*d],N.count=0;const{bounds:_,leftCacheBounds:S,rightCacheBounds:E}=N;for(let F=0;F<3;F++)E[F]=1/0,E[F+3]=-1/0,S[F]=1/0,S[F+3]=-1/0,_[F]=1/0,_[F+3]=-1/0;sn(M,e,_)}y.sort(Hu);let w=n;for(let M=0;M<w;M++){const N=y[M];for(;M+1<w&&y[M+1].candidate===N.candidate;)y.splice(M+1,1),w--}for(let M=h;M<l;M+=6){const N=e[M+2*d];for(let _=0;_<w;_++){const S=y[_];N>=S.candidate?sn(M,e,S.rightCacheBounds):(sn(M,e,S.leftCacheBounds),S.count++)}}for(let M=0;M<w;M++){const N=y[M],_=N.count,S=n-N.count,E=N.leftCacheBounds,F=N.rightCacheBounds;let R=0;_!==0&&(R=ys(E)/c);let I=0;S!==0&&(I=ys(F)/c);const B=fo+gi*(R*_+I*S);B<u&&(o=d,u=B,a=N.candidate)}}else{for(let w=0;w<jt;w++){const M=oe[w];M.count=0,M.candidate=f+g+w*g;const N=M.bounds;for(let _=0;_<3;_++)N[_]=1/0,N[_+3]=-1/0}for(let w=h;w<l;w+=6){let _=~~((e[w+2*d]-f)/g);_>=jt&&(_=jt-1);const S=oe[_];S.count++,sn(w,e,S.bounds)}const y=oe[jt-1];go(y.bounds,y.rightCacheBounds);for(let w=jt-2;w>=0;w--){const M=oe[w],N=oe[w+1];xo(M.bounds,N.rightCacheBounds,M.rightCacheBounds)}let T=0;for(let w=0;w<jt-1;w++){const M=oe[w],N=M.count,_=M.bounds,E=oe[w+1].rightCacheBounds;N!==0&&(T===0?go(_,nn):xo(_,nn,nn)),T+=N;let F=0,R=0;T!==0&&(F=ys(nn)/c);const I=n-T;I!==0&&(R=ys(E)/c);const B=fo+gi*(F*T+R*I);B<u&&(o=d,u=B,a=M.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${i} used.`);return{axis:o,pos:a}}function $u(r,t,e,s){let n=0;for(let i=t,o=t+e;i<o;i++)n+=r[i*6+s*2];return n/e}class Ni{constructor(){this.boundingData=new Float32Array(6)}}function Gu(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2;for(;;){for(;o<=a&&e[o*6+u]<c;)o++;for(;o<=a&&e[a*6+u]>=c;)a--;if(o<a){for(let h=0;h<3;h++){let l=t[o*3+h];t[o*3+h]=t[a*3+h],t[a*3+h]=l}for(let h=0;h<6;h++){let l=e[o*6+h];e[o*6+h]=e[a*6+h],e[a*6+h]=l}o++,a--}else return o}}function Wu(r,t,e,s,n,i){let o=s,a=s+n-1;const c=i.pos,u=i.axis*2;for(;;){for(;o<=a&&e[o*6+u]<c;)o++;for(;o<=a&&e[a*6+u]>=c;)a--;if(o<a){let h=r[o];r[o]=r[a],r[a]=h;for(let l=0;l<6;l++){let d=e[o*6+l];e[o*6+l]=e[a*6+l],e[a*6+l]=d}o++,a--}else return o}}function pt(r,t){return t[r+15]===65535}function Tt(r,t){return t[r+6]}function St(r,t){return t[r+14]}function _t(r){return r+8}function zt(r,t){return t[r+6]}function To(r,t){return t[r+7]}function jl(r){return r}let No,gs,rn,wo;const Xu=Math.pow(2,32);function wi(r){return"count"in r?1:1+wi(r.left)+wi(r.right)}function Yu(r,t,e){return No=new Float32Array(e),gs=new Uint32Array(e),rn=new Uint16Array(e),wo=new Uint8Array(e),Ai(r,t)}function Ai(r,t){const e=r/4,s=r/2,n="count"in t,i=t.boundingData;for(let o=0;o<6;o++)No[e+o]=i[o];if(n)if(t.buffer){const o=t.buffer;wo.set(new Uint8Array(o),r);for(let a=r,c=r+o.byteLength;a<c;a+=ms){const u=a/2;pt(u,rn)||(gs[a/4+6]+=e)}return r+o.byteLength}else{const o=t.offset,a=t.count;return gs[e+6]=o,rn[s+14]=a,rn[s+15]=en,r+ms}else{const o=t.left,a=t.right,c=t.splitAxis;let u;if(u=Ai(r+ms,o),u/4>Xu)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return gs[e+6]=u/4,u=Ai(u,a),gs[e+7]=c,u}}function Zu(r,t){const e=(r.index?r.index.count:r.attributes.position.count)/3,s=e>2**16,n=s?4:2,i=t?new SharedArrayBuffer(e*n):new ArrayBuffer(e*n),o=s?new Uint32Array(i):new Uint16Array(i);for(let a=0,c=o.length;a<c;a++)o[a]=a;return o}function Ju(r,t,e,s,n){const{maxDepth:i,verbose:o,maxLeafTris:a,strategy:c,onProgress:u,indirect:h}=n,l=r._indirectBuffer,d=r.geometry,f=d.index?d.index.array:null,p=h?Wu:Gu,m=De(d),g=new Float32Array(6);let y=!1;const T=new Ni;return Ti(t,e,s,T.boundingData,g),M(T,e,s,g),T;function w(N){u&&u(N/m)}function M(N,_,S,E=null,F=0){if(!y&&F>=i&&(y=!0,o&&(console.warn(`MeshBVH: Max depth of ${i} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),S<=a||F>=i)return w(_+S),N.offset=_,N.count=S,N;const R=qu(N.boundingData,E,t,_,S,c);if(R.axis===-1)return w(_+S),N.offset=_,N.count=S,N;const I=p(l,f,t,_,S,R);if(I===_||I===_+S)w(_+S),N.offset=_,N.count=S;else{N.splitAxis=R.axis;const B=new Ni,P=_,L=I-_;N.left=B,Ti(t,P,L,B.boundingData,g),M(B,P,L,g,F+1);const V=new Ni,G=I,Nt=S-L;N.right=V,Ti(t,G,Nt,V.boundingData,g),M(V,G,Nt,g,F+1)}return N}}function ju(r,t){const e=r.geometry;t.indirect&&(r._indirectBuffer=Zu(e,t.useSharedArrayBuffer),Uu(e,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),r._indirectBuffer||Vu(e,t);const s=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=ku(e),i=t.indirect?po(e,t.range):mo(e,t.range);r._roots=i.map(o=>{const a=Ju(r,n,o.offset,o.count,t),c=wi(a),u=new s(ms*c);return Yu(0,a,u),u})}class Qt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let s=1/0,n=-1/0;for(let i=0,o=t.length;i<o;i++){const c=t[i][e];s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}setFromPoints(t,e){let s=1/0,n=-1/0;for(let i=0,o=e.length;i<o;i++){const a=e[i],c=t.dot(a);s=c<s?c:s,n=c>n?c:n}this.min=s,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}Qt.prototype.setFromBox=function(){const r=new A;return function(e,s){const n=s.min,i=s.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){r.x=n.x*c+i.x*(1-c),r.y=n.y*u+i.y*(1-u),r.z=n.z*h+i.z*(1-h);const l=e.dot(r);o=Math.min(l,o),a=Math.max(l,a)}this.min=o,this.max=a}}();const Qu=function(){const r=new A,t=new A,e=new A;return function(n,i,o){const a=n.start,c=r,u=i.start,h=t;e.subVectors(a,u),r.subVectors(n.end,n.start),t.subVectors(i.end,i.start);const l=e.dot(h),d=h.dot(c),f=h.dot(h),p=e.dot(c),g=c.dot(c)*f-d*d;let y,T;g!==0?y=(l*d-p*f)/g:y=0,T=(l+y*d)/f,o.x=y,o.y=T}}(),Mi=function(){const r=new J,t=new A,e=new A;return function(n,i,o,a){Qu(n,i,r);let c=r.x,u=r.y;if(c>=0&&c<=1&&u>=0&&u<=1){n.at(c,o),i.at(u,a);return}else if(c>=0&&c<=1){u<0?i.at(0,a):i.at(1,a),n.closestPointToPoint(a,!0,o);return}else if(u>=0&&u<=1){c<0?n.at(0,o):n.at(1,o),i.closestPointToPoint(o,!0,a);return}else{let h;c<0?h=n.start:h=n.end;let l;u<0?l=i.start:l=i.end;const d=t,f=e;if(n.closestPointToPoint(l,!0,t),i.closestPointToPoint(h,!0,e),d.distanceToSquared(l)<=f.distanceToSquared(h)){o.copy(d),a.copy(l);return}else{o.copy(h),a.copy(f);return}}}}(),Ku=function(){const r=new A,t=new A,e=new Xn,s=new Zt;return function(i,o){const{radius:a,center:c}=i,{a:u,b:h,c:l}=o;if(s.start=u,s.end=h,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a||(s.start=u,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a)||(s.start=h,s.end=l,s.closestPointToPoint(c,!0,r).distanceTo(c)<=a))return!0;const m=o.getPlane(e);if(Math.abs(m.distanceToPoint(c))<=a){const y=m.projectPoint(c,t);if(o.containsPoint(y))return!0}return!1}}(),tl=1e-15;function Si(r){return Math.abs(r)<tl}class Lt extends wt{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new A),this.satBounds=new Array(4).fill().map(()=>new Qt),this.points=[this.a,this.b,this.c],this.sphere=new cr,this.plane=new Xn,this.needsUpdate=!0}intersectsSphere(t){return Ku(t,this)}update(){const t=this.a,e=this.b,s=this.c,n=this.points,i=this.satAxes,o=this.satBounds,a=i[0],c=o[0];this.getNormal(a),c.setFromPoints(a,n);const u=i[1],h=o[1];u.subVectors(t,e),h.setFromPoints(u,n);const l=i[2],d=o[2];l.subVectors(e,s),d.setFromPoints(l,n);const f=i[3],p=o[3];f.subVectors(s,t),p.setFromPoints(f,n),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}Lt.prototype.closestPointToSegment=function(){const r=new A,t=new A,e=new Zt;return function(n,i=null,o=null){const{start:a,end:c}=n,u=this.points;let h,l=1/0;for(let d=0;d<3;d++){const f=(d+1)%3;e.start.copy(u[d]),e.end.copy(u[f]),Mi(e,n,r,t),h=r.distanceToSquared(t),h<l&&(l=h,i&&i.copy(r),o&&o.copy(t))}return this.closestPointToPoint(a,r),h=a.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(a)),this.closestPointToPoint(c,r),h=c.distanceToSquared(r),h<l&&(l=h,i&&i.copy(r),o&&o.copy(c)),Math.sqrt(l)}}(),Lt.prototype.intersectsTriangle=function(){const r=new Lt,t=new Array(3),e=new Array(3),s=new Qt,n=new Qt,i=new A,o=new A,a=new A,c=new A,u=new A,h=new Zt,l=new Zt,d=new Zt,f=new A;function p(m,g,y){const T=m.points;let w=0,M=-1;for(let N=0;N<3;N++){const{start:_,end:S}=h;_.copy(T[N]),S.copy(T[(N+1)%3]),h.delta(o);const E=Si(g.distanceToPoint(_));if(Si(g.normal.dot(o))&&E){y.copy(h),w=2;break}const F=g.intersectLine(h,f);if(!F&&E&&f.copy(_),(F||E)&&!Si(f.distanceTo(S))){if(w<=1)(w===1?y.start:y.end).copy(f),E&&(M=w);else if(w>=2){(M===1?y.start:y.end).copy(f),w=2;break}if(w++,w===2&&M===-1)break}}return w}return function(g,y=null,T=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(r.copy(g),r.update(),g=r);const w=this.plane,M=g.plane;if(Math.abs(w.normal.dot(M.normal))>1-1e-10){const N=this.satBounds,_=this.satAxes;e[0]=g.a,e[1]=g.b,e[2]=g.c;for(let F=0;F<4;F++){const R=N[F],I=_[F];if(s.setFromPoints(I,e),R.isSeparated(s))return!1}const S=g.satBounds,E=g.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let F=0;F<4;F++){const R=S[F],I=E[F];if(s.setFromPoints(I,t),R.isSeparated(s))return!1}for(let F=0;F<4;F++){const R=_[F];for(let I=0;I<4;I++){const B=E[I];if(i.crossVectors(R,B),s.setFromPoints(i,t),n.setFromPoints(i,e),s.isSeparated(n))return!1}}return y&&(T||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),y.start.set(0,0,0),y.end.set(0,0,0)),!0}else{const N=p(this,M,l);if(N===1&&g.containsPoint(l.end))return y&&(y.start.copy(l.end),y.end.copy(l.end)),!0;if(N!==2)return!1;const _=p(g,w,d);if(_===1&&this.containsPoint(d.end))return y&&(y.start.copy(d.end),y.end.copy(d.end)),!0;if(_!==2)return!1;if(l.delta(a),d.delta(c),a.dot(c)<0){let P=d.start;d.start=d.end,d.end=P}const S=l.start.dot(a),E=l.end.dot(a),F=d.start.dot(a),R=d.end.dot(a),I=E<F,B=S<R;return S!==R&&F!==E&&I===B?!1:(y&&(u.subVectors(l.start,d.start),u.dot(a)>0?y.start.copy(l.start):y.start.copy(d.start),u.subVectors(l.end,d.end),u.dot(a)<0?y.end.copy(l.end):y.end.copy(d.end)),!0)}}}(),Lt.prototype.distanceToPoint=function(){const r=new A;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),Lt.prototype.distanceToTriangle=function(){const r=new A,t=new A,e=["a","b","c"],s=new Zt,n=new Zt;return function(o,a=null,c=null){const u=a||c?s:null;if(this.intersectsTriangle(o,u))return(a||c)&&(a&&u.getCenter(a),c&&u.getCenter(c)),0;let h=1/0;for(let l=0;l<3;l++){let d;const f=e[l],p=o[f];this.closestPointToPoint(p,r),d=p.distanceToSquared(r),d<h&&(h=d,a&&a.copy(r),c&&c.copy(p));const m=this[f];o.closestPointToPoint(m,r),d=m.distanceToSquared(r),d<h&&(h=d,a&&a.copy(m),c&&c.copy(r))}for(let l=0;l<3;l++){const d=e[l],f=e[(l+1)%3];s.set(this[d],this[f]);for(let p=0;p<3;p++){const m=e[p],g=e[(p+1)%3];n.set(o[m],o[g]),Mi(s,n,r,t);const y=r.distanceToSquared(t);y<h&&(h=y,a&&a.copy(r),c&&c.copy(t))}}return Math.sqrt(h)}}();class lt{constructor(t,e,s){this.isOrientedBox=!0,this.min=new A,this.max=new A,this.matrix=new nt,this.invMatrix=new nt,this.points=new Array(8).fill().map(()=>new A),this.satAxes=new Array(3).fill().map(()=>new A),this.satBounds=new Array(3).fill().map(()=>new Qt),this.alignedSatBounds=new Array(3).fill().map(()=>new Qt),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),s&&this.matrix.copy(s)}set(t,e,s){this.min.copy(t),this.max.copy(e),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}lt.prototype.update=function(){return function(){const t=this.matrix,e=this.min,s=this.max,n=this.points;for(let u=0;u<=1;u++)for(let h=0;h<=1;h++)for(let l=0;l<=1;l++){const d=1*u|2*h|4*l,f=n[d];f.x=u?s.x:e.x,f.y=h?s.y:e.y,f.z=l?s.z:e.z,f.applyMatrix4(t)}const i=this.satBounds,o=this.satAxes,a=n[0];for(let u=0;u<3;u++){const h=o[u],l=i[u],d=1<<u,f=n[d];h.subVectors(a,f),l.setFromPoints(h,n)}const c=this.alignedSatBounds;c[0].setFromPointsField(n,"x"),c[1].setFromPointsField(n,"y"),c[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),lt.prototype.intersectsBox=function(){const r=new Qt;return function(e){this.needsUpdate&&this.update();const s=e.min,n=e.max,i=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(r.min=s.x,r.max=n.x,a[0].isSeparated(r)||(r.min=s.y,r.max=n.y,a[1].isSeparated(r))||(r.min=s.z,r.max=n.z,a[2].isSeparated(r)))return!1;for(let c=0;c<3;c++){const u=o[c],h=i[c];if(r.setFromBox(u,e),h.isSeparated(r))return!1}return!0}}(),lt.prototype.intersectsTriangle=function(){const r=new Lt,t=new Array(3),e=new Qt,s=new Qt,n=new A;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(r.copy(o),r.update(),o=r);const a=this.satBounds,c=this.satAxes;t[0]=o.a,t[1]=o.b,t[2]=o.c;for(let d=0;d<3;d++){const f=a[d],p=c[d];if(e.setFromPoints(p,t),f.isSeparated(e))return!1}const u=o.satBounds,h=o.satAxes,l=this.points;for(let d=0;d<3;d++){const f=u[d],p=h[d];if(e.setFromPoints(p,l),f.isSeparated(e))return!1}for(let d=0;d<3;d++){const f=c[d];for(let p=0;p<4;p++){const m=h[p];if(n.crossVectors(f,m),e.setFromPoints(n,t),s.setFromPoints(n,l),e.isSeparated(s))return!1}}return!0}}(),lt.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),lt.prototype.distanceToPoint=function(){const r=new A;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),lt.prototype.distanceToBox=function(){const r=["x","y","z"],t=new Array(12).fill().map(()=>new Zt),e=new Array(12).fill().map(()=>new Zt),s=new A,n=new A;return function(o,a=0,c=null,u=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||u)&&(o.getCenter(n),this.closestPointToPoint(n,s),o.closestPointToPoint(s,n),c&&c.copy(s),u&&u.copy(n)),0;const h=a*a,l=o.min,d=o.max,f=this.points;let p=1/0;for(let g=0;g<8;g++){const y=f[g];n.copy(y).clamp(l,d);const T=y.distanceToSquared(n);if(T<p&&(p=T,c&&c.copy(y),u&&u.copy(n),T<h))return Math.sqrt(T)}let m=0;for(let g=0;g<3;g++)for(let y=0;y<=1;y++)for(let T=0;T<=1;T++){const w=(g+1)%3,M=(g+2)%3,N=y<<w|T<<M,_=1<<g|y<<w|T<<M,S=f[N],E=f[_];t[m].set(S,E);const R=r[g],I=r[w],B=r[M],P=e[m],L=P.start,V=P.end;L[R]=l[R],L[I]=y?l[I]:d[I],L[B]=T?l[B]:d[I],V[R]=d[R],V[I]=y?l[I]:d[I],V[B]=T?l[B]:d[I],m++}for(let g=0;g<=1;g++)for(let y=0;y<=1;y++)for(let T=0;T<=1;T++){n.x=g?d.x:l.x,n.y=y?d.y:l.y,n.z=T?d.z:l.z,this.closestPointToPoint(n,s);const w=n.distanceToSquared(s);if(w<p&&(p=w,c&&c.copy(s),u&&u.copy(n),w<h))return Math.sqrt(w)}for(let g=0;g<12;g++){const y=t[g];for(let T=0;T<12;T++){const w=e[T];Mi(y,w,s,n);const M=s.distanceToSquared(n);if(M<p&&(p=M,c&&c.copy(s),u&&u.copy(n),M<h))return Math.sqrt(M)}}return Math.sqrt(p)}}();class _i{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class el extends _i{constructor(){super(()=>new Lt)}}const bt=new el;class sl{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=s=>{e&&t.push(e),e=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const X=new sl;let ae,Ve;const Ue=[],on=new _i(()=>new ht);function nl(r,t,e,s,n,i){ae=on.getPrimitive(),Ve=on.getPrimitive(),Ue.push(ae,Ve),X.setBuffer(r._roots[t]);const o=zi(0,r.geometry,e,s,n,i);X.clearBuffer(),on.releasePrimitive(ae),on.releasePrimitive(Ve),Ue.pop(),Ue.pop();const a=Ue.length;return a>0&&(Ve=Ue[a-1],ae=Ue[a-2]),o}function zi(r,t,e,s,n=null,i=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:u}=X;let h=r*2;if(pt(h,c)){const d=Tt(r,u),f=St(h,c);return Z(r,a,ae),s(d,f,!1,o,i+r,ae)}else{let R=function(B){const{uint16Array:P,uint32Array:L}=X;let V=B*2;for(;!pt(V,P);)B=_t(B),V=B*2;return Tt(B,L)},I=function(B){const{uint16Array:P,uint32Array:L}=X;let V=B*2;for(;!pt(V,P);)B=zt(B,L),V=B*2;return Tt(B,L)+St(V,P)};const d=_t(r),f=zt(r,u);let p=d,m=f,g,y,T,w;if(n&&(T=ae,w=Ve,Z(p,a,T),Z(m,a,w),g=n(T),y=n(w),y<g)){p=f,m=d;const B=g;g=y,y=B,T=w}T||(T=ae,Z(p,a,T));const M=pt(p*2,c),N=e(T,M,g,o+1,i+p);let _;if(N===lo){const B=R(p),L=I(p)-B;_=s(B,L,!0,o+1,i+p,T)}else _=N&&zi(p,t,e,s,n,i,o+1);if(_)return!0;w=Ve,Z(m,a,w);const S=pt(m*2,c),E=e(w,S,y,o+1,i+m);let F;if(E===lo){const B=R(m),L=I(m)-B;F=s(B,L,!0,o+1,i+m,w)}else F=E&&zi(m,t,e,s,n,i,o+1);return!!F}}const xs=new A,bi=new A;function il(r,t,e={},s=0,n=1/0){const i=s*s,o=n*n;let a=1/0,c=null;if(r.shapecast({boundsTraverseOrder:h=>(xs.copy(t).clamp(h.min,h.max),xs.distanceToSquared(t)),intersectsBounds:(h,l,d)=>d<a&&d<o,intersectsTriangle:(h,l)=>{h.closestPointToPoint(t,xs);const d=t.distanceToSquared(xs);return d<a&&(bi.copy(xs),a=d,c=l),d<i}}),a===1/0)return null;const u=Math.sqrt(a);return e.point?e.point.copy(bi):e.point=bi.clone(),e.distance=u,e.faceIndex=c,e}const rl=parseInt(Xe)>=169,me=new A,ye=new A,ge=new A,an=new J,cn=new J,hn=new J,Ao=new A,Mo=new A,So=new A,Ts=new A;function ol(r,t,e,s,n,i,o,a){let c;if(i===Ui?c=r.intersectTriangle(s,e,t,!0,n):c=r.intersectTriangle(t,e,s,i!==Eo,n),c===null)return null;const u=r.origin.distanceTo(n);return u<o||u>a?null:{distance:u,point:n.clone()}}function al(r,t,e,s,n,i,o,a,c,u,h){me.fromBufferAttribute(t,i),ye.fromBufferAttribute(t,o),ge.fromBufferAttribute(t,a);const l=ol(r,me,ye,ge,Ts,c,u,h);if(l){const d=new A;wt.getBarycoord(Ts,me,ye,ge,d),s&&(an.fromBufferAttribute(s,i),cn.fromBufferAttribute(s,o),hn.fromBufferAttribute(s,a),l.uv=wt.getInterpolation(Ts,me,ye,ge,an,cn,hn,new J)),n&&(an.fromBufferAttribute(n,i),cn.fromBufferAttribute(n,o),hn.fromBufferAttribute(n,a),l.uv1=wt.getInterpolation(Ts,me,ye,ge,an,cn,hn,new J)),e&&(Ao.fromBufferAttribute(e,i),Mo.fromBufferAttribute(e,o),So.fromBufferAttribute(e,a),l.normal=wt.getInterpolation(Ts,me,ye,ge,Ao,Mo,So,new A),l.normal.dot(r.direction)>0&&l.normal.multiplyScalar(-1));const f={a:i,b:o,c:a,normal:new A,materialIndex:0};wt.getNormal(me,ye,ge,f.normal),l.face=f,l.faceIndex=i,rl&&(l.barycoord=d)}return l}function un(r,t,e,s,n,i,o){const a=s*3;let c=a+0,u=a+1,h=a+2;const l=r.index;r.index&&(c=l.getX(c),u=l.getX(u),h=l.getX(h));const{position:d,normal:f,uv:p,uv1:m}=r.attributes,g=al(e,d,f,p,m,c,u,h,t,i,o);return g?(g.faceIndex=s,n&&n.push(g),g):null}function st(r,t,e,s){const n=r.a,i=r.b,o=r.c;let a=t,c=t+1,u=t+2;e&&(a=e.getX(a),c=e.getX(c),u=e.getX(u)),n.x=s.getX(a),n.y=s.getY(a),n.z=s.getZ(a),i.x=s.getX(c),i.y=s.getY(c),i.z=s.getZ(c),o.x=s.getX(u),o.y=s.getY(u),o.z=s.getZ(u)}function cl(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++)un(c,t,e,h,i,o,a)}function hl(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let f;f=un(a,t,e,l,null,i,o),f&&f.distance<u&&(h=f,u=f.distance)}return h}function ul(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=h,st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function ll(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,f=h.length;d<f;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,f,p=!1){const m=d*2;if(a[m+15]===en){const y=o[d+6],T=a[m+14];let w=1/0,M=1/0,N=1/0,_=-1/0,S=-1/0,E=-1/0;for(let F=3*y,R=3*(y+T);F<R;F++){let I=s[F];const B=n.getX(I),P=n.getY(I),L=n.getZ(I);B<w&&(w=B),B>_&&(_=B),P<M&&(M=P),P>S&&(S=P),L<N&&(N=L),L>E&&(E=L)}return c[d+0]!==w||c[d+1]!==M||c[d+2]!==N||c[d+3]!==_||c[d+4]!==S||c[d+5]!==E?(c[d+0]=w,c[d+1]=M,c[d+2]=N,c[d+3]=_,c[d+4]=S,c[d+5]=E,!0):!1}else{const y=d+8,T=o[d+6],w=y+f,M=T+f;let N=p,_=!1,S=!1;t?N||(_=t.has(w),S=t.has(M),N=!_&&!S):(_=!0,S=!0);const E=N||_,F=N||S;let R=!1;E&&(R=l(y,f,N));let I=!1;F&&(I=l(T,f,N));const B=R||I;if(B)for(let P=0;P<3;P++){const L=y+P,V=T+P,G=c[L],Nt=c[L+3],Ht=c[V],qt=c[V+3];c[d+P]=G<Ht?G:Ht,c[d+P+3]=Nt>qt?Nt:qt}return B}}}function ce(r,t,e,s,n){let i,o,a,c,u,h;const l=1/e.direction.x,d=1/e.direction.y,f=1/e.direction.z,p=e.origin.x,m=e.origin.y,g=e.origin.z;let y=t[r],T=t[r+3],w=t[r+1],M=t[r+3+1],N=t[r+2],_=t[r+3+2];return l>=0?(i=(y-p)*l,o=(T-p)*l):(i=(T-p)*l,o=(y-p)*l),d>=0?(a=(w-m)*d,c=(M-m)*d):(a=(M-m)*d,c=(w-m)*d),i>c||a>o||((a>i||isNaN(i))&&(i=a),(c<o||isNaN(o))&&(o=c),f>=0?(u=(N-g)*f,h=(_-g)*f):(u=(_-g)*f,h=(N-g)*f),i>h||u>o)?!1:((u>i||i!==i)&&(i=u),(h<o||o!==o)&&(o=h),i<=n&&o>=s)}function dl(r,t,e,s,n,i,o,a){const{geometry:c,_indirectBuffer:u}=r;for(let h=s,l=s+n;h<l;h++){let d=u?u[h]:h;un(c,t,e,d,i,o,a)}}function fl(r,t,e,s,n,i,o){const{geometry:a,_indirectBuffer:c}=r;let u=1/0,h=null;for(let l=s,d=s+n;l<d;l++){let f;f=un(a,t,e,c?c[l]:l,null,i,o),f&&f.distance<u&&(h=f,u=f.distance)}return h}function pl(r,t,e,s,n,i,o){const{geometry:a}=e,{index:c}=a,u=a.attributes.position;for(let h=r,l=t+r;h<l;h++){let d;if(d=e.resolveTriangleIndex(h),st(o,d*3,c,u),o.needsUpdate=!0,s(o,d,n,i))return!0}return!1}function ml(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),Ei(0,r,e,s,n,i,o),X.clearBuffer()}function Ei(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(pt(h,c)){const d=Tt(r,u),f=St(h,c);cl(t,e,s,d,f,n,i,o)}else{const d=_t(r);ce(d,a,s,i,o)&&Ei(d,t,e,s,n,i,o);const f=zt(r,u);ce(f,a,s,i,o)&&Ei(f,t,e,s,n,i,o)}}const yl=["x","y","z"];function gl(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=Ci(0,r,e,s,n,i);return X.clearBuffer(),o}function Ci(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(pt(u,a)){const l=Tt(r,c),d=St(u,a);return hl(t,e,s,l,d,n,i)}else{const l=To(r,c),d=yl[l],p=s.direction[d]>=0;let m,g;p?(m=_t(r),g=zt(r,c)):(m=zt(r,c),g=_t(r));const T=ce(m,o,s,n,i)?Ci(m,t,e,s,n,i):null;if(T){const N=T.point[d];if(p?N<=o[g+l]:N>=o[g+l+3])return T}const M=ce(g,o,s,n,i)?Ci(g,t,e,s,n,i):null;return T&&M?T.distance<=M.distance?T:M:T||M||null}}const ln=new ht,ke=new Lt,He=new Lt,Ns=new nt,_o=new lt,dn=new lt;function xl(r,t,e,s){X.setBuffer(r._roots[t]);const n=Fi(0,r,e,s);return X.clearBuffer(),n}function Fi(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),_o.set(e.boundingBox.min,e.boundingBox.max,s),n=_o),pt(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,f=e.index,p=e.attributes.position,m=Tt(r,a),g=St(c,o);if(Ns.copy(s).invert(),e.boundsTree)return Z(r,i,dn),dn.matrix.copy(Ns),dn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:T=>dn.intersectsBox(T),intersectsTriangle:T=>{T.a.applyMatrix4(s),T.b.applyMatrix4(s),T.c.applyMatrix4(s),T.needsUpdate=!0;for(let w=m*3,M=(g+m)*3;w<M;w+=3)if(st(He,w,l,d),He.needsUpdate=!0,T.intersectsTriangle(He))return!0;return!1}});for(let y=m*3,T=(g+m)*3;y<T;y+=3){st(ke,y,l,d),ke.a.applyMatrix4(Ns),ke.b.applyMatrix4(Ns),ke.c.applyMatrix4(Ns),ke.needsUpdate=!0;for(let w=0,M=f.count;w<M;w+=3)if(st(He,w,f,p),He.needsUpdate=!0,ke.intersectsTriangle(He))return!0}}else{const h=r+8,l=a[r+6];return Z(h,i,ln),!!(n.intersectsBox(ln)&&Fi(h,t,e,s,n)||(Z(l,i,ln),n.intersectsBox(ln)&&Fi(l,t,e,s,n)))}}const fn=new nt,Ri=new lt,ws=new lt,Tl=new A,Nl=new A,wl=new A,Al=new A;function Ml(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Ri.set(t.boundingBox.min,t.boundingBox.max,e),Ri.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=bt.getPrimitive(),f=bt.getPrimitive();let p=Tl,m=Nl,g=null,y=null;n&&(g=wl,y=Al);let T=1/0,w=null,M=null;return fn.copy(e).invert(),ws.matrix.copy(fn),r.shapecast({boundsTraverseOrder:N=>Ri.distanceToBox(N),intersectsBounds:(N,_,S)=>S<T&&S<o?(_&&(ws.min.copy(N.min),ws.max.copy(N.max),ws.needsUpdate=!0),!0):!1,intersectsRange:(N,_)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:E=>ws.distanceToBox(E),intersectsBounds:(E,F,R)=>R<T&&R<o,intersectsRange:(E,F)=>{for(let R=E,I=E+F;R<I;R++){st(f,3*R,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let B=N,P=N+_;B<P;B++){st(d,3*B,u,c),d.needsUpdate=!0;const L=d.distanceToTriangle(f,p,g);if(L<T&&(m.copy(p),y&&y.copy(g),T=L,w=B,M=R),L<i)return!0}}}});{const S=De(t);for(let E=0,F=S;E<F;E++){st(f,3*E,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let R=N,I=N+_;R<I;R++){st(d,3*R,u,c),d.needsUpdate=!0;const B=d.distanceToTriangle(f,p,g);if(B<T&&(m.copy(p),y&&y.copy(g),T=B,w=R,M=E),B<i)return!0}}}}}),bt.releasePrimitive(d),bt.releasePrimitive(f),T===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=T,s.faceIndex=w,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(fn),m.applyMatrix4(fn),n.distance=m.sub(n.point).length(),n.faceIndex=M),s)}function Sl(r,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=r.geometry,s=e.index?e.index.array:null,n=e.attributes.position;let i,o,a,c,u=0;const h=r._roots;for(let d=0,f=h.length;d<f;d++)i=h[d],o=new Uint32Array(i),a=new Uint16Array(i),c=new Float32Array(i),l(0,u),u+=i.byteLength;function l(d,f,p=!1){const m=d*2;if(a[m+15]===en){const y=o[d+6],T=a[m+14];let w=1/0,M=1/0,N=1/0,_=-1/0,S=-1/0,E=-1/0;for(let F=y,R=y+T;F<R;F++){const I=3*r.resolveTriangleIndex(F);for(let B=0;B<3;B++){let P=I+B;P=s?s[P]:P;const L=n.getX(P),V=n.getY(P),G=n.getZ(P);L<w&&(w=L),L>_&&(_=L),V<M&&(M=V),V>S&&(S=V),G<N&&(N=G),G>E&&(E=G)}}return c[d+0]!==w||c[d+1]!==M||c[d+2]!==N||c[d+3]!==_||c[d+4]!==S||c[d+5]!==E?(c[d+0]=w,c[d+1]=M,c[d+2]=N,c[d+3]=_,c[d+4]=S,c[d+5]=E,!0):!1}else{const y=d+8,T=o[d+6],w=y+f,M=T+f;let N=p,_=!1,S=!1;t?N||(_=t.has(w),S=t.has(M),N=!_&&!S):(_=!0,S=!0);const E=N||_,F=N||S;let R=!1;E&&(R=l(y,f,N));let I=!1;F&&(I=l(T,f,N));const B=R||I;if(B)for(let P=0;P<3;P++){const L=y+P,V=T+P,G=c[L],Nt=c[L+3],Ht=c[V],qt=c[V+3];c[d+P]=G<Ht?G:Ht,c[d+P+3]=Nt>qt?Nt:qt}return B}}}function _l(r,t,e,s,n,i,o){X.setBuffer(r._roots[t]),Bi(0,r,e,s,n,i,o),X.clearBuffer()}function Bi(r,t,e,s,n,i,o){const{float32Array:a,uint16Array:c,uint32Array:u}=X,h=r*2;if(pt(h,c)){const d=Tt(r,u),f=St(h,c);dl(t,e,s,d,f,n,i,o)}else{const d=_t(r);ce(d,a,s,i,o)&&Bi(d,t,e,s,n,i,o);const f=zt(r,u);ce(f,a,s,i,o)&&Bi(f,t,e,s,n,i,o)}}const zl=["x","y","z"];function bl(r,t,e,s,n,i){X.setBuffer(r._roots[t]);const o=Ii(0,r,e,s,n,i);return X.clearBuffer(),o}function Ii(r,t,e,s,n,i){const{float32Array:o,uint16Array:a,uint32Array:c}=X;let u=r*2;if(pt(u,a)){const l=Tt(r,c),d=St(u,a);return fl(t,e,s,l,d,n,i)}else{const l=To(r,c),d=zl[l],p=s.direction[d]>=0;let m,g;p?(m=_t(r),g=zt(r,c)):(m=zt(r,c),g=_t(r));const T=ce(m,o,s,n,i)?Ii(m,t,e,s,n,i):null;if(T){const N=T.point[d];if(p?N<=o[g+l]:N>=o[g+l+3])return T}const M=ce(g,o,s,n,i)?Ii(g,t,e,s,n,i):null;return T&&M?T.distance<=M.distance?T:M:T||M||null}}const pn=new ht,qe=new Lt,$e=new Lt,As=new nt,zo=new lt,mn=new lt;function El(r,t,e,s){X.setBuffer(r._roots[t]);const n=vi(0,r,e,s);return X.clearBuffer(),n}function vi(r,t,e,s,n=null){const{float32Array:i,uint16Array:o,uint32Array:a}=X;let c=r*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),zo.set(e.boundingBox.min,e.boundingBox.max,s),n=zo),pt(c,o)){const h=t.geometry,l=h.index,d=h.attributes.position,f=e.index,p=e.attributes.position,m=Tt(r,a),g=St(c,o);if(As.copy(s).invert(),e.boundsTree)return Z(r,i,mn),mn.matrix.copy(As),mn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:T=>mn.intersectsBox(T),intersectsTriangle:T=>{T.a.applyMatrix4(s),T.b.applyMatrix4(s),T.c.applyMatrix4(s),T.needsUpdate=!0;for(let w=m,M=g+m;w<M;w++)if(st($e,3*t.resolveTriangleIndex(w),l,d),$e.needsUpdate=!0,T.intersectsTriangle($e))return!0;return!1}});for(let y=m,T=g+m;y<T;y++){const w=t.resolveTriangleIndex(y);st(qe,3*w,l,d),qe.a.applyMatrix4(As),qe.b.applyMatrix4(As),qe.c.applyMatrix4(As),qe.needsUpdate=!0;for(let M=0,N=f.count;M<N;M+=3)if(st($e,M,f,p),$e.needsUpdate=!0,qe.intersectsTriangle($e))return!0}}else{const h=r+8,l=a[r+6];return Z(h,i,pn),!!(n.intersectsBox(pn)&&vi(h,t,e,s,n)||(Z(l,i,pn),n.intersectsBox(pn)&&vi(l,t,e,s,n)))}}const yn=new nt,Pi=new lt,Ms=new lt,Cl=new A,Fl=new A,Rl=new A,Bl=new A;function Il(r,t,e,s={},n={},i=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Pi.set(t.boundingBox.min,t.boundingBox.max,e),Pi.needsUpdate=!0;const a=r.geometry,c=a.attributes.position,u=a.index,h=t.attributes.position,l=t.index,d=bt.getPrimitive(),f=bt.getPrimitive();let p=Cl,m=Fl,g=null,y=null;n&&(g=Rl,y=Bl);let T=1/0,w=null,M=null;return yn.copy(e).invert(),Ms.matrix.copy(yn),r.shapecast({boundsTraverseOrder:N=>Pi.distanceToBox(N),intersectsBounds:(N,_,S)=>S<T&&S<o?(_&&(Ms.min.copy(N.min),Ms.max.copy(N.max),Ms.needsUpdate=!0),!0):!1,intersectsRange:(N,_)=>{if(t.boundsTree){const S=t.boundsTree;return S.shapecast({boundsTraverseOrder:E=>Ms.distanceToBox(E),intersectsBounds:(E,F,R)=>R<T&&R<o,intersectsRange:(E,F)=>{for(let R=E,I=E+F;R<I;R++){const B=S.resolveTriangleIndex(R);st(f,3*B,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let P=N,L=N+_;P<L;P++){const V=r.resolveTriangleIndex(P);st(d,3*V,u,c),d.needsUpdate=!0;const G=d.distanceToTriangle(f,p,g);if(G<T&&(m.copy(p),y&&y.copy(g),T=G,w=P,M=R),G<i)return!0}}}})}else{const S=De(t);for(let E=0,F=S;E<F;E++){st(f,3*E,l,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let R=N,I=N+_;R<I;R++){const B=r.resolveTriangleIndex(R);st(d,3*B,u,c),d.needsUpdate=!0;const P=d.distanceToTriangle(f,p,g);if(P<T&&(m.copy(p),y&&y.copy(g),T=P,w=R,M=E),P<i)return!0}}}}}),bt.releasePrimitive(d),bt.releasePrimitive(f),T===1/0?null:(s.point?s.point.copy(m):s.point=m.clone(),s.distance=T,s.faceIndex=w,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(yn),m.applyMatrix4(yn),n.distance=m.sub(n.point).length(),n.faceIndex=M),s)}function vl(){return typeof SharedArrayBuffer<"u"}const Ss=new X.constructor,gn=new X.constructor,he=new _i(()=>new ht),Ge=new ht,We=new ht,Li=new ht,Oi=new ht;let Di=!1;function Pl(r,t,e,s){if(Di)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Di=!0;const n=r._roots,i=t._roots;let o,a=0,c=0;const u=new nt().copy(e).invert();for(let h=0,l=n.length;h<l;h++){Ss.setBuffer(n[h]),c=0;const d=he.getPrimitive();Z(0,Ss.float32Array,d),d.applyMatrix4(u);for(let f=0,p=i.length;f<p&&(gn.setBuffer(i[f]),o=Ot(0,0,e,u,s,a,c,0,0,d),gn.clearBuffer(),c+=i[f].length,!o);f++);if(he.releasePrimitive(d),Ss.clearBuffer(),a+=n[h].length,o)break}return Di=!1,o}function Ot(r,t,e,s,n,i=0,o=0,a=0,c=0,u=null,h=!1){let l,d;h?(l=gn,d=Ss):(l=Ss,d=gn);const f=l.float32Array,p=l.uint32Array,m=l.uint16Array,g=d.float32Array,y=d.uint32Array,T=d.uint16Array,w=r*2,M=t*2,N=pt(w,m),_=pt(M,T);let S=!1;if(_&&N)h?S=n(Tt(t,y),St(t*2,T),Tt(r,p),St(r*2,m),c,o+t,a,i+r):S=n(Tt(r,p),St(r*2,m),Tt(t,y),St(t*2,T),a,i+r,c,o+t);else if(_){const E=he.getPrimitive();Z(t,g,E),E.applyMatrix4(e);const F=_t(r),R=zt(r,p);Z(F,f,Ge),Z(R,f,We);const I=E.intersectsBox(Ge),B=E.intersectsBox(We);S=I&&Ot(t,F,s,e,n,o,i,c,a+1,E,!h)||B&&Ot(t,R,s,e,n,o,i,c,a+1,E,!h),he.releasePrimitive(E)}else{const E=_t(t),F=zt(t,y);Z(E,g,Li),Z(F,g,Oi);const R=u.intersectsBox(Li),I=u.intersectsBox(Oi);if(R&&I)S=Ot(r,E,e,s,n,i,o,a,c+1,u,h)||Ot(r,F,e,s,n,i,o,a,c+1,u,h);else if(R)if(N)S=Ot(r,E,e,s,n,i,o,a,c+1,u,h);else{const B=he.getPrimitive();B.copy(Li).applyMatrix4(e);const P=_t(r),L=zt(r,p);Z(P,f,Ge),Z(L,f,We);const V=B.intersectsBox(Ge),G=B.intersectsBox(We);S=V&&Ot(E,P,s,e,n,o,i,c,a+1,B,!h)||G&&Ot(E,L,s,e,n,o,i,c,a+1,B,!h),he.releasePrimitive(B)}else if(I)if(N)S=Ot(r,F,e,s,n,i,o,a,c+1,u,h);else{const B=he.getPrimitive();B.copy(Oi).applyMatrix4(e);const P=_t(r),L=zt(r,p);Z(P,f,Ge),Z(L,f,We);const V=B.intersectsBox(Ge),G=B.intersectsBox(We);S=V&&Ot(F,P,s,e,n,o,i,c,a+1,B,!h)||G&&Ot(F,L,s,e,n,o,i,c,a+1,B,!h),he.releasePrimitive(B)}}return S}const xn=new lt,bo=new ht,Ll={strategy:uo,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Tn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const s=t.geometry,n=t._roots,i=t._indirectBuffer,o=s.getIndex();let a;return e.cloneBuffers?a={roots:n.map(c=>c.slice()),index:o?o.array.slice():null,indirectBuffer:i?i.slice():null}:a={roots:n,index:o?o.array:null,indirectBuffer:i},a}static deserialize(t,e,s={}){s={setIndex:!0,indirect:!!t.indirectBuffer,...s};const{index:n,roots:i,indirectBuffer:o}=t,a=new Tn(e,{...s,[xi]:!0});if(a._roots=i,a._indirectBuffer=o||null,s.setIndex){const c=e.getIndex();if(c===null){const u=new vt(t.index,1,!1);e.setIndex(u)}else c.array!==n&&(c.array.set(n),c.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...Ll,[xi]:!1},e),e.useSharedArrayBuffer&&!vl())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[xi]||(ju(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new ht))),this.resolveTriangleIndex=e.indirect?s=>this._indirectBuffer[s]:s=>s}refit(t=null){return(this.indirect?Sl:ll)(this,t)}traverse(t,e=0){const s=this._roots[e],n=new Uint32Array(s),i=new Uint16Array(s);o(0);function o(a,c=0){const u=a*2,h=i[u+15]===en;if(h){const l=n[a+6],d=i[u+14];t(c,h,new Float32Array(s,a*4,6),l,d)}else{const l=a+ms/4,d=n[a+6],f=n[a+7];t(c,h,new Float32Array(s,a*4,6),f)||(o(l,c+1),o(d,c+1))}}}raycast(t,e=Vi,s=0,n=1/0){const i=this._roots,o=this.geometry,a=[],c=e.isMaterial,u=Array.isArray(e),h=o.groups,l=c?e.side:e,d=this.indirect?_l:ml;for(let f=0,p=i.length;f<p;f++){const m=u?e[h[f].materialIndex].side:l,g=a.length;if(d(this,f,m,t,a,s,n),u){const y=h[f].materialIndex;for(let T=g,w=a.length;T<w;T++)a[T].face.materialIndex=y}}return a}raycastFirst(t,e=Vi,s=0,n=1/0){const i=this._roots,o=this.geometry,a=e.isMaterial,c=Array.isArray(e);let u=null;const h=o.groups,l=a?e.side:e,d=this.indirect?bl:gl;for(let f=0,p=i.length;f<p;f++){const m=c?e[h[f].materialIndex].side:l,g=d(this,f,m,t,s,n);g!=null&&(u==null||g.distance<u.distance)&&(u=g,c&&(g.face.materialIndex=h[f].materialIndex))}return u}intersectsGeometry(t,e){let s=!1;const n=this._roots,i=this.indirect?El:xl;for(let o=0,a=n.length;o<a&&(s=i(this,o,t,e),!s);o++);return s}shapecast(t){const e=bt.getPrimitive(),s=this.indirect?pl:ul;let{boundsTraverseOrder:n,intersectsBounds:i,intersectsRange:o,intersectsTriangle:a}=t;if(o&&a){const l=o;o=(d,f,p,m,g)=>l(d,f,p,m,g)?!0:s(d,f,this,a,p,m,e)}else o||(a?o=(l,d,f,p)=>s(l,d,this,a,f,p,e):o=(l,d,f)=>f);let c=!1,u=0;const h=this._roots;for(let l=0,d=h.length;l<d;l++){const f=h[l];if(c=nl(this,l,i,o,n,u),c)break;u+=f.byteLength}return bt.releasePrimitive(e),c}bvhcast(t,e,s){let{intersectsRanges:n,intersectsTriangles:i}=s;const o=bt.getPrimitive(),a=this.geometry.index,c=this.geometry.attributes.position,u=this.indirect?p=>{const m=this.resolveTriangleIndex(p);st(o,m*3,a,c)}:p=>{st(o,p*3,a,c)},h=bt.getPrimitive(),l=t.geometry.index,d=t.geometry.attributes.position,f=t.indirect?p=>{const m=t.resolveTriangleIndex(p);st(h,m*3,l,d)}:p=>{st(h,p*3,l,d)};if(i){const p=(m,g,y,T,w,M,N,_)=>{for(let S=y,E=y+T;S<E;S++){f(S),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let F=m,R=m+g;F<R;F++)if(u(F),o.needsUpdate=!0,i(o,h,F,S,w,M,N,_))return!0}return!1};if(n){const m=n;n=function(g,y,T,w,M,N,_,S){return m(g,y,T,w,M,N,_,S)?!0:p(g,y,T,w,M,N,_,S)}}else n=p}return Pl(this,t,e,n)}intersectsBox(t,e){return xn.set(t.min,t.max,e),xn.needsUpdate=!0,this.shapecast({intersectsBounds:s=>xn.intersectsBox(s),intersectsTriangle:s=>xn.intersectsTriangle(s)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,s={},n={},i=0,o=1/0){return(this.indirect?Il:Ml)(this,t,e,s,n,i,o)}closestPointToPoint(t,e={},s=0,n=1/0){return il(this,t,e,s,n)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(s=>{Z(0,new Float32Array(s),bo),t.union(bo)}),t}}onmessage=({data:r})=>{let t=performance.now();function e(o){o=Math.min(o,1);const a=performance.now();a-t>=10&&o!==1&&(postMessage({error:null,serialized:null,position:null,progress:o}),t=a)}const{index:s,position:n,options:i}=r;try{const o=new Gn;if(o.setAttribute("position",new vt(n,3,!1)),s&&o.setIndex(new vt(s,1,!1)),i.includedProgressCallback&&(i.onProgress=e),i.groups){const h=i.groups;for(const l in h){const d=h[l];o.addGroup(d.start,d.count,d.materialIndex)}}const a=new Tn(o,i),c=Tn.serialize(a,{copyIndexBuffer:!1});let u=[n.buffer,...c.roots];c.index&&u.push(c.index.buffer),u=u.filter(h=>typeof SharedArrayBuffer>"u"||!(h instanceof SharedArrayBuffer)),a._indirectBuffer&&u.push(c.indirectBuffer.buffer),postMessage({error:null,serialized:c,position:n,progress:1},u)}catch(o){postMessage({error:o,serialized:null,position:null,progress:1})}}})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const g=require("./three.light.umd.cjs"),Z=require("./three-examples.light.umd.cjs"),Fe="";globalThis.GLTF_PROGRESSIVE_VERSION=Fe;console.debug("[gltf-progressive] version -");let F="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",j="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ue=F,Ve=j,Pe=new URL(F+"draco_decoder.js");Pe.searchParams.append("range","true");fetch(Pe,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${F} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),F===Ue&&Ce("./include/draco/"),j===Ve&&Be("./include/ktx2/")}).finally(()=>{ke()});function Ce(t){F=t,C&&C[me]!=F?(console.debug("Updating Draco decoder path to "+t),C[me]=F,C.setDecoderPath(F),C.preload()):console.debug("Setting Draco decoder path to "+t)}function Be(t){j=t,$&&$.transcoderPath!=j?(console.debug("Updating KTX2 transcoder path to "+t),$.setTranscoderPath(j),$.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let C,de,$;function ke(){C||(C=new Z.DRACOLoader,C[me]=F,C.setDecoderPath(F),C.setDecoderConfig({type:"js"}),C.preload()),$||($=new Z.KTX2Loader,$.setTranscoderPath(j),$.init()),de||(de=Z.MeshoptDecoder)}function we(t){return ke(),t?$.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:C,ktx2Loader:$,meshoptDecoder:de}}function Oe(t){t.dracoLoader||t.setDRACOLoader(C),t.ktx2Loader||t.setKTX2Loader($),t.meshoptDecoder||t.setMeshoptDecoder(de)}const xe=new WeakMap;function Se(t,e){let s=xe.get(t);s?s=Object.assign(s,e):s=e,xe.set(t,s)}const pe=Z.GLTFLoader.prototype.load;function We(...t){const e=xe.get(this);let s=t[0];const o=new URL(s,window.location.href);if(o.hostname.endsWith("needle.tools")){const r=(e==null?void 0:e.progressive)!==void 0?e.progressive:!0,n=e!=null&&e.usecase?e.usecase:"default";r?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${n}`:this.requestHeader.Accept=`*/*;usecase=${n}`,s=o.toString()}return t[0]=s,pe==null?void 0:pe.call(this,...t)}Z.GLTFLoader.prototype.load=We;ne("debugprogressive");function ne(t){if(typeof window>"u")return!1;const s=new URL(window.location.href).searchParams.get(t);return s==null||s==="0"||s==="false"?!1:s===""?!0:s}function ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const s=t.lastIndexOf("/");if(s>=0){const o=t.substring(0,s+1);for(;o.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return o+e}return e}let te;function Xe(){return te!==void 0||(te=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),ne("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",te)),te}const qe=typeof window>"u"&&typeof document>"u",De=Symbol("needle:raycast-mesh");function ee(t){return(t==null?void 0:t[De])instanceof g.BufferGeometry?t[De]:null}function Ke(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!ee(t)){const o=He(e);o.userData={isRaycastMesh:!0},t[De]=o}}function Ye(t=!0){if(t){if(se)return;const e=se=g.Mesh.prototype.raycast;g.Mesh.prototype.raycast=function(s,o){const i=this,r=ee(i);let n;r&&i.isMesh&&(n=i.geometry,i.geometry=r),e.call(this,s,o),n&&(i.geometry=n)}}else{if(!se)return;g.Mesh.prototype.raycast=se,se=null}}let se=null;function He(t){const e=new g.BufferGeometry;for(const s in t.attributes)e.setAttribute(s,t.getAttribute(s));return e.setIndex(t.getIndex()),e}const H=new Array,z="NEEDLE_progressive",y=ne("debugprogressive"),Me=Symbol("needle-progressive-texture"),oe=new Map,_e=new Set;if(y){let t=function(){e+=1,console.log("Toggle LOD level",e,oe),oe.forEach((i,r)=>{for(const n of i.keys){const a=r[n];if(a!=null)if(a.isBufferGeometry===!0){const c=E.getMeshLODInformation(a),l=c?Math.min(e,c.lods.length):0;r["DEBUG:LOD"]=l,c&&(s=Math.max(s,c.lods.length-1))}else r.isMaterial===!0&&(r["DEBUG:LOD"]=e)}}),e>=s&&(e=-1)},e=-1,s=2,o=!1;window.addEventListener("keyup",i=>{i.key==="p"&&t(),i.key==="w"&&(o=!o,_e&&_e.forEach(r=>{r.name!="BackgroundCubeMaterial"&&r.glyphMap==null&&"wireframe"in r&&(r.wireframe=o)}))})}function be(t,e,s){var i;if(!y)return;oe.has(t)||oe.set(t,{keys:[],sourceId:s});const o=oe.get(t);((i=o==null?void 0:o.keys)==null?void 0:i.includes(e))==!1&&o.keys.push(e)}const _=class{constructor(t,e){this.loadMesh=s=>{var i,r;if(this._isLoadingMesh)return null;const o=(r=(i=this.parser.json.meshes[s])==null?void 0:i.extensions)==null?void 0:r[z];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",s).then(n=>{var a;return this._isLoadingMesh=!1,n&&_.registerMesh(this.url,o.guid,n,(a=o.lods)==null?void 0:a.length,void 0,o),n})):null},y&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return z}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const s=this,o="LODS:minmax",i=t[o];if(i!=null)return i;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const n of t)this.getMaterialMinMaxLODsCount(n,e);return t[o]=e,e}if(y==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const n=t;for(const a of Object.keys(n.uniforms)){const c=n.uniforms[a].value;(c==null?void 0:c.isTexture)===!0&&r(c,e)}}else if(t.isMaterial)for(const n of Object.keys(t)){const a=t[n];(a==null?void 0:a.isTexture)===!0&&r(a,e)}return t[o]=e,e;function r(n,a){const c=s.getAssignedLODInformation(n);if(c){const l=s.lodInfos.get(c.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let d=0;d<l.lods.length;d++){const h=l.lods[d];h.width&&(a.lods[d]=a.lods[d]||{min_height:1/0,max_height:0},a.lods[d].min_height=Math.min(a.lods[d].min_height,h.height),a.lods[d].max_height=Math.max(a.lods[d].max_height,h.height))}}}}}static hasLODLevelAvailable(t,e){var i;if(Array.isArray(t)){for(const r of t)if(this.hasLODLevelAvailable(r,e))return!0;return!1}if(t.isMaterial===!0){for(const r of Object.keys(t)){const n=t[r];if(n&&n.isTexture&&this.hasLODLevelAvailable(n,e))return!0}return!1}else if(t.isGroup===!0){for(const r of t.children)if(r.isMesh===!0&&this.hasLODLevelAvailable(r,e))return!0}let s,o;if(t.isMesh?s=t.geometry:(t.isBufferGeometry||t.isTexture)&&(s=t),s&&(i=s==null?void 0:s.userData)!=null&&i.LODS){const r=s.userData.LODS;if(o=this.lodInfos.get(r.key),e===void 0)return o!=null;if(o)return Array.isArray(o.lods)?e<o.lods.length:e===0}return!1}static assignMeshLOD(t,e){var s;if(!t)return Promise.resolve(null);if(t instanceof g.Mesh||t.isMesh===!0){const o=t.geometry,i=this.getAssignedLODInformation(o);if(!i)return Promise.resolve(null);for(const r of H)(s=r.onBeforeGetLODMesh)==null||s.call(r,t,e);return t["LOD:requested level"]=e,_.getOrLoadLOD(o,e).then(r=>{if(Array.isArray(r)){const n=i.index||0;r=r[n]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],r&&o!=r&&((r==null?void 0:r.isBufferGeometry)?(t.geometry=r,y&&be(t,"geometry",i.url)):y&&console.error("Invalid LOD geometry",r))),r}).catch(r=>(console.error("Error loading mesh LOD",t,r),null))}else y&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const s=t;if(Array.isArray(s.material)){const o=new Array;for(const i of s.material){const r=this.assignTextureLOD(i,e);o.push(r)}return Promise.all(o).then(i=>{const r=new Array;for(const n of i)Array.isArray(n)&&r.push(...n);return r})}else return this.assignTextureLOD(s.material,e)}if(t.isMaterial===!0){const s=t,o=[],i=new Array;if(y&&_e.add(s),s.uniforms&&(s.isRawShaderMaterial||s.isShaderMaterial===!0)){const r=s;for(const n of Object.keys(r.uniforms)){const a=r.uniforms[n].value;if((a==null?void 0:a.isTexture)===!0){const c=this.assignTextureLODForSlot(a,e,s,n).then(l=>(l&&r.uniforms[n].value!=l&&(r.uniforms[n].value=l,r.uniformsNeedUpdate=!0),l));o.push(c),i.push(n)}}}else for(const r of Object.keys(s)){const n=s[r];if((n==null?void 0:n.isTexture)===!0){const a=this.assignTextureLODForSlot(n,e,s,r);o.push(a),i.push(r)}}return Promise.all(o).then(r=>{const n=new Array;for(let a=0;a<r.length;a++){const c=r[a],l=i[a];c&&c.isTexture===!0?n.push({material:s,slot:l,texture:c,level:e}):n.push({material:s,slot:l,texture:null,level:e})}return n})}if(t instanceof g.Texture||t.isTexture===!0){const s=t;return this.assignTextureLODForSlot(s,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,s,o){return(t==null?void 0:t.isTexture)!==!0?Promise.resolve(null):o==="glyphMap"?Promise.resolve(t):_.getOrLoadLOD(t,e).then(i=>{if(Array.isArray(i))return null;if((i==null?void 0:i.isTexture)===!0){if(i!=t){if(s&&o){const r=s[o];if(r&&!y){const n=this.getAssignedLODInformation(r);if(n&&(n==null?void 0:n.level)<e)return y==="verbose"&&console.warn("Assigned texture level is already higher: ",n.level,e,s,r,i),null}s[o]=i}if(y&&o&&s){const r=this.getAssignedLODInformation(t);r?be(s,o,r.url):console.warn("No LOD info for texture",t)}}return i}else y=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(i=>(console.error("Error loading LOD",t,i),null))}afterRoot(t){var e,s;return y&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((o,i)=>{var r;if(o!=null&&o.extensions){const n=o==null?void 0:o.extensions[z];if(n){if(!n.lods){y&&console.warn("Texture has no LODs",n);return}let a=!1;for(const c of this.parser.associations.keys())if(c.isTexture===!0){const l=this.parser.associations.get(c);(l==null?void 0:l.textures)===i&&(a=!0,_.registerTexture(this.url,c,(r=n.lods)==null?void 0:r.length,i,n))}a||this.parser.getDependency("texture",i).then(c=>{var l;c&&_.registerTexture(this.url,c,(l=n.lods)==null?void 0:l.length,i,n)})}}}),(s=this.parser.json.meshes)==null||s.forEach((o,i)=>{if(o!=null&&o.extensions){const r=o==null?void 0:o.extensions[z];if(r&&r.lods){for(const n of this.parser.associations.keys())if(n.isMesh){const a=this.parser.associations.get(n);(a==null?void 0:a.meshes)===i&&_.registerMesh(this.url,r.guid,n,r.lods.length,a.primitives,r)}}}}),null}static async getOrLoadLOD(t,e){var n,a,c,l;const s=y=="verbose",o=t.userData.LODS;if(!o)return null;const i=o==null?void 0:o.key;let r;if(t.isTexture===!0){const d=t;d.source&&d.source[Me]&&(r=d.source[Me])}if(r||(r=_.lodInfos.get(i)),r){if(e>0){let D=!1;const m=Array.isArray(r.lods);if(m&&e>=r.lods.length?D=!0:m||(D=!0),D)return this.lowresCache.get(i)}const d=Array.isArray(r.lods)?(n=r.lods[e])==null?void 0:n.path:r.lods;if(!d)return y&&!r["missing:uri"]&&(r["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,r)),null;const h=ze(o.url,d);if(h.endsWith(".glb")||h.endsWith(".gltf")){if(!r.guid)return console.warn("missing pointer for glb/gltf texture",r),null;const D=h+"_"+r.guid,m=this.previouslyLoaded.get(D);if(m!==void 0){s&&console.log(`LOD ${e} was already loading/loaded: ${D}`);let f=await m.catch(N=>(console.error(`Error loading LOD ${e} from ${h}
|
|
1
|
+
"use strict";const g=require("./three-67c59991.umd.cjs"),Z=require("./three-examples-a36ec195.umd.cjs"),Fe="";globalThis.GLTF_PROGRESSIVE_VERSION=Fe;console.debug("[gltf-progressive] version -");let F="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",j="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ue=F,Ve=j,Pe=new URL(F+"draco_decoder.js");Pe.searchParams.append("range","true");fetch(Pe,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${F} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),F===Ue&&Ce("./include/draco/"),j===Ve&&Be("./include/ktx2/")}).finally(()=>{ke()});function Ce(t){F=t,C&&C[me]!=F?(console.debug("Updating Draco decoder path to "+t),C[me]=F,C.setDecoderPath(F),C.preload()):console.debug("Setting Draco decoder path to "+t)}function Be(t){j=t,$&&$.transcoderPath!=j?(console.debug("Updating KTX2 transcoder path to "+t),$.setTranscoderPath(j),$.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let C,de,$;function ke(){C||(C=new Z.DRACOLoader,C[me]=F,C.setDecoderPath(F),C.setDecoderConfig({type:"js"}),C.preload()),$||($=new Z.KTX2Loader,$.setTranscoderPath(j),$.init()),de||(de=Z.MeshoptDecoder)}function we(t){return ke(),t?$.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:C,ktx2Loader:$,meshoptDecoder:de}}function Oe(t){t.dracoLoader||t.setDRACOLoader(C),t.ktx2Loader||t.setKTX2Loader($),t.meshoptDecoder||t.setMeshoptDecoder(de)}const xe=new WeakMap;function Se(t,e){let s=xe.get(t);s?s=Object.assign(s,e):s=e,xe.set(t,s)}const pe=Z.GLTFLoader.prototype.load;function We(...t){const e=xe.get(this);let s=t[0];const o=new URL(s,window.location.href);if(o.hostname.endsWith("needle.tools")){const r=(e==null?void 0:e.progressive)!==void 0?e.progressive:!0,n=e!=null&&e.usecase?e.usecase:"default";r?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${n}`:this.requestHeader.Accept=`*/*;usecase=${n}`,s=o.toString()}return t[0]=s,pe==null?void 0:pe.call(this,...t)}Z.GLTFLoader.prototype.load=We;ne("debugprogressive");function ne(t){if(typeof window>"u")return!1;const s=new URL(window.location.href).searchParams.get(t);return s==null||s==="0"||s==="false"?!1:s===""?!0:s}function ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const s=t.lastIndexOf("/");if(s>=0){const o=t.substring(0,s+1);for(;o.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return o+e}return e}let te;function Xe(){return te!==void 0||(te=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),ne("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",te)),te}const qe=typeof window>"u"&&typeof document>"u",De=Symbol("needle:raycast-mesh");function ee(t){return(t==null?void 0:t[De])instanceof g.BufferGeometry?t[De]:null}function Ke(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!ee(t)){const o=He(e);o.userData={isRaycastMesh:!0},t[De]=o}}function Ye(t=!0){if(t){if(se)return;const e=se=g.Mesh.prototype.raycast;g.Mesh.prototype.raycast=function(s,o){const i=this,r=ee(i);let n;r&&i.isMesh&&(n=i.geometry,i.geometry=r),e.call(this,s,o),n&&(i.geometry=n)}}else{if(!se)return;g.Mesh.prototype.raycast=se,se=null}}let se=null;function He(t){const e=new g.BufferGeometry;for(const s in t.attributes)e.setAttribute(s,t.getAttribute(s));return e.setIndex(t.getIndex()),e}const H=new Array,z="NEEDLE_progressive",y=ne("debugprogressive"),Me=Symbol("needle-progressive-texture"),oe=new Map,_e=new Set;if(y){let t=function(){e+=1,console.log("Toggle LOD level",e,oe),oe.forEach((i,r)=>{for(const n of i.keys){const a=r[n];if(a!=null)if(a.isBufferGeometry===!0){const c=E.getMeshLODInformation(a),l=c?Math.min(e,c.lods.length):0;r["DEBUG:LOD"]=l,c&&(s=Math.max(s,c.lods.length-1))}else r.isMaterial===!0&&(r["DEBUG:LOD"]=e)}}),e>=s&&(e=-1)},e=-1,s=2,o=!1;window.addEventListener("keyup",i=>{i.key==="p"&&t(),i.key==="w"&&(o=!o,_e&&_e.forEach(r=>{r.name!="BackgroundCubeMaterial"&&r.glyphMap==null&&"wireframe"in r&&(r.wireframe=o)}))})}function be(t,e,s){var i;if(!y)return;oe.has(t)||oe.set(t,{keys:[],sourceId:s});const o=oe.get(t);((i=o==null?void 0:o.keys)==null?void 0:i.includes(e))==!1&&o.keys.push(e)}const _=class{constructor(t,e){this.loadMesh=s=>{var i,r;if(this._isLoadingMesh)return null;const o=(r=(i=this.parser.json.meshes[s])==null?void 0:i.extensions)==null?void 0:r[z];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",s).then(n=>{var a;return this._isLoadingMesh=!1,n&&_.registerMesh(this.url,o.guid,n,(a=o.lods)==null?void 0:a.length,void 0,o),n})):null},y&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return z}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const s=this,o="LODS:minmax",i=t[o];if(i!=null)return i;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const n of t)this.getMaterialMinMaxLODsCount(n,e);return t[o]=e,e}if(y==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const n=t;for(const a of Object.keys(n.uniforms)){const c=n.uniforms[a].value;(c==null?void 0:c.isTexture)===!0&&r(c,e)}}else if(t.isMaterial)for(const n of Object.keys(t)){const a=t[n];(a==null?void 0:a.isTexture)===!0&&r(a,e)}return t[o]=e,e;function r(n,a){const c=s.getAssignedLODInformation(n);if(c){const l=s.lodInfos.get(c.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let d=0;d<l.lods.length;d++){const h=l.lods[d];h.width&&(a.lods[d]=a.lods[d]||{min_height:1/0,max_height:0},a.lods[d].min_height=Math.min(a.lods[d].min_height,h.height),a.lods[d].max_height=Math.max(a.lods[d].max_height,h.height))}}}}}static hasLODLevelAvailable(t,e){var i;if(Array.isArray(t)){for(const r of t)if(this.hasLODLevelAvailable(r,e))return!0;return!1}if(t.isMaterial===!0){for(const r of Object.keys(t)){const n=t[r];if(n&&n.isTexture&&this.hasLODLevelAvailable(n,e))return!0}return!1}else if(t.isGroup===!0){for(const r of t.children)if(r.isMesh===!0&&this.hasLODLevelAvailable(r,e))return!0}let s,o;if(t.isMesh?s=t.geometry:(t.isBufferGeometry||t.isTexture)&&(s=t),s&&(i=s==null?void 0:s.userData)!=null&&i.LODS){const r=s.userData.LODS;if(o=this.lodInfos.get(r.key),e===void 0)return o!=null;if(o)return Array.isArray(o.lods)?e<o.lods.length:e===0}return!1}static assignMeshLOD(t,e){var s;if(!t)return Promise.resolve(null);if(t instanceof g.Mesh||t.isMesh===!0){const o=t.geometry,i=this.getAssignedLODInformation(o);if(!i)return Promise.resolve(null);for(const r of H)(s=r.onBeforeGetLODMesh)==null||s.call(r,t,e);return t["LOD:requested level"]=e,_.getOrLoadLOD(o,e).then(r=>{if(Array.isArray(r)){const n=i.index||0;r=r[n]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],r&&o!=r&&((r==null?void 0:r.isBufferGeometry)?(t.geometry=r,y&&be(t,"geometry",i.url)):y&&console.error("Invalid LOD geometry",r))),r}).catch(r=>(console.error("Error loading mesh LOD",t,r),null))}else y&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const s=t;if(Array.isArray(s.material)){const o=new Array;for(const i of s.material){const r=this.assignTextureLOD(i,e);o.push(r)}return Promise.all(o).then(i=>{const r=new Array;for(const n of i)Array.isArray(n)&&r.push(...n);return r})}else return this.assignTextureLOD(s.material,e)}if(t.isMaterial===!0){const s=t,o=[],i=new Array;if(y&&_e.add(s),s.uniforms&&(s.isRawShaderMaterial||s.isShaderMaterial===!0)){const r=s;for(const n of Object.keys(r.uniforms)){const a=r.uniforms[n].value;if((a==null?void 0:a.isTexture)===!0){const c=this.assignTextureLODForSlot(a,e,s,n).then(l=>(l&&r.uniforms[n].value!=l&&(r.uniforms[n].value=l,r.uniformsNeedUpdate=!0),l));o.push(c),i.push(n)}}}else for(const r of Object.keys(s)){const n=s[r];if((n==null?void 0:n.isTexture)===!0){const a=this.assignTextureLODForSlot(n,e,s,r);o.push(a),i.push(r)}}return Promise.all(o).then(r=>{const n=new Array;for(let a=0;a<r.length;a++){const c=r[a],l=i[a];c&&c.isTexture===!0?n.push({material:s,slot:l,texture:c,level:e}):n.push({material:s,slot:l,texture:null,level:e})}return n})}if(t instanceof g.Texture||t.isTexture===!0){const s=t;return this.assignTextureLODForSlot(s,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,s,o){return(t==null?void 0:t.isTexture)!==!0?Promise.resolve(null):o==="glyphMap"?Promise.resolve(t):_.getOrLoadLOD(t,e).then(i=>{if(Array.isArray(i))return null;if((i==null?void 0:i.isTexture)===!0){if(i!=t){if(s&&o){const r=s[o];if(r&&!y){const n=this.getAssignedLODInformation(r);if(n&&(n==null?void 0:n.level)<e)return y==="verbose"&&console.warn("Assigned texture level is already higher: ",n.level,e,s,r,i),null}s[o]=i}if(y&&o&&s){const r=this.getAssignedLODInformation(t);r?be(s,o,r.url):console.warn("No LOD info for texture",t)}}return i}else y=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(i=>(console.error("Error loading LOD",t,i),null))}afterRoot(t){var e,s;return y&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((o,i)=>{var r;if(o!=null&&o.extensions){const n=o==null?void 0:o.extensions[z];if(n){if(!n.lods){y&&console.warn("Texture has no LODs",n);return}let a=!1;for(const c of this.parser.associations.keys())if(c.isTexture===!0){const l=this.parser.associations.get(c);(l==null?void 0:l.textures)===i&&(a=!0,_.registerTexture(this.url,c,(r=n.lods)==null?void 0:r.length,i,n))}a||this.parser.getDependency("texture",i).then(c=>{var l;c&&_.registerTexture(this.url,c,(l=n.lods)==null?void 0:l.length,i,n)})}}}),(s=this.parser.json.meshes)==null||s.forEach((o,i)=>{if(o!=null&&o.extensions){const r=o==null?void 0:o.extensions[z];if(r&&r.lods){for(const n of this.parser.associations.keys())if(n.isMesh){const a=this.parser.associations.get(n);(a==null?void 0:a.meshes)===i&&_.registerMesh(this.url,r.guid,n,r.lods.length,a.primitives,r)}}}}),null}static async getOrLoadLOD(t,e){var n,a,c,l;const s=y=="verbose",o=t.userData.LODS;if(!o)return null;const i=o==null?void 0:o.key;let r;if(t.isTexture===!0){const d=t;d.source&&d.source[Me]&&(r=d.source[Me])}if(r||(r=_.lodInfos.get(i)),r){if(e>0){let D=!1;const m=Array.isArray(r.lods);if(m&&e>=r.lods.length?D=!0:m||(D=!0),D)return this.lowresCache.get(i)}const d=Array.isArray(r.lods)?(n=r.lods[e])==null?void 0:n.path:r.lods;if(!d)return y&&!r["missing:uri"]&&(r["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,r)),null;const h=ze(o.url,d);if(h.endsWith(".glb")||h.endsWith(".gltf")){if(!r.guid)return console.warn("missing pointer for glb/gltf texture",r),null;const D=h+"_"+r.guid,m=this.previouslyLoaded.get(D);if(m!==void 0){s&&console.log(`LOD ${e} was already loading/loaded: ${D}`);let f=await m.catch(N=>(console.error(`Error loading LOD ${e} from ${h}
|
|
2
2
|
`,N),null)),O=!1;if(f==null||(f instanceof g.Texture&&t instanceof g.Texture?(a=f.image)!=null&&a.data||(c=f.source)!=null&&c.data?f=this.copySettings(t,f):(O=!0,this.previouslyLoaded.delete(D)):f instanceof g.BufferGeometry&&t instanceof g.BufferGeometry&&((l=f.attributes.position)!=null&&l.array||(O=!0,this.previouslyLoaded.delete(D)))),!O)return f}const M=r,k=new Promise(async(f,O)=>{const N=new Z.GLTFLoader;Oe(N),y&&(await new Promise(S=>setTimeout(S,1e3)),s&&console.warn("Start loading (delayed) "+h,M.guid));let R=h;if(M&&Array.isArray(M.lods)){const S=M.lods[e];S.hash&&(R+="?v="+S.hash)}const A=await N.loadAsync(R).catch(S=>(console.error(`Error loading LOD ${e} from ${h}
|
|
3
3
|
`,S),null));if(!A)return null;const V=A.parser;s&&console.log("Loading finished "+h,M.guid);let w=0;if(A.parser.json.textures){let S=!1;for(const u of A.parser.json.textures){if(u!=null&&u.extensions){const p=u==null?void 0:u.extensions[z];if(p!=null&&p.guid&&p.guid===M.guid){S=!0;break}}w++}if(S){let u=await V.getDependency("texture",w);return u&&_.assignLODInformation(o.url,u,i,e,void 0,void 0),s&&console.log('change "'+t.name+'" → "'+u.name+'"',h,w,u,D),t instanceof g.Texture&&(u=this.copySettings(t,u)),u&&(u.guid=M.guid),f(u)}else y&&console.warn("Could not find texture with guid",M.guid,A.parser.json)}if(w=0,A.parser.json.meshes){let S=!1;for(const u of A.parser.json.meshes){if(u!=null&&u.extensions){const p=u==null?void 0:u.extensions[z];if(p!=null&&p.guid&&p.guid===M.guid){S=!0;break}}w++}if(S){const u=await V.getDependency("mesh",w),p=M;if(s&&console.log(`Loaded Mesh "${u.name}"`,h,w,u,D),u.isMesh===!0){const v=u.geometry;return _.assignLODInformation(o.url,v,i,e,void 0,p.density),f(v)}else{const v=new Array;for(let b=0;b<u.children.length;b++){const P=u.children[b];if(P.isMesh===!0){const X=P.geometry;_.assignLODInformation(o.url,X,i,e,b,p.density),v.push(X)}}return f(v)}}else y&&console.warn("Could not find mesh with guid",M.guid,A.parser.json)}return f(null)});return this.previouslyLoaded.set(D,k),await k}else if(t instanceof g.Texture){s&&console.log("Load texture from uri: "+h);const m=await new g.TextureLoader().loadAsync(h);return m?(m.guid=r.guid,m.flipY=!1,m.needsUpdate=!0,m.colorSpace=t.colorSpace,s&&console.log(r,m)):y&&console.warn("failed loading",h),m}}else y&&console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`,t.type);return null}static assignLODInformation(t,e,s,o,i,r){if(!e)return;e.userData||(e.userData={});const n=new Je(t,s,o,i,r);e.userData.LODS=n}static getAssignedLODInformation(t){var e;return((e=t==null?void 0:t.userData)==null?void 0:e.LODS)||null}static copySettings(t,e){return e?(y&&console.warn(`Copy texture settings
|
|
4
4
|
`,t.uuid,`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BufferGeometry as he, Mesh as Q, Texture as ee, TextureLoader as ze, Vector3 as z, Matrix4 as be, Sphere as Ve, Box3 as Ee, MeshStandardMaterial as Xe, Clock as qe } from "./three.light.js";
|
|
2
|
-
import { DRACOLoader as Ke, KTX2Loader as Ye, GLTFLoader as Se, MeshoptDecoder as He } from "./three-examples.light.js";
|
|
1
|
+
import { BufferGeometry as he, Mesh as Q, Texture as ee, TextureLoader as ze, Vector3 as z, Matrix4 as be, Sphere as Ve, Box3 as Ee, MeshStandardMaterial as Xe, Clock as qe } from "./three-3fd45ef1.light.js";
|
|
2
|
+
import { DRACOLoader as Ke, KTX2Loader as Ye, GLTFLoader as Se, MeshoptDecoder as He } from "./three-examples-ae5d9997.light.js";
|
|
3
3
|
const Je = "";
|
|
4
4
|
globalThis.GLTF_PROGRESSIVE_VERSION = Je;
|
|
5
5
|
console.debug("[gltf-progressive] version -");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BufferGeometry as he, Mesh as Q, Texture as ee, TextureLoader as ze, Vector3 as z, Matrix4 as be, Sphere as Ve, Box3 as Ee, MeshStandardMaterial as Xe, Clock as qe } from "./three.js";
|
|
2
|
-
import { DRACOLoader as Ke, KTX2Loader as Ye, GLTFLoader as Se, MeshoptDecoder as He } from "./three-examples.js";
|
|
1
|
+
import { BufferGeometry as he, Mesh as Q, Texture as ee, TextureLoader as ze, Vector3 as z, Matrix4 as be, Sphere as Ve, Box3 as Ee, MeshStandardMaterial as Xe, Clock as qe } from "./three-3fd45ef1.js";
|
|
2
|
+
import { DRACOLoader as Ke, KTX2Loader as Ye, GLTFLoader as Se, MeshoptDecoder as He } from "./three-examples-9070776e.js";
|
|
3
3
|
const Je = "";
|
|
4
4
|
globalThis.GLTF_PROGRESSIVE_VERSION = Je;
|
|
5
5
|
console.debug("[gltf-progressive] version -");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const g=require("./three.umd.cjs"),Z=require("./three-examples.umd.cjs"),Fe="";globalThis.GLTF_PROGRESSIVE_VERSION=Fe;console.debug("[gltf-progressive] version -");let F="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",j="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ue=F,Ve=j,Pe=new URL(F+"draco_decoder.js");Pe.searchParams.append("range","true");fetch(Pe,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${F} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),F===Ue&&Ce("./include/draco/"),j===Ve&&Be("./include/ktx2/")}).finally(()=>{ke()});function Ce(t){F=t,C&&C[me]!=F?(console.debug("Updating Draco decoder path to "+t),C[me]=F,C.setDecoderPath(F),C.preload()):console.debug("Setting Draco decoder path to "+t)}function Be(t){j=t,$&&$.transcoderPath!=j?(console.debug("Updating KTX2 transcoder path to "+t),$.setTranscoderPath(j),$.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let C,de,$;function ke(){C||(C=new Z.DRACOLoader,C[me]=F,C.setDecoderPath(F),C.setDecoderConfig({type:"js"}),C.preload()),$||($=new Z.KTX2Loader,$.setTranscoderPath(j),$.init()),de||(de=Z.MeshoptDecoder)}function we(t){return ke(),t?$.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:C,ktx2Loader:$,meshoptDecoder:de}}function Oe(t){t.dracoLoader||t.setDRACOLoader(C),t.ktx2Loader||t.setKTX2Loader($),t.meshoptDecoder||t.setMeshoptDecoder(de)}const xe=new WeakMap;function Se(t,e){let s=xe.get(t);s?s=Object.assign(s,e):s=e,xe.set(t,s)}const pe=Z.GLTFLoader.prototype.load;function We(...t){const e=xe.get(this);let s=t[0];const o=new URL(s,window.location.href);if(o.hostname.endsWith("needle.tools")){const r=(e==null?void 0:e.progressive)!==void 0?e.progressive:!0,n=e!=null&&e.usecase?e.usecase:"default";r?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${n}`:this.requestHeader.Accept=`*/*;usecase=${n}`,s=o.toString()}return t[0]=s,pe==null?void 0:pe.call(this,...t)}Z.GLTFLoader.prototype.load=We;ne("debugprogressive");function ne(t){if(typeof window>"u")return!1;const s=new URL(window.location.href).searchParams.get(t);return s==null||s==="0"||s==="false"?!1:s===""?!0:s}function ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const s=t.lastIndexOf("/");if(s>=0){const o=t.substring(0,s+1);for(;o.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return o+e}return e}let te;function Xe(){return te!==void 0||(te=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),ne("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",te)),te}const qe=typeof window>"u"&&typeof document>"u",De=Symbol("needle:raycast-mesh");function ee(t){return(t==null?void 0:t[De])instanceof g.BufferGeometry?t[De]:null}function Ke(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!ee(t)){const o=He(e);o.userData={isRaycastMesh:!0},t[De]=o}}function Ye(t=!0){if(t){if(se)return;const e=se=g.Mesh.prototype.raycast;g.Mesh.prototype.raycast=function(s,o){const i=this,r=ee(i);let n;r&&i.isMesh&&(n=i.geometry,i.geometry=r),e.call(this,s,o),n&&(i.geometry=n)}}else{if(!se)return;g.Mesh.prototype.raycast=se,se=null}}let se=null;function He(t){const e=new g.BufferGeometry;for(const s in t.attributes)e.setAttribute(s,t.getAttribute(s));return e.setIndex(t.getIndex()),e}const H=new Array,z="NEEDLE_progressive",y=ne("debugprogressive"),Me=Symbol("needle-progressive-texture"),oe=new Map,_e=new Set;if(y){let t=function(){e+=1,console.log("Toggle LOD level",e,oe),oe.forEach((i,r)=>{for(const n of i.keys){const a=r[n];if(a!=null)if(a.isBufferGeometry===!0){const c=E.getMeshLODInformation(a),l=c?Math.min(e,c.lods.length):0;r["DEBUG:LOD"]=l,c&&(s=Math.max(s,c.lods.length-1))}else r.isMaterial===!0&&(r["DEBUG:LOD"]=e)}}),e>=s&&(e=-1)},e=-1,s=2,o=!1;window.addEventListener("keyup",i=>{i.key==="p"&&t(),i.key==="w"&&(o=!o,_e&&_e.forEach(r=>{r.name!="BackgroundCubeMaterial"&&r.glyphMap==null&&"wireframe"in r&&(r.wireframe=o)}))})}function be(t,e,s){var i;if(!y)return;oe.has(t)||oe.set(t,{keys:[],sourceId:s});const o=oe.get(t);((i=o==null?void 0:o.keys)==null?void 0:i.includes(e))==!1&&o.keys.push(e)}const _=class{constructor(t,e){this.loadMesh=s=>{var i,r;if(this._isLoadingMesh)return null;const o=(r=(i=this.parser.json.meshes[s])==null?void 0:i.extensions)==null?void 0:r[z];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",s).then(n=>{var a;return this._isLoadingMesh=!1,n&&_.registerMesh(this.url,o.guid,n,(a=o.lods)==null?void 0:a.length,void 0,o),n})):null},y&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return z}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const s=this,o="LODS:minmax",i=t[o];if(i!=null)return i;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const n of t)this.getMaterialMinMaxLODsCount(n,e);return t[o]=e,e}if(y==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const n=t;for(const a of Object.keys(n.uniforms)){const c=n.uniforms[a].value;(c==null?void 0:c.isTexture)===!0&&r(c,e)}}else if(t.isMaterial)for(const n of Object.keys(t)){const a=t[n];(a==null?void 0:a.isTexture)===!0&&r(a,e)}return t[o]=e,e;function r(n,a){const c=s.getAssignedLODInformation(n);if(c){const l=s.lodInfos.get(c.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let d=0;d<l.lods.length;d++){const h=l.lods[d];h.width&&(a.lods[d]=a.lods[d]||{min_height:1/0,max_height:0},a.lods[d].min_height=Math.min(a.lods[d].min_height,h.height),a.lods[d].max_height=Math.max(a.lods[d].max_height,h.height))}}}}}static hasLODLevelAvailable(t,e){var i;if(Array.isArray(t)){for(const r of t)if(this.hasLODLevelAvailable(r,e))return!0;return!1}if(t.isMaterial===!0){for(const r of Object.keys(t)){const n=t[r];if(n&&n.isTexture&&this.hasLODLevelAvailable(n,e))return!0}return!1}else if(t.isGroup===!0){for(const r of t.children)if(r.isMesh===!0&&this.hasLODLevelAvailable(r,e))return!0}let s,o;if(t.isMesh?s=t.geometry:(t.isBufferGeometry||t.isTexture)&&(s=t),s&&(i=s==null?void 0:s.userData)!=null&&i.LODS){const r=s.userData.LODS;if(o=this.lodInfos.get(r.key),e===void 0)return o!=null;if(o)return Array.isArray(o.lods)?e<o.lods.length:e===0}return!1}static assignMeshLOD(t,e){var s;if(!t)return Promise.resolve(null);if(t instanceof g.Mesh||t.isMesh===!0){const o=t.geometry,i=this.getAssignedLODInformation(o);if(!i)return Promise.resolve(null);for(const r of H)(s=r.onBeforeGetLODMesh)==null||s.call(r,t,e);return t["LOD:requested level"]=e,_.getOrLoadLOD(o,e).then(r=>{if(Array.isArray(r)){const n=i.index||0;r=r[n]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],r&&o!=r&&((r==null?void 0:r.isBufferGeometry)?(t.geometry=r,y&&be(t,"geometry",i.url)):y&&console.error("Invalid LOD geometry",r))),r}).catch(r=>(console.error("Error loading mesh LOD",t,r),null))}else y&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const s=t;if(Array.isArray(s.material)){const o=new Array;for(const i of s.material){const r=this.assignTextureLOD(i,e);o.push(r)}return Promise.all(o).then(i=>{const r=new Array;for(const n of i)Array.isArray(n)&&r.push(...n);return r})}else return this.assignTextureLOD(s.material,e)}if(t.isMaterial===!0){const s=t,o=[],i=new Array;if(y&&_e.add(s),s.uniforms&&(s.isRawShaderMaterial||s.isShaderMaterial===!0)){const r=s;for(const n of Object.keys(r.uniforms)){const a=r.uniforms[n].value;if((a==null?void 0:a.isTexture)===!0){const c=this.assignTextureLODForSlot(a,e,s,n).then(l=>(l&&r.uniforms[n].value!=l&&(r.uniforms[n].value=l,r.uniformsNeedUpdate=!0),l));o.push(c),i.push(n)}}}else for(const r of Object.keys(s)){const n=s[r];if((n==null?void 0:n.isTexture)===!0){const a=this.assignTextureLODForSlot(n,e,s,r);o.push(a),i.push(r)}}return Promise.all(o).then(r=>{const n=new Array;for(let a=0;a<r.length;a++){const c=r[a],l=i[a];c&&c.isTexture===!0?n.push({material:s,slot:l,texture:c,level:e}):n.push({material:s,slot:l,texture:null,level:e})}return n})}if(t instanceof g.Texture||t.isTexture===!0){const s=t;return this.assignTextureLODForSlot(s,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,s,o){return(t==null?void 0:t.isTexture)!==!0?Promise.resolve(null):o==="glyphMap"?Promise.resolve(t):_.getOrLoadLOD(t,e).then(i=>{if(Array.isArray(i))return null;if((i==null?void 0:i.isTexture)===!0){if(i!=t){if(s&&o){const r=s[o];if(r&&!y){const n=this.getAssignedLODInformation(r);if(n&&(n==null?void 0:n.level)<e)return y==="verbose"&&console.warn("Assigned texture level is already higher: ",n.level,e,s,r,i),null}s[o]=i}if(y&&o&&s){const r=this.getAssignedLODInformation(t);r?be(s,o,r.url):console.warn("No LOD info for texture",t)}}return i}else y=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(i=>(console.error("Error loading LOD",t,i),null))}afterRoot(t){var e,s;return y&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((o,i)=>{var r;if(o!=null&&o.extensions){const n=o==null?void 0:o.extensions[z];if(n){if(!n.lods){y&&console.warn("Texture has no LODs",n);return}let a=!1;for(const c of this.parser.associations.keys())if(c.isTexture===!0){const l=this.parser.associations.get(c);(l==null?void 0:l.textures)===i&&(a=!0,_.registerTexture(this.url,c,(r=n.lods)==null?void 0:r.length,i,n))}a||this.parser.getDependency("texture",i).then(c=>{var l;c&&_.registerTexture(this.url,c,(l=n.lods)==null?void 0:l.length,i,n)})}}}),(s=this.parser.json.meshes)==null||s.forEach((o,i)=>{if(o!=null&&o.extensions){const r=o==null?void 0:o.extensions[z];if(r&&r.lods){for(const n of this.parser.associations.keys())if(n.isMesh){const a=this.parser.associations.get(n);(a==null?void 0:a.meshes)===i&&_.registerMesh(this.url,r.guid,n,r.lods.length,a.primitives,r)}}}}),null}static async getOrLoadLOD(t,e){var n,a,c,l;const s=y=="verbose",o=t.userData.LODS;if(!o)return null;const i=o==null?void 0:o.key;let r;if(t.isTexture===!0){const d=t;d.source&&d.source[Me]&&(r=d.source[Me])}if(r||(r=_.lodInfos.get(i)),r){if(e>0){let D=!1;const m=Array.isArray(r.lods);if(m&&e>=r.lods.length?D=!0:m||(D=!0),D)return this.lowresCache.get(i)}const d=Array.isArray(r.lods)?(n=r.lods[e])==null?void 0:n.path:r.lods;if(!d)return y&&!r["missing:uri"]&&(r["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,r)),null;const h=ze(o.url,d);if(h.endsWith(".glb")||h.endsWith(".gltf")){if(!r.guid)return console.warn("missing pointer for glb/gltf texture",r),null;const D=h+"_"+r.guid,m=this.previouslyLoaded.get(D);if(m!==void 0){s&&console.log(`LOD ${e} was already loading/loaded: ${D}`);let f=await m.catch(N=>(console.error(`Error loading LOD ${e} from ${h}
|
|
1
|
+
"use strict";const g=require("./three-ed3e16aa.light.umd.cjs"),Z=require("./three-examples-609de8cf.light.umd.cjs"),Fe="";globalThis.GLTF_PROGRESSIVE_VERSION=Fe;console.debug("[gltf-progressive] version -");let F="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",j="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ue=F,Ve=j,Pe=new URL(F+"draco_decoder.js");Pe.searchParams.append("range","true");fetch(Pe,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${F} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),F===Ue&&Ce("./include/draco/"),j===Ve&&Be("./include/ktx2/")}).finally(()=>{ke()});function Ce(t){F=t,C&&C[me]!=F?(console.debug("Updating Draco decoder path to "+t),C[me]=F,C.setDecoderPath(F),C.preload()):console.debug("Setting Draco decoder path to "+t)}function Be(t){j=t,$&&$.transcoderPath!=j?(console.debug("Updating KTX2 transcoder path to "+t),$.setTranscoderPath(j),$.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let C,de,$;function ke(){C||(C=new Z.DRACOLoader,C[me]=F,C.setDecoderPath(F),C.setDecoderConfig({type:"js"}),C.preload()),$||($=new Z.KTX2Loader,$.setTranscoderPath(j),$.init()),de||(de=Z.MeshoptDecoder)}function we(t){return ke(),t?$.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:C,ktx2Loader:$,meshoptDecoder:de}}function Oe(t){t.dracoLoader||t.setDRACOLoader(C),t.ktx2Loader||t.setKTX2Loader($),t.meshoptDecoder||t.setMeshoptDecoder(de)}const xe=new WeakMap;function Se(t,e){let s=xe.get(t);s?s=Object.assign(s,e):s=e,xe.set(t,s)}const pe=Z.GLTFLoader.prototype.load;function We(...t){const e=xe.get(this);let s=t[0];const o=new URL(s,window.location.href);if(o.hostname.endsWith("needle.tools")){const r=(e==null?void 0:e.progressive)!==void 0?e.progressive:!0,n=e!=null&&e.usecase?e.usecase:"default";r?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${n}`:this.requestHeader.Accept=`*/*;usecase=${n}`,s=o.toString()}return t[0]=s,pe==null?void 0:pe.call(this,...t)}Z.GLTFLoader.prototype.load=We;ne("debugprogressive");function ne(t){if(typeof window>"u")return!1;const s=new URL(window.location.href).searchParams.get(t);return s==null||s==="0"||s==="false"?!1:s===""?!0:s}function ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const s=t.lastIndexOf("/");if(s>=0){const o=t.substring(0,s+1);for(;o.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return o+e}return e}let te;function Xe(){return te!==void 0||(te=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),ne("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",te)),te}const qe=typeof window>"u"&&typeof document>"u",De=Symbol("needle:raycast-mesh");function ee(t){return(t==null?void 0:t[De])instanceof g.BufferGeometry?t[De]:null}function Ke(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!ee(t)){const o=He(e);o.userData={isRaycastMesh:!0},t[De]=o}}function Ye(t=!0){if(t){if(se)return;const e=se=g.Mesh.prototype.raycast;g.Mesh.prototype.raycast=function(s,o){const i=this,r=ee(i);let n;r&&i.isMesh&&(n=i.geometry,i.geometry=r),e.call(this,s,o),n&&(i.geometry=n)}}else{if(!se)return;g.Mesh.prototype.raycast=se,se=null}}let se=null;function He(t){const e=new g.BufferGeometry;for(const s in t.attributes)e.setAttribute(s,t.getAttribute(s));return e.setIndex(t.getIndex()),e}const H=new Array,z="NEEDLE_progressive",y=ne("debugprogressive"),Me=Symbol("needle-progressive-texture"),oe=new Map,_e=new Set;if(y){let t=function(){e+=1,console.log("Toggle LOD level",e,oe),oe.forEach((i,r)=>{for(const n of i.keys){const a=r[n];if(a!=null)if(a.isBufferGeometry===!0){const c=E.getMeshLODInformation(a),l=c?Math.min(e,c.lods.length):0;r["DEBUG:LOD"]=l,c&&(s=Math.max(s,c.lods.length-1))}else r.isMaterial===!0&&(r["DEBUG:LOD"]=e)}}),e>=s&&(e=-1)},e=-1,s=2,o=!1;window.addEventListener("keyup",i=>{i.key==="p"&&t(),i.key==="w"&&(o=!o,_e&&_e.forEach(r=>{r.name!="BackgroundCubeMaterial"&&r.glyphMap==null&&"wireframe"in r&&(r.wireframe=o)}))})}function be(t,e,s){var i;if(!y)return;oe.has(t)||oe.set(t,{keys:[],sourceId:s});const o=oe.get(t);((i=o==null?void 0:o.keys)==null?void 0:i.includes(e))==!1&&o.keys.push(e)}const _=class{constructor(t,e){this.loadMesh=s=>{var i,r;if(this._isLoadingMesh)return null;const o=(r=(i=this.parser.json.meshes[s])==null?void 0:i.extensions)==null?void 0:r[z];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",s).then(n=>{var a;return this._isLoadingMesh=!1,n&&_.registerMesh(this.url,o.guid,n,(a=o.lods)==null?void 0:a.length,void 0,o),n})):null},y&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return z}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const s=this,o="LODS:minmax",i=t[o];if(i!=null)return i;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const n of t)this.getMaterialMinMaxLODsCount(n,e);return t[o]=e,e}if(y==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const n=t;for(const a of Object.keys(n.uniforms)){const c=n.uniforms[a].value;(c==null?void 0:c.isTexture)===!0&&r(c,e)}}else if(t.isMaterial)for(const n of Object.keys(t)){const a=t[n];(a==null?void 0:a.isTexture)===!0&&r(a,e)}return t[o]=e,e;function r(n,a){const c=s.getAssignedLODInformation(n);if(c){const l=s.lodInfos.get(c.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let d=0;d<l.lods.length;d++){const h=l.lods[d];h.width&&(a.lods[d]=a.lods[d]||{min_height:1/0,max_height:0},a.lods[d].min_height=Math.min(a.lods[d].min_height,h.height),a.lods[d].max_height=Math.max(a.lods[d].max_height,h.height))}}}}}static hasLODLevelAvailable(t,e){var i;if(Array.isArray(t)){for(const r of t)if(this.hasLODLevelAvailable(r,e))return!0;return!1}if(t.isMaterial===!0){for(const r of Object.keys(t)){const n=t[r];if(n&&n.isTexture&&this.hasLODLevelAvailable(n,e))return!0}return!1}else if(t.isGroup===!0){for(const r of t.children)if(r.isMesh===!0&&this.hasLODLevelAvailable(r,e))return!0}let s,o;if(t.isMesh?s=t.geometry:(t.isBufferGeometry||t.isTexture)&&(s=t),s&&(i=s==null?void 0:s.userData)!=null&&i.LODS){const r=s.userData.LODS;if(o=this.lodInfos.get(r.key),e===void 0)return o!=null;if(o)return Array.isArray(o.lods)?e<o.lods.length:e===0}return!1}static assignMeshLOD(t,e){var s;if(!t)return Promise.resolve(null);if(t instanceof g.Mesh||t.isMesh===!0){const o=t.geometry,i=this.getAssignedLODInformation(o);if(!i)return Promise.resolve(null);for(const r of H)(s=r.onBeforeGetLODMesh)==null||s.call(r,t,e);return t["LOD:requested level"]=e,_.getOrLoadLOD(o,e).then(r=>{if(Array.isArray(r)){const n=i.index||0;r=r[n]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],r&&o!=r&&((r==null?void 0:r.isBufferGeometry)?(t.geometry=r,y&&be(t,"geometry",i.url)):y&&console.error("Invalid LOD geometry",r))),r}).catch(r=>(console.error("Error loading mesh LOD",t,r),null))}else y&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const s=t;if(Array.isArray(s.material)){const o=new Array;for(const i of s.material){const r=this.assignTextureLOD(i,e);o.push(r)}return Promise.all(o).then(i=>{const r=new Array;for(const n of i)Array.isArray(n)&&r.push(...n);return r})}else return this.assignTextureLOD(s.material,e)}if(t.isMaterial===!0){const s=t,o=[],i=new Array;if(y&&_e.add(s),s.uniforms&&(s.isRawShaderMaterial||s.isShaderMaterial===!0)){const r=s;for(const n of Object.keys(r.uniforms)){const a=r.uniforms[n].value;if((a==null?void 0:a.isTexture)===!0){const c=this.assignTextureLODForSlot(a,e,s,n).then(l=>(l&&r.uniforms[n].value!=l&&(r.uniforms[n].value=l,r.uniformsNeedUpdate=!0),l));o.push(c),i.push(n)}}}else for(const r of Object.keys(s)){const n=s[r];if((n==null?void 0:n.isTexture)===!0){const a=this.assignTextureLODForSlot(n,e,s,r);o.push(a),i.push(r)}}return Promise.all(o).then(r=>{const n=new Array;for(let a=0;a<r.length;a++){const c=r[a],l=i[a];c&&c.isTexture===!0?n.push({material:s,slot:l,texture:c,level:e}):n.push({material:s,slot:l,texture:null,level:e})}return n})}if(t instanceof g.Texture||t.isTexture===!0){const s=t;return this.assignTextureLODForSlot(s,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,s,o){return(t==null?void 0:t.isTexture)!==!0?Promise.resolve(null):o==="glyphMap"?Promise.resolve(t):_.getOrLoadLOD(t,e).then(i=>{if(Array.isArray(i))return null;if((i==null?void 0:i.isTexture)===!0){if(i!=t){if(s&&o){const r=s[o];if(r&&!y){const n=this.getAssignedLODInformation(r);if(n&&(n==null?void 0:n.level)<e)return y==="verbose"&&console.warn("Assigned texture level is already higher: ",n.level,e,s,r,i),null}s[o]=i}if(y&&o&&s){const r=this.getAssignedLODInformation(t);r?be(s,o,r.url):console.warn("No LOD info for texture",t)}}return i}else y=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(i=>(console.error("Error loading LOD",t,i),null))}afterRoot(t){var e,s;return y&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((o,i)=>{var r;if(o!=null&&o.extensions){const n=o==null?void 0:o.extensions[z];if(n){if(!n.lods){y&&console.warn("Texture has no LODs",n);return}let a=!1;for(const c of this.parser.associations.keys())if(c.isTexture===!0){const l=this.parser.associations.get(c);(l==null?void 0:l.textures)===i&&(a=!0,_.registerTexture(this.url,c,(r=n.lods)==null?void 0:r.length,i,n))}a||this.parser.getDependency("texture",i).then(c=>{var l;c&&_.registerTexture(this.url,c,(l=n.lods)==null?void 0:l.length,i,n)})}}}),(s=this.parser.json.meshes)==null||s.forEach((o,i)=>{if(o!=null&&o.extensions){const r=o==null?void 0:o.extensions[z];if(r&&r.lods){for(const n of this.parser.associations.keys())if(n.isMesh){const a=this.parser.associations.get(n);(a==null?void 0:a.meshes)===i&&_.registerMesh(this.url,r.guid,n,r.lods.length,a.primitives,r)}}}}),null}static async getOrLoadLOD(t,e){var n,a,c,l;const s=y=="verbose",o=t.userData.LODS;if(!o)return null;const i=o==null?void 0:o.key;let r;if(t.isTexture===!0){const d=t;d.source&&d.source[Me]&&(r=d.source[Me])}if(r||(r=_.lodInfos.get(i)),r){if(e>0){let D=!1;const m=Array.isArray(r.lods);if(m&&e>=r.lods.length?D=!0:m||(D=!0),D)return this.lowresCache.get(i)}const d=Array.isArray(r.lods)?(n=r.lods[e])==null?void 0:n.path:r.lods;if(!d)return y&&!r["missing:uri"]&&(r["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,r)),null;const h=ze(o.url,d);if(h.endsWith(".glb")||h.endsWith(".gltf")){if(!r.guid)return console.warn("missing pointer for glb/gltf texture",r),null;const D=h+"_"+r.guid,m=this.previouslyLoaded.get(D);if(m!==void 0){s&&console.log(`LOD ${e} was already loading/loaded: ${D}`);let f=await m.catch(N=>(console.error(`Error loading LOD ${e} from ${h}
|
|
2
2
|
`,N),null)),O=!1;if(f==null||(f instanceof g.Texture&&t instanceof g.Texture?(a=f.image)!=null&&a.data||(c=f.source)!=null&&c.data?f=this.copySettings(t,f):(O=!0,this.previouslyLoaded.delete(D)):f instanceof g.BufferGeometry&&t instanceof g.BufferGeometry&&((l=f.attributes.position)!=null&&l.array||(O=!0,this.previouslyLoaded.delete(D)))),!O)return f}const M=r,k=new Promise(async(f,O)=>{const N=new Z.GLTFLoader;Oe(N),y&&(await new Promise(S=>setTimeout(S,1e3)),s&&console.warn("Start loading (delayed) "+h,M.guid));let R=h;if(M&&Array.isArray(M.lods)){const S=M.lods[e];S.hash&&(R+="?v="+S.hash)}const A=await N.loadAsync(R).catch(S=>(console.error(`Error loading LOD ${e} from ${h}
|
|
3
3
|
`,S),null));if(!A)return null;const V=A.parser;s&&console.log("Loading finished "+h,M.guid);let w=0;if(A.parser.json.textures){let S=!1;for(const u of A.parser.json.textures){if(u!=null&&u.extensions){const p=u==null?void 0:u.extensions[z];if(p!=null&&p.guid&&p.guid===M.guid){S=!0;break}}w++}if(S){let u=await V.getDependency("texture",w);return u&&_.assignLODInformation(o.url,u,i,e,void 0,void 0),s&&console.log('change "'+t.name+'" → "'+u.name+'"',h,w,u,D),t instanceof g.Texture&&(u=this.copySettings(t,u)),u&&(u.guid=M.guid),f(u)}else y&&console.warn("Could not find texture with guid",M.guid,A.parser.json)}if(w=0,A.parser.json.meshes){let S=!1;for(const u of A.parser.json.meshes){if(u!=null&&u.extensions){const p=u==null?void 0:u.extensions[z];if(p!=null&&p.guid&&p.guid===M.guid){S=!0;break}}w++}if(S){const u=await V.getDependency("mesh",w),p=M;if(s&&console.log(`Loaded Mesh "${u.name}"`,h,w,u,D),u.isMesh===!0){const v=u.geometry;return _.assignLODInformation(o.url,v,i,e,void 0,p.density),f(v)}else{const v=new Array;for(let b=0;b<u.children.length;b++){const P=u.children[b];if(P.isMesh===!0){const X=P.geometry;_.assignLODInformation(o.url,X,i,e,b,p.density),v.push(X)}}return f(v)}}else y&&console.warn("Could not find mesh with guid",M.guid,A.parser.json)}return f(null)});return this.previouslyLoaded.set(D,k),await k}else if(t instanceof g.Texture){s&&console.log("Load texture from uri: "+h);const m=await new g.TextureLoader().loadAsync(h);return m?(m.guid=r.guid,m.flipY=!1,m.needsUpdate=!0,m.colorSpace=t.colorSpace,s&&console.log(r,m)):y&&console.warn("failed loading",h),m}}else y&&console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`,t.type);return null}static assignLODInformation(t,e,s,o,i,r){if(!e)return;e.userData||(e.userData={});const n=new Je(t,s,o,i,r);e.userData.LODS=n}static getAssignedLODInformation(t){var e;return((e=t==null?void 0:t.userData)==null?void 0:e.LODS)||null}static copySettings(t,e){return e?(y&&console.warn(`Copy texture settings
|
|
4
4
|
`,t.uuid,`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BufferGeometry as ae,Mesh as K,Texture as ee,TextureLoader as Ue,Vector3 as $,Matrix4 as be,Sphere as Fe,Box3 as Se,MeshStandardMaterial as ze,Clock as Ve}from"./three.light.min.js";import{DRACOLoader as qe,KTX2Loader as Xe,GLTFLoader as fe,MeshoptDecoder as Ke}from"./three-examples.light.min.js";const He="";globalThis.GLTF_PROGRESSIVE_VERSION=He,console.debug("[gltf-progressive] version -");let G="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",J="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ye=G,Je=J,Te=new URL(G+"draco_decoder.js");Te.searchParams.append("range","true"),fetch(Te,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${G} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),G===Ye&&Ee("./include/draco/"),J===Je&&Ae("./include/ktx2/")}).finally(()=>{Pe()});function Ee(t){G=t,A&&A[me]!=G?(console.debug("Updating Draco decoder path to "+t),A[me]=G,A.setDecoderPath(G),A.preload()):console.debug("Setting Draco decoder path to "+t)}function Ae(t){J=t,C&&C.transcoderPath!=J?(console.debug("Updating KTX2 transcoder path to "+t),C.setTranscoderPath(J),C.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let A,le,C;function Pe(){A||(A=new qe,A[me]=G,A.setDecoderPath(G),A.setDecoderConfig({type:"js"}),A.preload()),C||(C=new Xe,C.setTranscoderPath(J),C.init()),le||(le=Ke)}function pe(t){return Pe(),t?C.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:A,ktx2Loader:C,meshoptDecoder:le}}function ve(t){t.dracoLoader||t.setDRACOLoader(A),t.ktx2Loader||t.setKTX2Loader(C),t.meshoptDecoder||t.setMeshoptDecoder(le)}const xe=new WeakMap;function ye(t,e){let r=xe.get(t);r?r=Object.assign(r,e):r=e,xe.set(t,r)}const Be=fe.prototype.load;function Qe(...t){const e=xe.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Be?.call(this,...t)}fe.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",Le=Symbol("needle:raycast-mesh");function Q(t){return t?.[Le]instanceof ae?t[Le]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Q(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[Le]=r}}function st(t=!0){if(t){if(re)return;const e=re=K.prototype.raycast;K.prototype.raycast=function(r,n){const s=this,o=Q(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;K.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new ae;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const F=new Array,N="NEEDLE_progressive",v=te("debugprogressive"),De=Symbol("needle-progressive-texture"),se=new Map,Me=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const l=o[i];if(l!=null)if(l.isBufferGeometry===!0){const u=S.getMeshLODInformation(l),a=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=a,u&&(r=Math.max(r,u.lods.length-1))}else o.isMaterial===!0&&(o["DEBUG:LOD"]=e)}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,Me&&Me.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Ie(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const M=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[N];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var l;return this._isLoadingMesh=!1,i&&M.registerMesh(this.url,o.guid,i,(l=o.lods)==null?void 0:l.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return N}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const l of Object.keys(i.uniforms)){const u=i.uniforms[l].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const l=t[i];l?.isTexture===!0&&o(l,e)}return t[n]=e,e;function o(i,l){const u=r.getAssignedLODInformation(i);if(u){const a=r.lodInfos.get(u.key);if(a&&a.lods){l.min_count=Math.min(l.min_count,a.lods.length),l.max_count=Math.max(l.max_count,a.lods.length);for(let h=0;h<a.lods.length;h++){const g=a.lods[h];g.width&&(l.lods[h]=l.lods[h]||{min_height:1/0,max_height:0},l.lods[h].min_height=Math.min(l.lods[h].min_height,g.height),l.lods[h].max_height=Math.max(l.lods[h].max_height,g.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof K||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of F)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,M.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Ie(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&Me.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const l=o.uniforms[i].value;if(l?.isTexture===!0){const u=this.assignTextureLODForSlot(l,e,r,i).then(a=>(a&&o.uniforms[i].value!=a&&(o.uniforms[i].value=a,o.uniformsNeedUpdate=!0),a));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const l=this.assignTextureLODForSlot(i,e,r,o);n.push(l),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let l=0;l<o.length;l++){const u=o[l],a=s[l];u&&u.isTexture===!0?i.push({material:r,slot:a,texture:u,level:e}):i.push({material:r,slot:a,texture:null,level:e})}return i})}if(t instanceof ee||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):M.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o&&!v){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o?Ie(r,n,o.url):console.warn("No LOD info for texture",t)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[N];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let l=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const a=this.parser.associations.get(u);a?.textures===s&&(l=!0,M.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}l||this.parser.getDependency("texture",s).then(u=>{var a;u&&M.registerTexture(this.url,u,(a=i.lods)==null?void 0:a.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[N];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const l=this.parser.associations.get(i);l?.meshes===s&&M.registerMesh(this.url,o.guid,i,o.lods.length,l.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",l=t.userData.LODS;if(!l)return null;const u=l?.key;let a;if(t.isTexture===!0){const h=t;h.source&&h.source[De]&&(a=h.source[De])}if(a||(a=M.lodInfos.get(u)),a){if(e>0){let p=!1;const E=Array.isArray(a.lods);if(E&&e>=a.lods.length?p=!0:E||(p=!0),p)return this.lowresCache.get(u)}const h=Array.isArray(a.lods)?(r=a.lods[e])==null?void 0:r.path:a.lods;if(!h)return v&&!a["missing:uri"]&&(a["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,a)),null;const g=Ze(l.url,h);if(g.endsWith(".glb")||g.endsWith(".gltf")){if(!a.guid)return console.warn("missing pointer for glb/gltf texture",a),null;const p=g+"_"+a.guid,E=this.previouslyLoaded.get(p);if(E!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${p}`);let c=await E.catch(_=>(console.error(`Error loading LOD ${e} from ${g}
|
|
1
|
+
import{BufferGeometry as ae,Mesh as K,Texture as ee,TextureLoader as Ue,Vector3 as $,Matrix4 as be,Sphere as Fe,Box3 as Se,MeshStandardMaterial as ze,Clock as Ve}from"./three-41cc41b9.light.min.js";import{DRACOLoader as qe,KTX2Loader as Xe,GLTFLoader as fe,MeshoptDecoder as Ke}from"./three-examples-e915b453.light.min.js";const He="";globalThis.GLTF_PROGRESSIVE_VERSION=He,console.debug("[gltf-progressive] version -");let G="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",J="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ye=G,Je=J,Te=new URL(G+"draco_decoder.js");Te.searchParams.append("range","true"),fetch(Te,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${G} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),G===Ye&&Ee("./include/draco/"),J===Je&&Ae("./include/ktx2/")}).finally(()=>{Pe()});function Ee(t){G=t,A&&A[me]!=G?(console.debug("Updating Draco decoder path to "+t),A[me]=G,A.setDecoderPath(G),A.preload()):console.debug("Setting Draco decoder path to "+t)}function Ae(t){J=t,C&&C.transcoderPath!=J?(console.debug("Updating KTX2 transcoder path to "+t),C.setTranscoderPath(J),C.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let A,le,C;function Pe(){A||(A=new qe,A[me]=G,A.setDecoderPath(G),A.setDecoderConfig({type:"js"}),A.preload()),C||(C=new Xe,C.setTranscoderPath(J),C.init()),le||(le=Ke)}function pe(t){return Pe(),t?C.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:A,ktx2Loader:C,meshoptDecoder:le}}function ve(t){t.dracoLoader||t.setDRACOLoader(A),t.ktx2Loader||t.setKTX2Loader(C),t.meshoptDecoder||t.setMeshoptDecoder(le)}const xe=new WeakMap;function ye(t,e){let r=xe.get(t);r?r=Object.assign(r,e):r=e,xe.set(t,r)}const Be=fe.prototype.load;function Qe(...t){const e=xe.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Be?.call(this,...t)}fe.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",Le=Symbol("needle:raycast-mesh");function Q(t){return t?.[Le]instanceof ae?t[Le]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Q(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[Le]=r}}function st(t=!0){if(t){if(re)return;const e=re=K.prototype.raycast;K.prototype.raycast=function(r,n){const s=this,o=Q(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;K.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new ae;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const F=new Array,N="NEEDLE_progressive",v=te("debugprogressive"),De=Symbol("needle-progressive-texture"),se=new Map,Me=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const l=o[i];if(l!=null)if(l.isBufferGeometry===!0){const u=S.getMeshLODInformation(l),a=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=a,u&&(r=Math.max(r,u.lods.length-1))}else o.isMaterial===!0&&(o["DEBUG:LOD"]=e)}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,Me&&Me.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Ie(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const M=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[N];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var l;return this._isLoadingMesh=!1,i&&M.registerMesh(this.url,o.guid,i,(l=o.lods)==null?void 0:l.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return N}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const l of Object.keys(i.uniforms)){const u=i.uniforms[l].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const l=t[i];l?.isTexture===!0&&o(l,e)}return t[n]=e,e;function o(i,l){const u=r.getAssignedLODInformation(i);if(u){const a=r.lodInfos.get(u.key);if(a&&a.lods){l.min_count=Math.min(l.min_count,a.lods.length),l.max_count=Math.max(l.max_count,a.lods.length);for(let h=0;h<a.lods.length;h++){const g=a.lods[h];g.width&&(l.lods[h]=l.lods[h]||{min_height:1/0,max_height:0},l.lods[h].min_height=Math.min(l.lods[h].min_height,g.height),l.lods[h].max_height=Math.max(l.lods[h].max_height,g.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof K||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of F)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,M.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Ie(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&Me.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const l=o.uniforms[i].value;if(l?.isTexture===!0){const u=this.assignTextureLODForSlot(l,e,r,i).then(a=>(a&&o.uniforms[i].value!=a&&(o.uniforms[i].value=a,o.uniformsNeedUpdate=!0),a));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const l=this.assignTextureLODForSlot(i,e,r,o);n.push(l),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let l=0;l<o.length;l++){const u=o[l],a=s[l];u&&u.isTexture===!0?i.push({material:r,slot:a,texture:u,level:e}):i.push({material:r,slot:a,texture:null,level:e})}return i})}if(t instanceof ee||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):M.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o&&!v){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o?Ie(r,n,o.url):console.warn("No LOD info for texture",t)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[N];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let l=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const a=this.parser.associations.get(u);a?.textures===s&&(l=!0,M.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}l||this.parser.getDependency("texture",s).then(u=>{var a;u&&M.registerTexture(this.url,u,(a=i.lods)==null?void 0:a.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[N];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const l=this.parser.associations.get(i);l?.meshes===s&&M.registerMesh(this.url,o.guid,i,o.lods.length,l.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",l=t.userData.LODS;if(!l)return null;const u=l?.key;let a;if(t.isTexture===!0){const h=t;h.source&&h.source[De]&&(a=h.source[De])}if(a||(a=M.lodInfos.get(u)),a){if(e>0){let p=!1;const E=Array.isArray(a.lods);if(E&&e>=a.lods.length?p=!0:E||(p=!0),p)return this.lowresCache.get(u)}const h=Array.isArray(a.lods)?(r=a.lods[e])==null?void 0:r.path:a.lods;if(!h)return v&&!a["missing:uri"]&&(a["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,a)),null;const g=Ze(l.url,h);if(g.endsWith(".glb")||g.endsWith(".gltf")){if(!a.guid)return console.warn("missing pointer for glb/gltf texture",a),null;const p=g+"_"+a.guid,E=this.previouslyLoaded.get(p);if(E!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${p}`);let c=await E.catch(_=>(console.error(`Error loading LOD ${e} from ${g}
|
|
2
2
|
`,_),null)),w=!1;if(c==null||(c instanceof ee&&t instanceof ee?(n=c.image)!=null&&n.data||(s=c.source)!=null&&s.data?c=this.copySettings(t,c):(w=!0,this.previouslyLoaded.delete(p)):c instanceof ae&&t instanceof ae&&((o=c.attributes.position)!=null&&o.array||(w=!0,this.previouslyLoaded.delete(p)))),!w)return c}const D=a,x=new Promise(async(c,w)=>{const _=new fe;ve(_),v&&(await new Promise(m=>setTimeout(m,1e3)),i&&console.warn("Start loading (delayed) "+g,D.guid));let B=g;if(D&&Array.isArray(D.lods)){const m=D.lods[e];m.hash&&(B+="?v="+m.hash)}const O=await _.loadAsync(B).catch(m=>(console.error(`Error loading LOD ${e} from ${g}
|
|
3
3
|
`,m),null));if(!O)return null;const I=O.parser;i&&console.log("Loading finished "+g,D.guid);let f=0;if(O.parser.json.textures){let m=!1;for(const d of O.parser.json.textures){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}f++}if(m){let d=await I.getDependency("texture",f);return d&&M.assignLODInformation(l.url,d,u,e,void 0,void 0),i&&console.log('change "'+t.name+'" \u2192 "'+d.name+'"',g,f,d,p),t instanceof ee&&(d=this.copySettings(t,d)),d&&(d.guid=D.guid),c(d)}else v&&console.warn("Could not find texture with guid",D.guid,O.parser.json)}if(f=0,O.parser.json.meshes){let m=!1;for(const d of O.parser.json.meshes){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}f++}if(m){const d=await I.getDependency("mesh",f),L=D;if(i&&console.log(`Loaded Mesh "${d.name}"`,g,f,d,p),d.isMesh===!0){const b=d.geometry;return M.assignLODInformation(l.url,b,u,e,void 0,L.density),c(b)}else{const b=new Array;for(let j=0;j<d.children.length;j++){const X=d.children[j];if(X.isMesh===!0){const Y=X.geometry;M.assignLODInformation(l.url,Y,u,e,j,L.density),b.push(Y)}}return c(b)}}else v&&console.warn("Could not find mesh with guid",D.guid,O.parser.json)}return c(null)});return this.previouslyLoaded.set(p,x),await x}else if(t instanceof ee){i&&console.log("Load texture from uri: "+g);const p=await new Ue().loadAsync(g);return p?(p.guid=a.guid,p.flipY=!1,p.needsUpdate=!0,p.colorSpace=t.colorSpace,i&&console.log(a,p)):v&&console.warn("failed loading",g),p}}else v&&console.warn(`Can not load LOD ${e}: no LOD info found for "${u}" ${t.name}`,t.type);return null}static assignLODInformation(t,e,r,n,s,o){if(!e)return;e.userData||(e.userData={});const i=new nt(t,r,n,s,o);e.userData.LODS=i}static getAssignedLODInformation(t){var e;return((e=t?.userData)==null?void 0:e.LODS)||null}static copySettings(t,e){return e?(v&&console.warn(`Copy texture settings
|
|
4
4
|
`,t.uuid,`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BufferGeometry as ae,Mesh as K,Texture as ee,TextureLoader as Ue,Vector3 as $,Matrix4 as be,Sphere as Fe,Box3 as Se,MeshStandardMaterial as ze,Clock as Ve}from"./three.min.js";import{DRACOLoader as qe,KTX2Loader as Xe,GLTFLoader as fe,MeshoptDecoder as Ke}from"./three-examples.min.js";const He="";globalThis.GLTF_PROGRESSIVE_VERSION=He,console.debug("[gltf-progressive] version -");let G="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",J="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ye=G,Je=J,Te=new URL(G+"draco_decoder.js");Te.searchParams.append("range","true"),fetch(Te,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${G} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),G===Ye&&Ee("./include/draco/"),J===Je&&Ae("./include/ktx2/")}).finally(()=>{Pe()});function Ee(t){G=t,A&&A[me]!=G?(console.debug("Updating Draco decoder path to "+t),A[me]=G,A.setDecoderPath(G),A.preload()):console.debug("Setting Draco decoder path to "+t)}function Ae(t){J=t,C&&C.transcoderPath!=J?(console.debug("Updating KTX2 transcoder path to "+t),C.setTranscoderPath(J),C.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let A,le,C;function Pe(){A||(A=new qe,A[me]=G,A.setDecoderPath(G),A.setDecoderConfig({type:"js"}),A.preload()),C||(C=new Xe,C.setTranscoderPath(J),C.init()),le||(le=Ke)}function pe(t){return Pe(),t?C.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:A,ktx2Loader:C,meshoptDecoder:le}}function ve(t){t.dracoLoader||t.setDRACOLoader(A),t.ktx2Loader||t.setKTX2Loader(C),t.meshoptDecoder||t.setMeshoptDecoder(le)}const xe=new WeakMap;function ye(t,e){let r=xe.get(t);r?r=Object.assign(r,e):r=e,xe.set(t,r)}const Be=fe.prototype.load;function Qe(...t){const e=xe.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Be?.call(this,...t)}fe.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",Le=Symbol("needle:raycast-mesh");function Q(t){return t?.[Le]instanceof ae?t[Le]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Q(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[Le]=r}}function st(t=!0){if(t){if(re)return;const e=re=K.prototype.raycast;K.prototype.raycast=function(r,n){const s=this,o=Q(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;K.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new ae;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const F=new Array,N="NEEDLE_progressive",v=te("debugprogressive"),De=Symbol("needle-progressive-texture"),se=new Map,Me=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const l=o[i];if(l!=null)if(l.isBufferGeometry===!0){const u=S.getMeshLODInformation(l),a=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=a,u&&(r=Math.max(r,u.lods.length-1))}else o.isMaterial===!0&&(o["DEBUG:LOD"]=e)}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,Me&&Me.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Ie(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const M=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[N];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var l;return this._isLoadingMesh=!1,i&&M.registerMesh(this.url,o.guid,i,(l=o.lods)==null?void 0:l.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return N}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const l of Object.keys(i.uniforms)){const u=i.uniforms[l].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const l=t[i];l?.isTexture===!0&&o(l,e)}return t[n]=e,e;function o(i,l){const u=r.getAssignedLODInformation(i);if(u){const a=r.lodInfos.get(u.key);if(a&&a.lods){l.min_count=Math.min(l.min_count,a.lods.length),l.max_count=Math.max(l.max_count,a.lods.length);for(let h=0;h<a.lods.length;h++){const g=a.lods[h];g.width&&(l.lods[h]=l.lods[h]||{min_height:1/0,max_height:0},l.lods[h].min_height=Math.min(l.lods[h].min_height,g.height),l.lods[h].max_height=Math.max(l.lods[h].max_height,g.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof K||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of F)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,M.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Ie(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&Me.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const l=o.uniforms[i].value;if(l?.isTexture===!0){const u=this.assignTextureLODForSlot(l,e,r,i).then(a=>(a&&o.uniforms[i].value!=a&&(o.uniforms[i].value=a,o.uniformsNeedUpdate=!0),a));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const l=this.assignTextureLODForSlot(i,e,r,o);n.push(l),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let l=0;l<o.length;l++){const u=o[l],a=s[l];u&&u.isTexture===!0?i.push({material:r,slot:a,texture:u,level:e}):i.push({material:r,slot:a,texture:null,level:e})}return i})}if(t instanceof ee||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):M.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o&&!v){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o?Ie(r,n,o.url):console.warn("No LOD info for texture",t)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[N];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let l=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const a=this.parser.associations.get(u);a?.textures===s&&(l=!0,M.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}l||this.parser.getDependency("texture",s).then(u=>{var a;u&&M.registerTexture(this.url,u,(a=i.lods)==null?void 0:a.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[N];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const l=this.parser.associations.get(i);l?.meshes===s&&M.registerMesh(this.url,o.guid,i,o.lods.length,l.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",l=t.userData.LODS;if(!l)return null;const u=l?.key;let a;if(t.isTexture===!0){const h=t;h.source&&h.source[De]&&(a=h.source[De])}if(a||(a=M.lodInfos.get(u)),a){if(e>0){let p=!1;const E=Array.isArray(a.lods);if(E&&e>=a.lods.length?p=!0:E||(p=!0),p)return this.lowresCache.get(u)}const h=Array.isArray(a.lods)?(r=a.lods[e])==null?void 0:r.path:a.lods;if(!h)return v&&!a["missing:uri"]&&(a["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,a)),null;const g=Ze(l.url,h);if(g.endsWith(".glb")||g.endsWith(".gltf")){if(!a.guid)return console.warn("missing pointer for glb/gltf texture",a),null;const p=g+"_"+a.guid,E=this.previouslyLoaded.get(p);if(E!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${p}`);let c=await E.catch(_=>(console.error(`Error loading LOD ${e} from ${g}
|
|
1
|
+
import{BufferGeometry as ae,Mesh as K,Texture as ee,TextureLoader as Ue,Vector3 as $,Matrix4 as be,Sphere as Fe,Box3 as Se,MeshStandardMaterial as ze,Clock as Ve}from"./three-41cc41b9.min.js";import{DRACOLoader as qe,KTX2Loader as Xe,GLTFLoader as fe,MeshoptDecoder as Ke}from"./three-examples-84a86d3a.min.js";const He="";globalThis.GLTF_PROGRESSIVE_VERSION=He,console.debug("[gltf-progressive] version -");let G="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",J="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const Ye=G,Je=J,Te=new URL(G+"draco_decoder.js");Te.searchParams.append("range","true"),fetch(Te,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{console.debug(`Failed to fetch remote Draco decoder from ${G} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),G===Ye&&Ee("./include/draco/"),J===Je&&Ae("./include/ktx2/")}).finally(()=>{Pe()});function Ee(t){G=t,A&&A[me]!=G?(console.debug("Updating Draco decoder path to "+t),A[me]=G,A.setDecoderPath(G),A.preload()):console.debug("Setting Draco decoder path to "+t)}function Ae(t){J=t,C&&C.transcoderPath!=J?(console.debug("Updating KTX2 transcoder path to "+t),C.setTranscoderPath(J),C.init()):console.debug("Setting KTX2 transcoder path to "+t)}const me=Symbol("dracoDecoderPath");let A,le,C;function Pe(){A||(A=new qe,A[me]=G,A.setDecoderPath(G),A.setDecoderConfig({type:"js"}),A.preload()),C||(C=new Xe,C.setTranscoderPath(J),C.init()),le||(le=Ke)}function pe(t){return Pe(),t?C.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:A,ktx2Loader:C,meshoptDecoder:le}}function ve(t){t.dracoLoader||t.setDRACOLoader(A),t.ktx2Loader||t.setKTX2Loader(C),t.meshoptDecoder||t.setMeshoptDecoder(le)}const xe=new WeakMap;function ye(t,e){let r=xe.get(t);r?r=Object.assign(r,e):r=e,xe.set(t,r)}const Be=fe.prototype.load;function Qe(...t){const e=xe.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Be?.call(this,...t)}fe.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",Le=Symbol("needle:raycast-mesh");function Q(t){return t?.[Le]instanceof ae?t[Le]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Q(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[Le]=r}}function st(t=!0){if(t){if(re)return;const e=re=K.prototype.raycast;K.prototype.raycast=function(r,n){const s=this,o=Q(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;K.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new ae;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const F=new Array,N="NEEDLE_progressive",v=te("debugprogressive"),De=Symbol("needle-progressive-texture"),se=new Map,Me=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const l=o[i];if(l!=null)if(l.isBufferGeometry===!0){const u=S.getMeshLODInformation(l),a=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=a,u&&(r=Math.max(r,u.lods.length-1))}else o.isMaterial===!0&&(o["DEBUG:LOD"]=e)}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,Me&&Me.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Ie(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const M=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[N];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var l;return this._isLoadingMesh=!1,i&&M.registerMesh(this.url,o.guid,i,(l=o.lods)==null?void 0:l.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return N}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const l of Object.keys(i.uniforms)){const u=i.uniforms[l].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const l=t[i];l?.isTexture===!0&&o(l,e)}return t[n]=e,e;function o(i,l){const u=r.getAssignedLODInformation(i);if(u){const a=r.lodInfos.get(u.key);if(a&&a.lods){l.min_count=Math.min(l.min_count,a.lods.length),l.max_count=Math.max(l.max_count,a.lods.length);for(let h=0;h<a.lods.length;h++){const g=a.lods[h];g.width&&(l.lods[h]=l.lods[h]||{min_height:1/0,max_height:0},l.lods[h].min_height=Math.min(l.lods[h].min_height,g.height),l.lods[h].max_height=Math.max(l.lods[h].max_height,g.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof K||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of F)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,M.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Ie(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&Me.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const l=o.uniforms[i].value;if(l?.isTexture===!0){const u=this.assignTextureLODForSlot(l,e,r,i).then(a=>(a&&o.uniforms[i].value!=a&&(o.uniforms[i].value=a,o.uniformsNeedUpdate=!0),a));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const l=this.assignTextureLODForSlot(i,e,r,o);n.push(l),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let l=0;l<o.length;l++){const u=o[l],a=s[l];u&&u.isTexture===!0?i.push({material:r,slot:a,texture:u,level:e}):i.push({material:r,slot:a,texture:null,level:e})}return i})}if(t instanceof ee||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):M.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o&&!v){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o?Ie(r,n,o.url):console.warn("No LOD info for texture",t)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[N];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let l=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const a=this.parser.associations.get(u);a?.textures===s&&(l=!0,M.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}l||this.parser.getDependency("texture",s).then(u=>{var a;u&&M.registerTexture(this.url,u,(a=i.lods)==null?void 0:a.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[N];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const l=this.parser.associations.get(i);l?.meshes===s&&M.registerMesh(this.url,o.guid,i,o.lods.length,l.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",l=t.userData.LODS;if(!l)return null;const u=l?.key;let a;if(t.isTexture===!0){const h=t;h.source&&h.source[De]&&(a=h.source[De])}if(a||(a=M.lodInfos.get(u)),a){if(e>0){let p=!1;const E=Array.isArray(a.lods);if(E&&e>=a.lods.length?p=!0:E||(p=!0),p)return this.lowresCache.get(u)}const h=Array.isArray(a.lods)?(r=a.lods[e])==null?void 0:r.path:a.lods;if(!h)return v&&!a["missing:uri"]&&(a["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,a)),null;const g=Ze(l.url,h);if(g.endsWith(".glb")||g.endsWith(".gltf")){if(!a.guid)return console.warn("missing pointer for glb/gltf texture",a),null;const p=g+"_"+a.guid,E=this.previouslyLoaded.get(p);if(E!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${p}`);let c=await E.catch(_=>(console.error(`Error loading LOD ${e} from ${g}
|
|
2
2
|
`,_),null)),w=!1;if(c==null||(c instanceof ee&&t instanceof ee?(n=c.image)!=null&&n.data||(s=c.source)!=null&&s.data?c=this.copySettings(t,c):(w=!0,this.previouslyLoaded.delete(p)):c instanceof ae&&t instanceof ae&&((o=c.attributes.position)!=null&&o.array||(w=!0,this.previouslyLoaded.delete(p)))),!w)return c}const D=a,x=new Promise(async(c,w)=>{const _=new fe;ve(_),v&&(await new Promise(m=>setTimeout(m,1e3)),i&&console.warn("Start loading (delayed) "+g,D.guid));let B=g;if(D&&Array.isArray(D.lods)){const m=D.lods[e];m.hash&&(B+="?v="+m.hash)}const O=await _.loadAsync(B).catch(m=>(console.error(`Error loading LOD ${e} from ${g}
|
|
3
3
|
`,m),null));if(!O)return null;const I=O.parser;i&&console.log("Loading finished "+g,D.guid);let f=0;if(O.parser.json.textures){let m=!1;for(const d of O.parser.json.textures){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}f++}if(m){let d=await I.getDependency("texture",f);return d&&M.assignLODInformation(l.url,d,u,e,void 0,void 0),i&&console.log('change "'+t.name+'" \u2192 "'+d.name+'"',g,f,d,p),t instanceof ee&&(d=this.copySettings(t,d)),d&&(d.guid=D.guid),c(d)}else v&&console.warn("Could not find texture with guid",D.guid,O.parser.json)}if(f=0,O.parser.json.meshes){let m=!1;for(const d of O.parser.json.meshes){if(d!=null&&d.extensions){const L=d?.extensions[N];if(L!=null&&L.guid&&L.guid===D.guid){m=!0;break}}f++}if(m){const d=await I.getDependency("mesh",f),L=D;if(i&&console.log(`Loaded Mesh "${d.name}"`,g,f,d,p),d.isMesh===!0){const b=d.geometry;return M.assignLODInformation(l.url,b,u,e,void 0,L.density),c(b)}else{const b=new Array;for(let j=0;j<d.children.length;j++){const X=d.children[j];if(X.isMesh===!0){const Y=X.geometry;M.assignLODInformation(l.url,Y,u,e,j,L.density),b.push(Y)}}return c(b)}}else v&&console.warn("Could not find mesh with guid",D.guid,O.parser.json)}return c(null)});return this.previouslyLoaded.set(p,x),await x}else if(t instanceof ee){i&&console.log("Load texture from uri: "+g);const p=await new Ue().loadAsync(g);return p?(p.guid=a.guid,p.flipY=!1,p.needsUpdate=!0,p.colorSpace=t.colorSpace,i&&console.log(a,p)):v&&console.warn("failed loading",g),p}}else v&&console.warn(`Can not load LOD ${e}: no LOD info found for "${u}" ${t.name}`,t.type);return null}static assignLODInformation(t,e,r,n,s,o){if(!e)return;e.userData||(e.userData={});const i=new nt(t,r,n,s,o);e.userData.LODS=i}static getAssignedLODInformation(t){var e;return((e=t?.userData)==null?void 0:e.LODS)||null}static copySettings(t,e){return e?(v&&console.warn(`Copy texture settings
|
|
4
4
|
`,t.uuid,`
|