!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=13)}([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 i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),a&&(i.name=a),n&&(i.byteStride=n),i},e._CreateAccessor=function(e,t,r,n,a,i,o,s){var u={name:t,bufferView:e,componentType:n,count:a,type:r};return null!=o&&(u.min=o),null!=s&&(u.max=s),null!=i&&(u.byteOffset=i),u},e._CalculateMinMaxPositions=function(t,r,a,i){var o,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),++o}}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 u})),r.d(t,"a",(function(){return l}));Object.create;Object.create;var n=r(0),a=r(10),i=r(1),o=r(3),s=r(7),u=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 a.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 i=n(t[r],e);return i?i.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,i=e._ExtensionNames;a=f;--o)i.setUInt32(r[o],a),a+=4;break;case n.Material.TriangleStripDrawMode:e.indexCount>=3&&(i.setUInt32(r[e.indexStart+2],a+4),i.setUInt32(r[e.indexStart+1],a+8))}},e.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,a,i,o,s,u){if(u&&r===n.Material.ClockWiseSideOrientation)switch(t){case n.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,a,i,o,s,u);break;case n.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,a,i,o,s,u);break;case n.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,a,i,o,s,u)}},e.prototype.reorderTriangleFillMode=function(e,t,r,a,i,o,s,u){var l=this.getVertexBufferFromMesh(a,e.getMesh());if(l){var c=l.byteStride/n.VertexBuffer.GetTypeByteLength(l.type);if(e.verticesCount%3!=0)n.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var f=[],h=0;switch(a){case n.VertexBuffer.PositionKind:case n.VertexBuffer.NormalKind:for(var p=e.verticesStart;p=e.verticesStart;--p)h=p*c,f.push(n.Vector4.FromArray(i,h));break;case n.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,4===l.getSize()?f.push(n.Vector4.FromArray(i,h)):f.push(n.Vector3.FromArray(i,h));break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(n.Vector2.FromArray(i,h));break;default:n.Tools.Error("Unsupported Vertex Buffer type: "+a)}this.writeVertexAttributeData(f,o+12,a,i,s,u)}else n.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+a+" not present!")},e.prototype.reorderTriangleFanMode=function(e,t,r,a,i,o,s,u){var l=this.getVertexBufferFromMesh(a,e.getMesh());if(l){var c=l.byteStride/n.VertexBuffer.GetTypeByteLength(l.type),f=[],h=0;switch(a){case n.VertexBuffer.PositionKind:case n.VertexBuffer.NormalKind:for(var p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(n.Vector3.FromArray(i,h));break;case n.VertexBuffer.TangentKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(n.Vector4.FromArray(i,h));break;case n.VertexBuffer.ColorKind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(n.Vector4.FromArray(i,h)),4===l.getSize()?f.push(n.Vector4.FromArray(i,h)):f.push(n.Vector3.FromArray(i,h));break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:for(p=e.verticesStart+e.verticesCount-1;p>=e.verticesStart;--p)h=p*c,f.push(n.Vector2.FromArray(i,h));break;default:n.Tools.Error("Unsupported Vertex Buffer type: "+a)}this.writeVertexAttributeData(f,o,a,i,s,u)}else n.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+a+" not present!")},e.prototype.writeVertexAttributeData=function(e,t,r,a,o,s){for(var u=0,l=e;u0){var k=null!==c.overrideMaterialSideOrientation?c.overrideMaterialSideOrientation:V.sideOrientation;if(k==n.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||k==n.Material.ClockWiseSideOrientation&&a&&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 U=null;if(null!=h&&(U=c.getIndices()),U)this.reorderIndicesBasedOnPrimitiveMode(R,p,U,D,r);else for(var K=0,H=f;Kn.Epsilon)return!1;return!(e instanceof n.Mesh&&null!==e.geometry||e instanceof n.InstancedMesh&&null!==e.sourceMesh.geometry)&&!this._includeCoordinateSystemConversionNodes}return!1},e.prototype.createSceneAsync=function(e,t){var r,a,i,o=this,s={nodes:[]},u=function(){for(var e=0,t=0,r=arguments.length;t0){o.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?n.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?n.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?n.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?n.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)&&n.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.r(t),r.d(t,"GLTFData",(function(){return n}));var n=function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var n=this.glTFFiles[t],a=void 0;e(t,".glb")?a={type:"model/gltf-binary"}:e(t,".bin")?a={type:"application/octet-stream"}:e(t,".gltf")?a={type:"model/gltf+json"}:e(t,".jpeg")?a={type:"image/jpeg"}:e(t,".png")&&(a={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],a)),r.click()}},e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"__IGLTFExporterExtension",(function(){return n}));var n=0},,function(e,t,r){"use strict";r.r(t),r.d(t,"_GLTFAnimation",(function(){return n.a})),r.d(t,"GLTFData",(function(){return a.GLTFData})),r.d(t,"_Exporter",(function(){return i.b})),r.d(t,"_BinaryWriter",(function(){return i.a})),r.d(t,"__IGLTFExporterExtensionV2",(function(){return o})),r.d(t,"_GLTFMaterialExporter",(function(){return s.a})),r.d(t,"GLTF2Export",(function(){return u.GLTF2Export})),r.d(t,"_GLTFUtilities",(function(){return l.a})),r.d(t,"KHR_texture_transform",(function(){return c.KHR_texture_transform})),r.d(t,"KHR_lights_punctual",(function(){return c.KHR_lights_punctual})),r.d(t,"KHR_materials_sheen",(function(){return c.KHR_materials_sheen})),r.d(t,"KHR_materials_unlit",(function(){return c.KHR_materials_unlit}));var n=r(7),a=r(3),i=r(2),o=0,s=r(10),u=r(8),l=r(1),c=r(9)},function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n,a=r(0),i=r(1);!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(n||(n={}));var o=function(){function e(){}return e._CreateNodeAnimation=function(t,r,n,i,o,s){var u=[],l=[],c=r.getKeys(),f=e.calculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,n,o),p=f.max-f.min,d=h.interpolationType,m=h.shouldBakeAnimation;return m?e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,u,l,f,i,o):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,u,l,i,o):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,u,l,i,o):e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,u,l,f,i,o),u.length&&l.length?{inputs:u,outputs:l,samplerInterpolation:d,inputsMin:m?f.min:a.Tools.FloatRound(f.min/r.framePerSecond),inputsMax:m?f.max:a.Tools.FloatRound(f.max/r.framePerSecond)}:null},e._DeduceAnimationInfo=function(e){var t=null,r="VEC3",n=!1,i=e.targetProperty.split(".");switch(i[0]){case"scaling":t="scale";break;case"position":t="translation";break;case"rotation":r="VEC4",t="rotation";break;case"rotationQuaternion":r="VEC4",n=!0,t="rotation";break;case"influence":r="SCALAR",t="weights";break;default:a.Tools.Error("Unsupported animatable property "+i[0])}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(a.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,i,o,s,u,l,c,f){var h;if(t instanceof a.TransformNode&&t.animations)for(var p=0,d=t.animations;p0;)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=i.a._CreateBufferView(0,l.getByteOffset(),V,void 0,t+" keyframe data view"),c.push(g),A.inputs.forEach((function(e){l.setFloat32(e)})),_=i.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*i.a._GetDataAccessorElementCount(o)*A.outputs.length,g=i.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)}))})),_=i.a._CreateAccessor(c.length-1,t+" data",o,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,i,o,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(i/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,i){var o;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!==(o=r.sheen.roughness)&&void 0!==o?o: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,i){var o=!1;r instanceof n.PBRMaterial?o=r.unlit:r instanceof n.StandardMaterial&&(o=r.disableLighting),o&&(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 a}));var n=r(0),a=function(){function e(e){this._textureMap={},this._textureMap={},this._exporter=e}return e.FuzzyEquals=function(e,t,r){return n.Scalar.WithinEpsilon(e.r,t.r,r)&&n.Scalar.WithinEpsilon(e.g,t.g,r)&&n.Scalar.WithinEpsilon(e.b,t.b,r)},e.prototype._convertMaterialsToGLTFAsync=function(e,t,r){for(var a=[],i=0,o=e;is.width?(i=t&&t instanceof n.Texture?n.TextureTools.CreateResizedCopy(t,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),a=e):(a=e,i=t),{texture1:a,texture2:i}},e.prototype._convertPixelArrayToFloat32=function(e){if(e instanceof Uint8Array){for(var t=e.length,r=new Float32Array(e.length),n=0;ne._Epsilon?R.baseColor.r:1,x[w+1]/=R.baseColor.g>e._Epsilon?R.baseColor.g:1,x[w+2]/=R.baseColor.b>e._Epsilon?R.baseColor.b:1;var C=n.Color3.FromInts(x[w],x[w+1],x[w+2]).toGammaSpace();x[w]=255*C.r,x[w+1]=255*C.g,x[w+2]=255*C.b,e.FuzzyEquals(C,n.Color3.White(),e._Epsilon)||(S=!0),_[w+1]/=R.roughness>e._Epsilon?R.roughness:1,_[w+2]/=R.metallic>e._Epsilon?R.metallic:1;var B=n.Color3.FromInts(255,_[w+1],_[w+2]);e.FuzzyEquals(B,n.Color3.White(),e._Epsilon)||(V=!0)}if(V){var I=this._createBase64FromCanvasAsync(_,h,p,i).then((function(e){R.metallicRoughnessTextureBase64=e}));o.push(I)}if(S){I=this._createBase64FromCanvasAsync(x,h,p,i).then((function(e){R.baseColorTextureBase64=e}));o.push(I)}return Promise.all(o).then((function(){return R}))}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),a=this._getPerceivedBrightness(t.specularColor),i=1-this._getMaxComponent(t.specularColor),o=e._SolveMetallic(r,a,i),s=t.diffuseColor.scale(i/(1-e._DielectricSpecular.r)/Math.max(1-o,e._Epsilon)),u=t.specularColor.subtract(e._DielectricSpecular.scale(1-o)).scale(1/Math.max(o,e._Epsilon)),l=n.Color3.Lerp(s,u,o*o);return{baseColor:l=l.clampToRef(0,1,l),metallic:o,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=[],i={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return n&&(e.albedoTexture&&a.push(this._exportTextureAsync(e.albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),e.metallicTexture&&a.push(this._exportTextureAsync(e.metallicTexture,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),Promise.all(a).then((function(){return i}))},e.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof n.Texture?e.samplingMode:null;if(null!=r)switch(r){case n.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case n.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case n.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case n.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case n.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case n.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case n.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case n.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case n.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case n.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case n.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case n.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},e.prototype._getGLTFTextureWrapMode=function(e){switch(e){case n.Texture.WRAP_ADDRESSMODE:return 10497;case n.Texture.CLAMP_ADDRESSMODE:return 33071;case n.Texture.MIRROR_ADDRESSMODE:return 33648;default:return n.Tools.Error("Unsupported Texture Wrap Mode "+e+"!"),10497}},e.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof n.Texture?e.wrapU:n.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof n.Texture?e.wrapV:n.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},e.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(e,t,r,a){var i=this;return Promise.resolve().then((function(){var o=i._exporter._samplers,s=i._exporter._textures,u={diffuseColor:e.albedoColor||n.Color3.White(),specularColor:e.reflectivityColor||n.Color3.White(),glossiness:e.microSurface||1},l=null,c=i._getGLTFTextureSampler(e.albedoTexture);return null!=c.magFilter&&null!=c.minFilter&&null!=c.wrapS&&null!=c.wrapT&&(o.push(c),l=o.length-1),e.reflectivityTexture&&!e.useMicroSurfaceFromReflectivityMapAlpha?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(e.albedoTexture||e.reflectivityTexture)&&a?i._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e.albedoTexture,e.reflectivityTexture,u,t).then((function(n){if(n.baseColorTextureBase64){var a=i._getTextureInfoFromBase64(n.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",t,e.albedoTexture?e.albedoTexture.coordinatesIndex:null,l);a&&(r.baseColorTexture=a)}if(n.metallicRoughnessTextureBase64){var o=i._getTextureInfoFromBase64(n.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",t,e.reflectivityTexture?e.reflectivityTexture.coordinatesIndex:null,l);o&&(r.metallicRoughnessTexture=o)}return n})):i._convertSpecularGlossinessToMetallicRoughness(u)}))},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,a={},i={name:e.name};return e.isMetallicWorkflow()?(e.albedoColor&&(a.baseColorFactor=[e.albedoColor.r,e.albedoColor.g,e.albedoColor.b,e.alpha]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n.setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))):this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,a,r).then((function(o){return n.setMetallicRoughnessPbrMaterial(o,e,i,a,t,r)}))},e.prototype.setMetallicRoughnessPbrMaterial=function(t,r,a,i,o,s){var u=this._exporter._materialMap,l=this._exporter._materials,c=[];if(t){if(e._SetAlphaMode(a,r),e.FuzzyEquals(t.baseColor,n.Color3.White(),e._Epsilon)&&r.alpha>=e._Epsilon||(i.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,r.alpha]),null!=t.metallic&&1!==t.metallic&&(i.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(i.roughnessFactor=t.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||n.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),a.doubleSided=!0),s){if(r.bumpTexture){var f=this._exportTextureAsync(r.bumpTexture,o).then((function(e){e&&(a.normalTexture=e,1!==r.bumpTexture.level&&(a.normalTexture.scale=r.bumpTexture.level))}));c.push(f)}if(r.ambientTexture){f=this._exportTextureAsync(r.ambientTexture,o).then((function(e){if(e){var t={index:e.index,texCoord:e.texCoord};a.occlusionTexture=t,r.ambientTextureStrength&&(t.strength=r.ambientTextureStrength)}}));c.push(f)}if(r.emissiveTexture){f=this._exportTextureAsync(r.emissiveTexture,o).then((function(e){e&&(a.emissiveTexture=e)}));c.push(f)}}e.FuzzyEquals(r.emissiveColor,n.Color3.Black(),e._Epsilon)||(a.emissiveFactor=r.emissiveColor.asArray()),a.pbrMetallicRoughness=i,l.push(a),u[r.uniqueId]=l.length-1}return this._finishMaterial(c,a,r,o)},e.prototype.getPixelsFromTexture=function(e){return e.textureType,n.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(){var n=e.uid;if(n in r._textureMap)return r._textureMap[n];var a=r.getPixelsFromTexture(e);if(!a)return null;for(var i=r._exporter._samplers,o=r._getGLTFTextureSampler(e),s=null,u=null,l=0;l-1||(l.GLTF2.Exporter[f]=s[f])}}.call(this,r(11))}])}));