@needle-tools/engine 4.8.0-next.9de3f45 → 4.8.0-next.d716e0e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/gltf-progressive-VTcU5sMu.min.js +8 -0
  2. package/dist/gltf-progressive-VXeY4K8o.js +1370 -0
  3. package/dist/gltf-progressive-_-uQwSK8.umd.cjs +8 -0
  4. package/dist/loader.worker-D5fjeWJO.js +27 -0
  5. package/dist/needle-engine.bundle-BYz57wrx.umd.cjs +1607 -0
  6. package/dist/needle-engine.bundle-CxDqrXwR.min.js +1607 -0
  7. package/dist/needle-engine.bundle-DNnYQtTS.js +42600 -0
  8. package/dist/needle-engine.d.ts +15 -15
  9. package/dist/needle-engine.js +591 -592
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/dist/{postprocessing-BzY0H7ry.min.js → postprocessing-ChsrvDkI.min.js} +54 -54
  13. package/dist/{postprocessing-vKBVFpSz.js → postprocessing-DElbMQgB.js} +479 -483
  14. package/dist/{postprocessing-Dw2OCMp4.umd.cjs → postprocessing-DtxaELce.umd.cjs} +66 -66
  15. package/dist/{three-examples-DUcCNw9s.umd.cjs → three-examples-BhQvv1B9.umd.cjs} +11 -11
  16. package/dist/{three-examples-tvuhV8Ne.js → three-examples-CM6Iip03.js} +23 -27
  17. package/dist/{three-examples-BMOhDaYR.min.js → three-examples-D2zemuAM.min.js} +12 -12
  18. package/dist/{three-mesh-ui-CxuWt7m-.js → three-mesh-ui-D6Mz5Yl7.js} +799 -810
  19. package/dist/three-mesh-ui-DWcMuyQ_.min.js +406 -0
  20. package/dist/three-mesh-ui-tt0buEDC.umd.cjs +406 -0
  21. package/dist/{vendor-BmYIgaS1.js → vendor-ClB-U1Hn.js} +10 -10
  22. package/dist/{vendor-Cavtu3CP.umd.cjs → vendor-bOWOWClg.umd.cjs} +1 -1
  23. package/package.json +3 -3
  24. package/plugins/vite/dependencies.js +28 -19
  25. package/plugins/vite/dependency-watcher.js +6 -1
  26. package/dist/gltf-progressive-Bz6FXMZ1.min.js +0 -8
  27. package/dist/gltf-progressive-DAdiYt1v.js +0 -1392
  28. package/dist/gltf-progressive-D_S7mZaT.umd.cjs +0 -8
  29. package/dist/loader.worker-qHzhYKEC.js +0 -1
  30. package/dist/needle-engine.bundle-C5vAAuK3.js +0 -43849
  31. package/dist/needle-engine.bundle-fg0LG9Pa.umd.cjs +0 -1607
  32. package/dist/needle-engine.bundle-tepIih-J.min.js +0 -1607
  33. package/dist/three-mesh-ui-B3p3gyUz.min.js +0 -406
  34. package/dist/three-mesh-ui-CQiIQIlA.umd.cjs +0 -406
@@ -1,8 +0,0 @@
1
- "use strict";var et=Object.defineProperty;var Ge=o=>{throw TypeError(o)};var tt=(o,e,t)=>e in o?et(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var u=(o,e,t)=>tt(o,typeof e!="symbol"?e+"":e,t),Ee=(o,e,t)=>e.has(o)||Ge("Cannot "+t);var S=(o,e,t)=>(Ee(o,e,"read from private field"),t?t.call(o):e.get(o)),j=(o,e,t)=>e.has(o)?Ge("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(o):e.set(o,t),K=(o,e,t,r)=>(Ee(o,e,"write to private field"),r?r.call(o,t):e.set(o,t),t);const g=require("./three-B_hneGZr.umd.cjs"),ne=require("./three-examples-DUcCNw9s.umd.cjs");var ve=typeof document<"u"?document.currentScript:null;const ze="3.1.1";globalThis.GLTF_PROGRESSIVE_VERSION=ze;console.debug(`[gltf-progressive] version ${ze}`);let z="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",re="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const rt=z,st=re,Ve=new URL(z+"draco_decoder.js");Ve.searchParams.append("range","true");fetch(Ve,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(o=>{console.debug(`Failed to fetch remote Draco decoder from ${z} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),z===rt&&qe("./include/draco/"),re===st&&Ke("./include/ktx2/")}).finally(()=>{Xe()});const nt=()=>({dracoDecoderPath:z,ktx2TranscoderPath:re});function qe(o){z=o,F&&F[Ce]!=z?(console.debug("Updating Draco decoder path to "+o),F[Ce]=z,F.setDecoderPath(z),F.preload()):console.debug("Setting Draco decoder path to "+o)}function Ke(o){re=o,V&&V.transcoderPath!=re?(console.debug("Updating KTX2 transcoder path to "+o),V.setTranscoderPath(re),V.init()):console.debug("Setting KTX2 transcoder path to "+o)}function Me(o){return Xe(),o?V.detectSupport(o):o!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:F,ktx2Loader:V,meshoptDecoder:we}}function Be(o){o.dracoLoader||o.setDRACOLoader(F),o.ktx2Loader||o.setKTX2Loader(V),o.meshoptDecoder||o.setMeshoptDecoder(we)}const Ce=Symbol("dracoDecoderPath");let F,we,V;function Xe(){F||(F=new ne.DRACOLoader,F[Ce]=z,F.setDecoderPath(z),F.setDecoderConfig({type:"js"}),F.preload()),V||(V=new ne.KTX2Loader,V.setTranscoderPath(re),V.init()),we||(we=ne.MeshoptDecoder)}const ke=new WeakMap;function Re(o,e){let t=ke.get(o);t?t=Object.assign(t,e):t=e,ke.set(o,t)}const Oe=ne.GLTFLoader.prototype.load;function it(...o){const e=ke.get(this);let t=o[0];const r=new URL(t,window.location.href);if(r.hostname.endsWith("needle.tools")){const s=(e==null?void 0:e.progressive)!==void 0?e.progressive:!0,i=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${i}`:this.requestHeader.Accept=`*/*;usecase=${i}`,t=r.toString()}return o[0]=t,Oe==null?void 0:Oe.call(this,...o)}ne.GLTFLoader.prototype.load=it;se("debugprogressive");function se(o){if(typeof window>"u")return!1;const t=new URL(window.location.href).searchParams.get(o);return t==null||t==="0"||t==="false"?!1:t===""?!0:t}function ot(o,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||o===void 0)return e;const t=o.lastIndexOf("/");if(t>=0){const r=o.substring(0,t+1);for(;r.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return r+e}return e}let le;function Ye(){return le!==void 0||(le=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),se("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",le)),le}function Fe(){if(typeof window>"u")return!1;const o=new URL(window.location.href),e=o.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(o.hostname);return o.hostname==="127.0.0.1"||e}class at{constructor(e=100,t={}){u(this,"maxConcurrent");u(this,"_running",new Map);u(this,"_queue",[]);u(this,"debug",!1);u(this,"tick",()=>{this.internalUpdate(),setTimeout(this.tick,10)});this.maxConcurrent=e,this.debug=t.debug??!1,window.requestAnimationFrame(this.tick)}slot(e){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${e}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(t=>{this._queue.push({key:e,resolve:t})})}add(e,t){this._running.has(e)||(this._running.set(e,t),t.finally(()=>{this._running.delete(e),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${e})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${e})`))}internalUpdate(){const e=this.maxConcurrent-this._running.size;for(let t=0;t<e&&this._queue.length>0;t++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:r,resolve:n}=this._queue.shift();n({use:s=>this.add(r,s)})}}}const lt=typeof window>"u"&&typeof document>"u",Ie=Symbol("needle:raycast-mesh");function oe(o){return(o==null?void 0:o[Ie])instanceof g.BufferGeometry?o[Ie]:null}function ut(o,e){if((o.type==="Mesh"||o.type==="SkinnedMesh")&&!oe(o)){const r=ct(e);r.userData={isRaycastMesh:!0},o[Ie]=r}}function dt(o=!0){if(o){if(ue)return;const e=ue=g.Mesh.prototype.raycast;g.Mesh.prototype.raycast=function(t,r){const n=this,s=oe(n);let i;s&&n.isMesh&&(i=n.geometry,n.geometry=s),e.call(this,t,r),i&&(n.geometry=i)}}else{if(!ue)return;g.Mesh.prototype.raycast=ue,ue=null}}let ue=null;function ct(o){const e=new g.BufferGeometry;for(const t in o.attributes)e.setAttribute(t,o.getAttribute(t));return e.setIndex(o.getIndex()),e}const J=new Array,w=se("debugprogressive");let ye,te=-1;if(w){let e=function(){te+=1,te>=o&&(te=-1),console.log(`Toggle LOD level [${te}]`)},o=6;window.addEventListener("keyup",t=>{t.key==="p"&&e(),t.key==="w"&&(ye=!ye,console.log(`Toggle wireframe [${ye}]`));const r=parseInt(t.key);!isNaN(r)&&r>=0&&(te=r,console.log(`Set LOD level to [${te}]`))})}function He(o){if(w)if(Array.isArray(o))for(const e of o)He(e);else o&&"wireframe"in o&&(o.wireframe=ye===!0)}const de=new Array;let ft=0;const ht=Ye()?2:10;function gt(o){if(de.length<ht){const r=de.length;w&&console.warn(`[Worker] Creating new worker #${r}`);const n=$e.createWorker(o||{});return de.push(n),n}const e=ft++%de.length;return de[e]}class $e{constructor(e,t){u(this,"worker");u(this,"_running",[]);u(this,"_webglRenderer",null);u(this,"_debug",!1);this.worker=e,this._debug=t.debug??!1,e.onmessage=r=>{const n=r.data;switch(this._debug&&console.log("[Worker] EVENT",n),n.type){case"loaded-gltf":for(const s of this._running)if(s.url===n.result.url){pt(n.result),s.resolve(n.result);const i=s.url;i.startsWith("blob:")&&URL.revokeObjectURL(i)}}},e.onerror=r=>{console.error("[Worker] Error in gltf-progressive worker:",r)},e.postMessage({type:"init"})}static async createWorker(e){const t=new Worker(new URL("/loader.worker-qHzhYKEC.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:ve&&ve.tagName.toUpperCase()==="SCRIPT"&&ve.src||new URL("gltf-progressive-D_S7mZaT.umd.cjs",document.baseURI).href),{type:"module"});return new $e(t,e)}async load(e,t){const r=nt();let n=t==null?void 0:t.renderer;n||(this._webglRenderer??(this._webglRenderer=(async()=>{const{WebGLRenderer:d}=await Promise.resolve().then(()=>require("./three-B_hneGZr.umd.cjs")).then(f=>f.THREE);return new d})()),n=await this._webglRenderer);const a=Me(n).ktx2Loader.workerConfig;e instanceof URL?e=e.toString():e.startsWith("file:")?e=URL.createObjectURL(new Blob([e])):!e.startsWith("blob:")&&!e.startsWith("http:")&&!e.startsWith("https:")&&(e=new URL(e,window.location.href).toString());const l={type:"load",url:e,dracoDecoderPath:r.dracoDecoderPath,ktx2TranscoderPath:r.ktx2TranscoderPath,ktx2LoaderConfig:a};return this._debug&&console.debug("[Worker] Sending load request",l),this.worker.postMessage(l),new Promise(d=>{this._running.push({url:e.toString(),resolve:d})})}}function pt(o){var e,t,r,n,s,i,a,l,d,f,y,b,L,P,v,B;for(const T of o.geometries){const c=T.geometry,O=new g.BufferGeometry;if(O.name=c.name||"",c.index){const h=c.index;O.setIndex(Se(h))}for(const h in c.attributes){const _=c.attributes[h],C=Se(_);O.setAttribute(h,C)}if(c.morphAttributes)for(const h in c.morphAttributes){const C=c.morphAttributes[h].map(U=>Se(U));O.morphAttributes[h]=C}if(O.morphTargetsRelative=c.morphTargetsRelative??!1,O.boundingBox=new g.Box3,O.boundingBox.min=new g.Vector3((e=c.boundingBox)==null?void 0:e.min.x,(t=c.boundingBox)==null?void 0:t.min.y,(r=c.boundingBox)==null?void 0:r.min.z),O.boundingBox.max=new g.Vector3((n=c.boundingBox)==null?void 0:n.max.x,(s=c.boundingBox)==null?void 0:s.max.y,(i=c.boundingBox)==null?void 0:i.max.z),O.boundingSphere=new g.Sphere(new g.Vector3((a=c.boundingSphere)==null?void 0:a.center.x,(l=c.boundingSphere)==null?void 0:l.center.y,(d=c.boundingSphere)==null?void 0:d.center.z),(f=c.boundingSphere)==null?void 0:f.radius),c.groups)for(const h of c.groups)O.addGroup(h.start,h.count,h.materialIndex);c.userData&&(O.userData=c.userData),T.geometry=O}for(const T of o.textures){const c=T.texture;let O=null;if(c.isCompressedTexture){const h=c.mipmaps,_=((y=c.image)==null?void 0:y.width)||((L=(b=c.source)==null?void 0:b.data)==null?void 0:L.width)||-1,C=((P=c.image)==null?void 0:P.height)||((B=(v=c.source)==null?void 0:v.data)==null?void 0:B.height)||-1;O=new g.CompressedTexture(h,_,C,c.format,c.type,c.mapping,c.wrapS,c.wrapT,c.magFilter,c.minFilter,c.anisotropy,c.colorSpace)}else O=new g.Texture(c.image,c.mapping,c.wrapS,c.wrapT,c.magFilter,c.minFilter,c.format,c.type,c.anisotropy,c.colorSpace),O.mipmaps=c.mipmaps,O.channel=c.channel,O.source.data=c.source.data,O.flipY=c.flipY,O.premultiplyAlpha=c.premultiplyAlpha,O.unpackAlignment=c.unpackAlignment,O.matrix=new g.Matrix3(...c.matrix.elements);if(!O){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}T.texture=O}return o}function Se(o){let e=o;if("isInterleavedBufferAttribute"in o&&o.isInterleavedBufferAttribute){const t=o.data,r=t.array,n=new g.InterleavedBuffer(r,t.stride);e=new g.InterleavedBufferAttribute(n,o.itemSize,r.byteOffset,o.normalized),e.offset=o.offset}else"isBufferAttribute"in o&&o.isBufferAttribute&&(e=new g.BufferAttribute(o.array,o.itemSize,o.normalized),e.usage=o.usage,e.gpuType=o.gpuType,e.updateRanges=o.updateRanges);return e}const mt=se("gltf-progressive-worker"),yt=se("gltf-progressive-reduce-mipmaps"),Te=Symbol("needle-progressive-texture"),X="NEEDLE_progressive",M=class M{constructor(e,t){u(this,"parser");u(this,"url");u(this,"_isLoadingMesh");u(this,"loadMesh",e=>{var r,n;if(this._isLoadingMesh)return null;const t=(n=(r=this.parser.json.meshes[e])==null?void 0:r.extensions)==null?void 0:n[X];return t?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",e).then(s=>{var i;return this._isLoadingMesh=!1,s&&M.registerMesh(this.url,t.guid,s,(i=t.lods)==null?void 0:i.length,0,t),s})):null});w&&console.log("Progressive extension registered for",t),this.parser=e,this.url=t}get name(){return X}static getMeshLODExtension(e){const t=this.getAssignedLODInformation(e);return t!=null&&t.key?this.lodInfos.get(t.key):null}static getPrimitiveIndex(e){var r;const t=(r=this.getAssignedLODInformation(e))==null?void 0:r.index;return t??-1}static getMaterialMinMaxLODsCount(e,t){const r=this,n="LODS:minmax",s=e[n];if(s!=null)return s;if(t||(t={min_count:1/0,max_count:0,lods:[]}),Array.isArray(e)){for(const a of e)this.getMaterialMinMaxLODsCount(a,t);return e[n]=t,t}if(w==="verbose"&&console.log("getMaterialMinMaxLODsCount",e),e.type==="ShaderMaterial"||e.type==="RawShaderMaterial"){const a=e;for(const l of Object.keys(a.uniforms)){const d=a.uniforms[l].value;(d==null?void 0:d.isTexture)===!0&&i(d,t)}}else if(e.isMaterial)for(const a of Object.keys(e)){const l=e[a];(l==null?void 0:l.isTexture)===!0&&i(l,t)}else w&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${e.type}`);return e[n]=t,t;function i(a,l){const d=r.getAssignedLODInformation(a);if(d){const f=r.lodInfos.get(d.key);if(f&&f.lods){l.min_count=Math.min(l.min_count,f.lods.length),l.max_count=Math.max(l.max_count,f.lods.length);for(let y=0;y<f.lods.length;y++){const b=f.lods[y];b.width&&(l.lods[y]=l.lods[y]||{min_height:1/0,max_height:0},l.lods[y].min_height=Math.min(l.lods[y].min_height,b.height),l.lods[y].max_height=Math.max(l.lods[y].max_height,b.height))}}}}}static hasLODLevelAvailable(e,t){var s;if(Array.isArray(e)){for(const i of e)if(this.hasLODLevelAvailable(i,t))return!0;return!1}if(e.isMaterial===!0){for(const i of Object.keys(e)){const a=e[i];if(a&&a.isTexture&&this.hasLODLevelAvailable(a,t))return!0}return!1}else if(e.isGroup===!0){for(const i of e.children)if(i.isMesh===!0&&this.hasLODLevelAvailable(i,t))return!0}let r,n;if(e.isMesh?r=e.geometry:(e.isBufferGeometry||e.isTexture)&&(r=e),r&&(s=r==null?void 0:r.userData)!=null&&s.LODS){const i=r.userData.LODS;if(n=this.lodInfos.get(i.key),t===void 0)return n!=null;if(n)return Array.isArray(n.lods)?t<n.lods.length:t===0}return!1}static assignMeshLOD(e,t){var r;if(!e)return Promise.resolve(null);if(e instanceof g.Mesh||e.isMesh===!0){const n=e.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const i of J)(r=i.onBeforeGetLODMesh)==null||r.call(i,e,t);return e["LOD:requested level"]=t,M.getOrLoadLOD(n,t).then(i=>{if(Array.isArray(i)){const a=s.index||0;i=i[a]}return e["LOD:requested level"]===t&&(delete e["LOD:requested level"],i&&n!=i&&((i==null?void 0:i.isBufferGeometry)?e.geometry=i:w&&console.error("Invalid LOD geometry",i))),i}).catch(i=>(console.error("Error loading mesh LOD",e,i),null))}else w&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",e);return Promise.resolve(null)}static assignTextureLOD(e,t=0){if(!e)return Promise.resolve(null);if(e.isMesh===!0){const r=e;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const i=this.assignTextureLOD(s,t);n.push(i)}return Promise.all(n).then(s=>{const i=new Array;for(const a of s)Array.isArray(a)&&i.push(...a);return i})}else return this.assignTextureLOD(r.material,t)}if(e.isMaterial===!0){const r=e,n=[],s=new Array;if(r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const i=r;for(const a of Object.keys(i.uniforms)){const l=i.uniforms[a].value;if((l==null?void 0:l.isTexture)===!0){const d=this.assignTextureLODForSlot(l,t,r,a).then(f=>(f&&i.uniforms[a].value!=f&&(i.uniforms[a].value=f,i.uniformsNeedUpdate=!0),f));n.push(d),s.push(a)}}}else for(const i of Object.keys(r)){const a=r[i];if((a==null?void 0:a.isTexture)===!0){const l=this.assignTextureLODForSlot(a,t,r,i);n.push(l),s.push(i)}}return Promise.all(n).then(i=>{const a=new Array;for(let l=0;l<i.length;l++){const d=i[l],f=s[l];d&&d.isTexture===!0?a.push({material:r,slot:f,texture:d,level:t}):a.push({material:r,slot:f,texture:null,level:t})}return a})}if(e instanceof g.Texture||e.isTexture===!0){const r=e;return this.assignTextureLODForSlot(r,t,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(e,t,r,n){return(e==null?void 0:e.isTexture)!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(e):M.getOrLoadLOD(e,t).then(s=>{var i,a;if(Array.isArray(s))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if((s==null?void 0:s.isTexture)===!0){if(s!=e&&r&&n){const l=r[n];if(l&&!w){const d=this.getAssignedLODInformation(l);if(d&&(d==null?void 0:d.level)<t)return w==="verbose"&&console.warn("Assigned texture level is already higher: ",d.level,t,r,l,s),null}if(yt&&s.mipmaps){const d=s.mipmaps.length;s.mipmaps.length=Math.min(s.mipmaps.length,3),d!==s.mipmaps.length&&w&&console.debug(`Reduced mipmap count from ${d} to ${s.mipmaps.length} for ${s.uuid}: ${(i=s.image)==null?void 0:i.width}x${(a=s.image)==null?void 0:a.height}.`)}r[n]=s}return s}else w=="verbose"&&console.warn("No LOD found for",e,t);return null}).catch(s=>(console.error("Error loading LOD",e,s),null))}afterRoot(e){var t,r;return w&&console.log("AFTER",this.url,e),(t=this.parser.json.textures)==null||t.forEach((n,s)=>{var i;if(n!=null&&n.extensions){const a=n==null?void 0:n.extensions[X];if(a){if(!a.lods){w&&console.warn("Texture has no LODs",a);return}let l=!1;for(const d of this.parser.associations.keys())if(d.isTexture===!0){const f=this.parser.associations.get(d);(f==null?void 0:f.textures)===s&&(l=!0,M.registerTexture(this.url,d,(i=a.lods)==null?void 0:i.length,s,a))}l||this.parser.getDependency("texture",s).then(d=>{var f;d&&M.registerTexture(this.url,d,(f=a.lods)==null?void 0:f.length,s,a)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const i=n==null?void 0:n.extensions[X];if(i&&i.lods){for(const a of this.parser.associations.keys())if(a.isMesh){const l=this.parser.associations.get(a);(l==null?void 0:l.meshes)===s&&M.registerMesh(this.url,i.guid,a,i.lods.length,l.primitives,i)}}}}),null}static async getOrLoadLOD(e,t){var l,d,f,y;const r=w=="verbose",n=this.getAssignedLODInformation(e);if(!n)return w&&console.warn(`[gltf-progressive] No LOD information found: ${e.name}, uuid: ${e.uuid}, type: ${e.type}`,e),null;const s=n==null?void 0:n.key;let i;if(e.isTexture===!0){const b=e;b.source&&b.source[Te]&&(i=b.source[Te])}if(i||(i=M.lodInfos.get(s)),i){if(t>0){let P=!1;const v=Array.isArray(i.lods);if(v&&t>=i.lods.length?P=!0:v||(P=!0),P)return this.lowresCache.get(s)}const b=Array.isArray(i.lods)?(l=i.lods[t])==null?void 0:l.path:i.lods;if(!b)return w&&!i["missing:uri"]&&(i["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+t,i)),null;const L=ot(n.url,b);if(L.endsWith(".glb")||L.endsWith(".gltf")){if(!i.guid)return console.warn("missing pointer for glb/gltf texture",i),null;const P=L+"_"+i.guid,v=await this.queue.slot(L),B=this.previouslyLoaded.get(P);if(B!==void 0){r&&console.log(`LOD ${t} was already loading/loaded: ${P}`);let h=await B.catch(C=>(console.error(`Error loading LOD ${t} from ${L}
2
- `,C),null)),_=!1;if(h==null||(h instanceof g.Texture&&e instanceof g.Texture?(d=h.image)!=null&&d.data||(f=h.source)!=null&&f.data?h=this.copySettings(e,h):(_=!0,this.previouslyLoaded.delete(P)):h instanceof g.BufferGeometry&&e instanceof g.BufferGeometry&&((y=h.attributes.position)!=null&&y.array||(_=!0,this.previouslyLoaded.delete(P)))),!_)return h}if(!v.use)return w&&console.log(`LOD ${t} was aborted: ${L}`),null;const T=i,c=new Promise(async(h,_)=>{if(mt){const m=await(await gt({})).load(L);if(m.textures.length>0)for(const p of m.textures){let x=p.texture;return M.assignLODInformation(n.url,x,s,t,void 0),e instanceof g.Texture&&(x=this.copySettings(e,x)),x&&(x.guid=T.guid),h(x)}if(m.geometries.length>0){const p=new Array;for(const x of m.geometries){const I=x.geometry;M.assignLODInformation(n.url,I,s,t,x.primitiveIndex),p.push(I)}return h(p)}return h(null)}const C=new ne.GLTFLoader;Be(C),w&&(await new Promise(A=>setTimeout(A,1e3)),r&&console.warn("Start loading (delayed) "+L,T.guid));let U=L;if(T&&Array.isArray(T.lods)){const A=T.lods[t];A.hash&&(U+="?v="+A.hash)}const k=await C.loadAsync(U).catch(A=>(console.error(`Error loading LOD ${t} from ${L}
3
- `,A),h(null)));if(!k)return h(null);const ee=k.parser;r&&console.log("Loading finished "+L,T.guid);let $=0;if(k.parser.json.textures){let A=!1;for(const m of k.parser.json.textures){if(m!=null&&m.extensions){const p=m==null?void 0:m.extensions[X];if(p!=null&&p.guid&&p.guid===T.guid){A=!0;break}}$++}if(A){let m=await ee.getDependency("texture",$);return m&&M.assignLODInformation(n.url,m,s,t,void 0),r&&console.log('change "'+e.name+'" → "'+m.name+'"',L,$,m,P),e instanceof g.Texture&&(m=this.copySettings(e,m)),m&&(m.guid=T.guid),h(m)}else w&&console.warn("Could not find texture with guid",T.guid,k.parser.json)}if($=0,k.parser.json.meshes){let A=!1;for(const m of k.parser.json.meshes){if(m!=null&&m.extensions){const p=m==null?void 0:m.extensions[X];if(p!=null&&p.guid&&p.guid===T.guid){A=!0;break}}$++}if(A){const m=await ee.getDependency("mesh",$);if(r&&console.log(`Loaded Mesh "${m.name}"`,L,$,m,P),m.isMesh===!0){const p=m.geometry;return M.assignLODInformation(n.url,p,s,t,0),h(p)}else{const p=new Array;for(let x=0;x<m.children.length;x++){const I=m.children[x];if(I.isMesh===!0){const R=I.geometry;M.assignLODInformation(n.url,R,s,t,x),p.push(R)}}return h(p)}}else w&&console.warn("Could not find mesh with guid",T.guid,k.parser.json)}return h(null)});return this.previouslyLoaded.set(P,c),v.use(c),await c}else if(e instanceof g.Texture){r&&console.log("Load texture from uri: "+L);const v=await new g.TextureLoader().loadAsync(L);return v?(v.guid=i.guid,v.flipY=!1,v.needsUpdate=!0,v.colorSpace=e.colorSpace,r&&console.log(i,v)):w&&console.warn("failed loading",L),v}}else w&&console.warn(`Can not load LOD ${t}: no LOD info found for "${s}" ${e.name}`,e.type);return null}static assignLODInformation(e,t,r,n,s){if(!t)return;t.userData||(t.userData={});const i=new xt(e,r,n,s);t.userData.LODS=i,"source"in t&&typeof t.source=="object"&&(t.source.LODS=i)}static getAssignedLODInformation(e){var t,r;return e?(t=e.userData)!=null&&t.LODS?e.userData.LODS:"source"in e&&((r=e.source)!=null&&r.LODS)?e.source.LODS:null:null}static copySettings(e,t){return t?(w==="verbose"&&console.debug(`Copy texture settings
4
- `,e.uuid,`
5
- `,t.uuid),t=t.clone(),t.offset=e.offset,t.repeat=e.repeat,t.colorSpace=e.colorSpace,t.magFilter=e.magFilter,t.minFilter=e.minFilter,t.wrapS=e.wrapS,t.wrapT=e.wrapT,t.flipY=e.flipY,t.anisotropy=e.anisotropy,t.mipmaps||(t.generateMipmaps=e.generateMipmaps),t):e}};u(M,"registerTexture",(e,t,r,n,s)=>{var a,l,d,f,y,b,L,P;if(!t){w&&console.error("gltf-progressive: Called register texture without texture");return}if(w){const v=((a=t.image)==null?void 0:a.width)||((d=(l=t.source)==null?void 0:l.data)==null?void 0:d.width)||0,B=((f=t.image)==null?void 0:f.height)||((b=(y=t.source)==null?void 0:y.data)==null?void 0:b.height)||0;console.log(`> Progressive: register texture[${n}] "${t.name||t.uuid}", Current: ${v}x${B}, Max: ${(L=s.lods[0])==null?void 0:L.width}x${(P=s.lods[0])==null?void 0:P.height}, uuid: ${t.uuid}`,s,t)}t.source&&(t.source[Te]=s);const i=s.guid;M.assignLODInformation(e,t,i,r,n),M.lodInfos.set(i,s),M.lowresCache.set(i,t)}),u(M,"registerMesh",(e,t,r,n,s,i)=>{var d;const a=r.geometry;if(!a){w&&console.warn("gltf-progressive: Register mesh without geometry");return}a.userData||(a.userData={}),w&&console.log("> Progressive: register mesh "+r.name,{index:s,uuid:r.uuid},i,r),M.assignLODInformation(e,a,t,n,s),M.lodInfos.set(t,i);let l=M.lowresCache.get(t);l?l.push(r.geometry):l=[r.geometry],M.lowresCache.set(t,l),n>0&&!oe(r)&&ut(r,a);for(const f of J)(d=f.onRegisteredNewMesh)==null||d.call(f,r,i)}),u(M,"lodInfos",new Map),u(M,"previouslyLoaded",new Map),u(M,"lowresCache",new Map),u(M,"workers",[]),u(M,"_workersIndex",0),u(M,"maxConcurrent",50),u(M,"queue",new at(M.maxConcurrent,{debug:w!=!1}));let W=M;class xt{constructor(e,t,r,n){u(this,"url");u(this,"key");u(this,"level");u(this,"index");this.url=e,this.key=t,this.level=r,n!=null&&(this.index=n)}}class xe{constructor(e,t){u(this,"frame_start");u(this,"frame_capture_end");u(this,"ready");u(this,"_resolve");u(this,"_signal");u(this,"_resolved",!1);u(this,"_addedCount",0);u(this,"_resolvedCount",0);u(this,"_awaiting",[]);u(this,"_maxPromisesPerObject",1);u(this,"_currentFrame",0);u(this,"_seen",new WeakMap);var s;const n=Math.max(t.frames??2,2);this.frame_start=e,this.frame_capture_end=e+n,this.ready=new Promise(i=>{this._resolve=i}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=t.signal,(s=this._signal)==null||s.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,t.maxPromisesPerObject??1)}get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}update(e){var t;this._currentFrame=e,((t=this._signal)!=null&&t.aborted||this._currentFrame>this.frame_capture_end&&this._awaiting.length===0)&&this.resolveNow()}add(e,t,r){if(this._resolved){w&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._currentFrame>this.frame_capture_end)){if(this._maxPromisesPerObject>=1)if(this._seen.has(t)){let n=this._seen.get(t);if(n>=this._maxPromisesPerObject){w&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(t,n+1)}else this._seen.set(t,1);this._awaiting.push(r),this._addedCount++,r.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(r),1)})}}resolveNow(){var e,t;this._resolved||(t=this._resolve)==null||t.call(this,{awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:((e=this._signal)==null?void 0:e.aborted)??!1})}}u(xe,"addPromise",(e,t,r,n)=>{n.forEach(s=>{s.add(e,t,r)})});const N=se("debugprogressive"),wt=se("noprogressive"),Pe=Symbol("Needle:LODSManager"),Ae=Symbol("Needle:LODState"),Q=Symbol("Needle:CurrentLOD"),G={mesh_lod:-1,texture_lod:-1};var D,E,Y,Le,Z,ie,_e,H;let fe=(D=class{constructor(e,t){u(this,"renderer");u(this,"context");u(this,"projectionScreenMatrix",new g.Matrix4);u(this,"targetTriangleDensity",2e5);u(this,"skinnedMeshAutoUpdateBoundsInterval",30);u(this,"updateInterval","auto");j(this,E,1);u(this,"pause",!1);u(this,"manual",!1);u(this,"_newPromiseGroups",[]);u(this,"_promiseGroupIds",0);u(this,"_lodchangedlisteners",[]);j(this,Y);j(this,Le,new g.Clock);j(this,Z,0);j(this,ie,0);j(this,_e,0);j(this,H,0);u(this,"_fpsBuffer",[60,60,60,60,60]);u(this,"_sphere",new g.Sphere);u(this,"_tempBox",new g.Box3);u(this,"_tempBox2",new g.Box3);u(this,"tempMatrix",new g.Matrix4);u(this,"_tempWorldPosition",new g.Vector3);u(this,"_tempBoxSize",new g.Vector3);u(this,"_tempBox2Size",new g.Vector3);this.renderer=e,this.context={...t}}static getObjectLODState(e){return e[Ae]}static addPlugin(e){J.push(e)}static removePlugin(e){const t=J.indexOf(e);t>=0&&J.splice(t,1)}static get(e,t){if(e[Pe])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),e[Pe];const r=new D(e,{engine:"unknown",...t});return e[Pe]=r,r}get plugins(){return J}awaitLoading(e){const t=this._promiseGroupIds++,r=new xe(S(this,Z),{...e});this._newPromiseGroups.push(r);const n=performance.now();return r.ready.finally(()=>{const s=this._newPromiseGroups.indexOf(r);s>=0&&(this._newPromiseGroups.splice(s,1),Fe()&&performance.measure("LODsManager:awaitLoading",{start:n,detail:{id:t,name:e==null?void 0:e.name,awaited:r.awaitedCount,resolved:r.resolvedCount}}))}),r.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let e=this._newPromiseGroups.length-1;e>=0;e--)this._newPromiseGroups[e].update(S(this,Z))}addEventListener(e,t){e==="changed"&&this._lodchangedlisteners.push(t)}removeEventListener(e,t){if(e==="changed"){const r=this._lodchangedlisteners.indexOf(t);r>=0&&this._lodchangedlisteners.splice(r,1)}}enable(){if(S(this,Y))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let e=0;K(this,Y,this.renderer.render);const t=this;Me(this.renderer),this.renderer.render=function(r,n){const s=t.renderer.getRenderTarget();(s==null||"isXRRenderTarget"in s&&s.isXRRenderTarget)&&(e=0,K(t,Z,S(t,Z)+1),K(t,ie,S(t,Le).getDelta()),K(t,_e,S(t,_e)+S(t,ie)),t._fpsBuffer.shift(),t._fpsBuffer.push(1/S(t,ie)),K(t,H,t._fpsBuffer.reduce((a,l)=>a+l)/t._fpsBuffer.length),N&&S(t,Z)%200===0&&console.log("FPS",Math.round(S(t,H)),"Interval:",S(t,E)));const i=e++;S(t,Y).call(this,r,n),t.onAfterRender(r,n,i)}}disable(){S(this,Y)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=S(this,Y),K(this,Y,void 0))}update(e,t){this.internalUpdate(e,t)}onAfterRender(e,t,r){if(this.pause)return;const s=this.renderer.renderLists.get(e,0).opaque;let i=!0;if(s.length===1){const a=s[0].material;(a.name==="EffectMaterial"||a.name==="CopyShader")&&(i=!1)}if((t.parent&&t.parent.type==="CubeCamera"||r>=1&&t.type==="OrthographicCamera")&&(i=!1),i){if(wt||(this.updateInterval==="auto"?S(this,H)<40&&S(this,E)<10?(K(this,E,S(this,E)+1),N&&console.warn("↓ Reducing LOD updates",S(this,E),S(this,H).toFixed(0))):S(this,H)>=60&&S(this,E)>1&&(K(this,E,S(this,E)-1),N&&console.warn("↑ Increasing LOD updates",S(this,E),S(this,H).toFixed(0))):K(this,E,this.updateInterval),S(this,E)>0&&S(this,Z)%S(this,E)!=0))return;this.internalUpdate(e,t),this._postprocessPromiseGroups()}}internalUpdate(e,t){var l,d;const r=this.renderer.renderLists.get(e,0),n=r.opaque;this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse);const s=this.targetTriangleDensity;for(const f of n){if(f.material&&(((l=f.geometry)==null?void 0:l.type)==="BoxGeometry"||((d=f.geometry)==null?void 0:d.type)==="BufferGeometry")&&(f.material.name==="SphericalGaussianBlur"||f.material.name=="BackgroundCubeMaterial"||f.material.name==="CubemapFromEquirect"||f.material.name==="EquirectangularToCubeUV")){N&&(f.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(f.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",f,f.material.name,f.material.type)));continue}switch(f.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(N==="color"&&f.material&&!f.object.progressive_debug_color){f.object.progressive_debug_color=!0;const b=Math.random()*16777215,L=new g.MeshStandardMaterial({color:b});f.object.material=L}const y=f.object;(y instanceof g.Mesh||y.isMesh)&&this.updateLODs(e,t,y,s)}const i=r.transparent;for(const f of i){const y=f.object;(y instanceof g.Mesh||y.isMesh)&&this.updateLODs(e,t,y,s)}const a=r.transmissive;for(const f of a){const y=f.object;(y instanceof g.Mesh||y.isMesh)&&this.updateLODs(e,t,y,s)}}updateLODs(e,t,r,n){var a,l;r.userData||(r.userData={});let s=r[Ae];if(s||(s=new Lt,r[Ae]=s),s.frames++<2)return;for(const d of J)(a=d.onBeforeUpdateLOD)==null||a.call(d,this.renderer,e,t,r);const i=D.overrideGlobalLodLevel!==void 0?D.overrideGlobalLodLevel:te;i>=0?(G.mesh_lod=i,G.texture_lod=i):(this.calculateLodLevel(t,r,s,n,G),G.mesh_lod=Math.round(G.mesh_lod),G.texture_lod=Math.round(G.texture_lod)),G.mesh_lod>=0&&this.loadProgressiveMeshes(r,G.mesh_lod),r.material&&G.texture_lod>=0&&this.loadProgressiveTextures(r.material,G.texture_lod,i),w&&r.material&&!r.isGizmo&&He(r.material);for(const d of J)(l=d.onAfterUpdatedLOD)==null||l.call(d,this.renderer,e,t,r,G);s.lastLodLevel_Mesh=G.mesh_lod,s.lastLodLevel_Texture=G.texture_lod}loadProgressiveTextures(e,t,r){if(!e)return;if(Array.isArray(e)){for(const s of e)this.loadProgressiveTextures(s,t);return}let n=!1;if((e[Q]===void 0||t<e[Q])&&(n=!0),r!==void 0&&r>=0&&(n=e[Q]!=r,t=r),n){e[Q]=t;const s=W.assignTextureLOD(e,t).then(i=>{this._lodchangedlisteners.forEach(a=>a({type:"texture",level:t,object:e}))});xe.addPromise("texture",e,s,this._newPromiseGroups)}}loadProgressiveMeshes(e,t){if(!e)return Promise.resolve(null);let r=e[Q]!==t;const n=e["DEBUG:LOD"];if(n!=null&&(r=e[Q]!=n,t=n),r){e[Q]=t;const s=e.geometry,i=W.assignMeshLOD(e,t).then(a=>(a&&e[Q]==t&&s!=e.geometry&&this._lodchangedlisteners.forEach(l=>l({type:"mesh",level:t,object:e})),a));return xe.addPromise("mesh",e,i,this._newPromiseGroups),i}return Promise.resolve(null)}static isInside(e,t){const r=e.min,n=e.max,s=(r.x+n.x)*.5,i=(r.y+n.y)*.5;return this._tempPtInside.set(s,i,r.z).applyMatrix4(t).z<0}calculateLodLevel(e,t,r,n,s){var B,T,c,O;if(!t){s.mesh_lod=-1,s.texture_lod=-1;return}if(!e){s.mesh_lod=-1,s.texture_lod=-1;return}let a=10+1,l=!1;if(N&&t["DEBUG:LOD"]!=null)return t["DEBUG:LOD"];const d=(B=W.getMeshLODExtension(t.geometry))==null?void 0:B.lods,f=W.getPrimitiveIndex(t.geometry),y=d&&d.length>0,b=W.getMaterialMinMaxLODsCount(t.material),L=b.min_count!==1/0&&b.min_count>=0&&b.max_count>=0;if(!y&&!L){s.mesh_lod=0,s.texture_lod=0;return}y||(l=!0,a=0);const P=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let v=t.geometry.boundingBox;if(t.type==="SkinnedMesh"){const h=t;if(!h.boundingBox)h.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!h[D.$skinnedMeshBoundsOffset]){const C=D.skinnedMeshBoundsFrameOffsetCounter++;h[D.$skinnedMeshBoundsOffset]=C}const _=h[D.$skinnedMeshBoundsOffset];if((r.frames+_)%this.skinnedMeshAutoUpdateBoundsInterval===0){const C=oe(h),U=h.geometry;C&&(h.geometry=C),h.computeBoundingBox(),h.geometry=U}}v=h.boundingBox}if(v){const h=e;if(t.geometry.attributes.color&&t.geometry.attributes.color.count<100&&t.geometry.boundingSphere){this._sphere.copy(t.geometry.boundingSphere),this._sphere.applyMatrix4(t.matrixWorld);const p=e.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(p)){s.mesh_lod=0,s.texture_lod=0;return}}if(this._tempBox.copy(v),this._tempBox.applyMatrix4(t.matrixWorld),h.isPerspectiveCamera&&D.isInside(this._tempBox,this.projectionScreenMatrix)){s.mesh_lod=0,s.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&h.isPerspectiveCamera&&h.fov>70){const p=this._tempBox.min,x=this._tempBox.max;let I=p.x,R=p.y,q=x.x,ae=x.y;const he=2,De=1.5,ge=(p.x+x.x)*.5,pe=(p.y+x.y)*.5;I=(I-ge)*he+ge,R=(R-pe)*he+pe,q=(q-ge)*he+ge,ae=(ae-pe)*he+pe;const Je=I<0&&q>0?0:Math.min(Math.abs(p.x),Math.abs(x.x)),Ze=R<0&&ae>0?0:Math.min(Math.abs(p.y),Math.abs(x.y)),be=Math.max(Je,Ze);r.lastCentrality=(De-be)*(De-be)*(De-be)}else r.lastCentrality=1;const _=this._tempBox.getSize(this._tempBoxSize);_.multiplyScalar(.5),screen.availHeight>0&&P>0&&_.multiplyScalar(P/screen.availHeight),e.isPerspectiveCamera?_.x*=e.aspect:e.isOrthographicCamera;const C=e.matrixWorldInverse,U=this._tempBox2;U.copy(v),U.applyMatrix4(t.matrixWorld),U.applyMatrix4(C);const k=U.getSize(this._tempBox2Size),ee=Math.max(k.x,k.y);if(Math.max(_.x,_.y)!=0&&ee!=0&&(_.z=k.z/Math.max(k.x,k.y)*Math.max(_.x,_.y)),r.lastScreenCoverage=Math.max(_.x,_.y,_.z),r.lastScreenspaceVolume.copy(_),r.lastScreenCoverage*=r.lastCentrality,N&&D.debugDrawLine){const p=this.tempMatrix.copy(this.projectionScreenMatrix);p.invert();const x=D.corner0,I=D.corner1,R=D.corner2,q=D.corner3;x.copy(this._tempBox.min),I.copy(this._tempBox.max),I.x=x.x,R.copy(this._tempBox.max),R.y=x.y,q.copy(this._tempBox.max);const ae=(x.z+q.z)*.5;x.z=I.z=R.z=q.z=ae,x.applyMatrix4(p),I.applyMatrix4(p),R.applyMatrix4(p),q.applyMatrix4(p),D.debugDrawLine(x,I,255),D.debugDrawLine(x,R,255),D.debugDrawLine(I,q,255),D.debugDrawLine(R,q,255)}let A=999;if(d&&r.lastScreenCoverage>0)for(let p=0;p<d.length;p++){const x=d[p],R=(((T=x.densities)==null?void 0:T[f])||x.density||1e-5)/r.lastScreenCoverage;if(f>0&&Fe()&&!x.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),R<n){A=p;break}}A<a&&(a=A,l=!0)}if(l?s.mesh_lod=a:s.mesh_lod=r.lastLodLevel_Mesh,N&&s.mesh_lod!=r.lastLodLevel_Mesh){const _=d==null?void 0:d[s.mesh_lod];_&&console.debug(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${s.mesh_lod} (density: ${(c=_.densities)==null?void 0:c[f].toFixed(0)}) | ${t.name}`)}if(L){const h="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(r.lastLodLevel_Texture<0){if(s.texture_lod=b.max_count-1,N){const _=b.lods[b.max_count-1];N&&console.log(`First Texture LOD ${s.texture_lod} (${_.max_height}px) - ${t.name}`)}}else{const _=r.lastScreenspaceVolume.x+r.lastScreenspaceVolume.y+r.lastScreenspaceVolume.z;let C=r.lastScreenCoverage*4;((O=this.context)==null?void 0:O.engine)==="model-viewer"&&(C*=1.5);const k=P/window.devicePixelRatio*C;let ee=!1;for(let $=b.lods.length-1;$>=0;$--){const A=b.lods[$];if(!(h&&A.max_height>=2048)&&!(Ye()&&A.max_height>4096)&&(A.max_height>k||!ee&&$===0)){if(ee=!0,s.texture_lod=$,N&&s.texture_lod<r.lastLodLevel_Texture){const m=A.max_height;console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${s.texture_lod} = ${m}px
6
- Screensize: ${k.toFixed(0)}px, Coverage: ${(100*r.lastScreenCoverage).toFixed(2)}%, Volume ${_.toFixed(1)}
7
- ${t.name}`)}break}}}}else s.texture_lod=0}},E=new WeakMap,Y=new WeakMap,Le=new WeakMap,Z=new WeakMap,ie=new WeakMap,_e=new WeakMap,H=new WeakMap,u(D,"debugDrawLine"),u(D,"overrideGlobalLodLevel"),u(D,"corner0",new g.Vector3),u(D,"corner1",new g.Vector3),u(D,"corner2",new g.Vector3),u(D,"corner3",new g.Vector3),u(D,"_tempPtInside",new g.Vector3),u(D,"skinnedMeshBoundsFrameOffsetCounter",0),u(D,"$skinnedMeshBoundsOffset",Symbol("gltf-progressive-skinnedMeshBoundsOffset")),D);class Lt{constructor(){u(this,"frames",0);u(this,"lastLodLevel_Mesh",-1);u(this,"lastLodLevel_Texture",-1);u(this,"lastScreenCoverage",0);u(this,"lastScreenspaceVolume",new g.Vector3);u(this,"lastCentrality",0)}}const Ue=Symbol("NEEDLE_mesh_lod"),me=Symbol("NEEDLE_texture_lod");let ce=null;function je(){const o=_t();o&&(o.mapURLs(function(e){return Ne(),e}),Ne(),ce==null||ce.disconnect(),ce=new MutationObserver(e=>{e.forEach(t=>{t.addedNodes.forEach(r=>{r instanceof HTMLElement&&r.tagName.toLowerCase()==="model-viewer"&&Qe(r)})})}),ce.observe(document,{childList:!0,subtree:!0}))}function _t(){if(typeof customElements>"u")return null;const o=customElements.get("model-viewer");return o||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),je()}),null)}function Ne(){if(typeof document>"u")return;document.querySelectorAll("model-viewer").forEach(e=>{Qe(e)})}const We=new WeakSet;let Mt=0;function Qe(o){if(!o||We.has(o))return null;We.add(o),console.debug("[gltf-progressive] found new model-viewer..."+ ++Mt+`
8
- `,o.getAttribute("src"));let e=null,t=null,r=null;for(let n=o;n!=null;n=Object.getPrototypeOf(n)){const s=Object.getOwnPropertySymbols(n),i=s.find(d=>d.toString()=="Symbol(renderer)"),a=s.find(d=>d.toString()=="Symbol(scene)"),l=s.find(d=>d.toString()=="Symbol(needsRender)");!e&&i!=null&&(e=o[i].threeRenderer),!t&&a!=null&&(t=o[a]),!r&&l!=null&&(r=o[l])}if(e&&t){let s=function(){if(r){let i=0,a=setInterval(()=>{if(i++>5){clearInterval(a);return}r==null||r.call(o)},300)}};console.debug("[gltf-progressive] setup model-viewer");const n=fe.get(e,{engine:"model-viewer"});return fe.addPlugin(new Dt),n.enable(),n.addEventListener("changed",()=>{r==null||r.call(o)}),o.addEventListener("model-visibility",i=>{i.detail.visible&&(r==null||r.call(o))}),o.addEventListener("load",()=>{s()}),()=>{n.disable()}}return null}class Dt{constructor(){u(this,"_didWarnAboutMissingUrl",!1)}onBeforeUpdateLOD(e,t,r,n){this.tryParseMeshLOD(t,n),this.tryParseTextureLOD(t,n)}getUrl(e){if(!e)return null;let t=e.getAttribute("src");return t||(t=e.src),t||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",e),this._didWarnAboutMissingUrl=!0),t}tryGetCurrentGLTF(e){return e._currentGLTF}tryGetCurrentModelViewer(e){return e.element}tryParseTextureLOD(e,t){if(t[me]==!0)return;t[me]=!0;const r=this.tryGetCurrentGLTF(e),n=this.tryGetCurrentModelViewer(e),s=this.getUrl(n);if(s&&r&&t.material){let a=function(l){var f,y,b;if(l[me]==!0)return;l[me]=!0,l.userData&&(l.userData.LOD=-1);const d=Object.keys(l);for(let L=0;L<d.length;L++){const P=d[L],v=l[P];if((v==null?void 0:v.isTexture)===!0){const B=(y=(f=v.userData)==null?void 0:f.associations)==null?void 0:y.textures;if(B==null)continue;const T=r.parser.json.textures[B];if(!T){console.warn("Texture data not found for texture index "+B);continue}if((b=T==null?void 0:T.extensions)!=null&&b[X]){const c=T.extensions[X];c&&s&&W.registerTexture(s,v,c.lods.length,B,c)}}}};const i=t.material;if(Array.isArray(i))for(const l of i)a(l);else a(i)}}tryParseMeshLOD(e,t){var i,a;if(t[Ue]==!0)return;t[Ue]=!0;const r=this.tryGetCurrentModelViewer(e),n=this.getUrl(r);if(!n)return;const s=(a=(i=t.userData)==null?void 0:i.gltfExtensions)==null?void 0:a[X];if(s&&n){const l=t.uuid;W.registerMesh(n,l,t,0,s.lods.length,s)}}}function bt(o,e,t,r){Me(e),Be(t),Re(t,{progressive:!0,...r==null?void 0:r.hints}),t.register(s=>new W(s,o));const n=fe.get(e);return(r==null?void 0:r.enableLODsManager)!==!1&&n.enable(),n}je();if(!lt){const o={gltfProgressive:{useNeedleProgressive:bt,LODsManager:fe,configureLoader:Re,getRaycastMesh:oe,useRaycastMeshes:dt}};if(!globalThis.Needle)globalThis.Needle=o;else for(const e in o)globalThis.Needle[e]=o[e]}exports.LODsManager=fe;exports.NEEDLE_progressive=W;exports.addDracoAndKTX2Loaders=Be;exports.configureLoader=Re;exports.createLoaders=Me;exports.getRaycastMesh=oe;exports.setDracoDecoderLocation=qe;exports.setKTX2TranscoderLocation=Ke;
@@ -1 +0,0 @@
1
- (function(u,x,p,h){"use strict";self.onmessage=e=>{const o=e.data;switch(o.type){case"init":break;case"load":L(o);break;default:console.error("[Worker] Unknown message type:",o.type);break}},self.onerror=e=>{console.error("[Worker] Error:",e)};function m(e){self.postMessage(e)}let r=null,i=null,c=null;async function L(e){r??(r=new u.GLTFLoader),r.setMeshoptDecoder(x.MeshoptDecoder),i??(i=new p.DRACOLoader),i.setDecoderConfig({type:"js"}),i.setDecoderPath(e.dracoDecoderPath),r.setDRACOLoader(i),c??(c=new h.KTX2Loader),c.workerConfig=e.ktx2LoaderConfig,c.setTranscoderPath(e.ktx2TranscoderPath),r.setKTX2Loader(c),r.load(e.url,o=>{const n={type:"loaded-gltf",result:{url:e.url,geometries:[],textures:[]}};f(o,n),m(n)})}function f(e,o){const{result:n}=o;for(const s of e.parser.associations.keys()){const a=e.parser.associations.get(s);if(a)if("isTexture"in s&&s.isTexture){const d=s,t=e.parser.json.textures[a.textures??-1];n.textures.push({texture:d,textureIndex:a.textures??-1,extensions:(t==null?void 0:t.extensions)??{}})}else if("isMesh"in s&&s.isMesh){const d=s,t=a.meshes??-1,k=a.primitives??-1,l=e.parser.json.meshes[t];n.geometries.push({geometry:d.geometry,meshIndex:t,primitiveIndex:k,extensions:(l==null?void 0:l.extensions)??{}})}else"isMaterial"in s&&s.isMaterial}}})(GLTFLoader_js,meshopt_decoder_module_js,DRACOLoader_js,KTX2Loader_js);