!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.SERIALIZERS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=14)}([function(t,r){t.exports=e},function(e,t,r){"use strict";r.d(t,"a",(function(){return a}));var n=r(0),a=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,a){var o={buffer:e,byteLength:r};return t&&(o.byteOffset=t),a&&(o.name=a),n&&(o.byteStride=n),o},e._CreateAccessor=function(e,t,r,n,a,o,i,s){var u={name:t,bufferView:e,componentType:n,count:a,type:r};return null!=i&&(u.min=i),null!=s&&(u.max=s),null!=o&&(u.byteOffset=o),u},e._CalculateMinMaxPositions=function(t,r,a,o){var i,s,u,l=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(a)for(var f=r,h=r+a;fc[p]&&(c[p]=d),++i}}return{min:l,max:c}},e._GetRightHandedPositionVector3=function(e){return new n.Vector3(e.x,e.y,-e.z)},e._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},e._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedNormalVector3=function(e){return new n.Vector3(e.x,e.y,-e.z)},e._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},e._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},e._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},e._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},e._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},e._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},e._NormalizeTangentFromRef=function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);t>0&&(e.x/=t,e.y/=t,e.z/=t)},e._GetRightHandedMatrixFromRef=function(e){var t=e.m;n.Matrix.FromValuesToRef(t[0],t[1],-t[2],t[3],t[4],t[5],-t[6],t[7],-t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15],e)},e._GetDataAccessorElementCount=function(e){switch(e){case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16;case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":return 4}},e}()},function(e,t,r){"use strict";r.d(t,"b",(function(){return l})),r.d(t,"a",(function(){return c}));var n=r(3),a=r(0),o=r(11),i=r(1),s=r(4),u=r(8),l=function(){function e(e,t){this._includeCoordinateSystemConversionNodes=!1,this._extensions={},this._glTF={asset:{generator:"BabylonJS",version:"2.0"}},this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._skins=[],this._animations=[],this._imageData={},this._orderedImageData=[],this._options=t||{},this._animationSampleRate=t&&t.animationSampleRate?t.animationSampleRate:1/60,this._includeCoordinateSystemConversionNodes=!(!t||!t.includeCoordinateSystemConversionNodes),this._glTFMaterialExporter=new o.a(this),this._loadExtensions()}return e.prototype._applyExtension=function(e,t,r,n){var a=this;if(r>=t.length)return Promise.resolve(e);var o=n(t[r],e);return o?o.then((function(e){return a._applyExtension(e,t,r+1,n)})):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],a=0,o=e._ExtensionNames;a=f;--i)o.setUInt32(r[i],n),n+=4;break;case a.Material.TriangleStripDrawMode:e.indexCount>=3&&(o.setUInt32(r[e.indexStart+2],n+4),o.setUInt32(r[e.indexStart+1],n+8))}},e.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,o,i,s,u){if(u&&r===a.Material.ClockWiseSideOrientation)switch(t){case a.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,n,o,i,s,u);break;case a.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,n,o,i,s,u);break;case a.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,n,o,i,s,u)}},e.prototype.reorderTriangleFillMode=function(e,t,r,n,o,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/a.VertexBuffer.GetTypeByteLength(l.type);if(e.verticesCount%3!=0)a.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var f=[],h=0;switch(n){case a.VertexBuffer.PositionKind:case a.VertexBuffer.NormalKind:for(var p=e.verticesStart;p=e.verticesStart;--p)h=p*c,f.push(a.Vector4.FromArray(o,h));break;case a.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,4===l.getSize()?f.push(a.Vector4.FromArray(o,h)):f.push(a.Vector3.FromArray(o,h));break;case a.VertexBuffer.UVKind:case a.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector2.FromArray(o,h));break;default:a.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(f,i+12,n,o,s,u)}else a.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+n+" not present!")},e.prototype.reorderTriangleFanMode=function(e,t,r,n,o,i,s,u){var l=this.getVertexBufferFromMesh(n,e.getMesh());if(l){var c=l.byteStride/a.VertexBuffer.GetTypeByteLength(l.type),f=[],h=0;switch(n){case a.VertexBuffer.PositionKind:case a.VertexBuffer.NormalKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector3.FromArray(o,h));break;case a.VertexBuffer.TangentKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector4.FromArray(o,h));break;case a.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector4.FromArray(o,h)),4===l.getSize()?f.push(a.Vector4.FromArray(o,h)):f.push(a.Vector3.FromArray(o,h));break;case a.VertexBuffer.UVKind:case a.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(a.Vector2.FromArray(o,h));break;default:a.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(f,i,n,o,s,u)}else a.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+n+" not present!")},e.prototype.writeVertexAttributeData=function(e,t,r,n,o,s){for(var u=0,l=e;u0){var k=null!==c.overrideMaterialSideOrientation?c.overrideMaterialSideOrientation:V.sideOrientation;if(k==a.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||k==a.Material.ClockWiseSideOrientation&&n&&c.overrideMaterialSideOrientation!==(null===(o=c.material)||void 0===o?void 0:o.sideOrientation)){var D=null!=h?this._bufferViews[h].byteOffset:null;null==D&&(D=0);var K=null;if(null!=h&&(K=c.getIndices()),K)this.reorderIndicesBasedOnPrimitiveMode(R,p,K,D,r);else for(var U=0,H=f;Ua.Epsilon)return!1;return!(e instanceof a.Mesh&&null!==e.geometry||e instanceof a.InstancedMesh&&null!==e.sourceMesh.geometry)&&!this._includeCoordinateSystemConversionNodes}return!1},e.prototype.createSceneAsync=function(e,t){var r,o,i,s=this,u={nodes:[]},l=Object(n.c)(e.transformNodes,e.meshes,e.lights),c=[];return this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.rootNodes.forEach((function(e){s._convertToRightHandedSystemMap[e.uniqueId]=s._convertToRightHandedSystem,e.getDescendants(!1).forEach((function(e){s._convertToRightHandedSystemMap[e.uniqueId]=s._convertToRightHandedSystem}))})),e.rootNodes.forEach((function(e){if(s.isBabylonCoordinateSystemConvertingNode(e)){c.push(e);var t=l.indexOf(e);-1!==t&&l.splice(t,1),e.getDescendants(!1).forEach((function(e){s._convertToRightHandedSystemMap[e.uniqueId]=!1}))}})),this._glTFMaterialExporter._convertMaterialsToGLTFAsync(e.materials,"image/png",!0).then((function(){return s.createNodeMapAndAnimationsAsync(e,l,t).then((function(n){return s.createSkinsAsync(e,n,t).then((function(e){if(s._nodeMap=n,s._totalByteLength=t.getByteOffset(),null==s._totalByteLength)throw new Error("undefined byte length!");for(var f=0,h=l;f0){i.weights=[];for(var u=0;u-1&&(c[h]=g),f=Math.max(f,h)}for(var m=0;m<=f;++m){var g,_=(g=c[m]).getTransformNode();if(_){var x=g.getInvertedAbsoluteTransform();s._convertToRightHandedSystem&&i.a._GetRightHandedMatrixFromRef(x),u.push(x),o.joints.push(t[_.uniqueId])}}var y=64*u.length,T=r.getByteOffset(),v=i.a._CreateBufferView(0,T,y,64,"InverseBindMatrices - "+n.name);s._bufferViews.push(v);var b=s._bufferViews.length-1,A=i.a._CreateAccessor(b,"InverseBindMatrices - "+n.name,"MAT4",5126,u.length,null,null,null),F=s._accessors.push(A)-1;o.inverseBindMatrices=F,s._skins.push(o),a[n.uniqueId]=s._skins.length-1,u.forEach((function(e){e.m.forEach((function(e){r.setFloat32(e)}))}))},s=this,u=0,l=e.skeletons;uthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset,e),this._byteOffset+=1)},e.prototype.setUInt16=function(e,t){null!=t?tthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint16(this._byteOffset,e,!0),this._byteOffset+=2)},e.prototype.getUInt32=function(e){if(ethis._byteOffset?a.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0))},e.prototype.setVector3Float32FromRef=function(e,t){t+8>this._byteOffset?a.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0))},e.prototype.getVector4Float32FromRef=function(e,t){t+12>this._byteOffset?a.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(e.x=this._dataView.getFloat32(t,!0),e.y=this._dataView.getFloat32(t+4,!0),e.z=this._dataView.getFloat32(t+8,!0),e.w=this._dataView.getFloat32(t+12,!0))},e.prototype.setVector4Float32FromRef=function(e,t){t+12>this._byteOffset?a.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(t,e.x,!0),this._dataView.setFloat32(t+4,e.y,!0),this._dataView.setFloat32(t+8,e.z,!0),this._dataView.setFloat32(t+12,e.w,!0))},e.prototype.setFloat32=function(e,t){isNaN(e)&&a.Tools.Error("Invalid data being written!"),null!=t&&(tthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,e,!0),this._byteOffset+=4},e.prototype.setUInt32=function(e,t){null!=t?tthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,e,!0),this._byteOffset+=4)},e}()},function(e,t,r){"use strict";r.d(t,"a",(function(){return n})),r.d(t,"b",(function(){return a})),r.d(t,"c",(function(){return o}));function n(e,t,r,n){return new(r||(r=Promise))((function(a,o){function i(e){try{u(n.next(e))}catch(e){o(e)}}function s(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((n=n.apply(e,t||[])).next())}))}function a(e,t){var r,n,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(a=2&o[0]?n.return:o[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;switch(n=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,n=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]0;)M=A.inputs.shift(),F%m==0&&E.push(M),F++;A.inputs=E}var R=u[n.uniqueId],V=4*A.inputs.length;g=o.a._CreateBufferView(0,l.getByteOffset(),V,void 0,t+" keyframe data view"),c.push(g),A.inputs.forEach((function(e){l.setFloat32(e)})),_=o.a._CreateAccessor(c.length-1,t+" keyframes","SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),f.push(_),x=f.length-1,T=A.outputs.length,V=4*o.a._GetDataAccessorElementCount(i)*A.outputs.length,g=o.a._CreateBufferView(0,l.getByteOffset(),V,void 0,t+" data view"),c.push(g),A.outputs.forEach((function(e){e.forEach((function(e){l.setFloat32(e)}))})),_=o.a._CreateAccessor(c.length-1,t+" data",i,5126,T,null,null,null),f.push(_),y=f.length-1,v={interpolation:A.samplerInterpolation,input:x,output:y},r.samplers.push(v),b={sampler:r.samplers.length-1,target:{node:R,path:s}},r.channels.push(b)}},e._CreateBakedAnimation=function(t,r,n,o,i,s,u,l,c,f,h,p){var d,m,g=a.Quaternion.Identity(),_=null,x=null,y=null,T=null,v=null,b=null;f.min=a.Tools.FloatRound(o/s);for(var A=r.getKeys(),F=0,M=A.length;F-1&&(this._textureInfos[n]=t)},e.prototype.postExportMaterialAdditionalTextures=function(e,t,r){return r instanceof n.PBRMaterial&&r.sheen.isEnabled&&r.sheen.texture?(this._exportedTextures.push(r.sheen.texture),[r.sheen.texture]):[]},e.prototype.postExportMaterialAsync=function(e,t,r){var a=this;return new Promise((function(e,o){var i;if(r instanceof n.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);a._wasUsed=!0,null==t.extensions&&(t.extensions={});var s={sheenColorFactor:r.sheen.color.asArray(),sheenRoughnessFactor:null!==(i=r.sheen.roughness)&&void 0!==i?i:0};if(r.sheen.texture)(u=a._getTextureIndex(r.sheen.texture))>-1&&(s.sheenColorTexture=a._textureInfos[u]);if(r.sheen.textureRoughness&&!r.sheen.useRoughnessFromMainTexture)(u=a._getTextureIndex(r.sheen.textureRoughness))>-1&&(s.sheenRoughnessTexture=a._textureInfos[u]);else if(r.sheen.texture&&r.sheen.useRoughnessFromMainTexture){var u;(u=a._getTextureIndex(r.sheen.texture))>-1&&(s.sheenRoughnessTexture=a._textureInfos[u])}t.extensions.KHR_materials_sheen=s}e(t)}))},e}();a.b.RegisterExtension("KHR_materials_sheen",(function(e){return new c(e)}));var f=function(){function e(e){this.name="KHR_materials_unlit",this.enabled=!0,this.required=!1,this._wasUsed=!1}return Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!1,configurable:!0}),e.prototype.dispose=function(){},e.prototype.postExportMaterialAsync=function(e,t,r){var a=this;return new Promise((function(e,o){var i=!1;r instanceof n.PBRMaterial?i=r.unlit:r instanceof n.StandardMaterial&&(i=r.disableLighting),i&&(a._wasUsed=!0,null==t.extensions&&(t.extensions={}),t.extensions.KHR_materials_unlit={}),e(t)}))},e}();a.b.RegisterExtension("KHR_materials_unlit",(function(e){return new f(e)}))},function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n=r(3),a=r(0),o=function(){function e(e){this._textureMap={},this._textureMap={},this._exporter=e}return e.FuzzyEquals=function(e,t,r){return a.Scalar.WithinEpsilon(e.r,t.r,r)&&a.Scalar.WithinEpsilon(e.g,t.g,r)&&a.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){for(var n=[],o=0,i=e;os.width?(o=t&&t instanceof a.Texture?a.TextureTools.CreateResizedCopy(t,i.width,i.height,!0):this._createWhiteTexture(i.width,i.height,r),n=e):(n=e,o=t),{texture1:n,texture2:o}},e.prototype._convertPixelArrayToFloat32=function(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;ne._Epsilon?S.baseColor.r:1,y[P+1]/=S.baseColor.g>e._Epsilon?S.baseColor.g:1,y[P+2]/=S.baseColor.b>e._Epsilon?S.baseColor.b:1,N=a.Color3.FromInts(y[P],y[P+1],y[P+2]),L=N.toGammaSpace(),y[P]=255*L.r,y[P+1]=255*L.g,y[P+2]=255*L.b,e.FuzzyEquals(L,a.Color3.White(),e._Epsilon)||(C=!0),x[P+1]/=S.roughness>e._Epsilon?S.roughness:1,x[P+2]/=S.metallic>e._Epsilon?S.metallic:1,O=a.Color3.FromInts(255,x[P+1],x[P+2]),e.FuzzyEquals(O,a.Color3.White(),e._Epsilon)||(w=!0);return w&&(G=this._createBase64FromCanvasAsync(x,p,d,i).then((function(e){S.metallicRoughnessTextureBase64=e})),s.push(G)),C&&(G=this._createBase64FromCanvasAsync(y,p,d,i).then((function(e){S.baseColorTextureBase64=e})),s.push(G)),[2,Promise.all(s).then((function(){return S}))];case 3:return[2,Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")]}}))}))},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),n=this._getPerceivedBrightness(t.specularColor),o=1-this._getMaxComponent(t.specularColor),i=e._SolveMetallic(r,n,o),s=t.diffuseColor.scale(o/(1-e._DielectricSpecular.r)/Math.max(1-i,e._Epsilon)),u=t.specularColor.subtract(e._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,e._Epsilon)),l=a.Color3.Lerp(s,u,i*i);return{baseColor:l=l.clampToRef(0,1,l),metallic:i,roughness:1-t.glossiness}},e.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},e.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},e.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var a=[],o={baseColor:e.albedoColor||e.baseColor,metallic:e.metallic||e.metallic,roughness:e.roughness||e.roughness};if(n){(e.albedoTexture||e.baseTexture)&&a.push(this._exportTextureAsync(e.albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)})));var i=e.metallicTexture||e.metallicRoughnessTexture;i&&a.push(this._exportTextureAsync(i,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))}return Promise.all(a).then((function(){return o}))},e.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof a.Texture?e.samplingMode:null;if(null!=r)switch(r){case a.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case a.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case a.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case a.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case a.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case a.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case a.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case a.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case a.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case a.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case a.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case a.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case a.Texture.WRAP_ADDRESSMODE:return 10497;case a.Texture.CLAMP_ADDRESSMODE:return 33071;case a.Texture.MIRROR_ADDRESSMODE:return 33648;default:return a.Tools.Error("Unsupported Texture Wrap Mode "+e+"!"),10497}},e.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof a.Texture?e.wrapU:a.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof a.Texture?e.wrapV:a.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,n){var o=this;return Promise.resolve().then((function(){var i=o._exporter._samplers,s=o._exporter._textures,u={diffuseColor:e.albedoColor||e.diffuseColor||a.Color3.White(),specularColor:e.reflectivityColor||e.specularColor||a.Color3.White(),glossiness:e.microSurface||e.glossiness||1},l=null,c=e.albedoTexture||e.diffuseTexture,f=e.reflectivityTexture||e.specularGlossinessTexture,h=o._getGLTFTextureSampler(c);null!=h.magFilter&&null!=h.minFilter&&null!=h.wrapS&&null!=h.wrapT&&(i.push(h),l=i.length-1);var p=e.useMicroSurfaceFromReflectivityMapAlpha||e.useMicroSurfaceFromReflectivityMapAlpha;return f&&!p?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(c||f)&&n?o._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(c,f,u,t).then((function(e){if(e.baseColorTextureBase64){var n=o._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",t,c?c.coordinatesIndex:null,l);n&&(r.baseColorTexture=n)}if(e.metallicRoughnessTextureBase64){var a=o._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",t,f?f.coordinatesIndex:null,l);a&&(r.metallicRoughnessTexture=a)}return e})):o._convertSpecularGlossinessToMetallicRoughness(u)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},o={name:e.name};if(e.isMetallicWorkflow()){var i=e.albedoColor||e.diffuseColor||e.baseColor,s=e.alpha;return i&&(a.baseColorFactor=[i.r,i.g,i.b,s]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,o,a,t,r)}))}return this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(i){return n.setMetallicRoughnessPbrMaterial(i,e,o,a,t,r)}))},e.prototype.setMetallicRoughnessPbrMaterial=function(t,r,n,o,i,s){var u=this._exporter._materialMap,l=this._exporter._materials,c=[];if(t){if(e._SetAlphaMode(n,r),e.FuzzyEquals(t.baseColor,a.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(o.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(o.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(o.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||r.doubleSided||a.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),s){var f=r.bumpTexture||r.normalTexture;if(f){var h=this._exportTextureAsync(f,i).then((function(e){e&&(n.normalTexture=e,1!==f.level&&(n.normalTexture.scale=f.level))}));c.push(h)}var p=r.ambientTexture||r.occlusionTexture;if(p){h=this._exportTextureAsync(p,i).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord};n.occlusionTexture=t;var a=r.ambientTextureStrength||r.occlusionStrength;a&&(t.strength=a)}}));c.push(h)}var d=r.emissiveTexture||r.emissiveTexture;if(d){h=this._exportTextureAsync(d,i).then((function(e){e&&(n.emissiveTexture=e)}));c.push(h)}}var m=r.emissiveColor||r.emissiveColor;e.FuzzyEquals(m,a.Color3.Black(),e._Epsilon)||(n.emissiveFactor=m.asArray()),n.pbrMetallicRoughness=o,l.push(n),u[r.uniqueId]=l.length-1}return this._finishMaterial(c,n,r,i)},e.prototype.getPixelsFromTexture=function(e){return e.textureType,a.Constants.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},e.prototype._exportTextureAsync=function(e,t){var r=this,n=this._exporter._extensionsPreExportTextureAsync("exporter",e,t);return n?n.then((function(n){return n?r._exportTextureInfoAsync(n,t):r._exportTextureInfoAsync(e,t)})):this._exportTextureInfoAsync(e,t)},e.prototype._exportTextureInfoAsync=function(e,t){var r=this;return Promise.resolve().then((function(){return Object(n.a)(r,void 0,void 0,(function(){var r,a,o,i,s,u,l,c,f,h=this;return Object(n.b)(this,(function(n){switch(n.label){case 0:return(r=e.uid)in this._textureMap?[2,this._textureMap[r]]:[3,1];case 1:return[4,this.getPixelsFromTexture(e)];case 2:if(!(a=n.sent()))return[2,null];for(o=this._exporter._samplers,i=this._getGLTFTextureSampler(e),s=null,u=null,l=0;l-1||(l.GLTF2.Exporter[f]=s[f])}}.call(this,r(12))}])}));