!(function(e,r){var t=[],n=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(n=n||require("babylonjs"),module.exports=r(n)):"function"==typeof define&&define.amd?(t.push("babylonjs"),define("babylonjs-loaders",t,r)):"object"==typeof exports?(n=n||require("babylonjs"),exports["babylonjs-loaders"]=r(n)):e.BABYLON=r(n)})(this,(function(e){e=e||this.BABYLON;var e,r=(this&&this.__decorate,this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t])};return function(r,t){function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}})());!(function(e){var r=(function(){function r(){this.solidPattern=/solid (\S*)([\S\s]*)endsolid[ ]*(\S*)/g,this.facetsPattern=/facet([\s\S]*?)endfacet/g,this.normalPattern=/normal[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.vertexPattern=/vertex[\s]+([\-+]?[0-9]+\.?[0-9]*([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+[\s]+([\-+]?[0-9]*\.?[0-9]+([eE][\-+]?[0-9]+)?)+/g,this.name="stl",this.extensions={".stl":{isBinary:!0}}}return r.prototype.importMesh=function(r,t,n,o,a,i,s){var l;if(this.isBinary(n)){var u=new e.Mesh("stlmesh",t);return this.parseBinary(u,n),a&&a.push(u),!0}for(var c=new Uint8Array(n),d="",f=0;f127)return!0;return!1},r.prototype.parseBinary=function(r,t){for(var n=new DataView(t),o=n.getUint32(80,!0),a=0,i=new Float32Array(3*o*3),s=new Float32Array(3*o*3),l=new Uint32Array(3*o),u=0,c=0;c=0?c.substring(0,d):c;f=f.toLowerCase();var h=d>=0?c.substring(d+1).trim():"";"newmtl"===f?(l&&this.materials.push(l),l=new e.StandardMaterial(h,t)):"kd"===f&&l?(a=h.split(s,3).map(parseFloat),l.diffuseColor=e.Color3.FromArray(a)):"ka"===f&&l?(a=h.split(s,3).map(parseFloat),l.ambientColor=e.Color3.FromArray(a)):"ks"===f&&l?(a=h.split(s,3).map(parseFloat),l.specularColor=e.Color3.FromArray(a)):"ke"===f&&l?(a=h.split(s,3).map(parseFloat),l.emissiveColor=e.Color3.FromArray(a)):"ns"===f&&l?l.specularPower=parseFloat(h):"d"===f&&l?l.alpha=parseFloat(h):"map_ka"===f&&l?l.ambientTexture=r._getTexture(o,h,t):"map_kd"===f&&l?l.diffuseTexture=r._getTexture(o,h,t):"map_ks"===f&&l?l.specularTexture=r._getTexture(o,h,t):"map_ns"===f||("map_bump"===f&&l?l.bumpTexture=r._getTexture(o,h,t):"map_d"===f&&l&&(l.opacityTexture=r._getTexture(o,h,t)))}}l&&this.materials.push(l)}},r._getTexture=function(r,t,n){if(!t)return null;var o=r;if("file:"===r){var a=t.lastIndexOf("\\");-1===a&&(a=t.lastIndexOf("/")),o+=a>-1?t.substr(a+1):t}else o+=t;return new e.Texture(o,n)},r})();e.MTLFileLoader=r;var t=(function(){function t(){this.name="obj",this.extensions=".obj",this.obj=/^o/,this.group=/^g/,this.mtllib=/^mtllib /,this.usemtl=/^usemtl /,this.smooth=/^s /,this.vertexPattern=/v( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.normalPattern=/vn( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.uvPattern=/vt( +[\d|\.|\+|\-|e|E]+)( +[\d|\.|\+|\-|e|E]+)/,this.facePattern1=/f\s+(([\d]{1,}[\s]?){3,})+/,this.facePattern2=/f\s+((([\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern3=/f\s+((([\d]{1,}\/[\d]{1,}\/[\d]{1,}[\s]?){3,})+)/,this.facePattern4=/f\s+((([\d]{1,}\/\/[\d]{1,}[\s]?){3,})+)/}return t.prototype._loadMTL=function(r,t,n){var o=e.Tools.BaseUrl+t+r;e.Tools.LoadFile(o,n,void 0,void 0,!1,(function(){console.warn("Error - Unable to load "+o)}))},t.prototype.importMesh=function(e,r,t,n,o,a,i){var s=this._parseSolid(e,r,t,n);return o&&s.forEach((function(e){o.push(e)})),!0},t.prototype.load=function(e,r,t){return this.importMesh(null,e,r,t,null,null,null)},t.prototype.loadAssetContainer=function(r,t,n,o){var a=new e.AssetContainer(r);return this.importMesh(null,r,t,n,a.meshes,null,null),a.removeAllFromScene(),a},t.prototype._parseSolid=function(n,o,a,i){for(var s,l=[],u=[],c=[],d=[],f=[],h=[],p=[],m=[],_=[],y=0,v=!1,b=[],A=[],T=[],g=[],E="",L="",x=new r,M=1,O=!0,S=function(e,r){e[r[0]]||(e[r[0]]={normals:[],idx:[]});var t=e[r[0]].normals.indexOf(r[1]);return-1===t?-1:e[r[0]].idx[t]},w=function(e,r){e[r[0]]||(e[r[0]]={normals:[],idx:[],uv:[]});var t=e[r[0]].normals.indexOf(r[1]);return 1!=t&&r[2]==e[r[0]].uv[t]?e[r[0]].idx[t]:-1},N=function(e,r,n,o,a,i){var s;s=t.OPTIMIZE_WITH_UV?w(_,[e,n,r]):S(_,[e,n]),-1==s?(f.push(h.length),h.push(o),p.push(a),m.push(i),_[e].normals.push(n),_[e].idx.push(y++),t.OPTIMIZE_WITH_UV&&_[e].uv.push(r)):f.push(s)},F=function(){for(var e=0;e0&&(s=d[d.length-1],F(),f.reverse(),s.indices=f.slice(),s.positions=b.slice(),s.normals=A.slice(),s.uvs=T.slice(),f=[],b=[],A=[],T=[])},C=a.split("\n"),R=0;R-1;)a.push(t),n=t+1;if(-1==t&&0==a.length)x.materials[r].dispose();else for(var s=0;s0)throw new Error("Incompatible minimum version: "+o.minVersion)}var s={1:n.CreateGLTFLoaderV1,2:n.CreateGLTFLoaderV2},l=s[a.major];if(!l)throw new Error("Unsupported version: "+o.version);var u=l();return u.coordinateSystemMode=this.coordinateSystemMode,u.animationStartMode=this.animationStartMode,u.compileMaterials=this.compileMaterials,u.useClipPlane=this.useClipPlane,u.compileShadowGenerators=this.compileShadowGenerators,u.transparencyAsCoverage=this.transparencyAsCoverage,u._normalizeAnimationGroupsToBeginAtZero=this._normalizeAnimationGroupsToBeginAtZero,u.preprocessUrlAsync=this.preprocessUrlAsync,u.onMeshLoadedObservable.add((function(e){return r.onMeshLoadedObservable.notifyObservers(e)})),u.onTextureLoadedObservable.add((function(e){return r.onTextureLoadedObservable.notifyObservers(e)})),u.onMaterialLoadedObservable.add((function(e){return r.onMaterialLoadedObservable.notifyObservers(e)})),u.onCameraLoadedObservable.add((function(e){return r.onCameraLoadedObservable.notifyObservers(e)})),u.onExtensionLoadedObservable.add((function(e){return r.onExtensionLoadedObservable.notifyObservers(e)})),u.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()})),u},n._parseBinary=function(e){var r={Magic:1179937895},t=new o(e),a=t.readUint32();if(a!==r.Magic)throw new Error("Unexpected magic: "+a);var i=t.readUint32();switch(i){case 1:return n._parseV1(t);case 2:return n._parseV2(t)}throw new Error("Unsupported version: "+i)},n._parseV1=function(e){var r={JSON:0},t=e.readUint32();if(t!=e.getLength())throw new Error("Length in header does not match actual data length: "+t+" != "+e.getLength());var o,a=e.readUint32(),i=e.readUint32();switch(i){case r.JSON:o=JSON.parse(n._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)}},n._parseV2=function(e){var r={JSON:1313821514,BIN:5130562},t=e.readUint32();if(t!==e.getLength())throw new Error("Length in header does not match actual data length: "+t+" != "+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(n._decodeBufferToText(e.readUint8Array(o))),i=null;e.getPosition()r.major?1:e.majorr.minor?1:e.minor=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"],l=function(e,r){for(var t in e){var n=e[t];r.buffers[t]=n,r.buffersCount++}},u=function(e,r){for(var t in e){var n=e[t];r.shaders[t]=n,r.shaderscount++}},c=function(e,r,t){for(var n in e){var o=e[n];t[r][n]=o}},d=function(e){if(e)for(var r=0;r0&&(h=_(i,a))&&-1===s.indexOf(h)&&s.push(h);new e.Bone(c.jointName||"",o,h,L).id=a}}else e.Tools.Warn("Joint named "+t.jointNames[l]+" does not exist")}}var x=o.bones;o.bones=[];for(var l=0;l1?(N=new e.MultiMaterial("multimat"+a,t.scene),N.subMaterials=s):N=new e.StandardMaterial("multimat"+a,t.scene),1===s.length&&(N=s[0]),i.material||(i.material=N),new e.Geometry(a,t.scene,l,!1,i),i.computeWorldMatrix(!0),i.subMeshes=[];for(var F=0,p=0;p0&&-1===r.importMeshesNames.indexOf(t.name||""))return null;if(t.skin){if(t.meshes){var i=r.skins[t.skin],s=T(r,t,t.meshes,n,t.babylonNode);s.skeleton=r.scene.getLastSkeletonByID(t.skin),null===s.skeleton&&(s.skeleton=A(r,i,0,i.babylonSkeleton,t.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),a=s}}else if(t.meshes){var s=T(r,t,t.mesh?[t.mesh]:t.meshes,n,t.babylonNode);a=s}else if(!t.light||t.babylonNode||r.importOnlyMeshes){if(t.camera&&!t.babylonNode&&!r.importOnlyMeshes){var l=r.cameras[t.camera];if(l)if("orthographic"===l.type){var u=new e.FreeCamera(t.camera,e.Vector3.Zero(),r.scene,!1);u.name=t.name||"",u.mode=e.Camera.ORTHOGRAPHIC_CAMERA,u.attachControl(r.scene.getEngine().getRenderingCanvas()),a=u}else if("perspective"===l.type){var c=l[l.type],d=new e.FreeCamera(t.camera,e.Vector3.Zero(),r.scene,!1);d.name=t.name||"",d.attachControl(r.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=r.scene.getEngine().getRenderWidth()/r.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(d.maxZ=c.zfar,d.minZ=c.znear),a=d}}}else{var f=r.lights[t.light];if(f)if("ambient"===f.type){var h=f[f.type],p=new e.HemisphericLight(t.light,e.Vector3.Zero(),r.scene);p.name=t.name||"",h.color&&(p.diffuse=e.Color3.FromArray(h.color)),a=p}else if("directional"===f.type){var m=f[f.type],_=new e.DirectionalLight(t.light,e.Vector3.Zero(),r.scene);_.name=t.name||"",m.color&&(_.diffuse=e.Color3.FromArray(m.color)),a=_}else if("point"===f.type){var y=f[f.type],v=new e.PointLight(t.light,e.Vector3.Zero(),r.scene);v.name=t.name||"", y.color&&(v.diffuse=e.Color3.FromArray(y.color)),a=v}else if("spot"===f.type){var b=f[f.type],L=new e.SpotLight(t.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,r.scene);L.name=t.name||"",b.color&&(L.diffuse=e.Color3.FromArray(b.color)),b.fallOfAngle&&(L.angle=b.fallOfAngle),b.fallOffExponent&&(L.exponent=b.fallOffExponent),a=L}}if(!t.jointName){if(t.babylonNode)return t.babylonNode;if(null===a){var x=new e.Mesh(t.name||"",r.scene);t.babylonNode=x,a=x}}if(null!==a){if(t.matrix&&a instanceof e.Mesh)E(a,t);else{var M=t.translation||[0,0,0],O=t.rotation||[0,0,0,1],S=t.scale||[1,1,1];g(a,e.Vector3.FromArray(M),e.Quaternion.FromArray(O),e.Vector3.FromArray(S))}a.updateCache(!0),t.babylonNode=a}return a},x=function(e,r,t,n){void 0===n&&(n=!1);var o=e.nodes[r],a=null;if(n=!(e.importOnlyMeshes&&!n&&e.importMeshesNames)||(-1!==e.importMeshesNames.indexOf(o.name||"")||0===e.importMeshesNames.length),!o.jointName&&n&&null!==(a=L(e,o,r))&&(a.id=r,a.parent=t),o.children)for(var i=0;ii.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(n+=i.byteOffset,a){case r.EComponentType.BYTE:return new Int8Array(s,n,o);case r.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,n,o);case r.EComponentType.SHORT:return new Int16Array(s,n,o);case r.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,n,o);default:return new Float32Array(s,n,o)}},t.GetBufferFromAccessor=function(e,r){var n=e.bufferViews[r.bufferView],o=r.count*t.GetByteStrideFromType(r);return t.GetBufferFromBufferView(e,n,r.byteOffset,o,r.componentType)},t.DecodeBufferToText=function(e){for(var r="",t=e.byteLength,n=0;nr.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+r.bin.byteLength+")"),n._data=Promise.resolve(r.bin)}else e.Tools.Warn("Unexpected BIN chunk")}},t.prototype._setupData=function(){if(r._ArrayItem.Assign(this._gltf.accessors),r._ArrayItem.Assign(this._gltf.animations),r._ArrayItem.Assign(this._gltf.buffers),r._ArrayItem.Assign(this._gltf.bufferViews),r._ArrayItem.Assign(this._gltf.cameras),r._ArrayItem.Assign(this._gltf.images),r._ArrayItem.Assign(this._gltf.materials),r._ArrayItem.Assign(this._gltf.meshes),r._ArrayItem.Assign(this._gltf.nodes),r._ArrayItem.Assign(this._gltf.samplers),r._ArrayItem.Assign(this._gltf.scenes),r._ArrayItem.Assign(this._gltf.skins),r._ArrayItem.Assign(this._gltf.textures),this._gltf.nodes){for(var e={},t=0,n=this._gltf.nodes;t=0;i--)if(a.push(t.GLTFLoader._GetProperty(e+"/ids/"+o[i],n,o[i])),a.length===this.maxLODsToLoad)return a;return a.push(r),a},a})(t.GLTFLoaderExtension);n.MSFT_lod=a,t.GLTFLoader._Register(o,(function(e){return new a(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){!(function(e){!(function(t){var n="MSFT_minecraftMesh",o=(function(e){function t(r){var t=e.call(this,r)||this;t.name=n,t._onMaterialLoaded=function(e){e.needAlphaBlending()&&(e.forceDepthWrite=!0,e.separateCullingPass=!0),e.backFaceCulling=e.forceDepthWrite,e.twoSidedLighting=!0};var o=r._gltf.meshes;if(o&&o.length)for(var a=0,i=o;a