!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 o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.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 o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));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 o});var n=r(0),o=function(){function e(){}return e._CreateBufferView=function(e,t,r,n,o){var i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),o&&(i.name=o),n&&(i.byteStride=n),i},e._CreateAccessor=function(e,t,r,n,o,i,a,s){var u={name:t,bufferView:e,componentType:n,count:o,type:r};return null!=a&&(u.min=a),null!=s&&(u.max=s),null!=i&&(u.byteOffset=i),u},e._CalculateMinMaxPositions=function(t,r,o,i){var a,s,u,l=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(o)for(var f=r,h=r+o;fc[p]&&(c[p]=d),++a}}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}()},function(e,t,r){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var n=r(0),o=r(10),i=r(1),a=r(3),s=r(7);r.d(t,"b",function(){return u}),r.d(t,"a",function(){return l});var 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._animations=[],this._imageData={},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 o=this;if(r>=t.length)return Promise.resolve(e);var i=n(t[r],e);return i?i.then(function(e){return o._applyExtension(e,t,r+1,n)}):this._applyExtension(e,t,r+1,n)},e.prototype._applyExtensions=function(t,r){for(var n=[],o=0,i=e._ExtensionNames;o=f;--a)i.setUInt32(r[a],o),o+=4;break;case n.Material.TriangleStripDrawMode:e.indexCount>=3&&(i.setUInt32(r[e.indexStart+2],o+4),i.setUInt32(r[e.indexStart+1],o+8))}},e.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,o,i,a,s,u){if(u&&r===n.Material.ClockWiseSideOrientation)switch(t){case n.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,o,i,a,s,u);break;case n.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,o,i,a,s,u);break;case n.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,o,i,a,s,u)}},e.prototype.reorderTriangleFillMode=function(e,t,r,o,i,a,s,u){var l=this.getVertexBufferFromMesh(o,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(o){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: "+o)}this.writeVertexAttributeData(f,a+12,o,i,s,u)}else n.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+o+" not present!")},e.prototype.reorderTriangleFanMode=function(e,t,r,o,i,a,s,u){var l=this.getVertexBufferFromMesh(o,e.getMesh());if(l){var c=l.byteStride/n.VertexBuffer.GetTypeByteLength(l.type),f=[],h=0;switch(o){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: "+o)}this.writeVertexAttributeData(f,a,o,i,s,u)}else n.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+o+" not present!")},e.prototype.writeVertexAttributeData=function(e,t,r,o,a,s){for(var u=0,l=e;u0){var O=null!==c.overrideMaterialSideOrientation?c.overrideMaterialSideOrientation:M.sideOrientation;if(O==n.Material.ClockWiseSideOrientation&&this._babylonScene.useRightHandedSystem||O==n.Material.ClockWiseSideOrientation&&o&&c.overrideMaterialSideOrientation!==(null===(a=c.material)||void 0===a?void 0:a.sideOrientation)){var G=null!=h?this._bufferViews[h].byteOffset:null;null==G&&(G=0);var D=null;if(null!=h&&(D=c.getIndices()),D)this.reorderIndicesBasedOnPrimitiveMode(E,p,D,G,r);else for(var U=0,k=f;Un.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,o,i,a=this,s={nodes:[]},u=function(){for(var e=0,t=0,r=arguments.length;tthis._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,e))},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],o=void 0;e(t,".glb")?o={type:"model/gltf-binary"}:e(t,".bin")?o={type:"application/octet-stream"}:e(t,".gltf")?o={type:"model/gltf+json"}:e(t,".jpeg")?o={type:"image/jpeg"}:e(t,".png")&&(o={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],o)),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);var n=r(7),o=r(3),i=r(2),a=r(10),s=r(8),u=r(1),l=r(9);r.d(t,"_GLTFAnimation",function(){return n.a}),r.d(t,"GLTFData",function(){return o.GLTFData}),r.d(t,"_Exporter",function(){return i.b}),r.d(t,"_BinaryWriter",function(){return i.a}),r.d(t,"__IGLTFExporterExtensionV2",function(){return 0}),r.d(t,"_GLTFMaterialExporter",function(){return a.a}),r.d(t,"GLTF2Export",function(){return s.GLTF2Export}),r.d(t,"_GLTFUtilities",function(){return u.a}),r.d(t,"KHR_texture_transform",function(){return l.KHR_texture_transform}),r.d(t,"KHR_lights_punctual",function(){return l.KHR_lights_punctual}),r.d(t,"KHR_materials_sheen",function(){return l.KHR_materials_sheen})},,function(e,t,r){"use strict";r.d(t,"a",function(){return a});var n,o=r(0),i=r(1);!function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"}(n||(n={}));var a=function(){function e(){}return e._CreateNodeAnimation=function(t,r,n,i,a,s){var u=[],l=[],c=r.getKeys(),f=e.calculateMinMaxKeyFrames(c),h=e._DeduceInterpolation(c,n,a),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,a):"LINEAR"===d||"STEP"===d?e._CreateLinearOrStepAnimation(t,r,n,p,u,l,i,a):"CUBICSPLINE"===d?e._CreateCubicSplineAnimation(t,r,n,p,u,l,i,a):e._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,u,l,f,i,a),u.length&&l.length?{inputs:u,outputs:l,samplerInterpolation:d,inputsMin:m?f.min:o.Tools.FloatRound(f.min/r.framePerSecond),inputsMax:m?f.max:o.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;default:o.Tools.Error("Unsupported animatable property "+i[0])}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(o.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},e._CreateNodeAnimationFromNodeAnimations=function(t,r,n,i,a,s,u,l,c,f){var h;if(t instanceof o.TransformNode&&t.animations)for(var p=0,d=t.animations;p-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 o=this;return new Promise(function(e,i){if(r instanceof n.PBRMaterial){if(!r.sheen.isEnabled)return void e(t);o._wasUsed=!0,null==t.extensions&&(t.extensions={});var a={colorFactor:r.sheen.color.asArray(),intensityFactor:r.sheen.intensity};if(r.sheen.texture){var s=o._getTextureIndex(r.sheen.texture);s>-1&&(a.colorIntensityTexture=o._textureInfos[s])}t.extensions[h]=a}e(t)})},e}();o.b.RegisterExtension(h,function(e){return new p(e)}),r.d(t,"KHR_texture_transform",function(){return s}),r.d(t,"KHR_lights_punctual",function(){return f}),r.d(t,"KHR_materials_sheen",function(){return p})},function(e,t,r){"use strict";r.d(t,"a",function(){return o});var n=r(0),o=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 o=[],i=0,a=e;is.width?(i=t&&t instanceof n.Texture?n.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):this._createWhiteTexture(a.width,a.height,r),o=e):(o=e,i=t),{texture1:o,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)||(V=!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)||(S=!0)}if(S){var P=this._createBase64FromCanvasAsync(_,h,p,i).then(function(e){R.metallicRoughnessTextureBase64=e});a.push(P)}if(V){P=this._createBase64FromCanvasAsync(x,h,p,i).then(function(e){R.baseColorTextureBase64=e});a.push(P)}return Promise.all(a).then(function(){return R})}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},e.prototype._convertSpecularGlossinessToMetallicRoughness=function(t){var r=this._getPerceivedBrightness(t.diffuseColor),o=this._getPerceivedBrightness(t.specularColor),i=1-this._getMaxComponent(t.specularColor),a=e._SolveMetallic(r,o,i),s=t.diffuseColor.scale(i/(1-e._DielectricSpecular.r)/Math.max(1-a,e._Epsilon)),u=t.specularColor.subtract(e._DielectricSpecular.scale(1-a)).scale(1/Math.max(a,e._Epsilon)),l=n.Color3.Lerp(s,u,a*a);return{baseColor:l=l.clampToRef(0,1,l),metallic:a,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 o=[],i={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return n&&(e.albedoTexture&&o.push(this._exportTextureAsync(e.albedoTexture,t).then(function(e){e&&(r.baseColorTexture=e)})),e.metallicTexture&&o.push(this._exportTextureAsync(e.metallicTexture,t).then(function(e){e&&(r.metallicRoughnessTexture=e)}))),Promise.all(o).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,o){var i=this;return Promise.resolve().then(function(){var a=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&&(a.push(c),l=a.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)&&o?i._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(e.albedoTexture,e.reflectivityTexture,u,t).then(function(n){if(n.baseColorTextureBase64){var o=i._getTextureInfoFromBase64(n.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",t,e.albedoTexture?e.albedoTexture.coordinatesIndex:null,l);o&&(r.baseColorTexture=o)}if(n.metallicRoughnessTextureBase64){var a=i._getTextureInfoFromBase64(n.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",t,e.reflectivityTexture?e.reflectivityTexture.coordinatesIndex:null,l);a&&(r.metallicRoughnessTexture=a)}return n}):i._convertSpecularGlossinessToMetallicRoughness(u)})},e.prototype._convertPBRMaterialAsync=function(e,t,r){var n=this,o={},i={name:e.name};return e.isMetallicWorkflow()?(e.albedoColor&&(o.baseColorFactor=[e.albedoColor.r,e.albedoColor.g,e.albedoColor.b,e.alpha]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,o,r).then(function(a){return n.setMetallicRoughnessPbrMaterial(a,e,i,o,t,r)})):this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,o,r).then(function(a){return n.setMetallicRoughnessPbrMaterial(a,e,i,o,t,r)})},e.prototype.setMetallicRoughnessPbrMaterial=function(t,r,o,i,a,s){var u=this._exporter._materialMap,l=this._exporter._materials,c=[];if(t){if(e._SetAlphaMode(o,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."),o.doubleSided=!0),s){if(r.bumpTexture){var f=this._exportTextureAsync(r.bumpTexture,a).then(function(e){e&&(o.normalTexture=e,1!==r.bumpTexture.level&&(o.normalTexture.scale=r.bumpTexture.level))});c.push(f)}if(r.ambientTexture){f=this._exportTextureAsync(r.ambientTexture,a).then(function(e){if(e){var t={index:e.index,texCoord:e.texCoord};o.occlusionTexture=t,r.ambientTextureStrength&&(t.strength=r.ambientTextureStrength)}});c.push(f)}if(r.emissiveTexture){f=this._exportTextureAsync(r.emissiveTexture,a).then(function(e){e&&(o.emissiveTexture=e)});c.push(f)}}e.FuzzyEquals(r.emissiveColor,n.Color3.Black(),e._Epsilon)||(o.emissiveFactor=r.emissiveColor.asArray()),o.pbrMetallicRoughness=i,l.push(o),u[r.uniqueId]=l.length-1}return this._finishMaterial(c,o,r,a)},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];for(var o=r._exporter._samplers,i=r._getGLTFTextureSampler(e),a=null,s=null,u=0;u-1||(l.GLTF2.Exporter[f]=s[f])}}.call(this,r(11))}])});