123456789101112131415 |
- !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;f<h;++f){a=3*f,s=n.Vector3.FromArray(t,a),i&&e._GetRightHandedPositionVector3FromRef(s),u=s.asArray();for(var p=0;p<3;++p){var d=u[p];d<l[p]&&(l[p]=d),d>c[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<i.length;o++){var a=i[o];n.push(this._extensions[a])}return this._applyExtension(t,n,0,r)},e.prototype._extensionsPreExportTextureAsync=function(e,t,r){return this._applyExtensions(t,function(t,n){return t.preExportTextureAsync&&t.preExportTextureAsync(e,n,r)})},e.prototype._extensionsPostExportMeshPrimitiveAsync=function(e,t,r,n){return this._applyExtensions(t,function(t,o){return t.postExportMeshPrimitiveAsync&&t.postExportMeshPrimitiveAsync(e,o,r,n)})},e.prototype._extensionsPostExportNodeAsync=function(e,t,r,n){return this._applyExtensions(t,function(t,o){return t.postExportNodeAsync&&t.postExportNodeAsync(e,o,r,n)})},e.prototype._extensionsPostExportMaterialAsync=function(e,t,r){return this._applyExtensions(t,function(t,n){return t.postExportMaterialAsync&&t.postExportMaterialAsync(e,n,r)})},e.prototype._extensionsPostExportMaterialAdditionalTextures=function(t,r,n){for(var o=[],i=0,a=e._ExtensionNames;i<a.length;i++){var s=a[i],u=this._extensions[s];u.postExportMaterialAdditionalTextures&&o.push.apply(o,u.postExportMaterialAdditionalTextures(t,r,n))}return o},e.prototype._extensionsPostExportTextures=function(t,r,n){for(var o=0,i=e._ExtensionNames;o<i.length;o++){var a=i[o],s=this._extensions[a];s.postExportTexture&&s.postExportTexture(t,r,n)}},e.prototype._forEachExtensions=function(t){for(var r=0,n=e._ExtensionNames;r<n.length;r++){var o=n[r],i=this._extensions[o];i.enabled&&t(i)}},e.prototype._extensionsOnExporting=function(){var e=this;this._forEachExtensions(function(t){t.wasUsed&&(null==e._glTF.extensionsUsed&&(e._glTF.extensionsUsed=[]),-1===e._glTF.extensionsUsed.indexOf(t.name)&&e._glTF.extensionsUsed.push(t.name),t.required&&(null==e._glTF.extensionsRequired&&(e._glTF.extensionsRequired=[]),-1===e._glTF.extensionsRequired.indexOf(t.name)&&e._glTF.extensionsRequired.push(t.name)),null==e._glTF.extensions&&(e._glTF.extensions={}),t.onExporting&&t.onExporting())})},e.prototype._loadExtensions=function(){for(var t=0,r=e._ExtensionNames;t<r.length;t++){var n=r[t],o=e._ExtensionFactories[n](this);this._extensions[n]=o}},e.prototype.dispose=function(){for(var e in this._extensions){this._extensions[e].dispose()}},e.RegisterExtension=function(t,r){e.UnregisterExtension(t)&&n.Tools.Warn("Extension with the name "+t+" already exists"),e._ExtensionFactories[t]=r,e._ExtensionNames.push(t)},e.UnregisterExtension=function(t){if(!e._ExtensionFactories[t])return!1;delete e._ExtensionFactories[t];var r=e._ExtensionNames.indexOf(t);return-1!==r&&e._ExtensionNames.splice(r,1),!0},e.prototype._getLocalEngine=function(){if(!this._localEngine){var e=document.createElement("canvas");e.id="WriteCanvas",e.width=2048,e.height=2048,this._localEngine=new n.Engine(e,!0,{premultipliedAlpha:n.Tools.IsSafari(),preserveDrawingBuffer:!0}),this._localEngine.setViewport(new n.Viewport(0,0,1,1))}return this._localEngine},e.prototype.reorderIndicesBasedOnPrimitiveMode=function(e,t,r,o,i){switch(t){case n.Material.TriangleFillMode:o||(o=0);for(var a=e.indexStart,s=e.indexStart+e.indexCount;a<s;a+=3){var u=o+4*a,l=i.getUInt32(u+4),c=i.getUInt32(u+8);i.setUInt32(c,u+4),i.setUInt32(l,u+8)}break;case n.Material.TriangleFanDrawMode:a=e.indexStart+e.indexCount-1;for(var f=e.indexStart;a>=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+e.verticesCount;p+=3)h=p*c,f.push(n.Vector3.FromArray(i,h)),f.push(n.Vector3.FromArray(i,h+2*c)),f.push(n.Vector3.FromArray(i,h+c));break;case n.VertexBuffer.TangentKind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(n.Vector4.FromArray(i,h)),f.push(n.Vector4.FromArray(i,h+2*c)),f.push(n.Vector4.FromArray(i,h+c));break;case n.VertexBuffer.ColorKind:var d=l.getSize();for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=d)h=p*c,4===d?(f.push(n.Vector4.FromArray(i,h)),f.push(n.Vector4.FromArray(i,h+2*c)),f.push(n.Vector4.FromArray(i,h+c))):(f.push(n.Vector3.FromArray(i,h)),f.push(n.Vector3.FromArray(i,h+2*c)),f.push(n.Vector3.FromArray(i,h+c)));break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:for(p=e.verticesStart;p<e.verticesStart+e.verticesCount;p+=3)h=p*c,f.push(n.Vector2.FromArray(i,h)),f.push(n.Vector2.FromArray(i,h+2*c)),f.push(n.Vector2.FromArray(i,h+c));break;default:n.Tools.Error("Unsupported Vertex Buffer type: "+o)}this.writeVertexAttributeData(f,a,o,i,s,u)}}else n.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+o+" not present!")},e.prototype.reorderTriangleStripDrawMode=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:h=e.verticesStart,f.push(n.Vector3.FromArray(i,h+2*c)),f.push(n.Vector3.FromArray(i,h+c));break;case n.VertexBuffer.TangentKind:for(var 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,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;u<l.length;u++){var c=l[u];!s||r===n.VertexBuffer.ColorKind||c instanceof n.Vector2||(c instanceof n.Vector3?r===n.VertexBuffer.NormalKind?i.a._GetRightHandedNormalVector3FromRef(c):r===n.VertexBuffer.PositionKind?i.a._GetRightHandedPositionVector3FromRef(c):n.Tools.Error("Unsupported vertex attribute kind!"):i.a._GetRightHandedVector4FromRef(c)),r===n.VertexBuffer.NormalKind?c.normalize():r===n.VertexBuffer.TangentKind&&c instanceof n.Vector4&&i.a._NormalizeTangentFromRef(c);for(var f=0,h=c.asArray();f<h.length;f++){var p=h[f];a.setFloat32(p,t),t+=4}}},e.prototype.writeAttributeData=function(e,t,r,o,a){var s,u=r/4,l=[];switch(e){case n.VertexBuffer.PositionKind:for(var c=0,f=t.length/u;c<f;++c){s=c*u;var h=n.Vector3.FromArray(t,s);a&&i.a._GetRightHandedPositionVector3FromRef(h),l.push(h.asArray())}break;case n.VertexBuffer.NormalKind:c=0;for(var p=t.length/u;c<p;++c){s=c*u;h=n.Vector3.FromArray(t,s);a&&i.a._GetRightHandedNormalVector3FromRef(h),h.normalize(),l.push(h.asArray())}break;case n.VertexBuffer.TangentKind:c=0;for(var d=t.length/u;c<d;++c){s=c*u;h=n.Vector4.FromArray(t,s);a&&i.a._GetRightHandedVector4FromRef(h),i.a._NormalizeTangentFromRef(h),l.push(h.asArray())}break;case n.VertexBuffer.ColorKind:c=0;for(var m=t.length/u;c<m;++c){s=c*u;h=3===u?n.Vector3.FromArray(t,s):n.Vector4.FromArray(t,s);l.push(h.asArray())}break;case n.VertexBuffer.UVKind:case n.VertexBuffer.UV2Kind:c=0;for(var g=t.length/u;c<g;++c)s=c*u,l.push([t[s],t[s+1]]);break;default:n.Tools.Warn("Unsupported Vertex Buffer Type: "+e),l=[]}for(var _=0,x=l;_<x.length;_++)for(var y=0,T=x[_];y<T.length;y++){var v=T[y];o.setFloat32(v)}},e.prototype.generateJSON=function(e,t,r){var n,o,a,s=this,u={byteLength:this._totalByteLength},l=this._totalByteLength;return u.byteLength&&(this._glTF.buffers=[u]),this._nodes&&this._nodes.length&&(this._glTF.nodes=this._nodes),this._meshes&&this._meshes.length&&(this._glTF.meshes=this._meshes),this._scenes&&this._scenes.length&&(this._glTF.scenes=this._scenes,this._glTF.scene=0),this._bufferViews&&this._bufferViews.length&&(this._glTF.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(this._glTF.accessors=this._accessors),this._animations&&this._animations.length&&(this._glTF.animations=this._animations),this._materials&&this._materials.length&&(this._glTF.materials=this._materials),this._textures&&this._textures.length&&(this._glTF.textures=this._textures),this._samplers&&this._samplers.length&&(this._glTF.samplers=this._samplers),this._images&&this._images.length&&(e?(this._glTF.images=[],this._images.forEach(function(e){e.uri&&(o=s._imageData[e.uri],n=e.uri.split(".")[0]+" image",a=i.a._CreateBufferView(0,l,o.data.length,void 0,n),l+=o.data.buffer.byteLength,s._bufferViews.push(a),e.bufferView=s._bufferViews.length-1,e.name=n,e.mimeType=o.mimeType,e.uri=void 0,s._glTF.images||(s._glTF.images=[]),s._glTF.images.push(e))}),u.byteLength=l):this._glTF.images=this._images),e||(u.uri=t+".bin"),r?JSON.stringify(this._glTF,null,2):JSON.stringify(this._glTF)},e.prototype._generateGLTFAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then(function(n){r._extensionsOnExporting();var o=r.generateJSON(!1,e,!0),i=new Blob([n],{type:"application/octet-stream"}),s=e+".gltf",u=e+".bin",l=new a.GLTFData;if(l.glTFFiles[s]=o,l.glTFFiles[u]=i,r._imageData)for(var c in r._imageData)l.glTFFiles[c]=new Blob([r._imageData[c].data],{type:r._imageData[c].mimeType});return t&&r.dispose(),l})},e.prototype._generateBinaryAsync=function(){var e=this,t=new l(4);return this.createSceneAsync(this._babylonScene,t).then(function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()})},e.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},e.prototype._generateGLBAsync=function(e,t){var r=this;return void 0===t&&(t=!0),this._generateBinaryAsync().then(function(n){r._extensionsOnExporting();var o=r.generateJSON(!0),i=e+".glb",s=o.length,u=0;for(var l in r._imageData)u+=r._imageData[l].data.byteLength;var c=r._getPadding(s),f=r._getPadding(n.byteLength),h=r._getPadding(u),p=28+s+c+n.byteLength+f+u+h,d=new ArrayBuffer(12),m=new DataView(d);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,p,!0);var g=new ArrayBuffer(8+s+c),_=new DataView(g);_.setUint32(0,s+c,!0),_.setUint32(4,1313821514,!0);for(var x=new Uint8Array(g,8),y=0;y<s;++y)x[y]=o.charCodeAt(y);var T=new Uint8Array(g,8+s);for(y=0;y<c;++y)T[y]=32;var v=new ArrayBuffer(8),A=new DataView(v);A.setUint32(0,n.byteLength+u+h,!0),A.setUint32(4,5130562,!0);var b=new ArrayBuffer(f),F=new Uint8Array(b);for(y=0;y<f;++y)F[y]=0;var E=new ArrayBuffer(h),M=new Uint8Array(E);for(y=0;y<h;++y)M[y]=0;var R=[d,g,v,n];for(var l in r._imageData)R.push(r._imageData[l].data.buffer);R.push(b),R.push(E);var S=new Blob(R,{type:"application/octet-stream"}),V=new a.GLTFData;return V.glTFFiles[i]=S,null!=r._localEngine&&r._localEngine.dispose(),t&&r.dispose(),V})},e.prototype.setNodeTransformation=function(e,t,r){t.getPivotPoint().equalsToFloats(0,0,0)||n.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=r?i.a._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var o=n.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&o.multiplyInPlace(t.rotationQuaternion),0===o.x&&0===o.y&&0===o.z&&1===o.w||(r&&i.a._GetRightHandedQuaternionFromRef(o),e.rotation=o.normalize().asArray())},e.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},e.prototype.createBufferViewKind=function(e,t,r,o,a){var s=t instanceof n.Mesh?t:t instanceof n.InstancedMesh?t.sourceMesh:null;if(s){var u=s.getVerticesData(e);if(u){var l=4*u.length,c=i.a._CreateBufferView(0,r.getByteOffset(),l,o,e+" - "+s.name);this._bufferViews.push(c),this.writeAttributeData(e,u,o,r,a)}}},e.prototype.getMeshPrimitiveMode=function(e){return e instanceof n.LinesMesh?n.Material.LineListDrawMode:e.material?e.material.fillMode:n.Material.TriangleFillMode},e.prototype.setPrimitiveMode=function(e,t){switch(t){case n.Material.TriangleFillMode:break;case n.Material.TriangleStripDrawMode:e.mode=5;break;case n.Material.TriangleFanDrawMode:e.mode=6;break;case n.Material.PointListDrawMode:e.mode=0;case n.Material.PointFillMode:e.mode=0;break;case n.Material.LineLoopDrawMode:e.mode=2;break;case n.Material.LineListDrawMode:e.mode=1;break;case n.Material.LineStripDrawMode:e.mode=3}},e.prototype.setAttributeKind=function(e,t){switch(t){case n.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case n.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case n.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case n.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case n.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case n.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;default:n.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},e.prototype.setPrimitiveAttributesAsync=function(e,t,r,o){var a,s,u,l=[],c=null;t instanceof n.Mesh?c=t:t instanceof n.InstancedMesh&&(c=t.sourceMesh);var f=[{kind:n.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:n.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:n.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:n.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:n.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:n.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(c){for(var h=null,p=this.getMeshPrimitiveMode(c),d={},m=0,g=f;m<g.length;m++){var _=(H=g[m]).kind;if(c.isVerticesDataPresent(_)){var x=this.getVertexBufferFromMesh(_,c);H.byteStride=x?4*x.getSize():4*n.VertexBuffer.DeduceStride(_),12===H.byteStride&&(H.accessorType="VEC3"),this.createBufferViewKind(_,t,r,H.byteStride,o),H.bufferViewIndex=this._bufferViews.length-1,d[_]=H.bufferViewIndex}}if(c.getTotalIndices()){var y=c.getIndices();if(y){var T=4*y.length;s=i.a._CreateBufferView(0,r.getByteOffset(),T,void 0,"Indices - "+c.name),this._bufferViews.push(s),h=this._bufferViews.length-1;for(var v=0,A=y.length;v<A;++v)r.setUInt32(y[v])}}if(c.subMeshes)for(var b=0,F=c.subMeshes;b<F.length;b++){var E=F[b],M=E.getMaterial()||c.getScene().defaultMaterial,R=null;if(M)if(c instanceof n.LinesMesh){var S={name:c.name+" material"};(!c.color.equals(n.Color3.White())||c.alpha<1)&&(S.pbrMetallicRoughness={baseColorFactor:c.color.asArray().concat([c.alpha])}),this._materials.push(S),R=this._materials.length-1}else if(M instanceof n.MultiMaterial){var V=M.subMaterials[E.materialIndex];V&&(M=V,R=this._materialMap[M.uniqueId])}else R=this._materialMap[M.uniqueId];var w=null!=R?this._materials[R]:null,C={attributes:{}};this.setPrimitiveMode(C,p);for(var B=0,P=f;B<P.length;B++){if((_=(H=P[B]).kind)!==n.VertexBuffer.UVKind&&_!==n.VertexBuffer.UV2Kind||!w||this._glTFMaterialExporter._hasTexturesPresent(w))if(K=c.getVerticesData(_))if(x=this.getVertexBufferFromMesh(_,c)){var I=x.getSize(),N=H.bufferViewIndex;if(null!=N){u={min:null,max:null},_==n.VertexBuffer.PositionKind&&(u=i.a._CalculateMinMaxPositions(K,0,K.length/I,o));var L=i.a._CreateAccessor(N,_+" - "+t.name,H.accessorType,5126,K.length/I,0,u.min,u.max);this._accessors.push(L),this.setAttributeKind(C,_)}}}if(h){L=i.a._CreateAccessor(h,"indices - "+t.name,"SCALAR",5125,E.indexCount,4*E.indexStart,null,null);this._accessors.push(L),C.indices=this._accessors.length-1}if(null!=R&&Object.keys(C.attributes).length>0){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;U<k.length;U++){var K,H=k[U];if(K=c.getVerticesData(H.kind)){var z=this._bufferViews[d[H.kind]].byteOffset;z||(z=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(E,p,O,H.kind,K,z,r,o)}}}C.material=R}e.primitives.push(C),this._extensionsPostExportMeshPrimitiveAsync("postExport",C,E,r)&&l.push()}}return Promise.all(l).then(function(){})},e.prototype.isBabylonCoordinateSystemConvertingNode=function(e){if(e instanceof n.TransformNode){if("__root__"!==e.name)return!1;for(var t=e.getWorldMatrix(),r=n.Matrix.Compose(this._convertToRightHandedSystem?new n.Vector3(-1,1,1):n.Vector3.One(),n.Quaternion.Identity(),n.Vector3.Zero()),o=t.multiply(r),i=n.Matrix.IdentityReadOnly,a=0;a<16;a++)if(Math.abs(o.m[a]-i.m[a])>n.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;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)n[o]=i[a];return n}(e.transformNodes,e.meshes,e.lights),l=[];return this._convertToRightHandedSystem=!e.useRightHandedSystem,this._convertToRightHandedSystemMap={},e.rootNodes.forEach(function(e){a._convertToRightHandedSystemMap[e.uniqueId]=a._convertToRightHandedSystem,e.getDescendants(!1).forEach(function(e){a._convertToRightHandedSystemMap[e.uniqueId]=a._convertToRightHandedSystem})}),e.rootNodes.forEach(function(e){if(a.isBabylonCoordinateSystemConvertingNode(e)){l.push(e);var t=u.indexOf(e);-1!==t&&u.splice(t,1),e.getDescendants(!1).forEach(function(e){a._convertToRightHandedSystemMap[e.uniqueId]=!1})}}),this._glTFMaterialExporter._convertMaterialsToGLTFAsync(e.materials,"image/png",!0).then(function(){return a.createNodeMapAndAnimationsAsync(e,u,t).then(function(e){if(a._nodeMap=e,a._totalByteLength=t.getByteOffset(),null==a._totalByteLength)throw new Error("undefined byte length!");for(var c=0,f=u;c<f.length;c++){var h=f[c];if(void 0!==(r=a._nodeMap[h.uniqueId])){if(o=a._nodes[r],h.metadata&&(a._options.metadataSelector?o.extras=a._options.metadataSelector(h.metadata):h.metadata.gltf&&(o.extras=h.metadata.gltf.extras)),!h.parent||-1!==l.indexOf(h.parent))if(a._options.shouldExportNode&&!a._options.shouldExportNode(h))n.Tools.Log("Omitting "+h.name+" from scene.");else a._convertToRightHandedSystemMap[h.uniqueId]&&(o.translation&&(o.translation[2]*=-1,o.translation[0]*=-1),o.rotation=o.rotation?n.Quaternion.FromArray([0,1,0,0]).multiply(n.Quaternion.FromArray(o.rotation)).asArray():n.Quaternion.FromArray([0,1,0,0]).asArray()),s.nodes.push(r);if(i=h.getDescendants(!0),!o.children&&i&&i.length){for(var p=[],d=0,m=i;d<m.length;d++){var g=m[d];null!=a._nodeMap[g.uniqueId]&&p.push(a._nodeMap[g.uniqueId])}p.length&&(o.children=p)}}}s.nodes.length&&a._scenes.push(s)})})},e.prototype.createNodeMapAndAnimationsAsync=function(e,t,r){for(var o,i=this,a=Promise.resolve(),u={},l={name:"runtime animations",channels:[],samplers:[]},c=[],f=function(t){!h._options.shouldExportNode||h._options.shouldExportNode(t)?a=a.then(function(){var a=i._convertToRightHandedSystemMap[t.uniqueId];return i.createNodeAsync(t,r,a,u).then(function(f){var h=i._extensionsPostExportNodeAsync("createNodeAsync",f,t,u);return null==h?(n.Tools.Warn("Not exporting node "+t.name),Promise.resolve()):h.then(function(n){n&&(i._nodes.push(n),o=i._nodes.length-1,u[t.uniqueId]=o,!e.animationGroups.length&&t.animations.length&&s.a._CreateNodeAnimationFromNodeAnimations(t,l,c,u,i._nodes,r,i._bufferViews,i._accessors,a,i._animationSampleRate))})})}):t.name},h=this,p=0,d=t;p<d.length;p++){f(d[p])}return a.then(function(){return l.channels.length&&l.samplers.length&&i._animations.push(l),c.forEach(function(e){e.channels.length&&e.samplers.length&&i._animations.push(e)}),e.animationGroups.length&&s.a._CreateNodeAnimationFromAnimationGroups(e,i._animations,u,i._nodes,r,i._bufferViews,i._accessors,i._convertToRightHandedSystemMap,i._animationSampleRate),u})},e.prototype.createNodeAsync=function(e,t,r,o){var i=this;return Promise.resolve().then(function(){var o={},a={primitives:[]};return e.name&&(o.name=e.name),e instanceof n.TransformNode?(i.setNodeTransformation(o,e,r),i.setPrimitiveAttributesAsync(a,e,t,r).then(function(){return a.primitives.length&&(i._meshes.push(a),o.mesh=i._meshes.length-1),o})):o})},e._ExtensionNames=new Array,e._ExtensionFactories={},e}(),l=function(){function e(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return e.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),n=new Uint8Array(t),o=0,i=n.byteLength;o<i;++o)n[o]=r[o];return this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer),t},e.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset())},e.prototype.getByteOffset=function(){if(null==this._byteOffset)throw new Error("Byte offset is undefined!");return this._byteOffset},e.prototype.setUInt8=function(e,t){null!=t?t<this._byteOffset?this._dataView.setUint8(t,e):n.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,e))},e.prototype.getUInt32=function(e){if(e<this._byteOffset)return this._dataView.getUint32(e,!0);throw n.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},e.prototype.getVector3Float32FromRef=function(e,t){t+8>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.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&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):n.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._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?t<this._byteOffset?this._dataView.setUint32(t,e,!0):n.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._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<d.length;p++){var m=d[p],g=e._DeduceAnimationInfo(m);g&&(h={name:m.name,samplers:[],channels:[]},e.AddAnimation(""+m.name,m.hasRunningRuntimeAnimations?r:h,t,m,g.dataAccessorType,g.animationChannelTargetPath,i,s,u,l,c,g.useQuaternion,f),h.samplers.length&&h.channels.length&&n.push(h))}},e._CreateNodeAnimationFromAnimationGroups=function(t,r,n,i,a,s,u,l,c){var f;if(t.animationGroups)for(var h=0,p=t.animationGroups;h<p.length;h++){var d=p[h];f={name:d.name,channels:[],samplers:[]};for(var m=0,g=d.targetedAnimations;m<g.length;m++){var _=g[m],x=_.target,y=_.animation;if(x instanceof o.TransformNode||1===x.length&&x[0]instanceof o.TransformNode){var T=e._DeduceAnimationInfo(_.animation);if(T){var v=x instanceof o.TransformNode?x:x[0],A=l[v.uniqueId];e.AddAnimation(""+y.name,f,v,y,T.dataAccessorType,T.animationChannelTargetPath,n,a,s,u,A,T.useQuaternion,c)}}}f.channels.length&&f.samplers.length&&r.push(f)}},e.AddAnimation=function(t,r,n,o,a,s,u,l,c,f,h,p,d){var m,g,_,x,y,T,v,A=e._CreateNodeAnimation(n,o,s,h,p,d);if(A){var b=u[n.uniqueId],F=4*A.inputs.length;m=i.a._CreateBufferView(0,l.getByteOffset(),F,void 0,t+" keyframe data view"),c.push(m),A.inputs.forEach(function(e){l.setFloat32(e)}),g=i.a._CreateAccessor(c.length-1,t+" keyframes","SCALAR",5126,A.inputs.length,null,[A.inputsMin],[A.inputsMax]),f.push(g),_=f.length-1,y=A.outputs.length,F="VEC3"===a?12*A.outputs.length:16*A.outputs.length,m=i.a._CreateBufferView(0,l.getByteOffset(),F,void 0,t+" data view"),c.push(m),A.outputs.forEach(function(e){e.forEach(function(e){l.setFloat32(e)})}),g=i.a._CreateAccessor(c.length-1,t+" data",a,5126,y,null,null,null),f.push(g),x=f.length-1,T={interpolation:A.samplerInterpolation,input:_,output:x},r.samplers.push(T),v={sampler:r.samplers.length-1,target:{node:b,path:s}},r.channels.push(v)}},e._CreateBakedAnimation=function(t,r,n,i,a,s,u,l,c,f,h,p){var d,m,g=o.Quaternion.Identity(),_=null,x=null,y=null,T=null,v=null,A=null;f.min=o.Tools.FloatRound(i/s);for(var b=r.getKeys(),F=0,E=b.length;F<E;++F){if(A=null,y=b[F],F+1<E)if(T=b[F+1],y.value.equals&&y.value.equals(T.value)||y.value===T.value){if(0!==F)continue;A=y.frame}else A=T.frame;else{if(v=b[F-1],y.value.equals&&y.value.equals(v.value)||y.value===v.value)continue;A=a}if(A)for(var M=y.frame;M<=A;M+=u)if((m=o.Tools.FloatRound(M/s))!==_){_=m,x=m;var R={key:0,repeatCount:0,loopMode:r.loopMode};d=r._interpolate(M,R),e._SetInterpolatedValue(t,d,m,r,n,g,l,c,h,p)}}x&&(f.max=x)},e._ConvertFactorToVector3OrQuaternion=function(t,r,n,i,a,s,u){var l,c,f=null,h=e._GetBasePositionRotationOrScale(r,a,s,u);if(i===o.Animation.ANIMATIONTYPE_FLOAT)switch(c=(l=n.targetProperty.split("."))?l[1]:"",f=u?o.Quaternion.FromArray(h).normalize():o.Vector3.FromArray(h),c){case"x":case"y":f[c]=s&&u&&"scale"!==a?-t:t;break;case"z":f[c]=s&&!u&&"scale"!==a?-t:t;break;case"w":f.w=t;break;default:o.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return f},e._SetInterpolatedValue=function(e,t,r,n,a,s,u,l,c,f){var h,p=n.dataType;u.push(r),"number"==typeof t&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,p,a,c,f)),t&&("rotation"===a?(f?s=t:(h=t,o.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,s)),c&&(i.a._GetRightHandedQuaternionFromRef(s),e.parent||(s=o.Quaternion.FromArray([0,1,0,0]).multiply(s))),l.push(s.asArray())):(h=t,c&&"scale"!==a&&(i.a._GetRightHandedPositionVector3FromRef(h),e.parent||(h.x*=-1,h.z*=-1)),l.push(h.asArray())))},e._CreateLinearOrStepAnimation=function(t,r,n,o,i,a,s,u){for(var l=0,c=r.getKeys();l<c.length;l++){var f=c[l];i.push(f.frame/r.framePerSecond),e._AddKeyframeValue(f,r,a,n,t,s,u)}},e._CreateCubicSplineAnimation=function(t,r,o,i,a,s,u,l){r.getKeys().forEach(function(c){a.push(c.frame/r.framePerSecond),e.AddSplineTangent(t,n.INTANGENT,s,o,"CUBICSPLINE",c,i,l,u),e._AddKeyframeValue(c,r,s,o,t,u,l),e.AddSplineTangent(t,n.OUTTANGENT,s,o,"CUBICSPLINE",c,i,l,u)})},e._GetBasePositionRotationOrScale=function(e,t,r,n){var a;return"rotation"===t?n?e.rotationQuaternion?(a=e.rotationQuaternion.asArray(),r&&(i.a._GetRightHandedQuaternionArrayFromRef(a),e.parent||(a=o.Quaternion.FromArray([0,1,0,0]).multiply(o.Quaternion.FromArray(a)).asArray()))):a=o.Quaternion.Identity().asArray():(a=e.rotation.asArray(),i.a._GetRightHandedNormalArray3FromRef(a)):"translation"===t?(a=e.position.asArray(),r&&i.a._GetRightHandedPositionArray3FromRef(a)):a=e.scaling.asArray(),a},e._AddKeyframeValue=function(e,t,r,n,a,s,u){var l,c,f=t.dataType;if(f===o.Animation.ANIMATIONTYPE_VECTOR3){if(l=e.value.asArray(),"rotation"===n){var h=o.Vector3.FromArray(l),p=o.Quaternion.RotationYawPitchRoll(h.y,h.x,h.z);s&&(i.a._GetRightHandedQuaternionFromRef(p),a.parent||(p=o.Quaternion.FromArray([0,1,0,0]).multiply(p))),l=p.asArray()}else"translation"===n&&s&&(i.a._GetRightHandedNormalArray3FromRef(l),a.parent||(l[0]*=-1,l[2]*=-1));r.push(l)}else if(f===o.Animation.ANIMATIONTYPE_FLOAT){if(c=this._ConvertFactorToVector3OrQuaternion(e.value,a,t,f,n,s,u)){if("rotation"===n){var d=u?c:o.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).normalize();s&&(i.a._GetRightHandedQuaternionFromRef(d),a.parent||(d=o.Quaternion.FromArray([0,1,0,0]).multiply(d))),r.push(d.asArray())}else"translation"===n&&s&&(i.a._GetRightHandedNormalVector3FromRef(c),a.parent||(c.x*=-1,c.z*=-1));r.push(c.asArray())}}else f===o.Animation.ANIMATIONTYPE_QUATERNION?(l=e.value.normalize().asArray(),s&&(i.a._GetRightHandedQuaternionArrayFromRef(l),a.parent||(l=o.Quaternion.FromArray([0,1,0,0]).multiply(o.Quaternion.FromArray(l)).asArray())),r.push(l)):o.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},e._DeduceInterpolation=function(e,t,r){var n,i,a=!1;if("rotation"===t&&!r)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,u=e.length;s<u;++s)if((i=e[s]).inTangent||i.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",a=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||i.interpolation&&i.interpolation===o.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=i.interpolation&&i.interpolation===o.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},e.AddSplineTangent=function(e,t,r,a,s,u,l,c,f){var h,p=t===n.INTANGENT?u.inTangent:u.outTangent;if("CUBICSPLINE"===s){if("rotation"===a)if(p){if(c)h=p.scale(l).asArray();else{var d=p.scale(l);h=o.Quaternion.RotationYawPitchRoll(d.y,d.x,d.z).asArray()}f&&(i.a._GetRightHandedQuaternionArrayFromRef(h),e.parent||(h=o.Quaternion.FromArray([0,1,0,0]).multiply(o.Quaternion.FromArray(h)).asArray()))}else h=[0,0,0,0];else p?(h=p.scale(l).asArray(),f&&"translation"===a&&(i.a._GetRightHandedPositionArray3FromRef(h),e.parent||(h[0]*=-1,h[2]*=-1))):h=[0,0,0];r.push(h)}},e.calculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach(function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)}),{min:t,max:r}},e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"GLTF2Export",function(){return o});var n=r(2),o=function(){function e(){}return e.GLTFAsync=function(e,t,r){return e.whenReadyAsync().then(function(){var o=t.replace(/\.[^\/.]+$/,"");return new n.b(e,r)._generateGLTFAsync(o)})},e._PreExportAsync=function(e,t){return Promise.resolve().then(function(){return t&&t.exportWithoutWaitingForScene?Promise.resolve():e.whenReadyAsync()})},e._PostExportAsync=function(e,t,r){return Promise.resolve().then(function(){return r&&r.exportWithoutWaitingForScene,t})},e.GLBAsync=function(e,t,r){var o=this;return this._PreExportAsync(e,r).then(function(){var i=t.replace(/\.[^\/.]+$/,"");return new n.b(e,r)._generateGLBAsync(i).then(function(t){return o._PostExportAsync(e,t,r)})})},e}()},function(e,t,r){"use strict";r.r(t);var n=r(0),o=r(2),i="precision highp float;\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform mat4 textureTransformMat;\nvoid main(void) {\nvec2 uvTransformed=(textureTransformMat*vec4(vUV.xy,1,1)).xy;\ngl_FragColor=texture2D(textureSampler,uvTransformed);\n}";n.Effect.ShadersStore.textureTransformPixelShader=i;var a="KHR_texture_transform",s=function(){function e(e){this._recordedTextures=[],this.name=a,this.enabled=!0,this.required=!1,this._wasUsed=!1}return e.prototype.dispose=function(){for(var e=0,t=this._recordedTextures;e<t.length;e++){t[e].dispose()}},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!0,configurable:!0}),e.prototype.postExportTexture=function(e,t,r){if(r&&0===r.uRotationCenter&&0===r.vRotationCenter){var n={},o=!1;if(0===r.uOffset&&0===r.vOffset||(n.offset=[r.uOffset,r.vOffset],o=!0),1===r.uScale&&1===r.vScale||(n.scale=[r.uScale,r.vScale],o=!0),0!==r.wAng&&(n.rotation=r.wAng,o=!0),0!==r.coordinatesIndex&&(n.texCoord=r.coordinatesIndex,o=!0),!o)return;this._wasUsed=!0,t.extensions||(t.extensions={}),t.extensions[a]=n}},e.prototype.preExportTextureAsync=function(e,t,r){var n=this;return new Promise(function(r,o){var i=t.getScene();if(i){var a=!1;if(0===t.uOffset&&0===t.vOffset||(a=!0),1===t.uScale&&1===t.vScale||(a=!0),0!==t.wAng&&(a=!0),a){if(0!==t.uRotationCenter||0!==t.vRotationCenter)return n._textureTransformTextureAsync(t,i).then(function(e){r(e)}).catch(function(e){o(e)});r(t)}else r(t)}else o(e+': "scene" is not defined for Babylon texture '+t.name+"!")})},e.prototype._textureTransformTextureAsync=function(e,t){var r=this;return new Promise(function(o){var i=new n.ProceduralTexture(""+e.name,e.getSize(),"textureTransform",t);i||(n.Tools.Log("Cannot create procedural texture for "+e.name+"!"),o(e)),i.reservedDataStore={hidden:!0,source:e},r._recordedTextures.push(i),i.coordinatesIndex=e.coordinatesIndex,i.setTexture("textureSampler",e),i.setMatrix("textureTransformMat",e.getTextureMatrix()),i.isReady()?(i.render(),o(i)):i.getEffect().executeWhenCompiled(function(){i.render(),o(i)})})},e}();o.b.RegisterExtension(a,function(e){return new s(e)});var u,l=r(1),c="KHR_lights_punctual";!function(e){e.DIRECTIONAL="directional",e.POINT="point",e.SPOT="spot"}(u||(u={}));var f=function(){function e(e){this.name=c,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){delete this._lights},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return!!this._lights},enumerable:!0,configurable:!0}),e.prototype.onExporting=function(){this._exporter._glTF.extensions[c]=this._lights},e.prototype.postExportNodeAsync=function(e,t,r,o){var i=this;return new Promise(function(a,s){if(t&&r instanceof n.ShadowLight){var f=r,h=void 0,p=f.getTypeID()==n.Light.LIGHTTYPEID_POINTLIGHT?u.POINT:f.getTypeID()==n.Light.LIGHTTYPEID_DIRECTIONALLIGHT?u.DIRECTIONAL:f.getTypeID()==n.Light.LIGHTTYPEID_SPOTLIGHT?u.SPOT:null;if(null==p)n.Logger.Warn(e+": Light "+f.name+" is not supported in "+c);else{var d=f.position.clone(),m=i._exporter._convertToRightHandedSystemMap[r.uniqueId];if(d.equals(n.Vector3.Zero())||(m&&l.a._GetRightHandedPositionVector3FromRef(d),t.translation=d.asArray()),p!==u.POINT){var g=f.direction,_=-Math.atan2(g.z*(i._exporter._babylonScene.useRightHandedSystem?-1:1),g.x)+Math.PI/2,x=Math.sqrt(g.x*g.x+g.z*g.z),y=-Math.atan2(g.y,x),T=n.Quaternion.RotationYawPitchRoll(_,y,0);m&&l.a._GetRightHandedQuaternionFromRef(T),T.equals(n.Quaternion.Identity())||(t.rotation=T.asArray())}if(f.falloffType!==n.Light.FALLOFF_GLTF&&n.Logger.Warn(e+": Light falloff for "+f.name+" does not match the "+c+" specification!"),h={type:p},f.diffuse.equals(n.Color3.White())||(h.color=f.diffuse.asArray()),1!==f.intensity&&(h.intensity=f.intensity),f.range!==Number.MAX_VALUE&&(h.range=f.range),p===u.SPOT){var v=f;v.angle!==Math.PI/2&&(null==h.spot&&(h.spot={}),h.spot.outerConeAngle=v.angle/2),0!==v.innerAngle&&(null==h.spot&&(h.spot={}),h.spot.innerConeAngle=v.innerAngle/2)}null==i._lights&&(i._lights={lights:[]}),i._lights.lights.push(h);var A={light:i._lights.lights.length-1},b=r.parent;if(b&&1==b.getChildren().length){var F=i._exporter._nodes[o[b.uniqueId]];if(F){var E=n.TmpVectors.Matrix[0],M=n.TmpVectors.Matrix[1],R=F.translation?new n.Vector3(F.translation[0],F.translation[1],F.translation[2]):n.Vector3.Zero(),S=F.rotation?new n.Quaternion(F.rotation[0],F.rotation[1],F.rotation[2],F.rotation[3]):n.Quaternion.Identity(),V=F.scale?new n.Vector3(F.scale[0],F.scale[1],F.scale[2]):n.Vector3.One();n.Matrix.ComposeToRef(V,S,R,E),E.invertToRef(M);var w=n.TmpVectors.Matrix[2],C=t.translation?new n.Vector3(t.translation[0],t.translation[1],t.translation[2]):n.Vector3.Zero();f instanceof n.DirectionalLight&&C.subtractInPlace(i._exporter._babylonScene.useRightHandedSystem?f.direction:l.a._GetRightHandedPositionVector3(f.direction));var B=i._exporter._babylonScene.useRightHandedSystem?n.Quaternion.Identity():new n.Quaternion(0,1,0,0);t.rotation&&B.multiplyInPlace(new n.Quaternion(t.rotation[0],t.rotation[1],t.rotation[2],t.rotation[3]));var P=t.scale?new n.Vector3(t.scale[0],t.scale[1],t.scale[2]):n.Vector3.One();n.Matrix.ComposeToRef(P,B,C,w),w.multiplyToRef(M,w);var I=n.TmpVectors.Vector3[0],N=n.TmpVectors.Quaternion[0],L=n.TmpVectors.Vector3[1];return w.decompose(I,N,L),F.scale=I.asArray(),F.rotation=N.asArray(),F.translation=L.asArray(),null==F.extensions&&(F.extensions={}),F.extensions[c]=A,void a(void 0)}}null==t.extensions&&(t.extensions={}),t.extensions[c]=A}}a(t)})},e}();o.b.RegisterExtension(c,function(e){return new f(e)});var h="KHR_materials_sheen",p=function(){function e(e){this.name=h,this.enabled=!0,this.required=!1,this._textureInfos=[],this._exportedTextures=[],this._wasUsed=!1}return e.prototype.dispose=function(){this._textureInfos=[],this._exportedTextures=[]},Object.defineProperty(e.prototype,"wasUsed",{get:function(){return this._wasUsed},enumerable:!0,configurable:!0}),e.prototype._getTextureIndex=function(e){var t=this._exportedTextures.indexOf(e);return-1===t&&e.reservedDataStore&&(t=this._exportedTextures.indexOf(e.reservedDataStore.source)),t},e.prototype.postExportTexture=function(e,t,r){var n=this._getTextureIndex(r);n>-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;i<a.length;i++){var s=a[i];s instanceof n.StandardMaterial?o.push(this._convertStandardMaterialAsync(s,t,r)):s instanceof n.PBRMetallicRoughnessMaterial?o.push(this._convertPBRMetallicRoughnessMaterialAsync(s,t,r)):s instanceof n.PBRMaterial?o.push(this._convertPBRMaterialAsync(s,t,r)):n.Tools.Warn("Unsupported material type: "+s.name)}return Promise.all(o).then(function(){})},e.prototype._stripTexturesFromMaterial=function(e){var t={};if(e){t.name=e.name,t.doubleSided=e.doubleSided,t.alphaMode=e.alphaMode,t.alphaCutoff=e.alphaCutoff,t.emissiveFactor=e.emissiveFactor;var r=e.pbrMetallicRoughness;r&&(t.pbrMetallicRoughness={},t.pbrMetallicRoughness.baseColorFactor=r.baseColorFactor,t.pbrMetallicRoughness.metallicFactor=r.metallicFactor,t.pbrMetallicRoughness.roughnessFactor=r.roughnessFactor)}return t},e.prototype._hasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},e.prototype._convertToGLTFPBRMetallicRoughness=function(t){var r=new n.Vector2(0,1),o=new n.Vector2(0,.1),i=new n.Vector2(0,.1),a=new n.Vector2(1300,.1);var s=t.diffuseColor.toLinearSpace().scale(.5),u=t.alpha,l=function(e){return function(e,t,r,n,o){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*n+e*e*e*o}(Math.pow(e/a.x,.333333),r.y,o.y,i.y,a.y)}(n.Scalar.Clamp(t.specularPower,0,e._MaxSpecularPower));return{baseColorFactor:[s.r,s.g,s.b,u],metallicFactor:0,roughnessFactor:l}},e._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var o=this._DielectricSpecular.r,i=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,a=i*i-4*o*(this._DielectricSpecular.r-t);return n.Scalar.Clamp((-i+Math.sqrt(a))/(2*o),0,1)},e._SetAlphaMode=function(e,t){t.needAlphaBlending()?e.alphaMode="BLEND":t.needAlphaTesting()&&(e.alphaMode="MASK",e.alphaCutoff=t.alphaCutOff)},e.prototype._convertStandardMaterialAsync=function(t,r,o){var i=this._exporter._materialMap,a=this._exporter._materials,s=[],u=this._convertToGLTFPBRMetallicRoughness(t),l={name:t.name};return null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||n.Tools.Warn(t.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),l.doubleSided=!0),o&&(t.diffuseTexture&&s.push(this._exportTextureAsync(t.diffuseTexture,r).then(function(e){e&&(u.baseColorTexture=e)})),t.bumpTexture&&s.push(this._exportTextureAsync(t.bumpTexture,r).then(function(e){e&&(l.normalTexture=e,null!=t.bumpTexture&&1!==t.bumpTexture.level&&(l.normalTexture.scale=t.bumpTexture.level))})),t.emissiveTexture&&(l.emissiveFactor=[1,1,1],s.push(this._exportTextureAsync(t.emissiveTexture,r).then(function(e){e&&(l.emissiveTexture=e)}))),t.ambientTexture&&s.push(this._exportTextureAsync(t.ambientTexture,r).then(function(e){if(e){var t={index:e.index};l.occlusionTexture=t,t.strength=1}}))),(t.alpha<1||t.opacityTexture)&&(t.alphaMode===n.Constants.ALPHA_COMBINE?l.alphaMode="BLEND":n.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!e.FuzzyEquals(t.emissiveColor,n.Color3.Black(),e._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=u,e._SetAlphaMode(l,t),a.push(l),i[t.uniqueId]=a.length-1,this._finishMaterial(s,l,t,r)},e.prototype._finishMaterial=function(e,t,r,n){var o=this;return Promise.all(e).then(function(){for(var e=null,i=0,a=o._exporter._extensionsPostExportMaterialAdditionalTextures("exportMaterial",t,r);i<a.length;i++){var s=a[i];e||(e=[]),e.push(o._exportTextureAsync(s,n))}return e||(e=[Promise.resolve(null)]),Promise.all(e).then(function(){var e=o._exporter._extensionsPostExportMaterialAsync("exportMaterial",t,r);return e?e.then(function(){return t}):t})})},e.prototype._convertPBRMetallicRoughnessMaterialAsync=function(t,r,o){var i=this._exporter._materialMap,a=this._exporter._materials,s=[],u={};t.baseColor&&(u.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,t.alpha]),null!=t.metallic&&1!==t.metallic&&(u.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(u.roughnessFactor=t.roughness);var l={name:t.name};return t.doubleSided&&(l.doubleSided=t.doubleSided),e._SetAlphaMode(l,t),o&&(null!=t.baseTexture&&s.push(this._exportTextureAsync(t.baseTexture,r).then(function(e){e&&(u.baseColorTexture=e)})),t.normalTexture&&s.push(this._exportTextureAsync(t.normalTexture,r).then(function(e){e&&(l.normalTexture=e,1!==t.normalTexture.level&&(l.normalTexture.scale=t.normalTexture.level))})),t.occlusionTexture&&s.push(this._exportTextureAsync(t.occlusionTexture,r).then(function(e){e&&(l.occlusionTexture=e,null!=t.occlusionStrength&&(l.occlusionTexture.strength=t.occlusionStrength))})),t.emissiveTexture&&s.push(this._exportTextureAsync(t.emissiveTexture,r).then(function(e){e&&(l.emissiveTexture=e)}))),e.FuzzyEquals(t.emissiveColor,n.Color3.Black(),e._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=u,a.push(l),i[t.uniqueId]=a.length-1,this._finishMaterial(s,l,t,r)},e.prototype._createBase64FromCanvasAsync=function(e,t,r,o){var i=this;return new Promise(function(o,a){var s,u=n.Constants.TEXTURETYPE_UNSIGNED_INT,l=i._exporter._getLocalEngine();s=new n.Scene(l);var c=l.createRawTexture(e,t,r,n.Constants.TEXTUREFORMAT_RGBA,!1,!0,n.Texture.NEAREST_SAMPLINGMODE,null,u),f=new n.PostProcess("pass","pass",null,null,1,null,n.Texture.NEAREST_SAMPLINGMODE,l,!1,void 0,n.Constants.TEXTURETYPE_UNSIGNED_INT,void 0,null,!1);f.getEffect().executeWhenCompiled(function(){f.onApply=function(e){e._bindTexture("textureSampler",c)},l.setSize(t,r),s.postProcessManager.directRender([f],null),f.dispose(),c.dispose();var e=l.getRenderingCanvas();if(e)if(e.toBlob)n.Tools.ToBlob(e,function(e){if(e){var t=new FileReader;t.onload=function(e){var t=e.target.result;s.dispose(),o(t)},t.readAsDataURL(e)}else a("gltfMaterialExporter: Failed to get blob from image canvas!")});else{var i=e.toDataURL();o(i)}else a("Engine is missing a canvas!")})})},e.prototype._createWhiteTexture=function(e,t,r){for(var o=new Uint8Array(e*t*4),i=0;i<o.length;i+=4)o[i]=o[i+1]=o[i+2]=o[i+3]=255;return n.RawTexture.CreateRGBATexture(o,e,t,r)},e.prototype._resizeTexturesToSameDimensions=function(e,t,r){var o,i,a=e?e.getSize():{width:0,height:0},s=t?t.getSize():{width:0,height:0};return a.width<s.width?(o=e&&e instanceof n.Texture?n.TextureTools.CreateResizedCopy(e,s.width,s.height,!0):this._createWhiteTexture(s.width,s.height,r),i=t):a.width>s.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;n<t;++n)r[n]=e[n]/255;return r}if(e instanceof Float32Array)return e;throw new Error("Unsupported pixel format!")},e.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(t,r,o,i){var a=[];if(!t&&!r)return Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!");var s=t?t.getScene():r?r.getScene():null;if(s){var u=this._resizeTexturesToSameDimensions(t,r,s),l=u.texture1.getSize(),c=void 0,f=void 0,h=l.width,p=l.height,d=u.texture1.readPixels(),m=u.texture2.readPixels();if(!d)return Promise.reject("Failed to retrieve pixels from diffuse texture!");if(c=this._convertPixelArrayToFloat32(d),!m)return Promise.reject("Failed to retrieve pixels from specular glossiness texture!");for(var g=(f=this._convertPixelArrayToFloat32(m)).byteLength,_=new Uint8Array(g),x=new Uint8Array(g),y=n.Color3.Black(),T=0,v=0,A=0;A<p;++A)for(var b=0;b<h;++b){var F=4*(h*A+b),E={diffuseColor:new n.Color3(c[F],c[F+1],c[F+2]).toLinearSpace().multiply(o.diffuseColor),specularColor:new n.Color3(f[F],f[F+1],f[F+2]).toLinearSpace().multiply(o.specularColor),glossiness:f[F+3]*o.glossiness},M=this._convertSpecularGlossinessToMetallicRoughness(E);y.r=Math.max(y.r,M.baseColor.r),y.g=Math.max(y.g,M.baseColor.g),y.b=Math.max(y.b,M.baseColor.b),T=Math.max(T,M.metallic),v=Math.max(v,M.roughness),x[F]=255*M.baseColor.r,x[F+1]=255*M.baseColor.g,x[F+2]=255*M.baseColor.b,x[F+3]=u.texture1.hasAlpha?255*c[F+3]:255,_[F]=0,_[F+1]=255*M.roughness,_[F+2]=255*M.metallic,_[F+3]=255}var R={baseColor:y,metallic:T,roughness:v},S=!1,V=!1;for(A=0;A<p;++A)for(b=0;b<h;++b){var w=4*(h*A+b);x[w]/=R.baseColor.r>e._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<o.length;++u){var l=o[u];if(l.minFilter===i.minFilter&&l.magFilter===i.magFilter&&l.wrapS===i.wrapS&&l.wrapT===i.wrapT){s=u;break}}null==s?(o.push(i),a=o.length-1):a=s;var c=r.getPixelsFromTexture(e),f=e.getSize();return r._createBase64FromCanvasAsync(c,f.width,f.height,t).then(function(o){var i=r._getTextureInfoFromBase64(o,e.name.replace(/\.\/|\/|\.\\|\\/g,"_"),t,e.coordinatesIndex,a);return i&&(r._textureMap[n]=i,r._exporter._extensionsPostExportTextures("linkTextureInfo",i,e)),i})})},e.prototype._getTextureInfoFromBase64=function(e,t,r,o,i){var a=this._exporter._textures,s=this._exporter._images,u=this._exporter._imageData,l=null,c={source:s.length,name:t};null!=i&&(c.sampler=i);for(var f=atob(e.split(",")[1]),h=new ArrayBuffer(f.length),p=new Uint8Array(h),d=0,m=f.length;d<m;++d)p[d]=f.charCodeAt(d);var g={data:p,mimeType:r},_="image/jpeg"===r?".jpeg":".png",x=t+_,y=x;if(x in u&&(x=t+"_"+n.Tools.RandomId()+_),u[x]=g,"image/jpeg"===r||"image/png"===r){var T={name:t,uri:x},v=null;for(d=0;d<s.length;++d)if(s[d].uri===y){v=d;break}null==v?(s.push(T),c.source=s.length-1):c.source=v,a.push(c),l={index:a.length-1},null!=o&&(l.texCoord=o)}else n.Tools.Error("Unsupported texture mime type "+r);return l},e._DielectricSpecular=new n.Color3(.04,.04,.04),e._MaxSpecularPower=1024,e._Epsilon=1e-6,e}()},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},,function(e,t,r){"use strict";r.r(t),function(e){var n=r(4),o=r(3),i=r(8),a=r(9),s=r(5);r.d(t,"__IGLTFExporterExtension",function(){return n.__IGLTFExporterExtension}),r.d(t,"GLTFData",function(){return s.GLTFData}),r.d(t,"GLTF2Export",function(){return s.GLTF2Export}),r.d(t,"_GLTFAnimation",function(){return s._GLTFAnimation}),r.d(t,"_Exporter",function(){return s._Exporter}),r.d(t,"_BinaryWriter",function(){return s._BinaryWriter}),r.d(t,"__IGLTFExporterExtensionV2",function(){return s.__IGLTFExporterExtensionV2}),r.d(t,"_GLTFMaterialExporter",function(){return s._GLTFMaterialExporter}),r.d(t,"_GLTFUtilities",function(){return s._GLTFUtilities}),r.d(t,"KHR_texture_transform",function(){return s.KHR_texture_transform}),r.d(t,"KHR_lights_punctual",function(){return s.KHR_lights_punctual}),r.d(t,"KHR_materials_sheen",function(){return s.KHR_materials_sheen});var u=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==u){u.BABYLON=u.BABYLON||{};var l=u.BABYLON;l.GLTF2=l.GLTF2||{},l.GLTF2.Exporter=l.GLTF2.Exporter||{},l.GLTF2.Exporter.Extensions=l.GLTF2.Exporter.Extensions||{};var c=[];for(var f in n)l[f]=n[f],c.push(f);for(var f in o)l[f]=o[f],c.push(f);for(var f in i)l[f]=i[f],c.push(f);for(var f in a)l.GLTF2.Exporter.Extensions[f]=a[f],c.push(f);for(var f in s)c.indexOf(f)>-1||(l.GLTF2.Exporter[f]=s[f])}}.call(this,r(11))}])});
|