@loaders.gl/gltf
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}([,function(e,t){},function(e,t,r){"use strict";(function(e,n){r.d(t,"a",function(){return s});const s="object"!=typeof e||"[object process]"!==String(e)||e.browser;"undefined"!=typeof self&&self,"undefined"!=typeof window&&window,"undefined"!=typeof document&&document}).call(this,r(7),r(4))},function(e,t){},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){(function(t){const n=r(9),s="undefined"==typeof window?t:window;s.loaders=s.loaders||{},e.exports=Object.assign(s.loaders,n)}).call(this,r(4))},,function(e,t){var r,n,s=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(e){r=i}try{n="function"==typeof clearTimeout?clearTimeout:o}catch(e){n=o}}();var a,f=[],c=!1,h=-1;function l(){c&&a&&(c=!1,a.length?f=a.concat(f):h=-1,f.length&&g())}function g(){if(!c){var e=u(l);c=!0;for(var t=f.length;t;){for(a=f,f=[];++h<t;)a&&a[h].run();h=-1,t=f.length}a=null,c=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===o||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function y(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];f.push(new d(e,t)),1!==f.length||c||u(g)},d.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=y,s.addListener=y,s.once=y,s.off=y,s.removeListener=y,s.removeAllListeners=y,s.emit=y,s.prependListener=y,s.prependOnceListener=y,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t){},function(e,t,r){"use strict";r.r(t);var n=r(2),s=r(1);function i(e,t){if(!e)throw new Error(t||"loader assertion failed.")}async function o(e,t){return await fetch(e,t)}let u="";const a={};function f(e){for(const t in a)if(e.startsWith(t)){const r=a[t];return e.replace(t,r)}return e+=u}var c=r(10);function h(e){return e+3&-4}function l(e,t,r,n=t.byteLength){const s=new Uint8Array(e,r,n),i=new Uint8Array(t);return s.set(i),e}function g(e,t,r){let n;if(e instanceof ArrayBuffer)n=new Uint8Array(e);else{const t=e.byteOffset,r=e.byteLength;n=new Uint8Array(e.buffer,t,r)}return t.set(n,r),r+h(n.byteLength)}const d=1735152710,y=12,m=8,p=1313821514,b=5130562,w=!0,x=!1;function A(e,t,r=0,n={}){const s=new DataView(t);e.byteOffset=r,e.magic=s.getUint32(r+0,x),e.version=s.getUint32(r+4,w),e.byteLength=s.getUint32(r+8,w),e.type=function(e){return`${String.fromCharCode(e.getUint8(0))}${String.fromCharCode(e.getUint8(1))}${String.fromCharCode(e.getUint8(2))}${String.fromCharCode(e.getUint8(3))}`}(s);const{magic:o=d}=n;e.magic===d||e.magic===o||console.warn(`Invalid GLB magic string ${e.type}`),i(2===e.version,`Invalid GLB version ${e.version}. Only .glb v2 supported`),i(e.byteLength>20),e.jsonChunkLength=s.getUint32(r+12,w),e.jsonChunkFormat=s.getUint32(r+16,w),i(e.jsonChunkFormat===p||0===e.jsonChunkFormat,`JSON chunk format ${e.jsonChunkFormat}`),e.jsonChunkByteOffset=y+m;const u=new Uint8Array(t,r+e.jsonChunkByteOffset,e.jsonChunkLength),a=new c.TextDecoder("utf8").decode(u);e.json=JSON.parse(a);const f=e.jsonChunkByteOffset+h(e.jsonChunkLength);if(e.hasBinChunk=f+8<=e.byteLength,e.binChunkByteOffset=0,e.binChunkLength=0,e.hasBinChunk){e.binChunkLength=s.getUint32(r+f+0,w),e.binChunkFormat=s.getUint32(r+f+4,w),i(e.binChunkFormat===b||1===e.binChunkFormat,`BIN chunk format ${e.binChunkFormat}`),e.binChunkByteOffset=f+m}return r+e.byteLength}const _={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},j={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},B={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function v(e,t,r){r&&(e=function(e,t){const r=e.byteLength-t,n=new ArrayBuffer(r),s=new Uint8Array(e),i=new Uint8Array(n);for(let e=0;e<r;e++)i[e]=s[t+e];return n}(e,r));const n=t.bufferViews||[];for(let e=0;e<n.length;++e){i(n[e].byteLength>=0)}return{accessors:T(e,n,t),images:L(e,n,t)}}function T(e,t,r){const n=r.accessors||[],s=[];for(let r=0;r<n.length;++r){const o=n[r];i(o);const u=t[o.bufferView];if(u){const{ArrayType:t,length:r}=U(o,u),n=new t(e,u.byteOffset,r);n.accessor=o,s.push(n)}}return s}function L(e,t,r){const n=r.images||[],s=[];for(let r=0;r<n.length;++r){const o=n[r];i(o);const u=t[o.bufferView];i(u);const a=new Uint8Array(e,u.byteOffset,u.byteLength);a.imate=o,s.push(a)}return s}function U(e,t){const r=B[e.componentType],n=_[e.type],s=j[e.componentType],o=e.count*n,u=e.count*n*s;return i(u>=0&&u<=t.byteLength),{ArrayType:r,length:o,byteLength:u}}function V(e,t,r={}){return function e(t,r,n,s={}){const i=t;const o=function(e,t){const r=function(e){if("string"==typeof e){if(0===e.indexOf("##/"))return e.slice(1);let t=e.match(/\#\/([a-z]+)\/([0-9]+)/);if(t){const e=parseInt(t[2],10);return[t[1],e]}if(t=e.match(/\$\$\$([0-9]+)/)){const e=parseInt(t[1],10);return["accessors",e]}}return null}(e);if(r){const[n,s]=r,i=t[n]&&t[n][s];if(i)return i;console.error(`Invalid JSON pointer ${e}: #/${n}/${s}`)}return null}(i,n);if(o)return o;if(Array.isArray(i))return i.map(t=>e(t,r,n,s));if(null!==i&&"object"==typeof i){const t={};for(const o in i)t[o]=e(i[o],r,n,s);return t}return i}(e,e,t,r)}const E=["SCALAR","VEC2","VEC3","VEC4"],C=new Map([[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126]]);function k(e){const t=C.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}const S={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},O={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},R={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},M=1735152710;class I{static isGLB(e,t={}){const{magic:r=M}=t,n=new DataView(e).getUint32(0,!1);return n===r||n===M}parse(e,t={}){return this.parseSync(e,t)}parseSync(e,t={}){if(this.glbArrayBuffer=e,this.binaryByteOffset=null,this.packedJson=null,this.json=null,null===this.json&&null===this.binaryByteOffset){const e=0;A(this,this.glbArrayBuffer,e,t),this.binaryByteOffset=this.binChunkByteOffset,this.packedJson=this.json,this.unpackedBuffers=v(this.glbArrayBuffer,this.json,this.binaryByteOffset),this.json=V(this.json,this.unpackedBuffers)}return this}getApplicationData(e){return this.json[e]}getJSON(){return this.json}getArrayBuffer(){return this.glbArrayBuffer}getBinaryByteOffset(){return this.binaryByteOffset}getBufferView(e){const t=(e.byteOffset||0)+this.binaryByteOffset;return new Uint8Array(this.glbArrayBuffer,t,e.byteLength)}getBuffer(e){const t=R[e.componentType],r=S[e.type],n=O[e.componentType],s=e.count*r,o=e.count*r*n,u=this.json.bufferViews[e.bufferView];i(o>=0&&e.byteOffset+o<=u.byteLength);const a=u.byteOffset+this.binaryByteOffset+e.byteOffset;return new t(this.glbArrayBuffer,a,s)}getImageData(e){return{typedArray:this.getBufferView(e.bufferView),mimeType:e.mimeType||"image/jpeg"}}getImage(e){const t=this.getBufferView(e.bufferView),r=e.mimeType||"image/jpeg",n=new Blob([t],{type:r}),s=(self.URL||self.webkitURL).createObjectURL(n),i=new Image;return i.src=s,i}getImageAsync(e){return new Promise(t=>{const r=this.getBufferView(e.bufferView),n=e.mimeType||"image/jpeg",s=new Blob([r],{type:n}),i=(self.URL||self.webkitURL).createObjectURL(s),o=new Image;o.onload=(()=>t(o)),o.src=i})}}function P(e,t){return e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:")?e:t.substr(0,t.lastIndexOf("/")+1)+e}const D={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},F={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},$={magFilter:10240,minFilter:10241,wrapS:10242,wrapT:10243};class N{postProcess(e,t,r={}){return this.gltf=e,this.glbParser=t,this._resolveToTree(r),this.gltf}_resolveToTree(e={}){const{gltf:t}=this;return(t.bufferViews||[]).forEach((e,t)=>this._resolveBufferView(e,t)),(t.images||[]).forEach((t,r)=>this._resolveImage(t,r,e)),(t.samplers||[]).forEach((e,t)=>this._resolveSampler(e,t)),(t.textures||[]).forEach((e,t)=>this._resolveTexture(e,t)),(t.accessors||[]).forEach((e,t)=>this._resolveAccessor(e,t)),(t.materials||[]).forEach((e,t)=>this._resolveMaterial(e,t)),(t.meshes||[]).forEach((e,t)=>this._resolveMesh(e,t)),(t.nodes||[]).forEach((e,t)=>this._resolveNode(e,t)),(t.skins||[]).forEach((e,t)=>this._resolveSkin(e,t)),(t.scenes||[]).forEach((e,t)=>this._resolveScene(e,t)),void 0!==t.scene&&(t.scene=t.scenes[this.gltf.scene]),this._process_extension_KHR_lights_punctual(),t}getScene(e){return this._get("scenes",e)}getNode(e){return this._get("nodes",e)}getSkin(e){return this._get("skins",e)}getMesh(e){return this._get("meshes",e)}getMaterial(e){return this._get("materials",e)}getAccessor(e){return this._get("accessors",e)}getCamera(e){return null}getTexture(e){return this._get("textures",e)}getSampler(e){return this._get("samplers",e)}getImage(e){return this._get("images",e)}getBufferView(e){return this._get("bufferViews",e)}getBuffer(e){return this._get("buffers",e)}_get(e,t){if("object"==typeof t)return t;const r=this.gltf[e]&&this.gltf[e][t];return r||console.warn(`glTF file error: Could not find ${e}[${t}]`),r}_resolveScene(e,t){e.id=`scene-${t}`,e.nodes=(e.nodes||[]).map(e=>this.getNode(e))}_resolveNode(e,t){e.id=`node-${t}`,e.children=(e.children||[]).map(e=>this.getNode(e)),void 0!==e.mesh&&(e.mesh=this.getMesh(e.mesh)),void 0!==e.camera&&(e.camera=this.getCamera(e.camera)),void 0!==e.skin&&(e.skin=this.getSkin(e.skin))}_resolveSkin(e,t){e.id=`skin-${t}`,e.inverseBindMatrices=this.getAccessor(e.inverseBindMatrices)}_resolveMesh(e,t){e.id=`mesh-${t}`;for(const t of e.primitives){for(const e in t.attributes)t.attributes[e]=this.getAccessor(t.attributes[e]);void 0!==t.indices&&(t.indices=this.getAccessor(t.indices)),void 0!==t.material&&(t.material=this.getMaterial(t.material))}}_resolveMaterial(e,t){if(e.id=`material-${t}`,e.normalTexture&&(e.normalTexture.texture=this.getTexture(e.normalTexture.index)),e.occlusionTexture&&(e.occlusionTexture.texture=this.getTexture(e.occlusionTexture.index)),e.emissiveTexture&&(e.emissiveTexture.texture=this.getTexture(e.emissiveTexture.index)),e.pbrMetallicRoughness){const t=e.pbrMetallicRoughness;t.baseColorTexture&&(t.baseColorTexture.texture=this.getTexture(t.baseColorTexture.index)),t.metallicRoughnessTexture&&(t.metallicRoughnessTexture.texture=this.getTexture(t.metallicRoughnessTexture.index))}}_resolveAccessor(e,t){e.id=`accessor-${t}`,void 0!==e.bufferView&&(e.bufferView=this.getBufferView(e.bufferView)),e.bytesPerComponent=F[e],e.components=D[e],e.bytesPerElement=e.bytesPerComponent*e.components}_resolveTexture(e,t){e.id=`texture-${t}`,e.sampler=this.getSampler(e.sampler),e.source=this.getImage(e.source)}_resolveSampler(e,t){e.id=`sampler-${t}`,e.parameters={};for(const t in e){const r=this._enumSamplerParameter(t);void 0!==r&&(e.parameters[r]=e[t])}}_enumSamplerParameter(e){return $[e]}_resolveImage(e,t,r){e.id=`image-${t}`,void 0!==e.bufferView&&(e.bufferView=this.getBufferView(e.bufferView));const{createImages:n=!0}=r;n?e.image=this.glbParser.getImage(e):e.getImageAsync=(()=>this.glbParser?this.glbParser.getImageAsync(e):e.uri?new Promise(t=>{const n=new Image;n.crossOrigin="anonymous",n.onload=(()=>t(n)),n.src=P(e.uri,r.uri)}):null)}_resolveBufferView(e,t){if(e.id=`bufferView-${t}`,e.buffer=this.getBuffer(e.buffer),this.glbParser)e.data=this.glbParser.getBufferView(e);else{const t=e.byteOffset||0;e.data=new Uint8Array(e.buffer.data,t,e.byteLength)}}_resolveCamera(e){e.perspective,e.orthographic}_process_extension_KHR_lights_punctual(){const{gltf:e}=this,t=e.extensions&&e.extensions.KHR_lights_punctual;t&&(e.lights=t.lights),this._removeExtension("KHR_lights_punctual");for(const t of e.nodes||[]){const e=t.extensions&&t.extensions.KHR_lights_punctual;e&&(t.light=this._get("lights",e.light),delete t.extensions.KHR_lights_punctual)}delete e.lights}_removeExtension(e){this.gltf.extensionsRequired&&this._removeStringFromArray(this.gltf.extensionsRequired,e),this.gltf.extensionsUsed&&this._removeStringFromArray(this.gltf.extensionsUsed,e),this.gltf.extensions&&delete this.gltf.extensions[e]}_removeStringFromArray(e,t){let r=!0;for(;r;){const n=e.indexOf(t);n>-1?e.splice(n,1):r=!1}}}const q="KHR_draco_mesh_compression",G="UBER_draco_point_cloud_compression";const W=["SCALAR","VEC2","VEC3","VEC4"],z=new Map([[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126]]);function J(e){return W[e-1]||W[0]}function K(e){const t=z.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}function H(e,t){const{buffer:r,size:n,count:s}=function(e,t){let r=e,n=1,s=0;e&&e.value&&(r=e.value,n=e.size||1);r&&(ArrayBuffer.isView(r)||(r=function(e,t,r=!1){if(!e)return null;if(Array.isArray(e))return new t(e);if(r&&!(e instanceof t))return new t(e);return e}(r,Float32Array)),s=r.length/n);return{buffer:r,size:n,count:s}}(e);return{value:r,size:n,bufferView:null,byteOffset:0,count:s,type:J(n),componentType:K(r)}}const X={fetchLinkedResources:!0,fetch:async function(e,t){return e=f(e),(n.a?o:s.fetchFile)(e,t)},decompress:!1,DracoLoader:null,postProcess:!0,createImages:!1,log:console};class Q{async parse(e,t={}){if(t=Object.assign({},X,t),this.parseSync(e,{...t,postProcess:!1,decompress:!1}),t.fetchLinkedResources&&await this._loadLinkedAssets(t),t.decompress&&this._decompressMeshes(t),t.postProcess){(new N).postProcess(this.gltf,this.glbParser,t)}return this.gltf}parseSync(e,t={}){if(t=Object.assign({},X,t),e instanceof ArrayBuffer&&!I.isGLB(e,t)){e=(new c.TextDecoder).decode(e)}if("string"==typeof e&&(e=JSON.parse(e)),e instanceof ArrayBuffer?(this.glbParser=new I,this.gltf=this.glbParser.parseSync(e).json,this.json=this.gltf):(this.glbParser=null,this.gltf=e,this.json=e),t.decompress&&this._decompressMeshes(t),t.postProcess){(new N).postProcess(this.gltf,this.glbParser,t)}return this.gltf}getApplicationData(e){return this.json[e]}getExtraData(e){return(this.json.extras||{})[e]}getExtension(e){const t=this.getUsedExtensions().find(t=>t===e),r=this.json.extensions||{};return t?r[e]||!0:null}getRequiredExtension(e){return this.getRequiredExtensions().find(t=>t===e)?this.getExtension(e):null}getRequiredExtensions(){return this.json.extensionsRequired||[]}getUsedExtensions(){return this.json.extensionsUsed||[]}getScene(e){return this._get("scenes",e)}getNode(e){return this._get("nodes",e)}getSkin(e){return this._get("skins",e)}getMesh(e){return this._get("meshes",e)}getMaterial(e){return this._get("materials",e)}getAccessor(e){return this._get("accessors",e)}getCamera(e){return null}getTexture(e){return this._get("textures",e)}getSampler(e){return this._get("samplers",e)}getImage(e){return this._get("images",e)}getBufferView(e){return this._get("bufferViews",e)}getBuffer(e){return this._get("buffers",e)}_get(e,t){if("object"==typeof t)return t;const r=this.gltf[e]&&this.gltf[e][t];return r||console.warn(`glTF file error: Could not find ${e}[${t}]`),r}async _loadLinkedAssets(e){return await Promise.all(this.gltf.buffers.map(t=>this._loadBuffer(t,e)))}async _loadBuffer(e,t){if(e.uri){const r=t.fetch||window.fetch,n=P(e.uri,t.uri),s=await r(n),i=await s.arrayBuffer();e.data=i,e.uri=null}}_decompressMeshes(e){if(e.DracoLoader&&e.decompress){for(const t of this.gltf.meshes||[])for(const r of t.primitives)if(this._decompressKhronosDracoPrimitive(r,e),this._decompressUberDracoPrimitive(r,e),!r.attributes||0===Object.keys(r.attributes).length)throw new Error("Empty glTF primitive: decompression failure?");this._removeExtension(q),this._removeExtension(G)}}_decompressKhronosDracoPrimitive(e,t){const r=e.extensions&&e.extensions[q];if(!r)return;delete e.extensions[q];const n=this._getBufferViewArray(r.bufferView),s=t.DracoLoader.parseSync(n);e.attributes=function(e){const t={};for(const r in e){const n=e[r];if("indices"!==r){const e=H(n);t[r]=e}}return t}(s.attributes),s.indices&&(e.indices=H(s.indices))}_decompressUberDracoPrimitive(e,t){const r=e.extensions&&e.extensions[G];if(!r)return;if(0!==e.mode)throw new Error(G);delete e.extensions[G];const n=this._getBufferViewArray(r.bufferView),s=t.DracoLoader.parseSync(n);e.attributes=s.attributes}_getBufferViewArray(e){const t=this.gltf.bufferViews[e];if(this.glbParser)return this.glbParser.getBufferView(t);const r=this.gltf.buffers[t.buffer].data,n=t.byteOffset||0;return new Uint8Array(r,n,t.byteLength)}_removeExtension(e){this.json.extensionsRequired&&this._removeStringFromArray(this.json.extensionsRequired,e),this.json.extensionsUsed&&this._removeStringFromArray(this.json.extensionsUsed,e),this.json.extensions&&delete this.json.extensions[e]}_removeStringFromArray(e,t){let r=!0;for(;r;){const n=e.indexOf(t);n>-1?e.splice(n,1):r=!1}}}var Y={name:"glTF",extension:["gltf","glb"],text:!0,binary:!0,parse:function(e,t={}){return(new Q).parse(e,t)},parseSync:function(e,t={}){return(new Q).parseSync(e,t)}},Z=r(3);const ee=!1,te=!0,re=new Map([["image/png",function(e){const t=ie(e);if(t.byteLength<24||2303741511!==t.getUint32(0,ee))return null;return{width:t.getUint32(16,ee),height:t.getUint32(20,ee)}}],["image/jpeg",function(e){const t=ie(e);if(t.byteLength<2||65496!==t.getUint16(0,ee))return null;const{tableMarkers:r,sofMarkers:n}=function(){const e=new Set([65499,65476,65484,65501,65534]);for(let t=65504;t<65520;++t)e.add(t);const t=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:t}}();let s=2;for(;s<t.byteLength;){const e=t.getUint16(s,ee);if(n.has(e))return{height:t.getUint16(s+5,ee),width:t.getUint16(s+7,ee)};if(!r.has(e))return null;s+=2,s+=t.getUint16(s,ee)}return null}],["image/gif",function(e){const t=ie(e);if(t.byteLength<10||1195984440!==t.getUint32(0,ee))return null;return{width:t.getUint16(6,te),height:t.getUint16(8,te)}}],["image/bmp",function(e){const t=ie(e);if(16973!==t.getUint16(0,ee))return null;return{width:t.getUint32(18,te),height:t.getUint32(22,te)}}]]),ne=`Invalid MIME type. Supported MIME types are: ${Array.from(re.keys()).join(", ")}`;function se(e,t){for(const[t,r]of re.entries()){const n=r(e);if(n)return n.mimeType=t,n}return null}function ie(e){if(Z.bufferToArrayBufferNode&&(e=Object(Z.bufferToArrayBufferNode)(e)),e instanceof ArrayBuffer||ArrayBuffer.isView(e))return new DataView(e.buffer||e);throw new Error("toDataView")}function oe(e,t=null){return function(e,t=null){if(t){const r=re.get(t);if(!r)throw new Error(ne);const n=r(e);if(!n)throw new Error(`invalid image data for type: ${t}`);return n}const r=se(e);if(!r)throw new Error(ne);return r}(e)}function ue(e,t=Float32Array){if(0===e.length)return new Float32Array(0);if(!function e(t,r=Number.isFinite){let n=-1;for(;++n<t.length;){const s=t[n];if(Array.isArray(s)||ArrayBuffer.isView(s)){if(!e(s,r))return!1}else if(!r(s))return!1}return!0}(e))return null;const r=new t(function e(t,r=3){let n=0;let s=0;let i=-1;for(;++i<t.length;){const r=t[i];Array.isArray(r)||ArrayBuffer.isView(r)?n+=e(r):s++}return n+(0===n&&s<r?r:s)}(e));return function(e,t,r=3){(function e(t,r,n,s){let i=-1,o=0;for(;++i<t.length;){const u=t[i];Array.isArray(u)||ArrayBuffer.isView(u)?s=e(u,r,n,s):o<n&&(r[s++]=u,o++)}return o>0&&o<n&&(r[s++]=0),s})(e,t,r,0)}(e,r),r}function ae(e,t,r={}){const{flattenArrays:n=!1}=r;let s=e;if("string"==typeof s&&0===s.indexOf("#/"))return`#${s}`;if(Array.isArray(s)){const e=n&&ue(s);if(!e)return s.map(e=>ae(e,t,r));s=e}if(ArrayBuffer.isView(s)&&t){if(t.isImage(s)){return`#/images/${t.addImage(s)}`}return`#/accessors/${t.addBuffer(s)}`}if(null!==s&&"object"==typeof s){const e={};for(const n in s)e[n]=ae(s[n],t,r);return e}return s}const fe=1179937895,ce=1313821514,he=5130562,le=!0,ge=12,de=8;class ye{constructor(e={}){this.byteLength=0,this.json={buffers:[{byteLength:0}],bufferViews:[],accessors:[],images:[],meshes:[]},this.sourceBuffers=[],this.log=e.log||console}getByteLength(){return this.byteLength}isImage(e){return function(e){const t=se(e);return!!t&&t.mimeType}(e)}encodeSync(e={}){return this.encodeAsGLB(e)}encodeAsGLB(e={}){return this._createGLBBuffer(e)}addApplicationData(e,t,r={}){const n=r.packTypedArrays?ae(t,this,r):t;return this.json[e]=n,this}addBuffer(e,t={size:3}){const r=this.addBufferView(e),n={size:t.size,componentType:k(e),count:Math.round(e.length/t.size)};return this.addAccessor(r,Object.assign(n,t))}addBufferView(e){const t=e.byteLength||e.length;return this.json.bufferViews.push({buffer:0,byteOffset:this.byteLength,byteLength:t}),this.byteLength+=h(t),this.sourceBuffers.push(e),this.json.bufferViews.length-1}addAccessor(e,t){var r;return this.json.accessors.push({bufferView:e,type:(r=t.size,E[r-1]||E[0]),componentType:t.componentType,count:t.count}),this.json.accessors.length-1}_pack(){return this._packBinaryChunk(),{arrayBuffer:this.arrayBuffer,json:this.json}}_packBinaryChunk(){if(this.arrayBuffer)return;const e=this.byteLength,t=new ArrayBuffer(e),r=new Uint8Array(t);let n=0;for(let e=0;e<this.sourceBuffers.length;e++){n=g(this.sourceBuffers[e],r,n)}this.json.buffers[0].byteLength=e,this.arrayBuffer=t,this.sourceBuffers=[]}_createGLBBuffer(e={}){this._packBinaryChunk();const t=this.arrayBuffer;e.magic&&console.warn("Custom glTF magic number no longer supported");const r=ge+de,n=this._convertObjectToJsonChunk(this.json),s=h(n.byteLength),i=s+r,o=i+de+h(t.byteLength),u=new ArrayBuffer(o),a=new DataView(u);a.setUint32(0,fe,le),a.setUint32(4,2,le),a.setUint32(8,o,le),a.setUint32(12,n.byteLength,le),a.setUint32(16,ce,le),l(u,n,r);for(let e=0;e<s-n.byteLength;++e)a.setUint8(r+n.byteLength+e,32);const f=h(t.byteLength);a.setUint32(i+0,f,le),a.setUint32(i+4,he,le),l(u,t,i+de);for(let e=0;e<f-t.byteLength;++e)a.setUint8(i+de+t.byteLength+e,0);return u}_getInternalCounts(){return{buffers:this.json.buffers.length,bufferViews:this.json.bufferViews.length,accessors:this.json.accessors.length,images:this.json.images.length}}_convertObjectToJsonChunk(e){const t=JSON.stringify(e);return new c.TextEncoder("utf8").encode(t)}}class me extends ye{constructor(e={}){super(e),this.DracoWriter=e.DracoWriter,this.DracoLoader=e.DracoLoader}addApplicationData(e,t,r={}){const n=r.packTypedArrays?ae(t,this,r):t;return this.json[e]=n,this}addExtraData(e,t,r={}){const n=r.packedTypedArrays?ae(t,this,r):t;return this.json.extras=this.json.extras||{},this.json.extras[e]=n,this}addExtension(e,t,r={}){i(t);const n=r.packTypedArrays?ae(t,this,r):t;return this.json.extensions=this.json.extensions||{},this.json.extensions[e]=n,this.registerUsedExtension(e),this}addRequiredExtension(e,t,r={}){i(t);const n=r.packTypedArrays?ae(t,this,r):t;return this.addExtension(e,n),this.registerRequiredExtension(e),this}registerUsedExtension(e){this.json.extensionsUsed=this.json.extensionsUsed||[],this.json.extensionsUsed.find(t=>t===e)||this.json.extensionsUsed.push(e)}registerRequiredExtension(e){this.registerUsedExtension(e),this.json.extensionsRequired=this.json.extensionsRequired||[],this.json.extensionsRequired.find(t=>t===e)||this.json.extensionsRequired.push(e)}addMesh(e,t,r=4){const n={primitives:[{attributes:this._addAttributes(e),indices:t,mode:r}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(n),this.json.meshes.length-1}addPointCloud(e){const t={primitives:[{attributes:this._addAttributes(e),mode:0}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(t),this.json.meshes.length-1}addCompressedMesh(e,t,r=4){if(!this.DracoWriter||!this.DracoLoader)throw new Error("DracoWriter/DracoLoader not available");this.registerRequiredExtension(q);const n=this.DracoWriter.encodeSync({attributes:e}),s=this.DracoLoader.parseSync({attributes:e}),i=this._addFauxAttributes(s.attributes),o=this.addBufferView(n),u={primitives:[{attributes:i,mode:r,extensions:{[q]:{bufferView:o,attributes:i}}}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(u),this.json.meshes.length-1}addCompressedPointCloud(e){if(!this.DracoWriter||!this.DracoLoader)throw new Error("DracoWriter/DracoLoader not available");e.mode=0;const t=this.DracoWriter.encodeSync(e,{pointcloud:!0}),r=this.addBufferView(t),n={primitives:[{attributes:{},mode:0,extensions:{[G]:{bufferView:r}}}]};return this.registerRequiredExtension(G),this.json.meshes=this.json.meshes||[],this.json.meshes.push(n),this.json.meshes.length-1}addImage(e){const t=this.addBufferView(e),r=oe(e)||{};if(r){const{mimeType:e,width:n,height:s}=r;this.json.images.push({bufferView:t,mimeType:e,width:n,height:s})}else this.json.images.push({bufferView:t});return this.json.images.length-1}}var pe={name:"GLB",extensions:["glb"],encodeSync:function(e,t){return(new me).encodeSync(e,t)}};r.d(t,"GLTFLoader",function(){return Y}),r.d(t,"GLTFWriter",function(){return pe}),r.d(t,"GLTFParser",function(){return Q}),r.d(t,"GLTFBuilder",function(){return me}),r.d(t,"GLBParser",function(){return I}),r.d(t,"GLBBuilder",function(){return ye}),r.d(t,"KHR_DRACO_MESH_COMPRESSION",function(){return q}),r.d(t,"UBER_POINT_CLOUD_EXTENSION",function(){return G}),r.d(t,"_parseGLBSync",function(){return A})},function(e,t,r){"undefined"==typeof TextDecoder?e.exports=r(8):e.exports={TextEncoder:TextEncoder,TextDecoder:TextDecoder}}])}); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}([,function(e,t){},function(e,t,r){"use strict";(function(e,n){r.d(t,"a",function(){return s});const s="object"!=typeof e||"[object process]"!==String(e)||e.browser;"undefined"!=typeof self&&self,"undefined"!=typeof window&&window,"undefined"!=typeof document&&document}).call(this,r(7),r(4))},function(e,t){},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){(function(t){const n=r(9),s="undefined"==typeof window?t:window;s.loaders=s.loaders||{},e.exports=Object.assign(s.loaders,n)}).call(this,r(4))},,function(e,t){var r,n,s=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function u(e){if(r===setTimeout)return setTimeout(e,0);if((r===i||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:i}catch(e){r=i}try{n="function"==typeof clearTimeout?clearTimeout:o}catch(e){n=o}}();var a,f=[],c=!1,h=-1;function l(){c&&a&&(c=!1,a.length?f=a.concat(f):h=-1,f.length&&g())}function g(){if(!c){var e=u(l);c=!0;for(var t=f.length;t;){for(a=f,f=[];++h<t;)a&&a[h].run();h=-1,t=f.length}a=null,c=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===o||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function y(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];f.push(new d(e,t)),1!==f.length||c||u(g)},d.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=y,s.addListener=y,s.once=y,s.off=y,s.removeListener=y,s.removeAllListeners=y,s.emit=y,s.prependListener=y,s.prependOnceListener=y,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t){},function(e,t,r){"use strict";r.r(t);var n=r(2),s=r(1);function i(e,t){if(!e)throw new Error(t||"loader assertion failed.")}async function o(e,t){return await fetch(e,t)}let u="";const a={};function f(e){for(const t in a)if(e.startsWith(t)){const r=a[t];return e.replace(t,r)}return e+=u}var c=r(10);function h(e){return e+3&-4}function l(e,t,r,n=t.byteLength){const s=new Uint8Array(e,r,n),i=new Uint8Array(t);return s.set(i),e}function g(e,t,r){let n;if(e instanceof ArrayBuffer)n=new Uint8Array(e);else{const t=e.byteOffset,r=e.byteLength;n=new Uint8Array(e.buffer,t,r)}return t.set(n,r),r+h(n.byteLength)}const d=1735152710,y=12,m=8,p=1313821514,b=5130562,w=!0,x=!1;function A(e,t,r=0,n={}){const s=new DataView(t);e.byteOffset=r,e.magic=s.getUint32(r+0,x),e.version=s.getUint32(r+4,w),e.byteLength=s.getUint32(r+8,w),e.type=function(e){return`${String.fromCharCode(e.getUint8(0))}${String.fromCharCode(e.getUint8(1))}${String.fromCharCode(e.getUint8(2))}${String.fromCharCode(e.getUint8(3))}`}(s);const{magic:o=d}=n;e.magic===d||e.magic===o||console.warn(`Invalid GLB magic string ${e.type}`),i(2===e.version,`Invalid GLB version ${e.version}. Only .glb v2 supported`),i(e.byteLength>20),e.jsonChunkLength=s.getUint32(r+12,w),e.jsonChunkFormat=s.getUint32(r+16,w),i(e.jsonChunkFormat===p||0===e.jsonChunkFormat,`JSON chunk format ${e.jsonChunkFormat}`),e.jsonChunkByteOffset=y+m;const u=new Uint8Array(t,r+e.jsonChunkByteOffset,e.jsonChunkLength),a=new c.TextDecoder("utf8").decode(u);e.json=JSON.parse(a);const f=e.jsonChunkByteOffset+h(e.jsonChunkLength);if(e.hasBinChunk=f+8<=e.byteLength,e.binChunkByteOffset=0,e.binChunkLength=0,e.hasBinChunk){e.binChunkLength=s.getUint32(r+f+0,w),e.binChunkFormat=s.getUint32(r+f+4,w),i(e.binChunkFormat===b||1===e.binChunkFormat,`BIN chunk format ${e.binChunkFormat}`),e.binChunkByteOffset=f+m}return r+e.byteLength}const _={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},j={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},B={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function v(e,t,r){r&&(e=function(e,t){const r=e.byteLength-t,n=new ArrayBuffer(r),s=new Uint8Array(e),i=new Uint8Array(n);for(let e=0;e<r;e++)i[e]=s[t+e];return n}(e,r));const n=t.bufferViews||[];for(let e=0;e<n.length;++e){i(n[e].byteLength>=0)}return{accessors:T(e,n,t),images:L(e,n,t)}}function T(e,t,r){const n=r.accessors||[],s=[];for(let r=0;r<n.length;++r){const o=n[r];i(o);const u=t[o.bufferView];if(u){const{ArrayType:t,length:r}=U(o,u),n=new t(e,u.byteOffset,r);n.accessor=o,s.push(n)}}return s}function L(e,t,r){const n=r.images||[],s=[];for(let r=0;r<n.length;++r){const o=n[r];i(o);const u=t[o.bufferView];i(u);const a=new Uint8Array(e,u.byteOffset,u.byteLength);a.imate=o,s.push(a)}return s}function U(e,t){const r=B[e.componentType],n=_[e.type],s=j[e.componentType],o=e.count*n,u=e.count*n*s;return i(u>=0&&u<=t.byteLength),{ArrayType:r,length:o,byteLength:u}}function V(e,t,r={}){return function e(t,r,n,s={}){const i=t;const o=function(e,t){const r=function(e){if("string"==typeof e){if(0===e.indexOf("##/"))return e.slice(1);let t=e.match(/\#\/([a-z]+)\/([0-9]+)/);if(t){const e=parseInt(t[2],10);return[t[1],e]}if(t=e.match(/\$\$\$([0-9]+)/)){const e=parseInt(t[1],10);return["accessors",e]}}return null}(e);if(r){const[n,s]=r,i=t[n]&&t[n][s];if(i)return i;console.error(`Invalid JSON pointer ${e}: #/${n}/${s}`)}return null}(i,n);if(o)return o;if(Array.isArray(i))return i.map(t=>e(t,r,n,s));if(null!==i&&"object"==typeof i){const t={};for(const o in i)t[o]=e(i[o],r,n,s);return t}return i}(e,e,t,r)}const E=["SCALAR","VEC2","VEC3","VEC4"],C=new Map([[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126]]);function k(e){const t=C.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}const S={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},O={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},R={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},M=1735152710;class I{static isGLB(e,t={}){const{magic:r=M}=t,n=new DataView(e).getUint32(0,!1);return n===r||n===M}parse(e,t={}){return this.parseSync(e,t)}parseSync(e,t={}){if(this.glbArrayBuffer=e,this.binaryByteOffset=null,this.packedJson=null,this.json=null,null===this.json&&null===this.binaryByteOffset){const e=0;A(this,this.glbArrayBuffer,e,t),this.binaryByteOffset=this.binChunkByteOffset,this.packedJson=this.json,this.unpackedBuffers=v(this.glbArrayBuffer,this.json,this.binaryByteOffset),this.json=V(this.json,this.unpackedBuffers)}return this}getApplicationData(e){return this.json[e]}getJSON(){return this.json}getArrayBuffer(){return this.glbArrayBuffer}getBinaryByteOffset(){return this.binaryByteOffset}getBufferView(e){const t=(e.byteOffset||0)+this.binaryByteOffset;return new Uint8Array(this.glbArrayBuffer,t,e.byteLength)}getBuffer(e){const t=R[e.componentType],r=S[e.type],n=O[e.componentType],s=e.count*r,o=e.count*r*n,u=this.json.bufferViews[e.bufferView];i(o>=0&&e.byteOffset+o<=u.byteLength);const a=u.byteOffset+this.binaryByteOffset+e.byteOffset;return new t(this.glbArrayBuffer,a,s)}getImageData(e){return{typedArray:this.getBufferView(e.bufferView),mimeType:e.mimeType||"image/jpeg"}}getImage(e){const t=this.getBufferView(e.bufferView),r=e.mimeType||"image/jpeg",n=new Blob([t],{type:r}),s=(self.URL||self.webkitURL).createObjectURL(n),i=new Image;return i.src=s,i}getImageAsync(e){return new Promise(t=>{const r=this.getBufferView(e.bufferView),n=e.mimeType||"image/jpeg",s=new Blob([r],{type:n}),i=(self.URL||self.webkitURL).createObjectURL(s),o=new Image;o.onload=(()=>t(o)),o.src=i})}}function P(e,t){return e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:")?e:t.substr(0,t.lastIndexOf("/")+1)+e}const D={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},F={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},$={magFilter:10240,minFilter:10241,wrapS:10242,wrapT:10243};class N{postProcess(e,t,r={}){return this.gltf=e,this.glbParser=t,this._resolveToTree(r),this.gltf}_resolveToTree(e={}){const{gltf:t}=this;return(t.bufferViews||[]).forEach((e,t)=>this._resolveBufferView(e,t)),(t.images||[]).forEach((t,r)=>this._resolveImage(t,r,e)),(t.samplers||[]).forEach((e,t)=>this._resolveSampler(e,t)),(t.textures||[]).forEach((e,t)=>this._resolveTexture(e,t)),(t.accessors||[]).forEach((e,t)=>this._resolveAccessor(e,t)),(t.materials||[]).forEach((e,t)=>this._resolveMaterial(e,t)),(t.meshes||[]).forEach((e,t)=>this._resolveMesh(e,t)),(t.nodes||[]).forEach((e,t)=>this._resolveNode(e,t)),(t.skins||[]).forEach((e,t)=>this._resolveSkin(e,t)),(t.scenes||[]).forEach((e,t)=>this._resolveScene(e,t)),void 0!==t.scene&&(t.scene=t.scenes[this.gltf.scene]),this._process_extension_KHR_lights_punctual(),t}getScene(e){return this._get("scenes",e)}getNode(e){return this._get("nodes",e)}getSkin(e){return this._get("skins",e)}getMesh(e){return this._get("meshes",e)}getMaterial(e){return this._get("materials",e)}getAccessor(e){return this._get("accessors",e)}getCamera(e){return null}getTexture(e){return this._get("textures",e)}getSampler(e){return this._get("samplers",e)}getImage(e){return this._get("images",e)}getBufferView(e){return this._get("bufferViews",e)}getBuffer(e){return this._get("buffers",e)}_get(e,t){if("object"==typeof t)return t;const r=this.gltf[e]&&this.gltf[e][t];return r||console.warn(`glTF file error: Could not find ${e}[${t}]`),r}_resolveScene(e,t){e.id=`scene-${t}`,e.nodes=(e.nodes||[]).map(e=>this.getNode(e))}_resolveNode(e,t){e.id=`node-${t}`,e.children=(e.children||[]).map(e=>this.getNode(e)),void 0!==e.mesh&&(e.mesh=this.getMesh(e.mesh)),void 0!==e.camera&&(e.camera=this.getCamera(e.camera)),void 0!==e.skin&&(e.skin=this.getSkin(e.skin))}_resolveSkin(e,t){e.id=`skin-${t}`,e.inverseBindMatrices=this.getAccessor(e.inverseBindMatrices)}_resolveMesh(e,t){e.id=`mesh-${t}`;for(const t of e.primitives){for(const e in t.attributes)t.attributes[e]=this.getAccessor(t.attributes[e]);void 0!==t.indices&&(t.indices=this.getAccessor(t.indices)),void 0!==t.material&&(t.material=this.getMaterial(t.material))}}_resolveMaterial(e,t){if(e.id=`material-${t}`,e.normalTexture&&(e.normalTexture.texture=this.getTexture(e.normalTexture.index)),e.occlusionTexture&&(e.occlusionTexture.texture=this.getTexture(e.occlusionTexture.index)),e.emissiveTexture&&(e.emissiveTexture.texture=this.getTexture(e.emissiveTexture.index)),e.pbrMetallicRoughness){const t=e.pbrMetallicRoughness;t.baseColorTexture&&(t.baseColorTexture.texture=this.getTexture(t.baseColorTexture.index)),t.metallicRoughnessTexture&&(t.metallicRoughnessTexture.texture=this.getTexture(t.metallicRoughnessTexture.index))}}_resolveAccessor(e,t){e.id=`accessor-${t}`,void 0!==e.bufferView&&(e.bufferView=this.getBufferView(e.bufferView)),e.bytesPerComponent=F[e],e.components=D[e],e.bytesPerElement=e.bytesPerComponent*e.components}_resolveTexture(e,t){e.id=`texture-${t}`,e.sampler=this.getSampler(e.sampler),e.source=this.getImage(e.source)}_resolveSampler(e,t){e.id=`sampler-${t}`,e.parameters={};for(const t in e){const r=this._enumSamplerParameter(t);void 0!==r&&(e.parameters[r]=e[t])}}_enumSamplerParameter(e){return $[e]}_resolveImage(e,t,r){e.id=`image-${t}`,void 0!==e.bufferView&&(e.bufferView=this.getBufferView(e.bufferView));const{createImages:n=!0}=r;n?e.image=this.glbParser.getImage(e):e.getImageAsync=(()=>this.glbParser?this.glbParser.getImageAsync(e):e.uri?new Promise(t=>{const n=new Image;n.crossOrigin="anonymous",n.onload=(()=>t(n)),n.src=P(e.uri,r.uri)}):null)}_resolveBufferView(e,t){if(e.id=`bufferView-${t}`,e.buffer=this.getBuffer(e.buffer),this.glbParser)e.data=this.glbParser.getBufferView(e);else{const t=e.byteOffset||0;e.data=new Uint8Array(e.buffer.data,t,e.byteLength)}}_resolveCamera(e){e.perspective,e.orthographic}_process_extension_KHR_lights_punctual(){const{gltf:e}=this,t=e.extensions&&e.extensions.KHR_lights_punctual;t&&(e.lights=t.lights),this._removeExtension("KHR_lights_punctual");for(const t of e.nodes||[]){const e=t.extensions&&t.extensions.KHR_lights_punctual;e&&(t.light=this._get("lights",e.light),delete t.extensions.KHR_lights_punctual)}delete e.lights}_removeExtension(e){this.gltf.extensionsRequired&&this._removeStringFromArray(this.gltf.extensionsRequired,e),this.gltf.extensionsUsed&&this._removeStringFromArray(this.gltf.extensionsUsed,e),this.gltf.extensions&&delete this.gltf.extensions[e]}_removeStringFromArray(e,t){let r=!0;for(;r;){const n=e.indexOf(t);n>-1?e.splice(n,1):r=!1}}}const q="KHR_draco_mesh_compression",G="UBER_draco_point_cloud_compression";const W=["SCALAR","VEC2","VEC3","VEC4"],z=new Map([[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126]]);function J(e){return W[e-1]||W[0]}function K(e){const t=z.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}function H(e,t){const{buffer:r,size:n,count:s}=function(e,t){let r=e,n=1,s=0;e&&e.value&&(r=e.value,n=e.size||1);r&&(ArrayBuffer.isView(r)||(r=function(e,t,r=!1){if(!e)return null;if(Array.isArray(e))return new t(e);if(r&&!(e instanceof t))return new t(e);return e}(r,Float32Array)),s=r.length/n);return{buffer:r,size:n,count:s}}(e);return{value:r,size:n,bufferView:null,byteOffset:0,count:s,type:J(n),componentType:K(r)}}const X={fetchLinkedResources:!0,fetch:async function(e,t){return e=f(e),(n.a?o:s.fetchFile)(e,t)},decompress:!1,DracoLoader:null,postProcess:!0,createImages:!1,log:console};class Q{async parse(e,t={}){if(t=Object.assign({},X,t),this.parseSync(e,{...t,postProcess:!1,decompress:!1}),t.fetchLinkedResources&&await this._loadLinkedAssets(t),t.decompress&&this._decompressMeshes(t),t.postProcess){(new N).postProcess(this.gltf,this.glbParser,t)}return this.gltf}parseSync(e,t={}){if(t=Object.assign({},X,t),e instanceof ArrayBuffer&&!I.isGLB(e,t)){e=(new c.TextDecoder).decode(e)}if("string"==typeof e&&(e=JSON.parse(e)),e instanceof ArrayBuffer?(this.glbParser=new I,this.gltf=this.glbParser.parseSync(e).json,this.json=this.gltf):(this.glbParser=null,this.gltf=e,this.json=e),t.decompress&&this._decompressMeshes(t),t.postProcess){(new N).postProcess(this.gltf,this.glbParser,t)}return this.gltf}getApplicationData(e){return this.json[e]}getExtraData(e){return(this.json.extras||{})[e]}getExtension(e){const t=this.getUsedExtensions().find(t=>t===e),r=this.json.extensions||{};return t?r[e]||!0:null}getRequiredExtension(e){return this.getRequiredExtensions().find(t=>t===e)?this.getExtension(e):null}getRequiredExtensions(){return this.json.extensionsRequired||[]}getUsedExtensions(){return this.json.extensionsUsed||[]}getScene(e){return this._get("scenes",e)}getNode(e){return this._get("nodes",e)}getSkin(e){return this._get("skins",e)}getMesh(e){return this._get("meshes",e)}getMaterial(e){return this._get("materials",e)}getAccessor(e){return this._get("accessors",e)}getCamera(e){return null}getTexture(e){return this._get("textures",e)}getSampler(e){return this._get("samplers",e)}getImage(e){return this._get("images",e)}getBufferView(e){return this._get("bufferViews",e)}getBuffer(e){return this._get("buffers",e)}_get(e,t){if("object"==typeof t)return t;const r=this.gltf[e]&&this.gltf[e][t];return r||console.warn(`glTF file error: Could not find ${e}[${t}]`),r}async _loadLinkedAssets(e){return await Promise.all(this.gltf.buffers.map(t=>this._loadBuffer(t,e)))}async _loadBuffer(e,t){if(e.uri){const r=t.fetch||window.fetch,n=P(e.uri,t.uri),s=await r(n),i=await s.arrayBuffer();e.data=i,e.uri=null}}_decompressMeshes(e){if(e.DracoLoader&&e.decompress){for(const t of this.gltf.meshes||[])for(const r of t.primitives)if(this._decompressKhronosDracoPrimitive(r,e),this._decompressUberDracoPrimitive(r,e),!r.attributes||0===Object.keys(r.attributes).length)throw new Error("Empty glTF primitive: decompression failure?");this._removeExtension(q),this._removeExtension(G)}}_decompressKhronosDracoPrimitive(e,t){const r=e.extensions&&e.extensions[q];if(!r)return;delete e.extensions[q];const n=this._getBufferViewArray(r.bufferView),s=t.DracoLoader.parseSync(n);e.attributes=function(e){const t={};for(const r in e){const n=e[r];if("indices"!==r){const e=H(n);t[r]=e}}return t}(s.attributes),s.indices&&(e.indices=H(s.indices))}_decompressUberDracoPrimitive(e,t){const r=e.extensions&&e.extensions[G];if(!r)return;if(0!==e.mode)throw new Error(G);delete e.extensions[G];const n=this._getBufferViewArray(r.bufferView),s=t.DracoLoader.parseSync(n);e.attributes=s.attributes}_getBufferViewArray(e){const t=this.gltf.bufferViews[e];if(this.glbParser)return this.glbParser.getBufferView(t);const r=this.gltf.buffers[t.buffer].data,n=t.byteOffset||0;return new Uint8Array(r,n,t.byteLength)}_removeExtension(e){this.json.extensionsRequired&&this._removeStringFromArray(this.json.extensionsRequired,e),this.json.extensionsUsed&&this._removeStringFromArray(this.json.extensionsUsed,e),this.json.extensions&&delete this.json.extensions[e]}_removeStringFromArray(e,t){let r=!0;for(;r;){const n=e.indexOf(t);n>-1?e.splice(n,1):r=!1}}}var Y={name:"glTF",extension:["gltf","glb"],text:!0,binary:!0,parse:function(e,t={}){return(new Q).parse(e,t)},parseSync:function(e,t={}){return(new Q).parseSync(e,t)}},Z=r(3);const ee=!1,te=!0,re=new Map([["image/png",function(e){const t=ie(e);if(t.byteLength<24||2303741511!==t.getUint32(0,ee))return null;return{width:t.getUint32(16,ee),height:t.getUint32(20,ee)}}],["image/jpeg",function(e){const t=ie(e);if(t.byteLength<2||65496!==t.getUint16(0,ee))return null;const{tableMarkers:r,sofMarkers:n}=function(){const e=new Set([65499,65476,65484,65501,65534]);for(let t=65504;t<65520;++t)e.add(t);const t=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:t}}();let s=2;for(;s<t.byteLength;){const e=t.getUint16(s,ee);if(n.has(e))return{height:t.getUint16(s+5,ee),width:t.getUint16(s+7,ee)};if(!r.has(e))return null;s+=2,s+=t.getUint16(s,ee)}return null}],["image/gif",function(e){const t=ie(e);if(t.byteLength<10||1195984440!==t.getUint32(0,ee))return null;return{width:t.getUint16(6,te),height:t.getUint16(8,te)}}],["image/bmp",function(e){const t=ie(e);if(16973!==t.getUint16(0,ee))return null;return{width:t.getUint32(18,te),height:t.getUint32(22,te)}}]]),ne=`Invalid MIME type. Supported MIME types are: ${Array.from(re.keys()).join(", ")}`;function se(e,t){for(const[t,r]of re.entries()){const n=r(e);if(n)return n.mimeType=t,n}return null}function ie(e){if(Z.bufferToArrayBuffer&&(e=Object(Z.bufferToArrayBuffer)(e)),e instanceof ArrayBuffer||ArrayBuffer.isView(e))return new DataView(e.buffer||e);throw new Error("toDataView")}function oe(e,t=null){return function(e,t=null){if(t){const r=re.get(t);if(!r)throw new Error(ne);const n=r(e);if(!n)throw new Error(`invalid image data for type: ${t}`);return n}const r=se(e);if(!r)throw new Error(ne);return r}(e)}function ue(e,t=Float32Array){if(0===e.length)return new Float32Array(0);if(!function e(t,r=Number.isFinite){let n=-1;for(;++n<t.length;){const s=t[n];if(Array.isArray(s)||ArrayBuffer.isView(s)){if(!e(s,r))return!1}else if(!r(s))return!1}return!0}(e))return null;const r=new t(function e(t,r=3){let n=0;let s=0;let i=-1;for(;++i<t.length;){const r=t[i];Array.isArray(r)||ArrayBuffer.isView(r)?n+=e(r):s++}return n+(0===n&&s<r?r:s)}(e));return function(e,t,r=3){(function e(t,r,n,s){let i=-1,o=0;for(;++i<t.length;){const u=t[i];Array.isArray(u)||ArrayBuffer.isView(u)?s=e(u,r,n,s):o<n&&(r[s++]=u,o++)}return o>0&&o<n&&(r[s++]=0),s})(e,t,r,0)}(e,r),r}function ae(e,t,r={}){const{flattenArrays:n=!1}=r;let s=e;if("string"==typeof s&&0===s.indexOf("#/"))return`#${s}`;if(Array.isArray(s)){const e=n&&ue(s);if(!e)return s.map(e=>ae(e,t,r));s=e}if(ArrayBuffer.isView(s)&&t){if(t.isImage(s)){return`#/images/${t.addImage(s)}`}return`#/accessors/${t.addBuffer(s)}`}if(null!==s&&"object"==typeof s){const e={};for(const n in s)e[n]=ae(s[n],t,r);return e}return s}const fe=1179937895,ce=1313821514,he=5130562,le=!0,ge=12,de=8;class ye{constructor(e={}){this.byteLength=0,this.json={buffers:[{byteLength:0}],bufferViews:[],accessors:[],images:[],meshes:[]},this.sourceBuffers=[],this.log=e.log||console}getByteLength(){return this.byteLength}isImage(e){return function(e){const t=se(e);return!!t&&t.mimeType}(e)}encodeSync(e={}){return this.encodeAsGLB(e)}encodeAsGLB(e={}){return this._createGLBBuffer(e)}addApplicationData(e,t,r={}){const n=r.packTypedArrays?ae(t,this,r):t;return this.json[e]=n,this}addBuffer(e,t={size:3}){const r=this.addBufferView(e),n={size:t.size,componentType:k(e),count:Math.round(e.length/t.size)};return this.addAccessor(r,Object.assign(n,t))}addBufferView(e){const t=e.byteLength||e.length;return this.json.bufferViews.push({buffer:0,byteOffset:this.byteLength,byteLength:t}),this.byteLength+=h(t),this.sourceBuffers.push(e),this.json.bufferViews.length-1}addAccessor(e,t){var r;return this.json.accessors.push({bufferView:e,type:(r=t.size,E[r-1]||E[0]),componentType:t.componentType,count:t.count}),this.json.accessors.length-1}_pack(){return this._packBinaryChunk(),{arrayBuffer:this.arrayBuffer,json:this.json}}_packBinaryChunk(){if(this.arrayBuffer)return;const e=this.byteLength,t=new ArrayBuffer(e),r=new Uint8Array(t);let n=0;for(let e=0;e<this.sourceBuffers.length;e++){n=g(this.sourceBuffers[e],r,n)}this.json.buffers[0].byteLength=e,this.arrayBuffer=t,this.sourceBuffers=[]}_createGLBBuffer(e={}){this._packBinaryChunk();const t=this.arrayBuffer;e.magic&&console.warn("Custom glTF magic number no longer supported");const r=ge+de,n=this._convertObjectToJsonChunk(this.json),s=h(n.byteLength),i=s+r,o=i+de+h(t.byteLength),u=new ArrayBuffer(o),a=new DataView(u);a.setUint32(0,fe,le),a.setUint32(4,2,le),a.setUint32(8,o,le),a.setUint32(12,n.byteLength,le),a.setUint32(16,ce,le),l(u,n,r);for(let e=0;e<s-n.byteLength;++e)a.setUint8(r+n.byteLength+e,32);const f=h(t.byteLength);a.setUint32(i+0,f,le),a.setUint32(i+4,he,le),l(u,t,i+de);for(let e=0;e<f-t.byteLength;++e)a.setUint8(i+de+t.byteLength+e,0);return u}_getInternalCounts(){return{buffers:this.json.buffers.length,bufferViews:this.json.bufferViews.length,accessors:this.json.accessors.length,images:this.json.images.length}}_convertObjectToJsonChunk(e){const t=JSON.stringify(e);return new c.TextEncoder("utf8").encode(t)}}class me extends ye{constructor(e={}){super(e),this.DracoWriter=e.DracoWriter,this.DracoLoader=e.DracoLoader}addApplicationData(e,t,r={}){const n=r.packTypedArrays?ae(t,this,r):t;return this.json[e]=n,this}addExtraData(e,t,r={}){const n=r.packedTypedArrays?ae(t,this,r):t;return this.json.extras=this.json.extras||{},this.json.extras[e]=n,this}addExtension(e,t,r={}){i(t);const n=r.packTypedArrays?ae(t,this,r):t;return this.json.extensions=this.json.extensions||{},this.json.extensions[e]=n,this.registerUsedExtension(e),this}addRequiredExtension(e,t,r={}){i(t);const n=r.packTypedArrays?ae(t,this,r):t;return this.addExtension(e,n),this.registerRequiredExtension(e),this}registerUsedExtension(e){this.json.extensionsUsed=this.json.extensionsUsed||[],this.json.extensionsUsed.find(t=>t===e)||this.json.extensionsUsed.push(e)}registerRequiredExtension(e){this.registerUsedExtension(e),this.json.extensionsRequired=this.json.extensionsRequired||[],this.json.extensionsRequired.find(t=>t===e)||this.json.extensionsRequired.push(e)}addMesh(e,t,r=4){const n={primitives:[{attributes:this._addAttributes(e),indices:t,mode:r}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(n),this.json.meshes.length-1}addPointCloud(e){const t={primitives:[{attributes:this._addAttributes(e),mode:0}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(t),this.json.meshes.length-1}addCompressedMesh(e,t,r=4){if(!this.DracoWriter||!this.DracoLoader)throw new Error("DracoWriter/DracoLoader not available");this.registerRequiredExtension(q);const n=this.DracoWriter.encodeSync({attributes:e}),s=this.DracoLoader.parseSync({attributes:e}),i=this._addFauxAttributes(s.attributes),o=this.addBufferView(n),u={primitives:[{attributes:i,mode:r,extensions:{[q]:{bufferView:o,attributes:i}}}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(u),this.json.meshes.length-1}addCompressedPointCloud(e){if(!this.DracoWriter||!this.DracoLoader)throw new Error("DracoWriter/DracoLoader not available");e.mode=0;const t=this.DracoWriter.encodeSync(e,{pointcloud:!0}),r=this.addBufferView(t),n={primitives:[{attributes:{},mode:0,extensions:{[G]:{bufferView:r}}}]};return this.registerRequiredExtension(G),this.json.meshes=this.json.meshes||[],this.json.meshes.push(n),this.json.meshes.length-1}addImage(e){const t=this.addBufferView(e),r=oe(e)||{};if(r){const{mimeType:e,width:n,height:s}=r;this.json.images.push({bufferView:t,mimeType:e,width:n,height:s})}else this.json.images.push({bufferView:t});return this.json.images.length-1}}var pe={name:"GLB",extensions:["glb"],encodeSync:function(e,t){return(new me).encodeSync(e,t)}};r.d(t,"GLTFLoader",function(){return Y}),r.d(t,"GLTFWriter",function(){return pe}),r.d(t,"GLTFParser",function(){return Q}),r.d(t,"GLTFBuilder",function(){return me}),r.d(t,"GLBParser",function(){return I}),r.d(t,"GLBBuilder",function(){return ye}),r.d(t,"KHR_DRACO_MESH_COMPRESSION",function(){return q}),r.d(t,"UBER_POINT_CLOUD_EXTENSION",function(){return G}),r.d(t,"_parseGLBSync",function(){return A})},function(e,t,r){"undefined"==typeof TextDecoder?e.exports=r(8):e.exports={TextEncoder:TextEncoder,TextDecoder:TextDecoder}}])}); |
{ | ||
"name": "@loaders.gl/gltf", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Framework-independent loader for the glTF format", | ||
@@ -41,5 +41,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/core": "1.0.0", | ||
"@loaders.gl/images": "1.0.0" | ||
"@loaders.gl/core": "1.0.1", | ||
"@loaders.gl/images": "1.0.1" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
816040
11
+ Added@loaders.gl/core@1.0.1(transitive)
+ Added@loaders.gl/images@1.0.1(transitive)
- Removed@loaders.gl/core@1.0.0(transitive)
- Removed@loaders.gl/images@1.0.0(transitive)
Updated@loaders.gl/core@1.0.1
Updated@loaders.gl/images@1.0.1