@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
1 lines • 65.7 kB
JavaScript
import{bS as e,aY as t,O as s,bT as n,y as r,bU as a,bV as o,bW as i,bX as l,bn as h,bp as d,bo as c,F as u,bY as _,aV as p,bh as m,bi as f,bZ as b,bJ as y,V as g,M as A,aD as v,aU as x,b_ as M,b$ as w,c0 as C,bk as E,a7 as O,i as T,bv as L,c1 as S,m as $,c2 as P,c3 as R,c4 as k,T as I,bl as N}from"./index-BPURObVq.esm.min.js";import{M as B,a as V,F}from"./morphTargetManager-CdEb1BHc.esm.min.js";import{B as G}from"./bone.pure-BcPT5kCP.esm.min.js";import{S as D}from"./skeleton-DinTjF3y.esm.min.js";import{A as U}from"./assetContainer-CAncviZo.esm.min.js";import{a as j}from"./objectModelMapping-ClgDmo5Q.esm.min.js";class W{constructor(e){this.byteOffset=0,this.buffer=e}async loadAsync(e){const t=await this.buffer.readAsync(this.byteOffset,e);this._dataView=new DataView(t.buffer,t.byteOffset,t.byteLength),this._dataByteOffset=0}readUint32(){const e=this._dataView.getUint32(this._dataByteOffset,!0);return this._dataByteOffset+=4,this.byteOffset+=4,e}readUint8Array(e){const t=new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+this._dataByteOffset,e);return this._dataByteOffset+=e,this.byteOffset+=e,t}readString(t){return e(this.readUint8Array(t))}skipBytes(e){this._dataByteOffset+=e,this.byteOffset+=e}}function H(e,t,s,n){const r={externalResourceFunction:n};return s&&(r.uri="file:"===t?s:t+s),ArrayBuffer.isView(e)?GLTFValidator.validateBytes(e,r):GLTFValidator.validateString(e,r)}function K(){const e=[];onmessage=t=>{const s=t.data;switch(s.id){case"init":importScripts(s.url);break;case"validate":H(s.data,s.rootUrl,s.fileName,t=>new Promise((s,n)=>{const r=e.length;e.push({resolve:s,reject:n}),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 q{static ValidateAsync(e,s,n,r){return"function"==typeof Worker?new Promise((a,o)=>{const i=`${H}(${K})()`,l=URL.createObjectURL(new Blob([i],{type:"application/javascript"})),h=new Worker(l),d=e=>{h.removeEventListener("error",d),h.removeEventListener("message",c),o(e)},c=e=>{const t=e.data;switch(t.id){case"getExternalResource":r(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",d),h.removeEventListener("message",c),q._LastResults=t.value,a(t.value),h.terminate();break;case"validate.reject":h.removeEventListener("error",d),h.removeEventListener("message",c),o(t.reason),h.terminate()}};if(h.addEventListener("error",d),h.addEventListener("message",c),h.postMessage({id:"init",url:t.GetBabylonScriptURL(this.Configuration.url)}),ArrayBuffer.isView(e)){const t=e.slice();h.postMessage({id:"validate",data:t,rootUrl:s,fileName:n},[t.buffer])}else h.postMessage({id:"validate",data:e,rootUrl:s,fileName:n})}):(this._LoadScriptPromise||(this._LoadScriptPromise=t.LoadBabylonScriptAsync(this.Configuration.url)),this._LoadScriptPromise.then(()=>H(e,s,n,r)))}}function J(e,t,s){try{return Promise.resolve(new Uint8Array(e,t,s))}catch(e){return Promise.reject(e)}}var z,X,Z;q.Configuration={url:`${t._DefaultCdnUrl}/gltf_validator.js`},q._LastResults=null,function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"}(z||(z={})),function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"}(X||(X={})),function(e){e[e.LOADING=0]="LOADING",e[e.READY=1]="READY",e[e.COMPLETE=2]="COMPLETE"}(Z||(Z={}));class Y{constructor(){this.alwaysComputeBoundingBox=!1,this.alwaysComputeSkeletonRootNode=!1,this.animationStartMode=X.FIRST,this.compileMaterials=!1,this.compileShadowGenerators=!1,this.coordinateSystemMode=z.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 Q=new Y;class ee extends Y{constructor(){super(...arguments),this.extensionOptions={},this.preprocessUrlAsync=e=>Promise.resolve(e)}copyFrom(e){e&&(this.alwaysComputeBoundingBox=e.alwaysComputeBoundingBox??this.alwaysComputeBoundingBox,this.alwaysComputeSkeletonRootNode=e.alwaysComputeSkeletonRootNode??this.alwaysComputeSkeletonRootNode,this.animationStartMode=e.animationStartMode??this.animationStartMode,this.capturePerformanceCounters=e.capturePerformanceCounters??this.capturePerformanceCounters,this.compileMaterials=e.compileMaterials??this.compileMaterials,this.compileShadowGenerators=e.compileShadowGenerators??this.compileShadowGenerators,this.coordinateSystemMode=e.coordinateSystemMode??this.coordinateSystemMode,this.createInstances=e.createInstances??this.createInstances,this.customRootNode=e.customRootNode,this.extensionOptions=e.extensionOptions??this.extensionOptions,this.loadAllMaterials=e.loadAllMaterials??this.loadAllMaterials,this.loadMorphTargets=e.loadMorphTargets??this.loadMorphTargets,this.loadNodeAnimations=e.loadNodeAnimations??this.loadNodeAnimations,this.loadOnlyMaterials=e.loadOnlyMaterials??this.loadOnlyMaterials,this.loadSkins=e.loadSkins??this.loadSkins,this.loggingEnabled=e.loggingEnabled??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=e.preprocessUrlAsync??this.preprocessUrlAsync,this.skipMaterials=e.skipMaterials??this.skipMaterials,this.targetFps=e.targetFps??this.targetFps,this.transparencyAsCoverage=e.transparencyAsCoverage??this.transparencyAsCoverage,this.useClipPlane=e.useClipPlane??this.useClipPlane,this.useGltfTextureNames=e.useGltfTextureNames??this.useGltfTextureNames,this.useMaxMorphTargetInfluencers=e.useMaxMorphTargetInfluencers??this.useMaxMorphTargetInfluencers,this.useOpenPBR=e.useOpenPBR??this.useOpenPBR,this.useRangeRequests=e.useRangeRequests??this.useRangeRequests,this.useSRGBBuffers=e.useSRGBBuffers??this.useSRGBBuffers,this.validate=e.validate??this.validate,this.dontUseTransmissionHelper=e.dontUseTransmissionHelper??this.dontUseTransmissionHelper)}}class te extends ee{constructor(e){super(),this.onParsedObservable=new s,this.onMeshLoadedObservable=new s,this.onSkinLoadedObservable=new s,this.onTextureLoadedObservable=new s,this.onMaterialLoadedObservable=new s,this.onCameraLoadedObservable=new s,this.onCompleteObservable=new s,this.onErrorObservable=new s,this.onDisposeObservable=new s,this.onExtensionLoadedObservable=new s,this.onValidatedObservable=new s,this._loader=null,this._state=null,this._requests=new Array,this.name=n.name,this.extensions=n.extensions,this.onLoaderStateChangedObservable=new s,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({...Q},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,a,o,i,l,h,d){if(ArrayBuffer.isView(n))return this._loadBinary(e,n,a,o,h,d),null;this._progressCallback=i;const c=n.name||t.GetFilename(n);if(l){if(this.useRangeRequests){this.validate&&r.Warn("glTF validation is not supported when range requests are enabled");const t={abort:()=>{},onCompleteObservable:new s},a={readAsync:(t,s)=>new Promise((r,a)=>{this._loadFile(e,n,e=>{r(new Uint8Array(e))},!0,e=>{a(e)},e=>{e.setRequestHeader("Range",`bytes=${t}-${t+s-1}`)})}),byteLength:0};return this._unpackBinaryAsync(new W(a)).then(e=>{t.onCompleteObservable.notifyObservers(t),o(e)},h?e=>h(void 0,e):void 0),t}return this._loadFile(e,n,t=>{this._validate(e,new Uint8Array(t,0,t.byteLength),a,c),this._unpackBinaryAsync(new W({readAsync:(e,s)=>J(t,e,s),byteLength:t.byteLength})).then(e=>{o(e)},h?e=>h(void 0,e):void 0)},!0,h)}return this._loadFile(e,n,t=>{try{this._validate(e,t,a,c),o({json:this._parseJson(t)})}catch{h&&h()}},!1,h)}_loadBinary(e,t,s,n,r,a){this._validate(e,new Uint8Array(t.buffer,t.byteOffset,t.byteLength),s,a),this._unpackBinaryAsync(new W({readAsync:(e,s)=>function(e,t,s){try{if(t<0||t>=e.byteLength)throw new RangeError("Offset is out of range.");if(t+s>e.byteLength)throw new RangeError("Length is out of range.");return Promise.resolve(new Uint8Array(e.buffer,e.byteOffset+t,s))}catch(e){return Promise.reject(e)}}(t,e,s),byteLength:t.byteLength})).then(e=>{n(e)},r?e=>r(void 0,e):void 0)}importMeshAsync(e,t,s,n,r,a){return Promise.resolve().then(()=>(this.onParsedObservable.notifyObservers(s),this.onParsedObservable.clear(),this._log(`Loading ${a||""}`),this._loader=this._getLoader(s),this._loader.importMeshAsync(e,t,null,s,n,r,a)))}loadAsync(e,t,s,n,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,s,n,r)))}loadAssetContainerAsync(e,t,s,n,r){return Promise.resolve().then(()=>{this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),this._log(`Loading ${r||""}`),this._loader=this._getLoader(t);const a=new U(e),o=[];this.onMaterialLoadedObservable.add(e=>{o.push(e)});const i=[];this.onTextureLoadedObservable.add(e=>{i.push(e)});const l=[];this.onCameraLoadedObservable.add(e=>{l.push(e)});const h=[];return this.onMeshLoadedObservable.add(e=>{e.morphTargetManager&&h.push(e.morphTargetManager)}),this._loader.importMeshAsync(null,e,a,t,s,n,r).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,o),Array.prototype.push.apply(a.textures,i),Array.prototype.push.apply(a.lights,e.lights),Array.prototype.push.apply(a.transformNodes,e.transformNodes),Array.prototype.push.apply(a.cameras,l),Array.prototype.push.apply(a.morphTargetManagers,h),a))})}canDirectLoad(e){return n.canDirectLoad(e)}directLoad(e,t){if(t.startsWith("base64,"+a)||t.startsWith(";base64,"+a)||t.startsWith("application/octet-stream;base64,"+a)||t.startsWith("model/gltf-binary;base64,"+a)){const s=o(t);return this._validate(e,new Uint8Array(s,0,s.byteLength)),this._unpackBinaryAsync(new W({readAsync:(e,t)=>J(s,e,t),byteLength:s.byteLength}))}return this._validate(e,t),Promise.resolve({json:this._parseJson(t)})}createPlugin(e){return new te(e[n.name])}get loaderState(){return this._state}whenCompleteAsync(){return new Promise((e,t)=>{this.onCompleteObservable.addOnce(()=>{e()}),this.onErrorObservable.addOnce(e=>{t(e)})})}_setState(e){this._state!==e&&(this._state=e,this.onLoaderStateChangedObservable.notifyObservers(this._state),this._log(Z[this._state]))}_loadFile(e,t,s,n,r,a){const o=e._loadFile(t,s,e=>{this._onProgress(e,o)},!0,n,r,a);return o.onCompleteObservable.add(()=>{o._lengthComputable=!0,o._total=o._loaded}),this._requests.push(o),o}_onProgress(e,t){if(!this._progressCallback)return;t._lengthComputable=e.lengthComputable,t._loaded=e.loaded,t._total=e.total;let s=!0,n=0,r=0;for(const e of this._requests){if(void 0===e._lengthComputable||void 0===e._loaded||void 0===e._total)return;s=s&&e._lengthComputable,n+=e._loaded,r+=e._total}this._progressCallback({lengthComputable:s,loaded:n,total:s?r:0})}_validate(e,s,n="",r=""){this.validate&&(this._startPerformanceCounter("Validate JSON"),q.ValidateAsync(s,n,r,t=>this.preprocessUrlAsync(n+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.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 s=te._parseVersion(t.version);if(!s)throw new Error("Invalid version: "+t.version);if(void 0!==t.minVersion){const e=te._parseVersion(t.minVersion);if(!e)throw new Error("Invalid minimum version: "+t.minVersion);if(te._compareVersion(e,{major:2,minor:0})>0)throw new Error("Incompatible minimum version: "+t.minVersion)}const n={1:te._CreateGLTF1Loader,2:te._CreateGLTF2Loader}[s.major];if(!n)throw new Error("Unsupported version: "+t.version);return n(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 t=e.readUint32();if(1179937895!==t)throw new i("Unexpected magic: "+t,l.GLTFLoaderUnexpectedMagicError);const s=e.readUint32();this.loggingEnabled&&this._log(`Binary version: ${s}`);const n=e.readUint32();let a;switch(this.useRangeRequests||n===e.buffer.byteLength||r.Warn(`Length in header does not match actual data length: ${n} != ${e.buffer.byteLength}`),s){case 1:a=this._unpackBinaryV1Async(e,n);break;case 2:a=this._unpackBinaryV2Async(e,n);break;default:throw new Error("Unsupported version: "+s)}return this._endPerformanceCounter("Unpack Binary"),a})}_unpackBinaryV1Async(e,t){const s=e.readUint32(),n=e.readUint32();if(0!==n)throw new Error(`Unexpected content format: ${n}`);const r=t-e.byteOffset,a={json:this._parseJson(e.readString(s)),bin:null};if(0!==r){const t=e.byteOffset;a.bin={readAsync:(s,n)=>e.buffer.readAsync(t+s,n),byteLength:r}}return Promise.resolve(a)}_unpackBinaryV2Async(e,t){const s=1313821514,n=5130562,r=e.readUint32();if(e.readUint32()!==s)throw new Error("First chunk format is not JSON");return e.byteOffset+r===t?e.loadAsync(r).then(()=>({json:this._parseJson(e.readString(r)),bin:null})):e.loadAsync(r+8).then(()=>{const a={json:this._parseJson(e.readString(r)),bin:null},o=()=>{const r=e.readUint32();switch(e.readUint32()){case s:throw new Error("Unexpected JSON chunk");case n:{const t=e.byteOffset;a.bin={readAsync:(s,n)=>e.buffer.readAsync(t+s,n),byteLength:r},e.skipBytes(r);break}default:e.skipBytes(r)}return e.byteOffset!==t?e.loadAsync(8).then(o):Promise.resolve(a)};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 t=te._logSpaces.substring(0,2*this._logIndentLevel);r.Log(`${t}${e}`)}_logDisabled(e){}_startPerformanceCounterEnabled(e){t.StartPerformanceCounter(e)}_startPerformanceCounterDisabled(e){}_endPerformanceCounterEnabled(e){t.EndPerformanceCounter(e)}_endPerformanceCounterDisabled(e){}}te.IncrementalLoading=!0,te.HomogeneousCoordinates=!1,te._logSpaces=" ";let se=!1;function ne(){se||(se=!0,h(new te))}const re=new M(()=>import("./animationGroup-ChS5fjKZ.esm.min.js")),ae=new M(()=>import("./glTFLoaderAnimation-BVk4dWhg.esm.min.js"));class oe{static Get(e,t,s){if(!t||null==s||!t[s])throw new Error(`${e}: Failed to find index (${s})`);return t[s]}static TryGet(e,t){return e&&null!=t&&e[t]?e[t]:null}static Assign(e){if(e)for(let t=0;t<e.length;t++)e[t].index=t}}function ie(e){if(e.min&&e.max){const t=e.min,s=e.max,n=I.Vector3[0].copyFromFloats(t[0],t[1],t[2]),r=I.Vector3[1].copyFromFloats(s[0],s[1],s[2]);if(e.normalized&&5126!==e.componentType){let t=1;switch(e.componentType){case 5120:t=127;break;case 5121:t=255;break;case 5122:t=32767;break;case 5123:t=65535}const s=1/t;n.scaleInPlace(s),r.scaleInPlace(s)}return new N(n,r)}return null}class le{isMatchingMaterialType(e){if(!e)return!1;const t=Array.from(this._pbrMaterialImpls.values());for(const s of t)if(e instanceof s.materialClass)return!0;return!1}static RegisterExtension(e,t){d(e,!1,t)}static UnregisterExtension(e){return c(e)}get gltf(){if(!this._gltf)throw new Error("glTF JSON is not available");return this._gltf}get bin(){return this._bin}get parent(){return this._parent}get babylonScene(){if(!this._babylonScene)throw new Error("Scene is not available");return this._babylonScene}get rootBabylonMesh(){return this._rootBabylonMesh}get rootUrl(){return this._rootUrl}constructor(e){this._completePromises=new Array,this._assetContainer=null,this._babylonLights=[],this._disableInstancedMesh=0,this._allMaterialsDirtyRequired=!1,this._skipStartAnimationStep=!1,this._extensions=new Array,this._disposed=!1,this._rootUrl=null,this._fileName=null,this._uniqueRootUrl=null,this._bin=null,this._rootBabylonMesh=null,this._defaultBabylonMaterialData={},this._postSceneLoadActions=new Array,this._materialAdapterCache=new WeakMap,this._materialAdapters=new Set,this._pbrMaterialImpls=new Map,this._parent=e}_getOrCreateMaterialAdapter(e){let t=this._materialAdapterCache.get(e);if(!t){const s=Array.from(this._pbrMaterialImpls.values());for(const n of s)if(e instanceof n.materialClass){t=new n.adapterClass(e);break}if(!t)throw new Error("Appropriate material adapter class not found");const n=t;this._materialAdapterCache.set(e,n),this._materialAdapters.add(n)}return t}dispose(){this._disposed||(this._disposed=!0,this._completePromises.length=0,this._extensions.forEach(e=>e.dispose&&e.dispose()),this._extensions.length=0,this._materialAdapters.clear(),this._gltf=null,this._bin=null,this._babylonScene=null,this._rootBabylonMesh=null,this._defaultBabylonMaterialData={},this._postSceneLoadActions.length=0,this._parent.dispose())}async importMeshAsync(e,t,s,n,r,a,o=""){return await Promise.resolve().then(async()=>{this._babylonScene=t,this._assetContainer=s,this._loadData(n);let a=null;if(e){const t={};if(this._gltf.nodes)for(const e of this._gltf.nodes)e.name&&(t[e.name]=e.index);a=(e instanceof Array?e:[e]).map(e=>{const s=t[e];if(void 0===s)throw new Error(`Failed to find node '${e}'`);return s})}return await this._loadAsync(r,o,a,()=>({meshes:this._getMeshes(),particleSystems:[],skeletons:this._getSkeletons(),animationGroups:this._getAnimationGroups(),lights:this._babylonLights,transformNodes:this._getTransformNodes(),geometries:this._getGeometries(),spriteManagers:[]}))})}async loadAsync(e,t,s,n,r=""){return this._babylonScene=e,this._loadData(t),await this._loadAsync(s,r,null,()=>{})}async _loadAsync(e,s,n,r){return await Promise.resolve().then(async()=>{if(this._rootUrl=e,this._uniqueRootUrl=!e.startsWith("file:")&&s?e:`${e}${Date.now()}/`,this._fileName=s,this._allMaterialsDirtyRequired=!1,await this._loadExtensionsAsync(),!this.parent.skipMaterials){const e=this.parent.useOpenPBR||this.isExtensionUsed("KHR_materials_openpbr");let t=!1;this.parent.useOpenPBR?this._gltf.materials?.length&&this._gltf.materials.some(e=>!e.extensions?.KHR_materials_openpbr)&&(t=!0):t=!0;const s=[];e&&!this._pbrMaterialImpls.has("openpbr")&&s.push(Promise.all([import("./openpbrMaterial.pure-BTbF5aqI.esm.min.js"),import("./openpbrMaterialLoadingAdapter-CTilhLtn.esm.min.js")]).then(([{OpenPBRMaterial:e,RegisterOpenpbrMaterial:t},{OpenPBRMaterialLoadingAdapter:s}])=>{t(),this._pbrMaterialImpls.set("openpbr",{materialClass:e,adapterClass:s})})),t&&!this._pbrMaterialImpls.has("pbr")&&s.push(Promise.all([import("./pbrMaterial.pure-BfTTBEBK.esm.min.js"),import("./pbrMaterialLoadingAdapter-D4SUWDd6.esm.min.js")]).then(([{PBRMaterial:e,RegisterPbrMaterial:t},{PBRMaterialLoadingAdapter:s}])=>{t(),this._pbrMaterialImpls.set("pbr",{materialClass:e,adapterClass:s})})),await Promise.all(s)}const a=`${Z[Z.LOADING]} => ${Z[Z.READY]}`,o=`${Z[Z.LOADING]} => ${Z[Z.COMPLETE]}`;this._parent._startPerformanceCounter(a),this._parent._startPerformanceCounter(o),this._parent._setState(Z.LOADING),this._extensionsOnLoading();const i=new Array,l=this._babylonScene.blockMaterialDirtyMechanism;if(this._babylonScene.blockMaterialDirtyMechanism=!0,!this.parent.loadOnlyMaterials)if(n)i.push(this.loadSceneAsync("/nodes",{nodes:n,index:-1}));else if(null!=this._gltf.scene||this._gltf.scenes&&this._gltf.scenes[0]){const e=oe.Get("/scene",this._gltf.scenes,this._gltf.scene||0);i.push(this.loadSceneAsync(`/scenes/${e.index}`,e))}if(!this.parent.skipMaterials&&this.parent.loadAllMaterials&&this._gltf.materials)for(let e=0;e<this._gltf.materials.length;++e){const t=this._gltf.materials[e],s="/materials/"+e,n=u.TriangleFillMode;i.push(this._loadMaterialAsync(s,t,null,n,()=>{}))}this._allMaterialsDirtyRequired?this._babylonScene.blockMaterialDirtyMechanism=l:this._babylonScene._forceBlockMaterialDirtyMechanism(l),this._parent.compileMaterials&&i.push(this._compileMaterialsAsync()),this._parent.compileShadowGenerators&&i.push(this._compileShadowGeneratorsAsync());const h=Promise.all(i).then(()=>{this._rootBabylonMesh&&this._rootBabylonMesh!==this._parent.customRootNode&&this._rootBabylonMesh.setEnabled(!0);for(const e of this._babylonScene.materials){const t=e;void 0!==t.maxSimultaneousLights&&(t.maxSimultaneousLights=Math.max(t.maxSimultaneousLights,this._babylonScene.lights.length))}for(const e of Array.from(this._materialAdapters))this._completePromises.push(e.finalizeAsync(this));return this._extensionsOnReady(),this._parent._setState(Z.READY),this._skipStartAnimationStep||this._startAnimations(),r()});return await h.then(e=>(this._parent._endPerformanceCounter(a),t.SetImmediate(()=>{this._disposed||Promise.all(this._completePromises).then(()=>{this._parent._endPerformanceCounter(o),this._parent._setState(Z.COMPLETE),this._parent.onCompleteObservable.notifyObservers(void 0),this._parent.onCompleteObservable.clear(),this.dispose()},e=>{this._parent.onErrorObservable.notifyObservers(e),this._parent.onErrorObservable.clear(),this.dispose()})}),e))}).catch(e=>{throw this._disposed||(this._parent.onErrorObservable.notifyObservers(e),this._parent.onErrorObservable.clear(),this.dispose()),e})}_loadData(e){if(this._gltf=e.json,this._setupData(),e.bin){const t=this._gltf.buffers;if(t&&t[0]&&!t[0].uri){const s=t[0];(s.byteLength<e.bin.byteLength-3||s.byteLength>e.bin.byteLength)&&r.Warn(`Binary buffer length (${s.byteLength}) from JSON does not match chunk length (${e.bin.byteLength})`),this._bin=e.bin}else r.Warn("Unexpected BIN chunk")}}_setupData(){if(oe.Assign(this._gltf.accessors),oe.Assign(this._gltf.animations),oe.Assign(this._gltf.buffers),oe.Assign(this._gltf.bufferViews),oe.Assign(this._gltf.cameras),oe.Assign(this._gltf.images),oe.Assign(this._gltf.materials),oe.Assign(this._gltf.meshes),oe.Assign(this._gltf.nodes),oe.Assign(this._gltf.samplers),oe.Assign(this._gltf.scenes),oe.Assign(this._gltf.skins),oe.Assign(this._gltf.textures),this._gltf.nodes){const e={};for(const t of this._gltf.nodes)if(t.children)for(const s of t.children)e[s]=t.index;const t=this._createRootNode();for(const s of this._gltf.nodes){const n=e[s.index];s.parent=void 0===n?t:this._gltf.nodes[n]}}}async _loadExtensionsAsync(){const e=[];if(_.forEach((t,s)=>{!1===this.parent.extensionOptions[s]?.enabled?t.isGLTFExtension&&this.isExtensionUsed(s)&&r.Warn(`Extension ${s} is used but has been explicitly disabled.`):t.isGLTFExtension&&!this.isExtensionUsed(s)||e.push((async()=>{const e=await t.factory(this);return e.name!==s&&r.Warn(`The name of the glTF loader extension instance does not match the registered name: ${e.name} !== ${s}`),this._parent.onExtensionLoadedObservable.notifyObservers(e),e})())}),this._extensions.push(...await Promise.all(e)),this._extensions.sort((e,t)=>(e.order||Number.MAX_VALUE)-(t.order||Number.MAX_VALUE)),this._parent.onExtensionLoadedObservable.clear(),this._gltf.extensionsRequired)for(const e of this._gltf.extensionsRequired){if(!this._extensions.some(t=>t.name===e&&t.enabled)){if(!1===this.parent.extensionOptions[e]?.enabled)throw new Error(`Required extension ${e} is disabled`);throw new Error(`Required extension ${e} is not available`)}}}_createRootNode(){if(void 0!==this._parent.customRootNode)return this._rootBabylonMesh=this._parent.customRootNode,{_babylonTransformNode:null===this._rootBabylonMesh?void 0:this._rootBabylonMesh,index:-1};this._babylonScene._blockEntityCollection=!!this._assetContainer;const e=new p("__root__",this._babylonScene);this._rootBabylonMesh=e,this._rootBabylonMesh._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,this._rootBabylonMesh.setEnabled(!1);const t={_babylonTransformNode:this._rootBabylonMesh,index:-1};switch(this._parent.coordinateSystemMode){case z.AUTO:this._babylonScene.useRightHandedSystem||(t.rotation=[0,1,0,0],t.scale=[1,1,-1],le._LoadTransform(t,this._rootBabylonMesh));break;case z.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:throw new Error(`Invalid coordinate system mode (${this._parent.coordinateSystemMode})`)}return this._parent.onMeshLoadedObservable.notifyObservers(e),t}loadSceneAsync(e,t){const s=this._extensionsLoadSceneAsync(e,t);if(s)return s;const n=new Array;if(this.logOpen(`${e} ${t.name||""}`),t.nodes)for(const s of t.nodes){const t=oe.Get(`${e}/nodes/${s}`,this._gltf.nodes,s);n.push(this.loadNodeAsync(`/nodes/${t.index}`,t,e=>{e.parent=this._rootBabylonMesh}))}for(const e of this._postSceneLoadActions)e();return n.push(this._loadAnimationsAsync()),this.logClose(),Promise.all(n).then(()=>{})}_forEachPrimitive(e,t){if(e._primitiveBabylonMeshes)for(const s of e._primitiveBabylonMeshes)t(s)}_getGeometries(){const e=[],t=this._gltf.nodes;if(t)for(const s of t)this._forEachPrimitive(s,t=>{const s=t.geometry;s&&-1===e.indexOf(s)&&e.push(s)});return e}_getMeshes(){const e=[];this._rootBabylonMesh instanceof m&&e.push(this._rootBabylonMesh);const t=this._gltf.nodes;if(t)for(const s of t)this._forEachPrimitive(s,t=>{e.push(t)});return e}_getTransformNodes(){const e=[],t=this._gltf.nodes;if(t)for(const s of t)s._babylonTransformNode&&"TransformNode"===s._babylonTransformNode.getClassName()&&e.push(s._babylonTransformNode),s._babylonTransformNodeForSkin&&e.push(s._babylonTransformNodeForSkin);return e}_getSkeletons(){const e=[],t=this._gltf.skins;if(t)for(const s of t)s._data&&e.push(s._data.babylonSkeleton);return e}_getAnimationGroups(){const e=[],t=this._gltf.animations;if(t)for(const s of t)s._babylonAnimationGroup&&e.push(s._babylonAnimationGroup);return e}_startAnimations(){switch(this._parent.animationStartMode){case X.NONE:break;case X.FIRST:{const e=this._getAnimationGroups();0!==e.length&&e[0].start(!0);break}case X.ALL:{const e=this._getAnimationGroups();for(const t of e)t.start(!0);break}default:return void r.Error(`Invalid animation start mode (${this._parent.animationStartMode})`)}}loadNodeAsync(e,t,s=()=>{}){const n=this._extensionsLoadNodeAsync(e,t,s);if(n)return n;if(t._babylonTransformNode)throw new Error(`${e}: Invalid recursive node hierarchy`);const r=new Array;this.logOpen(`${e} ${t.name||""}`);const a=n=>{if(le.AddPointerMetadata(n,e),le._LoadTransform(t,n),null!=t.camera){const s=oe.Get(`${e}/camera`,this._gltf.cameras,t.camera);r.push(this.loadCameraAsync(`/cameras/${s.index}`,s,e=>{e.parent=n,this._babylonScene.useRightHandedSystem||(n.scaling.x=-1)}))}if(t.children)for(const s of t.children){const t=oe.Get(`${e}/children/${s}`,this._gltf.nodes,s);r.push(this.loadNodeAsync(`/nodes/${t.index}`,t,e=>{e.parent=n}))}s(n)},o=null!=t.mesh,i=this._parent.loadSkins&&null!=t.skin;if(!o||i){const e=t.name||`node${t.index}`;this._babylonScene._blockEntityCollection=!!this._assetContainer;const s=new f(e,this._babylonScene);s._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,null==t.mesh?t._babylonTransformNode=s:t._babylonTransformNodeForSkin=s,a(s)}if(o)if(i){const s=oe.Get(`${e}/mesh`,this._gltf.meshes,t.mesh);r.push(this._loadMeshAsync(`/meshes/${s.index}`,t,s,s=>{const n=t._babylonTransformNodeForSkin;s.metadata=b(n.metadata,s.metadata||{});const a=oe.Get(`${e}/skin`,this._gltf.skins,t.skin);r.push(this._loadSkinAsync(`/skins/${a.index}`,t,a,e=>{this._forEachPrimitive(t,t=>{t.skeleton=e}),this._postSceneLoadActions.push(()=>{if(null!=a.skeleton){const e=oe.Get(`/skins/${a.index}/skeleton`,this._gltf.nodes,a.skeleton).parent;t.index===e.index?s.parent=n.parent:s.parent=e._babylonTransformNode}else s.parent=this._rootBabylonMesh;this._parent.onSkinLoadedObservable.notifyObservers({node:n,skinnedNode:s})})}))}))}else{const s=oe.Get(`${e}/mesh`,this._gltf.meshes,t.mesh);r.push(this._loadMeshAsync(`/meshes/${s.index}`,t,s,a))}return this.logClose(),Promise.all(r).then(()=>(this._forEachPrimitive(t,e=>{const t=e;!t.isAnInstance&&t.geometry&&t.geometry.useBoundingInfoFromGeometry?e._updateBoundingInfo():e.refreshBoundingInfo(!0,!0)}),t._babylonTransformNode))}_loadMeshAsync(e,t,s,n){const r=s.primitives;if(!r||!r.length)throw new Error(`${e}: Primitives are missing`);null==r[0].index&&oe.Assign(r);const a=new Array;this.logOpen(`${e} ${s.name||""}`);const o=t.name||`node${t.index}`;if(1===r.length){const n=s.primitives[0];a.push(this._loadMeshPrimitiveAsync(`${e}/primitives/${n.index}`,o,t,s,n,e=>{t._babylonTransformNode=e,t._primitiveBabylonMeshes=[e]}))}else{this._babylonScene._blockEntityCollection=!!this._assetContainer,t._babylonTransformNode=new f(o,this._babylonScene),t._babylonTransformNode._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,t._primitiveBabylonMeshes=[];for(const n of r)a.push(this._loadMeshPrimitiveAsync(`${e}/primitives/${n.index}`,`${o}_primitive${n.index}`,t,s,n,e=>{e.parent=t._babylonTransformNode,t._primitiveBabylonMeshes.push(e)}))}return n(t._babylonTransformNode),this.logClose(),Promise.all(a).then(()=>t._babylonTransformNode)}_loadMeshPrimitiveAsync(e,t,s,n,r,a){const o=this._extensionsLoadMeshPrimitiveAsync(e,t,s,n,r,a);if(o)return o;this.logOpen(`${e}`);const i=0===this._disableInstancedMesh&&this._parent.createInstances&&null==s.skin&&!n.primitives[0].targets;let l,h;if(i&&r._instanceData)this._babylonScene._blockEntityCollection=!!this._assetContainer,l=r._instanceData.babylonSourceMesh.createInstance(t),l._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,h=r._instanceData.promise;else{const a=new Array;this._babylonScene._blockEntityCollection=!!this._assetContainer;const o=new p(t,this._babylonScene);if(o._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,o.sideOrientation=this._babylonScene.useRightHandedSystem?u.CounterClockWiseSideOrientation:u.ClockWiseSideOrientation,this._createMorphTargets(e,s,n,r,o),a.push(this._loadVertexDataAsync(e,r,o).then(async t=>await this._loadMorphTargetsAsync(e,r,o,t).then(()=>{this._disposed||(this._babylonScene._blockEntityCollection=!!this._assetContainer,t.applyToMesh(o),t._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1)}))),!this.parent.skipMaterials){const t=le._GetDrawMode(e,r.mode);if(null==r.material){let e=this._defaultBabylonMaterialData[t];e||(e=this._createDefaultMaterial("__GLTFLoader._default",t,this._getDefaultImpl()),this._parent.onMaterialLoadedObservable.notifyObservers(e),this._defaultBabylonMaterialData[t]=e),o.material=e}else{const s=oe.Get(`${e}/material`,this._gltf.materials,r.material);a.push(this._loadMaterialAsync(`/materials/${s.index}`,s,o,t,e=>{o.material=e}))}}h=Promise.all(a),i&&(r._instanceData={babylonSourceMesh:o,promise:h}),l=o}return le.AddPointerMetadata(l,e),this._parent.onMeshLoadedObservable.notifyObservers(l),a(l),this.logClose(),h.then(()=>l)}_loadVertexDataAsync(e,t,s){const n=this._extensionsLoadVertexDataAsync(e,t,s);if(n)return n;const r=t.attributes;if(!r)throw new Error(`${e}: Attributes are missing`);const a=new Array,o=new y(s.name,this._babylonScene);if(null==t.indices)s.isUnIndexed=!0;else{const s=oe.Get(`${e}/indices`,this._gltf.accessors,t.indices);a.push(this._loadIndicesAccessorAsync(`/accessors/${s.index}`,s).then(e=>{o.setIndices(e)}))}const i=(t,n,i)=>{if(null==r[t])return;s._delayInfo=s._delayInfo||[],-1===s._delayInfo.indexOf(n)&&s._delayInfo.push(n);const l=oe.Get(`${e}/attributes/${t}`,this._gltf.accessors,r[t]);a.push(this._loadVertexAccessorAsync(`/accessors/${l.index}`,l,n).then(e=>{if(e.getKind()===O.PositionKind&&!this.parent.alwaysComputeBoundingBox&&!s.skeleton){const e=ie(l);e&&(o._boundingInfo=e,o.useBoundingInfoFromGeometry=!0)}o.setVerticesBuffer(e,l.count)})),n==O.MatricesIndicesExtraKind&&(s.numBoneInfluencers=8),i&&i(l)};return i("POSITION",O.PositionKind),i("NORMAL",O.NormalKind),i("TANGENT",O.TangentKind),i("TEXCOORD_0",O.UVKind),i("TEXCOORD_1",O.UV2Kind),i("TEXCOORD_2",O.UV3Kind),i("TEXCOORD_3",O.UV4Kind),i("TEXCOORD_4",O.UV5Kind),i("TEXCOORD_5",O.UV6Kind),i("JOINTS_0",O.MatricesIndicesKind),i("WEIGHTS_0",O.MatricesWeightsKind),i("JOINTS_1",O.MatricesIndicesExtraKind),i("WEIGHTS_1",O.MatricesWeightsExtraKind),i("COLOR_0",O.ColorKind,e=>{"VEC4"===e.type&&(s.hasVertexAlpha=!0)}),Promise.all(a).then(()=>o)}_createMorphTargets(e,t,s,n,r){if(!n.targets||!this._parent.loadMorphTargets)return;if(null==t._numMorphTargets)t._numMorphTargets=n.targets.length;else if(n.targets.length!==t._numMorphTargets)throw new Error(`${e}: Primitives do not have the same number of targets`);const a=s.extras?s.extras.targetNames:null;this._babylonScene._blockEntityCollection=!!this._assetContainer,r.morphTargetManager=new B(this._babylonScene),r.morphTargetManager._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,r.morphTargetManager.areUpdatesFrozen=!0;for(let e=0;e<n.targets.length;e++){const n=t.weights?t.weights[e]:s.weights?s.weights[e]:0,o=a?a[e]:`morphTarget${e}`;r.morphTargetManager.addTarget(new V(o,n,r.getScene()))}}_loadMorphTargetsAsync(e,t,s,n){if(!t.targets||!this._parent.loadMorphTargets)return Promise.resolve();const r=new Array,a=s.morphTargetManager;for(let s=0;s<a.numTargets;s++){const o=a.getTarget(s);r.push(this._loadMorphTargetVertexDataAsync(`${e}/targets/${s}`,n,t.targets[s],o))}return Promise.all(r).then(()=>{a.areUpdatesFrozen=!1,this._parent.useMaxMorphTargetInfluencers&&(a.isUsingTextureForTargets||a.numTargets<=B.MaxActiveMorphTargetsInVertexAttributeMode)&&(a.optimizeInfluencers=!1,a.numMaxInfluencers=a.numTargets)})}async _loadMorphTargetVertexDataAsync(e,t,s,n){const r=new Array,a=(n,a,o)=>{if(null==s[n])return;const i=t.getVertexBuffer(a);if(!i)return;const l=oe.Get(`${e}/${n}`,this._gltf.accessors,s[n]);r.push(this._loadFloatAccessorAsync(`/accessors/${l.index}`,l).then(e=>{o(i,e)}))};return a("POSITION",O.PositionKind,(e,t)=>{const s=new Float32Array(t.length);e.forEach(t.length,(e,n)=>{s[n]=t[n]+e}),n.setPositions(s)}),a("NORMAL",O.NormalKind,(e,t)=>{const s=new Float32Array(t.length);e.forEach(s.length,(e,n)=>{s[n]=t[n]+e}),n.setNormals(s)}),a("TANGENT",O.TangentKind,(e,t)=>{const s=new Float32Array(t.length/3*4);let r=0;e.forEach(t.length/3*4,(e,n)=>{(n+1)%4!=0&&(s[r]=t[r]+e,r++)}),n.setTangents(s)}),a("TEXCOORD_0",O.UVKind,(e,t)=>{const s=new Float32Array(t.length);e.forEach(t.length,(e,n)=>{s[n]=t[n]+e}),n.setUVs(s)}),a("TEXCOORD_1",O.UV2Kind,(e,t)=>{const s=new Float32Array(t.length);e.forEach(t.length,(e,n)=>{s[n]=t[n]+e}),n.setUV2s(s)}),a("COLOR_0",O.ColorKind,(t,s)=>{let r=null;const a=t.getSize();if(3===a){r=new Float32Array(s.length/3*4),t.forEach(s.length,(e,t)=>{const n=Math.floor(t/3),a=t%3;r[4*n+a]=s[3*n+a]+e});for(let e=0;e<s.length/3;++e)r[4*e+3]=1}else{if(4!==a)throw new Error(`${e}: Invalid number of components (${a}) for COLOR_0 attribute`);r=new Float32Array(s.length),t.forEach(s.length,(e,t)=>{r[t]=s[t]+e})}n.setColors(r)}),await Promise.all(r).then(()=>{})}static _LoadTransform(e,t){if(null!=e.skin)return;let s=g.Zero(),n=v.Identity(),r=g.One();if(e.matrix){A.FromArray(e.matrix).decompose(r,n,s)}else e.translation&&(s=g.FromArray(e.translation)),e.rotation&&(n=v.FromArray(e.rotation)),e.scale&&(r=g.FromArray(e.scale));t.position=s,t.rotationQuaternion=n,t.scaling=r}_loadSkinAsync(e,t,s,n){if(!this._parent.loadSkins)return Promise.resolve();const r=this._extensionsLoadSkinAsync(e,t,s);if(r)return r;if(s._data)return n(s._data.babylonSkeleton),s._data.promise;const a=`skeleton${s.index}`;this._babylonScene._blockEntityCollection=!!this._assetContainer;const o=new D(s.name||a,a,this._babylonScene);o._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,this._loadBones(e,s,o);const i=this._loadSkinInverseBindMatricesDataAsync(e,s).then(e=>{this._updateBoneMatrices(o,e)});return s._data={babylonSkeleton:o,promise:i},n(o),i}_loadBones(e,t,s){if(null==t.skeleton||this._parent.alwaysComputeSkeletonRootNode){const s=this._findSkeletonRootNode(`${e}/joints`,t.joints);if(s)if(void 0===t.skeleton)t.skeleton=s.index;else{const n=(e,t)=>{for(;t.parent;t=t.parent)if(t.parent===e)return!0;return!1},a=oe.Get(`${e}/skeleton`,this._gltf.nodes,t.skeleton);a===s||n(a,s)||(r.Warn(`${e}/skeleton: Overriding with nearest common ancestor as skeleton node is not a common root`),t.skeleton=s.index)}else r.Warn(`${e}: Failed to find common root`)}const n={};for(const r of t.joints){const a=oe.Get(`${e}/joints/${r}`,this._gltf.nodes,r);this._loadBone(a,t,s,n)}}_findSkeletonRootNode(e,t){if(0===t.length)return null;const s={};for(const n of t){const t=[];let r=oe.Get(`${e}/${n}`,this._gltf.nodes,n);for(;-1!==r.index;)t.unshift(r),r=r.parent;s[n]=t}let n=null;for(let e=0;;++e){let r=s[t[0]];if(e>=r.length)return n;const a=r[e];for(let o=1;o<t.length;++o)if(r=s[t[o]],e>=r.length||a!==r[e])return n;n=a}}_loadBone(e,t,s,n){e._isJoint=!0;let a=n[e.index];if(a)return a;let o=null;e.index!==t.skeleton&&(e.parent&&-1!==e.parent.index?o=this._loadBone(e.parent,t,s,n):void 0!==t.skeleton&&r.Warn(`/skins/${t.index}/skeleton: Skeleton node is not a common root`));const i=t.joints.indexOf(e.index);return a=new G(e.name||`joint${e.index}`,s,o,this._getNodeMatrix(e),null,null,i),n[e.index]=a,this._postSceneLoadActions.push(()=>{a.linkTransformNode(e._babylonTransformNode)}),a}_loadSkinInverseBindMatricesDataAsync(e,t){if(null==t.inverseBindMatrices)return Promise.resolve(null);const s=oe.Get(`${e}/inverseBindMatrices`,this._gltf.accessors,t.inverseBindMatrices);return this._loadFloatAccessorAsync(`/accessors/${s.index}`,s)}_updateBoneMatrices(e,t){for(const s of e.bones){const e=A.Identity(),n=s._index;t&&-1!==n&&(A.FromArrayToRef(t,16*n,e),e.invertToRef(e));const r=s.getParent();r&&e.multiplyToRef(r.getAbsoluteInverseBindMatrix(),e),s.updateMatrix(e,!1,!1),s._updateAbsoluteBindMatrices(void 0,!1)}}_getNodeMatrix(e){return e.matrix?A.FromArray(e.matrix):A.Compose(e.scale?g.FromArray(e.scale):g.One(),e.rotation?v.FromArray(e.rotation):v.Identity(),e.translation?g.FromArray(e.translation):g.Zero())}loadCameraAsync(e,t,s=()=>{}){const n=this._extensionsLoadCameraAsync(e,t,s);if(n)return n;const r=new Array;this.logOpen(`${e} ${t.name||""}`),this._babylonScene._blockEntityCollection=!!this._assetContainer;const a=new F(t.name||`camera${t.index}`,g.Zero(),this._babylonScene,!1);switch(a._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,t._babylonCamera=a,a.setTarget(new g(0,0,-1)),t.type){case"perspective":{const s=t.perspective;if(!s)throw new Error(`${e}: Camera perspective properties are missing`);a.fov=s.yfov,a.minZ=s.znear,a.maxZ=s.zfar||0;break}case"orthographic":if(!t.orthographic)throw new Error(`${e}: Camera orthographic properties are missing`);a.mode=x.ORTHOGRAPHIC_CAMERA,a.orthoLeft=-t.orthographic.xmag,a.orthoRight=t.orthographic.xmag,a.orthoBottom=-t.orthographic.ymag,a.orthoTop=t.orthographic.ymag,a.minZ=t.orthographic.znear,a.maxZ=t.orthographic.zfar;break;default:throw new Error(`${e}: Invalid camera type (${t.type})`)}return le.AddPointerMetadata(a,e),this._parent.onCameraLoadedObservable.notifyObservers(a),s(a),this.logClose(),Promise.all(r).then(()=>a)}_loadAnimationsAsync(){this._parent._startPerformanceCounter("Load animations");const e=this._gltf.animations;if(!e)return Promise.resolve();const t=new Array;for(let s=0;s<e.length;s++){const n=e[s];t.push(this.loadAnimationAsync(`/animations/${n.index}`,n).then(e=>{0===e.targetedAnimations.length&&e.dispose()}))}return Promise.all(t).then(()=>{this._parent._endPerformanceCounter("Load animations")})}loadAnimationAsync(e,t){this._parent._startPerformanceCounter("Load animation");const s=this._extensionsLoadAnimationAsync(e,t);return s||re.value.then(({AnimationGroup:s})=>{this._babylonScene._blockEntityCollection=!!this._assetContainer;const n=new s(t.name||`animation${t.index}`,this._babylonScene);n._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,t._babylonAnimationGroup=n;const r=new Array;oe.Assign(t.channels),oe.Assign(t.samplers);for(const s of t.channels)r.push(this._loadAnimationChannelAsync(`${e}/channels/${s.index}`,e,t,s,(e,t)=>{e.animations=e.animations||[],e.animations.push(t),n.addTargetedAnimation(t,e)}));return this._parent._endPerformanceCounter("Load animation"),Promise.all(r).then(()=>(n.normalize(0),n))})}_loadAnimationChannelAsync(e,t,s,n,r){const a=this._extensionsLoadAnimationChannelAsync(e,t,s,n,r);if(a)return a;if(null==n.target.node)return Promise.resolve();const o=oe.Get(`${e}/target/node`,this._gltf.nodes,n.target.node),i=n.target.path,l="weights"===i;return l&&!o._numMorphTargets||!l&&!o._babylonTransformNode?Promise.resolve():this._parent.loadNodeAnimations||l||o._isJoint?ae.value.then(()=>{let a;switch(i){case"translation":a=j("/nodes/{}/translation")?.interpolation;break;case"rotation":a=j("/nodes/{}/rotation")?.interpolation;break;case"scale":a=j("/nodes/{}/scale")?.interpolation;break;case"weights":a=j("/nodes/{}/weights")?.interpolation;break;default:throw new Error(`${e}/target/path: Invalid value (${n.target.path})`)}if(!a)throw new Error(`${e}/target/path: Could not find interpolation properties for target path (${n.target.path})`);const l={object:o,info:a};return this._loadAnimationChannelFromTargetInfoAsync(e,t,s,n,l,r)}):Promise.resolve()}_loadAnimationChannelFromTargetInfoAsync(e,t,s,n,r,a){const o=this.parent.targetFps,i=1/o,l=oe.Get(`${e}/sampler`,s.samplers,n.sampler);return this._loadAnimationSamplerAsync(`${t}/samplers/${n.sampler}`,l).then(e=>{let t=0;const l=r.object,h=r.info;for(const r of h){const h=r.getStride(l),d=e.input,c=e.output,u=new Array(d.length);let _=0;switch(e.interpolation){case"STEP":for(let e=0;e<d.length;e++){const t=r.getValue(l,c,_,1);_+=h,u[e]={frame:d[e]*o,value:t,interpolation:1}}break;case"CUBICSPLINE":for(let e=0;e<d.length;e++){const t=r.getValue(l,c,_,i);_+=h;const s=r.getValue(l,c,_,1);_+=h;const n=r.getValue(l,c,_,i);_+=h,u[e]={frame:d[e]*o,inTangent:t,value:s,outTangent:n}}break;case"LINEAR":for(let e=0;e<d.length;e++){const t=r.getValue(l,c,_,1);_+=h,u[e]={frame:d[e]*o,value:t}}}if(_>0){const e=`${s.name||`animation${s.index}`}_channel${n.index}_${t}`,i=r.buildAnimations(l,e,o,u);for(const e of i)t++,a(e.babylonAnimatable,e.babylonAnimation)}}})}_loadAnimationSamplerAsync(e,t){if(t._data)return t._data;const s=t.interpolation||"LINEAR";switch(s){case"STEP":case"LINEAR":case"CUBICSPLINE":break;default:throw new Error(`${e}/interpolation: Invalid value (${t.interpolation})`)}const n=oe.Get(`${e}/input`,this._gltf.accessors,t.input),r=oe.Get(`${e}/output`,this._gltf.accessors,t.output);return t._data=Promise.all([this._loadFloatAccessorAsync(`/accessors/${n.index}`,n),this._loadFloatAccessorAsync(`/accessors/${r.index}`,r)]).then(([e,t])=>({input:e,interpolation:s,output:t})),t._data}loadBufferAsync(e,t,s,n){const r=this._extensionsLoadBufferAsync(e,t,s,n);if(r)return r;if(!t._data)if(t.uri)t._data=this.loadUriAsync(`${e}/uri`,t,t.uri);else{if(!this._bin)throw new Error(`${e}: Uri is missing or the binary glTF is missing its binary chunk`);t._data=this._bin.readAsync(0,t.byteLength)}return t._data.then(t=>{try{return new Uint8Array(t.buffer,t.byteOffset+s,n)}catch(t){throw new Error(`${e}: ${t.message}`,{cause:t})}})}loadBufferViewAsync(e,t){const s=this._extensionsLoadBufferViewAsync(e,t);if(s)return s;if(t._data)return t._data;const n=oe.Get(`${e}/buffer`,this._gltf.buffers,t.buffer);return t._data=this.loadBufferAsync(`/buffers/${n.index}`,n,t.byteOffset||0,t.byteLength),t._data}_loadAccessorAsync(e,t,s){if(t._data)return t._data;const n=le._GetNumComponents(e,t.type),r=n*w(t.componentType),a=n*t.count;if(null==t.bufferView)t._data=Promise.resolve(new s(a));else{const o=oe.Get(`${e}/bufferView`,this._gltf.bufferViews,t.bufferView);t._data=this.loadBufferViewAsync(`/bufferViews/${o.index}`,o).then(i=>{if(5126!==t.componentType||t.normalized||o.byteStride&&o.byteStride!==r){const e=new s(a);return C(i,t.byteOffset||0,o.byteStride||r,n,t.componentType,e.length,t.normalized||!1,(t,s)=>{e[s]=t}),e}return le._GetTypedArray(e,t.componentType,i,t.byteOffset,a)})}if(t.sparse){const a=t.sparse;t._data=t._data.then(o=>{const i=o,l=oe.Get(`${e}/sparse/indices/bufferView`,this._gltf.bufferViews,a.indices.bufferView),h=oe.Get(`${e}/sparse/values/bufferView`,this._gltf.bufferViews,a.values.bufferView);return Promise.all([this.loadBufferViewAsync(`/bufferViews/${l.index}`,l),this.loadBufferViewAsync(`/bufferViews/${h.index}`,h)]).then(([o,l])=>{const h=le._GetTypedArray(`${e}/sparse/indices`,a.indices.componentType,o,a.indices.byteOffset,a.count),d=n*a.count;let c;if(5126!==t.componentType||t.normalized){const o=le._GetTypedArray(`${e}/sparse/values`,t.componentType,l,a.values.byteOffset,d);c=new s(d),C(o,0,r,n,t.componentType,c.length,t.normalized||!1,(e,t)=>{c[t]=e})}else c=le._GetTypedArray(`${e}/sparse/values`,t.componentType,l,a.values.byteOffset,d);let u=0;for(let e=0;e<h.length;e++){let t=h[e]*n;for(let e=0;e<n;e++)i[t++]=c[u++]}return i})})}return t._data}_loadFloatAccessorAsync(e,t){return this._loadAccessorAsync(e,t,Float32Array)}_loadIndicesAccessorAsync(e,t){if("SCALAR"!==t.type)throw new Error(`${e}/type: Invalid value ${t.type}`);if(5121!==t.componentType&&5123!==t.componentType&&5125!==t.componentType)throw new Error(`${e}/componentType: Invalid value ${t.componentType}`);if(t._data)return t._data;if(t.sparse){const s=le._GetTypedArrayConstructor(`${e}/componentType`,t.componentType);t._data=this._loadAccessorAsync(e,t,s)}else{const s=oe.Get(`${e}/bufferView`,this._gltf.bufferViews,t.bufferView);t._data=this.loadBufferViewAsync(`/bufferViews/${s.index}`,s).t