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 i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLTFAsync(i)}))},t.GLBAsync=function(t,r,a){return t.whenReadyAsync().then((function(){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLBAsync(i)}))},t})();e.GLTF2Export=t})(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.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}return r.prototype.reorderIndicesBasedOnPrimitiveMode=function(t,r,a,i,n){switch(r){case e.Material.TriangleFillMode:i||(i=0);for(var o=t.indexStart,s=t.indexStart+t.indexCount;o<s;o+=3){var l=i+4*o,u=n.getUInt32(l+4),c=n.getUInt32(l+8);n.setUInt32(c,l+4),n.setUInt32(u,l+8)}break;case e.Material.TriangleFanDrawMode:for(var o=t.indexStart+t.indexCount-1,h=t.indexStart;o>=h;--o)n.setUInt32(a[o],i),i+=4;break;case e.Material.TriangleStripDrawMode:t.indexCount>=3&&(n.setUInt32(a[t.indexStart+2],i+4),n.setUInt32(a[t.indexStart+1],i+8))}},r.prototype.reorderVertexAttributeDataBasedOnPrimitiveMode=function(t,r,a,i,n,o,s){if(this.convertToRightHandedSystem&&a===e.Material.ClockWiseSideOrientation)switch(r){case e.Material.TriangleFillMode:this.reorderTriangleFillMode(t,r,a,i,n,o,s);break;case e.Material.TriangleStripDrawMode:this.reorderTriangleStripDrawMode(t,r,a,i,n,o,s);break;case e.Material.TriangleFanDrawMode:this.reorderTriangleFanMode(t,r,a,i,n,o,s)}},r.prototype.reorderTriangleFillMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type);if(t.verticesCount%3!=0)e.Tools.Error("The submesh vertices for the triangle fill mode is not divisible by 3!");else{var c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector3.FromArray(n,h)),c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector4.FromArray(n,h)),c.push(e.Vector4.FromArray(n,h+2*u)),c.push(e.Vector4.FromArray(n,h+u));break;case e.VertexBuffer.ColorKind:for(var d=l.getSize(),f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=d)h=f*u,4===d?(c.push(e.Vector4.FromArray(n,h)),c.push(e.Vector4.FromArray(n,h+2*u)),c.push(e.Vector4.FromArray(n,h+u))):(c.push(e.Vector3.FromArray(n,h)),c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u)));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart;f<t.verticesStart+t.verticesCount;f+=3)h=f*u,c.push(e.Vector2.FromArray(n,h)),c.push(e.Vector2.FromArray(n,h+2*u)),c.push(e.Vector2.FromArray(n,h+u));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o,i,n,s)}}else e.Tools.Warn("reorderTriangleFillMode: Vertex Buffer Kind "+i+" not present!")},r.prototype.reorderTriangleStripDrawMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:h=t.verticesStart,c.push(e.Vector3.FromArray(n,h+2*u)),c.push(e.Vector3.FromArray(n,h+u));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h));break;case e.VertexBuffer.ColorKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,4===l.getSize()?c.push(e.Vector4.FromArray(n,h)):c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector2.FromArray(n,h));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o+12,i,n,s)}else e.Tools.Warn("reorderTriangleStripDrawMode: Vertex buffer kind "+i+" not present!")},r.prototype.reorderTriangleFanMode=function(t,r,a,i,n,o,s){var l=this.getVertexBufferFromMesh(i,t.getMesh());if(l){var u=l.byteStride/e.VertexBuffer.GetTypeByteLength(l.type),c=[],h=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.TangentKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h));break;case e.VertexBuffer.ColorKind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector4.FromArray(n,h)),4===l.getSize()?c.push(e.Vector4.FromArray(n,h)):c.push(e.Vector3.FromArray(n,h));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=t.verticesStart+t.verticesCount-1;f>=t.verticesStart;--f)h=f*u,c.push(e.Vector2.FromArray(n,h));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(c,o,i,n,s)}else e.Tools.Warn("reorderTriangleFanMode: Vertex buffer kind "+i+" not present!")},r.prototype.writeVertexAttributeData=function(r,a,i,n,o){for(var s=0,l=r;s<l.length;s++){var u=l[s];!this.convertToRightHandedSystem||i===e.VertexBuffer.ColorKind||u instanceof e.Vector2||(u instanceof e.Vector3?i===e.VertexBuffer.PositionKind?t._GLTFUtilities.GetRightHandedPositionVector3FromRef(u):t._GLTFUtilities.GetRightHandedNormalVector3FromRef(u):t._GLTFUtilities.GetRightHandedVector4FromRef(u));for(var c=0,h=u.asArray();c<h.length;c++){var f=h[c];o.setFloat32(f,a),a+=4}}},r.prototype.writeAttributeData=function(r,a,i,n){var o,s=i/4,l=[];switch(r){case e.VertexBuffer.PositionKind:for(var u=0,c=a.length/s;u<c;++u){o=u*s;var h=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedPositionVector3FromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.NormalKind:for(var u=0,f=a.length/s;u<f;++u){o=u*s;var h=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedNormalVector3FromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.TangentKind:for(var u=0,d=a.length/s;u<d;++u){o=u*s;var h=e.Vector4.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedVector4FromRef(h),l.push(h.asArray())}break;case e.VertexBuffer.ColorKind:for(var u=0,m=a.length/s;u<m;++u){o=u*s;var h=3===s?e.Vector3.FromArray(a,o):e.Vector4.FromArray(a,o);l.push(h.asArray())}break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var u=0,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];n.setFloat32(x)}},r.prototype.generateJSON=function(e,r,a){var i,n,o,s=this,l={byteLength:this.totalByteLength},u=this.totalByteLength,c={asset:this.asset};return l.byteLength&&(c.buffers=[l]),this.nodes&&this.nodes.length&&(c.nodes=this.nodes),this.meshes&&this.meshes.length&&(c.meshes=this.meshes),this.scenes&&this.scenes.length&&(c.scenes=this.scenes,c.scene=0),this.bufferViews&&this.bufferViews.length&&(c.bufferViews=this.bufferViews),this.accessors&&this.accessors.length&&(c.accessors=this.accessors),this.animations&&this.animations.length&&(c.animations=this.animations),this.materials&&this.materials.length&&(c.materials=this.materials),this.textures&&this.textures.length&&(c.textures=this.textures),this.samplers&&this.samplers.length&&(c.samplers=this.samplers),this.images&&this.images.length&&(e?(c.images=[],this.images.forEach((function(e){e.uri&&(n=s.imageData[e.uri],i=e.uri.split(".")[0]+" image",o=t._GLTFUtilities.CreateBufferView(0,u,n.data.length,void 0,i),u+=n.data.buffer.byteLength,s.bufferViews.push(o),e.bufferView=s.bufferViews.length-1,e.name=i,e.mimeType=n.mimeType,e.uri=void 0,c.images||(c.images=[]),c.images.push(e))})),l.byteLength=u):c.images=this.images),e||(l.uri=r+".bin"),a?JSON.stringify(c,null,2):JSON.stringify(c)},r.prototype._generateGLTFAsync=function(t){var r=this;return this._generateBinaryAsync().then((function(a){var i=r.generateJSON(!1,t,!0),n=new Blob([a],{type:"application/octet-stream"}),o=t+".gltf",s=t+".bin",l=new e.GLTFData;if(l.glTFFiles[o]=i,l.glTFFiles[s]=n,r.imageData)for(var u in r.imageData)l.glTFFiles[u]=new Blob([r.imageData[u].data],{type:r.imageData[u].mimeType});return l}))},r.prototype._generateBinaryAsync=function(){var e=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 i=r.generateJSON(!0),n=t+".glb",o=i.length,s=0;for(var l in r.imageData)s+=r.imageData[l].data.byteLength;var u=r._getPadding(o),c=r._getPadding(a.byteLength),h=r._getPadding(s),f=28+o+u+a.byteLength+c+s+h,d=new ArrayBuffer(12),m=new DataView(d);m.setUint32(0,1179937895,!0),m.setUint32(4,2,!0),m.setUint32(8,f,!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]=i.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+h,!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(h),M=new Uint8Array(_),y=0;y<h;++y)M[y]=0;var R=[d,p,A,a];for(var l in r.imageData)R.push(r.imageData[l].data.buffer);R.push(b),R.push(_);var B=new Blob(R,{type:"application/octet-stream"}),S=new e.GLTFData;return S.glTFFiles[n]=B,S}))},r.prototype.setNodeTransformation=function(r,a){a.position.equalsToFloats(0,0,0)||(r.translation=this.convertToRightHandedSystem?t._GLTFUtilities.GetRightHandedPositionVector3(a.position).asArray():a.position.asArray()),a.scaling.equalsToFloats(1,1,1)||(r.scale=a.scaling.asArray());var i=e.Quaternion.RotationYawPitchRoll(a.rotation.y,a.rotation.x,a.rotation.z);a.rotationQuaternion&&i.multiplyInPlace(a.rotationQuaternion),0===i.x&&0===i.y&&0===i.z&&1===i.w||(this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedQuaternionFromRef(i),r.rotation=i.normalize().asArray())},r.prototype.getVertexBufferFromMesh=function(e,t){if(t.isVerticesDataPresent(e)){var r=t.getVertexBuffer(e);if(r)return r}return null},r.prototype.createBufferViewKind=function(r,a,i,n){var o=a instanceof e.Mesh?a:a instanceof e.InstancedMesh?a.sourceMesh:null;if(o){var s=o.getVerticesData(r);if(s){var l=4*s.length,u=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),l,n,r+" - "+o.name);this.bufferViews.push(u),this.writeAttributeData(r,s,n,i)}}},r.prototype.getMeshPrimitiveMode=function(t){return t instanceof e.LinesMesh?e.Material.LineListDrawMode:t.material?t.material.fillMode:e.Material.TriangleFillMode},r.prototype.setPrimitiveMode=function(t,r){switch(r){case e.Material.TriangleFillMode:break;case e.Material.TriangleStripDrawMode:t.mode=5;break;case e.Material.TriangleFanDrawMode:t.mode=6;break;case e.Material.PointListDrawMode:t.mode=0;case e.Material.PointFillMode:t.mode=0;break;case e.Material.LineLoopDrawMode:t.mode=2;break;case e.Material.LineListDrawMode:t.mode=1;break;case e.Material.LineStripDrawMode:t.mode=3}},r.prototype.setAttributeKind=function(t,r){switch(r){case e.VertexBuffer.PositionKind:t.attributes.POSITION=this.accessors.length-1;break;case e.VertexBuffer.NormalKind:t.attributes.NORMAL=this.accessors.length-1;break;case e.VertexBuffer.ColorKind:t.attributes.COLOR_0=this.accessors.length-1;break;case e.VertexBuffer.TangentKind:t.attributes.TANGENT=this.accessors.length-1;break;case e.VertexBuffer.UVKind:t.attributes.TEXCOORD_0=this.accessors.length-1;break;case e.VertexBuffer.UV2Kind:t.attributes.TEXCOORD_1=this.accessors.length-1;break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+r)}},r.prototype.setPrimitiveAttributes=function(r,a,i){var n,o,s,l=null;a instanceof e.Mesh?l=a:a instanceof e.InstancedMesh&&(l=a.sourceMesh);var u=[{kind:e.VertexBuffer.PositionKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.NormalKind,accessorType:"VEC3",byteStride:12},{kind:e.VertexBuffer.ColorKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.TangentKind,accessorType:"VEC4",byteStride:16},{kind:e.VertexBuffer.UVKind,accessorType:"VEC2",byteStride:8},{kind:e.VertexBuffer.UV2Kind,accessorType:"VEC2",byteStride:8}];if(l){for(var c=null,h=this.getMeshPrimitiveMode(l),f={},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,i,p.byteStride),p.bufferViewIndex=this.bufferViews.length-1,f[g]=p.bufferViewIndex}}if(l.getTotalIndices()){var y=l.getIndices();if(y){var v=4*y.length;n=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),v,void 0,"Indices - "+l.name),this.bufferViews.push(n),c=this.bufferViews.length-1;for(var A=0,x=y.length;A<x;++A)i.setUInt32(y[A])}}if(l.subMeshes)for(var b=0,F=l.subMeshes;b<F.length;b++){var _=F[b];o=!1;var M=_.getMaterial(),R=null;if(M)if(l instanceof e.LinesMesh){var B={name:l.name+" material"};(!l.color.equals(e.Color3.White())||l.alpha<1)&&(B.pbrMetallicRoughness={baseColorFactor:l.color.asArray().concat([l.alpha])}),this.materials.push(B),R=this.materials.length-1}else M instanceof e.MultiMaterial?(M=M.subMaterials[_.materialIndex])&&(R=this.materialMap[M.uniqueId]):R=this.materialMap[M.uniqueId];var S=null!=R?this.materials[R]:null,C={attributes:{}};this.setPrimitiveMode(C,h);for(var V=0,E=u;V<E.length;V++){var p=E[V],g=p.kind;if(g!==e.VertexBuffer.UVKind&&g!==e.VertexBuffer.UV2Kind||!S||t._GLTFMaterial._HasTexturesPresent(S)){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(null!=R&&Object.keys(C.attributes).length>0){var N=this.babylonScene.materials[R].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(_,h,U,I,i);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[f[p.kind]].byteOffset;D||(D=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(_,h,N,p.kind,L,D,i)}}}if(!o&&t._GLTFMaterial._HasTexturesPresent(this.materials[R])){var K=t._GLTFMaterial._StripTexturesFromMaterial(this.materials[R]);this.materials.push(K),R=this.materials.length-1}C.material=R}r.primitives.push(C)}}},r.prototype.createSceneAsync=function(r,a){var i,n,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.materialMap,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 h=c[t];if(null!=(i=s.nodeMap[h.uniqueId])&&(n=s.nodes[i],h.parent||(s.shouldExportTransformNode(h)?(s.convertToRightHandedSystem&&(n.translation&&(n.translation[2]*=-1,n.translation[0]*=-1),n.rotation=n.rotation?e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(n.rotation)).asArray():e.Quaternion.FromArray([0,1,0,0]).asArray()),l.nodes.push(i)):e.Tools.Log("Omitting "+h.name+" from scene.")),o=h.getDescendants(!0),!n.children&&o&&o.length)){n.children=[];for(var f=0,d=o;f<d.length;f++){var m=d[f];null!=s.nodeMap[m.uniqueId]&&n.children.push(s.nodeMap[m.uniqueId])}}}l.nodes.length&&s.scenes.push(l)}))},r.prototype.createNodeMapAndAnimations=function(e,r,a,i){for(var n,o,s=this,l={},u={name:"runtime animations",channels:[],samplers:[]},c=[],h=0,f=r;h<f.length;h++){var d=f[h];a(d)?(o=this.createNode(d,i),this.nodes.push(o),n=this.nodes.length-1,l[d.uniqueId]=n,!e.animationGroups.length&&d.animations.length&&t._GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations(d,u,c,l,this.nodes,i,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,i,this.bufferViews,this.accessors,this.convertToRightHandedSystem,this.animationSampleRate),l},r.prototype.createNode=function(e,t){var r={},a={primitives:[]};return e.name&&(r.name=e.name),this.setNodeTransformation(r,e),this.setPrimitiveAttributes(a,e,t),a.primitives.length&&(this.meshes.push(a),r.mesh=this.meshes.length-1),r},r})();t._Exporter=r;var a=(function(){function t(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return t.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),a=new Uint8Array(t),i=0,n=a.byteLength;i<n;++i)a[i]=r[i];this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer)},t.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset()),this._arrayBuffer},t.prototype.getByteOffset=function(){return this._byteOffset},t.prototype.setUInt8=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint8(r,t):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,t))},t.prototype.getUInt32=function(t){if(t<this._byteOffset)return this._dataView.getUint32(t,!0);throw e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},t.prototype.getVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0))},t.prototype.setVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0))},t.prototype.getVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0),t.w=this._dataView.getFloat32(r+12,!0))},t.prototype.setVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0),this._dataView.setFloat32(r+12,t.w,!0))},t.prototype.setFloat32=function(t,r){isNaN(t)&&e.Tools.Error("Invalid data being written!"),null!=r&&(r<this._byteOffset?this._dataView.setFloat32(r,t,!0):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,t,!0),this._byteOffset+=4},t.prototype.setUInt32=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint32(r,t,!0):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,t,!0),this._byteOffset+=4)},t})();t._BinaryWriter=a})(e.GLTF2||(e.GLTF2={}))})(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],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([a],i)),r.click()}},e})();e.GLTFData=t})(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,i,n,o,s,l,u,c){for(var h=[],f=0,d=r;f<d.length;f++){var m=d[f];m instanceof e.StandardMaterial?h.push(t._ConvertStandardMaterialAsync(m,a,i,n,o,s,l,u,c)):m instanceof e.PBRMetallicRoughnessMaterial?h.push(t._ConvertPBRMetallicRoughnessMaterialAsync(m,a,i,n,o,s,l,u,c)):m instanceof e.PBRMaterial?h.push(t._ConvertPBRMaterialAsync(m,a,i,n,o,s,l,u,c)):e.Tools.Warn("Unsupported material type: "+m.name)}return Promise.all(h).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,i){return(1-e)*(1-e)*(1-e)*t+3*(1-e)*(1-e)*e*r+3*(1-e)*e*e*a+e*e*e*i}var a=new e.Vector2(0,1),i=new e.Vector2(0,.1),n=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,i.y,n.y,o.y)})(u);return{baseColorFactor:[s.r,s.g,s.b,l],metallicFactor:0,roughnessFactor:c}},t._SolveMetallic=function(r,a,i){if(a<t._dielectricSpecular.r)return t._dielectricSpecular,0;var n=t._dielectricSpecular.r,o=r*i/(1-t._dielectricSpecular.r)+a-2*t._dielectricSpecular.r,s=t._dielectricSpecular.r-a,l=o*o-4*n*s;return e.Scalar.Clamp((-o+Math.sqrt(l))/(2*n),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 i=t;switch(i.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 "+i.transparencyMode),null}}},t._ConvertStandardMaterialAsync=function(r,a,i,n,o,s,l,u,c){var h=this._GetAlphaMode(r),f="OPAQUE"!==h,d=[],m=t._ConvertToGLTFPBRMetallicRoughness(r),p={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."),p.doubleSided=!0),c){if(r.diffuseTexture){var g=t._ExportTextureAsync(r.diffuseTexture,a,i,n,o,u,f).then((function(e){e&&(m.baseColorTexture=e)}));d.push(g)}if(r.bumpTexture){var g=t._ExportTextureAsync(r.bumpTexture,a,i,n,o,u,f).then((function(e){e&&(p.normalTexture=e,null!=r.bumpTexture&&1!==r.bumpTexture.level&&(p.normalTexture.scale=r.bumpTexture.level))}));d.push(g)}if(r.emissiveTexture){var g=t._ExportTextureAsync(r.emissiveTexture,a,i,n,o,u,f).then((function(e){e&&(p.emissiveTexture=e),p.emissiveFactor=[1,1,1]}));d.push(g)}if(r.ambientTexture){var g=t._ExportTextureAsync(r.ambientTexture,a,i,n,o,u,f).then((function(e){if(e){var t={index:e.index};p.occlusionTexture=t,t.strength=1}}));d.push(g)}}if((r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?p.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)&&(p.emissiveFactor=r.emissiveColor.asArray()),p.pbrMetallicRoughness=m,"OPAQUE"!==h)switch(h){case"BLEND":p.alphaMode="BLEND";break;case"MASK":p.alphaMode="MASK",p.alphaCutoff=r.alphaCutOff;break;default:e.Tools.Warn("Unsupported alpha mode "+h)}return s.push(p),l[r.uniqueId]=s.length-1,Promise.all(d).then((function(){}))},t._SetAlphaToOneAsync=function(t,r){return new Promise(function(a,i){if(r)a(t);else{var n=t.getScene();if(n){var o=new e.ProceduralTexture("texture",t.getSize(),"setAlphaToOne",n);o?(o.setTexture("textureSampler",t),o.onLoadObservable.add((function(){a(o)}))):i("Cannot create procedural texture for "+t.name+"!")}else i("Scene not available for texture "+t.name)}})},t._ConvertPBRMetallicRoughnessMaterialAsync=function(r,a,i,n,o,s,l,u,c){var h=[],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 d={name:r.name};r.doubleSided&&(d.doubleSided=r.doubleSided);var m=null,p=!1;if(null!=r.transparencyMode&&(m=t._GetAlphaMode(r))&&"OPAQUE"!==m&&(d.alphaMode=m,"MASK"===m&&(d.alphaCutoff=r.alphaCutOff)),"OPAQUE"!==m&&(p=!0),c){if(null!=r.baseTexture){var g=t._ExportTextureAsync(r.baseTexture,a,i,n,o,u,p).then((function(e){e&&(f.baseColorTexture=e)}));h.push(g)}if(r.normalTexture){var g=t._ExportTextureAsync(r.normalTexture,a,i,n,o,u,p).then((function(e){e&&(d.normalTexture=e,1!==r.normalTexture.level&&(d.normalTexture.scale=r.normalTexture.level))}));h.push(g)}if(r.occlusionTexture){var g=t._ExportTextureAsync(r.occlusionTexture,a,i,n,o,u,p).then((function(e){e&&(d.occlusionTexture=e,null!=r.occlusionStrength&&(d.occlusionTexture.strength=r.occlusionStrength))}));h.push(g)}if(r.emissiveTexture){var g=t._ExportTextureAsync(r.emissiveTexture,a,i,n,o,u,p).then((function(e){e&&(d.emissiveTexture=e)}));h.push(g)}}return this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(d.emissiveFactor=r.emissiveColor.asArray()),d.pbrMetallicRoughness=f,s.push(d),l[r.uniqueId]=s.length-1,Promise.all(h).then((function(){}))},t._CreateBase64FromCanvas=function(e,t,r,a){var i=document.createElement("canvas");i.width=t,i.height=r,i.id="WriteCanvas";var n=i.getContext("2d"),o=n.createImageData(t,r);return o.data.set(e),n.putImageData(o,0,0),i.toDataURL(a)},t._CreateWhiteTexture=function(t,r,a){for(var i=new Uint8Array(t*r*4),n=0;n<i.length;n+=4)i[n]=i[n+1]=i[n+2]=i[n+3]=255;return e.RawTexture.CreateRGBATexture(i,t,r,a)},t._ResizeTexturesToSameDimensions=function(t,r,a){var i,n,o=t?t.getSize():{width:0,height:0},s=r?r.getSize():{width:0,height:0};return o.width<s.width?(i=t?e.TextureTools.CreateResizedCopy(t,s.width,s.height,!0):this._CreateWhiteTexture(s.width,s.height,a),n=r):o.width>s.width?(n=r?e.TextureTools.CreateResizedCopy(r,o.width,o.height,!0):this._CreateWhiteTexture(o.width,o.height,a),i=t):(i=t,n=r),{texture1:i,texture2:n}},t._ConvertSpecularGlossinessTexturesToMetallicRoughness=function(t,r,a,i){if(!t&&!r)return e.Tools.Warn("_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!"),null;var n=t?t.getScene():r?r.getScene():null;if(n){var o=this._ResizeTexturesToSameDimensions(t,r,n),s=o.texture1.getSize(),l=void 0,u=void 0,c=s.width,h=s.height,f=o.texture1.readPixels();if(f instanceof Uint8Array){if(l=o.texture1.readPixels(),(f=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<h;++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,M={diffuseColor:b,specularColor:F,glossiness:_},R=this._ConvertSpecularGlossinessToMetallicRoughness(M);g.r=Math.max(g.r,R.baseColor.r),g.g=Math.max(g.g,R.baseColor.g),g.b=Math.max(g.b,R.baseColor.b),T=Math.max(T,R.metallic),y=Math.max(y,R.roughness),p[x]=255*R.baseColor.r,p[x+1]=255*R.baseColor.g,p[x+2]=255*R.baseColor.b,p[x+3]=o.texture1.hasAlpha?l[x+3]:255,m[x]=0,m[x+1]=255*R.roughness,m[x+2]=255*R.metallic,m[x+3]=255}for(var B={baseColor:g,metallic:T,roughness:y},S=!1,C=!1,v=0;v<h;++v)for(var A=0;A<c;++A){var V=4*(c*v+A);p[V]/=B.baseColor.r>this._epsilon?B.baseColor.r:1,p[V+1]/=B.baseColor.g>this._epsilon?B.baseColor.g:1,p[V+2]/=B.baseColor.b>this._epsilon?B.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]/=B.roughness>this._epsilon?B.roughness:1,m[V+2]/=B.metallic>this._epsilon?B.metallic:1;var w=e.Color3.FromInts(255,m[V+1],m[V+2]);this.FuzzyEquals(w,e.Color3.White(),this._epsilon)||(S=!0)}if(S){var G=this._CreateBase64FromCanvas(m,c,h,i);B.metallicRoughnessTextureBase64=G}if(C){var P=this._CreateBase64FromCanvas(p,c,h,i);B.baseColorTextureBase64=P}return B}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),i=t._GetPerceivedBrightness(r.specularColor),n=1-t._GetMaxComponent(r.specularColor),o=t._SolveMetallic(a,i,n),s=r.diffuseColor.scale(n/(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,i,n,o,s,l){var u=this._GetAlphaMode(e),c="OPAQUE"!==u,h=[],f={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};if(l){if(e.albedoTexture){var d=t._ExportTextureAsync(e.albedoTexture,r,a,i,n,s,c).then((function(e){e&&(o.baseColorTexture=e)}));h.push(d)}if(e.metallicTexture){var d=t._ExportTextureAsync(e.metallicTexture,r,a,i,n,s,c).then((function(e){e&&(o.metallicRoughnessTexture=e)}));h.push(d)}}return Promise.all(h).then((function(){return f}))},t._GetGLTFTextureSampler=function(r){var a=t._GetGLTFTextureWrapModesSampler(r),i=r instanceof e.Texture?r.samplingMode:null;if(null!=i)switch(i){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),i=t._GetGLTFTextureWrapMode(r instanceof e.Texture?r.wrapV:e.Texture.WRAP_ADDRESSMODE);return 10497===a&&10497===i?{}:{wrapS:a,wrapT:i}},t._ConvertSpecGlossFactorsToMetallicRoughness=function(r,a,i,n,o,s,l,u){var c={diffuseColor:r.albedoColor||e.Color3.White(),specularColor:r.reflectivityColor||e.Color3.White(),glossiness:r.microSurface||1},h=null,f=this._GetGLTFTextureSampler(r.albedoTexture);if(null!=f.magFilter&&null!=f.minFilter&&null!=f.wrapS&&null!=f.wrapT&&(o.push(f),h=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_"+n.length+".png",a,i,n,r.albedoTexture?r.albedoTexture.coordinatesIndex:null,h,l);null!=m&&(s.baseColorTexture=m)}if(d.metallicRoughnessTextureBase64){var p=t._GetTextureInfoFromBase64(d.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+n.length+".png",a,i,n,r.reflectivityTexture?r.reflectivityTexture.coordinatesIndex:null,h,l);null!=p&&(s.metallicRoughnessTexture=p)}return d}return this._ConvertSpecularGlossinessToMetallicRoughness(c)},t._ConvertPBRMaterialAsync=function(e,r,a,i,n,o,s,l,u){var c={},h={name:e.name};if(e.isMetallicWorkflow())return e.albedoColor&&(c.baseColorFactor=[e.albedoColor.r,e.albedoColor.g,e.albedoColor.b,e.alpha]),this._ConvertMetalRoughFactorsToMetallicRoughnessAsync(e,r,a,i,n,c,l,u).then((function(f){return t.SetMetallicRoughnessPbrMaterial(f,e,h,c,r,a,i,n,o,s,l,u)}));var f=this._ConvertSpecGlossFactorsToMetallicRoughness(e,r,a,i,n,c,l,u);return t.SetMetallicRoughnessPbrMaterial(f,e,h,c,r,a,i,n,o,s,l,u)},t.SetMetallicRoughnessPbrMaterial=function(r,a,i,n,o,s,l,u,c,h,f,d){var m=[];if(r){var p=null,g=!1;if(null!=a.transparencyMode&&(p=t._GetAlphaMode(a))&&"OPAQUE"!==p&&(g=!0,i.alphaMode=p,"MASK"===p&&(i.alphaCutoff=a.alphaCutOff)),this.FuzzyEquals(r.baseColor,e.Color3.White(),this._epsilon)&&a.alpha>=this._epsilon||(n.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,a.alpha]),null!=r.metallic&&1!==r.metallic&&(n.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(n.roughnessFactor=r.roughness),null==a.backFaceCulling||a.backFaceCulling||(a.twoSidedLighting||e.Tools.Warn(a.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),i.doubleSided=!0),d){if(a.bumpTexture){var T=t._ExportTextureAsync(a.bumpTexture,o,s,l,u,f,g).then((function(e){e&&(i.normalTexture=e,1!==a.bumpTexture.level&&(i.normalTexture.scale=a.bumpTexture.level))}));m.push(T)}if(a.ambientTexture){var T=t._ExportTextureAsync(a.ambientTexture,o,s,l,u,f,g).then((function(e){if(e){var t={index:e.index};i.occlusionTexture=t,a.ambientTextureStrength&&(t.strength=a.ambientTextureStrength)}}));m.push(T)}if(a.emissiveTexture){var T=t._ExportTextureAsync(a.emissiveTexture,o,s,l,u,f,g).then((function(e){e&&(i.emissiveTexture=e)}));m.push(T)}}this.FuzzyEquals(a.emissiveColor,e.Color3.Black(),this._epsilon)||(i.emissiveFactor=a.emissiveColor.asArray()),i.pbrMetallicRoughness=n,c.push(i),h[a.uniqueId]=c.length-1}return Promise.all(m).then((function(e){}))},t.GetPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t._ExportTextureAsync=function(r,a,i,n,o,s,l){for(var u=this,c=t._GetGLTFTextureSampler(r),h=null,f=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){f=d;break}}null==f?(o.push(c),h=o.length-1):h=f;var p=e.Tools.RandomId(),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,i,n,r.coordinatesIndex,h,s)}))},t._GetTextureInfoFromBase64=function(e,t,r,a,i,n,o,s){var l=null,u={source:a.length,name:t};null!=o&&(u.sampler=o);for(var c=atob(e.split(",")[1]),h=new ArrayBuffer(c.length),f=new Uint8Array(h),d=0,m=c.length;d<m;++d)f[d]=c.charCodeAt(d);var p={data:f,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,i.push(u),l={index:i.length-1},null!=n&&(l.texCoord=n)}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,i,n,o,s){var l=[],u=[],c=r.getKeys(),h=a.calculateMinMaxKeyFrames(c),f=a._DeduceInterpolation(c,i,o),d=h.max-h.min,m=f.interpolationType,p=f.shouldBakeAnimation;if(p?a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o):"LINEAR"===m||"STEP"===m?a._CreateLinearOrStepAnimation(t,r,i,d,l,u,n,o):"CUBICSPLINE"===m?a._CreateCubicSplineAnimation(t,r,i,d,l,u,n,o):a._CreateBakedAnimation(t,r,i,h.min,h.max,r.framePerSecond,s,l,u,h,n,o),l.length&&u.length){return{inputs:l,outputs:u,samplerInterpolation:m,inputsMin:p?h.min:e.Tools.FloatRound(h.min/r.framePerSecond),inputsMax:p?h.max:e.Tools.FloatRound(h.max/r.framePerSecond)}}return null},a._DeduceAnimationInfo=function(t){var r=null,a="VEC3",i=!1,n=t.targetProperty.split(".");switch(n[0]){case"scaling":r="scale";break;case"position":r="translation";break;case"rotation":a="VEC4",r="rotation";break;case"rotationQuaternion":a="VEC4",i=!0,r="rotation";break;default:e.Tools.Error("Unsupported animatable property "+n[0])}return r?{animationChannelTargetPath:r,dataAccessorType:a,useQuaternion:i}:(e.Tools.Error("animation channel target path and data accessor type could be deduced"),null)},a._CreateNodeAnimationFromTransformNodeAnimations=function(e,t,r,i,n,o,s,l,u,c){var h;if(e.animations)for(var f=0,d=e.animations;f<d.length;f++){var m=d[f],p=a._DeduceAnimationInfo(m);p&&(h={name:m.name,samplers:[],channels:[]},a.AddAnimation(""+m.name,m.hasRunningRuntimeAnimations?t:h,e,m,p.dataAccessorType,p.animationChannelTargetPath,i,o,s,l,u,p.useQuaternion,c),h.samplers.length&&h.channels.length&&r.push(h))}},a._CreateNodeAnimationFromAnimationGroups=function(t,r,i,n,o,s,l,u,c){var h;if(t.animationGroups)for(var f=t.animationGroups,d=0,m=f;d<m.length;d++){var p=m[d];h={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,h,b,A,x.dataAccessorType,x.animationChannelTargetPath,i,o,s,l,u,x.useQuaternion,c)}}}h.channels.length&&h.samplers.length&&r.push(h)}},a.AddAnimation=function(e,r,i,n,o,s,l,u,c,h,f,d,m){var p,g,T,y,v,A,x,b=a._CreateNodeAnimation(i,n,s,f,d,m);if(b){var F=l[i.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]),h.push(g),T=h.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),h.push(g),y=h.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,i,n,o,s,l,u,c,h,f,d){var m,p,g=e.Quaternion.Identity(),T=null,y=null,v=null,A=null,x=null,b=null;h.min=e.Tools.FloatRound(n/s);for(var F=r.getKeys(),_=0,M=F.length;_<M;++_){if(b=null,v=F[_],_+1<M)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 R=v.frame;R<=b;R+=l)(p=e.Tools.FloatRound(R/s))!==T&&(T=p,y=p,m=r._interpolate(R,0,void 0,r.loopMode),a._SetInterpolatedValue(t,m,p,r,i,g,u,c,f,d))}y&&(h.max=y)},a._ConvertFactorToVector3OrQuaternion=function(t,r,i,n,o,s,l){var u,c,h=null,f=a._GetBasePositionRotationOrScale(r,o,s,l);if(n===e.Animation.ANIMATIONTYPE_FLOAT)switch(u=i.targetProperty.split("."),c=u?u[1]:"",h=l?e.Quaternion.FromArray(f).normalize():e.Vector3.FromArray(f),c){case"x":case"y":h[c]=s&&l&&"scale"!==o?-t:t;break;case"z":h[c]=s&&!l&&"scale"!==o?-t:t;break;case"w":h.w=t;break;default:e.Tools.Error('glTFAnimation: Unsupported component type "'+c+'" for scale animation!')}return h},a._SetInterpolatedValue=function(r,a,i,n,o,s,l,u,c,h){var f,d=n.dataType;l.push(i),"number"==typeof a&&(a=this._ConvertFactorToVector3OrQuaternion(a,r,n,d,o,c,h)),a&&("rotation"===o?(h?s=a:(f=a,e.Quaternion.RotationYawPitchRollToRef(f.y,f.x,f.z,s)),c&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(s),r.parent||(s=e.Quaternion.FromArray([0,1,0,0]).multiply(s))),u.push(s.asArray())):(f=a,c&&"scale"!==o&&(t._GLTFUtilities.GetRightHandedPositionVector3FromRef(f),r.parent||(f.x*=-1,f.z*=-1)),u.push(f.asArray())))},a._CreateLinearOrStepAnimation=function(e,t,r,i,n,o,s,l){for(var u=0,c=t.getKeys();u<c.length;u++){var h=c[u];n.push(h.frame/t.framePerSecond),a._AddKeyframeValue(h,t,o,r,e,s,l)}},a._CreateCubicSplineAnimation=function(e,t,i,n,o,s,l,u){t.getKeys().forEach((function(c){o.push(c.frame/t.framePerSecond),a.AddSplineTangent(e,r.INTANGENT,s,i,"CUBICSPLINE",c,n,u,l),a._AddKeyframeValue(c,t,s,i,e,l,u),a.AddSplineTangent(e,r.OUTTANGENT,s,i,"CUBICSPLINE",c,n,u,l)}))},a._GetBasePositionRotationOrScale=function(r,a,i,n){var o;return"rotation"===a?n?r.rotationQuaternion?(o=r.rotationQuaternion.asArray(),i&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(o),r.parent||(o=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(o)).asArray()))):o=e.Quaternion.Identity().asArray():(o=r.rotation.asArray(),t._GLTFUtilities.GetRightHandedNormalArray3FromRef(o)):"translation"===a?(o=r.position.asArray(),i&&t._GLTFUtilities.GetRightHandedPositionArray3FromRef(o)):o=r.scaling.asArray(),o},a._AddKeyframeValue=function(r,a,i,n,o,s,l){var u,c,h=a.dataType;if(h===e.Animation.ANIMATIONTYPE_VECTOR3){if(u=r.value.asArray(),"rotation"===n){var f=e.Vector3.FromArray(u),d=e.Quaternion.RotationYawPitchRoll(f.y,f.x,f.z);s&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(d),o.parent||(d=e.Quaternion.FromArray([0,1,0,0]).multiply(d))),u=d.asArray()}else"translation"===n&&s&&(t._GLTFUtilities.GetRightHandedNormalArray3FromRef(u),o.parent||(u[0]*=-1,u[2]*=-1));i.push(u)}else if(h===e.Animation.ANIMATIONTYPE_FLOAT){if(c=this._ConvertFactorToVector3OrQuaternion(r.value,o,a,h,n,s,l)){if("rotation"===n){var m=l?c:e.Quaternion.RotationYawPitchRoll(c.y,c.x,c.z).normalize();s&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(m),o.parent||(m=e.Quaternion.FromArray([0,1,0,0]).multiply(m))),i.push(m.asArray())}else"translation"===n&&s&&(t._GLTFUtilities.GetRightHandedNormalVector3FromRef(c),o.parent||(c.x*=-1,c.z*=-1));i.push(c.asArray())}}else h===e.Animation.ANIMATIONTYPE_QUATERNION?(u=r.value.normalize().asArray(),s&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(u),o.parent||(u=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(u)).asArray())),i.push(u)):e.Tools.Error("glTFAnimation: Unsupported key frame values for animation!")},a._DeduceInterpolation=function(t,r,a){var i,n,o=!1;if("rotation"===r&&!a)return{interpolationType:"LINEAR",shouldBakeAnimation:!0};for(var s=0,l=t.length;s<l;++s)if(n=t[s],n.inTangent||n.outTangent)if(i){if("CUBICSPLINE"!==i){i="LINEAR",o=!0;break}}else i="CUBICSPLINE";else if(i){if("CUBICSPLINE"===i||n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP&&"STEP"!==i){i="LINEAR",o=!0;break}}else i=n.interpolation&&n.interpolation===e.AnimationKeyInterpolation.STEP?"STEP":"LINEAR";return i||(i="LINEAR"),{interpolationType:i,shouldBakeAnimation:o}},a.AddSplineTangent=function(a,i,n,o,s,l,u,c,h){var f,d=i===r.INTANGENT?l.inTangent:l.outTangent;if("CUBICSPLINE"===s){if("rotation"===o)if(d){if(c)f=d.scale(u).asArray();else{var m=d.scale(u);f=e.Quaternion.RotationYawPitchRoll(m.y,m.x,m.z).asArray()}h&&(t._GLTFUtilities.GetRightHandedQuaternionArrayFromRef(f),a.parent||(f=e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(f)).asArray()))}else f=[0,0,0,0];else d?(f=d.scale(u).asArray(),h&&"translation"===o&&(t._GLTFUtilities.GetRightHandedPositionArray3FromRef(f),a.parent||(f[0]*=-1,f[2]*=-1))):f=[0,0,0];n.push(f)}},a.calculateMinMaxKeyFrames=function(e){var t=1/0,r=-1/0;return e.forEach((function(e){t=Math.min(t,e.frame),r=Math.max(r,e.frame)})),{min:t,max:r}},a})();t._GLTFAnimation=a})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function t(){}return t.CreateBufferView=function(e,t,r,a,i){var n={buffer:e,byteLength:r};return t&&(n.byteOffset=t),i&&(n.name=i),a&&(n.byteStride=a),n},t.CreateAccessor=function(e,t,r,a,i,n,o,s){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=n&&(l.byteOffset=n),l},t.CalculateMinMaxPositions=function(r,a,i,n){var o,s,l,u=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];if(i)for(var h=a,f=a+i;h<f;++h){o=3*h,s=e.Vector3.FromArray(r,o),n&&t.GetRightHandedPositionVector3FromRef(s),l=s.asArray();for(var 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={}));
|