var globalObject="undefined"!=typeof global?global:"undefined"!=typeof window?window:this,babylonDependency=globalObject&&globalObject.BABYLON||BABYLON||"undefined"!=typeof require&&require("babylonjs"),BABYLON=babylonDependency,__decorate=this&&this.__decorate||function(e,t,r,n){var o,a=arguments.length,i=a<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(i=(a<3?o(i):a>3?o(t,r,i):o(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i},__extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(e){var t=(function(){function t(){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 t.prototype.importMesh=function(t,r,n,o,a,i,s){var l;if(this.isBinary(n)){var u=new e.Mesh("stlmesh",r);return this.parseBinary(u,n),a&&a.push(u),!0}for(var c=new Uint8Array(n),d="",f=0;f127)return!0;return!1},t.prototype.parseBinary=function(t,r){for(var n=new DataView(r),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?u.substring(0,c):u;d=d.toLowerCase();var f=c>=0?u.substring(c+1).trim():"";"newmtl"===d?(s&&this.materials.push(s),s=new e.StandardMaterial(f,r)):"kd"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.diffuseColor=e.Color3.FromArray(a)):"ka"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.ambientColor=e.Color3.FromArray(a)):"ks"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.specularColor=e.Color3.FromArray(a)):"ke"===d&&s?(a=f.split(/\s+/,3).map(parseFloat),s.emissiveColor=e.Color3.FromArray(a)):"ns"===d&&s?s.specularPower=parseFloat(f):"d"===d&&s?s.alpha=parseFloat(f):"map_ka"===d&&s?s.ambientTexture=t._getTexture(o,f,r):"map_kd"===d&&s?s.diffuseTexture=t._getTexture(o,f,r):"map_ks"===d&&s?s.specularTexture=t._getTexture(o,f,r):"map_ns"===d||("map_bump"===d&&s?s.bumpTexture=t._getTexture(o,f,r):"map_d"===d&&s&&(s.opacityTexture=t._getTexture(o,f,r)))}}s&&this.materials.push(s)},t._getTexture=function(t,r,n){if(!r)return null;var o=t;if("file:"===t){var a=r.lastIndexOf("\\");-1===a&&(a=r.lastIndexOf("/")),o+=a>-1?r.substr(a+1):r}else o+=r;return new e.Texture(o,n)},t})();e.MTLFileLoader=t;var r=(function(){function r(){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 r.prototype._loadMTL=function(t,r,n){var o=e.Tools.BaseUrl+r+t;e.Tools.LoadFile(o,n,void 0,void 0,!1,(function(){console.warn("Error - Unable to load "+o)}))},r.prototype.importMesh=function(e,t,r,n,o,a,i){var s=this._parseSolid(e,t,r,n);return o&&s.forEach((function(e){o.push(e)})),!0},r.prototype.load=function(e,t,r){return this.importMesh(null,e,t,r,null,null,null)},r.prototype.loadAssetContainer=function(t,r,n,o){var a=new e.AssetContainer(t);return this.importMesh(null,t,r,n,a.meshes,null,null),a.removeAllFromScene(),a},r.prototype._parseSolid=function(n,o,a,i){for(var s,l=[],u=[],c=[],d=[],f=[],h=[],p=[],m=[],_=[],y=0,A=!1,v=[],T=[],b=[],g=[],E="",L="",O=new t,M=1,x=!0,N=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[]});var r=e[t[0]].normals.indexOf(t[1]);return-1===r?-1:e[t[0]].idx[r]},S=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});var r=e[t[0]].normals.indexOf(t[1]);return 1!=r&&t[2]==e[t[0]].uv[r]?e[t[0]].idx[r]:-1},w=function(e,t,n,o,a,i){var s;s=r.OPTIMIZE_WITH_UV?S(_,[e,n,t]):N(_,[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++),r.OPTIMIZE_WITH_UV&&_[e].uv.push(t)):f.push(s)},F=function(){for(var e=0;e0&&(s=d[d.length-1],F(),f.reverse(),s.indices=f.slice(),s.positions=v.slice(),s.normals=T.slice(),s.uvs=b.slice(),f=[],v=[],T=[],b=[])},R=a.split("\n"),P=0;P-1;)a.push(r),n=r+1;if(-1==r&&0==a.length)O.materials[t].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.onMeshLoadedObservable.add((function(e){return t.onMeshLoadedObservable.notifyObservers(e)})),u.onTextureLoadedObservable.add((function(e){return t.onTextureLoadedObservable.notifyObservers(e)})),u.onMaterialLoadedObservable.add((function(e){return t.onMaterialLoadedObservable.notifyObservers(e)})),u.onCompleteObservable.add((function(){return t.onCompleteObservable.notifyObservers(t)})),u.onExtensionLoadedObservable.add((function(e){return t.onExtensionLoadedObservable.notifyObservers(e)})),u},n._parseBinary=function(e){var t={Magic:1179937895},r=new o(e),a=r.readUint32();if(a!==t.Magic)throw new Error("Unexpected magic: "+a);var i=r.readUint32();switch(i){case 1:return n._parseV1(r);case 2:return n._parseV2(r)}throw new Error("Unsupported version: "+i)},n._parseV1=function(e){var t={JSON:0},r=e.readUint32();if(r!=e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o,a=e.readUint32(),i=e.readUint32();switch(i){case t.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 t={JSON:1313821514,BIN:5130562},r=e.readUint32();if(r!==e.getLength())throw new Error("Length in header does not match actual data length: "+r+" != "+e.getLength());var o=e.readUint32();if(e.readUint32()!==t.JSON)throw new Error("First chunk format is not JSON");for(var a=JSON.parse(n._decodeBufferToText(e.readUint8Array(o))),i=null;e.getPosition()t.major?1:e.majort.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,t){for(var r in e){var n=e[r];t.buffers[r]=n,t.buffersCount++}},u=function(e,t){for(var r in e){var n=e[r];t.shaders[r]=n,t.shaderscount++}},c=function(e,t,r){for(var n in e){var o=e[n];r[t][n]=o}},d=function(e){if(e)for(var t=0;t0&&(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 "+r.jointNames[l]+" does not exist")}}var O=o.bones;o.bones=[];for(var l=0;l1?(w=new e.MultiMaterial("multimat"+a,r.scene),w.subMaterials=s):w=new e.StandardMaterial("multimat"+a,r.scene),1===s.length&&(w=s[0]),i.material||(i.material=w),new e.Geometry(a,r.scene,l,!1,i),i.computeWorldMatrix(!0),i.subMeshes=[];for(var F=0,p=0;p0&&-1===t.importMeshesNames.indexOf(r.name||""))return null;if(r.skin){if(r.meshes){var i=t.skins[r.skin],s=b(t,r,r.meshes,n,r.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(r.skin),null===s.skeleton&&(s.skeleton=T(t,i,0,i.babylonSkeleton,r.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),a=s}}else if(r.meshes){var s=b(t,r,r.mesh?[r.mesh]:r.meshes,n,r.babylonNode);a=s}else if(!r.light||r.babylonNode||t.importOnlyMeshes){if(r.camera&&!r.babylonNode&&!t.importOnlyMeshes){var l=t.cameras[r.camera];if(l)if("orthographic"===l.type){var u=new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene);u.name=r.name||"",u.mode=e.Camera.ORTHOGRAPHIC_CAMERA,u.attachControl(t.scene.getEngine().getRenderingCanvas()),a=u}else if("perspective"===l.type){var c=l[l.type],d=new e.FreeCamera(r.camera,e.Vector3.Zero(),t.scene);d.name=r.name||"",d.attachControl(t.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(d.maxZ=c.zfar,d.minZ=c.znear),a=d}}}else{var f=t.lights[r.light];if(f)if("ambient"===f.type){var h=f[f.type],p=new e.HemisphericLight(r.light,e.Vector3.Zero(),t.scene);p.name=r.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(r.light,e.Vector3.Zero(),t.scene);_.name=r.name||"",m.color&&(_.diffuse=e.Color3.FromArray(m.color)),a=_}else if("point"===f.type){var y=f[f.type],A=new e.PointLight(r.light,e.Vector3.Zero(),t.scene);A.name=r.name||"",y.color&&(A.diffuse=e.Color3.FromArray(y.color)),a=A}else if("spot"===f.type){var v=f[f.type],L=new e.SpotLight(r.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);L.name=r.name||"",v.color&&(L.diffuse=e.Color3.FromArray(v.color)),v.fallOfAngle&&(L.angle=v.fallOfAngle),v.fallOffExponent&&(L.exponent=v.fallOffExponent),a=L}}if(!r.jointName){if(r.babylonNode)return r.babylonNode;if(null===a){var O=new e.Mesh(r.name||"",t.scene);r.babylonNode=O,a=O}}if(null!==a){if(r.matrix&&a instanceof e.Mesh)E(a,r);else{var M=r.translation||[0,0,0],x=r.rotation||[0,0,0,1],N=r.scale||[1,1,1];g(a,e.Vector3.FromArray(M),e.Quaternion.FromArray(x),e.Vector3.FromArray(N))}a.updateCache(!0),r.babylonNode=a}return a},O=function(e,t,r,n){void 0===n&&(n=!1);var o=e.nodes[t],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,t))&&(a.id=t,a.parent=r),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 t.EComponentType.BYTE:return new Int8Array(s,n,o);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,n,o);case t.EComponentType.SHORT:return new Int16Array(s,n,o);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,n,o);default:return new Float32Array(s,n,o)}},r.GetBufferFromAccessor=function(e,t){var n=e.bufferViews[t.bufferView],o=t.count*r.GetByteStrideFromType(t);return r.GetBufferFromBufferView(e,n,t.byteOffset,o,t.componentType)},r.DecodeBufferToText=function(e){for(var t="",r=e.byteLength,n=0;nt.bin.byteLength)&&e.Tools.Warn("Binary buffer length ("+n.byteLength+") from JSON does not match chunk length ("+t.bin.byteLength+")"),n._data=Promise.resolve(t.bin)}else e.Tools.Warn("Unexpected BIN chunk")}},r.prototype._setupData=function(){if(t.ArrayItem.Assign(this._gltf.accessors),t.ArrayItem.Assign(this._gltf.animations),t.ArrayItem.Assign(this._gltf.buffers),t.ArrayItem.Assign(this._gltf.bufferViews),t.ArrayItem.Assign(this._gltf.cameras),t.ArrayItem.Assign(this._gltf.images),t.ArrayItem.Assign(this._gltf.materials),t.ArrayItem.Assign(this._gltf.meshes),t.ArrayItem.Assign(this._gltf.nodes),t.ArrayItem.Assign(this._gltf.samplers),t.ArrayItem.Assign(this._gltf.scenes),t.ArrayItem.Assign(this._gltf.skins),t.ArrayItem.Assign(this._gltf.textures),this._gltf.nodes){for(var e={},r=0,n=this._gltf.nodes;r=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},o})(t.GLTFLoaderExtension);r.MSFT_lod=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n="KHR_materials_pbrSpecularGlossiness",o=(function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=n,e}return __extends(r,t),r.prototype._loadMaterialAsync=function(e,t,r){var n=this;return this._loadExtensionAsync(e,t,(function(e,o){if(t._babylonMeshes=t._babylonMeshes||[],t._babylonMeshes.push(r),t._loaded)return r.material=t._babylonMaterial,t._loaded;var a=new Array,i=n._loader._createMaterial(t);return t._babylonMaterial=i,a.push(n._loader._loadMaterialBasePropertiesAsync(e,t)),a.push(n._loadSpecularGlossinessPropertiesAsync(n._loader,e,t,o)),n._loader.onMaterialLoadedObservable.notifyObservers(i),r.material=i,t._loaded=Promise.all(a).then((function(){}))}))},r.prototype._loadSpecularGlossinessPropertiesAsync=function(t,r,n,o){var a=new Array,i=n._babylonMaterial;return o.diffuseFactor?(i.albedoColor=e.Color3.FromArray(o.diffuseFactor),i.alpha=o.diffuseFactor[3]):i.albedoColor=e.Color3.White(),i.reflectivityColor=o.specularFactor?e.Color3.FromArray(o.specularFactor):e.Color3.White(),i.microSurface=void 0==o.glossinessFactor?1:o.glossinessFactor,o.diffuseTexture&&a.push(t._loadTextureAsync(r+"/diffuseTexture",o.diffuseTexture,(function(e){i.albedoTexture=e}))),o.specularGlossinessTexture&&(a.push(t._loadTextureAsync(r+"/specularGlossinessTexture",o.specularGlossinessTexture,(function(e){i.reflectivityTexture=e}))),i.reflectivityTexture.hasAlpha=!0,i.useMicroSurfaceFromReflectivityMapAlpha=!0),t._loadMaterialAlphaProperties(r,n),Promise.all(a).then((function(){}))},r})(t.GLTFLoaderExtension);r.KHR_materials_pbrSpecularGlossiness=o,t.GLTFLoader._Register(n,(function(e){return new o(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){!(function(r){var n,o="KHR_lights";!(function(e){e.AMBIENT="ambient",e.DIRECTIONAL="directional",e.POINT="point",e.SPOT="spot"})(n||(n={}));var a=(function(r){function a(){var e=null!==r&&r.apply(this,arguments)||this;return e.name=o,e}return __extends(a,r),a.prototype._loadSceneAsync=function(r,o){var a=this;return this._loadExtensionAsync(r,o,(function(r,i){var s=a._loader._loadSceneAsync(r,o),l=t.GLTFLoader._GetProperty(r,a._lights,i.light);if(l.type!==n.AMBIENT)throw new Error(r+": Only ambient lights are allowed on a scene");return a._loader._babylonScene.ambientColor=l.color?e.Color3.FromArray(l.color):e.Color3.Black(),s}))},a.prototype._loadNodeAsync=function(r,o){var a=this;return this._loadExtensionAsync(r,o,(function(r,i){var s,l=a._loader._loadNodeAsync(r,o),u=t.GLTFLoader._GetProperty(r,a._lights,i.light),c=o._babylonMesh.name;switch(u.type){case n.AMBIENT:throw new Error(r+": Ambient lights are not allowed on a node");case n.DIRECTIONAL:s=new e.DirectionalLight(c,e.Vector3.Forward(),a._loader._babylonScene);break;case n.POINT:s=new e.PointLight(c,e.Vector3.Zero(),a._loader._babylonScene);break;case n.SPOT:var d=u,f=d.outerConeAngle||Math.PI/4;s=new e.SpotLight(c,e.Vector3.Zero(),e.Vector3.Forward(),f,2,a._loader._babylonScene);break;default:throw new Error(r+": Invalid light type "+u.type)}return s.diffuse=u.color?e.Color3.FromArray(u.color):e.Color3.White(),s.intensity=void 0==u.intensity?1:u.intensity,s.parent=o._babylonMesh,l}))},Object.defineProperty(a.prototype,"_lights",{get:function(){var e=this._loader._gltf.extensions;if(!e||!e[this.name])throw new Error("#/extensions: "+this.name+" not found");return e[this.name].lights},enumerable:!0,configurable:!0}),a})(t.GLTFLoaderExtension);r.KHR_lights=a,t.GLTFLoader._Register(o,(function(e){return new a(e)}))})(t.Extensions||(t.Extensions={}))})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={})),(function(e,t){var r=t();e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=r:"function"==typeof define&&define.amd?define(["BJSLoaders"],t):"object"==typeof exports?exports.BJSLoaders=r:e.BABYLON=r)})(this,(function(){return BABYLON}));