babylonjs-serializers
Advanced tools
Comparing version 4.0.0-alpha.2 to 4.0.0-alpha.3
@@ -1,1 +0,1 @@ | ||
!(function(e,t){var r=[],n=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(n=n||require("babylonjs"),module.exports=t(n)):"function"==typeof define&&define.amd?(r.push("babylonjs"),define("babylonjs-serializers",r,t)):"object"==typeof exports?(n=n||require("babylonjs"),exports["babylonjs-serializers"]=t(n)):e.BABYLON=t(n)})(this,(function(e){e=e||this.BABYLON;var t,b,r,a,n,W,i,o,s,L,l,u,c,M,f,m,h,p,d,g,_,y,x,T,v;this&&this.__decorate,this&&this.__extends||(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])});return b=e||(e={}),r=(function(){function e(){}return e.OBJ=function(e,t,r,n){var i=[],a=1;t&&(r||(r="mat"),i.push("mtllib "+r+".mtl"));for(var o=0;o<e.length;o++){i.push("g object"+o),i.push("o object_"+o);var s=null;if(n){var l=b.Matrix.Translation(e[o].position.x,e[o].position.y,e[o].position.z);s=b.Matrix.Translation(-e[o].position.x,-e[o].position.y,-e[o].position.z),e[o].bakeTransformIntoVertices(l)}if(t){var u=e[o].material;u&&i.push("usemtl "+u.id)}var c=e[o].geometry;if(c){var f=c.getVerticesData("position"),h=c.getVerticesData("normal"),p=c.getVerticesData("uv"),m=c.getIndices(),d=0;if(f&&m){for(var g=0;g<f.length;g+=3)i.push("v "+f[g]+" "+f[g+1]+" "+f[g+2]),d++;if(null!=h)for(g=0;g<h.length;g+=3)i.push("vn "+h[g]+" "+h[g+1]+" "+h[g+2]);if(null!=p)for(g=0;g<p.length;g+=2)i.push("vt "+p[g]+" "+p[g+1]);for(g=0;g<m.length;g+=3){var _=[String(m[g+2]+a),String(m[g+1]+a),String(m[g]+a)],y=["","",""],x=_,T=null!=p?_:y,v=null!=h?_:y;i.push("f "+x[0]+"/"+T[0]+"/"+v[0]+" "+x[1]+"/"+T[1]+"/"+v[1]+" "+x[2]+"/"+T[2]+"/"+v[2])}n&&s&&e[o].bakeTransformIntoVertices(s),a+=d}else b.Tools.Warn("There are no position vertices or indices on the mesh!")}else b.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var t=[],r=e.material;t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4));return r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e})(),b.OBJExport=r,e.Effect.ShadersStore.textureTransformPixelShader="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}",a=e||(e={}),n=(function(){function e(){}return e.GLTFAsync=function(t,r,n){return t.whenReadyAsync().then((function(){var e=r.replace(/\.[^/.]+$/,"");return new a.GLTF2.Exporter._Exporter(t,n)._generateGLTFAsync(e)}))},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(t,r,n){var i=this;return this._PreExportAsync(t,n).then((function(){var e=r.replace(/\.[^/.]+$/,"");return new a.GLTF2.Exporter._Exporter(t,n)._generateGLBAsync(e).then((function(e){return i._PostExportAsync(t,e,n)}))}))},e})(),a.GLTF2Export=n,W=e||(e={}),(function(z){var e=(function(){function u(e,t){this._extensions={},this._asset={generator:"BabylonJS",version:"2.0"},this._extensionsUsed=[],this._extensionsRequired=[],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._convertToRightHandedSystem=!this._babylonScene.useRightHandedSystem;var r=t||{};this._shouldExportTransformNode=r.shouldExportTransformNode?r.shouldExportTransformNode:function(e){return!0},this._animationSampleRate=r.animationSampleRate?r.animationSampleRate:1/60,this._glTFMaterialExporter=new z._GLTFMaterialExporter(this),this._loadExtensions()}return u.prototype._applyExtensions=function(e,t){for(var r=0,n=u._ExtensionNames;r<n.length;r++){var i=n[r],a=this._extensions[i];if(a.enabled){var o=e;o._activeLoaderExtensions=o._activeLoaderExtensions||{};var s=o._activeLoaderExtensions;if(!s[i]){s[i]=!0;try{var l=t(a);if(l)return l}finally{delete s[i],delete o._activeLoaderExtensions}}}}return null},u.prototype._extensionsPreExportTextureAsync=function(t,r,n){return this._applyExtensions(r,(function(e){return e.preExportTextureAsync&&e.preExportTextureAsync(t,r,n)}))},u.prototype._extensionsPostExportMeshPrimitiveAsync=function(t,r,n,i){return this._applyExtensions(r,(function(e){return e.postExportMeshPrimitiveAsync&&e.postExportMeshPrimitiveAsync(t,r,n,i)}))},u.prototype._loadExtensions=function(){for(var e=0,t=u._ExtensionNames;e<t.length;e++){var r=t[e],n=u._ExtensionFactories[r](this);this._extensions[r]=n}},u.RegisterExtension=function(e,t){u.UnregisterExtension(e)&&W.Tools.Warn("Extension with the name "+e+" already exists"),u._ExtensionFactories[e]=t,u._ExtensionNames.push(e)},u.UnregisterExtension=function(e){if(!u._ExtensionFactories[e])return!1;delete u._ExtensionFactories[e];var t=u._ExtensionNames.indexOf(e);return-1!==t&&u._ExtensionNames.splice(t,1),!0},u.prototype._getLocalEngine=function(){if(!this._localEngine){var e=document.createElement("canvas");e.id="WriteCanvas",e.width=2048,e.height=2048,this._localEngine=new W.Engine(e,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!0}),this._localEngine.setViewport(new W.Viewport(0,0,1,1))}return this._localEngine},u.prototype.reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,i){switch(t){case W.Material.TriangleFillMode:n||(n=0);for(var a=e.indexStart,o=e.indexStart+e.indexCount;a<o;a+=3){var s=n+4*a,l=i.getUInt32(s+4),u=i.getUInt32(s+8);i.setUInt32(u,s+4),i.setUInt32(l,s+8)}break;case W.Material.TriangleFanDrawMode:a=e.indexStart+e.indexCount-1;for(var c=e.indexStart;c<=a;--a)i.setUInt32(r[a],n),n+=4;break;case W.Material.TriangleStripDrawMode:3<=e.indexCount&&(i.setUInt32(r[e.indexStart+2],n+4),i.setUInt32(r[e.indexStart+1],n+8))}},u.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,i,a,o){if(this._convertToRightHandedSystem&&r===W.Material.ClockWiseSideOrientation)switch(t){case W.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,n,i,a,o);break;case W.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,n,i,a,o);break;case W.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,n,i,a,o)}},u.prototype.reorderTriangleFillMode=function(e,t,r,n,i,a,o){var s=this.getVertexBufferFromMesh(n,e.getMesh());if(s){var l=s.byteStride/W.VertexBuffer.GetTypeByteLength(s.type);if(e.verticesCount%3!=0)W.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var u=[],c=0;switch(n){case W.VertexBuffer.PositionKind:case W.VertexBuffer.NormalKind:for(var f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=3)c=f*l,u.push(W.Vector3.FromArray(i,c)),u.push(W.Vector3.FromArray(i,c+2*l)),u.push(W.Vector3.FromArray(i,c+l));break;case W.VertexBuffer.TangentKind:for(f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=3)c=f*l,u.push(W.Vector4.FromArray(i,c)),u.push(W.Vector4.FromArray(i,c+2*l)),u.push(W.Vector4.FromArray(i,c+l));break;case W.VertexBuffer.ColorKind:var h=s.getSize();for(f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=h)c=f*l,4===h?(u.push(W.Vector4.FromArray(i,c)),u.push(W.Vector4.FromArray(i,c+2*l)),u.push(W.Vector4.FromArray(i,c+l))):(u.push(W.Vector3.FromArray(i,c)),u.push(W.Vector3.FromArray(i,c+2*l)),u.push(W.Vector3.FromArray(i,c+l)));break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:for(f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=3)c=f*l,u.push(W.Vector2.FromArray(i,c)),u.push(W.Vector2.FromArray(i,c+2*l)),u.push(W.Vector2.FromArray(i,c+l));break;default:W.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(u,a,n,i,o)}}else W.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+n+" not present!")},u.prototype.reorderTriangleStripDrawMode=function(e,t,r,n,i,a,o){var s=this.getVertexBufferFromMesh(n,e.getMesh());if(s){var l=s.byteStride/W.VertexBuffer.GetTypeByteLength(s.type),u=[],c=0;switch(n){case W.VertexBuffer.PositionKind:case W.VertexBuffer.NormalKind:c=e.verticesStart,u.push(W.Vector3.FromArray(i,c+2*l)),u.push(W.Vector3.FromArray(i,c+l));break;case W.VertexBuffer.TangentKind:for(var f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector4.FromArray(i,c));break;case W.VertexBuffer.ColorKind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,4===s.getSize()?u.push(W.Vector4.FromArray(i,c)):u.push(W.Vector3.FromArray(i,c));break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector2.FromArray(i,c));break;default:W.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(u,a+12,n,i,o)}else W.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+n+" not present!")},u.prototype.reorderTriangleFanMode=function(e,t,r,n,i,a,o){var s=this.getVertexBufferFromMesh(n,e.getMesh());if(s){var l=s.byteStride/W.VertexBuffer.GetTypeByteLength(s.type),u=[],c=0;switch(n){case W.VertexBuffer.PositionKind:case W.VertexBuffer.NormalKind:for(var f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector3.FromArray(i,c));break;case W.VertexBuffer.TangentKind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector4.FromArray(i,c));break;case W.VertexBuffer.ColorKind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector4.FromArray(i,c)),4===s.getSize()?u.push(W.Vector4.FromArray(i,c)):u.push(W.Vector3.FromArray(i,c));break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector2.FromArray(i,c));break;default:W.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(u,a,n,i,o)}else W.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+n+" not present!")},u.prototype.writeVertexAttributeData=function(e,t,r,n,i){for(var a=0,o=e;a<o.length;a++){var s=o[a];!this._convertToRightHandedSystem||r===W.VertexBuffer.ColorKind||s instanceof W.Vector2||(s instanceof W.Vector3?r===W.VertexBuffer.NormalKind?z._GLTFUtilities._GetRightHandedNormalVector3FromRef(s):r===W.VertexBuffer.PositionKind?z._GLTFUtilities._GetRightHandedPositionVector3FromRef(s):W.Tools.Error("Unsupported vertex attribute kind!"):z._GLTFUtilities._GetRightHandedVector4FromRef(s)),r===W.VertexBuffer.NormalKind?s.normalize():r===W.VertexBuffer.TangentKind&&s instanceof W.Vector4&&z._GLTFUtilities._NormalizeTangentFromRef(s);for(var l=0,u=s.asArray();l<u.length;l++){var c=u[l];i.setFloat32(c,t),t+=4}}},u.prototype.writeAttributeData=function(e,t,r,n){var i,a=r/4,o=[];switch(e){case W.VertexBuffer.PositionKind:for(var s=0,l=t.length/a;s<l;++s){i=s*a;var u=W.Vector3.FromArray(t,i);this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedPositionVector3FromRef(u),o.push(u.asArray())}break;case W.VertexBuffer.NormalKind:s=0;for(var c=t.length/a;s<c;++s)i=s*a,u=W.Vector3.FromArray(t,i),this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedNormalVector3FromRef(u),u.normalize(),o.push(u.asArray());break;case W.VertexBuffer.TangentKind:s=0;for(var f=t.length/a;s<f;++s)i=s*a,u=W.Vector4.FromArray(t,i),this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedVector4FromRef(u),z._GLTFUtilities._NormalizeTangentFromRef(u),o.push(u.asArray());break;case W.VertexBuffer.ColorKind:s=0;for(var h=t.length/a;s<h;++s)i=s*a,u=3===a?W.Vector3.FromArray(t,i):W.Vector4.FromArray(t,i),o.push(u.asArray());break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:s=0;for(var p=t.length/a;s<p;++s)i=s*a,o.push((this._convertToRightHandedSystem,[t[i],t[i+1]]));break;default:W.Tools.Warn("Unsupported Vertex Buffer Type: "+e),o=[]}for(var m=0,d=o;m<d.length;m++)for(var g=0,_=d[m];g<_.length;g++){var y=_[g];n.setFloat32(y)}},u.prototype.generateJSON=function(e,t,r){var n,i,a,o=this,s={byteLength:this._totalByteLength},l=this._totalByteLength,u={asset:this._asset};return this._extensionsUsed&&this._extensionsUsed.length&&(u.extensionsUsed=this._extensionsUsed),this._extensionsRequired&&this._extensionsRequired.length&&(u.extensionsRequired=this._extensionsRequired),s.byteLength&&(u.buffers=[s]),this._nodes&&this._nodes.length&&(u.nodes=this._nodes),this._meshes&&this._meshes.length&&(u.meshes=this._meshes),this._scenes&&this._scenes.length&&(u.scenes=this._scenes,u.scene=0),this._bufferViews&&this._bufferViews.length&&(u.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(u.accessors=this._accessors),this._animations&&this._animations.length&&(u.animations=this._animations),this._materials&&this._materials.length&&(u.materials=this._materials),this._textures&&this._textures.length&&(u.textures=this._textures),this._samplers&&this._samplers.length&&(u.samplers=this._samplers),this._images&&this._images.length&&(e?(u.images=[],this._images.forEach((function(e){e.uri&&(i=o._imageData[e.uri],n=e.uri.split(".")[0]+" image",a=z._GLTFUtilities._CreateBufferView(0,l,i.data.length,void 0,n),l+=i.data.buffer.byteLength,o._bufferViews.push(a),e.bufferView=o._bufferViews.length-1,e.name=n,e.mimeType=i.mimeType,e.uri=void 0,u.images||(u.images=[]),u.images.push(e))})),s.byteLength=l):u.images=this._images),e||(s.uri=t+".bin"),r?JSON.stringify(u,null,2):JSON.stringify(u)},u.prototype._generateGLTFAsync=function(s){var l=this;return this._generateBinaryAsync().then((function(e){var t=l.generateJSON(!1,s,!0),r=new Blob([e],{type:"application/octet-stream"}),n=s+".gltf",i=s+".bin",a=new W.GLTFData;if(a.glTFFiles[n]=t,a.glTFFiles[i]=r,l._imageData)for(var o in l._imageData)a.glTFFiles[o]=new Blob([l._imageData[o].data],{type:l._imageData[o].mimeType});return a}))},u.prototype._generateBinaryAsync=function(){var e=this,t=new r(4);return this.createSceneAsync(this._babylonScene,t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},u.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},u.prototype._generateGLBAsync=function(M){var S=this;return this._generateBinaryAsync().then((function(e){var t=S.generateJSON(!0),r=M+".glb",n=t.length,i=0;for(var a in S._imageData)i+=S._imageData[a].data.byteLength;var o=S._getPadding(n),s=S._getPadding(e.byteLength),l=S._getPadding(i),u=28+n+o+e.byteLength+s+i+l,c=new ArrayBuffer(12),f=new DataView(c);f.setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,u,!0);var h=new ArrayBuffer(8+n+o),p=new DataView(h);p.setUint32(0,n+o,!0),p.setUint32(4,1313821514,!0);for(var m=new Uint8Array(h,8),d=0;d<n;++d)m[d]=t.charCodeAt(d);var g=new Uint8Array(h,8+n);for(d=0;d<o;++d)g[d]=32;var _=new ArrayBuffer(8),y=new DataView(_);y.setUint32(0,e.byteLength+i+l,!0),y.setUint32(4,5130562,!0);var x=new ArrayBuffer(s),T=new Uint8Array(x);for(d=0;d<s;++d)T[d]=0;var v=new ArrayBuffer(l),b=new Uint8Array(v);for(d=0;d<l;++d)b[d]=0;var A=[c,h,_,e];for(var a in S._imageData)A.push(S._imageData[a].data.buffer);A.push(x),A.push(v);var F=new Blob(A,{type:"application/octet-stream"}),E=new W.GLTFData;return E.glTFFiles[r]=F,null!=S._localEngine&&S._localEngine.dispose(),E}))},u.prototype.setNodeTransformation=function(e,t){t.getPivotPoint().equalsToFloats(0,0,0)||W.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=this._convertToRightHandedSystem?z._GLTFUtilities._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var r=W.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),0===r.x&&0===r.y&&0===r.z&&1===r.w||(this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedQuaternionFromRef(r),e.rotation=r.normalize().asArray())},u.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},u.prototype.createBufferViewKind=function(e,t,r,n){var i=t instanceof W.Mesh?t:t instanceof W.InstancedMesh?t.sourceMesh:null;if(i){var a=i.getVerticesData(e);if(a){var o=4*a.length,s=z._GLTFUtilities._CreateBufferView(0,r.getByteOffset(),o,n,e+" - "+i.name);this._bufferViews.push(s),this.writeAttributeData(e,a,n,r)}}},u.prototype.getMeshPrimitiveMode=function(e){return e instanceof W.LinesMesh?W.Material.LineListDrawMode:e.material?e.material.fillMode:W.Material.TriangleFillMode},u.prototype.setPrimitiveMode=function(e,t){switch(t){case W.Material.TriangleFillMode:break;case W.Material.TriangleStripDrawMode:e.mode=5;break;case W.Material.TriangleFanDrawMode:e.mode=6;break;case W.Material.PointListDrawMode:e.mode=0;case W.Material.PointFillMode:e.mode=0;break;case W.Material.LineLoopDrawMode:e.mode=2;break;case W.Material.LineListDrawMode:e.mode=1;break;case W.Material.LineStripDrawMode:e.mode=3}},u.prototype.setAttributeKind=function(e,t){switch(t){case W.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case W.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case W.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case W.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case W.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case W.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;default:W.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},u.prototype.setPrimitiveAttributesAsync=function(e,t,r){var n,i,a,o=[],s=null;t instanceof W.Mesh?s=t:t instanceof W.InstancedMesh&&(s=t.sourceMesh);var l=[{kind:W.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:W.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:W.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:W.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:W.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:W.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(s){for(var u=null,c=this.getMeshPrimitiveMode(s),f={},h=0,p=l;h<p.length;h++){var m=(D=p[h]).kind;if(s.isVerticesDataPresent(m)){var d=this.getVertexBufferFromMesh(m,s);D.byteStride=d?4*d.getSize():4*W.VertexBuffer.DeduceStride(m),12===D.byteStride&&(D.accessorType="VEC3"),this.createBufferViewKind(m,t,r,D.byteStride),D.bufferViewIndex=this._bufferViews.length-1,f[m]=D.bufferViewIndex}}if(s.getTotalIndices()){var g=s.getIndices();if(g){var _=4*g.length;n=z._GLTFUtilities._CreateBufferView(0,r.getByteOffset(),_,void 0,"Indices - "+s.name),this._bufferViews.push(n),u=this._bufferViews.length-1;for(var y=0,x=g.length;y<x;++y)r.setUInt32(g[y])}}if(s.subMeshes)for(var T=0,v=s.subMeshes;T<v.length;T++){var b=v[T];i=!1;var A=b.getMaterial()||s.getScene().defaultMaterial,F=null;if(A)if(s instanceof W.LinesMesh){var E={name:s.name+" material"};(!s.color.equals(W.Color3.White())||s.alpha<1)&&(E.pbrMetallicRoughness={baseColorFactor:s.color.asArray().concat([s.alpha])}),this._materials.push(E),F=this._materials.length-1}else if(A instanceof W.MultiMaterial){var M=A.subMaterials[b.materialIndex];M&&(A=M,F=this._materialMap[A.uniqueId])}else F=this._materialMap[A.uniqueId];var S=null!=F?this._materials[F]:null,R={attributes:{}};this.setPrimitiveMode(R,c);for(var V=0,C=l;V<C.length;V++)if(((m=(D=C[V]).kind)!==W.VertexBuffer.UVKind&&m!==W.VertexBuffer.UV2Kind||!S||this._glTFMaterialExporter._hasTexturesPresent(S))&&(O=s.getVerticesData(m))&&(d=this.getVertexBufferFromMesh(m,s))){var w=d.getSize(),B=D.bufferViewIndex;if(null!=B){a={min:null,max:null},m==W.VertexBuffer.PositionKind&&(a=z._GLTFUtilities._CalculateMinMaxPositions(O,0,O.length/w,this._convertToRightHandedSystem));var L=z._GLTFUtilities._CreateAccessor(B,m+" - "+t.name,D.accessorType,5126,O.length/w,0,a.min,a.max);this._accessors.push(L),this.setAttributeKind(R,m),null==R.attributes.TEXCOORD_0&&null==R.attributes.TEXCOORD_1||(i=!0)}}if(u&&(L=z._GLTFUtilities._CreateAccessor(u,"indices - "+t.name,"SCALAR",5125,b.indexCount,4*b.indexStart,null,null),this._accessors.push(L),R.indices=this._accessors.length-1),null!=F&&0<Object.keys(R.attributes).length){var P=A.sideOrientation;if(this._convertToRightHandedSystem&&P===W.Material.ClockWiseSideOrientation){var N=null!=u?this._bufferViews[u].byteOffset:null;null==N&&(N=0);var G=null;if(null!=u&&(G=s.getIndices()),G)this.reorderIndicesBasedOnPrimitiveMode(b,c,G,N,r);else for(var I=0,U=l;I<U.length;I++){var O,D=U[I];if(O=s.getVerticesData(D.kind)){var k=this._bufferViews[f[D.kind]].byteOffset;k||(k=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(b,c,P,D.kind,O,k,r)}}}if(!i&&this._glTFMaterialExporter._hasTexturesPresent(this._materials[F])){var K=this._glTFMaterialExporter._stripTexturesFromMaterial(this._materials[F]);this._materials.push(K),F=this._materials.length-1}R.material=F}e.primitives.push(R),this._extensionsPostExportMeshPrimitiveAsync("postExport",R,b,r)&&o.push()}}return Promise.all(o).then((function(){}))},u.prototype.createSceneAsync=function(e,l){var u,c,f,h=this,p={nodes:[]},m=e.transformNodes.concat(e.meshes);return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(e.materials,"image/png",!0).then((function(){return h.createNodeMapAndAnimationsAsync(e,m,h._shouldExportTransformNode,l).then((function(e){if(h._nodeMap=e,h._totalByteLength=l.getByteOffset(),null==h._totalByteLength)throw new Error("undefined byte length!");for(var t=0,r=m;t<r.length;t++){var n=r[t];if(null!=(u=h._nodeMap[n.uniqueId])&&(c=h._nodes[u],n.parent||(h._shouldExportTransformNode(n)?(h._convertToRightHandedSystem&&(c.translation&&(c.translation[2]*=-1,c.translation[0]*=-1),c.rotation=c.rotation?W.Quaternion.FromArray([0,1,0,0]).multiply(W.Quaternion.FromArray(c.rotation)).asArray():W.Quaternion.FromArray([0,1,0,0]).asArray()),p.nodes.push(u)):W.Tools.Log("Omitting "+n.name+" from scene.")),f=n.getDescendants(!0),!c.children&&f&&f.length)){for(var i=[],a=0,o=f;a<o.length;a++){var s=o[a];null!=h._nodeMap[s.uniqueId]&&i.push(h._nodeMap[s.uniqueId])}i.length&&(c.children=i)}}p.nodes.length&&h._scenes.push(p)}))}))},u.prototype.createNodeMapAndAnimationsAsync=function(r,e,n,i){for(var a,o=this,s=Promise.resolve(),l={},u={name:"runtime animations",channels:[],samplers:[]},c=[],t=function(t){n(t)?s=s.then((function(){return o.createNodeAsync(t,i).then((function(e){(t.getDescendants(!0,(function(e){return e instanceof W.TransformNode})).length||null!=e.mesh)&&(o._nodes.push(e),a=o._nodes.length-1,l[t.uniqueId]=a),!r.animationGroups.length&&t.animations.length&&z._GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations(t,u,c,l,o._nodes,i,o._bufferViews,o._accessors,o._convertToRightHandedSystem,o._animationSampleRate)}))})):t.name},f=0,h=e;f<h.length;f++)t(h[f]);return s.then((function(){return u.channels.length&&u.samplers.length&&o._animations.push(u),c.forEach((function(e){e.channels.length&&e.samplers.length&&o._animations.push(e)})),r.animationGroups.length&&z._GLTFAnimation._CreateNodeAnimationFromAnimationGroups(r,o._animations,l,o._nodes,i,o._bufferViews,o._accessors,o._convertToRightHandedSystem,o._animationSampleRate),l}))},u.prototype.createNodeAsync=function(r,n){var i=this;return Promise.resolve().then((function(){var e={},t={primitives:[]};return r.name&&(e.name=r.name),i.setNodeTransformation(e,r),i.setPrimitiveAttributesAsync(t,r,n).then((function(){return t.primitives.length&&(i._meshes.push(t),e.mesh=i._meshes.length-1),e}))}))},u._ExtensionNames=new Array,u._ExtensionFactories={},u})();z._Exporter=e;var r=(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),i=0,a=n.byteLength;i<a;++i)n[i]=r[i];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):W.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 W.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?W.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?W.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?W.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?W.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)&&W.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):W.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):W.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})();z._BinaryWriter=r})((i=W.GLTF2||(W.GLTF2={})).Exporter||(i.Exporter={})),o=e||(e={}),s=(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],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],i)),r.click()}},e})(),o.GLTFData=s,L=e||(e={}),l=L.GLTF2||(L.GLTF2={}),u=l.Exporter||(l.Exporter={}),c=(function(){function B(e){this._textureMap={},this._textureMap={},this._exporter=e}return B.FuzzyEquals=function(e,t,r){return L.Scalar.WithinEpsilon(e.r,t.r,r)&&L.Scalar.WithinEpsilon(e.g,t.g,r)&&L.Scalar.WithinEpsilon(e.b,t.b,r)},B.prototype._convertMaterialsToGLTFAsync=function(e,t,r){for(var n=[],i=0,a=e;i<a.length;i++){var o=a[i];o instanceof L.StandardMaterial?n.push(this._convertStandardMaterialAsync(o,t,r)):o instanceof L.PBRMetallicRoughnessMaterial?n.push(this._convertPBRMetallicRoughnessMaterialAsync(o,t,r)):o instanceof L.PBRMaterial?n.push(this._convertPBRMaterialAsync(o,t,r)):L.Tools.Warn("Unsupported material type: "+o.name)}return Promise.all(n).then((function(){}))},B.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},B.prototype._hasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},B.prototype._convertToGLTFPBRMetallicRoughness=function(e){var t,r,n,i,a,o,s,l=new L.Vector2(0,1),u=new L.Vector2(0,.1),c=new L.Vector2(0,.1),f=new L.Vector2(1300,.1),h=e.diffuseColor.toLinearSpace().scale(.5),p=e.alpha,m=L.Scalar.Clamp(e.specularPower,0,B._MaxSpecularPower),d=(t=m,s=Math.pow(t/f.x,.333333),r=s,n=l.y,i=u.y,a=c.y,o=f.y,(1-r)*(1-r)*(1-r)*n+3*(1-r)*(1-r)*r*i+3*(1-r)*r*r*a+r*r*r*o);return{baseColorFactor:[h.r,h.g,h.b,p],metallicFactor:0,roughnessFactor:d}},B._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,i=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,a=i*i-4*n*(this._DielectricSpecular.r-t);return L.Scalar.Clamp((-i+Math.sqrt(a))/(2*n),0,1)},B.prototype._getAlphaMode=function(e){return e.needAlphaBlending()?"BLEND":e.needAlphaTesting()?"MASK":"OPAQUE"},B.prototype._convertStandardMaterialAsync=function(t,e,r){var n=this._exporter._materialMap,i=this._exporter._materials,a=this._getAlphaMode(t),o=[],s=this._convertToGLTFPBRMetallicRoughness(t),l={name:t.name};if(null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||L.Tools.Warn(t.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),l.doubleSided=!0),r&&(t.diffuseTexture&&o.push(this._exportTextureAsync(t.diffuseTexture,e).then((function(e){e&&(s.baseColorTexture=e)}))),t.bumpTexture&&o.push(this._exportTextureAsync(t.bumpTexture,e).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],o.push(this._exportTextureAsync(t.emissiveTexture,e).then((function(e){e&&(l.emissiveTexture=e)})))),t.ambientTexture&&o.push(this._exportTextureAsync(t.ambientTexture,e).then((function(e){if(e){var t={index:e.index};(l.occlusionTexture=t).strength=1}})))),(t.alpha<1||t.opacityTexture)&&(t.alphaMode===L.Engine.ALPHA_COMBINE?l.alphaMode="BLEND":L.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!B.FuzzyEquals(t.emissiveColor,L.Color3.Black(),B._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=s,"OPAQUE"!==a)switch(a){case"BLEND":l.alphaMode="BLEND";break;case"MASK":l.alphaMode="MASK",l.alphaCutoff=t.alphaCutOff;break;default:L.Tools.Warn("Unsupported alpha mode "+a)}return i.push(l),n[t.uniqueId]=i.length-1,Promise.all(o).then((function(){}))},B.prototype._convertPBRMetallicRoughnessMaterialAsync=function(t,e,r){var n=this._exporter._materialMap,i=this._exporter._materials,a=[],o={};t.baseColor&&(o.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,t.alpha]),null!=t.metallic&&1!==t.metallic&&(o.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(o.roughnessFactor=t.roughness);var s={name:t.name};t.doubleSided&&(s.doubleSided=t.doubleSided);var l=null;return null!=t.transparencyMode&&(l=this._getAlphaMode(t))&&"OPAQUE"!==l&&"MASK"===(s.alphaMode=l)&&(s.alphaCutoff=t.alphaCutOff),r&&(null!=t.baseTexture&&a.push(this._exportTextureAsync(t.baseTexture,e).then((function(e){e&&(o.baseColorTexture=e)}))),t.normalTexture&&a.push(this._exportTextureAsync(t.normalTexture,e).then((function(e){e&&(s.normalTexture=e,1!==t.normalTexture.level&&(s.normalTexture.scale=t.normalTexture.level))}))),t.occlusionTexture&&a.push(this._exportTextureAsync(t.occlusionTexture,e).then((function(e){e&&(s.occlusionTexture=e,null!=t.occlusionStrength&&(s.occlusionTexture.strength=t.occlusionStrength))}))),t.emissiveTexture&&a.push(this._exportTextureAsync(t.emissiveTexture,e).then((function(e){e&&(s.emissiveTexture=e)})))),B.FuzzyEquals(t.emissiveColor,L.Color3.Black(),B._Epsilon)&&(s.emissiveFactor=t.emissiveColor.asArray()),s.pbrMetallicRoughness=o,i.push(s),n[t.uniqueId]=i.length-1,Promise.all(a).then((function(){}))},B.prototype._createBase64FromCanvasAsync=function(t,l,u,e){var c=this;return new Promise(function(r,n){var i,e=L.Engine.TEXTURETYPE_UNSIGNED_INT,a=c._exporter._getLocalEngine();i=new L.Scene(a);var o=a.createRawTexture(t,l,u,L.Engine.TEXTUREFORMAT_RGBA,!1,!0,L.Texture.NEAREST_SAMPLINGMODE,null,e),s=new L.PostProcess("pass","pass",null,null,1,null,L.Texture.NEAREST_SAMPLINGMODE,a,!1,void 0,L.Engine.TEXTURETYPE_UNSIGNED_INT,void 0,null,!1);s.getEffect().executeWhenCompiled((function(){s.onApply=function(e){e._bindTexture("textureSampler",o)},a.setSize(l,u),i.postProcessManager.directRender([s],null),s.dispose(),o.dispose();var e=a.getRenderingCanvas();if(e)if(e.toBlob)L.Tools.ToBlob(e,(function(e){if(e){var t=new FileReader;t.onload=function(e){var t=e.target.result;i.dispose(),r(t)},t.readAsDataURL(e)}else n("gltfMaterialExporter: Failed to get blob from image canvas!")}));else{var t=e.toDataURL();r(t)}else n("Engine is missing a canvas!")}))})},B.prototype._createWhiteTexture=function(e,t,r){for(var n=new Uint8Array(e*t*4),i=0;i<n.length;i+=4)n[i]=n[i+1]=n[i+2]=n[i+3]=255;return L.RawTexture.CreateRGBATexture(n,e,t,r)},B.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,i,a=e?e.getSize():{width:0,height:0},o=t?t.getSize():{width:0,height:0};return a.width<o.width?(n=e&&e instanceof L.Texture?L.TextureTools.CreateResizedCopy(e,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),i=t):a.width>o.width?(i=t&&t instanceof L.Texture?L.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):this._createWhiteTexture(a.width,a.height,r),n=e):(n=e,i=t),{texture1:n,texture2:i}},B.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!")},B.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){var i=[];if(!e&&!t)return Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!");var a=e?e.getScene():t?t.getScene():null;if(a){var o=this._resizeTexturesToSameDimensions(e,t,a),s=o.texture1.getSize(),l=void 0,u=void 0,c=s.width,f=s.height,h=o.texture1.readPixels(),p=o.texture2.readPixels();if(!h)return Promise.reject("Failed to retrieve pixels from diffuse texture!");if(l=this._convertPixelArrayToFloat32(h),!p)return Promise.reject("Failed to retrieve pixels from specular glossiness texture!");for(var m=(u=this._convertPixelArrayToFloat32(p)).byteLength,d=new Uint8Array(m),g=new Uint8Array(m),_=L.Color3.Black(),y=0,x=0,T=0;T<f;++T)for(var v=0;v<c;++v){var b=4*(c*T+v),A={diffuseColor:new L.Color3(l[b],l[b+1],l[b+2]).toLinearSpace().multiply(r.diffuseColor),specularColor:new L.Color3(u[b],u[b+1],u[b+2]).toLinearSpace().multiply(r.specularColor),glossiness:u[b+3]*r.glossiness},F=this._convertSpecularGlossinessToMetallicRoughness(A);_.r=Math.max(_.r,F.baseColor.r),_.g=Math.max(_.g,F.baseColor.g),_.b=Math.max(_.b,F.baseColor.b),y=Math.max(y,F.metallic),x=Math.max(x,F.roughness),g[b]=255*F.baseColor.r,g[b+1]=255*F.baseColor.g,g[b+2]=255*F.baseColor.b,g[b+3]=o.texture1.hasAlpha?255*l[b+3]:255,d[b]=0,d[b+1]=255*F.roughness,d[b+2]=255*F.metallic,d[b+3]=255}var E={baseColor:_,metallic:y,roughness:x},M=!1,S=!1;for(T=0;T<f;++T)for(v=0;v<c;++v){var R=4*(c*T+v);g[R]/=E.baseColor.r>B._Epsilon?E.baseColor.r:1,g[R+1]/=E.baseColor.g>B._Epsilon?E.baseColor.g:1,g[R+2]/=E.baseColor.b>B._Epsilon?E.baseColor.b:1;var V=L.Color3.FromInts(g[R],g[R+1],g[R+2]).toGammaSpace();g[R]=255*V.r,g[R+1]=255*V.g,g[R+2]=255*V.b,B.FuzzyEquals(V,L.Color3.White(),B._Epsilon)||(S=!0),d[R+1]/=E.roughness>B._Epsilon?E.roughness:1,d[R+2]/=E.metallic>B._Epsilon?E.metallic:1;var C=L.Color3.FromInts(255,d[R+1],d[R+2]);B.FuzzyEquals(C,L.Color3.White(),B._Epsilon)||(M=!0)}if(M){var w=this._createBase64FromCanvasAsync(d,c,f,n).then((function(e){E.metallicRoughnessTextureBase64=e}));i.push(w)}return S&&(w=this._createBase64FromCanvasAsync(g,c,f,n).then((function(e){E.baseColorTextureBase64=e})),i.push(w)),Promise.all(i).then((function(){return E}))}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},B.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),i=B._SolveMetallic(t,r,n),a=e.diffuseColor.scale(n/(1-B._DielectricSpecular.r)/Math.max(1-i,B._Epsilon)),o=e.specularColor.subtract(B._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,B._Epsilon)),s=L.Color3.Lerp(a,o,i*i);return{baseColor:s=s.clampToRef(0,1,s),metallic:i,roughness:1-e.glossiness}},B.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},B.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},B.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var i=[],a={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return n&&(e.albedoTexture&&i.push(this._exportTextureAsync(e.albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),e.metallicTexture&&i.push(this._exportTextureAsync(e.metallicTexture,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),Promise.all(i).then((function(){return a}))},B.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof L.Texture?e.samplingMode:null;if(null!=r)switch(r){case L.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case L.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case L.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case L.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case L.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case L.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case L.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case L.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case L.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case L.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case L.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case L.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},B.prototype._getGLTFTextureWrapMode=function(e){switch(e){case L.Texture.WRAP_ADDRESSMODE:return 10497;case L.Texture.CLAMP_ADDRESSMODE:return 33071;case L.Texture.MIRROR_ADDRESSMODE:return 33648;default:return L.Tools.Error("Unsupported Texture Wrap Mode "+e+"!"),10497}},B.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof L.Texture?e.wrapU:L.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof L.Texture?e.wrapV:L.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},B.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(a,o,s,l){var u=this;return Promise.resolve().then((function(){var e=u._exporter._samplers,n=u._exporter._textures,t={diffuseColor:a.albedoColor||L.Color3.White(),specularColor:a.reflectivityColor||L.Color3.White(),glossiness:a.microSurface||1},i=null,r=u._getGLTFTextureSampler(a.albedoTexture);return null!=r.magFilter&&null!=r.minFilter&&null!=r.wrapS&&null!=r.wrapT&&(e.push(r),i=e.length-1),a.reflectivityTexture&&!a.useMicroSurfaceFromReflectivityMapAlpha?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(a.albedoTexture||a.reflectivityTexture)&&l?u._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a.albedoTexture,a.reflectivityTexture,t,o).then((function(e){if(e.baseColorTextureBase64){var t=u._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+n.length+".png",o,a.albedoTexture?a.albedoTexture.coordinatesIndex:null,i);t&&(s.baseColorTexture=t)}if(e.metallicRoughnessTextureBase64){var r=u._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+n.length+".png",o,a.reflectivityTexture?a.reflectivityTexture.coordinatesIndex:null,i);r&&(s.metallicRoughnessTexture=r)}return e})):u._convertSpecularGlossinessToMetallicRoughness(t)}))},B.prototype._convertPBRMaterialAsync=function(t,r,n){var i=this,a={},o={name:t.name};return t.isMetallicWorkflow()?(t.albedoColor&&(a.baseColorFactor=[t.albedoColor.r,t.albedoColor.g,t.albedoColor.b,t.alpha]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(t,r,a,n).then((function(e){return i.setMetallicRoughnessPbrMaterial(e,t,o,a,r,n)}))):this._convertSpecGlossFactorsToMetallicRoughnessAsync(t,r,a,n).then((function(e){return i.setMetallicRoughnessPbrMaterial(e,t,o,a,r,n)}))},B.prototype.setMetallicRoughnessPbrMaterial=function(e,r,n,t,i,a){var o=this._exporter._materialMap,s=this._exporter._materials,l=[];if(e){var u=null;if(null!=r.transparencyMode&&(u=this._getAlphaMode(r))&&"OPAQUE"!==u&&"MASK"===(n.alphaMode=u)&&(n.alphaCutoff=r.alphaCutOff),B.FuzzyEquals(e.baseColor,L.Color3.White(),B._Epsilon)&&r.alpha>=B._Epsilon||(t.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,r.alpha]),null!=e.metallic&&1!==e.metallic&&(t.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(t.roughnessFactor=e.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||L.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),a){if(r.bumpTexture){var c=this._exportTextureAsync(r.bumpTexture,i).then((function(e){e&&(n.normalTexture=e,1!==r.bumpTexture.level&&(n.normalTexture.scale=r.bumpTexture.level))}));l.push(c)}r.ambientTexture&&(c=this._exportTextureAsync(r.ambientTexture,i).then((function(e){if(e){var t={index:e.index};n.occlusionTexture=t,r.ambientTextureStrength&&(t.strength=r.ambientTextureStrength)}})),l.push(c)),r.emissiveTexture&&(c=this._exportTextureAsync(r.emissiveTexture,i).then((function(e){e&&(n.emissiveTexture=e)})),l.push(c))}B.FuzzyEquals(r.emissiveColor,L.Color3.Black(),B._Epsilon)||(n.emissiveFactor=r.emissiveColor.asArray()),n.pbrMetallicRoughness=t,s.push(n),o[r.uniqueId]=s.length-1}return Promise.all(l).then((function(e){}))},B.prototype.getPixelsFromTexture=function(e){return e.textureType,L.Engine.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},B.prototype._exportTextureAsync=function(t,r){var n=this,e=this._exporter._extensionsPreExportTextureAsync("exporter",t,r);return e?e.then((function(e){return e?n._exportTextureInfoAsync(e,r):n._exportTextureInfoAsync(t,r)})):this._exportTextureInfoAsync(t,r)},B.prototype._exportTextureInfoAsync=function(u,c){var f=this;return Promise.resolve().then((function(){var r=u.uid;if(r in f._textureMap)return f._textureMap[r];for(var e=f._exporter._samplers,t=f._getGLTFTextureSampler(u),n=null,i=null,a=0;a<e.length;++a){var o=e[a];if(o.minFilter===t.minFilter&&o.magFilter===t.magFilter&&o.wrapS===t.wrapS&&o.wrapT===t.wrapT){i=a;break}}null==i?(e.push(t),n=e.length-1):n=i;var s=f.getPixelsFromTexture(u),l=u.getSize();return f._createBase64FromCanvasAsync(s,l.width,l.height,c).then((function(e){var t=f._getTextureInfoFromBase64(e,u.name.replace(/\.\/|\/|\.\\|\\/g,"_"),c,u.coordinatesIndex,n);return t&&(f._textureMap[r]=t),t}))}))},B.prototype._getTextureInfoFromBase64=function(e,t,r,n,i){var a=this._exporter._textures,o=this._exporter._images,s=this._exporter._imageData,l=null,u={source:o.length,name:t};null!=i&&(u.sampler=i);for(var c=atob(e.split(",")[1]),f=new ArrayBuffer(c.length),h=new Uint8Array(f),p=0,m=c.length;p<m;++p)h[p]=c.charCodeAt(p);var d={data:h,mimeType:r},g="image/jpeg"===r?".jpeg":".png",_=t+g;if(_ in s&&(_=t+"_"+L.Tools.RandomId()+g),s[_]=d,"image/jpeg"===r||"image/png"===r){var y={name:t,uri:_},x=null;for(p=0;p<o.length;++p)if(o[p].uri===_){x=p;break}null==x?(o.push(y),u.source=o.length-1):u.source=x,a.push(u),l={index:a.length-1},null!=n&&(l.texCoord=n)}else L.Tools.Error("Unsupported texture mime type "+r);return l},B._DielectricSpecular=new L.Color3(.04,.04,.04),B._MaxSpecularPower=1024,B._Epsilon=1e-6,B})(),u._GLTFMaterialExporter=c,M=e||(e={}),(function(A){var h,e;(e=h||(h={}))[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT";var t=(function(){function E(){}return E._CreateNodeAnimation=function(e,t,r,n,i,a){var o=[],s=[],l=t.getKeys(),u=E.calculateMinMaxKeyFrames(l),c=E._DeduceInterpolation(l,r,i),f=u.max-u.min,h=c.interpolationType,p=c.shouldBakeAnimation;return p?E._CreateBakedAnimation(e,t,r,u.min,u.max,t.framePerSecond,a,o,s,u,n,i):"LINEAR"===h||"STEP"===h?E._CreateLinearOrStepAnimation(e,t,r,f,o,s,n,i):"CUBICSPLINE"===h?E._CreateCubicSplineAnimation(e,t,r,f,o,s,n,i):E._CreateBakedAnimation(e,t,r,u.min,u.max,t.framePerSecond,a,o,s,u,n,i),o.length&&s.length?{inputs:o,outputs:s,samplerInterpolation:h,inputsMin:p?u.min:M.Tools.FloatRound(u.min/t.framePerSecond),inputsMax:p?u.max:M.Tools.FloatRound(u.max/t.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:M.Tools.Error("Unsupported animatable property "+i[0])}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(M.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},E._CreateNodeAnimationFromTransformNodeAnimations=function(e,t,r,n,i,a,o,s,l,u){var c;if(e.animations)for(var f=0,h=e.animations;f<h.length;f++){var p=h[f],m=E._DeduceAnimationInfo(p);m&&(c={name:p.name,samplers:[],channels:[]},E.AddAnimation(""+p.name,p.hasRunningRuntimeAnimations?t:c,e,p,m.dataAccessorType,m.animationChannelTargetPath,n,a,o,s,l,m.useQuaternion,u),c.samplers.length&&c.channels.length&&r.push(c))}},E._CreateNodeAnimationFromAnimationGroups=function(e,t,r,n,i,a,o,s,l){var u;if(e.animationGroups)for(var c=0,f=e.animationGroups;c<f.length;c++){var h=f[c];u={name:h.name,channels:[],samplers:[]};for(var p=0,m=h.targetedAnimations;p<m.length;p++){var d=m[p],g=d.target,_=d.animation;if(g instanceof M.Mesh||1===g.length&&g[0]instanceof M.Mesh){var y=E._DeduceAnimationInfo(d.animation);if(y){var x=g instanceof M.Mesh?g:g[0];E.AddAnimation(""+_.name,u,x,_,y.dataAccessorType,y.animationChannelTargetPath,r,i,a,o,s,y.useQuaternion,l)}}}u.channels.length&&u.samplers.length&&t.push(u)}},E.AddAnimation=function(e,t,r,n,i,a,o,s,l,u,c,f,h){var p,m,d,g,_,y,x,T=E._CreateNodeAnimation(r,n,a,c,f,h);if(T){var v=o[r.uniqueId],b=4*T.inputs.length;p=A._GLTFUtilities._CreateBufferView(0,s.getByteOffset(),b,void 0,e+" keyframe data view"),l.push(p),T.inputs.forEach((function(e){s.setFloat32(e)})),m=A._GLTFUtilities._CreateAccessor(l.length-1,e+" keyframes","SCALAR",5126,T.inputs.length,null,[T.inputsMin],[T.inputsMax]),u.push(m),d=u.length-1,_=T.outputs.length,b="VEC3"===i?12*T.outputs.length:16*T.outputs.length,p=A._GLTFUtilities._CreateBufferView(0,s.getByteOffset(),b,void 0,e+" data view"),l.push(p),T.outputs.forEach((function(e){e.forEach((function(e){s.setFloat32(e)}))})),m=A._GLTFUtilities._CreateAccessor(l.length-1,e+" data",i,5126,_,null,null,null),u.push(m),g=u.length-1,y={interpolation:T.samplerInterpolation,input:d,output:g},t.samplers.push(y),x={sampler:t.samplers.length-1,target:{node:v,path:a}},t.channels.push(x)}},E._CreateBakedAnimation=function(e,t,r,n,i,a,o,s,l,u,c,f){var h,p,m=M.Quaternion.Identity(),d=null,g=null,_=null,y=null,x=null,T=null;u.min=M.Tools.FloatRound(n/a);for(var v=t.getKeys(),b=0,A=v.length;b<A;++b){if(T=null,_=v[b],b+1<A)if(y=v[b+1],_.value.equals(y.value)){if(0!==b)continue;T=_.frame}else T=y.frame;else{if(x=v[b-1],_.value.equals(x.value))continue;T=i}if(T)for(var F=_.frame;F<=T;F+=o)(p=M.Tools.FloatRound(F/a))!==d&&(g=d=p,h=t._interpolate(F,0,void 0,t.loopMode),E._SetInterpolatedValue(e,h,p,t,r,m,s,l,c,f))}g&&(u.max=g)},E._ConvertFactorToVector3OrQuaternion=function(e,t,r,n,i,a,o){var s,l,u=null,c=E._GetBasePositionRotationOrScale(t,i,a,o);if(n===M.Animation.ANIMATIONTYPE_FLOAT)switch(l=(s=r.targetProperty.split("."))?s[1]:"",u=o?M.Quaternion.FromArray(c).normalize():M.Vector3.FromArray(c),l){case"x":case"y":u[l]=a&&o&&"scale"!==i?-e:e;break;case"z":u[l]=a&&!o&&"scale"!==i?-e:e;break;case"w":u.w=e;break;default:M.Tools.Error('glTFAnimation: Unsupported component type "'+l+'" for scale animation!')}return u},E._SetInterpolatedValue=function(e,t,r,n,i,a,o,s,l,u){var c,f=n.dataType;o.push(r),"number"==typeof t&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,f,i,l,u)),t&&("rotation"===i?(u?a=t:(c=t,M.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),l&&(A._GLTFUtilities._GetRightHandedQuaternionFromRef(a),e.parent||(a=M.Quaternion.FromArray([0,1,0,0]).multiply(a))),s.push(a.asArray())):(c=t,l&&"scale"!==i&&(A._GLTFUtilities._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray())))},E._CreateLinearOrStepAnimation=function(e,t,r,n,i,a,o,s){for(var l=0,u=t.getKeys();l<u.length;l++){var c=u[l];i.push(c.frame/t.framePerSecond),E._AddKeyframeValue(c,t,a,r,e,o,s)}},E._CreateCubicSplineAnimation=function(t,r,n,i,a,o,s,l){r.getKeys().forEach((function(e){a.push(e.frame/r.framePerSecond),E.AddSplineTangent(t,h.INTANGENT,o,n,"CUBICSPLINE",e,i,l,s),E._AddKeyframeValue(e,r,o,n,t,s,l),E.AddSplineTangent(t,h.OUTTANGENT,o,n,"CUBICSPLINE",e,i,l,s)}))},E._GetBasePositionRotationOrScale=function(e,t,r,n){var i;return"rotation"===t?n?e.rotationQuaternion?(i=e.rotationQuaternion.asArray(),r&&(A._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(i),e.parent||(i=M.Quaternion.FromArray([0,1,0,0]).multiply(M.Quaternion.FromArray(i)).asArray()))):i=M.Quaternion.Identity().asArray():(i=e.rotation.asArray(),A._GLTFUtilities._GetRightHandedNormalArray3FromRef(i)):"translation"===t?(i=e.position.asArray(),r&&A._GLTFUtilities._GetRightHandedPositionArray3FromRef(i)):i=e.scaling.asArray(),i},E._AddKeyframeValue=function(e,t,r,n,i,a,o){var s,l,u=t.dataType;if(u===M.Animation.ANIMATIONTYPE_VECTOR3){if(s=e.value.asArray(),"rotation"===n){var c=M.Vector3.FromArray(s),f=M.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z);a&&(A._GLTFUtilities._GetRightHandedQuaternionFromRef(f),i.parent||(f=M.Quaternion.FromArray([0,1,0,0]).multiply(f))),s=f.asArray()}else"translation"===n&&a&&(A._GLTFUtilities._GetRightHandedNormalArray3FromRef(s),i.parent||(s[0]*=-1,s[2]*=-1));r.push(s)}else if(u===M.Animation.ANIMATIONTYPE_FLOAT){if(l=this._ConvertFactorToVector3OrQuaternion(e.value,i,t,u,n,a,o)){if("rotation"===n){var h=o?l:M.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).normalize();a&&(A._GLTFUtilities._GetRightHandedQuaternionFromRef(h),i.parent||(h=M.Quaternion.FromArray([0,1,0,0]).multiply(h))),r.push(h.asArray())}else"translation"===n&&a&&(A._GLTFUtilities._GetRightHandedNormalVector3FromRef(l),i.parent||(l.x*=-1,l.z*=-1));r.push(l.asArray())}}else u===M.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),a&&(A._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(s),i.parent||(s=M.Quaternion.FromArray([0,1,0,0]).multiply(M.Quaternion.FromArray(s)).asArray())),r.push(s)):M.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 o=0,s=e.length;o<s;++o)if((i=e[o]).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===M.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=i.interpolation&&i.interpolation===M.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},E.AddSplineTangent=function(e,t,r,n,i,a,o,s,l){var u,c=t===h.INTANGENT?a.inTangent:a.outTangent;if("CUBICSPLINE"===i){if("rotation"===n)if(c){if(s)u=c.scale(o).asArray();else{var f=c.scale(o);u=M.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z).asArray()}l&&(A._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(u),e.parent||(u=M.Quaternion.FromArray([0,1,0,0]).multiply(M.Quaternion.FromArray(u)).asArray()))}else u=[0,0,0,0];else c?(u=c.scale(o).asArray(),l&&"translation"===n&&(A._GLTFUtilities._GetRightHandedPositionArray3FromRef(u),e.parent||(u[0]*=-1,u[2]*=-1))):u=[0,0,0];r.push(u)}},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})();A._GLTFAnimation=t})((f=M.GLTF2||(M.GLTF2={})).Exporter||(f.Exporter={})),m=e||(e={}),h=m.GLTF2||(m.GLTF2={}),p=h.Exporter||(h.Exporter={}),d=(function(){function p(){}return p._CreateBufferView=function(e,t,r,n,i){var a={buffer:e,byteLength:r};return t&&(a.byteOffset=t),i&&(a.name=i),n&&(a.byteStride=n),a},p._CreateAccessor=function(e,t,r,n,i,a,o,s){var l={name:t,bufferView:e,componentType:n,count:i,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=a&&(l.byteOffset=a),l},p._CalculateMinMaxPositions=function(e,t,r,n){var i,a,o,s=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];if(r)for(var u=t,c=t+r;u<c;++u){i=3*u,a=m.Vector3.FromArray(e,i),n&&p._GetRightHandedPositionVector3FromRef(a),o=a.asArray();for(var f=0;f<3;++f){var h=o[f];h<s[f]&&(s[f]=h),h>l[f]&&(l[f]=h),++i}}return{min:s,max:l}},p._GetRightHandedPositionVector3=function(e){return new m.Vector3(e.x,e.y,-e.z)},p._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},p._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},p._GetRightHandedNormalVector3=function(e){return new m.Vector3(e.x,e.y,-e.z)},p._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},p._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},p._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},p._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},p._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},p._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},p._NormalizeTangentFromRef=function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);0<t&&(e.x/=t,e.y/=t,e.z/=t)},p})(),p._GLTFUtilities=d,g=e||(e={}),_=g.GLTF2||(g.GLTF2={}),y=_.Exporter||(_.Exporter={}),x=y.Extensions||(y.Extensions={}),T="KHR_texture_transform",v=(function(){function e(e){this.name=T,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){delete this._exporter},e.prototype.preExportTextureAsync=function(s,l,e){var u=this;return new Promise(function(t,e){var r={};0===l.uOffset&&0===l.vOffset||(r.offset=[l.uOffset,l.vOffset]),1===l.uScale&&1===l.vScale||(r.scale=[l.uScale,l.vScale]),0!==l.wAng&&(r.rotation=l.wAng),Object.keys(r).length||t(l);var n=r.scale?new g.Vector2(r.scale[0],r.scale[1]):g.Vector2.One(),i=null!=r.rotation?r.rotation:0,a=r.offset?new g.Vector2(r.offset[0],r.offset[1]):g.Vector2.Zero(),o=l.getScene();o?u.textureTransformTextureAsync(l,a,i,n,o).then((function(e){t(e)})):e(s+': "scene" is not defined for Babylon texture '+l.name+"!")})},e.prototype.textureTransformTextureAsync=function(n,e,t,r,i){return new Promise(function(e,t){var r=new g.ProceduralTexture(""+n.name,n.getSize(),"textureTransform",i);r||(g.Tools.Log("Cannot create procedural texture for "+n.name+"!"),e(n)),r.setTexture("textureSampler",n),r.setMatrix("textureTransformMat",n.getTextureMatrix()),r.isReady()?(r.render(),e(r)):r.getEffect().executeWhenCompiled((function(){r.render(),e(r)}))})},e})(),x.KHR_texture_transform=v,y._Exporter.RegisterExtension(T,(function(e){return new v(e)})),e})); | ||
!(function(e,t){var r=[],n=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(n=n||require("babylonjs"),module.exports=t(n)):"function"==typeof define&&define.amd?(r.push("babylonjs"),define("babylonjs-serializers",r,t)):"object"==typeof exports?(n=n||require("babylonjs"),exports["babylonjs-serializers"]=t(n)):e.BABYLON=t(n)})(this,(function(e){e=e||this.BABYLON;var t,b,r,a,n,W,i,o,s,L,l,u,c,M,f,m,h,p,d,g,_,y,x,T,v;this&&this.__decorate,this&&this.__extends||(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])});return b=e||(e={}),r=(function(){function e(){}return e.OBJ=function(e,t,r,n){var i=[],a=1;t&&(r||(r="mat"),i.push("mtllib "+r+".mtl"));for(var o=0;o<e.length;o++){i.push("g object"+o),i.push("o object_"+o);var s=null;if(n){var l=b.Matrix.Translation(e[o].position.x,e[o].position.y,e[o].position.z);s=b.Matrix.Translation(-e[o].position.x,-e[o].position.y,-e[o].position.z),e[o].bakeTransformIntoVertices(l)}if(t){var u=e[o].material;u&&i.push("usemtl "+u.id)}var c=e[o].geometry;if(c){var f=c.getVerticesData("position"),h=c.getVerticesData("normal"),p=c.getVerticesData("uv"),m=c.getIndices(),d=0;if(f&&m){for(var g=0;g<f.length;g+=3)i.push("v "+f[g]+" "+f[g+1]+" "+f[g+2]),d++;if(null!=h)for(g=0;g<h.length;g+=3)i.push("vn "+h[g]+" "+h[g+1]+" "+h[g+2]);if(null!=p)for(g=0;g<p.length;g+=2)i.push("vt "+p[g]+" "+p[g+1]);for(g=0;g<m.length;g+=3){var _=[String(m[g+2]+a),String(m[g+1]+a),String(m[g]+a)],y=["","",""],x=_,T=null!=p?_:y,v=null!=h?_:y;i.push("f "+x[0]+"/"+T[0]+"/"+v[0]+" "+x[1]+"/"+T[1]+"/"+v[1]+" "+x[2]+"/"+T[2]+"/"+v[2])}n&&s&&e[o].bakeTransformIntoVertices(s),a+=d}else b.Tools.Warn("There are no position vertices or indices on the mesh!")}else b.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var t=[],r=e.material;t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4));return r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},e})(),b.OBJExport=r,e.Effect.ShadersStore.textureTransformPixelShader="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}",a=e||(e={}),n=(function(){function e(){}return e.GLTFAsync=function(t,r,n){return t.whenReadyAsync().then((function(){var e=r.replace(/\.[^/.]+$/,"");return new a.GLTF2.Exporter._Exporter(t,n)._generateGLTFAsync(e)}))},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(t,r,n){var i=this;return this._PreExportAsync(t,n).then((function(){var e=r.replace(/\.[^/.]+$/,"");return new a.GLTF2.Exporter._Exporter(t,n)._generateGLBAsync(e).then((function(e){return i._PostExportAsync(t,e,n)}))}))},e})(),a.GLTF2Export=n,W=e||(e={}),(function(z){var e=(function(){function u(e,t){this._extensions={},this._asset={generator:"BabylonJS",version:"2.0"},this._extensionsUsed=[],this._extensionsRequired=[],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._convertToRightHandedSystem=!this._babylonScene.useRightHandedSystem;var r=t||{};this._shouldExportTransformNode=r.shouldExportTransformNode?r.shouldExportTransformNode:function(e){return!0},this._animationSampleRate=r.animationSampleRate?r.animationSampleRate:1/60,this._glTFMaterialExporter=new z._GLTFMaterialExporter(this),this._loadExtensions()}return u.prototype._applyExtensions=function(e,t){for(var r=0,n=u._ExtensionNames;r<n.length;r++){var i=n[r],a=this._extensions[i];if(a.enabled){var o=e;o._activeLoaderExtensions=o._activeLoaderExtensions||{};var s=o._activeLoaderExtensions;if(!s[i]){s[i]=!0;try{var l=t(a);if(l)return l}finally{delete s[i],delete o._activeLoaderExtensions}}}}return null},u.prototype._extensionsPreExportTextureAsync=function(t,r,n){return this._applyExtensions(r,(function(e){return e.preExportTextureAsync&&e.preExportTextureAsync(t,r,n)}))},u.prototype._extensionsPostExportMeshPrimitiveAsync=function(t,r,n,i){return this._applyExtensions(r,(function(e){return e.postExportMeshPrimitiveAsync&&e.postExportMeshPrimitiveAsync(t,r,n,i)}))},u.prototype._loadExtensions=function(){for(var e=0,t=u._ExtensionNames;e<t.length;e++){var r=t[e],n=u._ExtensionFactories[r](this);this._extensions[r]=n}},u.RegisterExtension=function(e,t){u.UnregisterExtension(e)&&W.Tools.Warn("Extension with the name "+e+" already exists"),u._ExtensionFactories[e]=t,u._ExtensionNames.push(e)},u.UnregisterExtension=function(e){if(!u._ExtensionFactories[e])return!1;delete u._ExtensionFactories[e];var t=u._ExtensionNames.indexOf(e);return-1!==t&&u._ExtensionNames.splice(t,1),!0},u.prototype._getLocalEngine=function(){if(!this._localEngine){var e=document.createElement("canvas");e.id="WriteCanvas",e.width=2048,e.height=2048,this._localEngine=new W.Engine(e,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!0}),this._localEngine.setViewport(new W.Viewport(0,0,1,1))}return this._localEngine},u.prototype.reorderIndicesBasedOnPrimitiveMode=function(e,t,r,n,i){switch(t){case W.Material.TriangleFillMode:n||(n=0);for(var a=e.indexStart,o=e.indexStart+e.indexCount;a<o;a+=3){var s=n+4*a,l=i.getUInt32(s+4),u=i.getUInt32(s+8);i.setUInt32(u,s+4),i.setUInt32(l,s+8)}break;case W.Material.TriangleFanDrawMode:a=e.indexStart+e.indexCount-1;for(var c=e.indexStart;c<=a;--a)i.setUInt32(r[a],n),n+=4;break;case W.Material.TriangleStripDrawMode:3<=e.indexCount&&(i.setUInt32(r[e.indexStart+2],n+4),i.setUInt32(r[e.indexStart+1],n+8))}},u.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(e,t,r,n,i,a,o){if(this._convertToRightHandedSystem&&r===W.Material.ClockWiseSideOrientation)switch(t){case W.Material.TriangleFillMode:this.reorderTriangleFillMode(e,t,r,n,i,a,o);break;case W.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(e,t,r,n,i,a,o);break;case W.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(e,t,r,n,i,a,o)}},u.prototype.reorderTriangleFillMode=function(e,t,r,n,i,a,o){var s=this.getVertexBufferFromMesh(n,e.getMesh());if(s){var l=s.byteStride/W.VertexBuffer.GetTypeByteLength(s.type);if(e.verticesCount%3!=0)W.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var u=[],c=0;switch(n){case W.VertexBuffer.PositionKind:case W.VertexBuffer.NormalKind:for(var f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=3)c=f*l,u.push(W.Vector3.FromArray(i,c)),u.push(W.Vector3.FromArray(i,c+2*l)),u.push(W.Vector3.FromArray(i,c+l));break;case W.VertexBuffer.TangentKind:for(f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=3)c=f*l,u.push(W.Vector4.FromArray(i,c)),u.push(W.Vector4.FromArray(i,c+2*l)),u.push(W.Vector4.FromArray(i,c+l));break;case W.VertexBuffer.ColorKind:var h=s.getSize();for(f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=h)c=f*l,4===h?(u.push(W.Vector4.FromArray(i,c)),u.push(W.Vector4.FromArray(i,c+2*l)),u.push(W.Vector4.FromArray(i,c+l))):(u.push(W.Vector3.FromArray(i,c)),u.push(W.Vector3.FromArray(i,c+2*l)),u.push(W.Vector3.FromArray(i,c+l)));break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:for(f=e.verticesStart;f<e.verticesStart+e.verticesCount;f+=3)c=f*l,u.push(W.Vector2.FromArray(i,c)),u.push(W.Vector2.FromArray(i,c+2*l)),u.push(W.Vector2.FromArray(i,c+l));break;default:W.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(u,a,n,i,o)}}else W.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+n+" not present!")},u.prototype.reorderTriangleStripDrawMode=function(e,t,r,n,i,a,o){var s=this.getVertexBufferFromMesh(n,e.getMesh());if(s){var l=s.byteStride/W.VertexBuffer.GetTypeByteLength(s.type),u=[],c=0;switch(n){case W.VertexBuffer.PositionKind:case W.VertexBuffer.NormalKind:c=e.verticesStart,u.push(W.Vector3.FromArray(i,c+2*l)),u.push(W.Vector3.FromArray(i,c+l));break;case W.VertexBuffer.TangentKind:for(var f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector4.FromArray(i,c));break;case W.VertexBuffer.ColorKind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,4===s.getSize()?u.push(W.Vector4.FromArray(i,c)):u.push(W.Vector3.FromArray(i,c));break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector2.FromArray(i,c));break;default:W.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(u,a+12,n,i,o)}else W.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+n+" not present!")},u.prototype.reorderTriangleFanMode=function(e,t,r,n,i,a,o){var s=this.getVertexBufferFromMesh(n,e.getMesh());if(s){var l=s.byteStride/W.VertexBuffer.GetTypeByteLength(s.type),u=[],c=0;switch(n){case W.VertexBuffer.PositionKind:case W.VertexBuffer.NormalKind:for(var f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector3.FromArray(i,c));break;case W.VertexBuffer.TangentKind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector4.FromArray(i,c));break;case W.VertexBuffer.ColorKind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector4.FromArray(i,c)),4===s.getSize()?u.push(W.Vector4.FromArray(i,c)):u.push(W.Vector3.FromArray(i,c));break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:for(f=e.verticesStart+e.verticesCount-1;f>=e.verticesStart;--f)c=f*l,u.push(W.Vector2.FromArray(i,c));break;default:W.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(u,a,n,i,o)}else W.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+n+" not present!")},u.prototype.writeVertexAttributeData=function(e,t,r,n,i){for(var a=0,o=e;a<o.length;a++){var s=o[a];!this._convertToRightHandedSystem||r===W.VertexBuffer.ColorKind||s instanceof W.Vector2||(s instanceof W.Vector3?r===W.VertexBuffer.NormalKind?z._GLTFUtilities._GetRightHandedNormalVector3FromRef(s):r===W.VertexBuffer.PositionKind?z._GLTFUtilities._GetRightHandedPositionVector3FromRef(s):W.Tools.Error("Unsupported vertex attribute kind!"):z._GLTFUtilities._GetRightHandedVector4FromRef(s)),r===W.VertexBuffer.NormalKind?s.normalize():r===W.VertexBuffer.TangentKind&&s instanceof W.Vector4&&z._GLTFUtilities._NormalizeTangentFromRef(s);for(var l=0,u=s.asArray();l<u.length;l++){var c=u[l];i.setFloat32(c,t),t+=4}}},u.prototype.writeAttributeData=function(e,t,r,n){var i,a=r/4,o=[];switch(e){case W.VertexBuffer.PositionKind:for(var s=0,l=t.length/a;s<l;++s){i=s*a;var u=W.Vector3.FromArray(t,i);this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedPositionVector3FromRef(u),o.push(u.asArray())}break;case W.VertexBuffer.NormalKind:s=0;for(var c=t.length/a;s<c;++s)i=s*a,u=W.Vector3.FromArray(t,i),this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedNormalVector3FromRef(u),u.normalize(),o.push(u.asArray());break;case W.VertexBuffer.TangentKind:s=0;for(var f=t.length/a;s<f;++s)i=s*a,u=W.Vector4.FromArray(t,i),this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedVector4FromRef(u),z._GLTFUtilities._NormalizeTangentFromRef(u),o.push(u.asArray());break;case W.VertexBuffer.ColorKind:s=0;for(var h=t.length/a;s<h;++s)i=s*a,u=3===a?W.Vector3.FromArray(t,i):W.Vector4.FromArray(t,i),o.push(u.asArray());break;case W.VertexBuffer.UVKind:case W.VertexBuffer.UV2Kind:s=0;for(var p=t.length/a;s<p;++s)i=s*a,o.push((this._convertToRightHandedSystem,[t[i],t[i+1]]));break;default:W.Tools.Warn("Unsupported Vertex Buffer Type: "+e),o=[]}for(var m=0,d=o;m<d.length;m++)for(var g=0,_=d[m];g<_.length;g++){var y=_[g];n.setFloat32(y)}},u.prototype.generateJSON=function(e,t,r){var n,i,a,o=this,s={byteLength:this._totalByteLength},l=this._totalByteLength,u={asset:this._asset};return this._extensionsUsed&&this._extensionsUsed.length&&(u.extensionsUsed=this._extensionsUsed),this._extensionsRequired&&this._extensionsRequired.length&&(u.extensionsRequired=this._extensionsRequired),s.byteLength&&(u.buffers=[s]),this._nodes&&this._nodes.length&&(u.nodes=this._nodes),this._meshes&&this._meshes.length&&(u.meshes=this._meshes),this._scenes&&this._scenes.length&&(u.scenes=this._scenes,u.scene=0),this._bufferViews&&this._bufferViews.length&&(u.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(u.accessors=this._accessors),this._animations&&this._animations.length&&(u.animations=this._animations),this._materials&&this._materials.length&&(u.materials=this._materials),this._textures&&this._textures.length&&(u.textures=this._textures),this._samplers&&this._samplers.length&&(u.samplers=this._samplers),this._images&&this._images.length&&(e?(u.images=[],this._images.forEach((function(e){e.uri&&(i=o._imageData[e.uri],n=e.uri.split(".")[0]+" image",a=z._GLTFUtilities._CreateBufferView(0,l,i.data.length,void 0,n),l+=i.data.buffer.byteLength,o._bufferViews.push(a),e.bufferView=o._bufferViews.length-1,e.name=n,e.mimeType=i.mimeType,e.uri=void 0,u.images||(u.images=[]),u.images.push(e))})),s.byteLength=l):u.images=this._images),e||(s.uri=t+".bin"),r?JSON.stringify(u,null,2):JSON.stringify(u)},u.prototype._generateGLTFAsync=function(s){var l=this;return this._generateBinaryAsync().then((function(e){var t=l.generateJSON(!1,s,!0),r=new Blob([e],{type:"application/octet-stream"}),n=s+".gltf",i=s+".bin",a=new W.GLTFData;if(a.glTFFiles[n]=t,a.glTFFiles[i]=r,l._imageData)for(var o in l._imageData)a.glTFFiles[o]=new Blob([l._imageData[o].data],{type:l._imageData[o].mimeType});return a}))},u.prototype._generateBinaryAsync=function(){var e=this,t=new r(4);return this.createSceneAsync(this._babylonScene,t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},u.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},u.prototype._generateGLBAsync=function(M){var S=this;return this._generateBinaryAsync().then((function(e){var t=S.generateJSON(!0),r=M+".glb",n=t.length,i=0;for(var a in S._imageData)i+=S._imageData[a].data.byteLength;var o=S._getPadding(n),s=S._getPadding(e.byteLength),l=S._getPadding(i),u=28+n+o+e.byteLength+s+i+l,c=new ArrayBuffer(12),f=new DataView(c);f.setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,u,!0);var h=new ArrayBuffer(8+n+o),p=new DataView(h);p.setUint32(0,n+o,!0),p.setUint32(4,1313821514,!0);for(var m=new Uint8Array(h,8),d=0;d<n;++d)m[d]=t.charCodeAt(d);var g=new Uint8Array(h,8+n);for(d=0;d<o;++d)g[d]=32;var _=new ArrayBuffer(8),y=new DataView(_);y.setUint32(0,e.byteLength+i+l,!0),y.setUint32(4,5130562,!0);var x=new ArrayBuffer(s),T=new Uint8Array(x);for(d=0;d<s;++d)T[d]=0;var v=new ArrayBuffer(l),b=new Uint8Array(v);for(d=0;d<l;++d)b[d]=0;var A=[c,h,_,e];for(var a in S._imageData)A.push(S._imageData[a].data.buffer);A.push(x),A.push(v);var F=new Blob(A,{type:"application/octet-stream"}),E=new W.GLTFData;return E.glTFFiles[r]=F,null!=S._localEngine&&S._localEngine.dispose(),E}))},u.prototype.setNodeTransformation=function(e,t){t.getPivotPoint().equalsToFloats(0,0,0)||W.Tools.Warn("Pivot points are not supported in the glTF serializer"),t.position.equalsToFloats(0,0,0)||(e.translation=this._convertToRightHandedSystem?z._GLTFUtilities._GetRightHandedPositionVector3(t.position).asArray():t.position.asArray()),t.scaling.equalsToFloats(1,1,1)||(e.scale=t.scaling.asArray());var r=W.Quaternion.RotationYawPitchRoll(t.rotation.y,t.rotation.x,t.rotation.z);t.rotationQuaternion&&r.multiplyInPlace(t.rotationQuaternion),0===r.x&&0===r.y&&0===r.z&&1===r.w||(this._convertToRightHandedSystem&&z._GLTFUtilities._GetRightHandedQuaternionFromRef(r),e.rotation=r.normalize().asArray())},u.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},u.prototype.createBufferViewKind=function(e,t,r,n){var i=t instanceof W.Mesh?t:t instanceof W.InstancedMesh?t.sourceMesh:null;if(i){var a=i.getVerticesData(e);if(a){var o=4*a.length,s=z._GLTFUtilities._CreateBufferView(0,r.getByteOffset(),o,n,e+" - "+i.name);this._bufferViews.push(s),this.writeAttributeData(e,a,n,r)}}},u.prototype.getMeshPrimitiveMode=function(e){return e instanceof W.LinesMesh?W.Material.LineListDrawMode:e.material?e.material.fillMode:W.Material.TriangleFillMode},u.prototype.setPrimitiveMode=function(e,t){switch(t){case W.Material.TriangleFillMode:break;case W.Material.TriangleStripDrawMode:e.mode=5;break;case W.Material.TriangleFanDrawMode:e.mode=6;break;case W.Material.PointListDrawMode:e.mode=0;case W.Material.PointFillMode:e.mode=0;break;case W.Material.LineLoopDrawMode:e.mode=2;break;case W.Material.LineListDrawMode:e.mode=1;break;case W.Material.LineStripDrawMode:e.mode=3}},u.prototype.setAttributeKind=function(e,t){switch(t){case W.VertexBuffer.PositionKind:e.attributes.POSITION=this._accessors.length-1;break;case W.VertexBuffer.NormalKind:e.attributes.NORMAL=this._accessors.length-1;break;case W.VertexBuffer.ColorKind:e.attributes.COLOR_0=this._accessors.length-1;break;case W.VertexBuffer.TangentKind:e.attributes.TANGENT=this._accessors.length-1;break;case W.VertexBuffer.UVKind:e.attributes.TEXCOORD_0=this._accessors.length-1;break;case W.VertexBuffer.UV2Kind:e.attributes.TEXCOORD_1=this._accessors.length-1;break;default:W.Tools.Warn("Unsupported Vertex Buffer Type: "+t)}},u.prototype.setPrimitiveAttributesAsync=function(e,t,r){var n,i,a,o=[],s=null;t instanceof W.Mesh?s=t:t instanceof W.InstancedMesh&&(s=t.sourceMesh);var l=[{kind:W.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:W.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:W.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:W.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:W.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:W.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(s){for(var u=null,c=this.getMeshPrimitiveMode(s),f={},h=0,p=l;h<p.length;h++){var m=(D=p[h]).kind;if(s.isVerticesDataPresent(m)){var d=this.getVertexBufferFromMesh(m,s);D.byteStride=d?4*d.getSize():4*W.VertexBuffer.DeduceStride(m),12===D.byteStride&&(D.accessorType="VEC3"),this.createBufferViewKind(m,t,r,D.byteStride),D.bufferViewIndex=this._bufferViews.length-1,f[m]=D.bufferViewIndex}}if(s.getTotalIndices()){var g=s.getIndices();if(g){var _=4*g.length;n=z._GLTFUtilities._CreateBufferView(0,r.getByteOffset(),_,void 0,"Indices - "+s.name),this._bufferViews.push(n),u=this._bufferViews.length-1;for(var y=0,x=g.length;y<x;++y)r.setUInt32(g[y])}}if(s.subMeshes)for(var T=0,v=s.subMeshes;T<v.length;T++){var b=v[T];i=!1;var A=b.getMaterial()||s.getScene().defaultMaterial,F=null;if(A)if(s instanceof W.LinesMesh){var E={name:s.name+" material"};(!s.color.equals(W.Color3.White())||s.alpha<1)&&(E.pbrMetallicRoughness={baseColorFactor:s.color.asArray().concat([s.alpha])}),this._materials.push(E),F=this._materials.length-1}else if(A instanceof W.MultiMaterial){var M=A.subMaterials[b.materialIndex];M&&(A=M,F=this._materialMap[A.uniqueId])}else F=this._materialMap[A.uniqueId];var S=null!=F?this._materials[F]:null,R={attributes:{}};this.setPrimitiveMode(R,c);for(var V=0,C=l;V<C.length;V++)if(((m=(D=C[V]).kind)!==W.VertexBuffer.UVKind&&m!==W.VertexBuffer.UV2Kind||!S||this._glTFMaterialExporter._hasTexturesPresent(S))&&(O=s.getVerticesData(m))&&(d=this.getVertexBufferFromMesh(m,s))){var w=d.getSize(),B=D.bufferViewIndex;if(null!=B){a={min:null,max:null},m==W.VertexBuffer.PositionKind&&(a=z._GLTFUtilities._CalculateMinMaxPositions(O,0,O.length/w,this._convertToRightHandedSystem));var L=z._GLTFUtilities._CreateAccessor(B,m+" - "+t.name,D.accessorType,5126,O.length/w,0,a.min,a.max);this._accessors.push(L),this.setAttributeKind(R,m),null==R.attributes.TEXCOORD_0&&null==R.attributes.TEXCOORD_1||(i=!0)}}if(u&&(L=z._GLTFUtilities._CreateAccessor(u,"indices - "+t.name,"SCALAR",5125,b.indexCount,4*b.indexStart,null,null),this._accessors.push(L),R.indices=this._accessors.length-1),null!=F&&0<Object.keys(R.attributes).length){var P=A.sideOrientation;if(this._convertToRightHandedSystem&&P===W.Material.ClockWiseSideOrientation){var N=null!=u?this._bufferViews[u].byteOffset:null;null==N&&(N=0);var G=null;if(null!=u&&(G=s.getIndices()),G)this.reorderIndicesBasedOnPrimitiveMode(b,c,G,N,r);else for(var I=0,U=l;I<U.length;I++){var O,D=U[I];if(O=s.getVerticesData(D.kind)){var k=this._bufferViews[f[D.kind]].byteOffset;k||(k=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(b,c,P,D.kind,O,k,r)}}}if(!i&&this._glTFMaterialExporter._hasTexturesPresent(this._materials[F])){var K=this._glTFMaterialExporter._stripTexturesFromMaterial(this._materials[F]);this._materials.push(K),F=this._materials.length-1}R.material=F}e.primitives.push(R),this._extensionsPostExportMeshPrimitiveAsync("postExport",R,b,r)&&o.push()}}return Promise.all(o).then((function(){}))},u.prototype.createSceneAsync=function(e,l){var u,c,f,h=this,p={nodes:[]},m=e.transformNodes.concat(e.meshes);return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(e.materials,"image/png",!0).then((function(){return h.createNodeMapAndAnimationsAsync(e,m,h._shouldExportTransformNode,l).then((function(e){if(h._nodeMap=e,h._totalByteLength=l.getByteOffset(),null==h._totalByteLength)throw new Error("undefined byte length!");for(var t=0,r=m;t<r.length;t++){var n=r[t];if(null!=(u=h._nodeMap[n.uniqueId])&&(c=h._nodes[u],n.parent||(h._shouldExportTransformNode(n)?(h._convertToRightHandedSystem&&(c.translation&&(c.translation[2]*=-1,c.translation[0]*=-1),c.rotation=c.rotation?W.Quaternion.FromArray([0,1,0,0]).multiply(W.Quaternion.FromArray(c.rotation)).asArray():W.Quaternion.FromArray([0,1,0,0]).asArray()),p.nodes.push(u)):W.Tools.Log("Omitting "+n.name+" from scene.")),f=n.getDescendants(!0),!c.children&&f&&f.length)){for(var i=[],a=0,o=f;a<o.length;a++){var s=o[a];null!=h._nodeMap[s.uniqueId]&&i.push(h._nodeMap[s.uniqueId])}i.length&&(c.children=i)}}p.nodes.length&&h._scenes.push(p)}))}))},u.prototype.createNodeMapAndAnimationsAsync=function(r,e,n,i){for(var a,o=this,s=Promise.resolve(),l={},u={name:"runtime animations",channels:[],samplers:[]},c=[],t=function(t){n(t)?s=s.then((function(){return o.createNodeAsync(t,i).then((function(e){(t.getDescendants(!0,(function(e){return e instanceof W.TransformNode})).length||null!=e.mesh)&&(o._nodes.push(e),a=o._nodes.length-1,l[t.uniqueId]=a),!r.animationGroups.length&&t.animations.length&&z._GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations(t,u,c,l,o._nodes,i,o._bufferViews,o._accessors,o._convertToRightHandedSystem,o._animationSampleRate)}))})):t.name},f=0,h=e;f<h.length;f++)t(h[f]);return s.then((function(){return u.channels.length&&u.samplers.length&&o._animations.push(u),c.forEach((function(e){e.channels.length&&e.samplers.length&&o._animations.push(e)})),r.animationGroups.length&&z._GLTFAnimation._CreateNodeAnimationFromAnimationGroups(r,o._animations,l,o._nodes,i,o._bufferViews,o._accessors,o._convertToRightHandedSystem,o._animationSampleRate),l}))},u.prototype.createNodeAsync=function(r,n){var i=this;return Promise.resolve().then((function(){var e={},t={primitives:[]};return r.name&&(e.name=r.name),i.setNodeTransformation(e,r),i.setPrimitiveAttributesAsync(t,r,n).then((function(){return t.primitives.length&&(i._meshes.push(t),e.mesh=i._meshes.length-1),e}))}))},u._ExtensionNames=new Array,u._ExtensionFactories={},u})();z._Exporter=e;var r=(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),i=0,a=n.byteLength;i<a;++i)n[i]=r[i];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):W.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 W.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?W.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?W.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?W.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?W.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)&&W.Tools.Error("Invalid data being written!"),null!=t&&(t<this._byteOffset?this._dataView.setFloat32(t,e,!0):W.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):W.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})();z._BinaryWriter=r})((i=W.GLTF2||(W.GLTF2={})).Exporter||(i.Exporter={})),o=e||(e={}),s=(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],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([n],i)),r.click()}},e})(),o.GLTFData=s,L=e||(e={}),l=L.GLTF2||(L.GLTF2={}),u=l.Exporter||(l.Exporter={}),c=(function(){function B(e){this._textureMap={},this._textureMap={},this._exporter=e}return B.FuzzyEquals=function(e,t,r){return L.Scalar.WithinEpsilon(e.r,t.r,r)&&L.Scalar.WithinEpsilon(e.g,t.g,r)&&L.Scalar.WithinEpsilon(e.b,t.b,r)},B.prototype._convertMaterialsToGLTFAsync=function(e,t,r){for(var n=[],i=0,a=e;i<a.length;i++){var o=a[i];o instanceof L.StandardMaterial?n.push(this._convertStandardMaterialAsync(o,t,r)):o instanceof L.PBRMetallicRoughnessMaterial?n.push(this._convertPBRMetallicRoughnessMaterialAsync(o,t,r)):o instanceof L.PBRMaterial?n.push(this._convertPBRMaterialAsync(o,t,r)):L.Tools.Warn("Unsupported material type: "+o.name)}return Promise.all(n).then((function(){}))},B.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},B.prototype._hasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},B.prototype._convertToGLTFPBRMetallicRoughness=function(e){var t,r,n,i,a,o,s,l=new L.Vector2(0,1),u=new L.Vector2(0,.1),c=new L.Vector2(0,.1),f=new L.Vector2(1300,.1),h=e.diffuseColor.toLinearSpace().scale(.5),p=e.alpha,m=L.Scalar.Clamp(e.specularPower,0,B._MaxSpecularPower),d=(t=m,s=Math.pow(t/f.x,.333333),r=s,n=l.y,i=u.y,a=c.y,o=f.y,(1-r)*(1-r)*(1-r)*n+3*(1-r)*(1-r)*r*i+3*(1-r)*r*r*a+r*r*r*o);return{baseColorFactor:[h.r,h.g,h.b,p],metallicFactor:0,roughnessFactor:d}},B._SolveMetallic=function(e,t,r){if(t<this._DielectricSpecular.r)return this._DielectricSpecular,0;var n=this._DielectricSpecular.r,i=e*r/(1-this._DielectricSpecular.r)+t-2*this._DielectricSpecular.r,a=i*i-4*n*(this._DielectricSpecular.r-t);return L.Scalar.Clamp((-i+Math.sqrt(a))/(2*n),0,1)},B.prototype._getAlphaMode=function(e){return e.needAlphaBlending()?"BLEND":e.needAlphaTesting()?"MASK":"OPAQUE"},B.prototype._convertStandardMaterialAsync=function(t,e,r){var n=this._exporter._materialMap,i=this._exporter._materials,a=this._getAlphaMode(t),o=[],s=this._convertToGLTFPBRMetallicRoughness(t),l={name:t.name};if(null==t.backFaceCulling||t.backFaceCulling||(t.twoSidedLighting||L.Tools.Warn(t.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),l.doubleSided=!0),r&&(t.diffuseTexture&&o.push(this._exportTextureAsync(t.diffuseTexture,e).then((function(e){e&&(s.baseColorTexture=e)}))),t.bumpTexture&&o.push(this._exportTextureAsync(t.bumpTexture,e).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],o.push(this._exportTextureAsync(t.emissiveTexture,e).then((function(e){e&&(l.emissiveTexture=e)})))),t.ambientTexture&&o.push(this._exportTextureAsync(t.ambientTexture,e).then((function(e){if(e){var t={index:e.index};(l.occlusionTexture=t).strength=1}})))),(t.alpha<1||t.opacityTexture)&&(t.alphaMode===L.Engine.ALPHA_COMBINE?l.alphaMode="BLEND":L.Tools.Warn(t.name+": glTF 2.0 does not support alpha mode: "+t.alphaMode.toString())),t.emissiveColor&&!B.FuzzyEquals(t.emissiveColor,L.Color3.Black(),B._Epsilon)&&(l.emissiveFactor=t.emissiveColor.asArray()),l.pbrMetallicRoughness=s,"OPAQUE"!==a)switch(a){case"BLEND":l.alphaMode="BLEND";break;case"MASK":l.alphaMode="MASK",l.alphaCutoff=t.alphaCutOff;break;default:L.Tools.Warn("Unsupported alpha mode "+a)}return i.push(l),n[t.uniqueId]=i.length-1,Promise.all(o).then((function(){}))},B.prototype._convertPBRMetallicRoughnessMaterialAsync=function(t,e,r){var n=this._exporter._materialMap,i=this._exporter._materials,a=[],o={};t.baseColor&&(o.baseColorFactor=[t.baseColor.r,t.baseColor.g,t.baseColor.b,t.alpha]),null!=t.metallic&&1!==t.metallic&&(o.metallicFactor=t.metallic),null!=t.roughness&&1!==t.roughness&&(o.roughnessFactor=t.roughness);var s={name:t.name};t.doubleSided&&(s.doubleSided=t.doubleSided);var l=null;return null!=t.transparencyMode&&(l=this._getAlphaMode(t))&&"OPAQUE"!==l&&"MASK"===(s.alphaMode=l)&&(s.alphaCutoff=t.alphaCutOff),r&&(null!=t.baseTexture&&a.push(this._exportTextureAsync(t.baseTexture,e).then((function(e){e&&(o.baseColorTexture=e)}))),t.normalTexture&&a.push(this._exportTextureAsync(t.normalTexture,e).then((function(e){e&&(s.normalTexture=e,1!==t.normalTexture.level&&(s.normalTexture.scale=t.normalTexture.level))}))),t.occlusionTexture&&a.push(this._exportTextureAsync(t.occlusionTexture,e).then((function(e){e&&(s.occlusionTexture=e,null!=t.occlusionStrength&&(s.occlusionTexture.strength=t.occlusionStrength))}))),t.emissiveTexture&&a.push(this._exportTextureAsync(t.emissiveTexture,e).then((function(e){e&&(s.emissiveTexture=e)})))),B.FuzzyEquals(t.emissiveColor,L.Color3.Black(),B._Epsilon)&&(s.emissiveFactor=t.emissiveColor.asArray()),s.pbrMetallicRoughness=o,i.push(s),n[t.uniqueId]=i.length-1,Promise.all(a).then((function(){}))},B.prototype._createBase64FromCanvasAsync=function(t,l,u,e){var c=this;return new Promise(function(r,n){var i,e=L.Engine.TEXTURETYPE_UNSIGNED_INT,a=c._exporter._getLocalEngine();i=new L.Scene(a);var o=a.createRawTexture(t,l,u,L.Engine.TEXTUREFORMAT_RGBA,!1,!0,L.Texture.NEAREST_SAMPLINGMODE,null,e),s=new L.PostProcess("pass","pass",null,null,1,null,L.Texture.NEAREST_SAMPLINGMODE,a,!1,void 0,L.Engine.TEXTURETYPE_UNSIGNED_INT,void 0,null,!1);s.getEffect().executeWhenCompiled((function(){s.onApply=function(e){e._bindTexture("textureSampler",o)},a.setSize(l,u),i.postProcessManager.directRender([s],null),s.dispose(),o.dispose();var e=a.getRenderingCanvas();if(e)if(e.toBlob)L.Tools.ToBlob(e,(function(e){if(e){var t=new FileReader;t.onload=function(e){var t=e.target.result;i.dispose(),r(t)},t.readAsDataURL(e)}else n("gltfMaterialExporter: Failed to get blob from image canvas!")}));else{var t=e.toDataURL();r(t)}else n("Engine is missing a canvas!")}))})},B.prototype._createWhiteTexture=function(e,t,r){for(var n=new Uint8Array(e*t*4),i=0;i<n.length;i+=4)n[i]=n[i+1]=n[i+2]=n[i+3]=255;return L.RawTexture.CreateRGBATexture(n,e,t,r)},B.prototype._resizeTexturesToSameDimensions=function(e,t,r){var n,i,a=e?e.getSize():{width:0,height:0},o=t?t.getSize():{width:0,height:0};return a.width<o.width?(n=e&&e instanceof L.Texture?L.TextureTools.CreateResizedCopy(e,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,r),i=t):a.width>o.width?(i=t&&t instanceof L.Texture?L.TextureTools.CreateResizedCopy(t,a.width,a.height,!0):this._createWhiteTexture(a.width,a.height,r),n=e):(n=e,i=t),{texture1:n,texture2:i}},B.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!")},B.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(e,t,r,n){var i=[];if(!e&&!t)return Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!");var a=e?e.getScene():t?t.getScene():null;if(a){var o=this._resizeTexturesToSameDimensions(e,t,a),s=o.texture1.getSize(),l=void 0,u=void 0,c=s.width,f=s.height,h=o.texture1.readPixels(),p=o.texture2.readPixels();if(!h)return Promise.reject("Failed to retrieve pixels from diffuse texture!");if(l=this._convertPixelArrayToFloat32(h),!p)return Promise.reject("Failed to retrieve pixels from specular glossiness texture!");for(var m=(u=this._convertPixelArrayToFloat32(p)).byteLength,d=new Uint8Array(m),g=new Uint8Array(m),_=L.Color3.Black(),y=0,x=0,T=0;T<f;++T)for(var v=0;v<c;++v){var b=4*(c*T+v),A={diffuseColor:new L.Color3(l[b],l[b+1],l[b+2]).toLinearSpace().multiply(r.diffuseColor),specularColor:new L.Color3(u[b],u[b+1],u[b+2]).toLinearSpace().multiply(r.specularColor),glossiness:u[b+3]*r.glossiness},F=this._convertSpecularGlossinessToMetallicRoughness(A);_.r=Math.max(_.r,F.baseColor.r),_.g=Math.max(_.g,F.baseColor.g),_.b=Math.max(_.b,F.baseColor.b),y=Math.max(y,F.metallic),x=Math.max(x,F.roughness),g[b]=255*F.baseColor.r,g[b+1]=255*F.baseColor.g,g[b+2]=255*F.baseColor.b,g[b+3]=o.texture1.hasAlpha?255*l[b+3]:255,d[b]=0,d[b+1]=255*F.roughness,d[b+2]=255*F.metallic,d[b+3]=255}var E={baseColor:_,metallic:y,roughness:x},M=!1,S=!1;for(T=0;T<f;++T)for(v=0;v<c;++v){var R=4*(c*T+v);g[R]/=E.baseColor.r>B._Epsilon?E.baseColor.r:1,g[R+1]/=E.baseColor.g>B._Epsilon?E.baseColor.g:1,g[R+2]/=E.baseColor.b>B._Epsilon?E.baseColor.b:1;var V=L.Color3.FromInts(g[R],g[R+1],g[R+2]).toGammaSpace();g[R]=255*V.r,g[R+1]=255*V.g,g[R+2]=255*V.b,B.FuzzyEquals(V,L.Color3.White(),B._Epsilon)||(S=!0),d[R+1]/=E.roughness>B._Epsilon?E.roughness:1,d[R+2]/=E.metallic>B._Epsilon?E.metallic:1;var C=L.Color3.FromInts(255,d[R+1],d[R+2]);B.FuzzyEquals(C,L.Color3.White(),B._Epsilon)||(M=!0)}if(M){var w=this._createBase64FromCanvasAsync(d,c,f,n).then((function(e){E.metallicRoughnessTextureBase64=e}));i.push(w)}return S&&(w=this._createBase64FromCanvasAsync(g,c,f,n).then((function(e){E.baseColorTextureBase64=e})),i.push(w)),Promise.all(i).then((function(){return E}))}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},B.prototype._convertSpecularGlossinessToMetallicRoughness=function(e){var t=this._getPerceivedBrightness(e.diffuseColor),r=this._getPerceivedBrightness(e.specularColor),n=1-this._getMaxComponent(e.specularColor),i=B._SolveMetallic(t,r,n),a=e.diffuseColor.scale(n/(1-B._DielectricSpecular.r)/Math.max(1-i,B._Epsilon)),o=e.specularColor.subtract(B._DielectricSpecular.scale(1-i)).scale(1/Math.max(i,B._Epsilon)),s=L.Color3.Lerp(a,o,i*i);return{baseColor:s=s.clampToRef(0,1,s),metallic:i,roughness:1-e.glossiness}},B.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},B.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},B.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,n){var i=[],a={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return n&&(e.albedoTexture&&i.push(this._exportTextureAsync(e.albedoTexture,t).then((function(e){e&&(r.baseColorTexture=e)}))),e.metallicTexture&&i.push(this._exportTextureAsync(e.metallicTexture,t).then((function(e){e&&(r.metallicRoughnessTexture=e)})))),Promise.all(i).then((function(){return a}))},B.prototype._getGLTFTextureSampler=function(e){var t=this._getGLTFTextureWrapModesSampler(e),r=e instanceof L.Texture?e.samplingMode:null;if(null!=r)switch(r){case L.Texture.LINEAR_LINEAR:t.magFilter=9729,t.minFilter=9729;break;case L.Texture.LINEAR_NEAREST:t.magFilter=9729,t.minFilter=9728;break;case L.Texture.NEAREST_LINEAR:t.magFilter=9728,t.minFilter=9729;break;case L.Texture.NEAREST_LINEAR_MIPLINEAR:t.magFilter=9728,t.minFilter=9987;break;case L.Texture.NEAREST_NEAREST:t.magFilter=9728,t.minFilter=9728;break;case L.Texture.NEAREST_LINEAR_MIPNEAREST:t.magFilter=9728,t.minFilter=9985;break;case L.Texture.LINEAR_NEAREST_MIPNEAREST:t.magFilter=9729,t.minFilter=9984;break;case L.Texture.LINEAR_NEAREST_MIPLINEAR:t.magFilter=9729,t.minFilter=9986;break;case L.Texture.NEAREST_NEAREST_MIPLINEAR:t.magFilter=9728,t.minFilter=9986;break;case L.Texture.LINEAR_LINEAR_MIPLINEAR:t.magFilter=9729,t.minFilter=9987;break;case L.Texture.LINEAR_LINEAR_MIPNEAREST:t.magFilter=9729,t.minFilter=9985;break;case L.Texture.NEAREST_NEAREST_MIPNEAREST:t.magFilter=9728,t.minFilter=9984}return t},B.prototype._getGLTFTextureWrapMode=function(e){switch(e){case L.Texture.WRAP_ADDRESSMODE:return 10497;case L.Texture.CLAMP_ADDRESSMODE:return 33071;case L.Texture.MIRROR_ADDRESSMODE:return 33648;default:return L.Tools.Error("Unsupported Texture Wrap Mode "+e+"!"),10497}},B.prototype._getGLTFTextureWrapModesSampler=function(e){var t=this._getGLTFTextureWrapMode(e instanceof L.Texture?e.wrapU:L.Texture.WRAP_ADDRESSMODE),r=this._getGLTFTextureWrapMode(e instanceof L.Texture?e.wrapV:L.Texture.WRAP_ADDRESSMODE);return 10497===t&&10497===r?{}:{wrapS:t,wrapT:r}},B.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(a,o,s,l){var u=this;return Promise.resolve().then((function(){var e=u._exporter._samplers,n=u._exporter._textures,t={diffuseColor:a.albedoColor||L.Color3.White(),specularColor:a.reflectivityColor||L.Color3.White(),glossiness:a.microSurface||1},i=null,r=u._getGLTFTextureSampler(a.albedoTexture);return null!=r.magFilter&&null!=r.minFilter&&null!=r.wrapS&&null!=r.wrapT&&(e.push(r),i=e.length-1),a.reflectivityTexture&&!a.useMicroSurfaceFromReflectivityMapAlpha?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(a.albedoTexture||a.reflectivityTexture)&&l?u._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(a.albedoTexture,a.reflectivityTexture,t,o).then((function(e){if(e.baseColorTextureBase64){var t=u._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+n.length+".png",o,a.albedoTexture?a.albedoTexture.coordinatesIndex:null,i);t&&(s.baseColorTexture=t)}if(e.metallicRoughnessTextureBase64){var r=u._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+n.length+".png",o,a.reflectivityTexture?a.reflectivityTexture.coordinatesIndex:null,i);r&&(s.metallicRoughnessTexture=r)}return e})):u._convertSpecularGlossinessToMetallicRoughness(t)}))},B.prototype._convertPBRMaterialAsync=function(t,r,n){var i=this,a={},o={name:t.name};return t.isMetallicWorkflow()?(t.albedoColor&&(a.baseColorFactor=[t.albedoColor.r,t.albedoColor.g,t.albedoColor.b,t.alpha]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(t,r,a,n).then((function(e){return i.setMetallicRoughnessPbrMaterial(e,t,o,a,r,n)}))):this._convertSpecGlossFactorsToMetallicRoughnessAsync(t,r,a,n).then((function(e){return i.setMetallicRoughnessPbrMaterial(e,t,o,a,r,n)}))},B.prototype.setMetallicRoughnessPbrMaterial=function(e,r,n,t,i,a){var o=this._exporter._materialMap,s=this._exporter._materials,l=[];if(e){var u=null;if(null!=r.transparencyMode&&(u=this._getAlphaMode(r))&&"OPAQUE"!==u&&"MASK"===(n.alphaMode=u)&&(n.alphaCutoff=r.alphaCutOff),B.FuzzyEquals(e.baseColor,L.Color3.White(),B._Epsilon)&&r.alpha>=B._Epsilon||(t.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,r.alpha]),null!=e.metallic&&1!==e.metallic&&(t.metallicFactor=e.metallic),null!=e.roughness&&1!==e.roughness&&(t.roughnessFactor=e.roughness),null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||L.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),n.doubleSided=!0),a){if(r.bumpTexture){var c=this._exportTextureAsync(r.bumpTexture,i).then((function(e){e&&(n.normalTexture=e,1!==r.bumpTexture.level&&(n.normalTexture.scale=r.bumpTexture.level))}));l.push(c)}r.ambientTexture&&(c=this._exportTextureAsync(r.ambientTexture,i).then((function(e){if(e){var t={index:e.index};n.occlusionTexture=t,r.ambientTextureStrength&&(t.strength=r.ambientTextureStrength)}})),l.push(c)),r.emissiveTexture&&(c=this._exportTextureAsync(r.emissiveTexture,i).then((function(e){e&&(n.emissiveTexture=e)})),l.push(c))}B.FuzzyEquals(r.emissiveColor,L.Color3.Black(),B._Epsilon)||(n.emissiveFactor=r.emissiveColor.asArray()),n.pbrMetallicRoughness=t,s.push(n),o[r.uniqueId]=s.length-1}return Promise.all(l).then((function(e){}))},B.prototype.getPixelsFromTexture=function(e){return e.textureType,L.Engine.TEXTURETYPE_UNSIGNED_INT,e.readPixels()},B.prototype._exportTextureAsync=function(t,r){var n=this,e=this._exporter._extensionsPreExportTextureAsync("exporter",t,r);return e?e.then((function(e){return e?n._exportTextureInfoAsync(e,r):n._exportTextureInfoAsync(t,r)})):this._exportTextureInfoAsync(t,r)},B.prototype._exportTextureInfoAsync=function(u,c){var f=this;return Promise.resolve().then((function(){var r=u.uid;if(r in f._textureMap)return f._textureMap[r];for(var e=f._exporter._samplers,t=f._getGLTFTextureSampler(u),n=null,i=null,a=0;a<e.length;++a){var o=e[a];if(o.minFilter===t.minFilter&&o.magFilter===t.magFilter&&o.wrapS===t.wrapS&&o.wrapT===t.wrapT){i=a;break}}n=null==i?(e.push(t),e.length-1):i;var s=f.getPixelsFromTexture(u),l=u.getSize();return f._createBase64FromCanvasAsync(s,l.width,l.height,c).then((function(e){var t=f._getTextureInfoFromBase64(e,u.name.replace(/\.\/|\/|\.\\|\\/g,"_"),c,u.coordinatesIndex,n);return t&&(f._textureMap[r]=t),t}))}))},B.prototype._getTextureInfoFromBase64=function(e,t,r,n,i){var a=this._exporter._textures,o=this._exporter._images,s=this._exporter._imageData,l=null,u={source:o.length,name:t};null!=i&&(u.sampler=i);for(var c=atob(e.split(",")[1]),f=new ArrayBuffer(c.length),h=new Uint8Array(f),p=0,m=c.length;p<m;++p)h[p]=c.charCodeAt(p);var d={data:h,mimeType:r},g="image/jpeg"===r?".jpeg":".png",_=t+g;if(_ in s&&(_=t+"_"+L.Tools.RandomId()+g),s[_]=d,"image/jpeg"===r||"image/png"===r){var y={name:t,uri:_},x=null;for(p=0;p<o.length;++p)if(o[p].uri===_){x=p;break}u.source=null==x?(o.push(y),o.length-1):x,a.push(u),l={index:a.length-1},null!=n&&(l.texCoord=n)}else L.Tools.Error("Unsupported texture mime type "+r);return l},B._DielectricSpecular=new L.Color3(.04,.04,.04),B._MaxSpecularPower=1024,B._Epsilon=1e-6,B})(),u._GLTFMaterialExporter=c,M=e||(e={}),(function(A){var h,e;(e=h||(h={}))[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT";var t=(function(){function E(){}return E._CreateNodeAnimation=function(e,t,r,n,i,a){var o=[],s=[],l=t.getKeys(),u=E.calculateMinMaxKeyFrames(l),c=E._DeduceInterpolation(l,r,i),f=u.max-u.min,h=c.interpolationType,p=c.shouldBakeAnimation;return p?E._CreateBakedAnimation(e,t,r,u.min,u.max,t.framePerSecond,a,o,s,u,n,i):"LINEAR"===h||"STEP"===h?E._CreateLinearOrStepAnimation(e,t,r,f,o,s,n,i):"CUBICSPLINE"===h?E._CreateCubicSplineAnimation(e,t,r,f,o,s,n,i):E._CreateBakedAnimation(e,t,r,u.min,u.max,t.framePerSecond,a,o,s,u,n,i),o.length&&s.length?{inputs:o,outputs:s,samplerInterpolation:h,inputsMin:p?u.min:M.Tools.FloatRound(u.min/t.framePerSecond),inputsMax:p?u.max:M.Tools.FloatRound(u.max/t.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:M.Tools.Error("Unsupported animatable property "+i[0])}return t?{animationChannelTargetPath:t,dataAccessorType:r,useQuaternion:n}:(M.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},E._CreateNodeAnimationFromTransformNodeAnimations=function(e,t,r,n,i,a,o,s,l,u){var c;if(e.animations)for(var f=0,h=e.animations;f<h.length;f++){var p=h[f],m=E._DeduceAnimationInfo(p);m&&(c={name:p.name,samplers:[],channels:[]},E.AddAnimation(""+p.name,p.hasRunningRuntimeAnimations?t:c,e,p,m.dataAccessorType,m.animationChannelTargetPath,n,a,o,s,l,m.useQuaternion,u),c.samplers.length&&c.channels.length&&r.push(c))}},E._CreateNodeAnimationFromAnimationGroups=function(e,t,r,n,i,a,o,s,l){var u;if(e.animationGroups)for(var c=0,f=e.animationGroups;c<f.length;c++){var h=f[c];u={name:h.name,channels:[],samplers:[]};for(var p=0,m=h.targetedAnimations;p<m.length;p++){var d=m[p],g=d.target,_=d.animation;if(g instanceof M.Mesh||1===g.length&&g[0]instanceof M.Mesh){var y=E._DeduceAnimationInfo(d.animation);if(y){var x=g instanceof M.Mesh?g:g[0];E.AddAnimation(""+_.name,u,x,_,y.dataAccessorType,y.animationChannelTargetPath,r,i,a,o,s,y.useQuaternion,l)}}}u.channels.length&&u.samplers.length&&t.push(u)}},E.AddAnimation=function(e,t,r,n,i,a,o,s,l,u,c,f,h){var p,m,d,g,_,y,x,T=E._CreateNodeAnimation(r,n,a,c,f,h);if(T){var v=o[r.uniqueId],b=4*T.inputs.length;p=A._GLTFUtilities._CreateBufferView(0,s.getByteOffset(),b,void 0,e+" keyframe data view"),l.push(p),T.inputs.forEach((function(e){s.setFloat32(e)})),m=A._GLTFUtilities._CreateAccessor(l.length-1,e+" keyframes","SCALAR",5126,T.inputs.length,null,[T.inputsMin],[T.inputsMax]),u.push(m),d=u.length-1,_=T.outputs.length,b="VEC3"===i?12*T.outputs.length:16*T.outputs.length,p=A._GLTFUtilities._CreateBufferView(0,s.getByteOffset(),b,void 0,e+" data view"),l.push(p),T.outputs.forEach((function(e){e.forEach((function(e){s.setFloat32(e)}))})),m=A._GLTFUtilities._CreateAccessor(l.length-1,e+" data",i,5126,_,null,null,null),u.push(m),g=u.length-1,y={interpolation:T.samplerInterpolation,input:d,output:g},t.samplers.push(y),x={sampler:t.samplers.length-1,target:{node:v,path:a}},t.channels.push(x)}},E._CreateBakedAnimation=function(e,t,r,n,i,a,o,s,l,u,c,f){var h,p,m=M.Quaternion.Identity(),d=null,g=null,_=null,y=null,x=null,T=null;u.min=M.Tools.FloatRound(n/a);for(var v=t.getKeys(),b=0,A=v.length;b<A;++b){if(T=null,_=v[b],b+1<A)if(y=v[b+1],_.value.equals(y.value)){if(0!==b)continue;T=_.frame}else T=y.frame;else{if(x=v[b-1],_.value.equals(x.value))continue;T=i}if(T)for(var F=_.frame;F<=T;F+=o)(p=M.Tools.FloatRound(F/a))!==d&&(g=d=p,h=t._interpolate(F,0,void 0,t.loopMode),E._SetInterpolatedValue(e,h,p,t,r,m,s,l,c,f))}g&&(u.max=g)},E._ConvertFactorToVector3OrQuaternion=function(e,t,r,n,i,a,o){var s,l,u=null,c=E._GetBasePositionRotationOrScale(t,i,a,o);if(n===M.Animation.ANIMATIONTYPE_FLOAT)switch(l=(s=r.targetProperty.split("."))?s[1]:"",u=o?M.Quaternion.FromArray(c).normalize():M.Vector3.FromArray(c),l){case"x":case"y":u[l]=a&&o&&"scale"!==i?-e:e;break;case"z":u[l]=a&&!o&&"scale"!==i?-e:e;break;case"w":u.w=e;break;default:M.Tools.Error('glTFAnimation: Unsupported component type "'+l+'" for scale animation!')}return u},E._SetInterpolatedValue=function(e,t,r,n,i,a,o,s,l,u){var c,f=n.dataType;o.push(r),"number"==typeof t&&(t=this._ConvertFactorToVector3OrQuaternion(t,e,n,f,i,l,u)),t&&("rotation"===i?(u?a=t:(c=t,M.Quaternion.RotationYawPitchRollToRef(c.y,c.x,c.z,a)),l&&(A._GLTFUtilities._GetRightHandedQuaternionFromRef(a),e.parent||(a=M.Quaternion.FromArray([0,1,0,0]).multiply(a))),s.push(a.asArray())):(c=t,l&&"scale"!==i&&(A._GLTFUtilities._GetRightHandedPositionVector3FromRef(c),e.parent||(c.x*=-1,c.z*=-1)),s.push(c.asArray())))},E._CreateLinearOrStepAnimation=function(e,t,r,n,i,a,o,s){for(var l=0,u=t.getKeys();l<u.length;l++){var c=u[l];i.push(c.frame/t.framePerSecond),E._AddKeyframeValue(c,t,a,r,e,o,s)}},E._CreateCubicSplineAnimation=function(t,r,n,i,a,o,s,l){r.getKeys().forEach((function(e){a.push(e.frame/r.framePerSecond),E.AddSplineTangent(t,h.INTANGENT,o,n,"CUBICSPLINE",e,i,l,s),E._AddKeyframeValue(e,r,o,n,t,s,l),E.AddSplineTangent(t,h.OUTTANGENT,o,n,"CUBICSPLINE",e,i,l,s)}))},E._GetBasePositionRotationOrScale=function(e,t,r,n){var i;return"rotation"===t?n?e.rotationQuaternion?(i=e.rotationQuaternion.asArray(),r&&(A._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(i),e.parent||(i=M.Quaternion.FromArray([0,1,0,0]).multiply(M.Quaternion.FromArray(i)).asArray()))):i=M.Quaternion.Identity().asArray():(i=e.rotation.asArray(),A._GLTFUtilities._GetRightHandedNormalArray3FromRef(i)):"translation"===t?(i=e.position.asArray(),r&&A._GLTFUtilities._GetRightHandedPositionArray3FromRef(i)):i=e.scaling.asArray(),i},E._AddKeyframeValue=function(e,t,r,n,i,a,o){var s,l,u=t.dataType;if(u===M.Animation.ANIMATIONTYPE_VECTOR3){if(s=e.value.asArray(),"rotation"===n){var c=M.Vector3.FromArray(s),f=M.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z);a&&(A._GLTFUtilities._GetRightHandedQuaternionFromRef(f),i.parent||(f=M.Quaternion.FromArray([0,1,0,0]).multiply(f))),s=f.asArray()}else"translation"===n&&a&&(A._GLTFUtilities._GetRightHandedNormalArray3FromRef(s),i.parent||(s[0]*=-1,s[2]*=-1));r.push(s)}else if(u===M.Animation.ANIMATIONTYPE_FLOAT){if(l=this._ConvertFactorToVector3OrQuaternion(e.value,i,t,u,n,a,o)){if("rotation"===n){var h=o?l:M.Quaternion.RotationYawPitchRoll(l.y,l.x,l.z).normalize();a&&(A._GLTFUtilities._GetRightHandedQuaternionFromRef(h),i.parent||(h=M.Quaternion.FromArray([0,1,0,0]).multiply(h))),r.push(h.asArray())}else"translation"===n&&a&&(A._GLTFUtilities._GetRightHandedNormalVector3FromRef(l),i.parent||(l.x*=-1,l.z*=-1));r.push(l.asArray())}}else u===M.Animation.ANIMATIONTYPE_QUATERNION?(s=e.value.normalize().asArray(),a&&(A._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(s),i.parent||(s=M.Quaternion.FromArray([0,1,0,0]).multiply(M.Quaternion.FromArray(s)).asArray())),r.push(s)):M.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 o=0,s=e.length;o<s;++o)if((i=e[o]).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===M.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",a=!0;break}}else n=i.interpolation&&i.interpolation===M.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:a}},E.AddSplineTangent=function(e,t,r,n,i,a,o,s,l){var u,c=t===h.INTANGENT?a.inTangent:a.outTangent;if("CUBICSPLINE"===i){if("rotation"===n)if(c){if(s)u=c.scale(o).asArray();else{var f=c.scale(o);u=M.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z).asArray()}l&&(A._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(u),e.parent||(u=M.Quaternion.FromArray([0,1,0,0]).multiply(M.Quaternion.FromArray(u)).asArray()))}else u=[0,0,0,0];else c?(u=c.scale(o).asArray(),l&&"translation"===n&&(A._GLTFUtilities._GetRightHandedPositionArray3FromRef(u),e.parent||(u[0]*=-1,u[2]*=-1))):u=[0,0,0];r.push(u)}},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})();A._GLTFAnimation=t})((f=M.GLTF2||(M.GLTF2={})).Exporter||(f.Exporter={})),m=e||(e={}),h=m.GLTF2||(m.GLTF2={}),p=h.Exporter||(h.Exporter={}),d=(function(){function p(){}return p._CreateBufferView=function(e,t,r,n,i){var a={buffer:e,byteLength:r};return t&&(a.byteOffset=t),i&&(a.name=i),n&&(a.byteStride=n),a},p._CreateAccessor=function(e,t,r,n,i,a,o,s){var l={name:t,bufferView:e,componentType:n,count:i,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=a&&(l.byteOffset=a),l},p._CalculateMinMaxPositions=function(e,t,r,n){var i,a,o,s=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];if(r)for(var u=t,c=t+r;u<c;++u){i=3*u,a=m.Vector3.FromArray(e,i),n&&p._GetRightHandedPositionVector3FromRef(a),o=a.asArray();for(var f=0;f<3;++f){var h=o[f];h<s[f]&&(s[f]=h),h>l[f]&&(l[f]=h),++i}}return{min:s,max:l}},p._GetRightHandedPositionVector3=function(e){return new m.Vector3(e.x,e.y,-e.z)},p._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},p._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},p._GetRightHandedNormalVector3=function(e){return new m.Vector3(e.x,e.y,-e.z)},p._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},p._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},p._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},p._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},p._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},p._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},p._NormalizeTangentFromRef=function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);0<t&&(e.x/=t,e.y/=t,e.z/=t)},p})(),p._GLTFUtilities=d,g=e||(e={}),_=g.GLTF2||(g.GLTF2={}),y=_.Exporter||(_.Exporter={}),x=y.Extensions||(y.Extensions={}),T="KHR_texture_transform",v=(function(){function e(e){this.name=T,this.enabled=!0,this.required=!1,this._exporter=e}return e.prototype.dispose=function(){delete this._exporter},e.prototype.preExportTextureAsync=function(s,l,e){var u=this;return new Promise(function(t,e){var r={};0===l.uOffset&&0===l.vOffset||(r.offset=[l.uOffset,l.vOffset]),1===l.uScale&&1===l.vScale||(r.scale=[l.uScale,l.vScale]),0!==l.wAng&&(r.rotation=l.wAng),Object.keys(r).length||t(l);var n=r.scale?new g.Vector2(r.scale[0],r.scale[1]):g.Vector2.One(),i=null!=r.rotation?r.rotation:0,a=r.offset?new g.Vector2(r.offset[0],r.offset[1]):g.Vector2.Zero(),o=l.getScene();o?u.textureTransformTextureAsync(l,a,i,n,o).then((function(e){t(e)})):e(s+': "scene" is not defined for Babylon texture '+l.name+"!")})},e.prototype.textureTransformTextureAsync=function(n,e,t,r,i){return new Promise(function(e,t){var r=new g.ProceduralTexture(""+n.name,n.getSize(),"textureTransform",i);r||(g.Tools.Log("Cannot create procedural texture for "+n.name+"!"),e(n)),r.setTexture("textureSampler",n),r.setMatrix("textureTransformMat",n.getTextureMatrix()),r.isReady()?(r.render(),e(r)):r.getEffect().executeWhenCompiled((function(){r.render(),e(r)}))})},e})(),x.KHR_texture_transform=v,y._Exporter.RegisterExtension(T,(function(e){return new v(e)})),e})); |
@@ -7,3 +7,3 @@ { | ||
"description": "The Babylon.js serializers library is an extension you can use to serialize Babylon scenes.", | ||
"version": "4.0.0-alpha.2", | ||
"version": "4.0.0-alpha.3", | ||
"repository": { | ||
@@ -31,4 +31,4 @@ "type": "git", | ||
"dependencies": { | ||
"babylonjs": "4.0.0-alpha.2", | ||
"babylonjs-gltf2interface": "4.0.0-alpha.2" | ||
"babylonjs": "4.0.0-alpha.3", | ||
"babylonjs-gltf2interface": "4.0.0-alpha.3" | ||
}, | ||
@@ -35,0 +35,0 @@ "engines": { |
331282
+ Addedbabylonjs@4.0.0-alpha.3(transitive)
+ Addedbabylonjs-gltf2interface@4.0.0-alpha.3(transitive)
- Removedbabylonjs@4.0.0-alpha.2(transitive)
- Removedbabylonjs-gltf2interface@4.0.0-alpha.2(transitive)
Updatedbabylonjs@4.0.0-alpha.3