12 |
- var BABYLON;!(function(e){var t;!(function(e){e[e.AUTO=0]="AUTO",e[e.PASS_THROUGH=1]="PASS_THROUGH",e[e.FORCE_RIGHT_HANDED=2]="FORCE_RIGHT_HANDED"})(t=e.GLTFLoaderCoordinateSystemMode||(e.GLTFLoaderCoordinateSystemMode={}));var n=(function(){function e(){this.coordinateSystemMode=t.AUTO,this.name="gltf",this.extensions={".gltf":{isBinary:!1},".glb":{isBinary:!0}}}return e.prototype.importMeshAsync=function(t,n,r,a,o,i,s){var l=e._parse(r,s);if(l){this.onParsed&&this.onParsed(l);var u=this._getLoader(l,s);u&&u.importMeshAsync(t,n,l,a,o,i,s)}},e.prototype.loadAsync=function(t,n,r,a,o,i){var s=e._parse(n,i);if(s){this.onParsed&&this.onParsed(s);var l=this._getLoader(s,i);if(l)return l.loadAsync(t,s,r,a,o,i)}},e.prototype.canDirectLoad=function(e){return-1!==e.indexOf("scene")&&-1!==e.indexOf("node")},e._parse=function(t,n){if(t instanceof ArrayBuffer)return e._parseBinary(t,n);try{return{json:JSON.parse(t),bin:null}}catch(e){return n(e.message),null}},e.prototype._getLoader=function(t,n){var r={major:2,minor:0},a=t.json.asset||{},o=e._parseVersion(a.version);if(!o)return n("Invalid version: "+a.version),null;if(void 0!==a.minVersion){var i=e._parseVersion(a.minVersion);if(!i)return n("Invalid minimum version: "+a.minVersion),null;if(e._compareVersion(i,r)>0)return n("Incompatible minimum version: "+a.minVersion),null}var s={1:e.CreateGLTFLoaderV1,2:e.CreateGLTFLoaderV2},l=s[o.major];return l?l(this):(n("Unsupported version: "+a.version),null)},e._parseBinary=function(t,n){var a={Magic:1179937895},o=new r(t),i=o.readUint32();if(i!==a.Magic)return n("Unexpected magic: "+i),null;var s=o.readUint32();switch(s){case 1:return e._parseV1(o,n);case 2:return e._parseV2(o,n)}return n("Unsupported version: "+s),null},e._parseV1=function(t,n){var r={JSON:0},a=t.readUint32();if(a!=t.getLength())return n("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o,i=t.readUint32(),s=t.readUint32();switch(s){case r.JSON:o=JSON.parse(e._decodeBufferToText(t.readUint8Array(i)));break;default:return n("Unexpected content format: "+s),null}var l=t.getLength()-t.getPosition();return{json:o,bin:t.readUint8Array(l)}},e._parseV2=function(t,n){var r={JSON:1313821514,BIN:5130562},a=t.readUint32();if(a!==t.getLength())return n("Length in header does not match actual data length: "+a+" != "+t.getLength()),null;var o=t.readUint32(),i=t.readUint32();if(i!==r.JSON)return n("First chunk format is not JSON"),null;for(var s=JSON.parse(e._decodeBufferToText(t.readUint8Array(o))),l=null;t.getPosition()<t.getLength();)switch(o=t.readUint32(),i=t.readUint32()){case r.JSON:return n("Unexpected JSON chunk"),null;case r.BIN:l=t.readUint8Array(o);break;default:t.skipBytes(o)}return{json:s,bin:l}},e._parseVersion=function(e){if(!e)return null;var t=e.split(".");if(2!=t.length)return null;var n=+t[0];if(isNaN(n))return null;var r=+t[1];return isNaN(r)?null:{major:n,minor:r}},e._compareVersion=function(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0},e._decodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;r<n;++r)t+=String.fromCharCode(e[r]);return t},e.HomogeneousCoordinates=!1,e.IncrementalLoading=!0,e})();e.GLTFFileLoader=n;var r=(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 t=new Uint8Array(this._arrayBuffer,this._byteOffset,e);return this._byteOffset+=e,t},e.prototype.skipBytes=function(e){this._byteOffset+=e},e})();e.SceneLoader&&e.SceneLoader.RegisterPlugin(new n)})(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.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.FLOAT=5126]="FLOAT"})(e.EComponentType||(e.EComponentType={}));!(function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(e.EMeshPrimitiveMode||(e.EMeshPrimitiveMode={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="LINEAR"})(e.ETextureMagFilter||(e.ETextureMagFilter={}));!(function(e){e[e.NEAREST=9728]="NEAREST",e[e.LINEAR=9729]="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.ETextureMinFilter||(e.ETextureMinFilter={}));!(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={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n=(function(){function e(e){this._pendingCount=0,this._callback=e}return e.prototype._addPendingData=function(e){this._pendingCount++},e.prototype._removePendingData=function(e){0==--this._pendingCount&&this._callback()},e})(),r=(function(){function r(t){this._renderReady=!1,this._disposed=!1,this._renderReadyObservable=new e.Observable,this._renderPendingCount=0,this._loaderPendingCount=0,this._loaderTrackers=new Array,this._parent=t}return r.RegisterExtension=function(n){if(r.Extensions[n.name])return void e.Tools.Error("Extension with the same name '"+n.name+"' already exists");r.Extensions[n.name]=n,t.GLTFLoaderExtension._Extensions.push(n)},r.prototype.dispose=function(){this._disposed||(this._disposed=!0,this._gltf.textures&&this._gltf.textures.forEach((function(e){e.url&&URL.revokeObjectURL(e.url)})),this._gltf=void 0,this._babylonScene=void 0,this._rootUrl=void 0,this._defaultMaterial=void 0,this._successCallback=void 0,this._errorCallback=void 0,this._renderReady=!1,this._renderReadyObservable.clear(),this._renderPendingCount=0,this._loaderPendingCount=0)},r.prototype.importMeshAsync=function(e,t,n,r,a,o,i){var s=this;this._loadAsync(e,t,n,r,(function(){a(s._getMeshes(),null,s._getSkeletons())}),o,i)},r.prototype.loadAsync=function(e,t,n,r,a,o){this._loadAsync(null,e,t,n,r,a,o)},r.prototype._loadAsync=function(e,t,n,r,a,o,i){this._loadData(n),this._babylonScene=t,this._rootUrl=r,this._successCallback=a,this._progressCallback=o,this._errorCallback=i,this._addPendingData(this),this._loadScene(e),this._loadAnimations(),this._removePendingData(this)},r.prototype._onError=function(e){this._errorCallback&&this._errorCallback(e),this.dispose()},r.prototype._onProgress=function(e){this._progressCallback&&this._progressCallback(e)},r.prototype._executeWhenRenderReady=function(e){this._renderReady?e():this._renderReadyObservable.add(e)},r.prototype._onRenderReady=function(){this._gltf.nodes[this._gltf.nodes.length-1].babylonMesh.setEnabled(!0),this._startAnimations(),this._successCallback(),this._renderReadyObservable.notifyObservers(this),this._parent.onReady&&this._parent.onReady()},r.prototype._onComplete=function(){this._parent.onComplete&&this._parent.onComplete(),this.dispose()},r.prototype._loadData=function(t){this._gltf=t.json;var n,r=this._gltf.buffers;r&&void 0===r[0].uri&&(n=r[0]),t.bin&&(n?n.byteLength!=t.bin.byteLength&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"):e.Tools.Warn("Unexpected BIN chunk"),n.loadedData=t.bin)},r.prototype._getMeshes=function(){var e=[],t=this._gltf.nodes;return t&&t.forEach((function(t){t.babylonMesh&&e.push(t.babylonMesh)})),e},r.prototype._getSkeletons=function(){var t=[],n=this._gltf.skins;return n&&n.forEach((function(n){n.babylonSkeleton instanceof e.Skeleton&&t.push(n.babylonSkeleton)})),t},r.prototype._getAnimationTargets=function(){var e=[],t=this._gltf.animations;return t&&t.forEach((function(t){e.push.apply(e,t.targets)})),e},r.prototype._startAnimations=function(){var e=this;this._getAnimationTargets().forEach((function(t){return e._babylonScene.beginAnimation(t,0,Number.MAX_VALUE,!0)}))},r.prototype._loadScene=function(t){var n=this._gltf.scenes[this._gltf.scene||0],r={name:"root",children:n.nodes};switch(this._parent.coordinateSystemMode){case e.GLTFLoaderCoordinateSystemMode.AUTO:this._babylonScene.useRightHandedSystem||(r.rotation=[0,1,0,0],r.scale=[1,1,-1]);break;case e.GLTFLoaderCoordinateSystemMode.PASS_THROUGH:break;case e.GLTFLoaderCoordinateSystemMode.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:e.Tools.Error("Invalid coordinate system mode ("+this._parent.coordinateSystemMode+")")}this._gltf.nodes=this._gltf.nodes||[],n.nodes=[this._gltf.nodes.length],this._gltf.nodes.push(r);var a=n.nodes;this._traverseNodes(a,(function(e,t,n){return e.index=t,e.parent=n,!0}));var o=this._gltf.materials;if(o&&o.forEach((function(e,t){return e.index=t})),t){t instanceof Array||(t=[t]);var i=new Array;this._traverseNodes(a,(function(e){return-1===t.indexOf(e.name)||(i.push(e.index),!1)})),a=i}for(var s=0;s<a.length;s++)this._loadNode(this._gltf.nodes[a[s]]);r.babylonMesh.setEnabled(!1)},r.prototype._loadNode=function(n){if(!t.GLTFLoaderExtension.LoadNode(this,n)){if(n.babylonMesh=new e.Mesh(n.name||"mesh"+n.index,this._babylonScene),this._loadTransform(n),void 0!==n.mesh){var r=this._gltf.meshes[n.mesh];this._loadMesh(n,r)}if(n.babylonMesh.parent=n.parent?n.parent.babylonMesh:null,n.babylonAnimationTargets=n.babylonAnimationTargets||[],n.babylonAnimationTargets.push(n.babylonMesh),void 0!==n.skin){var a=this._gltf.skins[n.skin];a.index=n.skin,n.babylonMesh.skeleton=this._loadSkin(a)}if(n.camera,n.children)for(var o=0;o<n.children.length;o++)this._loadNode(this._gltf.nodes[n.children[o]])}},r.prototype._loadMesh=function(n,r){var a=this;n.babylonMesh.name=r.name||n.babylonMesh.name;var o=new e.MultiMaterial(n.babylonMesh.name,this._babylonScene);n.babylonMesh.material=o;var i=new e.Geometry(n.babylonMesh.name,this._babylonScene,null,!1,n.babylonMesh),s=new e.VertexData;s.positions=[],s.indices=[];for(var l=[],u=0,d=r.primitives.length,c=this,f=0;f<d;f++)!(function(f){var _=r.primitives[f];if(_.mode&&_.mode!==t.EMeshPrimitiveMode.TRIANGLES)throw new Error("Not implemented");c._createMorphTargets(n,r,_,n.babylonMesh),c._loadVertexDataAsync(_,(function(t){a._loadMorphTargetsData(r,_,t,n.babylonMesh),l.push({materialIndex:f,verticesStart:s.positions.length,verticesCount:t.positions.length,indicesStart:s.indices.length,indicesCount:t.indices.length,loadMaterial:function(){if(void 0===_.material)return void(o.subMaterials[f]=a._getDefaultMaterial());var e=a._gltf.materials[_.material];a._loadMaterial(e,(function(t,r){r&&a._parent.onMaterialLoaded&&a._parent.onMaterialLoaded(t),a._parent.onBeforeMaterialReadyAsync?(a._addLoaderPendingData(e),a._parent.onBeforeMaterialReadyAsync(t,n.babylonMesh,null!=o.subMaterials[f],(function(){o.subMaterials[f]=t,a._removeLoaderPendingData(e)}))):o.subMaterials[f]=t}))}}),s.merge(t),++u===d&&(i.setAllVerticesData(s,!1),l.forEach((function(e){return e.loadMaterial()})),n.babylonMesh.subMeshes=[],l.forEach((function(t){return new e.SubMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indicesStart,t.indicesCount,n.babylonMesh)})))}))})(f)},r.prototype._loadVertexDataAsync=function(t,n){var r=this,a=t.attributes;if(!a)return void this._onError("Primitive has no attributes");var o,i=new e.VertexData,s=0,l=Object.keys(a).length,u=this;for(var d in a)!(function(d){o=u._gltf.accessors[a[d]],u._loadAccessorAsync(o,(function(a){switch(d){case"NORMAL":i.normals=a;break;case"POSITION":i.positions=a;break;case"TANGENT":i.tangents=a;break;case"TEXCOORD_0":i.uvs=a;break;case"TEXCOORD_1":i.uvs2=a;break;case"JOINTS_0":i.matricesIndices=new Float32Array(Array.prototype.slice.apply(a));break;case"WEIGHTS_0":i.matricesWeights=a;break;case"COLOR_0":i.colors=a;break;default:e.Tools.Warn("Ignoring unrecognized semantic '"+d+"'")}if(++s===l){var o=r._gltf.accessors[t.indices];o?r._loadAccessorAsync(o,(function(e){i.indices=e,n(i)})):(i.indices=new Uint32Array(i.positions.length/3),i.indices.forEach((function(e,t){return i.indices[t]=t})),n(i))}}))})(d)},r.prototype._createMorphTargets=function(t,n,r,a){var o=r.targets;if(o){a.morphTargetManager||(a.morphTargetManager=new e.MorphTargetManager);for(var i=0;i<o.length;i++){var s=t.weights?t.weights[i]:n.weights?n.weights[i]:0;a.morphTargetManager.addTarget(new e.MorphTarget("morphTarget"+i,s))}}},r.prototype._loadMorphTargetsData=function(n,r,a,o){var i=r.targets;if(i)for(var s,l,u=this,d=0;d<i.length;d++)!(function(){var n=o.morphTargetManager.getTarget(d);s=i[d];for(var r in s)!(function(r){l=u._gltf.accessors[s[r]],u._loadAccessorAsync(l,(function(o){l.name&&(n.name=l.name);var i=o;switch(r){case"NORMAL":t.GLTFUtils.ForEach(i,(function(e,t){return i[t]+=a.normals[t]})),n.setNormals(i);break;case"POSITION":t.GLTFUtils.ForEach(i,(function(e,t){return i[t]+=a.positions[t]})),n.setPositions(i);break;case"TANGENT":for(var s=0,u=0;s<i.length;s++,u++)i[s]+=a.tangents[u],(s+1)%3==0&&u++;n.setTangents(i);break;default:e.Tools.Warn("Ignoring unrecognized semantic '"+r+"'")}}))})(r)})()},r.prototype._loadTransform=function(t){var n=e.Vector3.Zero(),r=e.Quaternion.Identity(),a=e.Vector3.One();if(t.matrix){e.Matrix.FromArray(t.matrix).decompose(a,r,n)}else t.translation&&(n=e.Vector3.FromArray(t.translation)),t.rotation&&(r=e.Quaternion.FromArray(t.rotation)),t.scale&&(a=e.Vector3.FromArray(t.scale));t.babylonMesh.position=n,t.babylonMesh.rotationQuaternion=r,t.babylonMesh.scaling=a},r.prototype._loadSkin=function(t){var n=this,r="skeleton"+t.index;if(t.babylonSkeleton=new e.Skeleton(t.name||r,r,this._babylonScene),void 0===t.inverseBindMatrices)this._loadBones(t,null);else{var a=this._gltf.accessors[t.inverseBindMatrices];this._loadAccessorAsync(a,(function(e){n._loadBones(t,e)}))}return t.babylonSkeleton},r.prototype._createBone=function(t,n,r,a,o,i){var s=new e.Bone(t.name||"bone"+t.index,n.babylonSkeleton,r,a,null,o,i);return t.babylonBones=t.babylonBones||{},t.babylonBones[n.index]=s,t.babylonAnimationTargets=t.babylonAnimationTargets||[],t.babylonAnimationTargets.push(s),s},r.prototype._loadBones=function(e,t){for(var n={},r=0;r<e.joints.length;r++){var a=this._gltf.nodes[e.joints[r]];this._loadBone(a,e,t,n)}},r.prototype._loadBone=function(t,n,r,a){var o=a[t.index];if(o)return o;var i=n.joints.indexOf(t.index),s=e.Matrix.Identity();r&&-1!==i&&(s=e.Matrix.FromArray(r,16*i),s.invertToRef(s));var l;return t.index!=n.skeleton&&t.parent&&(l=this._loadBone(t.parent,n,r,a),s.multiplyToRef(l.getInvertedAbsoluteTransform(),s)),o=this._createBone(t,n,l,this._getNodeMatrix(t),s,i),a[t.index]=o,o},r.prototype._getNodeMatrix=function(t){return t.matrix?e.Matrix.FromArray(t.matrix):e.Matrix.Compose(t.scale?e.Vector3.FromArray(t.scale):e.Vector3.One(),t.rotation?e.Quaternion.FromArray(t.rotation):e.Quaternion.Identity(),t.translation?e.Vector3.FromArray(t.translation):e.Vector3.Zero())},r.prototype._traverseNodes=function(e,t,n){void 0===n&&(n=null);for(var r=0;r<e.length;r++)this._traverseNode(e[r],t,n)},r.prototype._traverseNode=function(e,n,r){if(void 0===r&&(r=null),!t.GLTFLoaderExtension.TraverseNode(this,e,n,r)){var a=this._gltf.nodes[e];n(a,e,r)&&a.children&&this._traverseNodes(a.children,n,a)}},r.prototype._loadAnimations=function(){var e=this._gltf.animations;if(e&&0!==e.length)for(var t=0;t<e.length;t++)for(var n=e[t],r=0;r<n.channels.length;r++)this._loadAnimationChannel(n,t,r)},r.prototype._loadAnimationChannel=function(t,n,r){var a=t.channels[r],o=a.sampler,i=t.samplers[o],s=this._gltf.nodes[a.target.node];if(!s)return void e.Tools.Warn("Animation channel target node ("+a.target.node+") does not exist");var l={translation:"position",rotation:"rotationQuaternion",scale:"scaling",weights:"influence"}[a.target.path];if(!l)return void e.Tools.Warn("Animation channel target path '"+a.target.path+"' is not valid");var u,d,c={position:e.Animation.ANIMATIONTYPE_VECTOR3,rotationQuaternion:e.Animation.ANIMATIONTYPE_QUATERNION,scaling:e.Animation.ANIMATIONTYPE_VECTOR3,influence:e.Animation.ANIMATIONTYPE_FLOAT}[l],f=function(){if(u&&d){for(var r=0,a={position:function(){var t=e.Vector3.FromArray(d,r);return r+=3,t},rotationQuaternion:function(){var t=e.Quaternion.FromArray(d,r);return r+=4,t},scaling:function(){var t=e.Vector3.FromArray(d,r);return r+=3,t},influence:function(){for(var e=s.babylonMesh.morphTargetManager.numTargets,t=new Array(e),n=0;n<e;n++)t[n]=d[r++];return t}}[l],o={LINEAR:function(e){return{frame:u[e],value:a()}},CUBICSPLINE:function(e){return{frame:u[e],inTangent:a(),value:a(),outTangent:a()}}}[i.interpolation],f=new Array(u.length),_=0;_<u.length;_++)f[_]=o(_);if(t.targets=t.targets||[],"influence"===l)for(var h=s.babylonMesh.morphTargetManager,p=0;p<h.numTargets;p++){var y=h.getTarget(p),T=(t.name||"anim"+n)+"_"+p,A=new e.Animation(T,l,1,c);A.setKeys(f.map((function(e){return{frame:e.frame,inTangent:e.inTangent?e.inTangent[p]:void 0,value:e.value[p],outTangent:e.outTangent?e.outTangent[p]:void 0}}))),y.animations.push(A),t.targets.push(y)}else{var T=t.name||"anim"+n,A=new e.Animation(T,l,1,c);A.setKeys(f);for(var b=0;b<s.babylonAnimationTargets.length;b++){var E=s.babylonAnimationTargets[b];E.animations.push(A.clone()),t.targets.push(E)}}}};this._loadAccessorAsync(this._gltf.accessors[i.input],(function(e){u=e,f()})),this._loadAccessorAsync(this._gltf.accessors[i.output],(function(e){d=e,f()}))},r.prototype._loadBufferAsync=function(n,r){var a=this,o=this._gltf.buffers[n];if(this._addPendingData(o),o.loadedData)setTimeout((function(){r(o.loadedData),a._removePendingData(o)}));else if(t.GLTFUtils.IsBase64(o.uri)){var i=t.GLTFUtils.DecodeBase64(o.uri);o.loadedData=new Uint8Array(i),setTimeout((function(){r(o.loadedData),a._removePendingData(o)}))}else o.loadedObservable?o.loadedObservable.add((function(e){r(e.loadedData),a._removePendingData(e)})):(o.loadedObservable=new e.Observable,o.loadedObservable.add((function(e){r(e.loadedData),a._removePendingData(e)})),e.Tools.LoadFile(this._rootUrl+o.uri,(function(e){o.loadedData=new Uint8Array(e),o.loadedObservable.notifyObservers(o),o.loadedObservable=null}),(function(e){a._disposed||a._onProgress(e)}),this._babylonScene.database,!0,(function(e){a._disposed||(a._onError("Failed to load file '"+o.uri+"': "+e.status+" "+e.statusText),a._removePendingData(o))})))},r.prototype._buildInt8ArrayBuffer=function(e,t,n,r,a){if(!r)return new Int8Array(e,t,n);var o=new Int8Array(e,t),i=new Int8Array(n);return this._extractInterleavedData(o,i,a,r,i.length),i},r.prototype._buildUint8ArrayBuffer=function(e,t,n,r,a){if(!r)return new Uint8Array(e,t,n);var o=new Uint8Array(e,t),i=new Uint8Array(n);return this._extractInterleavedData(o,i,a,r,i.length),i},r.prototype._buildInt16ArrayBuffer=function(e,t,n,r,a){if(!r)return new Int16Array(e,t,n);var o=new Int16Array(e,t),i=new Int16Array(n);return this._extractInterleavedData(o,i,a,r/2,i.length),i},r.prototype._buildUint16ArrayBuffer=function(e,t,n,r,a){if(!r)return new Uint16Array(e,t,n);var o=new Uint16Array(e,t),i=new Uint16Array(n);return this._extractInterleavedData(o,i,a,r/2,i.length),i},r.prototype._buildUint32ArrayBuffer=function(e,t,n,r,a){if(!r)return new Uint32Array(e,t,n);var o=new Uint32Array(e,t),i=new Uint32Array(n);return this._extractInterleavedData(o,i,a,r/4,i.length),i},r.prototype._buildFloat32ArrayBuffer=function(e,t,n,r,a){if(!r)return new Float32Array(e,t,n);var o=new Float32Array(e,t),i=new Float32Array(n);return this._extractInterleavedData(o,i,a,r/4,i.length),i},r.prototype._extractInterleavedData=function(e,t,n,r,a){for(var o=0,i=0,s=n;o<a;){for(var l=0;l<s;l++)t[o]=e[i+l],o++;i+=r}},r.prototype._loadBufferViewAsync=function(e,n,r,a,o,i){var s=this;n+=e.byteOffset||0,this._loadBufferAsync(e.buffer,(function(l){if(n+r>l.byteLength)return void s._onError("Buffer access is out of range");var u=l.buffer;n+=l.byteOffset;var d;switch(o){case t.EComponentType.BYTE:d=s._buildInt8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_BYTE:d=s._buildUint8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.SHORT:d=s._buildInt16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_SHORT:d=s._buildUint16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_INT:d=s._buildUint32ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.FLOAT:d=s._buildFloat32ArrayBuffer(u,n,r,e.byteStride,a);break;default:return void s._onError("Invalid component type ("+o+")")}i(d)}))},r.prototype._loadAccessorAsync=function(e,t){var n=this._gltf.bufferViews[e.bufferView],r=e.byteOffset||0,a=this._getByteStrideFromType(e),o=e.count*a;this._loadBufferViewAsync(n,r,o,a,e.componentType,t)},r.prototype._getByteStrideFromType=function(e){switch(e.type){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;default:return this._onError("Invalid accessor type ("+e.type+")"),0}},r.prototype._addPendingData=function(e){this._renderReady||this._renderPendingCount++,this._addLoaderPendingData(e)},r.prototype._removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this._removeLoaderPendingData(e)},r.prototype._addLoaderPendingData=function(e){this._loaderPendingCount++,this._loaderTrackers.forEach((function(t){return t._addPendingData(e)}))},r.prototype._removeLoaderPendingData=function(e){this._loaderTrackers.forEach((function(t){return t._removePendingData(e)})),0==--this._loaderPendingCount&&this._onComplete()},r.prototype._whenAction=function(e,t){var r=this,a=new n(function(){r._loaderTrackers.splice(r._loaderTrackers.indexOf(a)),t()});this._loaderTrackers.push(a),this._addLoaderPendingData(a),e(),this._removeLoaderPendingData(a)},r.prototype._getDefaultMaterial=function(){if(!this._defaultMaterial){var t="__gltf_default",n=this._babylonScene.getMaterialByName(t);n||(n=new e.PBRMaterial(t,this._babylonScene),n.sideOrientation=e.Material.CounterClockWiseSideOrientation,n.metallic=1,n.roughness=1),this._defaultMaterial=n}return this._defaultMaterial},r.prototype._loadMaterialMetallicRoughnessProperties=function(t){var n=t.babylonMaterial;n.metallic=1,n.roughness=1;var r=t.pbrMetallicRoughness;r&&(n.albedoColor=r.baseColorFactor?e.Color3.FromArray(r.baseColorFactor):new e.Color3(1,1,1),n.metallic=void 0===r.metallicFactor?1:r.metallicFactor,n.roughness=void 0===r.roughnessFactor?1:r.roughnessFactor,r.baseColorTexture&&(n.albedoTexture=this._loadTexture(r.baseColorTexture)),r.metallicRoughnessTexture&&(n.metallicTexture=this._loadTexture(r.metallicRoughnessTexture),n.useMetallnessFromMetallicTextureBlue=!0,n.useRoughnessFromMetallicTextureGreen=!0,n.useRoughnessFromMetallicTextureAlpha=!1),this._loadMaterialAlphaProperties(t,r.baseColorFactor))},r.prototype._loadMaterial=function(e,n){if(e.babylonMaterial)return void n(e.babylonMaterial,!1);t.GLTFLoaderExtension.LoadMaterial(this,e,n)||(this._createPbrMaterial(e),this._loadMaterialBaseProperties(e),this._loadMaterialMetallicRoughnessProperties(e),n(e.babylonMaterial,!0))},r.prototype._createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},r.prototype._loadMaterialBaseProperties=function(t){var n=t.babylonMaterial;n.emissiveColor=t.emissiveFactor?e.Color3.FromArray(t.emissiveFactor):new e.Color3(0,0,0),t.doubleSided&&(n.backFaceCulling=!1,n.twoSidedLighting=!0),t.normalTexture&&(n.bumpTexture=this._loadTexture(t.normalTexture),n.invertNormalMapX=!this._babylonScene.useRightHandedSystem,n.invertNormalMapY=this._babylonScene.useRightHandedSystem,void 0!==t.normalTexture.scale&&(n.bumpTexture.level=t.normalTexture.scale)),t.occlusionTexture&&(n.ambientTexture=this._loadTexture(t.occlusionTexture),n.useAmbientInGrayScale=!0,void 0!==t.occlusionTexture.strength&&(n.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&(n.emissiveTexture=this._loadTexture(t.emissiveTexture))},r.prototype._loadMaterialAlphaProperties=function(t,n){var r=t.babylonMaterial,a=t.alphaMode||"OPAQUE";switch(a){case"OPAQUE":break;case"MASK":case"BLEND":n&&(r.alpha=n[3]),r.albedoTexture&&(r.albedoTexture.hasAlpha=!0,r.useAlphaFromAlbedoTexture="BLEND"===a);break;default:e.Tools.Warn("Invalid alpha mode '"+t.alphaMode+"'")}r.alphaCutOff=void 0===t.alphaCutoff?.5:t.alphaCutoff},r.prototype._loadTexture=function(n){var r=this,a=this._gltf.textures[n.index],o=n.texCoord||0;if(!a||void 0===a.source)return null;var i=this._gltf.images[a.source],s=void 0===a.sampler?{}:this._gltf.samplers[a.sampler],l=s.minFilter===t.ETextureMinFilter.NEAREST||s.minFilter===t.ETextureMinFilter.LINEAR,u=t.GLTFUtils.GetTextureSamplingMode(s.magFilter,s.minFilter);this._addPendingData(a);var d=new e.Texture(null,this._babylonScene,l,!1,u,function(){r._disposed||r._removePendingData(a)},function(){r._disposed||(r._onError("Failed to load texture '"+i.uri+"'"),r._removePendingData(a))});if(a.url)d.updateURL(a.url);else if(a.dataReadyObservable)a.dataReadyObservable.add((function(e){d.updateURL(e.url)}));else{a.dataReadyObservable=new e.Observable,a.dataReadyObservable.add((function(e){d.updateURL(e.url)}));var c=function(e){a.url=URL.createObjectURL(new Blob([e],{type:i.mimeType})),a.dataReadyObservable.notifyObservers(a)};if(i.uri)t.GLTFUtils.IsBase64(i.uri)?c(new Uint8Array(t.GLTFUtils.DecodeBase64(i.uri))):e.Tools.LoadFile(this._rootUrl+i.uri,c,(function(e){r._disposed||r._onProgress(e)}),this._babylonScene.database,!0,(function(e){r._onError("Failed to load file '"+i.uri+"': "+e.status+" "+e.statusText)}));else{var f=this._gltf.bufferViews[i.bufferView];this._loadBufferViewAsync(f,0,f.byteLength,1,t.EComponentType.UNSIGNED_BYTE,c)}}return d.coordinatesIndex=o,d.wrapU=t.GLTFUtils.GetTextureWrapMode(s.wrapS),d.wrapV=t.GLTFUtils.GetTextureWrapMode(s.wrapT),d.name=a.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(d),d},r.Extensions={},r})();t.GLTFLoader=r,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new r(e)}})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var n=(function(){function n(){}return n.IsBase64=function(e){return!(e.length<5)&&"data:"===e.substr(0,5)},n.DecodeBase64=function(e){for(var t=atob(e.split(",")[1]),n=t.length,r=new Uint8Array(new ArrayBuffer(n)),a=0;a<n;a++)r[a]=t.charCodeAt(a);return r.buffer},n.ForEach=function(e,t){for(var n=0;n<e.length;n++)t(e[n],n)},n.GetTextureWrapMode=function(n){switch(n=void 0===n?t.ETextureWrapMode.REPEAT:n){case t.ETextureWrapMode.CLAMP_TO_EDGE:return e.Texture.CLAMP_ADDRESSMODE;case t.ETextureWrapMode.MIRRORED_REPEAT:return e.Texture.MIRROR_ADDRESSMODE;case t.ETextureWrapMode.REPEAT:return e.Texture.WRAP_ADDRESSMODE;default:return e.Tools.Warn("Invalid texture wrap mode ("+n+")"),e.Texture.WRAP_ADDRESSMODE}},n.GetTextureSamplingMode=function(n,r){if(n=void 0===n?t.ETextureMagFilter.LINEAR:n,r=void 0===r?t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:r,n===t.ETextureMagFilter.LINEAR)switch(r){case t.ETextureMinFilter.NEAREST:return e.Texture.LINEAR_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.LINEAR_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.LINEAR_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.LINEAR_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.LINEAR_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.LINEAR_LINEAR_MIPLINEAR;default:return e.Tools.Warn("Invalid texture minification filter ("+r+")"),e.Texture.LINEAR_LINEAR_MIPLINEAR}else switch(n!==t.ETextureMagFilter.NEAREST&&e.Tools.Warn("Invalid texture magnification filter ("+n+")"),r){case t.ETextureMinFilter.NEAREST:return e.Texture.NEAREST_NEAREST;case t.ETextureMinFilter.LINEAR:return e.Texture.NEAREST_LINEAR;case t.ETextureMinFilter.NEAREST_MIPMAP_NEAREST:return e.Texture.NEAREST_NEAREST_MIPNEAREST;case t.ETextureMinFilter.LINEAR_MIPMAP_NEAREST:return e.Texture.NEAREST_LINEAR_MIPNEAREST;case t.ETextureMinFilter.NEAREST_MIPMAP_LINEAR:return e.Texture.NEAREST_NEAREST_MIPLINEAR;case t.ETextureMinFilter.LINEAR_MIPMAP_LINEAR:return e.Texture.NEAREST_LINEAR_MIPLINEAR;default:return e.Tools.Warn("Invalid texture minification filter ("+r+")"),e.Texture.NEAREST_NEAREST_MIPNEAREST}},n.DecodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;r<n;++r)t+=String.fromCharCode(e[r]);return t},n})();t.GLTFUtils=n})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(e){var t=(function(){function e(){this.enabled=!0}return e.prototype._traverseNode=function(e,t,n,r){return!1},e.prototype._loadNode=function(e,t){return!1},e.prototype._loadMaterial=function(e,t,n){return!1},e.prototype._loadExtension=function(e,t){var n=this;if(!e.extensions)return!1;var r=e.extensions[this.name];return!!r&&(e.extensions[this.name]=void 0,t(r,(function(){e.extensions[n.name]=r})),!0)},e.TraverseNode=function(e,t,n,r){return this._ApplyExtensions((function(a){return a._traverseNode(e,t,n,r)}))},e.LoadNode=function(e,t){return this._ApplyExtensions((function(n){return n._loadNode(e,t)}))},e.LoadMaterial=function(e,t,n){return this._ApplyExtensions((function(r){return r._loadMaterial(e,t,n)}))},e._ApplyExtensions=function(t){var n=e._Extensions;if(n){for(var r=0;r<n.length;r++){var a=n[r];if(a.enabled&&t(a))return!0}return!1}},e._Extensions=[],e})();e.GLTFLoaderExtension=t})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}})(),BABYLON;!(function(e){!(function(t){!(function(n){var r=(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),Object.defineProperty(n.prototype,"name",{get:function(){return"MSFT_lod"},enumerable:!0,configurable:!0}),n.prototype._traverseNode=function(e,t,n,r){var a=e._gltf.nodes[t];return this._loadExtension(a,(function(a,o){for(var i=a.ids.length-1;i>=0;i--)e._traverseNode(a.ids[i],n,r);e._traverseNode(t,n,r),o()}))},n.prototype._loadNode=function(e,t){var n=this;return this._loadExtension(t,(function(r,a){var o=[t.index].concat(r.ids).map((function(t){return e._gltf.nodes[t]}));e._addLoaderPendingData(t),n._loadNodeLOD(e,o,o.length-1,(function(){e._removeLoaderPendingData(t),a()}))}))},n.prototype._loadNodeLOD=function(e,t,r,a){var o=this;e._whenAction((function(){e._loadNode(t[r])}),(function(){if(r!==t.length-1){t[r+1].babylonMesh.setEnabled(!1)}if(0===r)return void a();setTimeout((function(){o._loadNodeLOD(e,t,r-1,a)}),n.MinimalLODDelay)}))},n.prototype._loadMaterial=function(e,t,n){var r=this;return this._loadExtension(t,(function(a,o){var i=[t.index].concat(a.ids).map((function(t){return e._gltf.materials[t]}));e._addLoaderPendingData(t),r._loadMaterialLOD(e,i,i.length-1,n,(function(){t.extensions[r.name]=a,e._removeLoaderPendingData(t),o()}))}))},n.prototype._loadMaterialLOD=function(t,r,a,o,i){var s=this;t._loadMaterial(r[a],(function(l,u){if(o(l,u),0===a)return void i();t._executeWhenRenderReady((function(){e.BaseTexture.WhenAllReady(l.getActiveTextures(),(function(){setTimeout((function(){s._loadMaterialLOD(t,r,a-1,o,i)}),n.MinimalLODDelay)}))}))}))},n.MinimalLODDelay=250,n})(t.GLTFLoaderExtension);n.MSFTLOD=r,t.GLTFLoader.RegisterExtension(new r)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){
- for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}})(),BABYLON;!(function(e){!(function(t){!(function(n){var r=(function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return __extends(n,t),Object.defineProperty(n.prototype,"name",{get:function(){return"KHR_materials_pbrSpecularGlossiness"},enumerable:!0,configurable:!0}),n.prototype._loadMaterial=function(e,t,n){var r=this;return this._loadExtension(t,(function(a,o){e._createPbrMaterial(t),e._loadMaterialBaseProperties(t),r._loadSpecularGlossinessProperties(e,t,a),n(t.babylonMaterial,!0)}))},n.prototype._loadSpecularGlossinessProperties=function(t,n,r){var a=n.babylonMaterial;a.albedoColor=r.diffuseFactor?e.Color3.FromArray(r.diffuseFactor):new e.Color3(1,1,1),a.reflectivityColor=r.specularFactor?e.Color3.FromArray(r.specularFactor):new e.Color3(1,1,1),a.microSurface=void 0===r.glossinessFactor?1:r.glossinessFactor,r.diffuseTexture&&(a.albedoTexture=t._loadTexture(r.diffuseTexture)),r.specularGlossinessTexture&&(a.reflectivityTexture=t._loadTexture(r.specularGlossinessTexture),a.reflectivityTexture.hasAlpha=!0,a.useMicroSurfaceFromReflectivityMapAlpha=!0),t._loadMaterialAlphaProperties(n,r.diffuseFactor)},n})(t.GLTFLoaderExtension);n.KHRMaterialsPbrSpecularGlossiness=r,t.GLTFLoader.RegisterExtension(new r)})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));
|