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