12 |
- BABYLON.Effect.ShadersStore.setAlphaToOnePixelShader="precision highp float;\nuniform sampler2D textureSampler;\nvarying vec2 vUV;\nvoid main(void) {\nvec4 color=texture2D(textureSampler,vUV);\ngl_FragColor=vec4(color.rgb,1.0);\n}";var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTFAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var n=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLTFAsync(n)}))},t.GLBAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var n=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLBAsync(n)}))},t})();e.GLTF2Export=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(e,t){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.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}return r.prototype.reorderIndicesBasedOnPrimitiveMode=function(t,r,a,n,i){switch(r){case e.Material.TriangleFillMode:n||(n=0);for(var o=t.indexStart,s=t.indexStart+t.indexCount;o<s;o+=3){var l=n+4*o,u=i.getUInt32(l+4),c=i.getUInt32(l+8);i.setUInt32(c,l+4),i.setUInt32(u,l+8)}break;case e.Material.TriangleFanDrawMode:for(var o=t.indexStart+t.indexCount-1,f=t.indexStart;o>=f;--o)i.setUInt32(a[o],n),n+=4;break;case e.Material.TriangleStripDrawMode:t.indexCount>=3&&(i.setUInt32(a[t.indexStart+2],n+4),i.setUInt32(a[t.indexStart+1],n+8))}},r.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(t,r,a,n,i,o,s){if(this.convertToRightHandedSystem&&a===e.Material.ClockWiseSideOrientation)switch(r){case e.Material.TriangleFillMode:this.reorderTriangleFillMode(t,r,a,n,i,o,s);break;case e.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(t,r,a,n,i,o,s);break;case e.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(t,r,a,n,i,o,s)}},r.prototype.reorderTriangleFillMode=function(t,r,a,n,i,o,s){var l=this.getVertexBufferFromMesh(n,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=[],f=0;switch(n){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)f=h*u,c.push(e.Vector3.FromArray(i,f)),c.push(e.Vector3.FromArray(i,f+2*u)),c.push(e.Vector3.FromArray(i,f+u));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)f=h*u,c.push(e.Vector4.FromArray(i,f)),c.push(e.Vector4.FromArray(i,f+2*u)),c.push(e.Vector4.FromArray(i,f+u));break;case e.VertexBuffer.ColorKind:for(var d=l.getSize(),h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=d)f=h*u,4===d?(c.push(e.Vector4.FromArray(i,f)),c.push(e.Vector4.FromArray(i,f+2*u)),c.push(e.Vector4.FromArray(i,f+u))):(c.push(e.Vector3.FromArray(i,f)),c.push(e.Vector3.FromArray(i,f+2*u)),c.push(e.Vector3.FromArray(i,f+u)));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)f=h*u,c.push(e.Vector2.FromArray(i,f)),c.push(e.Vector2.FromArray(i,f+2*u)),c.push(e.Vector2.FromArray(i,f+u));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(c,o,n,i,s)}}else e.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+n+" not present!")},r.prototype.reorderTriangleStripDrawMode=function(t,r,a,n,i,o,s){var l=this.getVertexBufferFromMesh(n,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],f=0;switch(n){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:f=t.verticesStart,c.push(e.Vector3.FromArray(i,f+2*u)),c.push(e.Vector3.FromArray(i,f+u));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)f=h*u,c.push(e.Vector4.FromArray(i,f));break;case e.VertexBuffer.ColorKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)f=h*u,4===l.getSize()?c.push(e.Vector4.FromArray(i,f)):c.push(e.Vector3.FromArray(i,f));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)f=h*u,c.push(e.Vector2.FromArray(i,f));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(c,o+12,n,i,s)}else e.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+n+" not present!")},r.prototype.reorderTriangleFanMode=function(t,r,a,n,i,o,s){var l=this.getVertexBufferFromMesh(n,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],f=0;switch(n){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)f=h*u,c.push(e.Vector3.FromArray(i,f));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)f=h*u,c.push(e.Vector4.FromArray(i,f));break;case e.VertexBuffer.ColorKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)f=h*u,c.push(e.Vector4.FromArray(i,f)),4===l.getSize()?c.push(e.Vector4.FromArray(i,f)):c.push(e.Vector3.FromArray(i,f));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)f=h*u,c.push(e.Vector2.FromArray(i,f));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+n)}this.writeVertexAttributeData(c,o,n,i,s)}else e.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+n+" not present!")},r.prototype.writeVertexAttributeData=function(r,a,n,i,o){for(var s=0,l=r;s<l.length;s++){var u=l[s];!this.convertToRightHandedSystem||n===e.VertexBuffer.ColorKind||u instanceof e.Vector2||(u instanceof e.Vector3?n===e.VertexBuffer.PositionKind?t._GLTFUtilities.GetRightHandedPositionVector3FromRef(u):t._GLTFUtilities.GetRightHandedNormalVector3FromRef(u):t._GLTFUtilities.GetRightHandedVector4FromRef(u));for(var c=0,f=u.asArray();c<f.length;c++){var h=f[c];o.setFloat32(h,a),a+=4}}},r.prototype.writeAttributeData=function(r,a,n,i){var o,s=n/4,l=[];switch(r){case e.VertexBuffer.PositionKind:for(var u=0,c=a.length/s;u<c;++u){o=u*s;var f=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedPositionVector3FromRef(f),l.push(f.asArray())}break;case e.VertexBuffer.NormalKind:for(var u=0,h=a.length/s;u<h;++u){o=u*s;var f=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedNormalVector3FromRef(f),l.push(f.asArray())}break;case e.VertexBuffer.TangentKind:for(var u=0,d=a.length/s;u<d;++u){o=u*s;var f=e.Vector4.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedVector4FromRef(f),l.push(f.asArray())}break;case e.VertexBuffer.ColorKind:for(var u=0,m=a.length/s;u<m;++u){o=u*s;var f=3===s?e.Vector3.FromArray(a,o):e.Vector4.FromArray(a,o);l.push(f.asArray())}break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var u=0,p=a.length/s;u<p;++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,T=l;g<T.length;g++)for(var y=T[g],v=0,A=y;v<A.length;v++){var x=A[v];i.setFloat32(x)}},r.prototype.generateJSON=function(e,r,a){var n,i,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&&(i=s.imageData[e.uri],n=e.uri.split(".")[0]+" image",o=t._GLTFUtilities.CreateBufferView(0,u,i.data.length,void 0,n),u+=i.data.buffer.byteLength,s.bufferViews.push(o),e.bufferView=s.bufferViews.length-1,e.name=n,e.mimeType=i.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 n=r.generateJSON(!1,t,!0),i=new Blob([a],{type:"application/octet-stream"}),o=t+".gltf",s=t+".bin",l=new e.GLTFData;if(l.glTFFiles[o]=n,l.glTFFiles[s]=i,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=new a(4);return this.createSceneAsync(this.babylonScene,e).then((function(){return e.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 n=r.generateJSON(!0),i=t+".glb",o=n.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),f=r._getPadding(s),h=28+o+u+a.byteLength+c+s+f,d=new ArrayBuffer(12),m=new DataView(d);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,h,!0);var p=new ArrayBuffer(8+o+u),g=new DataView(p);g.setUint32(0,o+u,!0),g.setUint32(4,1313821514,!0);for(var T=new Uint8Array(p,8),y=0;y<o;++y)T[y]=n.charCodeAt(y);for(var v=new Uint8Array(p,8+o),y=0;y<u;++y)v[y]=32;var A=new ArrayBuffer(8),x=new DataView(A);x.setUint32(0,a.byteLength+s+f,!0),x.setUint32(4,5130562,!0);for(var b=new ArrayBuffer(c),F=new Uint8Array(b),y=0;y<c;++y)F[y]=0;for(var _=new ArrayBuffer(f),R=new Uint8Array(_),y=0;y<f;++y)R[y]=0;var B=[d,p,A,a];for(var l in r.imageData)B.push(r.imageData[l].data.buffer);B.push(b),B.push(_);var S=new Blob(B,{type:"application/octet-stream"}),M=new e.GLTFData;return M.glTFFiles[i]=S,M}))},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 n=e.Quaternion.RotationYawPitchRoll(a.rotation.y,a.rotation.x,a.rotation.z);a.rotationQuaternion&&n.multiplyInPlace(a.rotationQuaternion),0===n.x&&0===n.y&&0===n.z&&1===n.w||(this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedQuaternionFromRef(n),r.rotation=n.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,n,i){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,n.getByteOffset(),l,i,r+" - "+o.name);this.bufferViews.push(u),this.writeAttributeData(r,s,i,n)}}},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,n){var i,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,f=this.getMeshPrimitiveMode(l),h={},d=0,m=u;d<m.length;d++){var p=m[d],g=p.kind;if(l.isVerticesDataPresent(g)){var T=this.getVertexBufferFromMesh(g,l);p.byteStride=T?4*T.getSize():4*e.VertexBuffer.DeduceStride(g),12===p.byteStride&&(p.accessorType="VEC3"),this.createBufferViewKind(g,a,n,p.byteStride),p.bufferViewIndex=this.bufferViews.length-1,h[g]=p.bufferViewIndex}}if(l.getTotalIndices()){var y=l.getIndices();if(y){var v=4*y.length;i=t._GLTFUtilities.CreateBufferView(0,n.getByteOffset(),v,void 0,"Indices - "+l.name),this.bufferViews.push(i),c=this.bufferViews.length-1;for(var A=0,x=y.length;A<x;++A)n.setUInt32(y[A])}}if(l.subMeshes)for(var b=0,F=l.subMeshes;b<F.length;b++){var _=F[b];o=!1;var R=_.getMaterial(),B=null;if(R)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),B=this.materials.length-1}else R instanceof e.MultiMaterial?(R=R.subMaterials[_.materialIndex])&&(B=this.babylonScene.materials.indexOf(R)):B=this.babylonScene.materials.indexOf(R);var M=null!=B?this.materials[B]:null,C={attributes:{}};this.setPrimitiveMode(C,f);for(var V=0,E=u;V<E.length;V++){var p=E[V],g=p.kind;if(g!==e.VertexBuffer.UVKind&&g!==e.VertexBuffer.UV2Kind||!M||t._GLTFMaterial._HasTexturesPresent(M)){var L=l.getVerticesData(g);if(L){var T=this.getVertexBufferFromMesh(g,l);if(T){var w=T.getSize(),G=p.bufferViewIndex;if(void 0!=G){s={min:null,max:null},g==e.VertexBuffer.PositionKind&&(s=t._GLTFUtilities.CalculateMinMaxPositions(L,0,L.length/w,this.convertToRightHandedSystem));var P=t._GLTFUtilities.CreateAccessor(G,g+" - "+a.name,p.accessorType,5126,L.length/w,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,_.indexCount,4*_.indexStart,null,null);this.accessors.push(P),C.indices=this.accessors.length-1}if(R&&null!=B&&Object.keys(C.attributes).length>0){var N=this.babylonScene.materials[B].sideOrientation;if(this.convertToRightHandedSystem&&N===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,U,I,n);else for(var O=0,k=u;O<k.length;O++){var p=k[O],L=l.getVerticesData(p.kind);if(L){var D=this.bufferViews[h[p.kind]].byteOffset;D||(D=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(_,f,N,p.kind,L,D,n)}}}if(!o&&t._GLTFMaterial._HasTexturesPresent(this.materials[B])){var K=t._GLTFMaterial._StripTexturesFromMaterial(this.materials[B]);this.materials.push(K),B=this.materials.length-1}C.material=B}r.primitives.push(C)}}},r.prototype.createSceneAsync=function(r,a){var n,i,o,s=this,l={nodes:[]},u=r.transformNodes.concat(r.meshes);return t._GLTFMaterial._ConvertMaterialsToGLTFAsync(r.materials,"image/png",this.images,this.textures,this.samplers,this.materials,this.imageData,!0).then((function(){s.nodeMap=s.createNodeMapAndAnimations(r,u,s.shouldExportTransformNode,a),s.totalByteLength=a.getByteOffset();for(var t=0,c=u;t<c.length;t++){var f=c[t];if(null!=(n=s.nodeMap[f.uniqueId])&&(i=s.nodes[n],f.parent||(s.shouldExportTransformNode(f)?(s.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()),l.nodes.push(n)):e.Tools.Log("Omitting "+f.name+" from scene.")),o=f.getDescendants(!0),!i.children&&o&&o.length)){i.children=[];for(var h=0,d=o;h<d.length;h++){var m=d[h];null!=s.nodeMap[m.uniqueId]&&i.children.push(s.nodeMap[m.uniqueId])}}}l.nodes.length&&s.scenes.push(l)}))},r.prototype.createNodeMapAndAnimations=function(e,r,a,n){for(var i,o,s=this,l={},u={name:"runtime animations",channels:[],samplers:[]},c=[],f=0,h=r;f<h.length;f++){var d=h[f];a(d)?(o=this.createNode(d,n),this.nodes.push(o),i=this.nodes.length-1,l[d.uniqueId]=i,!e.animationGroups.length&&d.animations.length&&t._GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations(d,u,c,l,this.nodes,n,this.bufferViews,this.accessors,this.convertToRightHandedSystem,this.animationSampleRate)):d.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,n,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),n=0,i=a.byteLength;n<i;++n)a[n]=r[n];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={}))})(BABYLON||(BABYLON={}));var 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 a=this.glTFFiles[t],n=void 0;e(t,".glb")?n={type:"model/gltf-binary"}:e(t,".bin")?n={type:"application/octet-stream"}:e(t,".gltf")?n={type:"model/gltf+json"}:e(t,".jpeg")?n={type:"image/jpeg"}:e(t,".png")&&(n={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([a],n)),r.click()}},e})();e.GLTFData=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function t(){}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._ConvertMaterialsToGLTFAsync=function(r,a,n,i,o,s,l,u){for(var c=[],f=0,h=r;f<h.length;f++){var d=h[f];d instanceof e.StandardMaterial?c.push(t._ConvertStandardMaterialAsync(d,a,n,i,o,s,l,u)):d instanceof e.PBRMetallicRoughnessMaterial?c.push(t._ConvertPBRMetallicRoughnessMaterialAsync(d,a,n,i,o,s,l,u)):d instanceof e.PBRMaterial?c.push(t._ConvertPBRMaterialAsync(d,a,n,i,o,s,l,u)):e.Tools.Warn("Unsupported material type: "+d.name)}return Promise.all(c).then((function(){}))},t._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._HasTexturesPresent=function(e){if(e.emissiveTexture||e.normalTexture||e.occlusionTexture)return!0;var t=e.pbrMetallicRoughness;return!(!t||!t.baseColorTexture&&!t.metallicRoughnessTexture)},t._ConvertToGLTFPBRMetallicRoughness=function(t){function r(e,t,r,a,n){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*a+e*e*e*n}var a=new e.Vector2(0,1),n=new e.Vector2(0,.1),i=new e.Vector2(0,.1),o=new e.Vector2(1300,.1),s=t.diffuseColor.toLinearSpace().scale(.5),l=t.alpha,u=e.Scalar.Clamp(t.specularPower,0,this._maxSpecularPower),c=(function(e){return r(Math.pow(e/o.x,.333333),a.y,n.y,i.y,o.y)})(u);return{baseColorFactor:[s.r,s.g,s.b,l],metallicFactor:0,roughnessFactor:c}},t._SolveMetallic=function(r,a,n){if(a<t._dielectricSpecular.r)return t._dielectricSpecular,0;var i=t._dielectricSpecular.r,o=r*n/(1-t._dielectricSpecular.r)+a-2*t._dielectricSpecular.r,s=t._dielectricSpecular.r-a,l=o*o-4*i*s;return e.Scalar.Clamp((-o+Math.sqrt(l))/(2*i),0,1)},t._GetAlphaMode=function(t){if(t instanceof e.StandardMaterial){var r=t;return 1!==r.alpha||null!=r.diffuseTexture&&r.diffuseTexture.hasAlpha||null!=r.opacityTexture?"BLEND":"OPAQUE"}if(t instanceof e.PBRMetallicRoughnessMaterial){var a=t;switch(a.transparencyMode){case e.PBRMaterial.PBRMATERIAL_OPAQUE:return"OPAQUE";case e.PBRMaterial.PBRMATERIAL_ALPHABLEND:return"BLEND";case e.PBRMaterial.PBRMATERIAL_ALPHATEST:return"MASK";case e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND:return e.Tools.Warn(t.name+": GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:return e.Tools.Error("Unsupported alpha mode "+a.transparencyMode),null}}else{if(!(t instanceof e.PBRMaterial))return e.Tools.Error("Unsupported Babylon material type"),null;var n=t;switch(n.transparencyMode){case e.PBRMaterial.PBRMATERIAL_OPAQUE:return"OPAQUE";case e.PBRMaterial.PBRMATERIAL_ALPHABLEND:return"BLEND";case e.PBRMaterial.PBRMATERIAL_ALPHATEST:return"MASK";case e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND:return e.Tools.Warn(t.name+": GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:return e.Tools.Error("Unsupported alpha mode "+n.transparencyMode),null}}},t._ConvertStandardMaterialAsync=function(r,a,n,i,o,s,l,u){var c=this._GetAlphaMode(r),f="OPAQUE"!==c,h=[],d=t._ConvertToGLTFPBRMetallicRoughness(r),m={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."),m.doubleSided=!0),u){if(r.diffuseTexture){var p=t._ExportTextureAsync(r.diffuseTexture,a,n,i,o,l,f).then((function(e){e&&(d.baseColorTexture=e)}));h.push(p)}if(r.bumpTexture){var p=t._ExportTextureAsync(r.bumpTexture,a,n,i,o,l,f).then((function(e){e&&(m.normalTexture=e,null!=r.bumpTexture&&1!==r.bumpTexture.level&&(m.normalTexture.scale=r.bumpTexture.level))}));h.push(p)}if(r.emissiveTexture){var p=t._ExportTextureAsync(r.emissiveTexture,a,n,i,o,l,f).then((function(e){e&&(m.emissiveTexture=e),m.emissiveFactor=[1,1,1]}));h.push(p)}if(r.ambientTexture){var p=t._ExportTextureAsync(r.ambientTexture,a,n,i,o,l,f).then((function(e){if(e){var t={index:e.index};m.occlusionTexture=t,t.strength=1}}));h.push(p)}}return(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?m.alphaMode="BLEND":e.Tools.Warn(r.name+": glTF 2.0 does not support alpha mode: "+r.alphaMode.toString())),r.emissiveColor&&!this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(m.emissiveFactor=r.emissiveColor.asArray()),m.pbrMetallicRoughness=d,s.push(m),Promise.all(h).then((function(){}))},t._SetAlphaToOneAsync=function(t,r){return new Promise(function(a,n){if(r)a(t);else{var i=t.getScene();if(i){var o=new e.ProceduralTexture("texture",t.getSize(),"setAlphaToOne",i);o?(o.setTexture("textureSampler",t),o.onLoadObservable.add((function(){a(o)}))):n("Cannot create procedural texture for "+t.name+"!")}else n("Scene not available for texture "+t.name)}})},t._ConvertPBRMetallicRoughnessMaterialAsync=function(r,a,n,i,o,s,l,u){var c=[],f={};r.baseColor&&(f.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,r.alpha]),null!=r.metallic&&1!==r.metallic&&(f.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(f.roughnessFactor=r.roughness);var h={name:r.name};r.doubleSided&&(h.doubleSided=r.doubleSided);var d=null,m=!1;if(null!=r.transparencyMode&&(d=t._GetAlphaMode(r))&&"OPAQUE"!==d&&(h.alphaMode=d,"MASK"===d&&(h.alphaCutoff=r.alphaCutOff)),"OPAQUE"!==d&&(m=!0),u){if(null!=r.baseTexture){var p=t._ExportTextureAsync(r.baseTexture,a,n,i,o,l,m).then((function(e){e&&(f.baseColorTexture=e)}));c.push(p)}if(r.normalTexture){var p=t._ExportTextureAsync(r.normalTexture,a,n,i,o,l,m).then((function(e){e&&(h.normalTexture=e,1!==r.normalTexture.level&&(h.normalTexture.scale=r.normalTexture.level))}));c.push(p)}if(r.occlusionTexture){var p=t._ExportTextureAsync(r.occlusionTexture,a,n,i,o,l,m).then((function(e){e&&(h.occlusionTexture=e,null!=r.occlusionStrength&&(h.occlusionTexture.strength=r.occlusionStrength))}));c.push(p)}if(r.emissiveTexture){var p=t._ExportTextureAsync(r.emissiveTexture,a,n,i,o,l,m).then((function(e){e&&(h.emissiveTexture=e)}));c.push(p)}}return this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(h.emissiveFactor=r.emissiveColor.asArray()),h.pbrMetallicRoughness=f,s.push(h),Promise.all(c).then((function(){}))},t._CreateBase64FromCanvas=function(e,t,r,a){var n=document.createElement("canvas");n.width=t,n.height=r,n.id="WriteCanvas";var i=n.getContext("2d"),o=i.createImageData(t,r);return o.data.set(e),i.putImageData(o,0,0),n.toDataURL(a)},t._CreateWhiteTexture=function(t,r,a){for(var n=new Uint8Array(t*r*4),i=0;i<n.length;i+=4)n[i]=n[i+1]=n[i+2]=n[i+3]=255;return e.RawTexture.CreateRGBATexture(n,t,r,a)},t._ResizeTexturesToSameDimensions=function(t,r,a){var n,i,o=t?t.getSize():{width:0,height:0},s=r?r.getSize():{width:0,height:0};return o.width<s.width?(n=t?e.TextureTools.CreateResizedCopy(t,s.width,s.height,!0):this._CreateWhiteTexture(s.width,s.height,a),i=r):o.width>s.width?(i=r?e.TextureTools.CreateResizedCopy(r,o.width,o.height,!0):this._CreateWhiteTexture(o.width,o.height,a),n=t):(n=t,i=r),{texture1:n,texture2:i}},t._ConvertSpecularGlossinessTexturesToMetallicRoughness=function(t,r,a,n){if(!t&&!r)return e.Tools.Warn("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!"),null;var i=t?t.getScene():r?r.getScene():null;if(i){var o=this._ResizeTexturesToSameDimensions(t,r,i),s=o.texture1.getSize(),l=void 0,u=void 0,c=s.width,f=s.height,h=o.texture1.readPixels();if(h instanceof Uint8Array){if(l=o.texture1.readPixels(),(h=o.texture2.readPixels())instanceof Uint8Array){u=o.texture2.readPixels();for(var d=u.byteLength,m=new Uint8Array(d),p=new Uint8Array(d),g=e.Color3.Black(),T=0,y=0,v=0;v<f;++v)for(var A=0;A<c;++A){var x=4*(c*v+A),b=e.Color3.FromInts(l[x],l[x+1],l[x+2]).toLinearSpace().multiply(a.diffuseColor),F=e.Color3.FromInts(u[x],u[x+1],u[x+2]).toLinearSpace().multiply(a.specularColor),_=u[x+3]/255*a.glossiness,R={diffuseColor:b,specularColor:F,glossiness:_},B=this._ConvertSpecularGlossinessToMetallicRoughness(R);g.r=Math.max(g.r,B.baseColor.r),g.g=Math.max(g.g,B.baseColor.g),g.b=Math.max(g.b,B.baseColor.b),T=Math.max(T,B.metallic),y=Math.max(y,B.roughness),p[x]=255*B.baseColor.r,p[x+1]=255*B.baseColor.g,p[x+2]=255*B.baseColor.b,p[x+3]=o.texture1.hasAlpha?l[x+3]:255,m[x]=0,m[x+1]=255*B.roughness,m[x+2]=255*B.metallic,m[x+3]=255}for(var S={baseColor:g,metallic:T,roughness:y},M=!1,C=!1,v=0;v<f;++v)for(var A=0;A<c;++A){var V=4*(c*v+A);p[V]/=S.baseColor.r>this._epsilon?S.baseColor.r:1,p[V+1]/=S.baseColor.g>this._epsilon?S.baseColor.g:1,p[V+2]/=S.baseColor.b>this._epsilon?S.baseColor.b:1;var E=e.Color3.FromInts(p[V],p[V+1],p[V+2]),L=E.toGammaSpace();p[V]=255*L.r,p[V+1]=255*L.g,p[V+2]=255*L.b,this.FuzzyEquals(L,e.Color3.White(),this._epsilon)||(C=!0),m[V+1]/=S.roughness>this._epsilon?S.roughness:1,m[V+2]/=S.metallic>this._epsilon?S.metallic:1;var w=e.Color3.FromInts(255,m[V+1],m[V+2]);this.FuzzyEquals(w,e.Color3.White(),this._epsilon)||(M=!0)}if(M){var G=this._CreateBase64FromCanvas(m,c,f,n);S.metallicRoughnessTextureBase64=G}if(C){var P=this._CreateBase64FromCanvas(p,c,f,n);S.baseColorTextureBase64=P}return S}e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+o.texture2.name)}else e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+o.texture1.name)}else e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!");return null},
- t._ConvertSpecularGlossinessToMetallicRoughness=function(r){var a=t._GetPerceivedBrightness(r.diffuseColor),n=t._GetPerceivedBrightness(r.specularColor),i=1-t._GetMaxComponent(r.specularColor),o=t._SolveMetallic(a,n,i),s=r.diffuseColor.scale(i/(1-this._dielectricSpecular.r)/Math.max(1-o,this._epsilon)),l=r.specularColor.subtract(this._dielectricSpecular.scale(1-o)).scale(1/Math.max(o,this._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._GetPerceivedBrightness=function(e){return e?Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b):0},t._GetMaxComponent=function(e){return e?Math.max(e.r,Math.max(e.g,e.b)):0},t._ConvertMetalRoughFactorsToMetallicRoughnessAsync=function(e,r,a,n,i,o,s,l){var u=this._GetAlphaMode(e),c="OPAQUE"!==u,f=[],h={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};if(l){if(e.albedoTexture){var d=t._ExportTextureAsync(e.albedoTexture,r,a,n,i,s,c).then((function(e){e&&(o.baseColorTexture=e)}));f.push(d)}if(e.metallicTexture){var d=t._ExportTextureAsync(e.metallicTexture,r,a,n,i,s,c).then((function(e){e&&(o.metallicRoughnessTexture=e)}));f.push(d)}}return Promise.all(f).then((function(){return h}))},t._GetGLTFTextureSampler=function(r){var a=t._GetGLTFTextureWrapModesSampler(r),n=r instanceof e.Texture?r.samplingMode:null;if(null!=n)switch(n){case e.Texture.LINEAR_LINEAR:a.magFilter=9729,a.minFilter=9729;break;case e.Texture.LINEAR_NEAREST:a.magFilter=9729,a.minFilter=9728;break;case e.Texture.NEAREST_LINEAR:a.magFilter=9728,a.minFilter=9729;break;case e.Texture.NEAREST_LINEAR_MIPLINEAR:a.magFilter=9728,a.minFilter=9987;break;case e.Texture.NEAREST_NEAREST:a.magFilter=9728,a.minFilter=9728;break;case e.Texture.NEAREST_LINEAR_MIPNEAREST:a.magFilter=9728,a.minFilter=9985;break;case e.Texture.LINEAR_NEAREST_MIPNEAREST:a.magFilter=9729,a.minFilter=9984;break;case e.Texture.LINEAR_NEAREST_MIPLINEAR:a.magFilter=9729,a.minFilter=9986;break;case e.Texture.NEAREST_NEAREST_MIPLINEAR:a.magFilter=9728,a.minFilter=9986;break;case e.Texture.LINEAR_LINEAR_MIPLINEAR:a.magFilter=9729,a.minFilter=9987;break;case e.Texture.LINEAR_LINEAR_MIPNEAREST:a.magFilter=9729,a.minFilter=9985;break;case e.Texture.NEAREST_NEAREST_MIPNEAREST:a.magFilter=9728,a.minFilter=9984}return a},t._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._GetGLTFTextureWrapModesSampler=function(r){var a=t._GetGLTFTextureWrapMode(r instanceof e.Texture?r.wrapU:e.Texture.WRAP_ADDRESSMODE),n=t._GetGLTFTextureWrapMode(r instanceof e.Texture?r.wrapV:e.Texture.WRAP_ADDRESSMODE);return 10497===a&&10497===n?{}:{wrapS:a,wrapT:n}},t._ConvertSpecGlossFactorsToMetallicRoughness=function(r,a,n,i,o,s,l,u){var c={diffuseColor:r.albedoColor||e.Color3.White(),specularColor:r.reflectivityColor||e.Color3.White(),glossiness:r.microSurface||1},f=null,h=this._GetGLTFTextureSampler(r.albedoTexture);if(null!=h.magFilter&&null!=h.minFilter&&null!=h.wrapS&&null!=h.wrapT&&(o.push(h),f=o.length-1),r.reflectivityTexture&&!r.useMicroSurfaceFromReflectivityMapAlpha)return e.Tools.Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported"),null;var d=this._ConvertSpecularGlossinessTexturesToMetallicRoughness(r.albedoTexture,r.reflectivityTexture,c,a);if(d&&u){if(d.baseColorTextureBase64){var m=t._GetTextureInfoFromBase64(d.baseColorTextureBase64,"bjsBaseColorTexture_"+i.length+".png",a,n,i,r.albedoTexture?r.albedoTexture.coordinatesIndex:null,f,l);null!=m&&(s.baseColorTexture=m)}if(d.metallicRoughnessTextureBase64){var p=t._GetTextureInfoFromBase64(d.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+i.length+".png",a,n,i,r.reflectivityTexture?r.reflectivityTexture.coordinatesIndex:null,f,l);null!=p&&(s.metallicRoughnessTexture=p)}return d}return this._ConvertSpecularGlossinessToMetallicRoughness(c)},t._ConvertPBRMaterialAsync=function(e,r,a,n,i,o,s,l){var u={},c={name:e.name};if(e.isMetallicWorkflow())return e.albedoColor&&(u.baseColorFactor=[e.albedoColor.r,e.albedoColor.g,e.albedoColor.b,e.alpha]),this._ConvertMetalRoughFactorsToMetallicRoughnessAsync(e,r,a,n,i,u,s,l).then((function(f){return t.SetMetallicRoughnessPbrMaterial(f,e,c,u,r,a,n,i,o,s,l)}));var f=this._ConvertSpecGlossFactorsToMetallicRoughness(e,r,a,n,i,u,s,l);return t.SetMetallicRoughnessPbrMaterial(f,e,c,u,r,a,n,i,o,s,l)},t.SetMetallicRoughnessPbrMaterial=function(r,a,n,i,o,s,l,u,c,f,h){var d=[];if(r){var m=null,p=!1;if(null!=a.transparencyMode&&(m=t._GetAlphaMode(a))&&"OPAQUE"!==m&&(p=!0,n.alphaMode=m,"MASK"===m&&(n.alphaCutoff=a.alphaCutOff)),this.FuzzyEquals(r.baseColor,e.Color3.White(),this._epsilon)&&a.alpha>=this._epsilon||(i.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,a.alpha]),null!=r.metallic&&1!==r.metallic&&(i.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(i.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."),n.doubleSided=!0),h){if(a.bumpTexture){var g=t._ExportTextureAsync(a.bumpTexture,o,s,l,u,f,p).then((function(e){e&&(n.normalTexture=e,1!==a.bumpTexture.level&&(n.normalTexture.scale=a.bumpTexture.level))}));d.push(g)}if(a.ambientTexture){var g=t._ExportTextureAsync(a.ambientTexture,o,s,l,u,f,p).then((function(e){if(e){var t={index:e.index};n.occlusionTexture=t,a.ambientTextureStrength&&(t.strength=a.ambientTextureStrength)}}));d.push(g)}if(a.emissiveTexture){var g=t._ExportTextureAsync(a.emissiveTexture,o,s,l,u,f,p).then((function(e){e&&(n.emissiveTexture=e)}));d.push(g)}}this.FuzzyEquals(a.emissiveColor,e.Color3.Black(),this._epsilon)||(n.emissiveFactor=a.emissiveColor.asArray()),n.pbrMetallicRoughness=i,c.push(n)}return Promise.all(d).then((function(e){}))},t.GetPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t._ExportTextureAsync=function(r,a,n,i,o,s,l){for(var u=this,c=t._GetGLTFTextureSampler(r),f=null,h=null,d=0;d<o.length;++d){var m=o[d];if(m.minFilter===c.minFilter&&m.magFilter===c.magFilter&&m.wrapS===c.wrapS&&m.wrapT===c.wrapT){h=d;break}}null==h?(o.push(c),f=o.length-1):f=h;var p="texture_"+(i.length-1).toString(),g=r.getInternalTexture();null!=g&&(p=g.url||p),p=e.Tools.GetFilename(p);var T=p.split(".")[0],y="";if("image/jpeg"===a)y=".jpg";else{if("image/png"!==a)return Promise.reject("Unsupported mime type "+a);y=".png"}return p=T+y,this._SetAlphaToOneAsync(r,l).then((function(e){var o=t.GetPixelsFromTexture(e),l=r.getSize(),c=u._CreateBase64FromCanvas(o,l.width,l.height,a);return u._GetTextureInfoFromBase64(c,p,a,n,i,r.coordinatesIndex,f,s)}))},t._GetTextureInfoFromBase64=function(e,t,r,a,n,i,o,s){var l=null,u={source:a.length,name:t};null!=o&&(u.sampler=o);for(var c=atob(e.split(",")[1]),f=new ArrayBuffer(c.length),h=new Uint8Array(f),d=0,m=c.length;d<m;++d)h[d]=c.charCodeAt(d);var p={data:h,mimeType:r};if(s[t]=p,"image/jpeg"===r||"image/png"===r){for(var g={uri:t},T=null,d=0;d<a.length;++d)if(a[d].uri===t){T=d;break}null==T?(a.push(g),u.source=a.length-1):u.source=T,n.push(u),l={index:n.length-1},null!=i&&(l.texCoord=i)}return l},t._dielectricSpecular=new e.Color3(.04,.04,.04),t._maxSpecularPower=1024,t._epsilon=1e-6,t})();t._GLTFMaterial=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(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,n,i,o,s){var l=[],u=[],c=r.getKeys(),f=a.calculateMinMaxKeyFrames(c),h=a._DeduceInterpolation(c,n,o),d=f.max-f.min,m=h.interpolationType,p=h.shouldBakeAnimation;if(p?a._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,l,u,f,i,o):"LINEAR"===m||"STEP"===m?a._CreateLinearOrStepAnimation(t,r,n,d,l,u,i,o):"CUBICSPLINE"===m?a._CreateCubicSplineAnimation(t,r,n,d,l,u,i,o):a._CreateBakedAnimation(t,r,n,f.min,f.max,r.framePerSecond,s,l,u,f,i,o),l.length&&u.length){return{inputs:l,outputs:u,samplerInterpolation:m,inputsMin:p?f.min:e.Tools.FloatRound(f.min/r.framePerSecond),inputsMax:p?f.max:e.Tools.FloatRound(f.max/r.framePerSecond)}}return null},a._DeduceAnimationInfo=function(t){var r=null,a="VEC3",n=!1,i=t.targetProperty.split(".");switch(i[0]){case"scaling":r="scale";break;case"position":r="translation";break;case"rotation":a="VEC4",r="rotation";break;case"rotationQuaternion":a="VEC4",n=!0,r="rotation";break;default:e.Tools.Error("Unsupported animatable property "+i[0])}return r?{animationChannelTargetPath:r,dataAccessorType:a,useQuaternion:n}:(e.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},a._CreateNodeAnimationFromTransformNodeAnimations=function(e,t,r,n,i,o,s,l,u,c){var f;if(e.animations)for(var h=0,d=e.animations;h<d.length;h++){var m=d[h],p=a._DeduceAnimationInfo(m);p&&(f={name:m.name,samplers:[],channels:[]},a.AddAnimation(""+m.name,m.hasRunningRuntimeAnimations?t:f,e,m,p.dataAccessorType,p.animationChannelTargetPath,n,o,s,l,u,p.useQuaternion,c),f.samplers.length&&f.channels.length&&r.push(f))}},a._CreateNodeAnimationFromAnimationGroups=function(t,r,n,i,o,s,l,u,c){var f;if(t.animationGroups)for(var h=t.animationGroups,d=0,m=h;d<m.length;d++){var p=m[d];f={name:p.name,channels:[],samplers:[]};for(var g=0,T=p.targetedAnimations;g<T.length;g++){var y=T[g],v=y.target,A=y.animation;if(v instanceof e.Mesh||1===v.length&&v[0]instanceof e.Mesh){var x=a._DeduceAnimationInfo(y.animation);if(x){var b=v instanceof e.Mesh?v:v[0];a.AddAnimation(""+A.name,f,b,A,x.dataAccessorType,x.animationChannelTargetPath,n,o,s,l,u,x.useQuaternion,c)}}}f.channels.length&&f.samplers.length&&r.push(f)}},a.AddAnimation=function(e,r,n,i,o,s,l,u,c,f,h,d,m){var p,g,T,y,v,A,x,b=a._CreateNodeAnimation(n,i,s,h,d,m);if(b){var F=l[n.uniqueId],_=4*b.inputs.length;p=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),_,void 0,e+" keyframe data view"),c.push(p),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]),f.push(g),T=f.length-1,v=b.outputs.length,_="VEC3"===o?12*b.outputs.length:16*b.outputs.length,p=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),_,void 0,e+" data view"),c.push(p),b.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=t._GLTFUtilities.CreateAccessor(c.length-1,e+" data",o,5126,v,null,null,null),f.push(g),y=f.length-1,A={interpolation:b.samplerInterpolation,input:T,output:y},r.samplers.push(A),x={sampler:r.samplers.length-1,target:{node:F,path:s}},r.channels.push(x)}},a._CreateBakedAnimation=function(t,r,n,i,o,s,l,u,c,f,h,d){var m,p,g=e.Quaternion.Identity(),T=null,y=null,v=null,A=null,x=null,b=null;f.min=e.Tools.FloatRound(i/s);for(var F=r.getKeys(),_=0,R=F.length;_<R;++_){if(b=null,v=F[_],_+1<R)if(A=F[_+1],v.value.equals(A.value)){if(0!==_)continue;b=v.frame}else b=A.frame;else{if(x=F[_-1],v.value.equals(x.value))continue;b=o}if(b)for(var B=v.frame;B<=b;B+=l)(p=e.Tools.FloatRound(B/s))!==T&&(T=p,y=p,m=r._interpolate(B,0,void 0,r.loopMode),a._SetInterpolatedValue(t,m,p,r,n,g,u,c,h,d))}y&&(f.max=y)},a._ConvertFactorToVector3OrQuaternion=function(t,r,n,i,o,s,l){var u,c,f=null,h=a._GetBasePositionRotationOrScale(r,o,s,l);if(i===e.Animation.ANIMATIONTYPE_FLOAT)switch(u=n.targetProperty.split("."),c=u?u[1]:"",f=l?e.Quaternion.FromArray(h).normalize():e.Vector3.FromArray(h),c){case"x":case"y":f[c]=s&&l&&"scale"!==o?-t:t;break;case"z":f[c]=s&&!l&&"scale"!==o?-t:t;break;case"w":f.w=t;break;default:e.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return f},a._SetInterpolatedValue=function(r,a,n,i,o,s,l,u,c,f){var h,d=i.dataType;l.push(n),"number"==typeof a&&(a=this._ConvertFactorToVector3OrQuaternion(a,r,i,d,o,c,f)),a&&("rotation"===o?(f?s=a:(h=a,e.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,s)),c&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(s),r.parent||(s=e.Quaternion.FromArray([0,1,0,0]).multiply(s))),u.push(s.asArray())):(h=a,c&&"scale"!==o&&(t._GLTFUtilities.GetRightHandedPositionVector3FromRef(h),r.parent||(h.x*=-1,h.z*=-1)),u.push(h.asArray())))},a._CreateLinearOrStepAnimation=function(e,t,r,n,i,o,s,l){for(var u=0,c=t.getKeys();u<c.length;u++){var f=c[u];i.push(f.frame/t.framePerSecond),a._AddKeyframeValue(f,t,o,r,e,s,l)}},a._CreateCubicSplineAnimation=function(e,t,n,i,o,s,l,u){t.getKeys().forEach((function(c){o.push(c.frame/t.framePerSecond),a.AddSplineTangent(e,r.INTANGENT,s,n,"CUBICSPLINE",c,i,u,l),a._AddKeyframeValue(c,t,s,n,e,l,u),a.AddSplineTangent(e,r.OUTTANGENT,s,n,"CUBICSPLINE",c,i,u,l)}))},a._GetBasePositionRotationOrScale=function(r,a,n,i){var o;return"rotation"===a?i?r.rotationQuaternion?(o=r.rotationQuaternion.asArray(),n&&(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(),n&&t._GLTFUtilities.GetRightHandedPositionArray3FromRef(o)):o=r.scaling.asArray(),o},a._AddKeyframeValue=function(r,a,n,i,o,s,l){var u,c,f=a.dataType;if(f===e.Animation.ANIMATIONTYPE_VECTOR3){if(u=r.value.asArray(),"rotation"===i){var h=e.Vector3.FromArray(u),d=e.Quaternion.RotationYawPitchRoll(h.y,h.x,h.z);s&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(d),o.parent||(d=e.Quaternion.FromArray([0,1,0,0]).multiply(d))),u=d.asArray()}else"translation"===i&&s&&(t._GLTFUtilities.GetRightHandedNormalArray3FromRef(u),o.parent||(u[0]*=-1,u[2]*=-1));n.push(u)}else if(f===e.Animation.ANIMATIONTYPE_FLOAT){if(c=this._ConvertFactorToVector3OrQuaternion(r.value,o,a,f,i,s,l)){if("rotation"===i){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))),n.push(m.asArray())}else"translation"===i&&s&&(t._GLTFUtilities.GetRightHandedNormalVector3FromRef(c),o.parent||(c.x*=-1,c.z*=-1));n.push(c.asArray())}}else f===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())),n.push(u)):e.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},a._DeduceInterpolation=function(t,r,a){var n,i,o=!1;if("rotation"===r&&!a)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,l=t.length;s<l;++s)if(i=t[s],i.inTangent||i.outTangent)if(n){if("CUBICSPLINE"!==n){n="LINEAR",o=!0;break}}else n="CUBICSPLINE";else if(n){if("CUBICSPLINE"===n||i.interpolation&&i.interpolation===e.AnimationKeyInterpolation.STEP&&"STEP"!==n){n="LINEAR",o=!0;break}}else n=i.interpolation&&i.interpolation===e.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return n||(n="LINEAR"),{interpolationType:n,shouldBakeAnimation:o}},a.AddSplineTangent=function(a,n,i,o,s,l,u,c,f){var h,d=n===r.INTANGENT?l.inTangent:l.outTangent;if("CUBICSPLINE"===s){if("rotation"===o)if(d){if(c)h=d.scale(u).asArray();else{var m=d.scale(u);h=e.Quaternion.RotationYawPitchRoll(m.y,m.x,m.z).asArray()}f&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(h),a.parent||(h=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(h)).asArray()))}else h=[0,0,0,0];else d?(h=d.scale(u).asArray(),f&&"translation"===o&&(t._GLTFUtilities.GetRightHandedPositionArray3FromRef(h),a.parent||(h[0]*=-1,h[2]*=-1))):h=[0,0,0];i.push(h)}},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={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function t(){}return t.CreateBufferView=function(e,t,r,a,n){var i={buffer:e,byteLength:r};return t&&(i.byteOffset=t),n&&(i.name=n),a&&(i.byteStride=a),i},t.CreateAccessor=function(e,t,r,a,n,i,o,s){var l={name:t,bufferView:e,componentType:a,count:n,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=i&&(l.byteOffset=i),l},t.CalculateMinMaxPositions=function(r,a,n,i){var o,s,l,u=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(n)for(var f=a,h=a+n;f<h;++f){o=3*f,s=e.Vector3.FromArray(r,o),i&&t.GetRightHandedPositionVector3FromRef(s),l=s.asArray();for(var d=0;d<3;++d){var m=l[d];m<u[d]&&(u[d]=m),m>c[d]&&(c[d]=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})();t._GLTFUtilities=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));
|