Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babylonjs-serializers

Package Overview
Dependencies
Maintainers
1
Versions
648
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babylonjs-serializers - npm Package Compare versions

Comparing version 3.3.0-alpha.9 to 3.3.0-alpha.10

4

babylonjs.serializers.min.js

@@ -1,2 +0,2 @@

!(function(e,t){var r=[],a=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(a=a||require("babylonjs"),module.exports=t(a)):"function"==typeof define&&define.amd?(r.push("babylonjs"),define("babylonjs-serializers",r,t)):"object"==typeof exports?(a=a||require("babylonjs"),exports["babylonjs-serializers"]=t(a)):e.BABYLON=t(a)})(this,(function(e){e=e||this.BABYLON;var e;this&&this.__decorate,this&&this.__extends||(function(){var e=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])}})();!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var n=[],o=1;r&&(a||(a="mat"),n.push("mtllib "+a+".mtl"));for(var s=0;s<t.length;s++){n.push("g object"+s),n.push("o object_"+s);var l=null;if(i){var u=e.Matrix.Translation(t[s].position.x,t[s].position.y,t[s].position.z);l=e.Matrix.Translation(-t[s].position.x,-t[s].position.y,-t[s].position.z),t[s].bakeTransformIntoVertices(u)}if(r){var c=t[s].material;c&&n.push("usemtl "+c.id)}var h=t[s].geometry;if(h){var f=h.getVerticesData("position"),p=h.getVerticesData("normal"),d=h.getVerticesData("uv"),m=h.getIndices(),g=0;if(f&&p&&d&&m){for(var y=0;y<f.length;y+=3)n.push("v "+f[y]+" "+f[y+1]+" "+f[y+2]),g++;for(y=0;y<p.length;y+=3)n.push("vn "+p[y]+" "+p[y+1]+" "+p[y+2]);for(y=0;y<d.length;y+=2)n.push("vt "+d[y]+" "+d[y+1]);for(y=0;y<m.length;y+=3)n.push("f "+(m[y+2]+o)+"/"+(m[y+2]+o)+"/"+(m[y+2]+o)+" "+(m[y+1]+o)+"/"+(m[y+1]+o)+"/"+(m[y+1]+o)+" "+(m[y]+o)+"/"+(m[y]+o)+"/"+(m[y]+o));i&&l&&t[s].bakeTransformIntoVertices(l),o+=g}}}return n.join("\n")},t.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")},t})();e.OBJExport=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.GLTFAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLTFAsync(i)}))},t.GLBAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLBAsync(i)}))},t})();e.GLTF2Export=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function r(e,r){this._asset={generator:"BabylonJS",version:"2.0"},this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._animations=[],this._imageData={},this._convertToRightHandedSystem=!this._babylonScene.useRightHandedSystem;var a=r||{};this._shouldExportTransformNode=a.shouldExportTransformNode?a.shouldExportTransformNode:function(e){return!0},this._animationSampleRate=a.animationSampleRate?a.animationSampleRate:1/60,this._glTFMaterialExporter=new t._GLTFMaterialExporter(this)}return r.prototype._getLocalEngine=function(){if(!this._localEngine){var t=document.createElement("canvas");t.id="WriteCanvas",t.width=2048,t.height=2048,this._localEngine=new e.Engine(t,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!0}),this._localEngine.setViewport(new e.Viewport(0,0,1,1))}return this._localEngine},r.prototype.reorderIndicesBasedOnPrimitiveMode=function(t,r,a,i,n){switch(r){case e.Material.TriangleFillMode:i||(i=0);for(var o=t.indexStart,s=t.indexStart+t.indexCount;o<s;o+=3){var l=i+4*o,u=n.getUInt32(l+4),c=n.getUInt32(l+8);n.setUInt32(c,l+4),n.setUInt32(u,l+8)}break;case e.Material.TriangleFanDrawMode:for(var o=t.indexStart+t.indexCount-1,h=t.indexStart;o>=h;--o)n.setUInt32(a[o],i),i+=4;break;case e.Material.TriangleStripDrawMode:t.indexCount>=3&&(n.setUInt32(a[t.indexStart+2],i+4),n.setUInt32(a[t.indexStart+1],i+8))}},r.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(t,r,a,i,n,o,s){if(this._convertToRightHandedSystem&&a===e.Material.ClockWiseSideOrientation)switch(r){case e.Material.TriangleFillMode:this.reorderTriangleFillMode(t,r,a,i,n,o,s);break;case e.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(t,r,a,i,n,o,s);break;case e.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(t,r,a,i,n,o,s)}},r.prototype.reorderTriangleFillMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type);if(t.verticesCount%3!=0)e.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector3.FromArray(n,h)),c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector4.FromArray(n,h)),c.push(e.Vector4.FromArray(n,h+2*u)),c.push(e.Vector4.FromArray(n,h+u));break;case e.VertexBuffer.ColorKind:for(var p=l.getSize(),f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=p)h=f*u,4===p?(c.push(e.Vector4.FromArray(n,h)),c.push(e.Vector4.FromArray(n,h+2*u)),c.push(e.Vector4.FromArray(n,h+u))):(c.push(e.Vector3.FromArray(n,h)),c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u)));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector2.FromArray(n,h)),c.push(e.Vector2.FromArray(n,h+2*u)),c.push(e.Vector2.FromArray(n,h+u));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o,i,n,s)}}else e.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+i+" not present!")},r.prototype.reorderTriangleStripDrawMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:h=t.verticesStart,c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h));break;case e.VertexBuffer.ColorKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,4===l.getSize()?c.push(e.Vector4.FromArray(n,h)):c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector2.FromArray(n,h));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o+12,i,n,s)}else e.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+i+" not present!")},r.prototype.reorderTriangleFanMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h));break;case e.VertexBuffer.ColorKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h)),4===l.getSize()?c.push(e.Vector4.FromArray(n,h)):c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector2.FromArray(n,h));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o,i,n,s)}else e.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+i+" not present!")},r.prototype.writeVertexAttributeData=function(r,a,i,n,o){for(var s=0,l=r;s<l.length;s++){var u=l[s];!this._convertToRightHandedSystem||i===e.VertexBuffer.ColorKind||u instanceof e.Vector2||(u instanceof e.Vector3?i===e.VertexBuffer.PositionKind?t._GLTFUtilities.GetRightHandedPositionVector3FromRef(u):t._GLTFUtilities.GetRightHandedNormalVector3FromRef(u):t._GLTFUtilities.GetRightHandedVector4FromRef(u));for(var c=0,h=u.asArray();c<h.length;c++){var f=h[c];o.setFloat32(f,a),a+=4}}},r.prototype.writeAttributeData=function(r,a,i,n){var o,s=i/4,l=[];switch(r){case e.VertexBuffer.PositionKind:for(var u=0,c=a.length/s;u<c;++u){o=u*s;var h=e.Vector3.FromArray(a,o);this._convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedPositionVector3FromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.NormalKind:for(var u=0,f=a.length/s;u<f;++u){o=u*s;var h=e.Vector3.FromArray(a,o);this._convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedNormalVector3FromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.TangentKind:for(var u=0,p=a.length/s;u<p;++u){o=u*s;var h=e.Vector4.FromArray(a,o);this._convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedVector4FromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.ColorKind:for(var u=0,d=a.length/s;u<d;++u){o=u*s;var h=3===s?e.Vector3.FromArray(a,o):e.Vector4.FromArray(a,o);l.push(h.asArray())}break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var u=0,m=a.length/s;u<m;++u)o=u*s,l.push((this._convertToRightHandedSystem,[a[o],a[o+1]]));break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+r),l=[]}for(var g=0,y=l;g<y.length;g++)for(var T=y[g],_=0,x=T;_<x.length;_++){var v=x[_];n.setFloat32(v)}},r.prototype.generateJSON=function(e,r,a){var i,n,o,s=this,l={byteLength:this._totalByteLength},u=this._totalByteLength,c={asset:this._asset};return l.byteLength&&(c.buffers=[l]),this._nodes&&this._nodes.length&&(c.nodes=this._nodes),this._meshes&&this._meshes.length&&(c.meshes=this._meshes),this._scenes&&this._scenes.length&&(c.scenes=this._scenes,c.scene=0),this._bufferViews&&this._bufferViews.length&&(c.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(c.accessors=this._accessors),this._animations&&this._animations.length&&(c.animations=this._animations),this._materials&&this._materials.length&&(c.materials=this._materials),this._textures&&this._textures.length&&(c.textures=this._textures),this._samplers&&this._samplers.length&&(c.samplers=this._samplers),this._images&&this._images.length&&(e?(c.images=[],this._images.forEach((function(e){e.uri&&(n=s._imageData[e.uri],i=e.uri.split(".")[0]+" image",o=t._GLTFUtilities.CreateBufferView(0,u,n.data.length,void 0,i),u+=n.data.buffer.byteLength,s._bufferViews.push(o),e.bufferView=s._bufferViews.length-1,e.name=i,e.mimeType=n.mimeType,e.uri=void 0,c.images||(c.images=[]),c.images.push(e))})),l.byteLength=u):c.images=this._images),e||(l.uri=r+".bin"),a?JSON.stringify(c,null,2):JSON.stringify(c)},r.prototype._generateGLTFAsync=function(t){var r=this;return this._generateBinaryAsync().then((function(a){var i=r.generateJSON(!1,t,!0),n=new Blob([a],{type:"application/octet-stream"}),o=t+".gltf",s=t+".bin",l=new e.GLTFData;if(l.glTFFiles[o]=i,l.glTFFiles[s]=n,r._imageData)for(var u in r._imageData)l.glTFFiles[u]=new Blob([r._imageData[u].data],{type:r._imageData[u].mimeType});return l}))},r.prototype._generateBinaryAsync=function(){var e=this,t=new a(4);return this.createSceneAsync(this._babylonScene,t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},r.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},r.prototype._generateGLBAsync=function(t){var r=this;return this._generateBinaryAsync().then((function(a){var i=r.generateJSON(!0),n=t+".glb",o=i.length,s=0;for(var l in r._imageData)s+=r._imageData[l].data.byteLength;var u=r._getPadding(o),c=r._getPadding(a.byteLength),h=r._getPadding(s),f=28+o+u+a.byteLength+c+s+h,p=new ArrayBuffer(12),d=new DataView(p);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,f,!0);var m=new ArrayBuffer(8+o+u),g=new DataView(m);g.setUint32(0,o+u,!0),g.setUint32(4,1313821514,!0);for(var y=new Uint8Array(m,8),T=0;T<o;++T)y[T]=i.charCodeAt(T);for(var _=new Uint8Array(m,8+o),T=0;T<u;++T)_[T]=32;var x=new ArrayBuffer(8),v=new DataView(x);v.setUint32(0,a.byteLength+s+h,!0),v.setUint32(4,5130562,!0);for(var b=new ArrayBuffer(c),A=new Uint8Array(b),T=0;T<c;++T)A[T]=0;for(var F=new ArrayBuffer(h),M=new Uint8Array(F),T=0;T<h;++T)M[T]=0;var R=[p,m,x,a];for(var l in r._imageData)R.push(r._imageData[l].data.buffer);R.push(b),R.push(F);var S=new Blob(R,{type:"application/octet-stream"}),V=new e.GLTFData;return V.glTFFiles[n]=S,r._localEngine.dispose(),V}))},r.prototype.setNodeTransformation=function(r,a){a.position.equalsToFloats(0,0,0)||(r.translation=this._convertToRightHandedSystem?t._GLTFUtilities.GetRightHandedPositionVector3(a.position).asArray():a.position.asArray()),a.scaling.equalsToFloats(1,1,1)||(r.scale=a.scaling.asArray());var i=e.Quaternion.RotationYawPitchRoll(a.rotation.y,a.rotation.x,a.rotation.z);a.rotationQuaternion&&i.multiplyInPlace(a.rotationQuaternion),0===i.x&&0===i.y&&0===i.z&&1===i.w||(this._convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedQuaternionFromRef(i),r.rotation=i.normalize().asArray())},r.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},r.prototype.createBufferViewKind=function(r,a,i,n){var o=a instanceof e.Mesh?a:a instanceof e.InstancedMesh?a.sourceMesh:null;if(o){var s=o.getVerticesData(r);if(s){var l=4*s.length,u=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),l,n,r+" - "+o.name);this._bufferViews.push(u),this.writeAttributeData(r,s,n,i)}}},r.prototype.getMeshPrimitiveMode=function(t){return t instanceof e.LinesMesh?e.Material.LineListDrawMode:t.material?t.material.fillMode:e.Material.TriangleFillMode},r.prototype.setPrimitiveMode=function(t,r){switch(r){case e.Material.TriangleFillMode:break;case e.Material.TriangleStripDrawMode:t.mode=5;break;case e.Material.TriangleFanDrawMode:t.mode=6;break;case e.Material.PointListDrawMode:t.mode=0;case e.Material.PointFillMode:t.mode=0;break;case e.Material.LineLoopDrawMode:t.mode=2;break;case e.Material.LineListDrawMode:t.mode=1;break;case e.Material.LineStripDrawMode:t.mode=3}},r.prototype.setAttributeKind=function(t,r){switch(r){case e.VertexBuffer.PositionKind:t.attributes.POSITION=this._accessors.length-1;break;case e.VertexBuffer.NormalKind:t.attributes.NORMAL=this._accessors.length-1;break;case e.VertexBuffer.ColorKind:t.attributes.COLOR_0=this._accessors.length-1;break;case e.VertexBuffer.TangentKind:t.attributes.TANGENT=this._accessors.length-1;break;case e.VertexBuffer.UVKind:t.attributes.TEXCOORD_0=this._accessors.length-1;break;case e.VertexBuffer.UV2Kind:t.attributes.TEXCOORD_1=this._accessors.length-1;break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+r)}},r.prototype.setPrimitiveAttributes=function(r,a,i){var n,o,s,l=null;a instanceof e.Mesh?l=a:a instanceof e.InstancedMesh&&(l=a.sourceMesh);var u=[{kind:e.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:e.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(l){for(var c=null,h=this.getMeshPrimitiveMode(l),f={},p=0,d=u;p<d.length;p++){var m=d[p],g=m.kind;if(l.isVerticesDataPresent(g)){var y=this.getVertexBufferFromMesh(g,l);m.byteStride=y?4*y.getSize():4*e.VertexBuffer.DeduceStride(g),12===m.byteStride&&(m.accessorType="VEC3"),this.createBufferViewKind(g,a,i,m.byteStride),m.bufferViewIndex=this._bufferViews.length-1,f[g]=m.bufferViewIndex}}if(l.getTotalIndices()){var T=l.getIndices();if(T){var _=4*T.length;n=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),_,void 0,"Indices - "+l.name),this._bufferViews.push(n),c=this._bufferViews.length-1;for(var x=0,v=T.length;x<v;++x)i.setUInt32(T[x])}}if(l.subMeshes)for(var b=0,A=l.subMeshes;b<A.length;b++){var F=A[b];o=!1;var M=F.getMaterial(),R=null;if(M)if(l instanceof e.LinesMesh){var S={name:l.name+" material"};(!l.color.equals(e.Color3.White())||l.alpha<1)&&(S.pbrMetallicRoughness={baseColorFactor:l.color.asArray().concat([l.alpha])}),this._materials.push(S),R=this._materials.length-1}else M instanceof e.MultiMaterial?(M=M.subMaterials[F.materialIndex])&&(R=this._materialMap[M.uniqueId]):R=this._materialMap[M.uniqueId];var V=null!=R?this._materials[R]:null,C={attributes:{}};this.setPrimitiveMode(C,h);for(var E=0,B=u;E<B.length;E++){var m=B[E],g=m.kind;if(g!==e.VertexBuffer.UVKind&&g!==e.VertexBuffer.UV2Kind||!V||this._glTFMaterialExporter._hasTexturesPresent(V)){var w=l.getVerticesData(g);if(w){var y=this.getVertexBufferFromMesh(g,l);if(y){var L=y.getSize(),P=m.bufferViewIndex;if(void 0!=P){s={min:null,max:null},g==e.VertexBuffer.PositionKind&&(s=t._GLTFUtilities.CalculateMinMaxPositions(w,0,w.length/L,this._convertToRightHandedSystem));var N=t._GLTFUtilities.CreateAccessor(P,g+" - "+a.name,m.accessorType,5126,w.length/L,0,s.min,s.max);this._accessors.push(N),this.setAttributeKind(C,g),null==C.attributes.TEXCOORD_0&&null==C.attributes.TEXCOORD_1||(o=!0)}}}}}if(c){var N=t._GLTFUtilities.CreateAccessor(c,"indices - "+a.name,"SCALAR",5125,F.indexCount,4*F.indexStart,null,null);this._accessors.push(N),C.indices=this._accessors.length-1}if(null!=R&&Object.keys(C.attributes).length>0){var G=this._babylonScene.materials[R].sideOrientation;if(this._convertToRightHandedSystem&&G===e.Material.ClockWiseSideOrientation){var I=null!=c?this._bufferViews[c].byteOffset:null;null==I&&(I=0);var U=null;if(null!=c&&(U=l.getIndices()),U)this.reorderIndicesBasedOnPrimitiveMode(F,h,U,I,i);else for(var O=0,D=u;O<D.length;O++){var m=D[O],w=l.getVerticesData(m.kind);if(w){var k=this._bufferViews[f[m.kind]].byteOffset;k||(k=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(F,h,G,m.kind,w,k,i)}}}if(!o&&this._glTFMaterialExporter._hasTexturesPresent(this._materials[R])){var K=this._glTFMaterialExporter._stripTexturesFromMaterial(this._materials[R]);this._materials.push(K),R=this._materials.length-1}C.material=R}r.primitives.push(C)}}},r.prototype.createSceneAsync=function(t,r){var a,i,n,o=this,s={nodes:[]},l=t.transformNodes.concat(t.meshes);return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(t.materials,"image/png",!0).then((function(){o._nodeMap=o.createNodeMapAndAnimations(t,l,o._shouldExportTransformNode,r),o._totalByteLength=r.getByteOffset();for(var u=0,c=l;u<c.length;u++){var h=c[u];if(null!=(a=o._nodeMap[h.uniqueId])&&(i=o._nodes[a],h.parent||(o._shouldExportTransformNode(h)?(o._convertToRightHandedSystem&&(i.translation&&(i.translation[2]*=-1,i.translation[0]*=-1),i.rotation=i.rotation?e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(i.rotation)).asArray():e.Quaternion.FromArray([0,1,0,0]).asArray()),s.nodes.push(a)):e.Tools.Log("Omitting "+h.name+" from scene.")),n=h.getDescendants(!0),!i.children&&n&&n.length)){i.children=[];for(var f=0,p=n;f<p.length;f++){var d=p[f];null!=o._nodeMap[d.uniqueId]&&i.children.push(o._nodeMap[d.uniqueId])}}}s.nodes.length&&o._scenes.push(s)}))},r.prototype.createNodeMapAndAnimations=function(e,r,a,i){for(var n,o,s=this,l={},u={name:"runtime animations",channels:[],samplers:[]},c=[],h=0,f=r;h<f.length;h++){var p=f[h];a(p)?(o=this.createNode(p,i),this._nodes.push(o),n=this._nodes.length-1,l[p.uniqueId]=n,!e.animationGroups.length&&p.animations.length&&t._GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations(p,u,c,l,this._nodes,i,this._bufferViews,this._accessors,this._convertToRightHandedSystem,this._animationSampleRate)):p.name}return u.channels.length&&u.samplers.length&&this._animations.push(u),c.forEach((function(e){e.channels.length&&e.samplers.length&&s._animations.push(e)})),e.animationGroups.length&&t._GLTFAnimation._CreateNodeAnimationFromAnimationGroups(e,this._animations,l,this._nodes,i,this._bufferViews,this._accessors,this._convertToRightHandedSystem,this._animationSampleRate),l},r.prototype.createNode=function(e,t){var r={},a={primitives:[]};return e.name&&(r.name=e.name),this.setNodeTransformation(r,e),this.setPrimitiveAttributes(a,e,t),a.primitives.length&&(this._meshes.push(a),r.mesh=this._meshes.length-1),r},r})();t._Exporter=r;var a=(function(){function t(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return t.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),a=new Uint8Array(t),i=0,n=a.byteLength;i<n;++i)a[i]=r[i];this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer)},t.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset()),this._arrayBuffer},t.prototype.getByteOffset=function(){return this._byteOffset},t.prototype.setUInt8=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint8(r,t):e.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++,t))},t.prototype.getUInt32=function(t){if(t<this._byteOffset)return this._dataView.getUint32(t,!0);throw e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},t.prototype.getVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0))},t.prototype.setVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0))},t.prototype.getVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0),t.w=this._dataView.getFloat32(r+12,!0))},t.prototype.setVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0),this._dataView.setFloat32(r+12,t.w,!0))},t.prototype.setFloat32=function(t,r){isNaN(t)&&e.Tools.Error("Invalid data being written!"),null!=r&&(r<this._byteOffset?this._dataView.setFloat32(r,t,!0):e.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,t,!0),this._byteOffset+=4},t.prototype.setUInt32=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint32(r,t,!0):e.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,t,!0),this._byteOffset+=4)},t})();t._BinaryWriter=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){var t=(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 a=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([a],i)),r.click()}},e})();e.GLTFData=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function t(e){this._textureMap={},this._textureMap={},this._exporter=e}return t.FuzzyEquals=function(t,r,a){return e.Scalar.WithinEpsilon(t.r,r.r,a)&&e.Scalar.WithinEpsilon(t.g,r.g,a)&&e.Scalar.WithinEpsilon(t.b,r.b,a)},t.prototype._convertMaterialsToGLTFAsync=function(t,r,a){for(var i=[],n=0,o=t;n<o.length;n++){var s=o[n];s instanceof e.StandardMaterial?i.push(this._convertStandardMaterialAsync(s,r,a)):s instanceof e.PBRMetallicRoughnessMaterial?i.push(this._convertPBRMetallicRoughnessMaterialAsync(s,r,a)):s instanceof e.PBRMaterial?i.push(this._convertPBRMaterialAsync(s,r,a)):e.Tools.Warn("Unsupported material type: "+s.name)}return Promise.all(i).then((function(){}))},t.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},t.prototype._hasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},t.prototype._convertToGLTFPBRMetallicRoughness=function(r){function a(e,t,r,a,i){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*a+e*e*e*i}var i=new e.Vector2(0,1),n=new e.Vector2(0,.1),o=new e.Vector2(0,.1),s=new e.Vector2(1300,.1),l=r.diffuseColor.toLinearSpace().scale(.5),u=r.alpha,c=e.Scalar.Clamp(r.specularPower,0,t._MaxSpecularPower),h=(function(e){return a(Math.pow(e/s.x,.333333),i.y,n.y,o.y,s.y)})(c);return{baseColorFactor:[l.r,l.g,l.b,u],metallicFactor:0,roughnessFactor:h}},t._SolveMetallic=function(t,r,a){if(r<this._DielectricSpecular.r)return this._DielectricSpecular,0;var i=this._DielectricSpecular.r,n=t*a/(1-this._DielectricSpecular.r)+r-2*this._DielectricSpecular.r,o=this._DielectricSpecular.r-r,s=n*n-4*i*o;return e.Scalar.Clamp((-n+Math.sqrt(s))/(2*i),0,1)},t.prototype._getAlphaMode=function(e){return e.needAlphaBlending()?"BLEND":e.needAlphaTesting()?"MASK":"OPAQUE"},t.prototype._convertStandardMaterialAsync=function(r,a,i){var n=this._exporter._materialMap,o=this._exporter._materials,s=this._getAlphaMode(r),l=[],u=this._convertToGLTFPBRMetallicRoughness(r),c={name:r.name};if(null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),c.doubleSided=!0),i&&(r.diffuseTexture&&l.push(this._exportTextureAsync(r.diffuseTexture,a).then((function(e){e&&(u.baseColorTexture=e)}))),r.bumpTexture&&l.push(this._exportTextureAsync(r.bumpTexture,a).then((function(e){e&&(c.normalTexture=e,null!=r.bumpTexture&&1!==r.bumpTexture.level&&(c.normalTexture.scale=r.bumpTexture.level))}))),r.emissiveTexture&&(c.emissiveFactor=[1,1,1],l.push(this._exportTextureAsync(r.emissiveTexture,a).then((function(e){e&&(c.emissiveTexture=e)})))),r.ambientTexture&&l.push(this._exportTextureAsync(r.ambientTexture,a).then((function(e){if(e){var t={index:e.index};c.occlusionTexture=t,t.strength=1}})))),(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?c.alphaMode="BLEND":e.Tools.Warn(r.name+": glTF 2.0 does not support alpha mode: "+r.alphaMode.toString())),r.emissiveColor&&!t.FuzzyEquals(r.emissiveColor,e.Color3.Black(),t._Epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),c.pbrMetallicRoughness=u,"OPAQUE"!==s)switch(s){case"BLEND":c.alphaMode="BLEND";break;case"MASK":c.alphaMode="MASK",c.alphaCutoff=r.alphaCutOff;break;default:e.Tools.Warn("Unsupported alpha mode "+s)}return o.push(c),n[r.uniqueId]=o.length-1,Promise.all(l).then((function(){}))},t.prototype._convertPBRMetallicRoughnessMaterialAsync=function(r,a,i){var n=this._exporter._materialMap,o=this._exporter._materials,s=[],l={};r.baseColor&&(l.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,r.alpha]),null!=r.metallic&&1!==r.metallic&&(l.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(l.roughnessFactor=r.roughness);var u={name:r.name};r.doubleSided&&(u.doubleSided=r.doubleSided);var c=null;return null!=r.transparencyMode&&(c=this._getAlphaMode(r))&&"OPAQUE"!==c&&(u.alphaMode=c,"MASK"===c&&(u.alphaCutoff=r.alphaCutOff)),i&&(null!=r.baseTexture&&s.push(this._exportTextureAsync(r.baseTexture,a).then((function(e){e&&(l.baseColorTexture=e)}))),r.normalTexture&&s.push(this._exportTextureAsync(r.normalTexture,a).then((function(e){e&&(u.normalTexture=e,1!==r.normalTexture.level&&(u.normalTexture.scale=r.normalTexture.level))}))),r.occlusionTexture&&s.push(this._exportTextureAsync(r.occlusionTexture,a).then((function(e){e&&(u.occlusionTexture=e,null!=r.occlusionStrength&&(u.occlusionTexture.strength=r.occlusionStrength))}))),r.emissiveTexture&&s.push(this._exportTextureAsync(r.emissiveTexture,a).then((function(e){e&&(u.emissiveTexture=e)})))),t.FuzzyEquals(r.emissiveColor,e.Color3.Black(),t._Epsilon)&&(u.emissiveFactor=r.emissiveColor.asArray()),u.pbrMetallicRoughness=l,o.push(u),n[r.uniqueId]=o.length-1,Promise.all(s).then((function(){}))},t.prototype._createBase64FromCanvasAsync=function(t,r,a,i){var n=this;return new Promise(function(i,o){var s,l=e.Engine.TEXTURETYPE_UNSIGNED_INT,u=n._exporter._getLocalEngine();s=new e.Scene(u);var c=u.createRawTexture(t,r,a,e.Engine.TEXTUREFORMAT_RGBA,!1,!0,e.Texture.NEAREST_SAMPLINGMODE,null,l),h=new e.PostProcess("pass","pass",null,null,1,null,e.Texture.NEAREST_SAMPLINGMODE,u,!1,void 0,e.Engine.TEXTURETYPE_UNSIGNED_INT,void 0,null,!1);h.getEffect().executeWhenCompiled((function(){h.onApply=function(e){e._bindTexture("textureSampler",c)},u.setSize(r,a),s.postProcessManager.directRender([h],null),h.dispose(),c.dispose();var e=u.getRenderingCanvas();e?e.toBlob((function(e){if(e){var t=new FileReader;t.onload=function(e){var t=e.target.result;s.dispose(),i(t)},t.readAsDataURL(e)}else o("Failed to get blob from image canvas!")})):o("Engine is missing a canvas!")}))})},t.prototype._createWhiteTexture=function(t,r,a){for(var i=new Uint8Array(t*r*4),n=0;n<i.length;n+=4)i[n]=i[n+1]=i[n+2]=i[n+3]=255;return e.RawTexture.CreateRGBATexture(i,t,r,a)},t.prototype._resizeTexturesToSameDimensions=function(t,r,a){var i,n,o=t?t.getSize():{width:0,height:0},s=r?r.getSize():{width:0,height:0};return o.width<s.width?(i=t&&t instanceof e.Texture?e.TextureTools.CreateResizedCopy(t,s.width,s.height,!0):this._createWhiteTexture(s.width,s.height,a),n=r):o.width>s.width?(n=r&&r instanceof e.Texture?e.TextureTools.CreateResizedCopy(r,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,a),i=t):(i=t,n=r),{texture1:i,texture2:n}},t.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(r,a,i,n){var o=[]
;if(!r&&!a)return Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!");var s=r?r.getScene():a?a.getScene():null;if(s){var l=this._resizeTexturesToSameDimensions(r,a,s),u=l.texture1.getSize(),c=void 0,h=void 0,f=u.width,p=u.height,d=l.texture1.readPixels();if(d instanceof Uint8Array){if(c=l.texture1.readPixels(),(d=l.texture2.readPixels())instanceof Uint8Array){h=l.texture2.readPixels();for(var m=h.byteLength,g=new Uint8Array(m),y=new Uint8Array(m),T=e.Color3.Black(),_=0,x=0,v=0;v<p;++v)for(var b=0;b<f;++b){var A=4*(f*v+b),F=e.Color3.FromInts(c[A],c[A+1],c[A+2]).toLinearSpace().multiply(i.diffuseColor),M=e.Color3.FromInts(h[A],h[A+1],h[A+2]).toLinearSpace().multiply(i.specularColor),R=h[A+3]/255*i.glossiness,S={diffuseColor:F,specularColor:M,glossiness:R},V=this._convertSpecularGlossinessToMetallicRoughness(S);T.r=Math.max(T.r,V.baseColor.r),T.g=Math.max(T.g,V.baseColor.g),T.b=Math.max(T.b,V.baseColor.b),_=Math.max(_,V.metallic),x=Math.max(x,V.roughness),y[A]=255*V.baseColor.r,y[A+1]=255*V.baseColor.g,y[A+2]=255*V.baseColor.b,y[A+3]=l.texture1.hasAlpha?c[A+3]:255,g[A]=0,g[A+1]=255*V.roughness,g[A+2]=255*V.metallic,g[A+3]=255}for(var C={baseColor:T,metallic:_,roughness:x},E=!1,B=!1,v=0;v<p;++v)for(var b=0;b<f;++b){var w=4*(f*v+b);y[w]/=C.baseColor.r>t._Epsilon?C.baseColor.r:1,y[w+1]/=C.baseColor.g>t._Epsilon?C.baseColor.g:1,y[w+2]/=C.baseColor.b>t._Epsilon?C.baseColor.b:1;var L=e.Color3.FromInts(y[w],y[w+1],y[w+2]),P=L.toGammaSpace();y[w]=255*P.r,y[w+1]=255*P.g,y[w+2]=255*P.b,t.FuzzyEquals(P,e.Color3.White(),t._Epsilon)||(B=!0),g[w+1]/=C.roughness>t._Epsilon?C.roughness:1,g[w+2]/=C.metallic>t._Epsilon?C.metallic:1;var N=e.Color3.FromInts(255,g[w+1],g[w+2]);t.FuzzyEquals(N,e.Color3.White(),t._Epsilon)||(E=!0)}if(E){var G=this._createBase64FromCanvasAsync(g,f,p,n).then((function(e){C.metallicRoughnessTextureBase64=e}));o.push(G)}if(B){var G=this._createBase64FromCanvasAsync(y,f,p,n).then((function(e){C.baseColorTextureBase64=e}));o.push(G)}return Promise.all(o).then((function(){return C}))}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture2.name)}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture1.name)}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},t.prototype._convertSpecularGlossinessToMetallicRoughness=function(r){var a=this._getPerceivedBrightness(r.diffuseColor),i=this._getPerceivedBrightness(r.specularColor),n=1-this._getMaxComponent(r.specularColor),o=t._SolveMetallic(a,i,n),s=r.diffuseColor.scale(n/(1-t._DielectricSpecular.r)/Math.max(1-o,t._Epsilon)),l=r.specularColor.subtract(t._DielectricSpecular.scale(1-o)).scale(1/Math.max(o,t._Epsilon)),u=e.Color3.Lerp(s,l,o*o);return u=u.clampToRef(0,1,u),{baseColor:u,metallic:o,roughness:1-r.glossiness}},t.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},t.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},t.prototype._gonvertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,a){var i=[],n={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return a&&(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 n}))},t.prototype._getGLTFTextureSampler=function(t){var r=this._getGLTFTextureWrapModesSampler(t),a=t instanceof e.Texture?t.samplingMode:null;if(null!=a)switch(a){case e.Texture.LINEAR_LINEAR:r.magFilter=9729,r.minFilter=9729;break;case e.Texture.LINEAR_NEAREST:r.magFilter=9729,r.minFilter=9728;break;case e.Texture.NEAREST_LINEAR:r.magFilter=9728,r.minFilter=9729;break;case e.Texture.NEAREST_LINEAR_MIPLINEAR:r.magFilter=9728,r.minFilter=9987;break;case e.Texture.NEAREST_NEAREST:r.magFilter=9728,r.minFilter=9728;break;case e.Texture.NEAREST_LINEAR_MIPNEAREST:r.magFilter=9728,r.minFilter=9985;break;case e.Texture.LINEAR_NEAREST_MIPNEAREST:r.magFilter=9729,r.minFilter=9984;break;case e.Texture.LINEAR_NEAREST_MIPLINEAR:r.magFilter=9729,r.minFilter=9986;break;case e.Texture.NEAREST_NEAREST_MIPLINEAR:r.magFilter=9728,r.minFilter=9986;break;case e.Texture.LINEAR_LINEAR_MIPLINEAR:r.magFilter=9729,r.minFilter=9987;break;case e.Texture.LINEAR_LINEAR_MIPNEAREST:r.magFilter=9729,r.minFilter=9985;break;case e.Texture.NEAREST_NEAREST_MIPNEAREST:r.magFilter=9728,r.minFilter=9984}return r},t.prototype._getGLTFTextureWrapMode=function(t){switch(t){case e.Texture.WRAP_ADDRESSMODE:return 10497;case e.Texture.CLAMP_ADDRESSMODE:return 33071;case e.Texture.MIRROR_ADDRESSMODE:return 33648;default:return e.Tools.Error("Unsupported Texture Wrap Mode "+t+"!"),10497}},t.prototype._getGLTFTextureWrapModesSampler=function(t){var r=this._getGLTFTextureWrapMode(t instanceof e.Texture?t.wrapU:e.Texture.WRAP_ADDRESSMODE),a=this._getGLTFTextureWrapMode(t instanceof e.Texture?t.wrapV:e.Texture.WRAP_ADDRESSMODE);return 10497===r&&10497===a?{}:{wrapS:r,wrapT:a}},t.prototype._convertSpecGlossFactorsToMetallicRoughness=function(t,r,a,i){var n=this,o=this._exporter._samplers,s=this._exporter._textures,l={diffuseColor:t.albedoColor||e.Color3.White(),specularColor:t.reflectivityColor||e.Color3.White(),glossiness:t.microSurface||1},u=null,c=this._getGLTFTextureSampler(t.albedoTexture);return null!=c.magFilter&&null!=c.minFilter&&null!=c.wrapS&&null!=c.wrapT&&(o.push(c),u=o.length-1),t.reflectivityTexture&&!t.useMicroSurfaceFromReflectivityMapAlpha?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(t.albedoTexture,t.reflectivityTexture,l,r).then((function(e){if(i){if(e.baseColorTextureBase64){var o=n._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",r,t.albedoTexture?t.albedoTexture.coordinatesIndex:null,u);o&&(a.baseColorTexture=o)}if(e.metallicRoughnessTextureBase64){var c=n._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",r,t.reflectivityTexture?t.reflectivityTexture.coordinatesIndex:null,u);c&&(a.metallicRoughnessTexture=c)}return e}return n._convertSpecularGlossinessToMetallicRoughness(l)}))},t.prototype._convertPBRMaterialAsync=function(e,t,r){var a=this,i={},n={name:e.name};return e.isMetallicWorkflow()?(e.albedoColor&&(i.baseColorFactor=[e.albedoColor.r,e.albedoColor.g,e.albedoColor.b,e.alpha]),this._gonvertMetalRoughFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(o){return a.setMetallicRoughnessPbrMaterial(o,e,n,i,t,r)}))):this._convertSpecGlossFactorsToMetallicRoughness(e,t,i,r).then((function(o){return a.setMetallicRoughnessPbrMaterial(o,e,n,i,t,r)}))},t.prototype.setMetallicRoughnessPbrMaterial=function(r,a,i,n,o,s){var l=this._exporter._materialMap,u=this._exporter._materials,c=[];if(r){var h=null;if(null!=a.transparencyMode&&(h=this._getAlphaMode(a))&&"OPAQUE"!==h&&(i.alphaMode=h,"MASK"===h&&(i.alphaCutoff=a.alphaCutOff)),t.FuzzyEquals(r.baseColor,e.Color3.White(),t._Epsilon)&&a.alpha>=t._Epsilon||(n.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,a.alpha]),null!=r.metallic&&1!==r.metallic&&(n.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(n.roughnessFactor=r.roughness),null==a.backFaceCulling||a.backFaceCulling||(a.twoSidedLighting||e.Tools.Warn(a.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),i.doubleSided=!0),s){if(a.bumpTexture){var f=this._exportTextureAsync(a.bumpTexture,o).then((function(e){e&&(i.normalTexture=e,1!==a.bumpTexture.level&&(i.normalTexture.scale=a.bumpTexture.level))}));c.push(f)}if(a.ambientTexture){var f=this._exportTextureAsync(a.ambientTexture,o).then((function(e){if(e){var t={index:e.index};i.occlusionTexture=t,a.ambientTextureStrength&&(t.strength=a.ambientTextureStrength)}}));c.push(f)}if(a.emissiveTexture){var f=this._exportTextureAsync(a.emissiveTexture,o).then((function(e){e&&(i.emissiveTexture=e)}));c.push(f)}}t.FuzzyEquals(a.emissiveColor,e.Color3.Black(),t._Epsilon)||(i.emissiveFactor=a.emissiveColor.asArray()),i.pbrMetallicRoughness=n,u.push(i),l[a.uniqueId]=u.length-1}return Promise.all(c).then((function(e){}))},t.prototype.getPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t.prototype._exportTextureAsync=function(e,t){var r=this;return Promise.resolve().then((function(){var a=e.uid;if(a in r._textureMap)return r._textureMap[a];for(var i=r._exporter._samplers,n=r._getGLTFTextureSampler(e),o=null,s=null,l=0;l<i.length;++l){var u=i[l];if(u.minFilter===n.minFilter&&u.magFilter===n.magFilter&&u.wrapS===n.wrapS&&u.wrapT===n.wrapT){s=l;break}}null==s?(i.push(n),o=i.length-1):o=s;var c=r.getPixelsFromTexture(e),h=e.getSize();return r._createBase64FromCanvasAsync(c,h.width,h.height,t).then((function(i){var n=r._getTextureInfoFromBase64(i,e.name,t,e.coordinatesIndex,o);return n&&(r._textureMap[a]=n),n}))}))},t.prototype._getTextureInfoFromBase64=function(t,r,a,i,n){var o=this._exporter._textures,s=this._exporter._images,l=this._exporter._imageData,u=null,c={source:s.length,name:r};null!=n&&(c.sampler=n);for(var h=atob(t.split(",")[1]),f=new ArrayBuffer(h.length),p=new Uint8Array(f),d=0,m=h.length;d<m;++d)p[d]=h.charCodeAt(d);var g={data:p,mimeType:a},y="image/jpeg"===a?".jpeg":".png",T=r+y;if(T in l&&(T=r+"_"+e.Tools.RandomId()+y),l[T]=g,"image/jpeg"===a||"image/png"===a){for(var _={name:r,uri:T},x=null,d=0;d<s.length;++d)if(s[d].uri===T){x=d;break}null==x?(s.push(_),c.source=s.length-1):c.source=x,o.push(c),u={index:o.length-1},null!=i&&(u.texCoord=i)}else e.Tools.Error("Unsupported texture mime type "+a);return u},t._DielectricSpecular=new e.Color3(.04,.04,.04),t._MaxSpecularPower=1024,t._Epsilon=1e-6,t})();t._GLTFMaterialExporter=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){!(function(t){var r;!(function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"})(r||(r={}));var a=(function(){function a(){}return a._CreateNodeAnimation=function(t,r,i,n,o,s){var l=[],u=[],c=r.getKeys(),h=a.calculateMinMaxKeyFrames(c),f=a._DeduceInterpolation(c,i,o),p=h.max-h.min,d=f.interpolationType,m=f.shouldBakeAnimation;if(m?a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o):"LINEAR"===d||"STEP"===d?a._CreateLinearOrStepAnimation(t,r,i,p,l,u,n,o):"CUBICSPLINE"===d?a._CreateCubicSplineAnimation(t,r,i,p,l,u,n,o):a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o),l.length&&u.length){return{inputs:l,outputs:u,samplerInterpolation:d,inputsMin:m?h.min:e.Tools.FloatRound(h.min/r.framePerSecond),inputsMax:m?h.max:e.Tools.FloatRound(h.max/r.framePerSecond)}}return null},a._DeduceAnimationInfo=function(t){var r=null,a="VEC3",i=!1,n=t.targetProperty.split(".");switch(n[0]){case"scaling":r="scale";break;case"position":r="translation";break;case"rotation":a="VEC4",r="rotation";break;case"rotationQuaternion":a="VEC4",i=!0,r="rotation";break;default:e.Tools.Error("Unsupported animatable property "+n[0])}return r?{animationChannelTargetPath:r,dataAccessorType:a,useQuaternion:i}:(e.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},a._CreateNodeAnimationFromTransformNodeAnimations=function(e,t,r,i,n,o,s,l,u,c){var h;if(e.animations)for(var f=0,p=e.animations;f<p.length;f++){var d=p[f],m=a._DeduceAnimationInfo(d);m&&(h={name:d.name,samplers:[],channels:[]},a.AddAnimation(""+d.name,d.hasRunningRuntimeAnimations?t:h,e,d,m.dataAccessorType,m.animationChannelTargetPath,i,o,s,l,u,m.useQuaternion,c),h.samplers.length&&h.channels.length&&r.push(h))}},a._CreateNodeAnimationFromAnimationGroups=function(t,r,i,n,o,s,l,u,c){var h;if(t.animationGroups)for(var f=t.animationGroups,p=0,d=f;p<d.length;p++){var m=d[p];h={name:m.name,channels:[],samplers:[]};for(var g=0,y=m.targetedAnimations;g<y.length;g++){var T=y[g],_=T.target,x=T.animation;if(_ instanceof e.Mesh||1===_.length&&_[0]instanceof e.Mesh){var v=a._DeduceAnimationInfo(T.animation);if(v){var b=_ instanceof e.Mesh?_:_[0];a.AddAnimation(""+x.name,h,b,x,v.dataAccessorType,v.animationChannelTargetPath,i,o,s,l,u,v.useQuaternion,c)}}}h.channels.length&&h.samplers.length&&r.push(h)}},a.AddAnimation=function(e,r,i,n,o,s,l,u,c,h,f,p,d){var m,g,y,T,_,x,v,b=a._CreateNodeAnimation(i,n,s,f,p,d);if(b){var A=l[i.uniqueId],F=4*b.inputs.length;m=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),F,void 0,e+" keyframe data view"),c.push(m),b.inputs.forEach((function(e){u.setFloat32(e)})),g=t._GLTFUtilities.CreateAccessor(c.length-1,e+" keyframes","SCALAR",5126,b.inputs.length,null,[b.inputsMin],[b.inputsMax]),h.push(g),y=h.length-1,_=b.outputs.length,F="VEC3"===o?12*b.outputs.length:16*b.outputs.length,m=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),F,void 0,e+" data view"),c.push(m),b.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=t._GLTFUtilities.CreateAccessor(c.length-1,e+" data",o,5126,_,null,null,null),h.push(g),T=h.length-1,x={interpolation:b.samplerInterpolation,input:y,output:T},r.samplers.push(x),v={sampler:r.samplers.length-1,target:{node:A,path:s}},r.channels.push(v)}},a._CreateBakedAnimation=function(t,r,i,n,o,s,l,u,c,h,f,p){var d,m,g=e.Quaternion.Identity(),y=null,T=null,_=null,x=null,v=null,b=null;h.min=e.Tools.FloatRound(n/s);for(var A=r.getKeys(),F=0,M=A.length;F<M;++F){if(b=null,_=A[F],F+1<M)if(x=A[F+1],_.value.equals(x.value)){if(0!==F)continue;b=_.frame}else b=x.frame;else{if(v=A[F-1],_.value.equals(v.value))continue;b=o}if(b)for(var R=_.frame;R<=b;R+=l)(m=e.Tools.FloatRound(R/s))!==y&&(y=m,T=m,d=r._interpolate(R,0,void 0,r.loopMode),a._SetInterpolatedValue(t,d,m,r,i,g,u,c,f,p))}T&&(h.max=T)},a._ConvertFactorToVector3OrQuaternion=function(t,r,i,n,o,s,l){var u,c,h=null,f=a._GetBasePositionRotationOrScale(r,o,s,l);if(n===e.Animation.ANIMATIONTYPE_FLOAT)switch(u=i.targetProperty.split("."),c=u?u[1]:"",h=l?e.Quaternion.FromArray(f).normalize():e.Vector3.FromArray(f),c){case"x":case"y":h[c]=s&&l&&"scale"!==o?-t:t;break;case"z":h[c]=s&&!l&&"scale"!==o?-t:t;break;case"w":h.w=t;break;default:e.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return h},a._SetInterpolatedValue=function(r,a,i,n,o,s,l,u,c,h){var f,p=n.dataType;l.push(i),"number"==typeof a&&(a=this._ConvertFactorToVector3OrQuaternion(a,r,n,p,o,c,h)),a&&("rotation"===o?(h?s=a:(f=a,e.Quaternion.RotationYawPitchRollToRef(f.y,f.x,f.z,s)),c&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(s),r.parent||(s=e.Quaternion.FromArray([0,1,0,0]).multiply(s))),u.push(s.asArray())):(f=a,c&&"scale"!==o&&(t._GLTFUtilities.GetRightHandedPositionVector3FromRef(f),r.parent||(f.x*=-1,f.z*=-1)),u.push(f.asArray())))},a._CreateLinearOrStepAnimation=function(e,t,r,i,n,o,s,l){for(var u=0,c=t.getKeys();u<c.length;u++){var h=c[u];n.push(h.frame/t.framePerSecond),a._AddKeyframeValue(h,t,o,r,e,s,l)}},a._CreateCubicSplineAnimation=function(e,t,i,n,o,s,l,u){t.getKeys().forEach((function(c){o.push(c.frame/t.framePerSecond),a.AddSplineTangent(e,r.INTANGENT,s,i,"CUBICSPLINE",c,n,u,l),a._AddKeyframeValue(c,t,s,i,e,l,u),a.AddSplineTangent(e,r.OUTTANGENT,s,i,"CUBICSPLINE",c,n,u,l)}))},a._GetBasePositionRotationOrScale=function(r,a,i,n){var o;return"rotation"===a?n?r.rotationQuaternion?(o=r.rotationQuaternion.asArray(),i&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(o),r.parent||(o=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(o)).asArray()))):o=e.Quaternion.Identity().asArray():(o=r.rotation.asArray(),t._GLTFUtilities.GetRightHandedNormalArray3FromRef(o)):"translation"===a?(o=r.position.asArray(),i&&t._GLTFUtilities.GetRightHandedPositionArray3FromRef(o)):o=r.scaling.asArray(),o},a._AddKeyframeValue=function(r,a,i,n,o,s,l){var u,c,h=a.dataType;if(h===e.Animation.ANIMATIONTYPE_VECTOR3){if(u=r.value.asArray(),"rotation"===n){var f=e.Vector3.FromArray(u),p=e.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z);s&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(p),o.parent||(p=e.Quaternion.FromArray([0,1,0,0]).multiply(p))),u=p.asArray()}else"translation"===n&&s&&(t._GLTFUtilities.GetRightHandedNormalArray3FromRef(u),o.parent||(u[0]*=-1,u[2]*=-1));i.push(u)}else if(h===e.Animation.ANIMATIONTYPE_FLOAT){if(c=this._ConvertFactorToVector3OrQuaternion(r.value,o,a,h,n,s,l)){if("rotation"===n){var d=l?c:e.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).normalize();s&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(d),o.parent||(d=e.Quaternion.FromArray([0,1,0,0]).multiply(d))),i.push(d.asArray())}else"translation"===n&&s&&(t._GLTFUtilities.GetRightHandedNormalVector3FromRef(c),o.parent||(c.x*=-1,c.z*=-1));i.push(c.asArray())}}else h===e.Animation.ANIMATIONTYPE_QUATERNION?(u=r.value.normalize().asArray(),s&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(u),o.parent||(u=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(u)).asArray())),i.push(u)):e.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},a._DeduceInterpolation=function(t,r,a){var i,n,o=!1;if("rotation"===r&&!a)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,l=t.length;s<l;++s)if(n=t[s],n.inTangent||n.outTangent)if(i){if("CUBICSPLINE"!==i){i="LINEAR",o=!0;break}}else i="CUBICSPLINE";else if(i){if("CUBICSPLINE"===i||n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP&&"STEP"!==i){i="LINEAR",o=!0;break}}else i=n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return i||(i="LINEAR"),{interpolationType:i,shouldBakeAnimation:o}},a.AddSplineTangent=function(a,i,n,o,s,l,u,c,h){var f,p=i===r.INTANGENT?l.inTangent:l.outTangent;if("CUBICSPLINE"===s){if("rotation"===o)if(p){if(c)f=p.scale(u).asArray();else{var d=p.scale(u);f=e.Quaternion.RotationYawPitchRoll(d.y,d.x,d.z).asArray()}h&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(f),a.parent||(f=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(f)).asArray()))}else f=[0,0,0,0];else p?(f=p.scale(u).asArray(),h&&"translation"===o&&(t._GLTFUtilities.GetRightHandedPositionArray3FromRef(f),a.parent||(f[0]*=-1,f[2]*=-1))):f=[0,0,0];n.push(f)}},a.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}},a})();t._GLTFAnimation=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;return (function(e){!(function(t){var r=(function(){function t(){}return t.CreateBufferView=function(e,t,r,a,i){var n={buffer:e,byteLength:r};return t&&(n.byteOffset=t),i&&(n.name=i),a&&(n.byteStride=a),n},t.CreateAccessor=function(e,t,r,a,i,n,o,s){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=n&&(l.byteOffset=n),l},t.CalculateMinMaxPositions=function(r,a,i,n){var o,s,l,u=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(i)for(var h=a,f=a+i;h<f;++h){o=3*h,s=e.Vector3.FromArray(r,o),n&&t.GetRightHandedPositionVector3FromRef(s),l=s.asArray();for(var p=0;p<3;++p){var d=l[p];d<u[p]&&(u[p]=d),d>c[p]&&(c[p]=d),++o}}return{min:u,max:c}},t.GetRightHandedPositionVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},t.GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},t.GetRightHandedNormalVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},t.GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},t.GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},t.GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},t.GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},t.GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},t})();t._GLTFUtilities=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={})),e}));
!(function(e,t){var r=[],a=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(a=a||require("babylonjs"),module.exports=t(a)):"function"==typeof define&&define.amd?(r.push("babylonjs"),define("babylonjs-serializers",r,t)):"object"==typeof exports?(a=a||require("babylonjs"),exports["babylonjs-serializers"]=t(a)):e.BABYLON=t(a)})(this,(function(e){e=e||this.BABYLON;var e;this&&this.__decorate,this&&this.__extends||(function(){var e=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])}})();!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var n=[],o=1;r&&(a||(a="mat"),n.push("mtllib "+a+".mtl"));for(var s=0;s<t.length;s++){n.push("g object"+s),n.push("o object_"+s);var l=null;if(i){var u=e.Matrix.Translation(t[s].position.x,t[s].position.y,t[s].position.z);l=e.Matrix.Translation(-t[s].position.x,-t[s].position.y,-t[s].position.z),t[s].bakeTransformIntoVertices(u)}if(r){var c=t[s].material;c&&n.push("usemtl "+c.id)}var h=t[s].geometry;if(h){var f=h.getVerticesData("position"),p=h.getVerticesData("normal"),m=h.getVerticesData("uv"),d=h.getIndices(),g=0;if(f&&p&&m&&d){for(var _=0;_<f.length;_+=3)n.push("v "+f[_]+" "+f[_+1]+" "+f[_+2]),g++;for(_=0;_<p.length;_+=3)n.push("vn "+p[_]+" "+p[_+1]+" "+p[_+2]);for(_=0;_<m.length;_+=2)n.push("vt "+m[_]+" "+m[_+1]);for(_=0;_<d.length;_+=3)n.push("f "+(d[_+2]+o)+"/"+(d[_+2]+o)+"/"+(d[_+2]+o)+" "+(d[_+1]+o)+"/"+(d[_+1]+o)+"/"+(d[_+1]+o)+" "+(d[_]+o)+"/"+(d[_]+o)+"/"+(d[_]+o));i&&l&&t[s].bakeTransformIntoVertices(l),o+=g}}}return n.join("\n")},t.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")},t})();e.OBJExport=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.GLTFAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLTFAsync(i)}))},t.GLBAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLBAsync(i)}))},t})();e.GLTF2Export=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function r(e,r){this._asset={generator:"BabylonJS",version:"2.0"},this._babylonScene=e,this._bufferViews=[],this._accessors=[],this._meshes=[],this._scenes=[],this._nodes=[],this._images=[],this._materials=[],this._materialMap=[],this._textures=[],this._samplers=[],this._animations=[],this._imageData={},this._convertToRightHandedSystem=!this._babylonScene.useRightHandedSystem;var a=r||{};this._shouldExportTransformNode=a.shouldExportTransformNode?a.shouldExportTransformNode:function(e){return!0},this._animationSampleRate=a.animationSampleRate?a.animationSampleRate:1/60,this._glTFMaterialExporter=new t._GLTFMaterialExporter(this)}return r.prototype._getLocalEngine=function(){if(!this._localEngine){var t=document.createElement("canvas");t.id="WriteCanvas",t.width=2048,t.height=2048,this._localEngine=new e.Engine(t,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!0}),this._localEngine.setViewport(new e.Viewport(0,0,1,1))}return this._localEngine},r.prototype.reorderIndicesBasedOnPrimitiveMode=function(t,r,a,i,n){switch(r){case e.Material.TriangleFillMode:i||(i=0);for(var o=t.indexStart,s=t.indexStart+t.indexCount;o<s;o+=3){var l=i+4*o,u=n.getUInt32(l+4),c=n.getUInt32(l+8);n.setUInt32(c,l+4),n.setUInt32(u,l+8)}break;case e.Material.TriangleFanDrawMode:for(var o=t.indexStart+t.indexCount-1,h=t.indexStart;o>=h;--o)n.setUInt32(a[o],i),i+=4;break;case e.Material.TriangleStripDrawMode:t.indexCount>=3&&(n.setUInt32(a[t.indexStart+2],i+4),n.setUInt32(a[t.indexStart+1],i+8))}},r.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(t,r,a,i,n,o,s){if(this._convertToRightHandedSystem&&a===e.Material.ClockWiseSideOrientation)switch(r){case e.Material.TriangleFillMode:this.reorderTriangleFillMode(t,r,a,i,n,o,s);break;case e.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(t,r,a,i,n,o,s);break;case e.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(t,r,a,i,n,o,s)}},r.prototype.reorderTriangleFillMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type);if(t.verticesCount%3!=0)e.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector3.FromArray(n,h)),c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector4.FromArray(n,h)),c.push(e.Vector4.FromArray(n,h+2*u)),c.push(e.Vector4.FromArray(n,h+u));break;case e.VertexBuffer.ColorKind:for(var p=l.getSize(),f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=p)h=f*u,4===p?(c.push(e.Vector4.FromArray(n,h)),c.push(e.Vector4.FromArray(n,h+2*u)),c.push(e.Vector4.FromArray(n,h+u))):(c.push(e.Vector3.FromArray(n,h)),c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u)));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector2.FromArray(n,h)),c.push(e.Vector2.FromArray(n,h+2*u)),c.push(e.Vector2.FromArray(n,h+u));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o,i,n,s)}}else e.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+i+" not present!")},r.prototype.reorderTriangleStripDrawMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:h=t.verticesStart,c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h));break;case e.VertexBuffer.ColorKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,4===l.getSize()?c.push(e.Vector4.FromArray(n,h)):c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector2.FromArray(n,h));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o+12,i,n,s)}else e.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+i+" not present!")},r.prototype.reorderTriangleFanMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h));break;case e.VertexBuffer.ColorKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h)),4===l.getSize()?c.push(e.Vector4.FromArray(n,h)):c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector2.FromArray(n,h));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o,i,n,s)}else e.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+i+" not present!")},r.prototype.writeVertexAttributeData=function(r,a,i,n,o){for(var s=0,l=r;s<l.length;s++){var u=l[s];!this._convertToRightHandedSystem||i===e.VertexBuffer.ColorKind||u instanceof e.Vector2||(u instanceof e.Vector3?i===e.VertexBuffer.NormalKind?t._GLTFUtilities._GetRightHandedNormalVector3FromRef(u):i===e.VertexBuffer.PositionKind?t._GLTFUtilities._GetRightHandedPositionVector3FromRef(u):e.Tools.Error("Unsupported vertex attribute kind!"):t._GLTFUtilities._GetRightHandedVector4FromRef(u)),i===e.VertexBuffer.NormalKind?u.normalize():i===e.VertexBuffer.TangentKind&&u instanceof e.Vector4&&t._GLTFUtilities._NormalizeTangentFromRef(u);for(var c=0,h=u.asArray();c<h.length;c++){var f=h[c];o.setFloat32(f,a),a+=4}}},r.prototype.writeAttributeData=function(r,a,i,n){var o,s=i/4,l=[];switch(r){case e.VertexBuffer.PositionKind:for(var u=0,c=a.length/s;u<c;++u){o=u*s;var h=e.Vector3.FromArray(a,o);this._convertToRightHandedSystem&&t._GLTFUtilities._GetRightHandedPositionVector3FromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.NormalKind:for(var u=0,f=a.length/s;u<f;++u){o=u*s;var h=e.Vector3.FromArray(a,o);this._convertToRightHandedSystem&&t._GLTFUtilities._GetRightHandedNormalVector3FromRef(h),h.normalize(),l.push(h.asArray())}break;case e.VertexBuffer.TangentKind:for(var u=0,p=a.length/s;u<p;++u){o=u*s;var h=e.Vector4.FromArray(a,o);this._convertToRightHandedSystem&&t._GLTFUtilities._GetRightHandedVector4FromRef(h),t._GLTFUtilities._NormalizeTangentFromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.ColorKind:for(var u=0,m=a.length/s;u<m;++u){o=u*s;var h=3===s?e.Vector3.FromArray(a,o):e.Vector4.FromArray(a,o);l.push(h.asArray())}break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var u=0,d=a.length/s;u<d;++u)o=u*s,l.push((this._convertToRightHandedSystem,[a[o],a[o+1]]));break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+r),l=[]}for(var g=0,_=l;g<_.length;g++)for(var y=_[g],T=0,x=y;T<x.length;T++){var v=x[T];n.setFloat32(v)}},r.prototype.generateJSON=function(e,r,a){var i,n,o,s=this,l={byteLength:this._totalByteLength},u=this._totalByteLength,c={asset:this._asset};return l.byteLength&&(c.buffers=[l]),this._nodes&&this._nodes.length&&(c.nodes=this._nodes),this._meshes&&this._meshes.length&&(c.meshes=this._meshes),this._scenes&&this._scenes.length&&(c.scenes=this._scenes,c.scene=0),this._bufferViews&&this._bufferViews.length&&(c.bufferViews=this._bufferViews),this._accessors&&this._accessors.length&&(c.accessors=this._accessors),this._animations&&this._animations.length&&(c.animations=this._animations),this._materials&&this._materials.length&&(c.materials=this._materials),this._textures&&this._textures.length&&(c.textures=this._textures),this._samplers&&this._samplers.length&&(c.samplers=this._samplers),this._images&&this._images.length&&(e?(c.images=[],this._images.forEach((function(e){e.uri&&(n=s._imageData[e.uri],i=e.uri.split(".")[0]+" image",o=t._GLTFUtilities._CreateBufferView(0,u,n.data.length,void 0,i),u+=n.data.buffer.byteLength,s._bufferViews.push(o),e.bufferView=s._bufferViews.length-1,e.name=i,e.mimeType=n.mimeType,e.uri=void 0,c.images||(c.images=[]),c.images.push(e))})),l.byteLength=u):c.images=this._images),e||(l.uri=r+".bin"),a?JSON.stringify(c,null,2):JSON.stringify(c)},r.prototype._generateGLTFAsync=function(t){var r=this;return this._generateBinaryAsync().then((function(a){var i=r.generateJSON(!1,t,!0),n=new Blob([a],{type:"application/octet-stream"}),o=t+".gltf",s=t+".bin",l=new e.GLTFData;if(l.glTFFiles[o]=i,l.glTFFiles[s]=n,r._imageData)for(var u in r._imageData)l.glTFFiles[u]=new Blob([r._imageData[u].data],{type:r._imageData[u].mimeType});return l}))},r.prototype._generateBinaryAsync=function(){var e=this,t=new a(4);return this.createSceneAsync(this._babylonScene,t).then((function(){return e._localEngine&&e._localEngine.dispose(),t.getArrayBuffer()}))},r.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},r.prototype._generateGLBAsync=function(t){var r=this;return this._generateBinaryAsync().then((function(a){var i=r.generateJSON(!0),n=t+".glb",o=i.length,s=0;for(var l in r._imageData)s+=r._imageData[l].data.byteLength;var u=r._getPadding(o),c=r._getPadding(a.byteLength),h=r._getPadding(s),f=28+o+u+a.byteLength+c+s+h,p=new ArrayBuffer(12),m=new DataView(p);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,f,!0);var d=new ArrayBuffer(8+o+u),g=new DataView(d);g.setUint32(0,o+u,!0),g.setUint32(4,1313821514,!0);for(var _=new Uint8Array(d,8),y=0;y<o;++y)_[y]=i.charCodeAt(y);for(var T=new Uint8Array(d,8+o),y=0;y<u;++y)T[y]=32;var x=new ArrayBuffer(8),v=new DataView(x);v.setUint32(0,a.byteLength+s+h,!0),v.setUint32(4,5130562,!0);for(var b=new ArrayBuffer(c),A=new Uint8Array(b),y=0;y<c;++y)A[y]=0;for(var F=new ArrayBuffer(h),M=new Uint8Array(F),y=0;y<h;++y)M[y]=0;var R=[p,d,x,a];for(var l in r._imageData)R.push(r._imageData[l].data.buffer);R.push(b),R.push(F);var V=new Blob(R,{type:"application/octet-stream"}),S=new e.GLTFData;return S.glTFFiles[n]=V,r._localEngine.dispose(),S}))},r.prototype.setNodeTransformation=function(r,a){a.position.equalsToFloats(0,0,0)||(r.translation=this._convertToRightHandedSystem?t._GLTFUtilities._GetRightHandedPositionVector3(a.position).asArray():a.position.asArray()),a.scaling.equalsToFloats(1,1,1)||(r.scale=a.scaling.asArray());var i=e.Quaternion.RotationYawPitchRoll(a.rotation.y,a.rotation.x,a.rotation.z);a.rotationQuaternion&&i.multiplyInPlace(a.rotationQuaternion),0===i.x&&0===i.y&&0===i.z&&1===i.w||(this._convertToRightHandedSystem&&t._GLTFUtilities._GetRightHandedQuaternionFromRef(i),r.rotation=i.normalize().asArray())},r.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},r.prototype.createBufferViewKind=function(r,a,i,n){var o=a instanceof e.Mesh?a:a instanceof e.InstancedMesh?a.sourceMesh:null;if(o){var s=o.getVerticesData(r);if(s){var l=4*s.length,u=t._GLTFUtilities._CreateBufferView(0,i.getByteOffset(),l,n,r+" - "+o.name);this._bufferViews.push(u),this.writeAttributeData(r,s,n,i)}}},r.prototype.getMeshPrimitiveMode=function(t){return t instanceof e.LinesMesh?e.Material.LineListDrawMode:t.material?t.material.fillMode:e.Material.TriangleFillMode},r.prototype.setPrimitiveMode=function(t,r){switch(r){case e.Material.TriangleFillMode:break;case e.Material.TriangleStripDrawMode:t.mode=5;break;case e.Material.TriangleFanDrawMode:t.mode=6;break;case e.Material.PointListDrawMode:t.mode=0;case e.Material.PointFillMode:t.mode=0;break;case e.Material.LineLoopDrawMode:t.mode=2;break;case e.Material.LineListDrawMode:t.mode=1;break;case e.Material.LineStripDrawMode:t.mode=3}},r.prototype.setAttributeKind=function(t,r){switch(r){case e.VertexBuffer.PositionKind:t.attributes.POSITION=this._accessors.length-1;break;case e.VertexBuffer.NormalKind:t.attributes.NORMAL=this._accessors.length-1;break;case e.VertexBuffer.ColorKind:t.attributes.COLOR_0=this._accessors.length-1;break;case e.VertexBuffer.TangentKind:t.attributes.TANGENT=this._accessors.length-1;break;case e.VertexBuffer.UVKind:t.attributes.TEXCOORD_0=this._accessors.length-1;break;case e.VertexBuffer.UV2Kind:t.attributes.TEXCOORD_1=this._accessors.length-1;break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+r)}},r.prototype.setPrimitiveAttributes=function(r,a,i){var n,o,s,l=null;a instanceof e.Mesh?l=a:a instanceof e.InstancedMesh&&(l=a.sourceMesh);var u=[{kind:e.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:e.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(l){for(var c=null,h=this.getMeshPrimitiveMode(l),f={},p=0,m=u;p<m.length;p++){var d=m[p],g=d.kind;if(l.isVerticesDataPresent(g)){var _=this.getVertexBufferFromMesh(g,l);d.byteStride=_?4*_.getSize():4*e.VertexBuffer.DeduceStride(g),12===d.byteStride&&(d.accessorType="VEC3"),this.createBufferViewKind(g,a,i,d.byteStride),d.bufferViewIndex=this._bufferViews.length-1,f[g]=d.bufferViewIndex}}if(l.getTotalIndices()){var y=l.getIndices();if(y){var T=4*y.length;n=t._GLTFUtilities._CreateBufferView(0,i.getByteOffset(),T,void 0,"Indices - "+l.name),this._bufferViews.push(n),c=this._bufferViews.length-1;for(var x=0,v=y.length;x<v;++x)i.setUInt32(y[x])}}if(l.subMeshes)for(var b=0,A=l.subMeshes;b<A.length;b++){var F=A[b];o=!1;var M=F.getMaterial(),R=null;if(M)if(l instanceof e.LinesMesh){var V={name:l.name+" material"};(!l.color.equals(e.Color3.White())||l.alpha<1)&&(V.pbrMetallicRoughness={baseColorFactor:l.color.asArray().concat([l.alpha])}),this._materials.push(V),R=this._materials.length-1}else M instanceof e.MultiMaterial?(M=M.subMaterials[F.materialIndex])&&(R=this._materialMap[M.uniqueId]):R=this._materialMap[M.uniqueId];var S=null!=R?this._materials[R]:null,C={attributes:{}};this.setPrimitiveMode(C,h);for(var E=0,B=u;E<B.length;E++){var d=B[E],g=d.kind;if(g!==e.VertexBuffer.UVKind&&g!==e.VertexBuffer.UV2Kind||!S||this._glTFMaterialExporter._hasTexturesPresent(S)){var w=l.getVerticesData(g);if(w){var _=this.getVertexBufferFromMesh(g,l);if(_){var L=_.getSize(),N=d.bufferViewIndex;if(void 0!=N){s={min:null,max:null},g==e.VertexBuffer.PositionKind&&(s=t._GLTFUtilities._CalculateMinMaxPositions(w,0,w.length/L,this._convertToRightHandedSystem));var P=t._GLTFUtilities._CreateAccessor(N,g+" - "+a.name,d.accessorType,5126,w.length/L,0,s.min,s.max);this._accessors.push(P),this.setAttributeKind(C,g),null==C.attributes.TEXCOORD_0&&null==C.attributes.TEXCOORD_1||(o=!0)}}}}}if(c){var P=t._GLTFUtilities._CreateAccessor(c,"indices - "+a.name,"SCALAR",5125,F.indexCount,4*F.indexStart,null,null);this._accessors.push(P),C.indices=this._accessors.length-1}if(null!=R&&Object.keys(C.attributes).length>0){var G=this._babylonScene.materials[R].sideOrientation;if(this._convertToRightHandedSystem&&G===e.Material.ClockWiseSideOrientation){var I=null!=c?this._bufferViews[c].byteOffset:null;null==I&&(I=0);var U=null;if(null!=c&&(U=l.getIndices()),U)this.reorderIndicesBasedOnPrimitiveMode(F,h,U,I,i);else for(var O=0,k=u;O<k.length;O++){var d=k[O],w=l.getVerticesData(d.kind);if(w){var D=this._bufferViews[f[d.kind]].byteOffset;D||(D=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(F,h,G,d.kind,w,D,i)}}}if(!o&&this._glTFMaterialExporter._hasTexturesPresent(this._materials[R])){var K=this._glTFMaterialExporter._stripTexturesFromMaterial(this._materials[R]);this._materials.push(K),R=this._materials.length-1}C.material=R}r.primitives.push(C)}}},r.prototype.createSceneAsync=function(t,r){var a,i,n,o=this,s={nodes:[]},l=t.transformNodes.concat(t.meshes);return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(t.materials,"image/png",!0).then((function(){o._nodeMap=o.createNodeMapAndAnimations(t,l,o._shouldExportTransformNode,r),o._totalByteLength=r.getByteOffset();for(var u=0,c=l;u<c.length;u++){var h=c[u];if(null!=(a=o._nodeMap[h.uniqueId])&&(i=o._nodes[a],h.parent||(o._shouldExportTransformNode(h)?(o._convertToRightHandedSystem&&(i.translation&&(i.translation[2]*=-1,i.translation[0]*=-1),i.rotation=i.rotation?e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(i.rotation)).asArray():e.Quaternion.FromArray([0,1,0,0]).asArray()),s.nodes.push(a)):e.Tools.Log("Omitting "+h.name+" from scene.")),n=h.getDescendants(!0),!i.children&&n&&n.length)){i.children=[];for(var f=0,p=n;f<p.length;f++){var m=p[f];null!=o._nodeMap[m.uniqueId]&&i.children.push(o._nodeMap[m.uniqueId])}}}s.nodes.length&&o._scenes.push(s)}))},r.prototype.createNodeMapAndAnimations=function(e,r,a,i){for(var n,o,s=this,l={},u={name:"runtime animations",channels:[],samplers:[]},c=[],h=0,f=r;h<f.length;h++){var p=f[h];a(p)?(o=this.createNode(p,i),this._nodes.push(o),n=this._nodes.length-1,l[p.uniqueId]=n,!e.animationGroups.length&&p.animations.length&&t._GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations(p,u,c,l,this._nodes,i,this._bufferViews,this._accessors,this._convertToRightHandedSystem,this._animationSampleRate)):p.name}return u.channels.length&&u.samplers.length&&this._animations.push(u),c.forEach((function(e){e.channels.length&&e.samplers.length&&s._animations.push(e)})),e.animationGroups.length&&t._GLTFAnimation._CreateNodeAnimationFromAnimationGroups(e,this._animations,l,this._nodes,i,this._bufferViews,this._accessors,this._convertToRightHandedSystem,this._animationSampleRate),l},r.prototype.createNode=function(e,t){var r={},a={primitives:[]};return e.name&&(r.name=e.name),this.setNodeTransformation(r,e),this.setPrimitiveAttributes(a,e,t),a.primitives.length&&(this._meshes.push(a),r.mesh=this._meshes.length-1),r},r})();t._Exporter=r;var a=(function(){function t(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return t.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),a=new Uint8Array(t),i=0,n=a.byteLength;i<n;++i)a[i]=r[i];this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer)},t.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset()),this._arrayBuffer},t.prototype.getByteOffset=function(){return this._byteOffset},t.prototype.setUInt8=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint8(r,t):e.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++,t))},t.prototype.getUInt32=function(t){if(t<this._byteOffset)return this._dataView.getUint32(t,!0);throw e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},t.prototype.getVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0))},t.prototype.setVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0))},t.prototype.getVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0),t.w=this._dataView.getFloat32(r+12,!0))},t.prototype.setVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0),this._dataView.setFloat32(r+12,t.w,!0))},t.prototype.setFloat32=function(t,r){isNaN(t)&&e.Tools.Error("Invalid data being written!"),null!=r&&(r<this._byteOffset?this._dataView.setFloat32(r,t,!0):e.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,t,!0),this._byteOffset+=4},t.prototype.setUInt32=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint32(r,t,!0):e.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,t,!0),this._byteOffset+=4)},t})();t._BinaryWriter=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){var t=(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 a=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([a],i)),r.click()}},e})();e.GLTFData=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function t(e){this._textureMap={},this._textureMap={},this._exporter=e}return t.FuzzyEquals=function(t,r,a){return e.Scalar.WithinEpsilon(t.r,r.r,a)&&e.Scalar.WithinEpsilon(t.g,r.g,a)&&e.Scalar.WithinEpsilon(t.b,r.b,a)},t.prototype._convertMaterialsToGLTFAsync=function(t,r,a){for(var i=[],n=0,o=t;n<o.length;n++){var s=o[n];s instanceof e.StandardMaterial?i.push(this._convertStandardMaterialAsync(s,r,a)):s instanceof e.PBRMetallicRoughnessMaterial?i.push(this._convertPBRMetallicRoughnessMaterialAsync(s,r,a)):s instanceof e.PBRMaterial?i.push(this._convertPBRMaterialAsync(s,r,a)):e.Tools.Warn("Unsupported material type: "+s.name)}return Promise.all(i).then((function(){}))},t.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},t.prototype._hasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},t.prototype._convertToGLTFPBRMetallicRoughness=function(r){function a(e,t,r,a,i){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*a+e*e*e*i}var i=new e.Vector2(0,1),n=new e.Vector2(0,.1),o=new e.Vector2(0,.1),s=new e.Vector2(1300,.1),l=r.diffuseColor.toLinearSpace().scale(.5),u=r.alpha,c=e.Scalar.Clamp(r.specularPower,0,t._MaxSpecularPower),h=(function(e){return a(Math.pow(e/s.x,.333333),i.y,n.y,o.y,s.y)})(c);return{baseColorFactor:[l.r,l.g,l.b,u],metallicFactor:0,roughnessFactor:h}},t._SolveMetallic=function(t,r,a){if(r<this._DielectricSpecular.r)return this._DielectricSpecular,0;var i=this._DielectricSpecular.r,n=t*a/(1-this._DielectricSpecular.r)+r-2*this._DielectricSpecular.r,o=this._DielectricSpecular.r-r,s=n*n-4*i*o;return e.Scalar.Clamp((-n+Math.sqrt(s))/(2*i),0,1)},t.prototype._getAlphaMode=function(e){return e.needAlphaBlending()?"BLEND":e.needAlphaTesting()?"MASK":"OPAQUE"},t.prototype._convertStandardMaterialAsync=function(r,a,i){var n=this._exporter._materialMap,o=this._exporter._materials,s=this._getAlphaMode(r),l=[],u=this._convertToGLTFPBRMetallicRoughness(r),c={name:r.name};if(null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),c.doubleSided=!0),i&&(r.diffuseTexture&&l.push(this._exportTextureAsync(r.diffuseTexture,a).then((function(e){e&&(u.baseColorTexture=e)}))),r.bumpTexture&&l.push(this._exportTextureAsync(r.bumpTexture,a).then((function(e){e&&(c.normalTexture=e,null!=r.bumpTexture&&1!==r.bumpTexture.level&&(c.normalTexture.scale=r.bumpTexture.level))}))),r.emissiveTexture&&(c.emissiveFactor=[1,1,1],l.push(this._exportTextureAsync(r.emissiveTexture,a).then((function(e){e&&(c.emissiveTexture=e)})))),r.ambientTexture&&l.push(this._exportTextureAsync(r.ambientTexture,a).then((function(e){if(e){var t={index:e.index};c.occlusionTexture=t,t.strength=1}})))),(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?c.alphaMode="BLEND":e.Tools.Warn(r.name+": glTF 2.0 does not support alpha mode: "+r.alphaMode.toString())),r.emissiveColor&&!t.FuzzyEquals(r.emissiveColor,e.Color3.Black(),t._Epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),c.pbrMetallicRoughness=u,"OPAQUE"!==s)switch(s){case"BLEND":c.alphaMode="BLEND";break;case"MASK":c.alphaMode="MASK",c.alphaCutoff=r.alphaCutOff;break;default:e.Tools.Warn("Unsupported alpha mode "+s)}return o.push(c),n[r.uniqueId]=o.length-1,Promise.all(l).then((function(){}))},t.prototype._convertPBRMetallicRoughnessMaterialAsync=function(r,a,i){var n=this._exporter._materialMap,o=this._exporter._materials,s=[],l={};r.baseColor&&(l.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,r.alpha]),null!=r.metallic&&1!==r.metallic&&(l.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(l.roughnessFactor=r.roughness);var u={name:r.name};r.doubleSided&&(u.doubleSided=r.doubleSided);var c=null;return null!=r.transparencyMode&&(c=this._getAlphaMode(r))&&"OPAQUE"!==c&&(u.alphaMode=c,"MASK"===c&&(u.alphaCutoff=r.alphaCutOff)),i&&(null!=r.baseTexture&&s.push(this._exportTextureAsync(r.baseTexture,a).then((function(e){e&&(l.baseColorTexture=e)}))),r.normalTexture&&s.push(this._exportTextureAsync(r.normalTexture,a).then((function(e){e&&(u.normalTexture=e,1!==r.normalTexture.level&&(u.normalTexture.scale=r.normalTexture.level))}))),r.occlusionTexture&&s.push(this._exportTextureAsync(r.occlusionTexture,a).then((function(e){e&&(u.occlusionTexture=e,null!=r.occlusionStrength&&(u.occlusionTexture.strength=r.occlusionStrength))}))),r.emissiveTexture&&s.push(this._exportTextureAsync(r.emissiveTexture,a).then((function(e){e&&(u.emissiveTexture=e)})))),t.FuzzyEquals(r.emissiveColor,e.Color3.Black(),t._Epsilon)&&(u.emissiveFactor=r.emissiveColor.asArray()),u.pbrMetallicRoughness=l,o.push(u),n[r.uniqueId]=o.length-1,Promise.all(s).then((function(){}))},t.prototype._createBase64FromCanvasAsync=function(t,r,a,i){var n=this;return new Promise(function(i,o){var s,l=e.Engine.TEXTURETYPE_UNSIGNED_INT,u=n._exporter._getLocalEngine();s=new e.Scene(u);var c=u.createRawTexture(t,r,a,e.Engine.TEXTUREFORMAT_RGBA,!1,!0,e.Texture.NEAREST_SAMPLINGMODE,null,l),h=new e.PostProcess("pass","pass",null,null,1,null,e.Texture.NEAREST_SAMPLINGMODE,u,!1,void 0,e.Engine.TEXTURETYPE_UNSIGNED_INT,void 0,null,!1);h.getEffect().executeWhenCompiled((function(){h.onApply=function(e){e._bindTexture("textureSampler",c)},u.setSize(r,a),s.postProcessManager.directRender([h],null),h.dispose(),c.dispose();var t=u.getRenderingCanvas();t?e.Tools.ToBlob(t,(function(e){if(e){var t=new FileReader;t.onload=function(e){var t=e.target.result;s.dispose(),i(t)},t.readAsDataURL(e)}else o("Failed to get blob from image canvas!")})):o("Engine is missing a canvas!")}))})},t.prototype._createWhiteTexture=function(t,r,a){for(var i=new Uint8Array(t*r*4),n=0;n<i.length;n+=4)i[n]=i[n+1]=i[n+2]=i[n+3]=255;return e.RawTexture.CreateRGBATexture(i,t,r,a)},t.prototype._resizeTexturesToSameDimensions=function(t,r,a){var i,n,o=t?t.getSize():{width:0,height:0},s=r?r.getSize():{width:0,height:0};return o.width<s.width?(i=t&&t instanceof e.Texture?e.TextureTools.CreateResizedCopy(t,s.width,s.height,!0):this._createWhiteTexture(s.width,s.height,a),
n=r):o.width>s.width?(n=r&&r instanceof e.Texture?e.TextureTools.CreateResizedCopy(r,o.width,o.height,!0):this._createWhiteTexture(o.width,o.height,a),i=t):(i=t,n=r),{texture1:i,texture2:n}},t.prototype._convertSpecularGlossinessTexturesToMetallicRoughnessAsync=function(r,a,i,n){var o=[];if(!r&&!a)return Promise.reject("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!");var s=r?r.getScene():a?a.getScene():null;if(s){var l=this._resizeTexturesToSameDimensions(r,a,s),u=l.texture1.getSize(),c=void 0,h=void 0,f=u.width,p=u.height,m=l.texture1.readPixels();if(m instanceof Uint8Array){if(c=l.texture1.readPixels(),(m=l.texture2.readPixels())instanceof Uint8Array){h=l.texture2.readPixels();for(var d=h.byteLength,g=new Uint8Array(d),_=new Uint8Array(d),y=e.Color3.Black(),T=0,x=0,v=0;v<p;++v)for(var b=0;b<f;++b){var A=4*(f*v+b),F=e.Color3.FromInts(c[A],c[A+1],c[A+2]).toLinearSpace().multiply(i.diffuseColor),M=e.Color3.FromInts(h[A],h[A+1],h[A+2]).toLinearSpace().multiply(i.specularColor),R=h[A+3]/255*i.glossiness,V={diffuseColor:F,specularColor:M,glossiness:R},S=this._convertSpecularGlossinessToMetallicRoughness(V);y.r=Math.max(y.r,S.baseColor.r),y.g=Math.max(y.g,S.baseColor.g),y.b=Math.max(y.b,S.baseColor.b),T=Math.max(T,S.metallic),x=Math.max(x,S.roughness),_[A]=255*S.baseColor.r,_[A+1]=255*S.baseColor.g,_[A+2]=255*S.baseColor.b,_[A+3]=l.texture1.hasAlpha?c[A+3]:255,g[A]=0,g[A+1]=255*S.roughness,g[A+2]=255*S.metallic,g[A+3]=255}for(var C={baseColor:y,metallic:T,roughness:x},E=!1,B=!1,v=0;v<p;++v)for(var b=0;b<f;++b){var w=4*(f*v+b);_[w]/=C.baseColor.r>t._Epsilon?C.baseColor.r:1,_[w+1]/=C.baseColor.g>t._Epsilon?C.baseColor.g:1,_[w+2]/=C.baseColor.b>t._Epsilon?C.baseColor.b:1;var L=e.Color3.FromInts(_[w],_[w+1],_[w+2]),N=L.toGammaSpace();_[w]=255*N.r,_[w+1]=255*N.g,_[w+2]=255*N.b,t.FuzzyEquals(N,e.Color3.White(),t._Epsilon)||(B=!0),g[w+1]/=C.roughness>t._Epsilon?C.roughness:1,g[w+2]/=C.metallic>t._Epsilon?C.metallic:1;var P=e.Color3.FromInts(255,g[w+1],g[w+2]);t.FuzzyEquals(P,e.Color3.White(),t._Epsilon)||(E=!0)}if(E){var G=this._createBase64FromCanvasAsync(g,f,p,n).then((function(e){C.metallicRoughnessTextureBase64=e}));o.push(G)}if(B){var G=this._createBase64FromCanvasAsync(_,f,p,n).then((function(e){C.baseColorTextureBase64=e}));o.push(G)}return Promise.all(o).then((function(){return C}))}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture2.name)}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture1.name)}return Promise.reject("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!")},t.prototype._convertSpecularGlossinessToMetallicRoughness=function(r){var a=this._getPerceivedBrightness(r.diffuseColor),i=this._getPerceivedBrightness(r.specularColor),n=1-this._getMaxComponent(r.specularColor),o=t._SolveMetallic(a,i,n),s=r.diffuseColor.scale(n/(1-t._DielectricSpecular.r)/Math.max(1-o,t._Epsilon)),l=r.specularColor.subtract(t._DielectricSpecular.scale(1-o)).scale(1/Math.max(o,t._Epsilon)),u=e.Color3.Lerp(s,l,o*o);return u=u.clampToRef(0,1,u),{baseColor:u,metallic:o,roughness:1-r.glossiness}},t.prototype._getPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},t.prototype._getMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},t.prototype._convertMetalRoughFactorsToMetallicRoughnessAsync=function(e,t,r,a){var i=[],n={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};return a&&(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 n}))},t.prototype._getGLTFTextureSampler=function(t){var r=this._getGLTFTextureWrapModesSampler(t),a=t instanceof e.Texture?t.samplingMode:null;if(null!=a)switch(a){case e.Texture.LINEAR_LINEAR:r.magFilter=9729,r.minFilter=9729;break;case e.Texture.LINEAR_NEAREST:r.magFilter=9729,r.minFilter=9728;break;case e.Texture.NEAREST_LINEAR:r.magFilter=9728,r.minFilter=9729;break;case e.Texture.NEAREST_LINEAR_MIPLINEAR:r.magFilter=9728,r.minFilter=9987;break;case e.Texture.NEAREST_NEAREST:r.magFilter=9728,r.minFilter=9728;break;case e.Texture.NEAREST_LINEAR_MIPNEAREST:r.magFilter=9728,r.minFilter=9985;break;case e.Texture.LINEAR_NEAREST_MIPNEAREST:r.magFilter=9729,r.minFilter=9984;break;case e.Texture.LINEAR_NEAREST_MIPLINEAR:r.magFilter=9729,r.minFilter=9986;break;case e.Texture.NEAREST_NEAREST_MIPLINEAR:r.magFilter=9728,r.minFilter=9986;break;case e.Texture.LINEAR_LINEAR_MIPLINEAR:r.magFilter=9729,r.minFilter=9987;break;case e.Texture.LINEAR_LINEAR_MIPNEAREST:r.magFilter=9729,r.minFilter=9985;break;case e.Texture.NEAREST_NEAREST_MIPNEAREST:r.magFilter=9728,r.minFilter=9984}return r},t.prototype._getGLTFTextureWrapMode=function(t){switch(t){case e.Texture.WRAP_ADDRESSMODE:return 10497;case e.Texture.CLAMP_ADDRESSMODE:return 33071;case e.Texture.MIRROR_ADDRESSMODE:return 33648;default:return e.Tools.Error("Unsupported Texture Wrap Mode "+t+"!"),10497}},t.prototype._getGLTFTextureWrapModesSampler=function(t){var r=this._getGLTFTextureWrapMode(t instanceof e.Texture?t.wrapU:e.Texture.WRAP_ADDRESSMODE),a=this._getGLTFTextureWrapMode(t instanceof e.Texture?t.wrapV:e.Texture.WRAP_ADDRESSMODE);return 10497===r&&10497===a?{}:{wrapS:r,wrapT:a}},t.prototype._convertSpecGlossFactorsToMetallicRoughnessAsync=function(t,r,a,i){var n=this;return Promise.resolve().then((function(){var o=n._exporter._samplers,s=n._exporter._textures,l={diffuseColor:t.albedoColor||e.Color3.White(),specularColor:t.reflectivityColor||e.Color3.White(),glossiness:t.microSurface||1},u=null,c=n._getGLTFTextureSampler(t.albedoTexture);return null!=c.magFilter&&null!=c.minFilter&&null!=c.wrapS&&null!=c.wrapT&&(o.push(c),u=o.length-1),t.reflectivityTexture&&!t.useMicroSurfaceFromReflectivityMapAlpha?Promise.reject("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"):(t.albedoTexture||t.reflectivityTexture)&&i?n._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(t.albedoTexture,t.reflectivityTexture,l,r).then((function(e){if(e.baseColorTextureBase64){var i=n._getTextureInfoFromBase64(e.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",r,t.albedoTexture?t.albedoTexture.coordinatesIndex:null,u);i&&(a.baseColorTexture=i)}if(e.metallicRoughnessTextureBase64){var o=n._getTextureInfoFromBase64(e.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",r,t.reflectivityTexture?t.reflectivityTexture.coordinatesIndex:null,u);o&&(a.metallicRoughnessTexture=o)}return e})):n._convertSpecularGlossinessToMetallicRoughness(l)}))},t.prototype._convertPBRMaterialAsync=function(e,t,r){var a=this,i={},n={name:e.name};return e.isMetallicWorkflow()?(e.albedoColor&&(i.baseColorFactor=[e.albedoColor.r,e.albedoColor.g,e.albedoColor.b,e.alpha]),this._convertMetalRoughFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(o){return a.setMetallicRoughnessPbrMaterial(o,e,n,i,t,r)}))):this._convertSpecGlossFactorsToMetallicRoughnessAsync(e,t,i,r).then((function(o){return a.setMetallicRoughnessPbrMaterial(o,e,n,i,t,r)}))},t.prototype.setMetallicRoughnessPbrMaterial=function(r,a,i,n,o,s){var l=this._exporter._materialMap,u=this._exporter._materials,c=[];if(r){var h=null;if(null!=a.transparencyMode&&(h=this._getAlphaMode(a))&&"OPAQUE"!==h&&(i.alphaMode=h,"MASK"===h&&(i.alphaCutoff=a.alphaCutOff)),t.FuzzyEquals(r.baseColor,e.Color3.White(),t._Epsilon)&&a.alpha>=t._Epsilon||(n.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,a.alpha]),null!=r.metallic&&1!==r.metallic&&(n.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(n.roughnessFactor=r.roughness),null==a.backFaceCulling||a.backFaceCulling||(a.twoSidedLighting||e.Tools.Warn(a.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),i.doubleSided=!0),s){if(a.bumpTexture){var f=this._exportTextureAsync(a.bumpTexture,o).then((function(e){e&&(i.normalTexture=e,1!==a.bumpTexture.level&&(i.normalTexture.scale=a.bumpTexture.level))}));c.push(f)}if(a.ambientTexture){var f=this._exportTextureAsync(a.ambientTexture,o).then((function(e){if(e){var t={index:e.index};i.occlusionTexture=t,a.ambientTextureStrength&&(t.strength=a.ambientTextureStrength)}}));c.push(f)}if(a.emissiveTexture){var f=this._exportTextureAsync(a.emissiveTexture,o).then((function(e){e&&(i.emissiveTexture=e)}));c.push(f)}}t.FuzzyEquals(a.emissiveColor,e.Color3.Black(),t._Epsilon)||(i.emissiveFactor=a.emissiveColor.asArray()),i.pbrMetallicRoughness=n,u.push(i),l[a.uniqueId]=u.length-1}return Promise.all(c).then((function(e){}))},t.prototype.getPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t.prototype._exportTextureAsync=function(e,t){var r=this;return Promise.resolve().then((function(){var a=e.uid;if(a in r._textureMap)return r._textureMap[a];for(var i=r._exporter._samplers,n=r._getGLTFTextureSampler(e),o=null,s=null,l=0;l<i.length;++l){var u=i[l];if(u.minFilter===n.minFilter&&u.magFilter===n.magFilter&&u.wrapS===n.wrapS&&u.wrapT===n.wrapT){s=l;break}}null==s?(i.push(n),o=i.length-1):o=s;var c=r.getPixelsFromTexture(e),h=e.getSize();return r._createBase64FromCanvasAsync(c,h.width,h.height,t).then((function(i){var n=r._getTextureInfoFromBase64(i,e.name,t,e.coordinatesIndex,o);return n&&(r._textureMap[a]=n),n}))}))},t.prototype._getTextureInfoFromBase64=function(t,r,a,i,n){var o=this._exporter._textures,s=this._exporter._images,l=this._exporter._imageData,u=null,c={source:s.length,name:r};null!=n&&(c.sampler=n);for(var h=atob(t.split(",")[1]),f=new ArrayBuffer(h.length),p=new Uint8Array(f),m=0,d=h.length;m<d;++m)p[m]=h.charCodeAt(m);var g={data:p,mimeType:a},_="image/jpeg"===a?".jpeg":".png",y=r+_;if(y in l&&(y=r+"_"+e.Tools.RandomId()+_),l[y]=g,"image/jpeg"===a||"image/png"===a){for(var T={name:r,uri:y},x=null,m=0;m<s.length;++m)if(s[m].uri===y){x=m;break}null==x?(s.push(T),c.source=s.length-1):c.source=x,o.push(c),u={index:o.length-1},null!=i&&(u.texCoord=i)}else e.Tools.Error("Unsupported texture mime type "+a);return u},t._DielectricSpecular=new e.Color3(.04,.04,.04),t._MaxSpecularPower=1024,t._Epsilon=1e-6,t})();t._GLTFMaterialExporter=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){!(function(t){var r;!(function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"})(r||(r={}));var a=(function(){function a(){}return a._CreateNodeAnimation=function(t,r,i,n,o,s){var l=[],u=[],c=r.getKeys(),h=a.calculateMinMaxKeyFrames(c),f=a._DeduceInterpolation(c,i,o),p=h.max-h.min,m=f.interpolationType,d=f.shouldBakeAnimation;if(d?a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o):"LINEAR"===m||"STEP"===m?a._CreateLinearOrStepAnimation(t,r,i,p,l,u,n,o):"CUBICSPLINE"===m?a._CreateCubicSplineAnimation(t,r,i,p,l,u,n,o):a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o),l.length&&u.length){return{inputs:l,outputs:u,samplerInterpolation:m,inputsMin:d?h.min:e.Tools.FloatRound(h.min/r.framePerSecond),inputsMax:d?h.max:e.Tools.FloatRound(h.max/r.framePerSecond)}}return null},a._DeduceAnimationInfo=function(t){var r=null,a="VEC3",i=!1,n=t.targetProperty.split(".");switch(n[0]){case"scaling":r="scale";break;case"position":r="translation";break;case"rotation":a="VEC4",r="rotation";break;case"rotationQuaternion":a="VEC4",i=!0,r="rotation";break;default:e.Tools.Error("Unsupported animatable property "+n[0])}return r?{animationChannelTargetPath:r,dataAccessorType:a,useQuaternion:i}:(e.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},a._CreateNodeAnimationFromTransformNodeAnimations=function(e,t,r,i,n,o,s,l,u,c){var h;if(e.animations)for(var f=0,p=e.animations;f<p.length;f++){var m=p[f],d=a._DeduceAnimationInfo(m);d&&(h={name:m.name,samplers:[],channels:[]},a.AddAnimation(""+m.name,m.hasRunningRuntimeAnimations?t:h,e,m,d.dataAccessorType,d.animationChannelTargetPath,i,o,s,l,u,d.useQuaternion,c),h.samplers.length&&h.channels.length&&r.push(h))}},a._CreateNodeAnimationFromAnimationGroups=function(t,r,i,n,o,s,l,u,c){var h;if(t.animationGroups)for(var f=t.animationGroups,p=0,m=f;p<m.length;p++){var d=m[p];h={name:d.name,channels:[],samplers:[]};for(var g=0,_=d.targetedAnimations;g<_.length;g++){var y=_[g],T=y.target,x=y.animation;if(T instanceof e.Mesh||1===T.length&&T[0]instanceof e.Mesh){var v=a._DeduceAnimationInfo(y.animation);if(v){var b=T instanceof e.Mesh?T:T[0];a.AddAnimation(""+x.name,h,b,x,v.dataAccessorType,v.animationChannelTargetPath,i,o,s,l,u,v.useQuaternion,c)}}}h.channels.length&&h.samplers.length&&r.push(h)}},a.AddAnimation=function(e,r,i,n,o,s,l,u,c,h,f,p,m){var d,g,_,y,T,x,v,b=a._CreateNodeAnimation(i,n,s,f,p,m);if(b){var A=l[i.uniqueId],F=4*b.inputs.length;d=t._GLTFUtilities._CreateBufferView(0,u.getByteOffset(),F,void 0,e+" keyframe data view"),c.push(d),b.inputs.forEach((function(e){u.setFloat32(e)})),g=t._GLTFUtilities._CreateAccessor(c.length-1,e+" keyframes","SCALAR",5126,b.inputs.length,null,[b.inputsMin],[b.inputsMax]),h.push(g),_=h.length-1,T=b.outputs.length,F="VEC3"===o?12*b.outputs.length:16*b.outputs.length,d=t._GLTFUtilities._CreateBufferView(0,u.getByteOffset(),F,void 0,e+" data view"),c.push(d),b.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=t._GLTFUtilities._CreateAccessor(c.length-1,e+" data",o,5126,T,null,null,null),h.push(g),y=h.length-1,x={interpolation:b.samplerInterpolation,input:_,output:y},r.samplers.push(x),v={sampler:r.samplers.length-1,target:{node:A,path:s}},r.channels.push(v)}},a._CreateBakedAnimation=function(t,r,i,n,o,s,l,u,c,h,f,p){var m,d,g=e.Quaternion.Identity(),_=null,y=null,T=null,x=null,v=null,b=null;h.min=e.Tools.FloatRound(n/s);for(var A=r.getKeys(),F=0,M=A.length;F<M;++F){if(b=null,T=A[F],F+1<M)if(x=A[F+1],T.value.equals(x.value)){if(0!==F)continue;b=T.frame}else b=x.frame;else{if(v=A[F-1],T.value.equals(v.value))continue;b=o}if(b)for(var R=T.frame;R<=b;R+=l)(d=e.Tools.FloatRound(R/s))!==_&&(_=d,y=d,m=r._interpolate(R,0,void 0,r.loopMode),a._SetInterpolatedValue(t,m,d,r,i,g,u,c,f,p))}y&&(h.max=y)},a._ConvertFactorToVector3OrQuaternion=function(t,r,i,n,o,s,l){var u,c,h=null,f=a._GetBasePositionRotationOrScale(r,o,s,l);if(n===e.Animation.ANIMATIONTYPE_FLOAT)switch(u=i.targetProperty.split("."),c=u?u[1]:"",h=l?e.Quaternion.FromArray(f).normalize():e.Vector3.FromArray(f),c){case"x":case"y":h[c]=s&&l&&"scale"!==o?-t:t;break;case"z":h[c]=s&&!l&&"scale"!==o?-t:t;break;case"w":h.w=t;break;default:e.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return h},a._SetInterpolatedValue=function(r,a,i,n,o,s,l,u,c,h){var f,p=n.dataType;l.push(i),"number"==typeof a&&(a=this._ConvertFactorToVector3OrQuaternion(a,r,n,p,o,c,h)),a&&("rotation"===o?(h?s=a:(f=a,e.Quaternion.RotationYawPitchRollToRef(f.y,f.x,f.z,s)),c&&(t._GLTFUtilities._GetRightHandedQuaternionFromRef(s),r.parent||(s=e.Quaternion.FromArray([0,1,0,0]).multiply(s))),u.push(s.asArray())):(f=a,c&&"scale"!==o&&(t._GLTFUtilities._GetRightHandedPositionVector3FromRef(f),r.parent||(f.x*=-1,f.z*=-1)),u.push(f.asArray())))},a._CreateLinearOrStepAnimation=function(e,t,r,i,n,o,s,l){for(var u=0,c=t.getKeys();u<c.length;u++){var h=c[u];n.push(h.frame/t.framePerSecond),a._AddKeyframeValue(h,t,o,r,e,s,l)}},a._CreateCubicSplineAnimation=function(e,t,i,n,o,s,l,u){t.getKeys().forEach((function(c){o.push(c.frame/t.framePerSecond),a.AddSplineTangent(e,r.INTANGENT,s,i,"CUBICSPLINE",c,n,u,l),a._AddKeyframeValue(c,t,s,i,e,l,u),a.AddSplineTangent(e,r.OUTTANGENT,s,i,"CUBICSPLINE",c,n,u,l)}))},a._GetBasePositionRotationOrScale=function(r,a,i,n){var o;return"rotation"===a?n?r.rotationQuaternion?(o=r.rotationQuaternion.asArray(),i&&(t._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(o),r.parent||(o=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(o)).asArray()))):o=e.Quaternion.Identity().asArray():(o=r.rotation.asArray(),t._GLTFUtilities._GetRightHandedNormalArray3FromRef(o)):"translation"===a?(o=r.position.asArray(),i&&t._GLTFUtilities._GetRightHandedPositionArray3FromRef(o)):o=r.scaling.asArray(),o},a._AddKeyframeValue=function(r,a,i,n,o,s,l){var u,c,h=a.dataType;if(h===e.Animation.ANIMATIONTYPE_VECTOR3){if(u=r.value.asArray(),"rotation"===n){var f=e.Vector3.FromArray(u),p=e.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z);s&&(t._GLTFUtilities._GetRightHandedQuaternionFromRef(p),o.parent||(p=e.Quaternion.FromArray([0,1,0,0]).multiply(p))),u=p.asArray()}else"translation"===n&&s&&(t._GLTFUtilities._GetRightHandedNormalArray3FromRef(u),o.parent||(u[0]*=-1,u[2]*=-1));i.push(u)}else if(h===e.Animation.ANIMATIONTYPE_FLOAT){if(c=this._ConvertFactorToVector3OrQuaternion(r.value,o,a,h,n,s,l)){if("rotation"===n){var m=l?c:e.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).normalize();s&&(t._GLTFUtilities._GetRightHandedQuaternionFromRef(m),o.parent||(m=e.Quaternion.FromArray([0,1,0,0]).multiply(m))),i.push(m.asArray())}else"translation"===n&&s&&(t._GLTFUtilities._GetRightHandedNormalVector3FromRef(c),o.parent||(c.x*=-1,c.z*=-1));i.push(c.asArray())}}else h===e.Animation.ANIMATIONTYPE_QUATERNION?(u=r.value.normalize().asArray(),s&&(t._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(u),o.parent||(u=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(u)).asArray())),i.push(u)):e.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},a._DeduceInterpolation=function(t,r,a){var i,n,o=!1;if("rotation"===r&&!a)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,l=t.length;s<l;++s)if(n=t[s],n.inTangent||n.outTangent)if(i){if("CUBICSPLINE"!==i){i="LINEAR",o=!0;break}}else i="CUBICSPLINE";else if(i){if("CUBICSPLINE"===i||n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP&&"STEP"!==i){i="LINEAR",o=!0;break}}else i=n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return i||(i="LINEAR"),{interpolationType:i,shouldBakeAnimation:o}},a.AddSplineTangent=function(a,i,n,o,s,l,u,c,h){var f,p=i===r.INTANGENT?l.inTangent:l.outTangent;if("CUBICSPLINE"===s){if("rotation"===o)if(p){if(c)f=p.scale(u).asArray();else{var m=p.scale(u);f=e.Quaternion.RotationYawPitchRoll(m.y,m.x,m.z).asArray()}h&&(t._GLTFUtilities._GetRightHandedQuaternionArrayFromRef(f),a.parent||(f=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(f)).asArray()))}else f=[0,0,0,0];else p?(f=p.scale(u).asArray(),h&&"translation"===o&&(t._GLTFUtilities._GetRightHandedPositionArray3FromRef(f),a.parent||(f[0]*=-1,f[2]*=-1))):f=[0,0,0];n.push(f)}},a.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}},a})();t._GLTFAnimation=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;return (function(e){!(function(t){var r=(function(){function t(){}return t._CreateBufferView=function(e,t,r,a,i){var n={buffer:e,byteLength:r};return t&&(n.byteOffset=t),i&&(n.name=i),a&&(n.byteStride=a),n},t._CreateAccessor=function(e,t,r,a,i,n,o,s){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=n&&(l.byteOffset=n),l},t._CalculateMinMaxPositions=function(r,a,i,n){var o,s,l,u=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(i)for(var h=a,f=a+i;h<f;++h){o=3*h,s=e.Vector3.FromArray(r,o),n&&t._GetRightHandedPositionVector3FromRef(s),l=s.asArray();for(var p=0;p<3;++p){var m=l[p];m<u[p]&&(u[p]=m),m>c[p]&&(c[p]=m),++o}}return{min:u,max:c}},t._GetRightHandedPositionVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t._GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},t._GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},t._GetRightHandedNormalVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t._GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},t._GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},t._GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},t._GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},t._GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},t._GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},t._NormalizeTangentFromRef=function(e){var t=Math.sqrt(e.x*e.x+e.y*e.y+e.z+e.z);e.x/=t,e.y/=t,e.z/=t},t})();t._GLTFUtilities=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={})),e}));

@@ -578,3 +578,3 @@ /// <reference types="babylonjs"/>

*/
private _gonvertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords);
private _convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords);
private _getGLTFTextureSampler(texture);

@@ -594,3 +594,3 @@ private _getGLTFTextureWrapMode(wrapMode);

*/
private _convertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords);
private _convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords);
/**

@@ -824,3 +824,3 @@ * Converts a Babylon PBR Metallic Roughness Material to a glTF Material

*/
static CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView;
static _CreateBufferView(bufferIndex: number, byteOffset: number, byteLength: number, byteStride?: number, name?: string): IBufferView;
/**

@@ -838,3 +838,3 @@ * Creates an accessor based on the supplied arguments

*/
static CreateAccessor(bufferviewIndex: number, name: string, type: AccessorType, componentType: AccessorComponentType, count: number, byteOffset: Nullable<number>, min: Nullable<number[]>, max: Nullable<number[]>): IAccessor;
static _CreateAccessor(bufferviewIndex: number, name: string, type: AccessorType, componentType: AccessorComponentType, count: number, byteOffset: Nullable<number>, min: Nullable<number[]>, max: Nullable<number[]>): IAccessor;
/**

@@ -847,3 +847,3 @@ * Calculates the minimum and maximum values of an array of position floats

*/
static CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number, convertToRightHandedSystem: boolean): {
static _CalculateMinMaxPositions(positions: FloatArray, vertexStart: number, vertexCount: number, convertToRightHandedSystem: boolean): {
min: number[];

@@ -857,3 +857,3 @@ max: number[];

*/
static GetRightHandedPositionVector3(vector: Vector3): Vector3;
static _GetRightHandedPositionVector3(vector: Vector3): Vector3;
/**

@@ -863,3 +863,3 @@ * Converts a Vector3 to right-handed

*/
static GetRightHandedPositionVector3FromRef(vector: Vector3): void;
static _GetRightHandedPositionVector3FromRef(vector: Vector3): void;
/**

@@ -869,3 +869,3 @@ * Converts a three element number array to right-handed

*/
static GetRightHandedPositionArray3FromRef(vector: number[]): void;
static _GetRightHandedPositionArray3FromRef(vector: number[]): void;
/**

@@ -876,3 +876,3 @@ * Converts a new right-handed Vector3

*/
static GetRightHandedNormalVector3(vector: Vector3): Vector3;
static _GetRightHandedNormalVector3(vector: Vector3): Vector3;
/**

@@ -882,3 +882,3 @@ * Converts a Vector3 to right-handed

*/
static GetRightHandedNormalVector3FromRef(vector: Vector3): void;
static _GetRightHandedNormalVector3FromRef(vector: Vector3): void;
/**

@@ -888,3 +888,3 @@ * Converts a three element number array to right-handed

*/
static GetRightHandedNormalArray3FromRef(vector: number[]): void;
static _GetRightHandedNormalArray3FromRef(vector: number[]): void;
/**

@@ -894,3 +894,3 @@ * Converts a Vector4 to right-handed

*/
static GetRightHandedVector4FromRef(vector: Vector4): void;
static _GetRightHandedVector4FromRef(vector: Vector4): void;
/**

@@ -900,3 +900,3 @@ * Converts a Vector4 to right-handed

*/
static GetRightHandedArray4FromRef(vector: number[]): void;
static _GetRightHandedArray4FromRef(vector: number[]): void;
/**

@@ -906,3 +906,3 @@ * Converts a Quaternion to right-handed

*/
static GetRightHandedQuaternionFromRef(quaternion: Quaternion): void;
static _GetRightHandedQuaternionFromRef(quaternion: Quaternion): void;
/**

@@ -912,4 +912,5 @@ * Converts a Quaternion to right-handed

*/
static GetRightHandedQuaternionArrayFromRef(quaternion: number[]): void;
static _GetRightHandedQuaternionArrayFromRef(quaternion: number[]): void;
static _NormalizeTangentFromRef(tangent: Vector4): void;
}
}

@@ -7,3 +7,3 @@ {

"description": "The Babylon.js serializers library is an extension you can use to serialize Babylon scenes.",
"version": "3.3.0-alpha.9",
"version": "3.3.0-alpha.10",
"repository": {

@@ -31,3 +31,3 @@ "type": "git",

"dependencies": {
"babylonjs-gltf2interface": "3.3.0-alpha.9"
"babylonjs-gltf2interface": "3.3.0-alpha.10"
},

@@ -34,0 +34,0 @@ "peerDependencies": {

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc