babylon.glTF1FileLoader.min.js 45 KB

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