var BABYLON=BABYLON||"undefined"!=typeof require&&require("babylonjs"),__decorate=this&&this.__decorate||function(e,t,n,r){var a,o=arguments.length,i=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(a=e[s])&&(i=(o<3?a(i):o>3?a(t,n,i):a(t,n))||i);return o>3&&i&&Object.defineProperty(t,n,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 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){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,n,r,a,o,i,s){var l;if(this.isBinary(r)){var u=new e.Mesh("stlmesh",n);return this.parseBinary(u,r),o&&o.push(u),!0}for(var c=new Uint8Array(r),f="",d=0;d127)return!0;return!1},t.prototype.parseBinary=function(t,n){for(var r=new DataView(n),a=r.getUint32(80,!0),o=0,i=new Float32Array(3*a*3),s=new Float32Array(3*a*3),l=new Uint32Array(3*a),u=0,c=0;c=0?u.substring(0,c):u;f=f.toLowerCase();var d=c>=0?u.substring(c+1).trim():"";"newmtl"===f?(i&&this.materials.push(i),i=new e.StandardMaterial(d,n)):"kd"===f?(o=d.split(/\s+/,3).map(parseFloat),i.diffuseColor=e.Color3.FromArray(o)):"ka"===f?(o=d.split(/\s+/,3).map(parseFloat),i.ambientColor=e.Color3.FromArray(o)):"ks"===f?(o=d.split(/\s+/,3).map(parseFloat),i.specularColor=e.Color3.FromArray(o)):"ke"===f?(o=d.split(/\s+/,3).map(parseFloat),i.emissiveColor=e.Color3.FromArray(o)):"ns"===f?i.specularPower=parseFloat(d):"d"===f?i.alpha=parseFloat(d):"map_ka"===f?i.ambientTexture=t._getTexture(a,d,n):"map_kd"===f?i.diffuseTexture=t._getTexture(a,d,n):"map_ks"===f?i.specularTexture=t._getTexture(a,d,n):"map_ns"===f||("map_bump"===f?i.bumpTexture=t._getTexture(a,d,n):"map_d"===f&&(i.opacityTexture=t._getTexture(a,d,n)))}}this.materials.push(i)}}return t._getTexture=function(t,n,r){if(!n)return null;var a=t;if("file:"===t){var o=n.lastIndexOf("\\");-1===o&&(o=n.lastIndexOf("/")),a+=o>-1?n.substr(o+1):n}else a+=n;return new e.Texture(a,r)},t})();e.MTLFileLoader=t;var n=(function(){function n(){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 n.prototype._loadMTL=function(t,n,r){var a=e.Tools.BaseUrl+n+t;e.Tools.LoadFile(a,r,null,null,!1,(function(){console.warn("Error - Unable to load "+a)}))},n.prototype.importMesh=function(e,t,n,r,a,o,i){var s=this._parseSolid(e,t,n,r);return a&&s.forEach((function(e){a.push(e)})),!0},n.prototype.load=function(e,t,n){return this.importMesh(null,e,t,n,null,null,null)},n.prototype._parseSolid=function(r,a,o,i){for(var s,l=[],u=[],c=[],f=[],d=[],h=[],p=[],m=[],T=[],A=0,E=!1,y=[],_=[],g=[],v=[],L="",b="",N=new t,M=1,x=!0,O=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[]});var n=e[t[0]].normals.indexOf(t[1]);return-1===n?-1:e[t[0]].idx[n]},S=function(e,t){e[t[0]]||(e[t[0]]={normals:[],idx:[],uv:[]});var n=e[t[0]].normals.indexOf(t[1]);return 1!=n&&t[2]==e[t[0]].uv[n]?e[t[0]].idx[n]:-1},R=function(e,t,r,a,o,i){var s;s=n.OPTIMIZE_WITH_UV?S(T,[e,r,t]):O(T,[e,r]),-1==s?(d.push(h.length),h.push(a),p.push(o),m.push(i),T[e].normals.push(r),T[e].idx.push(A++),n.OPTIMIZE_WITH_UV&&T[e].uv.push(t)):d.push(s)},F=function(){for(var e=0;e0&&(s=f[f.length-1],F(),d.reverse(),s.indices=d.slice(),s.positions=y.slice(),s.normals=_.slice(),s.uvs=g.slice(),d=[],y=[],_=[],g=[])},P=o.split("\n"),C=0;C-1;)o.push(n),r=n+1;if(-1==n&&0==o.length)N.materials[t].dispose();else for(var s=0;s0)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.major?1:e.majort.minor?1:e.minor=this._maxPos},e})(),a=["MODEL","VIEW","PROJECTION","MODELVIEW","MODELVIEWPROJECTION","JOINTMATRIX"],o=["world","view","projection","worldView","worldViewProjection","mBones"],i=["translation","rotation","scale"],s=["position","rotationQuaternion","scaling"],l=function(e,t){for(var n in e){var r=e[n];t.buffers[n]=r,t.buffersCount++}},u=function(e,t){for(var n in e){var r=e[n];t.shaders[n]=r,t.shaderscount++}},c=function(e,t,n){for(var r in e){var a=e[r];n[t][r]=a}},f=function(e){if(e)for(var t=0;t0&&(_=T(l,i))&&-1===u.indexOf(_)&&u.push(_);new e.Bone(d.jointName,o,_,N).id=i}}else e.Tools.Warn("Joint named "+r.jointNames[c]+" does not exist")}var M=o.bones;o.bones=[];for(var c=0;c0&&-1===t.importMeshesNames.indexOf(n.name))return null;if(n.skin){if(n.meshes){var i=t.skins[n.skin],s=g(t,n,n.meshes,r,n.babylonNode);s.skeleton=t.scene.getLastSkeletonByID(n.skin),null===s.skeleton&&(s.skeleton=_(t,i,0,i.babylonSkeleton,n.skin),i.babylonSkeleton||(i.babylonSkeleton=s.skeleton)),o=s}}else if(n.meshes){var s=g(t,n,n.mesh?[n.mesh]:n.meshes,r,n.babylonNode);o=s}else if(!n.light||n.babylonNode||t.importOnlyMeshes){if(n.camera&&!n.babylonNode&&!t.importOnlyMeshes){var l=t.cameras[n.camera];if(l)if("orthographic"===l.type){var u=(l[l.type],new e.FreeCamera(n.camera,e.Vector3.Zero(),t.scene));u.name=n.name,u.mode=e.Camera.ORTHOGRAPHIC_CAMERA,u.attachControl(t.scene.getEngine().getRenderingCanvas()),o=u}else if("perspective"===l.type){var c=l[l.type],f=new e.FreeCamera(n.camera,e.Vector3.Zero(),t.scene);f.name=n.name,f.attachControl(t.scene.getEngine().getRenderingCanvas()),c.aspectRatio||(c.aspectRatio=t.scene.getEngine().getRenderWidth()/t.scene.getEngine().getRenderHeight()),c.znear&&c.zfar&&(f.maxZ=c.zfar,f.minZ=c.znear),o=f}}}else{var d=t.lights[n.light];if(d)if("ambient"===d.type){var h=d[d.type],p=new e.HemisphericLight(n.light,e.Vector3.Zero(),t.scene);p.name=n.name,h.color&&(p.diffuse=e.Color3.FromArray(h.color)),o=p}else if("directional"===d.type){var m=d[d.type],T=new e.DirectionalLight(n.light,e.Vector3.Zero(),t.scene);T.name=n.name,m.color&&(T.diffuse=e.Color3.FromArray(m.color)),o=T}else if("point"===d.type){var A=d[d.type],E=new e.PointLight(n.light,e.Vector3.Zero(),t.scene);E.name=n.name,A.color&&(E.diffuse=e.Color3.FromArray(A.color)),o=E}else if("spot"===d.type){var y=d[d.type],b=new e.SpotLight(n.light,e.Vector3.Zero(),e.Vector3.Zero(),0,0,t.scene);b.name=n.name,y.color&&(b.diffuse=e.Color3.FromArray(y.color)),y.fallOfAngle&&(b.angle=y.fallOfAngle),y.fallOffExponent&&(b.exponent=y.fallOffExponent),o=b}}if(!n.jointName){if(n.babylonNode)return n.babylonNode;if(null===o){var N=new e.Mesh(n.name,t.scene);n.babylonNode=N,o=N}}if(null!==o){if(n.matrix&&o instanceof e.Mesh)L(o,n);else{var M=n.translation||[0,0,0],x=n.rotation||[0,0,0,1],O=n.scale||[1,1,1];v(o,e.Vector3.FromArray(M),e.Quaternion.FromArray(x),e.Vector3.FromArray(O))}o.updateCache(!0),n.babylonNode=o}return o},N=function(e,t,n,r){var a=e.nodes[t],o=null;if(r=!(e.importOnlyMeshes&&!r)||(-1!==e.importMeshesNames.indexOf(a.name)||0===e.importMeshesNames.length),!a.jointName&&r&&null!==(o=b(e,a,t))&&(o.id=t,o.parent=n),a.children)for(var i=0;ii.byteLength)throw new Error("Buffer access is out of range");var s=i.buffer;switch(r+=i.byteOffset,o){case t.EComponentType.BYTE:return new Int8Array(s,r,a);case t.EComponentType.UNSIGNED_BYTE:return new Uint8Array(s,r,a);case t.EComponentType.SHORT:return new Int16Array(s,r,a);case t.EComponentType.UNSIGNED_SHORT:return new Uint16Array(s,r,a);default:return new Float32Array(s,r,a)}},n.GetBufferFromAccessor=function(e,t){var r=e.bufferViews[t.bufferView],a=t.count*n.GetByteStrideFromType(t);return n.GetBufferFromBufferView(e,r,t.byteOffset,a,t.componentType)},n.DecodeBufferToText=function(e){for(var t="",n=e.byteLength,r=0;rl.byteLength)return void s._onError("Buffer access is out of range");var u=l.buffer;n+=l.byteOffset;var c;switch(o){case t.EComponentType.BYTE:c=s._buildInt8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_BYTE:c=s._buildUint8ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.SHORT:c=s._buildInt16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_SHORT:c=s._buildUint16ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.UNSIGNED_INT:c=s._buildUint32ArrayBuffer(u,n,r,e.byteStride,a);break;case t.EComponentType.FLOAT:c=s._buildFloat32ArrayBuffer(u,n,r,e.byteStride,a);break;default:return void s._onError("Invalid component type ("+o+")")}i(c)}))},n.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)},n.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}},Object.defineProperty(n.prototype,"blockPendingTracking",{set:function(e){this._blockPendingTracking=e},enumerable:!0,configurable:!0}),n.prototype.addPendingData=function(e){this._renderReady||this._renderPendingCount++,this.addLoaderPendingData(e)},n.prototype.removePendingData=function(e){this._renderReady||0==--this._renderPendingCount&&(this._renderReady=!0,this._onRenderReady()),this.removeLoaderPendingData(e)},n.prototype.addLoaderNonBlockingPendingData=function(e){this._nonBlockingData||(this._nonBlockingData=new Array),this._nonBlockingData.push(e)},n.prototype.addLoaderPendingData=function(e){if(this._blockPendingTracking)return void this.addLoaderNonBlockingPendingData(e);this._loaderPendingCount++},n.prototype.removeLoaderPendingData=function(e){var t=this._nonBlockingData?this._nonBlockingData.indexOf(e):-1;-1!==t?this._nonBlockingData.splice(t,1):0==--this._loaderPendingCount&&this._onLoaderFirstLODComplete(),this._nonBlockingData&&0!==this._nonBlockingData.length||0!==this._loaderPendingCount||(this._onLoaderComplete(),this.dispose())},n.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},n.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))},n.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))},n.prototype.createPbrMaterial=function(t){var n=new e.PBRMaterial(t.name||"mat"+t.index,this._babylonScene);n.sideOrientation=e.Material.CounterClockWiseSideOrientation,t.babylonMaterial=n},n.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))},n.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},n.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 c=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)c.updateURL(a.url);else if(a.dataReadyObservable)a.dataReadyObservable.add((function(e){c.updateURL(e.url)}));else{a.dataReadyObservable=new e.Observable,a.dataReadyObservable.add((function(e){c.updateURL(e.url)}));var f=function(e){a.url=URL.createObjectURL(new Blob([e],{type:i.mimeType})),a.dataReadyObservable.notifyObservers(a)};if(i.uri)t.GLTFUtils.IsBase64(i.uri)?f(new Uint8Array(t.GLTFUtils.DecodeBase64(i.uri))):e.Tools.LoadFile(this._rootUrl+i.uri,f,(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 d=this._gltf.bufferViews[i.bufferView];this._loadBufferViewAsync(d,0,d.byteLength,1,t.EComponentType.UNSIGNED_BYTE,f)}}return c.coordinatesIndex=o,c.wrapU=t.GLTFUtils.GetTextureWrapMode(s.wrapS),c.wrapV=t.GLTFUtils.GetTextureWrapMode(s.wrapT),c.name=a.name||"texture"+n.index,this._parent.onTextureLoaded&&this._parent.onTextureLoaded(c),c},n.Extensions={},n})();t.GLTFLoader=n,e.GLTFFileLoader.CreateGLTFLoaderV2=function(e){return new n(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