babylon.glTF1FileLoader.min.js 45 KB

12
  1. var BABYLON;!(function(e){var n;!(function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"})(n=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var r;!(function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"})(r=e.GLTFLoaderAnimationStartMode||(e.GLTFLoaderAnimationStartMode={}));!(function(e){e[e.LOADING=0]="LOADING",e[e.READY=1]="READY",e[e.COMPLETE=2]="COMPLETE"})(e.GLTFLoaderState||(e.GLTFLoaderState={}));var t=(function(){function t(){this.onParsedObservable=new e.Observable,this.coordinateSystemMode=n.AUTO,this.animationStartMode=r.FIRST,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this._normalizeAnimationGroupsToBeginAtZero=!0,this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable=new e.Observable,this.onTextureLoadedObservable=new e.Observable,this.onMaterialLoadedObservable=new e.Observable,this.onCameraLoadedObservable=new e.Observable,this.onCompleteObservable=new e.Observable,this.onDisposeObservable=new e.Observable,this.onExtensionLoadedObservable=new e.Observable,this._loader=null,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}},this._logIndentLevel=0,this._loggingEnabled=!1,this._log=this._logDisabled,this._capturePerformanceCounters=!1,this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled}return Object.defineProperty(t.prototype,"onParsed",{set:function(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),this._onParsedObserver=this.onParsedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onMeshLoaded",{set:function(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onTextureLoaded",{set:function(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onMaterialLoaded",{set:function(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onCameraLoaded",{set:function(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onComplete",{set:function(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"onExtensionLoaded",{set:function(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)},enumerable:!0,configurable:!0}),t.prototype.whenCompleteAsync=function(){var e=this;return new Promise(function(n){e.onCompleteObservable.addOnce((function(){n()}))})},Object.defineProperty(t.prototype,"loaderState",{get:function(){return this._loader?this._loader.state:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"loggingEnabled",{get:function(){return this._loggingEnabled},set:function(e){this._loggingEnabled!==e&&(this._loggingEnabled=e,this._loggingEnabled?this._log=this._logEnabled:this._log=this._logDisabled)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"capturePerformanceCounters",{get:function(){return this._capturePerformanceCounters},set:function(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))},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){this._loader&&(this._loader.dispose(),this._loader=null),this._clear(),this.onDisposeObservable.notifyObservers(void 0),this.onDisposeObservable.clear()},t.prototype._clear=function(){this.preprocessUrlAsync=function(e){return Promise.resolve(e)},this.onMeshLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCameraLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onExtensionLoadedObservable.clear()},t.prototype.importMeshAsync=function(e,n,r,t,o){var i=this;return Promise.resolve().then((function(){var a=i._parse(r);return i._loader=i._getLoader(a),i._loader.importMeshAsync(e,n,a,t,o)}))},t.prototype.loadAsync=function(e,n,r,t){var o=this;return Promise.resolve().then((function(){var i=o._parse(n);return o._loader=o._getLoader(i),o._loader.loadAsync(e,i,r,t)}))},t.prototype.loadAssetContainerAsync=function(n,r,t,o){var i=this;return Promise.resolve().then((function(){var a=i._parse(r);return i._loader=i._getLoader(a),i._loader.importMeshAsync(null,n,a,t,o).then((function(r){var t=new e.AssetContainer(n);return Array.prototype.push.apply(t.meshes,r.meshes),Array.prototype.push.apply(t.particleSystems,r.particleSystems),Array.prototype.push.apply(t.skeletons,r.skeletons),Array.prototype.push.apply(t.animationGroups,r.animationGroups),t.removeAllFromScene(),t}))}))},t.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},t.prototype.createPlugin=function(){return new t},t.prototype._parse=function(e){this._startPerformanceCounter("Parse");var n;return e instanceof ArrayBuffer?(this._log("Parsing binary"),n=this._parseBinary(e)):(this._log("Parsing JSON"),this._log("JSON length: "+e.length),n={json:JSON.parse(e),bin:null}),this.onParsedObservable.notifyObservers(n),this.onParsedObservable.clear(),this._endPerformanceCounter("Parse"),n},t.prototype._getLoader=function(e){var n=e.json.asset||{};this._log("Asset version: "+n.version),n.minVersion&&this._log("Asset minimum version: "+n.minVersion),n.generator&&this._log("Asset generator: "+n.generator);var r=t._parseVersion(n.version);if(!r)throw new Error("Invalid version: "+n.version);if(void 0!==n.minVersion){var o=t._parseVersion(n.minVersion);if(!o)throw new Error("Invalid minimum version: "+n.minVersion);if(t._compareVersion(o,{major:2,minor:0})>0)throw new Error("Incompatible minimum version: "+n.minVersion)}var i={1:t._CreateGLTFLoaderV1,2:t._CreateGLTFLoaderV2},a=i[r.major];if(!a)throw new Error("Unsupported version: "+n.version);return a(this)},t.prototype._parseBinary=function(e){var n={Magic:1179937895};this._log("Binary length: "+e.byteLength);var r=new o(e),t=r.readUint32();if(t!==n.Magic)throw new Error("Unexpected magic: "+t);var i=r.readUint32();switch(this.loggingEnabled&&this._log("Binary version: "+i),i){case 1:return this._parseV1(r);case 2:return this._parseV2(r)}throw new Error("Unsupported version: "+i)},t.prototype._parseV1=function(e){var n={JSON:0},r=e.readUint32();if(r!=e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o,i=e.readUint32(),a=e.readUint32();switch(a){case n.JSON:o=JSON.parse(t._decodeBufferToText(e.readUint8Array(i)));break;default:throw new Error("Unexpected content format: "+a)}var s=e.getLength()-e.getPosition();return{json:o,bin:e.readUint8Array(s)}},t.prototype._parseV2=function(e){var n={JSON:1313821514,BIN:5130562},r=e.readUint32();if(r!==e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==n.JSON)throw new Error("First chunk format is not JSON");for(var i=JSON.parse(t._decodeBufferToText(e.readUint8Array(o))),a=null;e.getPosition()<e.getLength();){var s=e.readUint32();switch(e.readUint32()){case n.JSON:throw new Error("Unexpected JSON chunk");case n.BIN:a=e.readUint8Array(s);break;default:e.skipBytes(s)}}return{json:i,bin:a}},t._parseVersion=function(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};var n=(e+"").match(/^(\d+)\.(\d+)/);return n?{major:parseInt(n[1]),minor:parseInt(n[2])}:null},t._compareVersion=function(e,n){return e.major>n.major?1:e.major<n.major?-1:e.minor>n.minor?1:e.minor<n.minor?-1:0},t._decodeBufferToText=function(e){for(var n="",r=e.byteLength,t=0;t<r;t++)n+=String.fromCharCode(e[t]);return n},t.prototype._logOpen=function(e){this._log(e),this._logIndentLevel++},t.prototype._logClose=function(){--this._logIndentLevel},t.prototype._logEnabled=function(n){var r=t._logSpaces.substr(0,2*this._logIndentLevel);e.Tools.Log(""+r+n)},t.prototype._logDisabled=function(e){},t.prototype._startPerformanceCounterEnabled=function(n){e.Tools.StartPerformanceCounter(n)},t.prototype._startPerformanceCounterDisabled=function(e){},t.prototype._endPerformanceCounterEnabled=function(n){e.Tools.EndPerformanceCounter(n)},t.prototype._endPerformanceCounterDisabled=function(e){},t.IncrementalLoading=!0,t.HomogeneousCoordinates=!1,t._logSpaces=" ",t})();e.GLTFFileLoader=t;var o=(function(){function e(e){this._arrayBuffer=e,this._dataView=new DataView(e),this._byteOffset=0}return e.prototype.getPosition=function(){return this._byteOffset},e.prototype.getLength=function(){return this._arrayBuffer.byteLength},e.prototype.readUint32=function(){var e=this._dataView.getUint32(this._byteOffset,!0);return this._byteOffset+=4,e},e.prototype.readUint8Array=function(e){var n=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,n},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new t)})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){!(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.EComponentType||(e.EComponentType={}));!(function(e){e[e.FRAGMENT=35632]="FRAGMENT",e[e.VERTEX=35633]="VERTEX"})(e.EShaderType||(e.EShaderType={}));!(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"})(e.EParameterType||(e.EParameterType={}));!(function(e){e[e.CLAMP_TO_EDGE=33071]="CLAMP_TO_EDGE",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",e[e.REPEAT=10497]="REPEAT"})(e.ETextureWrapMode||(e.ETextureWrapMode={}));!(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"})(e.ETextureFilterType||(e.ETextureFilterType={}));!(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"})(e.ETextureFormat||(e.ETextureFormat={}));!(function(e){e[e.FRONT=1028]="FRONT",e[e.BACK=1029]="BACK",e[e.FRONT_AND_BACK=1032]="FRONT_AND_BACK"})(e.ECullingType||(e.ECullingType={}));!(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"})(e.EBlendingFunction||(e.EBlendingFunction={}))})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(n){var r;!(function(e){e[e.IDENTIFIER=1]="IDENTIFIER",e[e.UNKNOWN=2]="UNKNOWN",e[e.END_OF_INPUT=3]="END_OF_INPUT"})(r||(r={}));var t=(function(){function e(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}return e.prototype.getNextToken=function(){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},e.prototype.peek=function(){return this._toParse[this._pos]},e.prototype.read=function(){return this._toParse[this._pos++]},e.prototype.forward=function(){this._pos++},e.prototype.isEnd=function(){return this._pos>=this._maxPos},e})(),o=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],i=["world","view","projection","worldView","worldViewProjection","mBones"],a=["translation","rotation","scale"],s=["position","rotationQuaternion","scaling"],u=function(e,n){for(var r in e){var t=e[r];n.buffers[r]=t,n.buffersCount++}},l=function(e,n){for(var r in e){var t=e[r];n.shaders[r]=t,n.shaderscount++}},c=function(e,n,r){for(var t in e){var o=e[t];r[n][t]=o}},f=function(e){if(e)for(var n=0;n<e.length/2;n++)e[2*n+1]=1-e[2*n+1]},d=function(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_")){var n=Number(e.semantic.split("_")[1]);return"uv"+(0===n?"":n+1)}return null},m=function(r){for(var t in r.animations){var o=r.animations[t];if(o.channels&&o.samplers)for(var i=null,u=0;u<o.channels.length;u++){var l=o.channels[u],c=o.samplers[l.sampler];if(c){var f=null,d=null;o.parameters?(f=o.parameters[c.input],d=o.parameters[c.output]):(f=c.input,d=c.output);var m=n.GLTFUtils.GetBufferFromAccessor(r,r.accessors[f]),p=n.GLTFUtils.GetBufferFromAccessor(r,r.accessors[d]),h=l.target.id,E=r.scene.getNodeByID(h);if(null===E&&(E=r.scene.getNodeByName(h)),null!==E){var A=E instanceof e.Bone,T=l.target.path,v=a.indexOf(T);-1!==v&&(T=s[v]);var y=e.Animation.ANIMATIONTYPE_MATRIX;A||("rotationQuaternion"===T?(y=e.Animation.ANIMATIONTYPE_QUATERNION,E.rotationQuaternion=new e.Quaternion):y=e.Animation.ANIMATIONTYPE_VECTOR3);var _=null,L=[],O=0,g=!1;A&&i&&i.getKeys().length===m.length&&(_=i,g=!0),g||(_=new e.Animation(t,A?"_matrix":T,1,y,e.Animation.ANIMATIONLOOPMODE_CYCLE));for(var b=0;b<m.length;b++){var N=null;if("rotationQuaternion"===T?(N=e.Quaternion.FromArray([p[O],p[O+1],p[O+2],p[O+3]]),O+=4):(N=e.Vector3.FromArray([p[O],p[O+1],p[O+2]]),O+=3),A){var S=E,M=e.Vector3.Zero(),x=new e.Quaternion,F=e.Vector3.Zero(),C=S.getBaseMatrix();g&&i&&(C=i.getKeys()[b].value),C.decompose(F,x,M),"position"===T?M=N:"rotationQuaternion"===T?x=N:F=N,N=e.Matrix.Compose(F,x,M)}g?i&&(i.getKeys()[b].value=N):L.push({frame:m[b],value:N})}!g&&_&&(_.setKeys(L),E.animations.push(_)),i=_,r.scene.stopAnimation(E),r.scene.beginAnimation(E,0,m[m.length-1],!0,1)}else e.Tools.Warn("Creating animation named "+t+". But cannot find node named "+h+" to attach to")}}}},p=function(n){var r=null;if(n.translation||n.rotation||n.scale){var t=e.Vector3.FromArray(n.scale||[1,1,1]),o=e.Quaternion.FromArray(n.rotation||[0,0,0,1]),i=e.Vector3.FromArray(n.translation||[0,0,0]);r=e.Matrix.Compose(t,o,i)}else r=e.Matrix.FromArray(n.matrix);return r},h=function(n,r,t,o){for(var i=0;i<o.bones.length;i++)if(o.bones[i].name===t)return o.bones[i];var a=n.nodes;for(var s in a){var u=a[s];if(u.jointName)for(var l=u.children,i=0;i<l.length;i++){var c=n.nodes[l[i]];if(c.jointName&&c.jointName===t){var f=p(u),d=new e.Bone(u.name||"",o,h(n,r,u.jointName,o),f);return d.id=s,d}}}return null},E=function(e,n){for(var r=0;r<e.length;r++)for(var t=e[r],o=0;o<t.node.children.length;o++){var i=t.node.children[o];if(i===n)return t.bone}return null},A=function(e,n){var r=e.nodes,t=r[n];if(t)return{node:t,id:n};for(var o in r)if(t=r[o],t.jointName===n)return{node:t,id:o};return null},T=function(e,n){for(var r=0;r<e.jointNames.length;r++)if(e.jointNames[r]===n)return!0;return!1},v=function(n,r,t,o){for(var i in n.nodes){var a=n.nodes[i],s=i;if(a.jointName&&!T(t,a.jointName)){var u=p(a),l=new e.Bone(a.name||"",r,null,u);l.id=s,o.push({bone:l,node:a,id:s})}}for(var c=0;c<o.length;c++)for(var f=o[c],d=f.node.children,m=0;m<d.length;m++){for(var h=null,E=0;E<o.length;E++)if(o[E].id===d[m]){h=o[E];break}h&&(h.bone._parent=f.bone,f.bone.children.push(h.bone))}},y=function(n,r,t,o,i){if(o||(o=new e.Skeleton(r.name||"","",n.scene)),!r.babylonSkeleton)return o;var a=[],s=[];v(n,o,r,a),o.bones=[];for(var u=0;u<r.jointNames.length;u++){var l=A(n,r.jointNames[u]);if(l){var c=l.node;if(c){var i=l.id,f=n.scene.getBoneByID(i);if(f)o.bones.push(f);else{for(var d=!1,m=null,T=0;T<u;T++){var y=A(n,r.jointNames[T]);if(y){var _=y.node;if(_){var L=_.children;if(L){d=!1;for(var O=0;O<L.length;O++)if(L[O]===i){m=h(n,r,r.jointNames[T],o),d=!0;break}if(d)break}}else e.Tools.Warn("Joint named "+r.jointNames[T]+" does not exist when looking for parent")}}var g=p(c);!m&&a.length>0&&(m=E(a,i))&&-1===s.indexOf(m)&&s.push(m);new e.Bone(c.jointName||"",o,m,g).id=i}}else e.Tools.Warn("Joint named "+r.jointNames[u]+" does not exist")}}var b=o.bones;o.bones=[];for(var u=0;u<r.jointNames.length;u++){var l=A(n,r.jointNames[u]);if(l)for(var T=0;T<b.length;T++)if(b[T].id===l.id){o.bones.push(b[T]);break}}o.prepare();for(var u=0;u<s.length;u++)o.bones.push(s[u]);return o},_=function(r,t,o,i,a){if(a||(a=new e.Mesh(t.name||"",r.scene),a.id=i),!t.babylonNode)return a;for(var s=[],u=null,l=new Array,c=new Array,d=new Array,m=new Array,p=0;p<o.length;p++){var h=o[p],E=r.meshes[h];if(E)for(var A=0;A<E.primitives.length;A++){var T=new e.VertexData,v=E.primitives[A];v.mode;var y=v.attributes,_=null,L=null;for(var O in y)if(_=r.accessors[y[O]],L=n.GLTFUtils.GetBufferFromAccessor(r,_),"NORMAL"===O)T.normals=new Float32Array(L.length),T.normals.set(L);else if("POSITION"===O){if(e.GLTFFileLoader.HomogeneousCoordinates){T.positions=new Float32Array(L.length-L.length/4);for(var g=0;g<L.length;g+=4)T.positions[g]=L[g],T.positions[g+1]=L[g+1],T.positions[g+2]=L[g+2]}else T.positions=new Float32Array(L.length),T.positions.set(L);c.push(T.positions.length)}else if(-1!==O.indexOf("TEXCOORD_")){var b=Number(O.split("_")[1]),N=e.VertexBuffer.UVKind+(0===b?"":b+1),S=new Float32Array(L.length);S.set(L),f(S),T.set(S,N)}else"JOINT"===O?(T.matricesIndices=new Float32Array(L.length),T.matricesIndices.set(L)):"WEIGHT"===O?(T.matricesWeights=new Float32Array(L.length),T.matricesWeights.set(L)):"COLOR"===O&&(T.colors=new Float32Array(L.length),T.colors.set(L));if(_=r.accessors[v.indices])L=n.GLTFUtils.GetBufferFromAccessor(r,_),T.indices=new Int32Array(L.length),T.indices.set(L),m.push(T.indices.length);else{for(var M=[],g=0;g<T.positions.length/3;g++)M.push(g);T.indices=new Int32Array(M),m.push(T.indices.length)}u?u.merge(T):u=T;var x=r.scene.getMaterialByID(v.material);s.push(null===x?n.GLTFUtils.GetDefaultMaterial(r.scene):x),l.push(0===l.length?0:l[l.length-1]+c[c.length-2]),d.push(0===d.length?0:d[d.length-1]+m[m.length-2])}}var F;s.length>1?(F=new e.MultiMaterial("multimat"+i,r.scene),F.subMaterials=s):F=new e.StandardMaterial("multimat"+i,r.scene),1===s.length&&(F=s[0]),a.material||(a.material=F),new e.Geometry(i,r.scene,u,!1,a),a.computeWorldMatrix(!0),a.subMeshes=[];for(var C=0,p=0;p<o.length;p++){var h=o[p],E=r.meshes[h];if(E)for(var A=0;A<E.primitives.length;A++)E.primitives[A].mode,e.SubMesh.AddToMesh(C,l[C],c[C],d[C],m[C],a,a,!0),C++}return a},L=function(e,n,r,t){e.position&&(e.position=n),(e.rotationQuaternion||e.rotation)&&(e.rotationQuaternion=r),e.scaling&&(e.scaling=t)},O=function(n,r,t){if(r.matrix){var o=new e.Vector3(0,0,0),i=new e.Quaternion,a=new e.Vector3(0,0,0);e.Matrix.FromArray(r.matrix).decompose(a,i,o),L(n,o,i,a)}else r.translation&&r.rotation&&r.scale&&L(n,e.Vector3.FromArray(r.translation),e.Quaternion.FromArray(r.rotation),e.Vector3.FromArray(r.scale));n.computeWorldMatrix(!0)},g=function(n,r,t,o){var i=null;if(n.importOnlyMeshes&&(r.skin||r.meshes)&&n.importMeshesNames&&n.importMeshesNames.length>0&&-1===n.importMeshesNames.indexOf(r.name||""))return null;if(r.skin){if(r.meshes){var a=n.skins[r.skin],s=_(n,r,r.meshes,t,r.babylonNode);s.skeleton=n.scene.getLastSkeletonByID(r.skin),null===s.skeleton&&(s.skeleton=y(n,a,0,a.babylonSkeleton,r.skin),a.babylonSkeleton||(a.babylonSkeleton=s.skeleton)),i=s}}else if(r.meshes){var s=_(n,r,r.mesh?[r.mesh]:r.meshes,t,r.babylonNode);i=s}else if(!r.light||r.babylonNode||n.importOnlyMeshes){if(r.camera&&!r.babylonNode&&!n.importOnlyMeshes){var u=n.cameras[r.camera];if(u)if("orthographic"===u.type){var l=new e.FreeCamera(r.camera,e.Vector3.Zero(),n.scene,!1);l.name=r.name||"",l.mode=e.Camera.ORTHOGRAPHIC_CAMERA,l.attachControl(n.scene.getEngine().getRenderingCanvas()),i=l}else if("perspective"===u.type){var c=u[u.type],f=new e.FreeCamera(r.camera,e.Vector3.Zero(),n.scene,!1);f.name=r.name||"",f.attachControl(n.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=n.scene.getEngine().getRenderWidth()/n.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(f.maxZ=c.zfar,f.minZ=c.znear),i=f}}}else{var d=n.lights[r.light];if(d)if("ambient"===d.type){var m=d[d.type],p=new e.HemisphericLight(r.light,e.Vector3.Zero(),n.scene);p.name=r.name||"",m.color&&(p.diffuse=e.Color3.FromArray(m.color)),i=p}else if("directional"===d.type){var h=d[d.type],E=new e.DirectionalLight(r.light,e.Vector3.Zero(),n.scene);E.name=r.name||"",h.color&&(E.diffuse=e.Color3.FromArray(h.color)),i=E}else if("point"===d.type){var A=d[d.type],T=new e.PointLight(r.light,e.Vector3.Zero(),n.scene);T.name=r.name||"",A.color&&(T.diffuse=e.Color3.FromArray(A.color)),i=T}else if("spot"===d.type){var v=d[d.type],g=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,n.scene);g.name=r.name||"",v.color&&(g.diffuse=e.Color3.FromArray(v.color)),v.fallOfAngle&&(g.angle=v.fallOfAngle),v.fallOffExponent&&(g.exponent=v.fallOffExponent),i=g}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===i){var b=new e.Mesh(r.name||"",n.scene);r.babylonNode=b,i=b}}if(null!==i){if(r.matrix&&i instanceof e.Mesh)O(i,r);else{var N=r.translation||[0,0,0],S=r.rotation||[0,0,0,1],M=r.scale||[1,1,1];L(i,e.Vector3.FromArray(N),e.Quaternion.FromArray(S),e.Vector3.FromArray(M))}i.updateCache(!0),r.babylonNode=i}return i},b=function(e,n,r,t){void 0===t&&(t=!1);var o=e.nodes[n],i=null;if(t=!(e.importOnlyMeshes&&!t&&e.importMeshesNames)||(-1!==e.importMeshesNames.indexOf(o.name||"")||0===e.importMeshesNames.length),!o.jointName&&t&&null!==(i=g(e,o,n))&&(i.id=n,i.parent=r),o.children)for(var a=0;a<o.children.length;a++)b(e,o.children[a],i,t)},N=function(e){var n=e.currentScene;if(n)for(var r=0;r<n.nodes.length;r++)b(e,n.nodes[r],null);else for(var t in e.scenes){n=e.scenes[t];for(var r=0;r<n.nodes.length;r++)b(e,n.nodes[r],null)}m(e);for(var r=0;r<e.scene.skeletons.length;r++){var o=e.scene.skeletons[r];e.scene.beginAnimation(o,0,Number.MAX_VALUE,!0,1)}},S=function(e,r,t,o,i,a,s){var u=a.values||i.parameters;for(var l in t){var c=t[l],f=c.type;if(f===n.EParameterType.FLOAT_MAT2||f===n.EParameterType.FLOAT_MAT3||f===n.EParameterType.FLOAT_MAT4)if(!c.semantic||c.source||c.node){if(c.semantic&&(c.source||c.node)){var d=r.scene.getNodeByName(c.source||c.node||"");if(null===d&&(d=r.scene.getNodeByID(c.source||c.node||"")),null===d)continue;n.GLTFUtils.SetMatrix(r.scene,d,c,l,o.getEffect())}}else n.GLTFUtils.SetMatrix(r.scene,e,c,l,o.getEffect());else{var m=u[i.uniforms[l]];if(!m)continue;if(f===n.EParameterType.SAMPLER_2D){var p=r.textures[a.values?m:c.value].babylonTexture;if(null===p||void 0===p)continue;o.getEffect().setTexture(l,p)}else n.GLTFUtils.SetUniform(o.getEffect(),l,m,f)}}s(o)},M=function(e,r,t,o,i){var a=o.values||t.parameters,s=t.uniforms;for(var u in i){var l=i[u],c=l.type,f=a[s[u]];if(void 0===f&&(f=l.value),f){var d=function(e){return function(n){l.value&&e&&(r.setTexture(e,n),delete i[e])}};c===n.EParameterType.SAMPLER_2D?n.GLTFLoaderExtension.LoadTextureAsync(e,o.values?f:l.value,d(u),(function(){return d(null)})):l.value&&n.GLTFUtils.SetUniform(r,u,o.values?f:l.value,c)&&delete i[u]}}},x=function(e,n,r){return function(t,o){n.dispose(!0),r("Cannot compile program named "+e.name+". Error: "+o+". Default material will be applied")}},F=function(e,n,r,t,o,i){return function(a){M(e,n,r,t,o),n.onBind=function(a){S(a,e,o,n,r,t,i)}}},C=function(e,n,r){for(var t in n.uniforms){var a=n.uniforms[t],s=n.parameters[a];if(e.currentIdentifier===t&&s.semantic&&!s.source&&!s.node){var u=o.indexOf(s.semantic);if(-1!==u)return delete r[t],i[u]}}return e.currentIdentifier},R=function(e){for(var r in e.materials)n.GLTFLoaderExtension.LoadMaterialAsync(e,r,(function(e){}),(function(){}))},P=(function(){function a(){}return a.CreateRuntime=function(e,n,r){var t={extensions:{},accessors:{},buffers:{},bufferViews:{},meshes:{},lights:{},cameras:{},nodes:{},images:{},textures:{},shaders:{},programs:{},samplers:{},techniques:{},materials:{},animations:{},skins:{},extensionsUsed:[],scenes:{},buffersCount:0,shaderscount:0,scene:n,rootUrl:r,loadedBufferCount:0,loadedBufferViews:{},loadedShaderCount:0,importOnlyMeshes:!1,dummyNodes:[]};return e.extensions&&c(e.extensions,"extensions",t),e.extensionsUsed&&c(e.extensionsUsed,"extensionsUsed",t),e.buffers&&u(e.buffers,t),e.bufferViews&&c(e.bufferViews,"bufferViews",t),e.accessors&&c(e.accessors,"accessors",t),e.meshes&&c(e.meshes,"meshes",t),e.lights&&c(e.lights,"lights",t),e.cameras&&c(e.cameras,"cameras",t),e.nodes&&c(e.nodes,"nodes",t),e.images&&c(e.images,"images",t),e.textures&&c(e.textures,"textures",t),e.shaders&&l(e.shaders,t),e.programs&&c(e.programs,"programs",t),e.samplers&&c(e.samplers,"samplers",t),e.techniques&&c(e.techniques,"techniques",t),e.materials&&c(e.materials,"materials",t),e.animations&&c(e.animations,"animations",t),e.skins&&c(e.skins,"skins",t),e.scenes&&(t.scenes=e.scenes),e.scene&&e.scenes&&(t.currentScene=e.scenes[e.scene]),t},a.LoadBufferAsync=function(n,r,t,o,i){var a=n.buffers[r];e.Tools.IsBase64(a.uri)?setTimeout((function(){return t(new Uint8Array(e.Tools.DecodeBase64(a.uri)))})):e.Tools.LoadFile(n.rootUrl+a.uri,(function(e){return t(new Uint8Array(e))}),i,void 0,!0,(function(e){e&&o(e.status+" "+e.statusText)}))},a.LoadTextureBufferAsync=function(n,r,t,o){var i=n.textures[r];if(!i||!i.source)return void o("");if(i.babylonTexture)return void t(null);var a=n.images[i.source];e.Tools.IsBase64(a.uri)?setTimeout((function(){return t(new Uint8Array(e.Tools.DecodeBase64(a.uri)))})):e.Tools.LoadFile(n.rootUrl+a.uri,(function(e){return t(new Uint8Array(e))}),void 0,void 0,!0,(function(e){e&&o(e.status+" "+e.statusText)}))},a.CreateTextureAsync=function(r,t,o,i,a){var s=r.textures[t];if(s.babylonTexture)return void i(s.babylonTexture);var u=r.samplers[s.sampler],l=u.minFilter===n.ETextureFilterType.NEAREST_MIPMAP_NEAREST||u.minFilter===n.ETextureFilterType.NEAREST_MIPMAP_LINEAR||u.minFilter===n.ETextureFilterType.LINEAR_MIPMAP_NEAREST||u.minFilter===n.ETextureFilterType.LINEAR_MIPMAP_LINEAR,c=e.Texture.BILINEAR_SAMPLINGMODE,f=new Blob([o]),d=URL.createObjectURL(f),m=function(){return URL.revokeObjectURL(d)},p=new e.Texture(d,r.scene,!l,!0,c,m,m);void 0!==u.wrapS&&(p.wrapU=n.GLTFUtils.GetWrapMode(u.wrapS)),void 0!==u.wrapT&&(p.wrapV=n.GLTFUtils.GetWrapMode(u.wrapT)),p.name=t,s.babylonTexture=p,i(p)},a.LoadShaderStringAsync=function(n,r,t,o){var i=n.shaders[r];if(e.Tools.IsBase64(i.uri)){var a=atob(i.uri.split(",")[1]);t&&t(a)}else e.Tools.LoadFile(n.rootUrl+i.uri,t,void 0,void 0,!1,(function(e){e&&o&&o(e.status+" "+e.statusText)}))},a.LoadMaterialAsync=function(a,s,u,l){var c=a.materials[s];if(!c.technique)return void(l&&l("No technique found."));var f=a.techniques[c.technique];if(!f){var m=new e.StandardMaterial(s,a.scene);return m.diffuseColor=new e.Color3(.5,.5,.5),m.sideOrientation=e.Material.CounterClockWiseSideOrientation,void u(m)}var p=a.programs[f.program],h=f.states,E=e.Effect.ShadersStore[p.vertexShader+"VertexShader"],A=e.Effect.ShadersStore[p.fragmentShader+"PixelShader"],T="",v="",y=new t(E),_=new t(A),L={},O=[],g=[],b=[];for(var N in f.uniforms){var S=f.uniforms[N],M=f.parameters[S];if(L[N]=M,!M.semantic||M.node||M.source)M.type===n.EParameterType.SAMPLER_2D?b.push(N):O.push(N);else{var R=o.indexOf(M.semantic);-1!==R?(O.push(i[R]),delete L[N]):O.push(N)}}for(var P in f.attributes){var I=f.attributes[P],B=f.parameters[I];B.semantic&&g.push(d(B))}for(;!y.isEnd()&&y.getNextToken();){var w=y.currentToken;if(w===r.IDENTIFIER){var G=!1;for(var P in f.attributes){var I=f.attributes[P],B=f.parameters[I];if(y.currentIdentifier===P&&B.semantic){T+=d(B),G=!0;break}}G||(T+=C(y,f,L))}else T+=y.currentString}for(;!_.isEnd()&&_.getNextToken();){var w=_.currentToken;w===r.IDENTIFIER?v+=C(_,f,L):v+=_.currentString}var V={vertex:p.vertexShader+s,fragment:p.fragmentShader+s},D={attributes:g,uniforms:O,samplers:b,needAlphaBlending:h&&h.enable&&-1!==h.enable.indexOf(3042)};e.Effect.ShadersStore[p.vertexShader+s+"VertexShader"]=T,e.Effect.ShadersStore[p.fragmentShader+s+"PixelShader"]=v;var U=new e.ShaderMaterial(s,a.scene,V,D);if(U.onError=x(p,U,l),U.onCompiled=F(a,U,f,c,L,u),U.sideOrientation=e.Material.CounterClockWiseSideOrientation,h&&h.functions){var k=h.functions;k.cullFace&&k.cullFace[0]!==n.ECullingType.BACK&&(U.backFaceCulling=!1);var j=k.blendFuncSeparate;j&&(j[0]===n.EBlendingFunction.SRC_ALPHA&&j[1]===n.EBlendingFunction.ONE_MINUS_SRC_ALPHA&&j[2]===n.EBlendingFunction.ONE&&j[3]===n.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_COMBINE:j[0]===n.EBlendingFunction.ONE&&j[1]===n.EBlendingFunction.ONE&&j[2]===n.EBlendingFunction.ZERO&&j[3]===n.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_ONEONE:j[0]===n.EBlendingFunction.SRC_ALPHA&&j[1]===n.EBlendingFunction.ONE&&j[2]===n.EBlendingFunction.ZERO&&j[3]===n.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_ADD:j[0]===n.EBlendingFunction.ZERO&&j[1]===n.EBlendingFunction.ONE_MINUS_SRC_COLOR&&j[2]===n.EBlendingFunction.ONE&&j[3]===n.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_SUBTRACT:j[0]===n.EBlendingFunction.DST_COLOR&&j[1]===n.EBlendingFunction.ZERO&&j[2]===n.EBlendingFunction.ONE&&j[3]===n.EBlendingFunction.ONE?U.alphaMode=e.Engine.ALPHA_MULTIPLY:j[0]===n.EBlendingFunction.SRC_ALPHA&&j[1]===n.EBlendingFunction.ONE_MINUS_SRC_COLOR&&j[2]===n.EBlendingFunction.ONE&&j[3]===n.EBlendingFunction.ONE&&(U.alphaMode=e.Engine.ALPHA_MAXIMIZED))}},a})();n.GLTFLoaderBase=P;var I=(function(){function r(){this.state=null}
  2. return r.RegisterExtension=function(n){if(r.Extensions[n.name])return void e.Tools.Error('Tool with the same name "'+n.name+'" already exists');r.Extensions[n.name]=n},r.prototype.dispose=function(){},r.prototype._importMeshAsync=function(r,t,o,i,a,s,u){var l=this;return t.useRightHandedSystem=!0,n.GLTFLoaderExtension.LoadRuntimeAsync(t,o,i,(function(n){n.importOnlyMeshes=!0,""===r?n.importMeshesNames=[]:"string"==typeof r?n.importMeshesNames=[r]:!r||r instanceof Array?(n.importMeshesNames=[],e.Tools.Warn("Argument meshesNames must be of type string or string[]")):n.importMeshesNames=[r],l._createNodes(n);var t=new Array,o=new Array;for(var i in n.nodes){var u=n.nodes[i];u.babylonNode instanceof e.AbstractMesh&&t.push(u.babylonNode)}for(var c in n.skins){var f=n.skins[c];f.babylonSkeleton instanceof e.Skeleton&&o.push(f.babylonSkeleton)}l._loadBuffersAsync(n,(function(){l._loadShadersAsync(n,(function(){R(n),N(n),!e.GLTFFileLoader.IncrementalLoading&&a&&a(t,o)}))}),s),e.GLTFFileLoader.IncrementalLoading&&a&&a(t,o)}),u),!0},r.prototype.importMeshAsync=function(e,n,r,t,o){var i=this;return new Promise(function(a,s){i._importMeshAsync(e,n,r,t,(function(e,n){a({meshes:e,particleSystems:[],skeletons:n,animationGroups:[]})}),o,(function(e){s(new Error(e))}))})},r.prototype._loadAsync=function(r,t,o,i,a,s){var u=this;r.useRightHandedSystem=!0,n.GLTFLoaderExtension.LoadRuntimeAsync(r,t,o,(function(r){n.GLTFLoaderExtension.LoadRuntimeExtensionsAsync(r,(function(){u._createNodes(r),u._loadBuffersAsync(r,(function(){u._loadShadersAsync(r,(function(){R(r),N(r),e.GLTFFileLoader.IncrementalLoading||i()}))})),e.GLTFFileLoader.IncrementalLoading&&i()}),s)}),s)},r.prototype.loadAsync=function(e,n,r,t){var o=this;return new Promise(function(i,a){o._loadAsync(e,n,r,(function(){i()}),t,(function(e){a(new Error(e))}))})},r.prototype._loadShadersAsync=function(r,t){var o=!1,i=function(o,i){n.GLTFLoaderExtension.LoadShaderStringAsync(r,o,(function(a){a instanceof ArrayBuffer||(r.loadedShaderCount++,a&&(e.Effect.ShadersStore[o+(i.type===n.EShaderType.VERTEX?"VertexShader":"PixelShader")]=a),r.loadedShaderCount===r.shaderscount&&t())}),(function(){e.Tools.Error("Error when loading shader program named "+o+" located at "+i.uri)}))};for(var a in r.shaders){o=!0;var s=r.shaders[a];s?i.bind(this,a,s)():e.Tools.Error("No shader named: "+a)}o||t()},r.prototype._loadBuffersAsync=function(r,t,o){var i=!1,a=function(o,i){n.GLTFLoaderExtension.LoadBufferAsync(r,o,(function(n){r.loadedBufferCount++,n&&(n.byteLength!=r.buffers[o].byteLength&&e.Tools.Error("Buffer named "+o+" is length "+n.byteLength+". Expected: "+i.byteLength),r.loadedBufferViews[o]=n),r.loadedBufferCount===r.buffersCount&&t()}),(function(){e.Tools.Error("Error when loading buffer named "+o+" located at "+i.uri)}))};for(var s in r.buffers){i=!0;var u=r.buffers[s];u?a.bind(this,s,u)():e.Tools.Error("No buffer named: "+s)}i||t()},r.prototype._createNodes=function(e){var n=e.currentScene;if(n)for(var r=0;r<n.nodes.length;r++)b(e,n.nodes[r],null);else for(var t in e.scenes){n=e.scenes[t];for(var r=0;r<n.nodes.length;r++)b(e,n.nodes[r],null)}},r.Extensions={},r})();n.GLTFLoader=I,e.GLTFFileLoader._CreateGLTFLoaderV1=function(){return new I}})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(n){var r=(function(){function r(){}return r.SetMatrix=function(r,t,o,i,a){var s=null;if("MODEL"===o.semantic?s=t.getWorldMatrix():"PROJECTION"===o.semantic?s=r.getProjectionMatrix():"VIEW"===o.semantic?s=r.getViewMatrix():"MODELVIEWINVERSETRANSPOSE"===o.semantic?s=e.Matrix.Transpose(t.getWorldMatrix().multiply(r.getViewMatrix()).invert()):"MODELVIEW"===o.semantic?s=t.getWorldMatrix().multiply(r.getViewMatrix()):"MODELVIEWPROJECTION"===o.semantic?s=t.getWorldMatrix().multiply(r.getTransformMatrix()):"MODELINVERSE"===o.semantic?s=t.getWorldMatrix().invert():"VIEWINVERSE"===o.semantic?s=r.getViewMatrix().invert():"PROJECTIONINVERSE"===o.semantic?s=r.getProjectionMatrix().invert():"MODELVIEWINVERSE"===o.semantic?s=t.getWorldMatrix().multiply(r.getViewMatrix()).invert():"MODELVIEWPROJECTIONINVERSE"===o.semantic?s=t.getWorldMatrix().multiply(r.getTransformMatrix()).invert():"MODELINVERSETRANSPOSE"===o.semantic&&(s=e.Matrix.Transpose(t.getWorldMatrix().invert())),s)switch(o.type){case n.EParameterType.FLOAT_MAT2:a.setMatrix2x2(i,e.Matrix.GetAsMatrix2x2(s));break;case n.EParameterType.FLOAT_MAT3:a.setMatrix3x3(i,e.Matrix.GetAsMatrix3x3(s));break;case n.EParameterType.FLOAT_MAT4:a.setMatrix(i,s)}},r.SetUniform=function(r,t,o,i){switch(i){case n.EParameterType.FLOAT:return r.setFloat(t,o),!0;case n.EParameterType.FLOAT_VEC2:return r.setVector2(t,e.Vector2.FromArray(o)),!0;case n.EParameterType.FLOAT_VEC3:return r.setVector3(t,e.Vector3.FromArray(o)),!0;case n.EParameterType.FLOAT_VEC4:return r.setVector4(t,e.Vector4.FromArray(o)),!0;default:return!1}},r.GetWrapMode=function(r){switch(r){case n.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case n.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case n.ETextureWrapMode.REPEAT:default:return e.Texture.WRAP_ADDRESSMODE}},r.GetByteStrideFromType=function(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}},r.GetTextureFilterMode=function(r){switch(r){case n.ETextureFilterType.LINEAR:case n.ETextureFilterType.LINEAR_MIPMAP_NEAREST:case n.ETextureFilterType.LINEAR_MIPMAP_LINEAR:return e.Texture.TRILINEAR_SAMPLINGMODE;case n.ETextureFilterType.NEAREST:case n.ETextureFilterType.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_SAMPLINGMODE;default:return e.Texture.BILINEAR_SAMPLINGMODE}},r.GetBufferFromBufferView=function(e,r,t,o,i){var t=r.byteOffset+t,a=e.loadedBufferViews[r.buffer];if(t+o>a.byteLength)throw new Error("Buffer access is out of range");var s=a.buffer;switch(t+=a.byteOffset,i){case n.EComponentType.BYTE:return new Int8Array(s,t,o);case n.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,t,o);case n.EComponentType.SHORT:return new Int16Array(s,t,o);case n.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,t,o);default:return new Float32Array(s,t,o)}},r.GetBufferFromAccessor=function(e,n){var t=e.bufferViews[n.bufferView],o=n.count*r.GetByteStrideFromType(n);return r.GetBufferFromBufferView(e,t,n.byteOffset,o,n.componentType)},r.DecodeBufferToText=function(e){for(var n="",r=e.byteLength,t=0;t<r;++t)n+=String.fromCharCode(e[t]);return n},r.GetDefaultMaterial=function(n){if(!r._DefaultMaterial){e.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"),e.Effect.ShadersStore.GLTFDefaultMaterialPixelShader=["precision highp float;","","uniform vec4 u_emission;","","void main(void)","{"," gl_FragColor = u_emission;","}"].join("\n");var t={vertex:"GLTFDefaultMaterial",fragment:"GLTFDefaultMaterial"},o={attributes:["position"],uniforms:["worldView","projection","u_emission"],samplers:new Array,needAlphaBlending:!1};r._DefaultMaterial=new e.ShaderMaterial("GLTFDefaultMaterial",n,t,o),r._DefaultMaterial.setColor4("u_emission",new e.Color4(.5,.5,.5,1))}return r._DefaultMaterial},r._DefaultMaterial=null,r})();n.GLTFUtils=r})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var n=(function(){function n(e){this._name=e}return Object.defineProperty(n.prototype,"name",{get:function(){return this._name},enumerable:!0,configurable:!0}),n.prototype.loadRuntimeAsync=function(e,n,r,t,o){return!1},n.prototype.loadRuntimeExtensionsAsync=function(e,n,r){return!1},n.prototype.loadBufferAsync=function(e,n,r,t,o){return!1},n.prototype.loadTextureBufferAsync=function(e,n,r,t){return!1},n.prototype.createTextureAsync=function(e,n,r,t,o){return!1},n.prototype.loadShaderStringAsync=function(e,n,r,t){return!1},n.prototype.loadMaterialAsync=function(e,n,r,t){return!1},n.LoadRuntimeAsync=function(r,t,o,i,a){n.ApplyExtensions((function(e){return e.loadRuntimeAsync(r,t,o,i,a)}),(function(){setTimeout((function(){i&&i(e.GLTFLoaderBase.CreateRuntime(t.json,r,o))}))}))},n.LoadRuntimeExtensionsAsync=function(e,r,t){n.ApplyExtensions((function(n){return n.loadRuntimeExtensionsAsync(e,r,t)}),(function(){setTimeout((function(){r()}))}))},n.LoadBufferAsync=function(r,t,o,i,a){n.ApplyExtensions((function(e){return e.loadBufferAsync(r,t,o,i,a)}),(function(){e.GLTFLoaderBase.LoadBufferAsync(r,t,o,i,a)}))},n.LoadTextureAsync=function(e,r,t,o){n.LoadTextureBufferAsync(e,r,(function(i){i&&n.CreateTextureAsync(e,r,i,t,o)}),o)},n.LoadShaderStringAsync=function(r,t,o,i){n.ApplyExtensions((function(e){return e.loadShaderStringAsync(r,t,o,i)}),(function(){e.GLTFLoaderBase.LoadShaderStringAsync(r,t,o,i)}))},n.LoadMaterialAsync=function(r,t,o,i){n.ApplyExtensions((function(e){return e.loadMaterialAsync(r,t,o,i)}),(function(){e.GLTFLoaderBase.LoadMaterialAsync(r,t,o,i)}))},n.LoadTextureBufferAsync=function(r,t,o,i){n.ApplyExtensions((function(e){return e.loadTextureBufferAsync(r,t,o,i)}),(function(){e.GLTFLoaderBase.LoadTextureBufferAsync(r,t,o,i)}))},n.CreateTextureAsync=function(r,t,o,i,a){n.ApplyExtensions((function(e){return e.createTextureAsync(r,t,o,i,a)}),(function(){e.GLTFLoaderBase.CreateTextureAsync(r,t,o,i,a)}))},n.ApplyExtensions=function(n,r){for(var t in e.GLTFLoader.Extensions){if(n(e.GLTFLoader.Extensions[t]))return}r()},n})();e.GLTFLoaderExtension=n})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])};return function(n,r){function t(){this.constructor=n}e(n,r),n.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}})(),BABYLON;!(function(e){!(function(e){var n=(function(n){function r(){return n.call(this,"KHR_binary_glTF")||this}return __extends(r,n),r.prototype.loadRuntimeAsync=function(n,r,t,o,i){var a=r.json.extensionsUsed;return!(!a||-1===a.indexOf(this.name)||!r.bin)&&(this._bin=r.bin,o(e.GLTFLoaderBase.CreateRuntime(r.json,n,t)),!0)},r.prototype.loadBufferAsync=function(e,n,r,t){return-1!==e.extensionsUsed.indexOf(this.name)&&("binary_glTF"===n&&(r(this._bin),!0))},r.prototype.loadTextureBufferAsync=function(n,r,t,o){var i=n.textures[r],a=n.images[i.source];if(!(a.extensions&&this.name in a.extensions))return!1;var s=a.extensions[this.name],u=n.bufferViews[s.bufferView];return t(e.GLTFUtils.GetBufferFromBufferView(n,u,0,u.byteLength,e.EComponentType.UNSIGNED_BYTE)),!0},r.prototype.loadShaderStringAsync=function(n,r,t,o){var i=n.shaders[r];if(!(i.extensions&&this.name in i.extensions))return!1;var a=i.extensions[this.name],s=n.bufferViews[a.bufferView],u=e.GLTFUtils.GetBufferFromBufferView(n,s,0,s.byteLength,e.EComponentType.UNSIGNED_BYTE);return setTimeout((function(){var n=e.GLTFUtils.DecodeBufferToText(u);t(n)})),!0},r})(e.GLTFLoaderExtension);e.GLTFBinaryExtension=n,e.GLTFLoader.RegisterExtension(new n)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])};return function(n,r){function t(){this.constructor=n}e(n,r),n.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}})(),BABYLON;!(function(e){!(function(n){var r=(function(r){function t(){return r.call(this,"KHR_materials_common")||this}return __extends(t,r),t.prototype.loadRuntimeExtensionsAsync=function(n,r,t){if(!n.extensions)return!1;var o=n.extensions[this.name];if(!o)return!1;var i=o.lights;if(i)for(var a in i){var s=i[a];switch(s.type){case"ambient":var u=new e.HemisphericLight(s.name,new e.Vector3(0,1,0),n.scene),l=s.ambient;l&&(u.diffuse=e.Color3.FromArray(l.color||[1,1,1]));break;case"point":var c=new e.PointLight(s.name,new e.Vector3(10,10,10),n.scene),f=s.point;f&&(c.diffuse=e.Color3.FromArray(f.color||[1,1,1]));break;case"directional":var d=new e.DirectionalLight(s.name,new e.Vector3(0,-1,0),n.scene),m=s.directional;m&&(d.diffuse=e.Color3.FromArray(m.color||[1,1,1]));break;case"spot":var p=s.spot;if(p){var h=new e.SpotLight(s.name,new e.Vector3(0,10,0),new e.Vector3(0,-1,0),p.fallOffAngle||Math.PI,p.fallOffExponent||0,n.scene);h.diffuse=e.Color3.FromArray(p.color||[1,1,1])}break;default:e.Tools.Warn('GLTF Material Common extension: light type "'+s.type+"” not supported")}}return!1},t.prototype.loadMaterialAsync=function(n,r,t,o){var i=n.materials[r];if(!i||!i.extensions)return!1;var a=i.extensions[this.name];if(!a)return!1;var s=new e.StandardMaterial(r,n.scene);return s.sideOrientation=e.Material.CounterClockWiseSideOrientation,"CONSTANT"===a.technique&&(s.disableLighting=!0),s.backFaceCulling=void 0!==a.doubleSided&&!a.doubleSided,s.alpha=void 0===a.values.transparency?1:a.values.transparency,s.specularPower=void 0===a.values.shininess?0:a.values.shininess,"string"==typeof a.values.ambient?this._loadTexture(n,a.values.ambient,s,"ambientTexture",o):s.ambientColor=e.Color3.FromArray(a.values.ambient||[0,0,0]),"string"==typeof a.values.diffuse?this._loadTexture(n,a.values.diffuse,s,"diffuseTexture",o):s.diffuseColor=e.Color3.FromArray(a.values.diffuse||[0,0,0]),"string"==typeof a.values.emission?this._loadTexture(n,a.values.emission,s,"emissiveTexture",o):s.emissiveColor=e.Color3.FromArray(a.values.emission||[0,0,0]),"string"==typeof a.values.specular?this._loadTexture(n,a.values.specular,s,"specularTexture",o):s.specularColor=e.Color3.FromArray(a.values.specular||[0,0,0]),!0},t.prototype._loadTexture=function(e,r,t,o,i){n.GLTFLoaderBase.LoadTextureBufferAsync(e,r,(function(a){n.GLTFLoaderBase.CreateTextureAsync(e,r,a,(function(e){return t[o]=e}),i)}),i)},t})(n.GLTFLoaderExtension);n.GLTFMaterialsCommonExtension=r,n.GLTFLoader.RegisterExtension(new r)})(e.GLTF1||(e.GLTF1={}))})(BABYLON||(BABYLON={}));