@needle-tools/engine 4.4.4 → 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 +5 -2
- package/dist/generateMeshBVH.worker-2bb9524d.js +25 -0
- package/dist/{gltf-progressive.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.light.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} +1927 -1927
- package/dist/{needle-engine.bundle.min.js → needle-engine.bundle-71861947.min.js} +87 -87
- package/dist/{needle-engine.bundle.umd.cjs → needle-engine.bundle-73459623.umd.cjs} +119 -119
- package/dist/{needle-engine.bundle.light.min.js → needle-engine.bundle-9def7e8b.light.min.js} +87 -87
- package/dist/{needle-engine.bundle.light.js → needle-engine.bundle-ad489836.light.js} +1919 -1919
- package/dist/{needle-engine.bundle.light.umd.cjs → needle-engine.bundle-cb5d2462.light.umd.cjs} +119 -119
- 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.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.light.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.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.light.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/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +4 -4
- package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_networking.ts +13 -2
- package/src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +4 -4
- /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
|
@@ -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-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.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-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,`
|