babylonjs-loaders 9.22.2 → 9.25.0

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.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";function n(e,t,n,s){const r={externalResourceFunction:s};return n&&(r.uri="file:"===t?n:t+n),ArrayBuffer.isView(e)?GLTFValidator.validateBytes(e,r):GLTFValidator.validateString(e,r)}function s(){const e=[];onmessage=t=>{const s=t.data;switch(s.id){case"init":importScripts(s.url);break;case"validate":n(s.data,s.rootUrl,s.fileName,t=>new Promise((n,s)=>{const r=e.length;e.push({resolve:n,reject:s}),postMessage({id:"getExternalResource",index:r,uri:t})})).then(e=>{postMessage({id:"validate.resolve",value:e})},e=>{postMessage({id:"validate.reject",reason:e})});break;case"getExternalResource.resolve":e[s.index].resolve(s.value);break;case"getExternalResource.reject":e[s.index].reject(s.reason)}}}class r{static ValidateAsync(e,o,a,i){return"function"==typeof Worker?new Promise((l,d)=>{const c=`${n}(${s})()`,u=URL.createObjectURL(new Blob([c],{type:"application/javascript"})),h=new Worker(u),m=e=>{h.removeEventListener("error",m),h.removeEventListener("message",f),d(e)},f=e=>{const t=e.data;switch(t.id){case"getExternalResource":i(t.uri).then(e=>{h.postMessage({id:"getExternalResource.resolve",index:t.index,value:e},[e.buffer])},e=>{h.postMessage({id:"getExternalResource.reject",index:t.index,reason:e})});break;case"validate.resolve":h.removeEventListener("error",m),h.removeEventListener("message",f),r._LastResults=t.value,l(t.value),h.terminate();break;case"validate.reject":h.removeEventListener("error",m),h.removeEventListener("message",f),d(t.reason),h.terminate()}};if(h.addEventListener("error",m),h.addEventListener("message",f),h.postMessage({id:"init",url:t.Tools.GetBabylonScriptURL(this.Configuration.url)}),ArrayBuffer.isView(e)){const t=e.slice();h.postMessage({id:"validate",data:t,rootUrl:o,fileName:a},[t.buffer])}else h.postMessage({id:"validate",data:e,rootUrl:o,fileName:a})}):(this._LoadScriptPromise||(this._LoadScriptPromise=t.Tools.LoadBabylonScriptAsync(this.Configuration.url)),this._LoadScriptPromise.then(()=>n(e,o,a,i)))}}r.Configuration={url:`${t.Tools._DefaultCdnUrl}/gltf_validator.js`},r._LastResults=null;var o={__proto__:null,GLTFValidation:r};const a="Z2xURg",i="gltf",l={".gltf":{isBinary:!1,mimeType:"model/gltf+json"},".glb":{isBinary:!0,mimeType:"model/gltf-binary"}},d=e=>-1!==e.indexOf("asset")&&-1!==e.indexOf("version")||e.startsWith("data:base64,"+a)||e.startsWith("data:;base64,"+a)||e.startsWith("data:application/octet-stream;base64,"+a)||e.startsWith("data:model/gltf-binary;base64,"+a);function c(e,t,n){try{return Promise.resolve(new Uint8Array(e,t,n))}catch(e){return Promise.reject(e)}}var u,h,m;e.GLTFLoaderCoordinateSystemMode=void 0,(u=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}))[u.AUTO=0]="AUTO",u[u.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED",e.GLTFLoaderAnimationStartMode=void 0,(h=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}))[h.NONE=0]="NONE",h[h.FIRST=1]="FIRST",h[h.ALL=2]="ALL",e.GLTFLoaderState=void 0,(m=e.GLTFLoaderState||(e.GLTFLoaderState={}))[m.LOADING=0]="LOADING",m[m.READY=1]="READY",m[m.COMPLETE=2]="COMPLETE";class f{constructor(){this.alwaysComputeBoundingBox=!1,this.alwaysComputeSkeletonRootNode=!1,this.animationStartMode=e.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.compileShadowGenerators=!1,this.coordinateSystemMode=e.GLTFLoaderCoordinateSystemMode.AUTO,this.createInstances=!0,this.loadAllMaterials=!1,this.loadMorphTargets=!0,this.useMaxMorphTargetInfluencers=!0,this.loadNodeAnimations=!0,this.loadOnlyMaterials=!1,this.loadSkins=!0,this.skipMaterials=!1,this.targetFps=60,this.transparencyAsCoverage=!1,this.useClipPlane=!1,this.useGltfTextureNames=!1,this.useRangeRequests=!1,this.useSRGBBuffers=!0,this.validate=!1,this.useOpenPBR=!1,this.dontUseTransmissionHelper=!1}}const p=new f;class b extends f{constructor(){super(...arguments),this.extensionOptions={},this.preprocessUrlAsync=e=>Promise.resolve(e)}copyFrom(e){var t,n,s,r,o,a,i,l,d,c,u,h,m,f,p,b,A,_,g,y,O,E,L,T,v,N,M;e&&(this.alwaysComputeBoundingBox=null!==(t=e.alwaysComputeBoundingBox)&&void 0!==t?t:this.alwaysComputeBoundingBox,this.alwaysComputeSkeletonRootNode=null!==(n=e.alwaysComputeSkeletonRootNode)&&void 0!==n?n:this.alwaysComputeSkeletonRootNode,this.animationStartMode=null!==(s=e.animationStartMode)&&void 0!==s?s:this.animationStartMode,this.capturePerformanceCounters=null!==(r=e.capturePerformanceCounters)&&void 0!==r?r:this.capturePerformanceCounters,this.compileMaterials=null!==(o=e.compileMaterials)&&void 0!==o?o:this.compileMaterials,this.compileShadowGenerators=null!==(a=e.compileShadowGenerators)&&void 0!==a?a:this.compileShadowGenerators,this.coordinateSystemMode=null!==(i=e.coordinateSystemMode)&&void 0!==i?i:this.coordinateSystemMode,this.createInstances=null!==(l=e.createInstances)&&void 0!==l?l:this.createInstances,this.customRootNode=e.customRootNode,this.extensionOptions=null!==(d=e.extensionOptions)&&void 0!==d?d:this.extensionOptions,this.loadAllMaterials=null!==(c=e.loadAllMaterials)&&void 0!==c?c:this.loadAllMaterials,this.loadMorphTargets=null!==(u=e.loadMorphTargets)&&void 0!==u?u:this.loadMorphTargets,this.loadNodeAnimations=null!==(h=e.loadNodeAnimations)&&void 0!==h?h:this.loadNodeAnimations,this.loadOnlyMaterials=null!==(m=e.loadOnlyMaterials)&&void 0!==m?m:this.loadOnlyMaterials,this.loadSkins=null!==(f=e.loadSkins)&&void 0!==f?f:this.loadSkins,this.loggingEnabled=null!==(p=e.loggingEnabled)&&void 0!==p?p:this.loggingEnabled,this.onCameraLoaded=e.onCameraLoaded,this.onMaterialLoaded=e.onMaterialLoaded,this.onMeshLoaded=e.onMeshLoaded,this.onParsed=e.onParsed,this.onSkinLoaded=e.onSkinLoaded,this.onTextureLoaded=e.onTextureLoaded,this.onValidated=e.onValidated,this.preprocessUrlAsync=null!==(b=e.preprocessUrlAsync)&&void 0!==b?b:this.preprocessUrlAsync,this.skipMaterials=null!==(A=e.skipMaterials)&&void 0!==A?A:this.skipMaterials,this.targetFps=null!==(_=e.targetFps)&&void 0!==_?_:this.targetFps,this.transparencyAsCoverage=null!==(g=e.transparencyAsCoverage)&&void 0!==g?g:this.transparencyAsCoverage,this.useClipPlane=null!==(y=e.useClipPlane)&&void 0!==y?y:this.useClipPlane,this.useGltfTextureNames=null!==(O=e.useGltfTextureNames)&&void 0!==O?O:this.useGltfTextureNames,this.useMaxMorphTargetInfluencers=null!==(E=e.useMaxMorphTargetInfluencers)&&void 0!==E?E:this.useMaxMorphTargetInfluencers,this.useOpenPBR=null!==(L=e.useOpenPBR)&&void 0!==L?L:this.useOpenPBR,this.useRangeRequests=null!==(T=e.useRangeRequests)&&void 0!==T?T:this.useRangeRequests,this.useSRGBBuffers=null!==(v=e.useSRGBBuffers)&&void 0!==v?v:this.useSRGBBuffers,this.validate=null!==(N=e.validate)&&void 0!==N?N:this.validate,this.dontUseTransmissionHelper=null!==(M=e.dontUseTransmissionHelper)&&void 0!==M?M:this.dontUseTransmissionHelper)}}class A extends b{constructor(e){super(),this.onParsedObservable=new t.Observable,this.onMeshLoadedObservable=new t.Observable,this.onSkinLoadedObservable=new t.Observable,this.onTextureLoadedObservable=new t.Observable,this.onMaterialLoadedObservable=new t.Observable,this.onCameraLoadedObservable=new t.Observable,this.onCompleteObservable=new t.Observable,this.onErrorObservable=new t.Observable,this.onDisposeObservable=new t.Observable,this.onExtensionLoadedObservable=new t.Observable,this.onValidatedObservable=new t.Observable,this._loader=null,this._state=null,this._requests=new Array,this.name=i,this.extensions=l,this.onLoaderStateChangedObservable=new t.Observable,this._logIndentLevel=0,this._loggingEnabled=!1,this._log=this._logDisabled,this._capturePerformanceCounters=!1,this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled,this.copyFrom(Object.assign(Object.assign({},p),e))}set onParsed(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),e&&(this._onParsedObserver=this.onParsedObservable.add(e))}set onMeshLoaded(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),e&&(this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e))}set onSkinLoaded(e){this._onSkinLoadedObserver&&this.onSkinLoadedObservable.remove(this._onSkinLoadedObserver),e&&(this._onSkinLoadedObserver=this.onSkinLoadedObservable.add(t=>e(t.node,t.skinnedNode)))}set onTextureLoaded(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),e&&(this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e))}set onMaterialLoaded(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),e&&(this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e))}set onCameraLoaded(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),e&&(this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e))}set onComplete(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)}set onError(e){this._onErrorObserver&&this.onErrorObservable.remove(this._onErrorObserver),this._onErrorObserver=this.onErrorObservable.add(e)}set onDispose(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)}set onExtensionLoaded(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)}get loggingEnabled(){return this._loggingEnabled}set loggingEnabled(e){this._loggingEnabled!==e&&(this._loggingEnabled=e,this._loggingEnabled?this._log=this._logEnabled:this._log=this._logDisabled)}get capturePerformanceCounters(){return this._capturePerformanceCounters}set capturePerformanceCounters(e){this._capturePerformanceCounters!==e&&(this._capturePerformanceCounters=e,this._capturePerformanceCounters?(this._startPerformanceCounter=this._startPerformanceCounterEnabled,this._endPerformanceCounter=this._endPerformanceCounterEnabled):(this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled))}set onValidated(e){this._onValidatedObserver&&this.onValidatedObservable.remove(this._onValidatedObserver),this._onValidatedObserver=this.onValidatedObservable.add(e)}dispose(){this._loader&&(this._loader.dispose(),this._loader=null);for(const e of this._requests)e.abort();this._requests.length=0,delete this._progressCallback,this.preprocessUrlAsync=e=>Promise.resolve(e),this.onMeshLoadedObservable.clear(),this.onSkinLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCameraLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onExtensionLoadedObservable.clear(),this.onDisposeObservable.notifyObservers(void 0),this.onDisposeObservable.clear()}loadFile(e,n,s,r,o,a,i,l){if(ArrayBuffer.isView(n))return this._loadBinary(e,n,s,r,i,l),null;this._progressCallback=o;const d=n.name||t.Tools.GetFilename(n);if(a){if(this.useRangeRequests){this.validate&&t.Logger.Warn("glTF validation is not supported when range requests are enabled");const s={abort:()=>{},onCompleteObservable:new t.Observable},o={readAsync:(t,s)=>new Promise((r,o)=>{this._loadFile(e,n,e=>{r(new Uint8Array(e))},!0,e=>{o(e)},e=>{e.setRequestHeader("Range",`bytes=${t}-${t+s-1}`)})}),byteLength:0};return this._unpackBinaryAsync(new t.DataReader(o)).then(e=>{s.onCompleteObservable.notifyObservers(s),r(e)},i?e=>i(void 0,e):void 0),s}return this._loadFile(e,n,n=>{this._validate(e,new Uint8Array(n,0,n.byteLength),s,d),this._unpackBinaryAsync(new t.DataReader({readAsync:(e,t)=>c(n,e,t),byteLength:n.byteLength})).then(e=>{r(e)},i?e=>i(void 0,e):void 0)},!0,i)}return this._loadFile(e,n,t=>{try{this._validate(e,t,s,d),r({json:this._parseJson(t)})}catch(e){i&&i()}},!1,i)}_loadBinary(e,n,s,r,o,a){this._validate(e,new Uint8Array(n.buffer,n.byteOffset,n.byteLength),s,a),this._unpackBinaryAsync(new t.DataReader({readAsync:(e,t)=>function(e,t,n){try{if(t<0||t>=e.byteLength)throw new RangeError("Offset is out of range.");if(t+n>e.byteLength)throw new RangeError("Length is out of range.");return Promise.resolve(new Uint8Array(e.buffer,e.byteOffset+t,n))}catch(e){return Promise.reject(e)}}(n,e,t),byteLength:n.byteLength})).then(e=>{r(e)},o?e=>o(void 0,e):void 0)}importMeshAsync(e,t,n,s,r,o){return Promise.resolve().then(()=>(this.onParsedObservable.notifyObservers(n),this.onParsedObservable.clear(),this._log(`Loading ${o||""}`),this._loader=this._getLoader(n),this._loader.importMeshAsync(e,t,null,n,s,r,o)))}loadAsync(e,t,n,s,r){return Promise.resolve().then(()=>(this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),this._log(`Loading ${r||""}`),this._loader=this._getLoader(t),this._loader.loadAsync(e,t,n,s,r)))}loadAssetContainerAsync(e,n,s,r,o){return Promise.resolve().then(()=>{this.onParsedObservable.notifyObservers(n),this.onParsedObservable.clear(),this._log(`Loading ${o||""}`),this._loader=this._getLoader(n);const a=new t.AssetContainer(e),i=[];this.onMaterialLoadedObservable.add(e=>{i.push(e)});const l=[];this.onTextureLoadedObservable.add(e=>{l.push(e)});const d=[];this.onCameraLoadedObservable.add(e=>{d.push(e)});const c=[];return this.onMeshLoadedObservable.add(e=>{e.morphTargetManager&&c.push(e.morphTargetManager)}),this._loader.importMeshAsync(null,e,a,n,s,r,o).then(e=>(Array.prototype.push.apply(a.geometries,e.geometries),Array.prototype.push.apply(a.meshes,e.meshes),Array.prototype.push.apply(a.particleSystems,e.particleSystems),Array.prototype.push.apply(a.skeletons,e.skeletons),Array.prototype.push.apply(a.animationGroups,e.animationGroups),Array.prototype.push.apply(a.materials,i),Array.prototype.push.apply(a.textures,l),Array.prototype.push.apply(a.lights,e.lights),Array.prototype.push.apply(a.transformNodes,e.transformNodes),Array.prototype.push.apply(a.cameras,d),Array.prototype.push.apply(a.morphTargetManagers,c),a))})}canDirectLoad(e){return d(e)}directLoad(e,n){if(n.startsWith("base64,"+a)||n.startsWith(";base64,"+a)||n.startsWith("application/octet-stream;base64,"+a)||n.startsWith("model/gltf-binary;base64,"+a)){const s=t.DecodeBase64UrlToBinary(n);return this._validate(e,new Uint8Array(s,0,s.byteLength)),this._unpackBinaryAsync(new t.DataReader({readAsync:(e,t)=>c(s,e,t),byteLength:s.byteLength}))}return this._validate(e,n),Promise.resolve({json:this._parseJson(n)})}createPlugin(e){return new A(e[i])}get loaderState(){return this._state}whenCompleteAsync(){return new Promise((e,t)=>{this.onCompleteObservable.addOnce(()=>{e()}),this.onErrorObservable.addOnce(e=>{t(e)})})}_setState(t){this._state!==t&&(this._state=t,this.onLoaderStateChangedObservable.notifyObservers(this._state),this._log(e.GLTFLoaderState[this._state]))}_loadFile(e,t,n,s,r,o){const a=e._loadFile(t,n,e=>{this._onProgress(e,a)},!0,s,r,o);return a.onCompleteObservable.add(()=>{a._lengthComputable=!0,a._total=a._loaded}),this._requests.push(a),a}_onProgress(e,t){if(!this._progressCallback)return;t._lengthComputable=e.lengthComputable,t._loaded=e.loaded,t._total=e.total;let n=!0,s=0,r=0;for(const e of this._requests){if(void 0===e._lengthComputable||void 0===e._loaded||void 0===e._total)return;n=n&&e._lengthComputable,s+=e._loaded,r+=e._total}this._progressCallback({lengthComputable:n,loaded:s,total:n?r:0})}_validate(e,n,s="",o=""){this.validate&&(this._startPerformanceCounter("Validate JSON"),r.ValidateAsync(n,s,o,t=>this.preprocessUrlAsync(s+t).then(t=>e._loadFileAsync(t,void 0,!0,!0).then(e=>new Uint8Array(e,0,e.byteLength)))).then(e=>{this._endPerformanceCounter("Validate JSON"),this.onValidatedObservable.notifyObservers(e),this.onValidatedObservable.clear()},e=>{this._endPerformanceCounter("Validate JSON"),t.Tools.Warn(`Failed to validate: ${e.message}`),this.onValidatedObservable.clear()}))}_getLoader(e){const t=e.json.asset||{};this._log(`Asset version: ${t.version}`),t.minVersion&&this._log(`Asset minimum version: ${t.minVersion}`),t.generator&&this._log(`Asset generator: ${t.generator}`);const n=A._parseVersion(t.version);if(!n)throw new Error("Invalid version: "+t.version);if(void 0!==t.minVersion){const e=A._parseVersion(t.minVersion);if(!e)throw new Error("Invalid minimum version: "+t.minVersion);if(A._compareVersion(e,{major:2,minor:0})>0)throw new Error("Incompatible minimum version: "+t.minVersion)}const s={1:A._CreateGLTF1Loader,2:A._CreateGLTF2Loader}[n.major];if(!s)throw new Error("Unsupported version: "+t.version);return s(this)}_parseJson(e){this._startPerformanceCounter("Parse JSON"),this._log(`JSON length: ${e.length}`);const t=JSON.parse(e);return this._endPerformanceCounter("Parse JSON"),t}_unpackBinaryAsync(e){return this._startPerformanceCounter("Unpack Binary"),e.loadAsync(20).then(()=>{const n=e.readUint32();if(1179937895!==n)throw new t.RuntimeError("Unexpected magic: "+n,t.ErrorCodes.GLTFLoaderUnexpectedMagicError);const s=e.readUint32();this.loggingEnabled&&this._log(`Binary version: ${s}`);const r=e.readUint32();let o;switch(this.useRangeRequests||r===e.buffer.byteLength||t.Logger.Warn(`Length in header does not match actual data length: ${r} != ${e.buffer.byteLength}`),s){case 1:o=this._unpackBinaryV1Async(e,r);break;case 2:o=this._unpackBinaryV2Async(e,r);break;default:throw new Error("Unsupported version: "+s)}return this._endPerformanceCounter("Unpack Binary"),o})}_unpackBinaryV1Async(e,t){const n=e.readUint32(),s=e.readUint32();if(0!==s)throw new Error(`Unexpected content format: ${s}`);const r=t-e.byteOffset,o={json:this._parseJson(e.readString(n)),bin:null};if(0!==r){const t=e.byteOffset;o.bin={readAsync:(n,s)=>e.buffer.readAsync(t+n,s),byteLength:r}}return Promise.resolve(o)}_unpackBinaryV2Async(e,t){const n=1313821514,s=e.readUint32();if(e.readUint32()!==n)throw new Error("First chunk format is not JSON");return e.byteOffset+s===t?e.loadAsync(s).then(()=>({json:this._parseJson(e.readString(s)),bin:null})):e.loadAsync(s+8).then(()=>{const r={json:this._parseJson(e.readString(s)),bin:null},o=()=>{const s=e.readUint32();switch(e.readUint32()){case n:throw new Error("Unexpected JSON chunk");case 5130562:{const t=e.byteOffset;r.bin={readAsync:(n,s)=>e.buffer.readAsync(t+n,s),byteLength:s},e.skipBytes(s);break}default:e.skipBytes(s)}return e.byteOffset!==t?e.loadAsync(8).then(o):Promise.resolve(r)};return o()})}static _parseVersion(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};const t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null}static _compareVersion(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0}_logOpen(e){this._log(e),this._logIndentLevel++}_logClose(){--this._logIndentLevel}_logEnabled(e){const n=A._logSpaces.substring(0,2*this._logIndentLevel);t.Logger.Log(`${n}${e}`)}_logDisabled(e){}_startPerformanceCounterEnabled(e){t.Tools.StartPerformanceCounter(e)}_startPerformanceCounterDisabled(e){}_endPerformanceCounterEnabled(e){t.Tools.EndPerformanceCounter(e)}_endPerformanceCounterDisabled(e){}}A.IncrementalLoading=!0,A.HomogeneousCoordinates=!1,A._logSpaces=" ";let _=!1;function g(){_||(_=!0,t.RegisterSceneLoaderPlugin(new A))}g();var y={__proto__:null,GLTFFileLoader:A,get GLTFLoaderAnimationStartMode(){return e.GLTFLoaderAnimationStartMode},get GLTFLoaderCoordinateSystemMode(){return e.GLTFLoaderCoordinateSystemMode},GLTFLoaderDefaultOptions:p,get GLTFLoaderState(){return e.GLTFLoaderState},RegisterGLTFFileLoader:g};const O="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==O){O.BABYLON=O.BABYLON||{};for(const e in y)O.BABYLON[e]=y[e];for(const e in o)O.BABYLON[e]=o[e]}var E,L,T,v,N,M,S,C,x;Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError,function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.FLOAT=5126]="FLOAT"}(E||(E={})),function(e){e[e.FRAGMENT=35632]="FRAGMENT",e[e.VERTEX=35633]="VERTEX"}(L||(L={})),function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.INT=5124]="INT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT",e[e.FLOAT_VEC2=35664]="FLOAT_VEC2",e[e.FLOAT_VEC3=35665]="FLOAT_VEC3",e[e.FLOAT_VEC4=35666]="FLOAT_VEC4",e[e.INT_VEC2=35667]="INT_VEC2",e[e.INT_VEC3=35668]="INT_VEC3",e[e.INT_VEC4=35669]="INT_VEC4",e[e.BOOL=35670]="BOOL",e[e.BOOL_VEC2=35671]="BOOL_VEC2",e[e.BOOL_VEC3=35672]="BOOL_VEC3",e[e.BOOL_VEC4=35673]="BOOL_VEC4",e[e.FLOAT_MAT2=35674]="FLOAT_MAT2",e[e.FLOAT_MAT3=35675]="FLOAT_MAT3",e[e.FLOAT_MAT4=35676]="FLOAT_MAT4",e[e.SAMPLER_2D=35678]="SAMPLER_2D"}(T||(T={})),function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"}(v||(v={})),function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9728]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"}(N||(N={})),function(e){e[e.ALPHA=6406]="ALPHA",e[e.RGB=6407]="RGB",e[e.RGBA=6408]="RGBA",e[e.LUMINANCE=6409]="LUMINANCE",e[e.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA"}(M||(M={})),function(e){e[e.FRONT=1028]="FRONT",e[e.BACK=1029]="BACK",e[e.FRONT_AND_BACK=1032]="FRONT_AND_BACK"}(S||(S={})),function(e){e[e.ZERO=0]="ZERO",e[e.ONE=1]="ONE",e[e.SRC_COLOR=768]="SRC_COLOR",e[e.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",e[e.DST_COLOR=774]="DST_COLOR",e[e.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.DST_ALPHA=772]="DST_ALPHA",e[e.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",e[e.CONSTANT_COLOR=32769]="CONSTANT_COLOR",e[e.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",e[e.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",e[e.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",e[e.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"}(C||(C={}));class R{static SetMatrix(e,n,s,r,o){let a=null;if("MODEL"===s.semantic?a=n.getWorldMatrix():"PROJECTION"===s.semantic?a=e.getProjectionMatrix():"VIEW"===s.semantic?a=e.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===s.semantic?a=t.Matrix.Transpose(n.getWorldMatrix().multiply(e.getViewMatrix()).invert()):"MODELVIEW"===s.semantic?a=n.getWorldMatrix().multiply(e.getViewMatrix()):"MODELVIEWPROJECTION"===s.semantic?a=n.getWorldMatrix().multiply(e.getTransformMatrix()):"MODELINVERSE"===s.semantic?a=n.getWorldMatrix().invert():"VIEWINVERSE"===s.semantic?a=e.getViewMatrix().invert():"PROJECTIONINVERSE"===s.semantic?a=e.getProjectionMatrix().invert():"MODELVIEWINVERSE"===s.semantic?a=n.getWorldMatrix().multiply(e.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===s.semantic?a=n.getWorldMatrix().multiply(e.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===s.semantic&&(a=t.Matrix.Transpose(n.getWorldMatrix().invert())),a)switch(s.type){case T.FLOAT_MAT2:o.setMatrix2x2(r,t.Matrix.GetAsMatrix2x2(a));break;case T.FLOAT_MAT3:o.setMatrix3x3(r,t.Matrix.GetAsMatrix3x3(a));break;case T.FLOAT_MAT4:o.setMatrix(r,a)}}static SetUniform(e,n,s,r){switch(r){case T.FLOAT:return e.setFloat(n,s),!0;case T.FLOAT_VEC2:return e.setVector2(n,t.Vector2.FromArray(s)),!0;case T.FLOAT_VEC3:return e.setVector3(n,t.Vector3.FromArray(s)),!0;case T.FLOAT_VEC4:return e.setVector4(n,t.Vector4.FromArray(s)),!0;default:return!1}}static GetWrapMode(e){switch(e){case v.CLAMP_TO_EDGE:return t.Texture.CLAMP_ADDRESSMODE;case v.MIRRORED_REPEAT:return t.Texture.MIRROR_ADDRESSMODE;case v.REPEAT:default:return t.Texture.WRAP_ADDRESSMODE}}static GetByteStrideFromType(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}}static GetTextureFilterMode(e){switch(e){case N.LINEAR:case N.LINEAR_MIPMAP_NEAREST:case N.LINEAR_MIPMAP_LINEAR:return t.Texture.TRILINEAR_SAMPLINGMODE;case N.NEAREST:case N.NEAREST_MIPMAP_NEAREST:return t.Texture.NEAREST_SAMPLINGMODE;default:return t.Texture.BILINEAR_SAMPLINGMODE}}static GetBufferFromBufferView(e,t,n,s,r){n=t.byteOffset+n;const o=e.loadedBufferViews[t.buffer];if(n+s>o.byteLength)throw new Error("Buffer access is out of range");const a=o.buffer;switch(n+=o.byteOffset,r){case E.BYTE:return new Int8Array(a,n,s);case E.UNSIGNED_BYTE:return new Uint8Array(a,n,s);case E.SHORT:return new Int16Array(a,n,s);case E.UNSIGNED_SHORT:return new Uint16Array(a,n,s);default:return new Float32Array(a,n,s)}}static GetBufferFromAccessor(e,t){const n=e.bufferViews[t.bufferView],s=t.count*R.GetByteStrideFromType(t);return R.GetBufferFromBufferView(e,n,t.byteOffset,s,t.componentType)}static DecodeBufferToText(e){let t="";const n=e.byteLength;for(let s=0;s<n;++s)t+=String.fromCharCode(e[s]);return t}static GetDefaultMaterial(e){if(!R._DefaultMaterial){t.Effect.ShadersStore.GLTFDefaultMaterialVertexShader=["precision highp float;","","uniform mat4 worldView;","uniform mat4 projection;","","attribute vec3 position;","","void main(void)","{"," gl_Position = projection * worldView * vec4(position, 1.0);","}"].join("\n"),t.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");const n={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},s={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};R._DefaultMaterial=new t.ShaderMaterial("GLTFDefaultMaterial",e,n,s),R._DefaultMaterial.setColor4("u_emission",new t.Color4(.5,.5,.5,1))}return R._DefaultMaterial}}R._DefaultMaterial=null,function(e){e[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT"}(x||(x={}));class w{constructor(e){this._pos=0,this.currentToken=x.UNKNOWN,this.currentIdentifier="",this.currentString="",this.isLetterOrDigitPattern=/^[a-zA-Z0-9]+$/,this._toParse=e,this._maxPos=e.length}getNextToken(){if(this.isEnd())return x.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=x.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=x.IDENTIFIER,this.currentIdentifier=this.currentString;!this.isEnd()&&(this.isLetterOrDigitPattern.test(this.currentString=this.peek())||"_"===this.currentString);)this.currentIdentifier+=this.currentString,this.forward();return this.currentToken}peek(){return this._toParse[this._pos]}read(){return this._toParse[this._pos++]}forward(){this._pos++}isEnd(){return this._pos>=this._maxPos}}const I=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],P=["world","view","projection","worldView","worldViewProjection","mBones"],F=["translation","rotation","scale"],B=["position","rotationQuaternion","scaling"],V=(e,t,n)=>{for(const s in e){const r=e[s];n[t][s]=r}},D=e=>{if(e)for(let t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},k=e=>{if("NORMAL"===e.semantic)return"normal";if("POSITION"===e.semantic)return"position";if("JOINT"===e.semantic)return"matricesIndices";if("WEIGHT"===e.semantic)return"matricesWeights";if("COLOR"===e.semantic)return"color";if(e.semantic&&-1!==e.semantic.indexOf("TEXCOORD_")){const t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},G=e=>{let n;if(e.translation||e.rotation||e.scale){const s=t.Vector3.FromArray(e.scale||[1,1,1]),r=t.Quaternion.FromArray(e.rotation||[0,0,0,1]),o=t.Vector3.FromArray(e.translation||[0,0,0]);n=t.Matrix.Compose(s,r,o)}else n=t.Matrix.FromArray(e.matrix);return n},U=(e,n,s,r)=>{for(let e=0;e<r.bones.length;e++)if(r.bones[e].name===s)return r.bones[e];const o=e.nodes;for(const a in o){const i=o[a];if(!i.jointName)continue;const l=i.children;for(let o=0;o<l.length;o++){const d=e.nodes[l[o]];if(d.jointName&&d.jointName===s){const s=G(i),o=new t.Bone(i.name||"",r,U(e,n,i.jointName,r),s);return o.id=a,o}}}return null},j=(e,t)=>{for(let n=0;n<e.length;n++){const s=e[n];for(let e=0;e<s.node.children.length;e++)if(s.node.children[e]===t)return s.bone}return null},H=(e,t)=>{const n=e.nodes;let s=n[t];if(s)return{node:s,id:t};for(const e in n)if(s=n[e],s.jointName===t)return{node:s,id:e};return null},W=(e,t)=>{for(let n=0;n<e.jointNames.length;n++)if(e.jointNames[n]===t)return!0;return!1},Y=(e,n,s,r,o)=>{if(o||(e.scene._blockEntityCollection=!!e.assetContainer,(o=new t.Mesh(n.name||"",e.scene))._parentContainer=e.assetContainer,e.scene._blockEntityCollection=!1,o.id=r),!n.babylonNode)return o;const a=[];let i=null;const l=[],d=[],c=[],u=[];for(let n=0;n<s.length;n++){const r=s[n],o=e.meshes[r];if(o)for(let n=0;n<o.primitives.length;n++){const s=new t.VertexData,r=o.primitives[n];r.mode;const h=r.attributes;let m,f;for(const n in h)if(m=e.accessors[h[n]],f=R.GetBufferFromAccessor(e,m),"NORMAL"===n)s.normals=new Float32Array(f.length),s.normals.set(f);else if("POSITION"===n){if(A.HomogeneousCoordinates){s.positions=new Float32Array(f.length-f.length/4);for(let e=0;e<f.length;e+=4)s.positions[e]=f[e],s.positions[e+1]=f[e+1],s.positions[e+2]=f[e+2]}else s.positions=new Float32Array(f.length),s.positions.set(f);d.push(s.positions.length)}else if(-1!==n.indexOf("TEXCOORD_")){const e=Number(n.split("_")[1]),r=t.VertexBuffer.UVKind+(0===e?"":e+1),o=new Float32Array(f.length);o.set(f),D(o),s.set(o,r)}else"JOINT"===n?(s.matricesIndices=new Float32Array(f.length),s.matricesIndices.set(f)):"WEIGHT"===n?(s.matricesWeights=new Float32Array(f.length),s.matricesWeights.set(f)):"COLOR"===n&&(s.colors=new Float32Array(f.length),s.colors.set(f));if(m=e.accessors[r.indices],m)f=R.GetBufferFromAccessor(e,m),s.indices=new Int32Array(f.length),s.indices.set(f),u.push(s.indices.length);else{const e=[];for(let t=0;t<s.positions.length/3;t++)e.push(t);s.indices=new Int32Array(e),u.push(s.indices.length)}i?i.merge(s):i=s;const p=e.scene.getMaterialById(r.material);a.push(null===p?R.GetDefaultMaterial(e.scene):p),l.push(0===l.length?0:l[l.length-1]+d[d.length-2]),c.push(0===c.length?0:c[c.length-1]+u[u.length-2])}}let h;e.scene._blockEntityCollection=!!e.assetContainer,a.length>1?(h=new t.MultiMaterial("multimat"+r,e.scene),h.subMaterials=a):h=new t.StandardMaterial("multimat"+r,e.scene),1===a.length&&(h=a[0]),h._parentContainer=e.assetContainer,o.material||(o.material=h),new t.Geometry(r,e.scene,i,!1,o),o.computeWorldMatrix(!0),e.scene._blockEntityCollection=!1,o.subMeshes=[];let m=0;for(let n=0;n<s.length;n++){const r=s[n],a=e.meshes[r];if(a)for(let e=0;e<a.primitives.length;e++)a.primitives[e].mode,t.SubMesh.AddToMesh(m,l[m],d[m],c[m],u[m],o,o,!0),m++}return o},J=(e,t,n,s)=>{e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=n),e.scaling&&(e.scaling=s)},q=(e,n,s)=>{let r=null;if(e.importOnlyMeshes&&(n.skin||n.meshes)&&e.importMeshesNames&&e.importMeshesNames.length>0&&-1===e.importMeshesNames.indexOf(n.name||""))return null;if(n.skin){if(n.meshes){const o=e.skins[n.skin],a=Y(e,n,n.meshes,s,n.babylonNode);a.skeleton=e.scene.getLastSkeletonById(n.skin),null===a.skeleton&&(a.skeleton=((e,n,s,r)=>{if(r||(r=new t.Skeleton(n.name||"","",e.scene)),!n.babylonSkeleton)return r;const o=[],a=[];((e,n,s,r)=>{for(const o in e.nodes){const a=e.nodes[o],i=o;if(!a.jointName||W(s,a.jointName))continue;const l=G(a),d=new t.Bone(a.name||"",n,null,l);d.id=i,r.push({bone:d,node:a,id:i})}for(let e=0;e<r.length;e++){const t=r[e],n=t.node.children;for(let e=0;e<n.length;e++){let s=null;for(let t=0;t<r.length;t++)if(r[t].id===n[e]){s=r[t];break}s&&(s.bone._parent=t.bone,t.bone.children.push(s.bone))}}})(e,r,n,o),r.bones=[];for(let s=0;s<n.jointNames.length;s++){const i=H(e,n.jointNames[s]);if(!i)continue;const l=i.node;if(!l){t.Tools.Warn("Joint named "+n.jointNames[s]+" does not exist");continue}const d=i.id,c=e.scene.getBoneById(d);if(c){r.bones.push(c);continue}let u,h=null;for(let o=0;o<s;o++){const s=H(e,n.jointNames[o]);if(!s)continue;const a=s.node;if(!a){t.Tools.Warn("Joint named "+n.jointNames[o]+" does not exist when looking for parent");continue}const i=a.children;if(i){u=!1;for(let t=0;t<i.length;t++)if(i[t]===d){h=U(e,n,n.jointNames[o],r),u=!0;break}if(u)break}}const m=G(l);!h&&o.length>0&&(h=j(o,d),h&&-1===a.indexOf(h)&&a.push(h)),new t.Bone(l.jointName||"",r,h,m).id=d}const i=r.bones;r.bones=[];for(let t=0;t<n.jointNames.length;t++){const s=H(e,n.jointNames[t]);if(s)for(let e=0;e<i.length;e++)if(i[e].id===s.id){r.bones.push(i[e]);break}}r.prepare();for(let e=0;e<a.length;e++)r.bones.push(a[e]);return r})(e,o,0,o.babylonSkeleton),o.babylonSkeleton||(o.babylonSkeleton=a.skeleton)),r=a}}else if(n.meshes)r=Y(e,n,n.mesh?[n.mesh]:n.meshes,s,n.babylonNode);else if(!n.light||n.babylonNode||e.importOnlyMeshes){if(n.camera&&!n.babylonNode&&!e.importOnlyMeshes){const s=e.cameras[n.camera];if(s){if(e.scene._blockEntityCollection=!!e.assetContainer,"orthographic"===s.type){const s=new t.FreeCamera(n.camera,t.Vector3.Zero(),e.scene,!1);s.name=n.name||"",s.mode=t.Camera.ORTHOGRAPHIC_CAMERA,s.attachControl(),r=s,s._parentContainer=e.assetContainer}else if("perspective"===s.type){const o=s[s.type],a=new t.FreeCamera(n.camera,t.Vector3.Zero(),e.scene,!1);a.name=n.name||"",a.attachControl(),o.aspectRatio||(o.aspectRatio=e.scene.getEngine().getRenderWidth()/e.scene.getEngine().getRenderHeight()),o.znear&&o.zfar&&(a.maxZ=o.zfar,a.minZ=o.znear),r=a,a._parentContainer=e.assetContainer}e.scene._blockEntityCollection=!1}}}else{const s=e.lights[n.light];if(s)if("ambient"===s.type){const o=s[s.type],a=new t.HemisphericLight(n.light,t.Vector3.Zero(),e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),r=a}else if("directional"===s.type){const o=s[s.type],a=new t.DirectionalLight(n.light,t.Vector3.Zero(),e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),r=a}else if("point"===s.type){const o=s[s.type],a=new t.PointLight(n.light,t.Vector3.Zero(),e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),r=a}else if("spot"===s.type){const o=s[s.type],a=new t.SpotLight(n.light,t.Vector3.Zero(),t.Vector3.Zero(),0,0,e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),o.fallOfAngle&&(a.angle=o.fallOfAngle),o.fallOffExponent&&(a.exponent=o.fallOffExponent),r=a}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===r){e.scene._blockEntityCollection=!!e.assetContainer;const s=new t.Mesh(n.name||"",e.scene);s._parentContainer=e.assetContainer,e.scene._blockEntityCollection=!1,n.babylonNode=s,r=s}}if(null!==r){if(n.matrix&&r instanceof t.Mesh)((e,n)=>{if(n.matrix){const s=new t.Vector3(0,0,0),r=new t.Quaternion,o=new t.Vector3(0,0,0);t.Matrix.FromArray(n.matrix).decompose(o,r,s),J(e,s,r,o)}else n.translation&&n.rotation&&n.scale&&J(e,t.Vector3.FromArray(n.translation),t.Quaternion.FromArray(n.rotation),t.Vector3.FromArray(n.scale));e.computeWorldMatrix(!0)})(r,n);else{const e=n.translation||[0,0,0],s=n.rotation||[0,0,0,1],o=n.scale||[1,1,1];J(r,t.Vector3.FromArray(e),t.Quaternion.FromArray(s),t.Vector3.FromArray(o))}r.updateCache(!0),n.babylonNode=r}return r},Z=(e,t,n,s=!1)=>{const r=e.nodes[t];let o=null;if(s=!(e.importOnlyMeshes&&!s&&e.importMeshesNames)||-1!==e.importMeshesNames.indexOf(r.name||"")||0===e.importMeshesNames.length,!r.jointName&&s&&(o=q(e,r,t),null!==o&&(o.id=t,o.parent=n)),r.children)for(let t=0;t<r.children.length;t++)Z(e,r.children[t],o,s)},$=e=>{let n=e.currentScene;if(n)for(let t=0;t<n.nodes.length;t++)Z(e,n.nodes[t],null);else for(const t in e.scenes){n=e.scenes[t];for(let t=0;t<n.nodes.length;t++)Z(e,n.nodes[t],null)}(e=>{for(const n in e.animations){const s=e.animations[n];if(!s.channels||!s.samplers)continue;let r=null;for(let o=0;o<s.channels.length;o++){const a=s.channels[o],i=s.samplers[a.sampler];if(!i)continue;let l,d;s.parameters?(l=s.parameters[i.input],d=s.parameters[i.output]):(l=i.input,d=i.output);const c=R.GetBufferFromAccessor(e,e.accessors[l]),u=R.GetBufferFromAccessor(e,e.accessors[d]),h=a.target.id;let m=e.scene.getNodeById(h);if(null===m&&(m=e.scene.getNodeByName(h)),null===m){t.Tools.Warn("Creating animation named "+n+". But cannot find node named "+h+" to attach to");continue}const f=m instanceof t.Bone;let p=a.target.path;const b=F.indexOf(p);-1!==b&&(p=B[b]);let A=t.Animation.ANIMATIONTYPE_MATRIX;f||("rotationQuaternion"===p?(A=t.Animation.ANIMATIONTYPE_QUATERNION,m.rotationQuaternion=new t.Quaternion):A=t.Animation.ANIMATIONTYPE_VECTOR3);let _=null;const g=[];let y=0,O=!1;f&&r&&r.getKeys().length===c.length&&(_=r,O=!0),O||(e.scene._blockEntityCollection=!!e.assetContainer,_=new t.Animation(n,f?"_matrix":p,1,A,t.Animation.ANIMATIONLOOPMODE_CYCLE),e.scene._blockEntityCollection=!1);for(let e=0;e<c.length;e++){let n;if("rotationQuaternion"===p?(n=t.Quaternion.FromArray([u[y],u[y+1],u[y+2],u[y+3]]),y+=4):(n=t.Vector3.FromArray([u[y],u[y+1],u[y+2]]),y+=3),f){const s=m;let o=t.Vector3.Zero(),a=new t.Quaternion,i=t.Vector3.Zero(),l=s.getBaseMatrix();O&&r&&(l=r.getKeys()[e].value),l.decompose(i,a,o),"position"===p?o=n:"rotationQuaternion"===p?a=n:i=n,n=t.Matrix.Compose(i,a,o)}O?r&&(r.getKeys()[e].value=n):g.push({frame:c[e],value:n})}!O&&_&&(_.setKeys(g),m.animations.push(_)),r=_,e.scene.stopAnimation(m),e.scene.beginAnimation(m,0,c[c.length-1],!0,1)}}})(e);for(let t=0;t<e.scene.skeletons.length;t++){const n=e.scene.skeletons[t];e.scene.beginAnimation(n,0,Number.MAX_VALUE,!0,1)}},K=(e,t,n)=>{for(const s in t.uniforms){const r=t.uniforms[s],o=t.parameters[r];if(e.currentIdentifier===s&&o.semantic&&!o.source&&!o.node){const e=I.indexOf(o.semantic);if(-1!==e)return delete n[s],P[e]}}return e.currentIdentifier},Q=e=>{for(const t in e.materials)ee.LoadMaterialAsync(e,t,()=>{},()=>{})};class X{static CreateRuntime(e,t,n){const s={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:t,rootUrl:n,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[],assetContainer:null};return e.extensions&&V(e.extensions,"extensions",s),e.extensionsUsed&&V(e.extensionsUsed,"extensionsUsed",s),e.buffers&&((e,t)=>{for(const n in e){const s=e[n];t.buffers[n]=s,t.buffersCount++}})(e.buffers,s),e.bufferViews&&V(e.bufferViews,"bufferViews",s),e.accessors&&V(e.accessors,"accessors",s),e.meshes&&V(e.meshes,"meshes",s),e.lights&&V(e.lights,"lights",s),e.cameras&&V(e.cameras,"cameras",s),e.nodes&&V(e.nodes,"nodes",s),e.images&&V(e.images,"images",s),e.textures&&V(e.textures,"textures",s),e.shaders&&((e,t)=>{for(const n in e){const s=e[n];t.shaders[n]=s,t.shaderscount++}})(e.shaders,s),e.programs&&V(e.programs,"programs",s),e.samplers&&V(e.samplers,"samplers",s),e.techniques&&V(e.techniques,"techniques",s),e.materials&&V(e.materials,"materials",s),e.animations&&V(e.animations,"animations",s),e.skins&&V(e.skins,"skins",s),e.scenes&&(s.scenes=e.scenes),e.scene&&e.scenes&&(s.currentScene=e.scenes[e.scene]),s}static LoadBufferAsync(e,n,s,r,o){const a=e.buffers[n];t.Tools.IsBase64(a.uri)?setTimeout(()=>s(new Uint8Array(t.Tools.DecodeBase64(a.uri)))):t.Tools.LoadFile(e.rootUrl+a.uri,e=>s(new Uint8Array(e)),o,void 0,!0,e=>{e&&r(e.status+" "+e.statusText)})}static LoadTextureBufferAsync(e,n,s,r){const o=e.textures[n];if(!o||!o.source)return void r("");if(o.babylonTexture)return void s(null);const a=e.images[o.source];t.Tools.IsBase64(a.uri)?setTimeout(()=>s(new Uint8Array(t.Tools.DecodeBase64(a.uri)))):t.Tools.LoadFile(e.rootUrl+a.uri,e=>s(new Uint8Array(e)),void 0,void 0,!0,e=>{e&&r(e.status+" "+e.statusText)})}static CreateTextureAsync(e,n,s,r){const o=e.textures[n];if(o.babylonTexture)return void r(o.babylonTexture);const a=e.samplers[o.sampler],i=a.minFilter===N.NEAREST_MIPMAP_NEAREST||a.minFilter===N.NEAREST_MIPMAP_LINEAR||a.minFilter===N.LINEAR_MIPMAP_NEAREST||a.minFilter===N.LINEAR_MIPMAP_LINEAR,l=t.Texture.BILINEAR_SAMPLINGMODE,d=null==s?new Blob:new Blob([t.GetBlobBufferSource(s)]),c=URL.createObjectURL(d),u=()=>URL.revokeObjectURL(c),h=new t.Texture(c,e.scene,!i,!0,l,u,u);void 0!==a.wrapS&&(h.wrapU=R.GetWrapMode(a.wrapS)),void 0!==a.wrapT&&(h.wrapV=R.GetWrapMode(a.wrapT)),h.name=n,o.babylonTexture=h,r(h)}static LoadShaderStringAsync(e,n,s,r){const o=e.shaders[n];if(t.Tools.IsBase64(o.uri)){const e=atob(o.uri.split(",")[1]);s&&s(e)}else t.Tools.LoadFile(e.rootUrl+o.uri,s,void 0,void 0,!1,e=>{e&&r&&r(e.status+" "+e.statusText)})}static LoadMaterialAsync(e,n,s,r){const o=e.materials[n];if(!o.technique)return void(r&&r("No technique found."));const a=e.techniques[o.technique];if(!a){e.scene._blockEntityCollection=!!e.assetContainer;const r=new t.StandardMaterial(n,e.scene);return r._parentContainer=e.assetContainer,e.scene._blockEntityCollection=!1,r.diffuseColor=new t.Color3(.5,.5,.5),r.sideOrientation=t.Material.CounterClockWiseSideOrientation,void s(r)}const i=e.programs[a.program],l=a.states,d=t.Effect.ShadersStore[i.vertexShader+"VertexShader"],c=t.Effect.ShadersStore[i.fragmentShader+"PixelShader"];let u="",h="";const m=new w(d),f=new w(c),p={},b=[],A=[],_=[];for(const e in a.uniforms){const t=a.uniforms[e],n=a.parameters[t];if(p[e]=n,!n.semantic||n.node||n.source)n.type===T.SAMPLER_2D?_.push(e):b.push(e);else{const t=I.indexOf(n.semantic);-1!==t?(b.push(P[t]),delete p[e]):b.push(e)}}for(const e in a.attributes){const t=a.attributes[e],n=a.parameters[t];if(n.semantic){const e=k(n);e&&A.push(e)}}for(;!m.isEnd()&&m.getNextToken();){if(m.currentToken!==x.IDENTIFIER){u+=m.currentString;continue}let e=!1;for(const t in a.attributes){const n=a.attributes[t],s=a.parameters[n];if(m.currentIdentifier===t&&s.semantic){u+=k(s),e=!0;break}}e||(u+=K(m,a,p))}for(;!f.isEnd()&&f.getNextToken();)f.currentToken===x.IDENTIFIER?h+=K(f,a,p):h+=f.currentString;const g={vertex:i.vertexShader+n,fragment:i.fragmentShader+n},y={attributes:A,uniforms:b,samplers:_,needAlphaBlending:l&&l.enable&&-1!==l.enable.indexOf(3042)};t.Effect.ShadersStore[i.vertexShader+n+"VertexShader"]=u,t.Effect.ShadersStore[i.fragmentShader+n+"PixelShader"]=h;const O=new t.ShaderMaterial(n,e.scene,g,y);if(O.onError=((e,t,n)=>(s,r)=>{t.dispose(!0),n("Cannot compile program named "+e.name+". Error: "+r+". Default material will be applied")})(i,O,r),O.onCompiled=((e,t,n,s,r,o)=>a=>{((e,t,n,s,r)=>{const o=s.values||n.parameters,a=n.uniforms;for(const n in r){const i=r[n],l=i.type;let d=o[a[n]];if(void 0===d&&(d=i.value),!d)continue;const c=e=>n=>{i.value&&e&&(t.setTexture(e,n),delete r[e])};l===T.SAMPLER_2D?ee.LoadTextureAsync(e,s.values?d:i.value,c(n),()=>c(null)):i.value&&R.SetUniform(t,n,s.values?d:i.value,l)&&delete r[n]}})(e,t,n,s,r),t.onBind=a=>{((e,t,n,s,r,o,a)=>{const i=o.values||r.parameters;for(const a in n){const l=n[a],d=l.type;if(d===T.FLOAT_MAT2||d===T.FLOAT_MAT3||d===T.FLOAT_MAT4)if(!l.semantic||l.source||l.node){if(l.semantic&&(l.source||l.node)){let e=t.scene.getNodeByName(l.source||l.node||"");if(null===e&&(e=t.scene.getNodeById(l.source||l.node||"")),null===e)continue;R.SetMatrix(t.scene,e,l,a,s.getEffect())}}else R.SetMatrix(t.scene,e,l,a,s.getEffect());else{const e=i[r.uniforms[a]];if(!e)continue;if(d===T.SAMPLER_2D){const n=t.textures[o.values?e:l.value].babylonTexture;if(null==n)continue;s.getEffect().setTexture(a,n)}else R.SetUniform(s.getEffect(),a,e,d)}}a(s)})(a,e,r,t,n,s,o)}})(e,O,a,o,p,s),O.sideOrientation=t.Material.CounterClockWiseSideOrientation,l&&l.functions){const e=l.functions;e.cullFace&&e.cullFace[0]!==S.BACK&&(O.backFaceCulling=!1);const n=e.blendFuncSeparate;n&&(n[0]===C.SRC_ALPHA&&n[1]===C.ONE_MINUS_SRC_ALPHA&&n[2]===C.ONE&&n[3]===C.ONE?O.alphaMode=t.Constants.ALPHA_COMBINE:n[0]===C.ONE&&n[1]===C.ONE&&n[2]===C.ZERO&&n[3]===C.ONE?O.alphaMode=t.Constants.ALPHA_ONEONE:n[0]===C.SRC_ALPHA&&n[1]===C.ONE&&n[2]===C.ZERO&&n[3]===C.ONE?O.alphaMode=t.Constants.ALPHA_ADD:n[0]===C.ZERO&&n[1]===C.ONE_MINUS_SRC_COLOR&&n[2]===C.ONE&&n[3]===C.ONE?O.alphaMode=t.Constants.ALPHA_SUBTRACT:n[0]===C.DST_COLOR&&n[1]===C.ZERO&&n[2]===C.ONE&&n[3]===C.ONE?O.alphaMode=t.Constants.ALPHA_MULTIPLY:n[0]===C.SRC_ALPHA&&n[1]===C.ONE_MINUS_SRC_COLOR&&n[2]===C.ONE&&n[3]===C.ONE&&(O.alphaMode=t.Constants.ALPHA_MAXIMIZED))}}}class z{static RegisterExtension(e){z.Extensions[e.name]?t.Tools.Error('Tool with the same name "'+e.name+'" already exists'):z.Extensions[e.name]=e}dispose(){}_importMeshAsync(e,n,s,r,o,a,i,l){return n.useRightHandedSystem=!0,ee.LoadRuntimeAsync(n,s,r,n=>{n.assetContainer=o,n.importOnlyMeshes=!0,""===e?n.importMeshesNames=[]:"string"==typeof e?n.importMeshesNames=[e]:!e||e instanceof Array?(n.importMeshesNames=[],t.Tools.Warn("Argument meshesNames must be of type string or string[]")):n.importMeshesNames=[e],this._createNodes(n);const s=[],r=[];for(const e in n.nodes){const r=n.nodes[e];r.babylonNode instanceof t.AbstractMesh&&s.push(r.babylonNode)}for(const e in n.skins){const s=n.skins[e];s.babylonSkeleton instanceof t.Skeleton&&r.push(s.babylonSkeleton)}this._loadBuffersAsync(n,()=>{this._loadShadersAsync(n,()=>{Q(n),$(n),!A.IncrementalLoading&&a&&a(s,r)})}),A.IncrementalLoading&&a&&a(s,r)},l),!0}importMeshAsync(e,t,n,s,r,o){return new Promise((a,i)=>{this._importMeshAsync(e,t,s,r,n,(e,t)=>{a({meshes:e,particleSystems:[],skeletons:t,animationGroups:[],lights:[],transformNodes:[],geometries:[],spriteManagers:[]})},o,e=>{i(new Error(e))})})}_loadAsync(e,t,n,s,r,o){e.useRightHandedSystem=!0,ee.LoadRuntimeAsync(e,t,n,e=>{ee.LoadRuntimeExtensionsAsync(e,()=>{this._createNodes(e),this._loadBuffersAsync(e,()=>{this._loadShadersAsync(e,()=>{Q(e),$(e),A.IncrementalLoading||s()})}),A.IncrementalLoading&&s()},o)},o)}loadAsync(e,t,n,s){return r=this,o=void 0,i=function*(){return yield new Promise((r,o)=>{this._loadAsync(e,t,n,()=>{r()},s,e=>{o(new Error(e))})})},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{l(i.next(e))}catch(e){t(e)}}function s(e){try{l(i.throw(e))}catch(e){t(e)}}function l(t){var r;t.done?e(t.value):(r=t.value,r instanceof a?r:new a(function(e){e(r)})).then(n,s)}l((i=i.apply(r,o||[])).next())});var r,o,a,i}_loadShadersAsync(e,n){let s=!1;const r=(s,r)=>{ee.LoadShaderStringAsync(e,s,o=>{o instanceof ArrayBuffer||(e.loadedShaderCount++,o&&(t.Effect.ShadersStore[s+(r.type===L.VERTEX?"VertexShader":"PixelShader")]=o),e.loadedShaderCount===e.shaderscount&&n())},()=>{t.Tools.Error("Error when loading shader program named "+s+" located at "+r.uri)})};for(const n in e.shaders){s=!0;const o=e.shaders[n];o?r.bind(this,n,o)():t.Tools.Error("No shader named: "+n)}s||n()}_loadBuffersAsync(e,n){let s=!1;const r=(s,r)=>{ee.LoadBufferAsync(e,s,o=>{e.loadedBufferCount++,o&&(o.byteLength!=e.buffers[s].byteLength&&t.Tools.Error("Buffer named "+s+" is length "+o.byteLength+". Expected: "+r.byteLength),e.loadedBufferViews[s]=o),e.loadedBufferCount===e.buffersCount&&n()},()=>{t.Tools.Error("Error when loading buffer named "+s+" located at "+r.uri)})};for(const n in e.buffers){s=!0;const o=e.buffers[n];o?r.bind(this,n,o)():t.Tools.Error("No buffer named: "+n)}s||n()}_createNodes(e){let t=e.currentScene;if(t)for(let n=0;n<t.nodes.length;n++)Z(e,t.nodes[n],null);else for(const n in e.scenes){t=e.scenes[n];for(let n=0;n<t.nodes.length;n++)Z(e,t.nodes[n],null)}}}z.Extensions={};class ee{constructor(e){this._name=e}get name(){return this._name}loadRuntimeAsync(e,t,n,s,r){return!1}loadRuntimeExtensionsAsync(e,t,n){return!1}loadBufferAsync(e,t,n,s,r){return!1}loadTextureBufferAsync(e,t,n,s){return!1}createTextureAsync(e,t,n,s,r){return!1}loadShaderStringAsync(e,t,n,s){return!1}loadMaterialAsync(e,t,n,s){return!1}static LoadRuntimeAsync(e,t,n,s,r){ee._ApplyExtensions(o=>o.loadRuntimeAsync(e,t,n,s,r),()=>{setTimeout(()=>{s&&s(X.CreateRuntime(t.json,e,n))})})}static LoadRuntimeExtensionsAsync(e,t,n){ee._ApplyExtensions(s=>s.loadRuntimeExtensionsAsync(e,t,n),()=>{setTimeout(()=>{t()})})}static LoadBufferAsync(e,t,n,s,r){ee._ApplyExtensions(o=>o.loadBufferAsync(e,t,n,s,r),()=>{X.LoadBufferAsync(e,t,n,s,r)})}static LoadTextureAsync(e,t,n,s){ee._LoadTextureBufferAsync(e,t,r=>{r&&ee._CreateTextureAsync(e,t,r,n,s)},s)}static LoadShaderStringAsync(e,t,n,s){ee._ApplyExtensions(r=>r.loadShaderStringAsync(e,t,n,s),()=>{X.LoadShaderStringAsync(e,t,n,s)})}static LoadMaterialAsync(e,t,n,s){ee._ApplyExtensions(r=>r.loadMaterialAsync(e,t,n,s),()=>{X.LoadMaterialAsync(e,t,n,s)})}static _LoadTextureBufferAsync(e,t,n,s){ee._ApplyExtensions(r=>r.loadTextureBufferAsync(e,t,n,s),()=>{X.LoadTextureBufferAsync(e,t,n,s)})}static _CreateTextureAsync(e,t,n,s,r){ee._ApplyExtensions(o=>o.createTextureAsync(e,t,n,s,r),()=>{X.CreateTextureAsync(e,t,n,s)})}static _ApplyExtensions(e,t){for(const t in z.Extensions)if(e(z.Extensions[t]))return;t()}}A._CreateGLTF1Loader=()=>new z;class te extends ee{constructor(){super("KHR_binary_glTF")}loadRuntimeAsync(e,t,n,s){const r=t.json.extensionsUsed;return!(!r||-1===r.indexOf(this.name)||!t.bin||(this._bin=t.bin,s(X.CreateRuntime(t.json,e,n)),0))}loadBufferAsync(e,t,n,s){return-1!==e.extensionsUsed.indexOf(this.name)&&"binary_glTF"===t&&(this._bin.readAsync(0,this._bin.byteLength).then(n,e=>s(e.message)),!0)}loadTextureBufferAsync(e,t,n){const s=e.textures[t],r=e.images[s.source];if(!r.extensions||!(this.name in r.extensions))return!1;const o=r.extensions[this.name],a=e.bufferViews[o.bufferView];return n(R.GetBufferFromBufferView(e,a,0,a.byteLength,E.UNSIGNED_BYTE)),!0}loadShaderStringAsync(e,t,n){const s=e.shaders[t];if(!s.extensions||!(this.name in s.extensions))return!1;const r=s.extensions[this.name],o=e.bufferViews[r.bufferView],a=R.GetBufferFromBufferView(e,o,0,o.byteLength,E.UNSIGNED_BYTE);return setTimeout(()=>{const e=R.DecodeBufferToText(a);n(e)}),!0}}z.RegisterExtension(new te);class ne extends ee{constructor(){super("KHR_materials_common")}loadRuntimeExtensionsAsync(e){if(!e.extensions)return!1;const n=e.extensions[this.name];if(!n)return!1;const s=n.lights;if(s)for(const n in s){const r=s[n];switch(r.type){case"ambient":{const n=new t.HemisphericLight(r.name,new t.Vector3(0,1,0),e.scene),s=r.ambient;s&&(n.diffuse=t.Color3.FromArray(s.color||[1,1,1]));break}case"point":{const n=new t.PointLight(r.name,new t.Vector3(10,10,10),e.scene),s=r.point;s&&(n.diffuse=t.Color3.FromArray(s.color||[1,1,1]));break}case"directional":{const n=new t.DirectionalLight(r.name,new t.Vector3(0,-1,0),e.scene),s=r.directional;s&&(n.diffuse=t.Color3.FromArray(s.color||[1,1,1]));break}case"spot":{const n=r.spot;n&&(new t.SpotLight(r.name,new t.Vector3(0,10,0),new t.Vector3(0,-1,0),n.fallOffAngle||Math.PI,n.fallOffExponent||0,e.scene).diffuse=t.Color3.FromArray(n.color||[1,1,1]));break}default:t.Tools.Warn('GLTF Material Common extension: light type "'+r.type+"” not supported")}}return!1}loadMaterialAsync(e,n,s,r){const o=e.materials[n];if(!o||!o.extensions)return!1;const a=o.extensions[this.name];if(!a)return!1;const i=new t.StandardMaterial(n,e.scene);return i.sideOrientation=t.Material.CounterClockWiseSideOrientation,"CONSTANT"===a.technique&&(i.disableLighting=!0),i.backFaceCulling=void 0!==a.doubleSided&&!a.doubleSided,i.alpha=void 0===a.values.transparency?1:a.values.transparency,i.specularPower=void 0===a.values.shininess?0:a.values.shininess,"string"==typeof a.values.ambient?this._loadTexture(e,a.values.ambient,i,"ambientTexture",r):i.ambientColor=t.Color3.FromArray(a.values.ambient||[0,0,0]),"string"==typeof a.values.diffuse?this._loadTexture(e,a.values.diffuse,i,"diffuseTexture",r):i.diffuseColor=t.Color3.FromArray(a.values.diffuse||[0,0,0]),"string"==typeof a.values.emission?this._loadTexture(e,a.values.emission,i,"emissiveTexture",r):i.emissiveColor=t.Color3.FromArray(a.values.emission||[0,0,0]),"string"==typeof a.values.specular?this._loadTexture(e,a.values.specular,i,"specularTexture",r):i.specularColor=t.Color3.FromArray(a.values.specular||[0,0,0]),!0}_loadTexture(e,t,n,s,r){X.LoadTextureBufferAsync(e,t,r=>{X.CreateTextureAsync(e,t,r,e=>n[s]=e)},r)}}z.RegisterExtension(new ne);var se={__proto__:null,get EBlendingFunction(){return C},get EComponentType(){return E},get ECullingType(){return S},get EParameterType(){return T},get EShaderType(){return L},get ETextureFilterType(){return N},get ETextureFormat(){return M},get ETextureWrapMode(){return v},GLTFBinaryExtension:te,GLTFLoader:z,GLTFLoaderBase:X,GLTFLoaderExtension:ee,GLTFMaterialsCommonExtension:ne,GLTFUtils:R};const re="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==re){re.BABYLON=re.BABYLON||{},re.BABYLON.GLTF1=re.BABYLON.GLTF1||{};for(const e in se)re.BABYLON.GLTF1[e]=se[e]}e.GLTF1=se,e.GLTFFileLoader=A,e.GLTFLoaderDefaultOptions=p,e.GLTFValidation=r,e.RegisterGLTFFileLoader=g});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babylonjs")):"function"==typeof define&&define.amd?define(["exports","babylonjs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).BABYLON=e.BABYLON||{},e.BABYLON)}(this,function(e,t){"use strict";function n(e,t,n,s){const r={externalResourceFunction:s};return n&&(r.uri="file:"===t?n:t+n),ArrayBuffer.isView(e)?GLTFValidator.validateBytes(e,r):GLTFValidator.validateString(e,r)}function s(){const e=[];onmessage=t=>{const s=t.data;switch(s.id){case"init":importScripts(s.url);break;case"validate":n(s.data,s.rootUrl,s.fileName,t=>new Promise((n,s)=>{const r=e.length;e.push({resolve:n,reject:s}),postMessage({id:"getExternalResource",index:r,uri:t})})).then(e=>{postMessage({id:"validate.resolve",value:e})},e=>{postMessage({id:"validate.reject",reason:e})});break;case"getExternalResource.resolve":e[s.index].resolve(s.value);break;case"getExternalResource.reject":e[s.index].reject(s.reason)}}}class r{static ValidateAsync(e,o,a,i){return"function"==typeof Worker?new Promise((l,d)=>{const c=`${n}(${s})()`,u=URL.createObjectURL(new Blob([c],{type:"application/javascript"})),h=new Worker(u),f=e=>{h.removeEventListener("error",f),h.removeEventListener("message",m),d(e)},m=e=>{const t=e.data;switch(t.id){case"getExternalResource":i(t.uri).then(e=>{h.postMessage({id:"getExternalResource.resolve",index:t.index,value:e},[e.buffer])},e=>{h.postMessage({id:"getExternalResource.reject",index:t.index,reason:e})});break;case"validate.resolve":h.removeEventListener("error",f),h.removeEventListener("message",m),r._LastResults=t.value,l(t.value),h.terminate();break;case"validate.reject":h.removeEventListener("error",f),h.removeEventListener("message",m),d(t.reason),h.terminate()}};if(h.addEventListener("error",f),h.addEventListener("message",m),h.postMessage({id:"init",url:t.Tools.GetBabylonScriptURL(this.Configuration.url)}),ArrayBuffer.isView(e)){const t=e.slice();h.postMessage({id:"validate",data:t,rootUrl:o,fileName:a},[t.buffer])}else h.postMessage({id:"validate",data:e,rootUrl:o,fileName:a})}):(this._LoadScriptPromise||(this._LoadScriptPromise=t.Tools.LoadBabylonScriptAsync(this.Configuration.url)),this._LoadScriptPromise.then(()=>n(e,o,a,i)))}}r.Configuration={url:`${t.Tools._DefaultCdnUrl}/gltf_validator.js`},r._LastResults=null;var o={__proto__:null,GLTFValidation:r};const a="Z2xURg",i="gltf",l={".gltf":{isBinary:!1,mimeType:"model/gltf+json"},".glb":{isBinary:!0,mimeType:"model/gltf-binary"}},d=e=>-1!==e.indexOf("asset")&&-1!==e.indexOf("version")||e.startsWith("data:base64,"+a)||e.startsWith("data:;base64,"+a)||e.startsWith("data:application/octet-stream;base64,"+a)||e.startsWith("data:model/gltf-binary;base64,"+a);function c(e,t,n){try{return Promise.resolve(new Uint8Array(e,t,n))}catch(e){return Promise.reject(e)}}var u,h,f;e.GLTFLoaderCoordinateSystemMode=void 0,(u=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}))[u.AUTO=0]="AUTO",u[u.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED",e.GLTFLoaderAnimationStartMode=void 0,(h=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}))[h.NONE=0]="NONE",h[h.FIRST=1]="FIRST",h[h.ALL=2]="ALL",e.GLTFLoaderState=void 0,(f=e.GLTFLoaderState||(e.GLTFLoaderState={}))[f.LOADING=0]="LOADING",f[f.READY=1]="READY",f[f.COMPLETE=2]="COMPLETE";const m=e=>Promise.resolve(e);class p{constructor(){this.alwaysComputeBoundingBox=!1,this.alwaysComputeSkeletonRootNode=!1,this.animationStartMode=e.GLTFLoaderAnimationStartMode.FIRST,this.compileMaterials=!1,this.compileShadowGenerators=!1,this.coordinateSystemMode=e.GLTFLoaderCoordinateSystemMode.AUTO,this.createInstances=!0,this.loadAllMaterials=!1,this.loadMorphTargets=!0,this.useMaxMorphTargetInfluencers=!0,this.loadNodeAnimations=!0,this.loadOnlyMaterials=!1,this.loadSkins=!0,this.skipMaterials=!1,this.targetFps=60,this.transparencyAsCoverage=!1,this.useClipPlane=!1,this.useGltfTextureNames=!1,this.useRangeRequests=!1,this.useSRGBBuffers=!0,this.validate=!1,this.useOpenPBR=!1,this.dontUseTransmissionHelper=!1}}const b=new p;class A extends p{constructor(){super(...arguments),this.extensionOptions={},this.preprocessUrlAsync=m}copyFrom(e){var t,n,s,r,o,a,i,l,d,c,u,h,f,m,p,b,A,_,g,y,E,O,L,T,v,N,M;e&&(this.alwaysComputeBoundingBox=null!==(t=e.alwaysComputeBoundingBox)&&void 0!==t?t:this.alwaysComputeBoundingBox,this.alwaysComputeSkeletonRootNode=null!==(n=e.alwaysComputeSkeletonRootNode)&&void 0!==n?n:this.alwaysComputeSkeletonRootNode,this.animationStartMode=null!==(s=e.animationStartMode)&&void 0!==s?s:this.animationStartMode,this.capturePerformanceCounters=null!==(r=e.capturePerformanceCounters)&&void 0!==r?r:this.capturePerformanceCounters,this.compileMaterials=null!==(o=e.compileMaterials)&&void 0!==o?o:this.compileMaterials,this.compileShadowGenerators=null!==(a=e.compileShadowGenerators)&&void 0!==a?a:this.compileShadowGenerators,this.coordinateSystemMode=null!==(i=e.coordinateSystemMode)&&void 0!==i?i:this.coordinateSystemMode,this.createInstances=null!==(l=e.createInstances)&&void 0!==l?l:this.createInstances,this.customRootNode=e.customRootNode,this.extensionOptions=null!==(d=e.extensionOptions)&&void 0!==d?d:this.extensionOptions,this.loadAllMaterials=null!==(c=e.loadAllMaterials)&&void 0!==c?c:this.loadAllMaterials,this.loadMorphTargets=null!==(u=e.loadMorphTargets)&&void 0!==u?u:this.loadMorphTargets,this.loadNodeAnimations=null!==(h=e.loadNodeAnimations)&&void 0!==h?h:this.loadNodeAnimations,this.loadOnlyMaterials=null!==(f=e.loadOnlyMaterials)&&void 0!==f?f:this.loadOnlyMaterials,this.loadSkins=null!==(m=e.loadSkins)&&void 0!==m?m:this.loadSkins,this.loggingEnabled=null!==(p=e.loggingEnabled)&&void 0!==p?p:this.loggingEnabled,this.onCameraLoaded=e.onCameraLoaded,this.onMaterialLoaded=e.onMaterialLoaded,this.onMeshLoaded=e.onMeshLoaded,this.onParsed=e.onParsed,this.onSkinLoaded=e.onSkinLoaded,this.onTextureLoaded=e.onTextureLoaded,this.onValidated=e.onValidated,this.preprocessUrlAsync=null!==(b=e.preprocessUrlAsync)&&void 0!==b?b:this.preprocessUrlAsync,this.skipMaterials=null!==(A=e.skipMaterials)&&void 0!==A?A:this.skipMaterials,this.targetFps=null!==(_=e.targetFps)&&void 0!==_?_:this.targetFps,this.transparencyAsCoverage=null!==(g=e.transparencyAsCoverage)&&void 0!==g?g:this.transparencyAsCoverage,this.useClipPlane=null!==(y=e.useClipPlane)&&void 0!==y?y:this.useClipPlane,this.useGltfTextureNames=null!==(E=e.useGltfTextureNames)&&void 0!==E?E:this.useGltfTextureNames,this.useMaxMorphTargetInfluencers=null!==(O=e.useMaxMorphTargetInfluencers)&&void 0!==O?O:this.useMaxMorphTargetInfluencers,this.useOpenPBR=null!==(L=e.useOpenPBR)&&void 0!==L?L:this.useOpenPBR,this.useRangeRequests=null!==(T=e.useRangeRequests)&&void 0!==T?T:this.useRangeRequests,this.useSRGBBuffers=null!==(v=e.useSRGBBuffers)&&void 0!==v?v:this.useSRGBBuffers,this.validate=null!==(N=e.validate)&&void 0!==N?N:this.validate,this.dontUseTransmissionHelper=null!==(M=e.dontUseTransmissionHelper)&&void 0!==M?M:this.dontUseTransmissionHelper)}}class _ extends A{constructor(e){super(),this.onParsedObservable=new t.Observable,this.onMeshLoadedObservable=new t.Observable,this.onSkinLoadedObservable=new t.Observable,this.onTextureLoadedObservable=new t.Observable,this.onMaterialLoadedObservable=new t.Observable,this.onCameraLoadedObservable=new t.Observable,this.onCompleteObservable=new t.Observable,this.onErrorObservable=new t.Observable,this.onDisposeObservable=new t.Observable,this.onExtensionLoadedObservable=new t.Observable,this.onValidatedObservable=new t.Observable,this._loader=null,this._state=null,this._requests=new Array,this.name=i,this.extensions=l,this.onLoaderStateChangedObservable=new t.Observable,this._logIndentLevel=0,this._loggingEnabled=!1,this._log=this._logDisabled,this._capturePerformanceCounters=!1,this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled,this.copyFrom(Object.assign(Object.assign({},b),e))}get _isPreprocessUrlAsyncSet(){return this.preprocessUrlAsync!==m}set onParsed(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),e&&(this._onParsedObserver=this.onParsedObservable.add(e))}set onMeshLoaded(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),e&&(this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e))}set onSkinLoaded(e){this._onSkinLoadedObserver&&this.onSkinLoadedObservable.remove(this._onSkinLoadedObserver),e&&(this._onSkinLoadedObserver=this.onSkinLoadedObservable.add(t=>e(t.node,t.skinnedNode)))}set onTextureLoaded(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),e&&(this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e))}set onMaterialLoaded(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),e&&(this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e))}set onCameraLoaded(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),e&&(this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e))}set onComplete(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)}set onError(e){this._onErrorObserver&&this.onErrorObservable.remove(this._onErrorObserver),this._onErrorObserver=this.onErrorObservable.add(e)}set onDispose(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)}set onExtensionLoaded(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)}get loggingEnabled(){return this._loggingEnabled}set loggingEnabled(e){this._loggingEnabled!==e&&(this._loggingEnabled=e,this._loggingEnabled?this._log=this._logEnabled:this._log=this._logDisabled)}get capturePerformanceCounters(){return this._capturePerformanceCounters}set capturePerformanceCounters(e){this._capturePerformanceCounters!==e&&(this._capturePerformanceCounters=e,this._capturePerformanceCounters?(this._startPerformanceCounter=this._startPerformanceCounterEnabled,this._endPerformanceCounter=this._endPerformanceCounterEnabled):(this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled))}set onValidated(e){this._onValidatedObserver&&this.onValidatedObservable.remove(this._onValidatedObserver),this._onValidatedObserver=this.onValidatedObservable.add(e)}dispose(){this._loader&&(this._loader.dispose(),this._loader=null);for(const e of this._requests)e.abort();this._requests.length=0,delete this._progressCallback,this.preprocessUrlAsync=m,this.onMeshLoadedObservable.clear(),this.onSkinLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCameraLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onExtensionLoadedObservable.clear(),this.onDisposeObservable.notifyObservers(void 0),this.onDisposeObservable.clear()}loadFile(e,n,s,r,o,a,i,l){if(ArrayBuffer.isView(n))return this._loadBinary(e,n,s,r,i,l),null;this._progressCallback=o;const d=n.name||t.Tools.GetFilename(n);if(a){if(this.useRangeRequests){this.validate&&t.Logger.Warn("glTF validation is not supported when range requests are enabled");const s={abort:()=>{},onCompleteObservable:new t.Observable},o={readAsync:(t,s)=>new Promise((r,o)=>{this._loadFile(e,n,e=>{r(new Uint8Array(e))},!0,e=>{o(e)},e=>{e.setRequestHeader("Range",`bytes=${t}-${t+s-1}`)})}),byteLength:0};return this._unpackBinaryAsync(new t.DataReader(o)).then(e=>{s.onCompleteObservable.notifyObservers(s),r(e)},i?e=>i(void 0,e):void 0),s}return this._loadFile(e,n,n=>{this._validate(e,new Uint8Array(n,0,n.byteLength),s,d),this._unpackBinaryAsync(new t.DataReader({readAsync:(e,t)=>c(n,e,t),byteLength:n.byteLength})).then(e=>{r(e)},i?e=>i(void 0,e):void 0)},!0,i)}return this._loadFile(e,n,t=>{try{this._validate(e,t,s,d),r({json:this._parseJson(t)})}catch(e){i&&i()}},!1,i)}_loadBinary(e,n,s,r,o,a){this._validate(e,new Uint8Array(n.buffer,n.byteOffset,n.byteLength),s,a),this._unpackBinaryAsync(new t.DataReader({readAsync:(e,t)=>function(e,t,n){try{if(t<0||t>=e.byteLength)throw new RangeError("Offset is out of range.");if(t+n>e.byteLength)throw new RangeError("Length is out of range.");return Promise.resolve(new Uint8Array(e.buffer,e.byteOffset+t,n))}catch(e){return Promise.reject(e)}}(n,e,t),byteLength:n.byteLength})).then(e=>{r(e)},o?e=>o(void 0,e):void 0)}importMeshAsync(e,t,n,s,r,o){return Promise.resolve().then(()=>(this.onParsedObservable.notifyObservers(n),this.onParsedObservable.clear(),this._log(`Loading ${o||""}`),this._loader=this._getLoader(n),this._loader.importMeshAsync(e,t,null,n,s,r,o)))}loadAsync(e,t,n,s,r){return Promise.resolve().then(()=>(this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),this._log(`Loading ${r||""}`),this._loader=this._getLoader(t),this._loader.loadAsync(e,t,n,s,r)))}loadAssetContainerAsync(e,n,s,r,o){return Promise.resolve().then(()=>{this.onParsedObservable.notifyObservers(n),this.onParsedObservable.clear(),this._log(`Loading ${o||""}`),this._loader=this._getLoader(n);const a=new t.AssetContainer(e),i=[];this.onMaterialLoadedObservable.add(e=>{i.push(e)});const l=[];this.onTextureLoadedObservable.add(e=>{l.push(e)});const d=[];this.onCameraLoadedObservable.add(e=>{d.push(e)});const c=[];return this.onMeshLoadedObservable.add(e=>{e.morphTargetManager&&c.push(e.morphTargetManager)}),this._loader.importMeshAsync(null,e,a,n,s,r,o).then(e=>(Array.prototype.push.apply(a.geometries,e.geometries),Array.prototype.push.apply(a.meshes,e.meshes),Array.prototype.push.apply(a.particleSystems,e.particleSystems),Array.prototype.push.apply(a.skeletons,e.skeletons),Array.prototype.push.apply(a.animationGroups,e.animationGroups),Array.prototype.push.apply(a.materials,i),Array.prototype.push.apply(a.textures,l),Array.prototype.push.apply(a.lights,e.lights),Array.prototype.push.apply(a.transformNodes,e.transformNodes),Array.prototype.push.apply(a.cameras,d),Array.prototype.push.apply(a.morphTargetManagers,c),a))})}canDirectLoad(e){return d(e)}directLoad(e,n){if(n.startsWith("base64,"+a)||n.startsWith(";base64,"+a)||n.startsWith("application/octet-stream;base64,"+a)||n.startsWith("model/gltf-binary;base64,"+a)){const s=t.DecodeBase64UrlToBinary(n);return this._validate(e,new Uint8Array(s,0,s.byteLength)),this._unpackBinaryAsync(new t.DataReader({readAsync:(e,t)=>c(s,e,t),byteLength:s.byteLength}))}return this._validate(e,n),Promise.resolve({json:this._parseJson(n)})}createPlugin(e){return new _(e[i])}get loaderState(){return this._state}whenCompleteAsync(){return new Promise((e,t)=>{this.onCompleteObservable.addOnce(()=>{e()}),this.onErrorObservable.addOnce(e=>{t(e)})})}_setState(t){this._state!==t&&(this._state=t,this.onLoaderStateChangedObservable.notifyObservers(this._state),this._log(e.GLTFLoaderState[this._state]))}_loadFile(e,t,n,s,r,o){const a=e._loadFile(t,n,e=>{this._onProgress(e,a)},!0,s,r,o);return a.onCompleteObservable.add(()=>{a._lengthComputable=!0,a._total=a._loaded}),this._requests.push(a),a}_onProgress(e,t){if(!this._progressCallback)return;t._lengthComputable=e.lengthComputable,t._loaded=e.loaded,t._total=e.total;let n=!0,s=0,r=0;for(const e of this._requests){if(void 0===e._lengthComputable||void 0===e._loaded||void 0===e._total)return;n=n&&e._lengthComputable,s+=e._loaded,r+=e._total}this._progressCallback({lengthComputable:n,loaded:s,total:n?r:0})}_validate(e,n,s="",o=""){this.validate&&(this._startPerformanceCounter("Validate JSON"),r.ValidateAsync(n,s,o,t=>this.preprocessUrlAsync(s+t,s).then(t=>e._loadFileAsync(t,void 0,!0,!0).then(e=>new Uint8Array(e,0,e.byteLength)))).then(e=>{this._endPerformanceCounter("Validate JSON"),this.onValidatedObservable.notifyObservers(e),this.onValidatedObservable.clear()},e=>{this._endPerformanceCounter("Validate JSON"),t.Tools.Warn(`Failed to validate: ${e.message}`),this.onValidatedObservable.clear()}))}_getLoader(e){const t=e.json.asset||{};this._log(`Asset version: ${t.version}`),t.minVersion&&this._log(`Asset minimum version: ${t.minVersion}`),t.generator&&this._log(`Asset generator: ${t.generator}`);const n=_._parseVersion(t.version);if(!n)throw new Error("Invalid version: "+t.version);if(void 0!==t.minVersion){const e=_._parseVersion(t.minVersion);if(!e)throw new Error("Invalid minimum version: "+t.minVersion);if(_._compareVersion(e,{major:2,minor:0})>0)throw new Error("Incompatible minimum version: "+t.minVersion)}const s={1:_._CreateGLTF1Loader,2:_._CreateGLTF2Loader}[n.major];if(!s)throw new Error("Unsupported version: "+t.version);return s(this)}_parseJson(e){this._startPerformanceCounter("Parse JSON"),this._log(`JSON length: ${e.length}`);const t=JSON.parse(e);return this._endPerformanceCounter("Parse JSON"),t}_unpackBinaryAsync(e){return this._startPerformanceCounter("Unpack Binary"),e.loadAsync(20).then(()=>{const n=e.readUint32();if(1179937895!==n)throw new t.RuntimeError("Unexpected magic: "+n,t.ErrorCodes.GLTFLoaderUnexpectedMagicError);const s=e.readUint32();this.loggingEnabled&&this._log(`Binary version: ${s}`);const r=e.readUint32();let o;switch(this.useRangeRequests||r===e.buffer.byteLength||t.Logger.Warn(`Length in header does not match actual data length: ${r} != ${e.buffer.byteLength}`),s){case 1:o=this._unpackBinaryV1Async(e,r);break;case 2:o=this._unpackBinaryV2Async(e,r);break;default:throw new Error("Unsupported version: "+s)}return this._endPerformanceCounter("Unpack Binary"),o})}_unpackBinaryV1Async(e,t){const n=e.readUint32(),s=e.readUint32();if(0!==s)throw new Error(`Unexpected content format: ${s}`);const r=t-e.byteOffset,o={json:this._parseJson(e.readString(n)),bin:null};if(0!==r){const t=e.byteOffset;o.bin={readAsync:(n,s)=>e.buffer.readAsync(t+n,s),byteLength:r}}return Promise.resolve(o)}_unpackBinaryV2Async(e,t){const n=1313821514,s=e.readUint32();if(e.readUint32()!==n)throw new Error("First chunk format is not JSON");return e.byteOffset+s===t?e.loadAsync(s).then(()=>({json:this._parseJson(e.readString(s)),bin:null})):e.loadAsync(s+8).then(()=>{const r={json:this._parseJson(e.readString(s)),bin:null},o=()=>{const s=e.readUint32();switch(e.readUint32()){case n:throw new Error("Unexpected JSON chunk");case 5130562:{const t=e.byteOffset;r.bin={readAsync:(n,s)=>e.buffer.readAsync(t+n,s),byteLength:s},e.skipBytes(s);break}default:e.skipBytes(s)}return e.byteOffset!==t?e.loadAsync(8).then(o):Promise.resolve(r)};return o()})}static _parseVersion(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};const t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null}static _compareVersion(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0}_logOpen(e){this._log(e),this._logIndentLevel++}_logClose(){--this._logIndentLevel}_logEnabled(e){const n=_._logSpaces.substring(0,2*this._logIndentLevel);t.Logger.Log(`${n}${e}`)}_logDisabled(e){}_startPerformanceCounterEnabled(e){t.Tools.StartPerformanceCounter(e)}_startPerformanceCounterDisabled(e){}_endPerformanceCounterEnabled(e){t.Tools.EndPerformanceCounter(e)}_endPerformanceCounterDisabled(e){}}_.IncrementalLoading=!0,_.HomogeneousCoordinates=!1,_._logSpaces=" ";let g=!1;function y(){g||(g=!0,t.RegisterSceneLoaderPlugin(new _))}y();var E={__proto__:null,GLTFFileLoader:_,get GLTFLoaderAnimationStartMode(){return e.GLTFLoaderAnimationStartMode},get GLTFLoaderCoordinateSystemMode(){return e.GLTFLoaderCoordinateSystemMode},GLTFLoaderDefaultOptions:b,get GLTFLoaderState(){return e.GLTFLoaderState},RegisterGLTFFileLoader:y};const O="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==O){O.BABYLON=O.BABYLON||{};for(const e in E)O.BABYLON[e]=E[e];for(const e in o)O.BABYLON[e]=o[e]}var L,T,v,N,M,S,C,x,R;Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError,function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.FLOAT=5126]="FLOAT"}(L||(L={})),function(e){e[e.FRAGMENT=35632]="FRAGMENT",e[e.VERTEX=35633]="VERTEX"}(T||(T={})),function(e){e[e.BYTE=5120]="BYTE",e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.SHORT=5122]="SHORT",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.INT=5124]="INT",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT",e[e.FLOAT_VEC2=35664]="FLOAT_VEC2",e[e.FLOAT_VEC3=35665]="FLOAT_VEC3",e[e.FLOAT_VEC4=35666]="FLOAT_VEC4",e[e.INT_VEC2=35667]="INT_VEC2",e[e.INT_VEC3=35668]="INT_VEC3",e[e.INT_VEC4=35669]="INT_VEC4",e[e.BOOL=35670]="BOOL",e[e.BOOL_VEC2=35671]="BOOL_VEC2",e[e.BOOL_VEC3=35672]="BOOL_VEC3",e[e.BOOL_VEC4=35673]="BOOL_VEC4",e[e.FLOAT_MAT2=35674]="FLOAT_MAT2",e[e.FLOAT_MAT3=35675]="FLOAT_MAT3",e[e.FLOAT_MAT4=35676]="FLOAT_MAT4",e[e.SAMPLER_2D=35678]="SAMPLER_2D"}(v||(v={})),function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"}(N||(N={})),function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9728]="LINEAR",e[e.NEAREST_MIPMAP_NEAREST=9984]="NEAREST_MIPMAP_NEAREST",e[e.LINEAR_MIPMAP_NEAREST=9985]="LINEAR_MIPMAP_NEAREST",e[e.NEAREST_MIPMAP_LINEAR=9986]="NEAREST_MIPMAP_LINEAR",e[e.LINEAR_MIPMAP_LINEAR=9987]="LINEAR_MIPMAP_LINEAR"}(M||(M={})),function(e){e[e.ALPHA=6406]="ALPHA",e[e.RGB=6407]="RGB",e[e.RGBA=6408]="RGBA",e[e.LUMINANCE=6409]="LUMINANCE",e[e.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA"}(S||(S={})),function(e){e[e.FRONT=1028]="FRONT",e[e.BACK=1029]="BACK",e[e.FRONT_AND_BACK=1032]="FRONT_AND_BACK"}(C||(C={})),function(e){e[e.ZERO=0]="ZERO",e[e.ONE=1]="ONE",e[e.SRC_COLOR=768]="SRC_COLOR",e[e.ONE_MINUS_SRC_COLOR=769]="ONE_MINUS_SRC_COLOR",e[e.DST_COLOR=774]="DST_COLOR",e[e.ONE_MINUS_DST_COLOR=775]="ONE_MINUS_DST_COLOR",e[e.SRC_ALPHA=770]="SRC_ALPHA",e[e.ONE_MINUS_SRC_ALPHA=771]="ONE_MINUS_SRC_ALPHA",e[e.DST_ALPHA=772]="DST_ALPHA",e[e.ONE_MINUS_DST_ALPHA=773]="ONE_MINUS_DST_ALPHA",e[e.CONSTANT_COLOR=32769]="CONSTANT_COLOR",e[e.ONE_MINUS_CONSTANT_COLOR=32770]="ONE_MINUS_CONSTANT_COLOR",e[e.CONSTANT_ALPHA=32771]="CONSTANT_ALPHA",e[e.ONE_MINUS_CONSTANT_ALPHA=32772]="ONE_MINUS_CONSTANT_ALPHA",e[e.SRC_ALPHA_SATURATE=776]="SRC_ALPHA_SATURATE"}(x||(x={}));class w{static SetMatrix(e,n,s,r,o){let a=null;if("MODEL"===s.semantic?a=n.getWorldMatrix():"PROJECTION"===s.semantic?a=e.getProjectionMatrix():"VIEW"===s.semantic?a=e.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===s.semantic?a=t.Matrix.Transpose(n.getWorldMatrix().multiply(e.getViewMatrix()).invert()):"MODELVIEW"===s.semantic?a=n.getWorldMatrix().multiply(e.getViewMatrix()):"MODELVIEWPROJECTION"===s.semantic?a=n.getWorldMatrix().multiply(e.getTransformMatrix()):"MODELINVERSE"===s.semantic?a=n.getWorldMatrix().invert():"VIEWINVERSE"===s.semantic?a=e.getViewMatrix().invert():"PROJECTIONINVERSE"===s.semantic?a=e.getProjectionMatrix().invert():"MODELVIEWINVERSE"===s.semantic?a=n.getWorldMatrix().multiply(e.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===s.semantic?a=n.getWorldMatrix().multiply(e.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===s.semantic&&(a=t.Matrix.Transpose(n.getWorldMatrix().invert())),a)switch(s.type){case v.FLOAT_MAT2:o.setMatrix2x2(r,t.Matrix.GetAsMatrix2x2(a));break;case v.FLOAT_MAT3:o.setMatrix3x3(r,t.Matrix.GetAsMatrix3x3(a));break;case v.FLOAT_MAT4:o.setMatrix(r,a)}}static SetUniform(e,n,s,r){switch(r){case v.FLOAT:return e.setFloat(n,s),!0;case v.FLOAT_VEC2:return e.setVector2(n,t.Vector2.FromArray(s)),!0;case v.FLOAT_VEC3:return e.setVector3(n,t.Vector3.FromArray(s)),!0;case v.FLOAT_VEC4:return e.setVector4(n,t.Vector4.FromArray(s)),!0;default:return!1}}static GetWrapMode(e){switch(e){case N.CLAMP_TO_EDGE:return t.Texture.CLAMP_ADDRESSMODE;case N.MIRRORED_REPEAT:return t.Texture.MIRROR_ADDRESSMODE;case N.REPEAT:default:return t.Texture.WRAP_ADDRESSMODE}}static GetByteStrideFromType(e){switch(e.type){case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return 1}}static GetTextureFilterMode(e){switch(e){case M.LINEAR:case M.LINEAR_MIPMAP_NEAREST:case M.LINEAR_MIPMAP_LINEAR:return t.Texture.TRILINEAR_SAMPLINGMODE;case M.NEAREST:case M.NEAREST_MIPMAP_NEAREST:return t.Texture.NEAREST_SAMPLINGMODE;default:return t.Texture.BILINEAR_SAMPLINGMODE}}static GetBufferFromBufferView(e,t,n,s,r){n=t.byteOffset+n;const o=e.loadedBufferViews[t.buffer];if(n+s>o.byteLength)throw new Error("Buffer access is out of range");const a=o.buffer;switch(n+=o.byteOffset,r){case L.BYTE:return new Int8Array(a,n,s);case L.UNSIGNED_BYTE:return new Uint8Array(a,n,s);case L.SHORT:return new Int16Array(a,n,s);case L.UNSIGNED_SHORT:return new Uint16Array(a,n,s);default:return new Float32Array(a,n,s)}}static GetBufferFromAccessor(e,t){const n=e.bufferViews[t.bufferView],s=t.count*w.GetByteStrideFromType(t);return w.GetBufferFromBufferView(e,n,t.byteOffset,s,t.componentType)}static DecodeBufferToText(e){let t="";const n=e.byteLength;for(let s=0;s<n;++s)t+=String.fromCharCode(e[s]);return t}static GetDefaultMaterial(e){if(!w._DefaultMaterial){t.Effect.ShadersStore.GLTFDefaultMaterialVertexShader=["precision highp float;","","uniform mat4 worldView;","uniform mat4 projection;","","attribute vec3 position;","","void main(void)","{"," gl_Position = projection * worldView * vec4(position, 1.0);","}"].join("\n"),t.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");const n={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},s={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};w._DefaultMaterial=new t.ShaderMaterial("GLTFDefaultMaterial",e,n,s),w._DefaultMaterial.setColor4("u_emission",new t.Color4(.5,.5,.5,1))}return w._DefaultMaterial}}w._DefaultMaterial=null,function(e){e[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT"}(R||(R={}));class I{constructor(e){this._pos=0,this.currentToken=R.UNKNOWN,this.currentIdentifier="",this.currentString="",this.isLetterOrDigitPattern=/^[a-zA-Z0-9]+$/,this._toParse=e,this._maxPos=e.length}getNextToken(){if(this.isEnd())return R.END_OF_INPUT;if(this.currentString=this.read(),this.currentToken=R.UNKNOWN,"_"===this.currentString||this.isLetterOrDigitPattern.test(this.currentString))for(this.currentToken=R.IDENTIFIER,this.currentIdentifier=this.currentString;!this.isEnd()&&(this.isLetterOrDigitPattern.test(this.currentString=this.peek())||"_"===this.currentString);)this.currentIdentifier+=this.currentString,this.forward();return this.currentToken}peek(){return this._toParse[this._pos]}read(){return this._toParse[this._pos++]}forward(){this._pos++}isEnd(){return this._pos>=this._maxPos}}const P=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],F=["world","view","projection","worldView","worldViewProjection","mBones"],B=["translation","rotation","scale"],V=["position","rotationQuaternion","scaling"],D=(e,t,n)=>{for(const s in e){const r=e[s];n[t][s]=r}},G=e=>{if(e)for(let t=0;t<e.length/2;t++)e[2*t+1]=1-e[2*t+1]},k=e=>{if("NORMAL"===e.semantic)return"normal";if("POSITION"===e.semantic)return"position";if("JOINT"===e.semantic)return"matricesIndices";if("WEIGHT"===e.semantic)return"matricesWeights";if("COLOR"===e.semantic)return"color";if(e.semantic&&-1!==e.semantic.indexOf("TEXCOORD_")){const t=Number(e.semantic.split("_")[1]);return"uv"+(0===t?"":t+1)}return null},U=e=>{let n;if(e.translation||e.rotation||e.scale){const s=t.Vector3.FromArray(e.scale||[1,1,1]),r=t.Quaternion.FromArray(e.rotation||[0,0,0,1]),o=t.Vector3.FromArray(e.translation||[0,0,0]);n=t.Matrix.Compose(s,r,o)}else n=t.Matrix.FromArray(e.matrix);return n},j=(e,n,s,r)=>{for(let e=0;e<r.bones.length;e++)if(r.bones[e].name===s)return r.bones[e];const o=e.nodes;for(const a in o){const i=o[a];if(!i.jointName)continue;const l=i.children;for(let o=0;o<l.length;o++){const d=e.nodes[l[o]];if(d.jointName&&d.jointName===s){const s=U(i),o=new t.Bone(i.name||"",r,j(e,n,i.jointName,r),s);return o.id=a,o}}}return null},H=(e,t)=>{for(let n=0;n<e.length;n++){const s=e[n];for(let e=0;e<s.node.children.length;e++)if(s.node.children[e]===t)return s.bone}return null},W=(e,t)=>{const n=e.nodes;let s=n[t];if(s)return{node:s,id:t};for(const e in n)if(s=n[e],s.jointName===t)return{node:s,id:e};return null},Y=(e,t)=>{for(let n=0;n<e.jointNames.length;n++)if(e.jointNames[n]===t)return!0;return!1},J=(e,n,s,r,o)=>{if(o||(e.scene._blockEntityCollection=!!e.assetContainer,(o=new t.Mesh(n.name||"",e.scene))._parentContainer=e.assetContainer,e.scene._blockEntityCollection=!1,o.id=r),!n.babylonNode)return o;const a=[];let i=null;const l=[],d=[],c=[],u=[];for(let n=0;n<s.length;n++){const r=s[n],o=e.meshes[r];if(o)for(let n=0;n<o.primitives.length;n++){const s=new t.VertexData,r=o.primitives[n];r.mode;const h=r.attributes;let f,m;for(const n in h)if(f=e.accessors[h[n]],m=w.GetBufferFromAccessor(e,f),"NORMAL"===n)s.normals=new Float32Array(m.length),s.normals.set(m);else if("POSITION"===n){if(_.HomogeneousCoordinates){s.positions=new Float32Array(m.length-m.length/4);for(let e=0;e<m.length;e+=4)s.positions[e]=m[e],s.positions[e+1]=m[e+1],s.positions[e+2]=m[e+2]}else s.positions=new Float32Array(m.length),s.positions.set(m);d.push(s.positions.length)}else if(-1!==n.indexOf("TEXCOORD_")){const e=Number(n.split("_")[1]),r=t.VertexBuffer.UVKind+(0===e?"":e+1),o=new Float32Array(m.length);o.set(m),G(o),s.set(o,r)}else"JOINT"===n?(s.matricesIndices=new Float32Array(m.length),s.matricesIndices.set(m)):"WEIGHT"===n?(s.matricesWeights=new Float32Array(m.length),s.matricesWeights.set(m)):"COLOR"===n&&(s.colors=new Float32Array(m.length),s.colors.set(m));if(f=e.accessors[r.indices],f)m=w.GetBufferFromAccessor(e,f),s.indices=new Int32Array(m.length),s.indices.set(m),u.push(s.indices.length);else{const e=[];for(let t=0;t<s.positions.length/3;t++)e.push(t);s.indices=new Int32Array(e),u.push(s.indices.length)}i?i.merge(s):i=s;const p=e.scene.getMaterialById(r.material);a.push(null===p?w.GetDefaultMaterial(e.scene):p),l.push(0===l.length?0:l[l.length-1]+d[d.length-2]),c.push(0===c.length?0:c[c.length-1]+u[u.length-2])}}let h;e.scene._blockEntityCollection=!!e.assetContainer,a.length>1?(h=new t.MultiMaterial("multimat"+r,e.scene),h.subMaterials=a):h=new t.StandardMaterial("multimat"+r,e.scene),1===a.length&&(h=a[0]),h._parentContainer=e.assetContainer,o.material||(o.material=h),new t.Geometry(r,e.scene,i,!1,o),o.computeWorldMatrix(!0),e.scene._blockEntityCollection=!1,o.subMeshes=[];let f=0;for(let n=0;n<s.length;n++){const r=s[n],a=e.meshes[r];if(a)for(let e=0;e<a.primitives.length;e++)a.primitives[e].mode,t.SubMesh.AddToMesh(f,l[f],d[f],c[f],u[f],o,o,!0),f++}return o},q=(e,t,n,s)=>{e.position&&(e.position=t),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=n),e.scaling&&(e.scaling=s)},Z=(e,n,s)=>{let r=null;if(e.importOnlyMeshes&&(n.skin||n.meshes)&&e.importMeshesNames&&e.importMeshesNames.length>0&&-1===e.importMeshesNames.indexOf(n.name||""))return null;if(n.skin){if(n.meshes){const o=e.skins[n.skin],a=J(e,n,n.meshes,s,n.babylonNode);a.skeleton=e.scene.getLastSkeletonById(n.skin),null===a.skeleton&&(a.skeleton=((e,n,s,r)=>{if(r||(r=new t.Skeleton(n.name||"","",e.scene)),!n.babylonSkeleton)return r;const o=[],a=[];((e,n,s,r)=>{for(const o in e.nodes){const a=e.nodes[o],i=o;if(!a.jointName||Y(s,a.jointName))continue;const l=U(a),d=new t.Bone(a.name||"",n,null,l);d.id=i,r.push({bone:d,node:a,id:i})}for(let e=0;e<r.length;e++){const t=r[e],n=t.node.children;for(let e=0;e<n.length;e++){let s=null;for(let t=0;t<r.length;t++)if(r[t].id===n[e]){s=r[t];break}s&&(s.bone._parent=t.bone,t.bone.children.push(s.bone))}}})(e,r,n,o),r.bones=[];for(let s=0;s<n.jointNames.length;s++){const i=W(e,n.jointNames[s]);if(!i)continue;const l=i.node;if(!l){t.Tools.Warn("Joint named "+n.jointNames[s]+" does not exist");continue}const d=i.id,c=e.scene.getBoneById(d);if(c){r.bones.push(c);continue}let u,h=null;for(let o=0;o<s;o++){const s=W(e,n.jointNames[o]);if(!s)continue;const a=s.node;if(!a){t.Tools.Warn("Joint named "+n.jointNames[o]+" does not exist when looking for parent");continue}const i=a.children;if(i){u=!1;for(let t=0;t<i.length;t++)if(i[t]===d){h=j(e,n,n.jointNames[o],r),u=!0;break}if(u)break}}const f=U(l);!h&&o.length>0&&(h=H(o,d),h&&-1===a.indexOf(h)&&a.push(h)),new t.Bone(l.jointName||"",r,h,f).id=d}const i=r.bones;r.bones=[];for(let t=0;t<n.jointNames.length;t++){const s=W(e,n.jointNames[t]);if(s)for(let e=0;e<i.length;e++)if(i[e].id===s.id){r.bones.push(i[e]);break}}r.prepare();for(let e=0;e<a.length;e++)r.bones.push(a[e]);return r})(e,o,0,o.babylonSkeleton),o.babylonSkeleton||(o.babylonSkeleton=a.skeleton)),r=a}}else if(n.meshes)r=J(e,n,n.mesh?[n.mesh]:n.meshes,s,n.babylonNode);else if(!n.light||n.babylonNode||e.importOnlyMeshes){if(n.camera&&!n.babylonNode&&!e.importOnlyMeshes){const s=e.cameras[n.camera];if(s){if(e.scene._blockEntityCollection=!!e.assetContainer,"orthographic"===s.type){const s=new t.FreeCamera(n.camera,t.Vector3.Zero(),e.scene,!1);s.name=n.name||"",s.mode=t.Camera.ORTHOGRAPHIC_CAMERA,s.attachControl(),r=s,s._parentContainer=e.assetContainer}else if("perspective"===s.type){const o=s[s.type],a=new t.FreeCamera(n.camera,t.Vector3.Zero(),e.scene,!1);a.name=n.name||"",a.attachControl(),o.aspectRatio||(o.aspectRatio=e.scene.getEngine().getRenderWidth()/e.scene.getEngine().getRenderHeight()),o.znear&&o.zfar&&(a.maxZ=o.zfar,a.minZ=o.znear),r=a,a._parentContainer=e.assetContainer}e.scene._blockEntityCollection=!1}}}else{const s=e.lights[n.light];if(s)if("ambient"===s.type){const o=s[s.type],a=new t.HemisphericLight(n.light,t.Vector3.Zero(),e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),r=a}else if("directional"===s.type){const o=s[s.type],a=new t.DirectionalLight(n.light,t.Vector3.Zero(),e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),r=a}else if("point"===s.type){const o=s[s.type],a=new t.PointLight(n.light,t.Vector3.Zero(),e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),r=a}else if("spot"===s.type){const o=s[s.type],a=new t.SpotLight(n.light,t.Vector3.Zero(),t.Vector3.Zero(),0,0,e.scene);a.name=n.name||"",o.color&&(a.diffuse=t.Color3.FromArray(o.color)),o.fallOfAngle&&(a.angle=o.fallOfAngle),o.fallOffExponent&&(a.exponent=o.fallOffExponent),r=a}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===r){e.scene._blockEntityCollection=!!e.assetContainer;const s=new t.Mesh(n.name||"",e.scene);s._parentContainer=e.assetContainer,e.scene._blockEntityCollection=!1,n.babylonNode=s,r=s}}if(null!==r){if(n.matrix&&r instanceof t.Mesh)((e,n)=>{if(n.matrix){const s=new t.Vector3(0,0,0),r=new t.Quaternion,o=new t.Vector3(0,0,0);t.Matrix.FromArray(n.matrix).decompose(o,r,s),q(e,s,r,o)}else n.translation&&n.rotation&&n.scale&&q(e,t.Vector3.FromArray(n.translation),t.Quaternion.FromArray(n.rotation),t.Vector3.FromArray(n.scale));e.computeWorldMatrix(!0)})(r,n);else{const e=n.translation||[0,0,0],s=n.rotation||[0,0,0,1],o=n.scale||[1,1,1];q(r,t.Vector3.FromArray(e),t.Quaternion.FromArray(s),t.Vector3.FromArray(o))}r.updateCache(!0),n.babylonNode=r}return r},$=(e,t,n,s=!1)=>{const r=e.nodes[t];let o=null;if(s=!(e.importOnlyMeshes&&!s&&e.importMeshesNames)||-1!==e.importMeshesNames.indexOf(r.name||"")||0===e.importMeshesNames.length,!r.jointName&&s&&(o=Z(e,r,t),null!==o&&(o.id=t,o.parent=n)),r.children)for(let t=0;t<r.children.length;t++)$(e,r.children[t],o,s)},K=e=>{let n=e.currentScene;if(n)for(let t=0;t<n.nodes.length;t++)$(e,n.nodes[t],null);else for(const t in e.scenes){n=e.scenes[t];for(let t=0;t<n.nodes.length;t++)$(e,n.nodes[t],null)}(e=>{for(const n in e.animations){const s=e.animations[n];if(!s.channels||!s.samplers)continue;let r=null;for(let o=0;o<s.channels.length;o++){const a=s.channels[o],i=s.samplers[a.sampler];if(!i)continue;let l,d;s.parameters?(l=s.parameters[i.input],d=s.parameters[i.output]):(l=i.input,d=i.output);const c=w.GetBufferFromAccessor(e,e.accessors[l]),u=w.GetBufferFromAccessor(e,e.accessors[d]),h=a.target.id;let f=e.scene.getNodeById(h);if(null===f&&(f=e.scene.getNodeByName(h)),null===f){t.Tools.Warn("Creating animation named "+n+". But cannot find node named "+h+" to attach to");continue}const m=f instanceof t.Bone;let p=a.target.path;const b=B.indexOf(p);-1!==b&&(p=V[b]);let A=t.Animation.ANIMATIONTYPE_MATRIX;m||("rotationQuaternion"===p?(A=t.Animation.ANIMATIONTYPE_QUATERNION,f.rotationQuaternion=new t.Quaternion):A=t.Animation.ANIMATIONTYPE_VECTOR3);let _=null;const g=[];let y=0,E=!1;m&&r&&r.getKeys().length===c.length&&(_=r,E=!0),E||(e.scene._blockEntityCollection=!!e.assetContainer,_=new t.Animation(n,m?"_matrix":p,1,A,t.Animation.ANIMATIONLOOPMODE_CYCLE),e.scene._blockEntityCollection=!1);for(let e=0;e<c.length;e++){let n;if("rotationQuaternion"===p?(n=t.Quaternion.FromArray([u[y],u[y+1],u[y+2],u[y+3]]),y+=4):(n=t.Vector3.FromArray([u[y],u[y+1],u[y+2]]),y+=3),m){const s=f;let o=t.Vector3.Zero(),a=new t.Quaternion,i=t.Vector3.Zero(),l=s.getBaseMatrix();E&&r&&(l=r.getKeys()[e].value),l.decompose(i,a,o),"position"===p?o=n:"rotationQuaternion"===p?a=n:i=n,n=t.Matrix.Compose(i,a,o)}E?r&&(r.getKeys()[e].value=n):g.push({frame:c[e],value:n})}!E&&_&&(_.setKeys(g),f.animations.push(_)),r=_,e.scene.stopAnimation(f),e.scene.beginAnimation(f,0,c[c.length-1],!0,1)}}})(e);for(let t=0;t<e.scene.skeletons.length;t++){const n=e.scene.skeletons[t];e.scene.beginAnimation(n,0,Number.MAX_VALUE,!0,1)}},Q=(e,t,n)=>{for(const s in t.uniforms){const r=t.uniforms[s],o=t.parameters[r];if(e.currentIdentifier===s&&o.semantic&&!o.source&&!o.node){const e=P.indexOf(o.semantic);if(-1!==e)return delete n[s],F[e]}}return e.currentIdentifier},X=e=>{for(const t in e.materials)te.LoadMaterialAsync(e,t,()=>{},()=>{})};class z{static CreateRuntime(e,t,n){const s={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:t,rootUrl:n,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[],assetContainer:null};return e.extensions&&D(e.extensions,"extensions",s),e.extensionsUsed&&D(e.extensionsUsed,"extensionsUsed",s),e.buffers&&((e,t)=>{for(const n in e){const s=e[n];t.buffers[n]=s,t.buffersCount++}})(e.buffers,s),e.bufferViews&&D(e.bufferViews,"bufferViews",s),e.accessors&&D(e.accessors,"accessors",s),e.meshes&&D(e.meshes,"meshes",s),e.lights&&D(e.lights,"lights",s),e.cameras&&D(e.cameras,"cameras",s),e.nodes&&D(e.nodes,"nodes",s),e.images&&D(e.images,"images",s),e.textures&&D(e.textures,"textures",s),e.shaders&&((e,t)=>{for(const n in e){const s=e[n];t.shaders[n]=s,t.shaderscount++}})(e.shaders,s),e.programs&&D(e.programs,"programs",s),e.samplers&&D(e.samplers,"samplers",s),e.techniques&&D(e.techniques,"techniques",s),e.materials&&D(e.materials,"materials",s),e.animations&&D(e.animations,"animations",s),e.skins&&D(e.skins,"skins",s),e.scenes&&(s.scenes=e.scenes),e.scene&&e.scenes&&(s.currentScene=e.scenes[e.scene]),s}static LoadBufferAsync(e,n,s,r,o){const a=e.buffers[n];t.Tools.IsBase64(a.uri)?setTimeout(()=>s(new Uint8Array(t.Tools.DecodeBase64(a.uri)))):t.Tools.LoadFile(e.rootUrl+a.uri,e=>s(new Uint8Array(e)),o,void 0,!0,e=>{e&&r(e.status+" "+e.statusText)})}static LoadTextureBufferAsync(e,n,s,r){const o=e.textures[n];if(!o||!o.source)return void r("");if(o.babylonTexture)return void s(null);const a=e.images[o.source];t.Tools.IsBase64(a.uri)?setTimeout(()=>s(new Uint8Array(t.Tools.DecodeBase64(a.uri)))):t.Tools.LoadFile(e.rootUrl+a.uri,e=>s(new Uint8Array(e)),void 0,void 0,!0,e=>{e&&r(e.status+" "+e.statusText)})}static CreateTextureAsync(e,n,s,r){const o=e.textures[n];if(o.babylonTexture)return void r(o.babylonTexture);const a=e.samplers[o.sampler],i=a.minFilter===M.NEAREST_MIPMAP_NEAREST||a.minFilter===M.NEAREST_MIPMAP_LINEAR||a.minFilter===M.LINEAR_MIPMAP_NEAREST||a.minFilter===M.LINEAR_MIPMAP_LINEAR,l=t.Texture.BILINEAR_SAMPLINGMODE,d=null==s?new Blob:new Blob([t.GetBlobBufferSource(s)]),c=URL.createObjectURL(d),u=()=>URL.revokeObjectURL(c),h=new t.Texture(c,e.scene,!i,!0,l,u,u);void 0!==a.wrapS&&(h.wrapU=w.GetWrapMode(a.wrapS)),void 0!==a.wrapT&&(h.wrapV=w.GetWrapMode(a.wrapT)),h.name=n,o.babylonTexture=h,r(h)}static LoadShaderStringAsync(e,n,s,r){const o=e.shaders[n];if(t.Tools.IsBase64(o.uri)){const e=atob(o.uri.split(",")[1]);s&&s(e)}else t.Tools.LoadFile(e.rootUrl+o.uri,s,void 0,void 0,!1,e=>{e&&r&&r(e.status+" "+e.statusText)})}static LoadMaterialAsync(e,n,s,r){const o=e.materials[n];if(!o.technique)return void(r&&r("No technique found."));const a=e.techniques[o.technique];if(!a){e.scene._blockEntityCollection=!!e.assetContainer;const r=new t.StandardMaterial(n,e.scene);return r._parentContainer=e.assetContainer,e.scene._blockEntityCollection=!1,r.diffuseColor=new t.Color3(.5,.5,.5),r.sideOrientation=t.Material.CounterClockWiseSideOrientation,void s(r)}const i=e.programs[a.program],l=a.states,d=t.Effect.ShadersStore[i.vertexShader+"VertexShader"],c=t.Effect.ShadersStore[i.fragmentShader+"PixelShader"];let u="",h="";const f=new I(d),m=new I(c),p={},b=[],A=[],_=[];for(const e in a.uniforms){const t=a.uniforms[e],n=a.parameters[t];if(p[e]=n,!n.semantic||n.node||n.source)n.type===v.SAMPLER_2D?_.push(e):b.push(e);else{const t=P.indexOf(n.semantic);-1!==t?(b.push(F[t]),delete p[e]):b.push(e)}}for(const e in a.attributes){const t=a.attributes[e],n=a.parameters[t];if(n.semantic){const e=k(n);e&&A.push(e)}}for(;!f.isEnd()&&f.getNextToken();){if(f.currentToken!==R.IDENTIFIER){u+=f.currentString;continue}let e=!1;for(const t in a.attributes){const n=a.attributes[t],s=a.parameters[n];if(f.currentIdentifier===t&&s.semantic){u+=k(s),e=!0;break}}e||(u+=Q(f,a,p))}for(;!m.isEnd()&&m.getNextToken();)m.currentToken===R.IDENTIFIER?h+=Q(m,a,p):h+=m.currentString;const g={vertex:i.vertexShader+n,fragment:i.fragmentShader+n},y={attributes:A,uniforms:b,samplers:_,needAlphaBlending:l&&l.enable&&-1!==l.enable.indexOf(3042)};t.Effect.ShadersStore[i.vertexShader+n+"VertexShader"]=u,t.Effect.ShadersStore[i.fragmentShader+n+"PixelShader"]=h;const E=new t.ShaderMaterial(n,e.scene,g,y);if(E.onError=((e,t,n)=>(s,r)=>{t.dispose(!0),n("Cannot compile program named "+e.name+". Error: "+r+". Default material will be applied")})(i,E,r),E.onCompiled=((e,t,n,s,r,o)=>a=>{((e,t,n,s,r)=>{const o=s.values||n.parameters,a=n.uniforms;for(const n in r){const i=r[n],l=i.type;let d=o[a[n]];if(void 0===d&&(d=i.value),!d)continue;const c=e=>n=>{i.value&&e&&(t.setTexture(e,n),delete r[e])};l===v.SAMPLER_2D?te.LoadTextureAsync(e,s.values?d:i.value,c(n),()=>c(null)):i.value&&w.SetUniform(t,n,s.values?d:i.value,l)&&delete r[n]}})(e,t,n,s,r),t.onBind=a=>{((e,t,n,s,r,o,a)=>{const i=o.values||r.parameters;for(const a in n){const l=n[a],d=l.type;if(d===v.FLOAT_MAT2||d===v.FLOAT_MAT3||d===v.FLOAT_MAT4)if(!l.semantic||l.source||l.node){if(l.semantic&&(l.source||l.node)){let e=t.scene.getNodeByName(l.source||l.node||"");if(null===e&&(e=t.scene.getNodeById(l.source||l.node||"")),null===e)continue;w.SetMatrix(t.scene,e,l,a,s.getEffect())}}else w.SetMatrix(t.scene,e,l,a,s.getEffect());else{const e=i[r.uniforms[a]];if(!e)continue;if(d===v.SAMPLER_2D){const n=t.textures[o.values?e:l.value].babylonTexture;if(null==n)continue;s.getEffect().setTexture(a,n)}else w.SetUniform(s.getEffect(),a,e,d)}}a(s)})(a,e,r,t,n,s,o)}})(e,E,a,o,p,s),E.sideOrientation=t.Material.CounterClockWiseSideOrientation,l&&l.functions){const e=l.functions;e.cullFace&&e.cullFace[0]!==C.BACK&&(E.backFaceCulling=!1);const n=e.blendFuncSeparate;n&&(n[0]===x.SRC_ALPHA&&n[1]===x.ONE_MINUS_SRC_ALPHA&&n[2]===x.ONE&&n[3]===x.ONE?E.alphaMode=t.Constants.ALPHA_COMBINE:n[0]===x.ONE&&n[1]===x.ONE&&n[2]===x.ZERO&&n[3]===x.ONE?E.alphaMode=t.Constants.ALPHA_ONEONE:n[0]===x.SRC_ALPHA&&n[1]===x.ONE&&n[2]===x.ZERO&&n[3]===x.ONE?E.alphaMode=t.Constants.ALPHA_ADD:n[0]===x.ZERO&&n[1]===x.ONE_MINUS_SRC_COLOR&&n[2]===x.ONE&&n[3]===x.ONE?E.alphaMode=t.Constants.ALPHA_SUBTRACT:n[0]===x.DST_COLOR&&n[1]===x.ZERO&&n[2]===x.ONE&&n[3]===x.ONE?E.alphaMode=t.Constants.ALPHA_MULTIPLY:n[0]===x.SRC_ALPHA&&n[1]===x.ONE_MINUS_SRC_COLOR&&n[2]===x.ONE&&n[3]===x.ONE&&(E.alphaMode=t.Constants.ALPHA_MAXIMIZED))}}}class ee{static RegisterExtension(e){ee.Extensions[e.name]?t.Tools.Error('Tool with the same name "'+e.name+'" already exists'):ee.Extensions[e.name]=e}dispose(){}_importMeshAsync(e,n,s,r,o,a,i,l){return n.useRightHandedSystem=!0,te.LoadRuntimeAsync(n,s,r,n=>{n.assetContainer=o,n.importOnlyMeshes=!0,""===e?n.importMeshesNames=[]:"string"==typeof e?n.importMeshesNames=[e]:!e||e instanceof Array?(n.importMeshesNames=[],t.Tools.Warn("Argument meshesNames must be of type string or string[]")):n.importMeshesNames=[e],this._createNodes(n);const s=[],r=[];for(const e in n.nodes){const r=n.nodes[e];r.babylonNode instanceof t.AbstractMesh&&s.push(r.babylonNode)}for(const e in n.skins){const s=n.skins[e];s.babylonSkeleton instanceof t.Skeleton&&r.push(s.babylonSkeleton)}this._loadBuffersAsync(n,()=>{this._loadShadersAsync(n,()=>{X(n),K(n),!_.IncrementalLoading&&a&&a(s,r)})}),_.IncrementalLoading&&a&&a(s,r)},l),!0}importMeshAsync(e,t,n,s,r,o){return new Promise((a,i)=>{this._importMeshAsync(e,t,s,r,n,(e,t)=>{a({meshes:e,particleSystems:[],skeletons:t,animationGroups:[],lights:[],transformNodes:[],geometries:[],spriteManagers:[]})},o,e=>{i(new Error(e))})})}_loadAsync(e,t,n,s,r,o){e.useRightHandedSystem=!0,te.LoadRuntimeAsync(e,t,n,e=>{te.LoadRuntimeExtensionsAsync(e,()=>{this._createNodes(e),this._loadBuffersAsync(e,()=>{this._loadShadersAsync(e,()=>{X(e),K(e),_.IncrementalLoading||s()})}),_.IncrementalLoading&&s()},o)},o)}loadAsync(e,t,n,s){return r=this,o=void 0,i=function*(){return yield new Promise((r,o)=>{this._loadAsync(e,t,n,()=>{r()},s,e=>{o(new Error(e))})})},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{l(i.next(e))}catch(e){t(e)}}function s(e){try{l(i.throw(e))}catch(e){t(e)}}function l(t){var r;t.done?e(t.value):(r=t.value,r instanceof a?r:new a(function(e){e(r)})).then(n,s)}l((i=i.apply(r,o||[])).next())});var r,o,a,i}_loadShadersAsync(e,n){let s=!1;const r=(s,r)=>{te.LoadShaderStringAsync(e,s,o=>{o instanceof ArrayBuffer||(e.loadedShaderCount++,o&&(t.Effect.ShadersStore[s+(r.type===T.VERTEX?"VertexShader":"PixelShader")]=o),e.loadedShaderCount===e.shaderscount&&n())},()=>{t.Tools.Error("Error when loading shader program named "+s+" located at "+r.uri)})};for(const n in e.shaders){s=!0;const o=e.shaders[n];o?r.bind(this,n,o)():t.Tools.Error("No shader named: "+n)}s||n()}_loadBuffersAsync(e,n){let s=!1;const r=(s,r)=>{te.LoadBufferAsync(e,s,o=>{e.loadedBufferCount++,o&&(o.byteLength!=e.buffers[s].byteLength&&t.Tools.Error("Buffer named "+s+" is length "+o.byteLength+". Expected: "+r.byteLength),e.loadedBufferViews[s]=o),e.loadedBufferCount===e.buffersCount&&n()},()=>{t.Tools.Error("Error when loading buffer named "+s+" located at "+r.uri)})};for(const n in e.buffers){s=!0;const o=e.buffers[n];o?r.bind(this,n,o)():t.Tools.Error("No buffer named: "+n)}s||n()}_createNodes(e){let t=e.currentScene;if(t)for(let n=0;n<t.nodes.length;n++)$(e,t.nodes[n],null);else for(const n in e.scenes){t=e.scenes[n];for(let n=0;n<t.nodes.length;n++)$(e,t.nodes[n],null)}}}ee.Extensions={};class te{constructor(e){this._name=e}get name(){return this._name}loadRuntimeAsync(e,t,n,s,r){return!1}loadRuntimeExtensionsAsync(e,t,n){return!1}loadBufferAsync(e,t,n,s,r){return!1}loadTextureBufferAsync(e,t,n,s){return!1}createTextureAsync(e,t,n,s,r){return!1}loadShaderStringAsync(e,t,n,s){return!1}loadMaterialAsync(e,t,n,s){return!1}static LoadRuntimeAsync(e,t,n,s,r){te._ApplyExtensions(o=>o.loadRuntimeAsync(e,t,n,s,r),()=>{setTimeout(()=>{s&&s(z.CreateRuntime(t.json,e,n))})})}static LoadRuntimeExtensionsAsync(e,t,n){te._ApplyExtensions(s=>s.loadRuntimeExtensionsAsync(e,t,n),()=>{setTimeout(()=>{t()})})}static LoadBufferAsync(e,t,n,s,r){te._ApplyExtensions(o=>o.loadBufferAsync(e,t,n,s,r),()=>{z.LoadBufferAsync(e,t,n,s,r)})}static LoadTextureAsync(e,t,n,s){te._LoadTextureBufferAsync(e,t,r=>{r&&te._CreateTextureAsync(e,t,r,n,s)},s)}static LoadShaderStringAsync(e,t,n,s){te._ApplyExtensions(r=>r.loadShaderStringAsync(e,t,n,s),()=>{z.LoadShaderStringAsync(e,t,n,s)})}static LoadMaterialAsync(e,t,n,s){te._ApplyExtensions(r=>r.loadMaterialAsync(e,t,n,s),()=>{z.LoadMaterialAsync(e,t,n,s)})}static _LoadTextureBufferAsync(e,t,n,s){te._ApplyExtensions(r=>r.loadTextureBufferAsync(e,t,n,s),()=>{z.LoadTextureBufferAsync(e,t,n,s)})}static _CreateTextureAsync(e,t,n,s,r){te._ApplyExtensions(o=>o.createTextureAsync(e,t,n,s,r),()=>{z.CreateTextureAsync(e,t,n,s)})}static _ApplyExtensions(e,t){for(const t in ee.Extensions)if(e(ee.Extensions[t]))return;t()}}let ne=!1;function se(){ne||(ne=!0,_._CreateGLTF1Loader=()=>new ee)}class re extends te{constructor(){super("KHR_binary_glTF")}loadRuntimeAsync(e,t,n,s){const r=t.json.extensionsUsed;return!(!r||-1===r.indexOf(this.name)||!t.bin||(this._bin=t.bin,s(z.CreateRuntime(t.json,e,n)),0))}loadBufferAsync(e,t,n,s){return-1!==e.extensionsUsed.indexOf(this.name)&&"binary_glTF"===t&&(this._bin.readAsync(0,this._bin.byteLength).then(n,e=>s(e.message)),!0)}loadTextureBufferAsync(e,t,n){const s=e.textures[t],r=e.images[s.source];if(!r.extensions||!(this.name in r.extensions))return!1;const o=r.extensions[this.name],a=e.bufferViews[o.bufferView];return n(w.GetBufferFromBufferView(e,a,0,a.byteLength,L.UNSIGNED_BYTE)),!0}loadShaderStringAsync(e,t,n){const s=e.shaders[t];if(!s.extensions||!(this.name in s.extensions))return!1;const r=s.extensions[this.name],o=e.bufferViews[r.bufferView],a=w.GetBufferFromBufferView(e,o,0,o.byteLength,L.UNSIGNED_BYTE);return setTimeout(()=>{const e=w.DecodeBufferToText(a);n(e)}),!0}}let oe=!1;function ae(){oe||(oe=!0,ee.RegisterExtension(new re))}se(),y(),ae();class ie extends te{constructor(){super("KHR_materials_common")}loadRuntimeExtensionsAsync(e){if(!e.extensions)return!1;const n=e.extensions[this.name];if(!n)return!1;const s=n.lights;if(s)for(const n in s){const r=s[n];switch(r.type){case"ambient":{const n=new t.HemisphericLight(r.name,new t.Vector3(0,1,0),e.scene),s=r.ambient;s&&(n.diffuse=t.Color3.FromArray(s.color||[1,1,1]));break}case"point":{const n=new t.PointLight(r.name,new t.Vector3(10,10,10),e.scene),s=r.point;s&&(n.diffuse=t.Color3.FromArray(s.color||[1,1,1]));break}case"directional":{const n=new t.DirectionalLight(r.name,new t.Vector3(0,-1,0),e.scene),s=r.directional;s&&(n.diffuse=t.Color3.FromArray(s.color||[1,1,1]));break}case"spot":{const n=r.spot;n&&(new t.SpotLight(r.name,new t.Vector3(0,10,0),new t.Vector3(0,-1,0),n.fallOffAngle||Math.PI,n.fallOffExponent||0,e.scene).diffuse=t.Color3.FromArray(n.color||[1,1,1]));break}default:t.Tools.Warn('GLTF Material Common extension: light type "'+r.type+"” not supported")}}return!1}loadMaterialAsync(e,n,s,r){const o=e.materials[n];if(!o||!o.extensions)return!1;const a=o.extensions[this.name];if(!a)return!1;const i=new t.StandardMaterial(n,e.scene);return i.sideOrientation=t.Material.CounterClockWiseSideOrientation,"CONSTANT"===a.technique&&(i.disableLighting=!0),i.backFaceCulling=void 0!==a.doubleSided&&!a.doubleSided,i.alpha=void 0===a.values.transparency?1:a.values.transparency,i.specularPower=void 0===a.values.shininess?0:a.values.shininess,"string"==typeof a.values.ambient?this._loadTexture(e,a.values.ambient,i,"ambientTexture",r):i.ambientColor=t.Color3.FromArray(a.values.ambient||[0,0,0]),"string"==typeof a.values.diffuse?this._loadTexture(e,a.values.diffuse,i,"diffuseTexture",r):i.diffuseColor=t.Color3.FromArray(a.values.diffuse||[0,0,0]),"string"==typeof a.values.emission?this._loadTexture(e,a.values.emission,i,"emissiveTexture",r):i.emissiveColor=t.Color3.FromArray(a.values.emission||[0,0,0]),"string"==typeof a.values.specular?this._loadTexture(e,a.values.specular,i,"specularTexture",r):i.specularColor=t.Color3.FromArray(a.values.specular||[0,0,0]),!0}_loadTexture(e,t,n,s,r){z.LoadTextureBufferAsync(e,t,r=>{z.CreateTextureAsync(e,t,r,e=>n[s]=e)},r)}}let le=!1;function de(){le||(le=!0,ee.RegisterExtension(new ie))}de();var ce={__proto__:null,get EBlendingFunction(){return x},get EComponentType(){return L},get ECullingType(){return C},get EParameterType(){return v},get EShaderType(){return T},get ETextureFilterType(){return M},get ETextureFormat(){return S},get ETextureWrapMode(){return N},GLTFBinaryExtension:re,GLTFLoader:ee,GLTFLoaderBase:z,GLTFLoaderExtension:te,GLTFMaterialsCommonExtension:ie,GLTFUtils:w,RegisterGLTF1Loader:se,RegisterGLTFBinaryExtension:ae,RegisterGLTFMaterialsCommonExtension:de};const ue="undefined"!=typeof global?global:"undefined"!=typeof window?window:void 0;if(void 0!==ue){ue.BABYLON=ue.BABYLON||{},ue.BABYLON.GLTF1=ue.BABYLON.GLTF1||{};for(const e in ce)ue.BABYLON.GLTF1[e]=ce[e]}e.GLTF1=ce,e.GLTFFileLoader=_,e.GLTFLoaderDefaultOptions=b,e.GLTFValidation=r,e.RegisterGLTFFileLoader=y});
2
2
  //# sourceMappingURL=babylon.glTF1FileLoader.min.js.map