12 |
- !(function(e,t){var r=[],a=e.BABYLON||this.BABYLON;"object"==typeof exports&&"object"==typeof module?(a=a||require("babylonjs"),module.exports=t(a)):"function"==typeof define&&define.amd?(r.push("babylonjs"),define("babylonjs-serializers",r,t)):"object"==typeof exports?(a=a||require("babylonjs"),exports["babylonjs-serializers"]=t(a)):e.BABYLON=t(a)})(this,(function(e){e=e||this.BABYLON;var e;this&&this.__decorate,this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}})();!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var n=[],o=1;r&&(a||(a="mat"),n.push("mtllib "+a+".mtl"));for(var s=0;s<t.length;s++){n.push("g object"+s),n.push("o object_"+s);var l=null;if(i){var u=e.Matrix.Translation(t[s].position.x,t[s].position.y,t[s].position.z);l=e.Matrix.Translation(-t[s].position.x,-t[s].position.y,-t[s].position.z),t[s].bakeTransformIntoVertices(u)}if(r){var f=t[s].material;f&&n.push("usemtl "+f.id)}var c=t[s].geometry;if(c){var h=c.getVerticesData("position"),d=c.getVerticesData("normal"),m=c.getVerticesData("uv"),p=c.getIndices(),g=0;if(h&&d&&m&&p){for(var T=0;T<h.length;T+=3)n.push("v "+h[T]+" "+h[T+1]+" "+h[T+2]),g++;for(T=0;T<d.length;T+=3)n.push("vn "+d[T]+" "+d[T+1]+" "+d[T+2]);for(T=0;T<m.length;T+=2)n.push("vt "+m[T]+" "+m[T+1]);for(T=0;T<p.length;T+=3)n.push("f "+(p[T+2]+o)+"/"+(p[T+2]+o)+"/"+(p[T+2]+o)+" "+(p[T+1]+o)+"/"+(p[T+1]+o)+"/"+(p[T+1]+o)+" "+(p[T]+o)+"/"+(p[T]+o)+"/"+(p[T]+o));i&&l&&t[s].bakeTransformIntoVertices(l),o+=g}}}return n.join("\n")},t.MTL=function(e){var t=[],r=e.material;t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4));return r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},t})();e.OBJExport=t})(e||(e={}));var e;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLTF(i)},t.GLTFAsync=function(e,r,a){return Promise.resolve(e.whenReadyAsync()).then((function(){return t.GLTF(e,r,a)}))},t.GLB=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,"");return new e.GLTF2._Exporter(t,a)._generateGLB(i)},t.GLBAsync=function(e,r,a){return Promise.resolve(e.whenReadyAsync()).then((function(){return t.GLB(e,r,a)}))},t})();e.GLTF2Export=t})(e||(e={}));var e;!(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,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),f=n.getUInt32(l+8);n.setUInt32(f,l+4),n.setUInt32(u,l+8)}break;case e.Material.TriangleFanDrawMode:for(var o=t.indexStart+t.indexCount-1,c=t.indexStart;o>=c;--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 f=[],c=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)c=h*u,f.push(e.Vector3.FromArray(n,c)),f.push(e.Vector3.FromArray(n,c+2*u)),f.push(e.Vector3.FromArray(n,c+u));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)c=h*u,f.push(e.Vector4.FromArray(n,c)),f.push(e.Vector4.FromArray(n,c+2*u)),f.push(e.Vector4.FromArray(n,c+u));break;case e.VertexBuffer.ColorKind:for(var d=l.getSize(),h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=d)c=h*u,4===d?(f.push(e.Vector4.FromArray(n,c)),f.push(e.Vector4.FromArray(n,c+2*u)),f.push(e.Vector4.FromArray(n,c+u))):(f.push(e.Vector3.FromArray(n,c)),f.push(e.Vector3.FromArray(n,c+2*u)),f.push(e.Vector3.FromArray(n,c+u)));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart;h<t.verticesStart+t.verticesCount;h+=3)c=h*u,f.push(e.Vector2.FromArray(n,c)),f.push(e.Vector2.FromArray(n,c+2*u)),f.push(e.Vector2.FromArray(n,c+u));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(f,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),f=[],c=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:c=t.verticesStart,f.push(e.Vector3.FromArray(n,c+2*u)),f.push(e.Vector3.FromArray(n,c+u));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector4.FromArray(n,c));break;case e.VertexBuffer.ColorKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,4===l.getSize()?f.push(e.Vector4.FromArray(n,c)):f.push(e.Vector3.FromArray(n,c));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector2.FromArray(n,c));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(f,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),f=[],c=0;switch(i){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector3.FromArray(n,c));break;case e.VertexBuffer.TangentKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector4.FromArray(n,c));break;case e.VertexBuffer.ColorKind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector4.FromArray(n,c)),4===l.getSize()?f.push(e.Vector4.FromArray(n,c)):f.push(e.Vector3.FromArray(n,c));break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=t.verticesStart+t.verticesCount-1;h>=t.verticesStart;--h)c=h*u,f.push(e.Vector2.FromArray(n,c));break;default:e.Tools.Error("Unsupported Vertex Buffer type: "+i)}this.writeVertexAttributeData(f,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 f=0,c=u.asArray();f<c.length;f++){var h=c[f];o.setFloat32(h,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,f=a.length/s;u<f;++u){o=u*s;var c=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedPositionVector3FromRef(c),l.push(c.asArray())}break;case e.VertexBuffer.NormalKind:for(var u=0,h=a.length/s;u<h;++u){o=u*s;var c=e.Vector3.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedNormalVector3FromRef(c),l.push(c.asArray())}break;case e.VertexBuffer.TangentKind:for(var u=0,d=a.length/s;u<d;++u){o=u*s;var c=e.Vector4.FromArray(a,o);this.convertToRightHandedSystem&&t._GLTFUtilities.GetRightHandedVector4FromRef(c),l.push(c.asArray())}break;case e.VertexBuffer.ColorKind:for(var u=0,m=a.length/s;u<m;++u){o=u*s;var c=3===s?e.Vector3.FromArray(a,o):e.Vector4.FromArray(a,o);l.push(c.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,x=y;v<x.length;v++){var b=x[v];n.setFloat32(b)}},r.prototype.generateJSON=function(e,r,a){var i,n,o,s=this,l={byteLength:this.totalByteLength},u=this.totalByteLength,f={asset:this.asset};return l.byteLength&&(f.buffers=[l]),this.nodes&&this.nodes.length&&(f.nodes=this.nodes),this.meshes&&this.meshes.length&&(f.meshes=this.meshes),this.scenes&&this.scenes.length&&(f.scenes=this.scenes,f.scene=0),this.bufferViews&&this.bufferViews.length&&(f.bufferViews=this.bufferViews),this.accessors&&this.accessors.length&&(f.accessors=this.accessors),this.animations&&this.animations.length&&(f.animations=this.animations),this.materials&&this.materials.length&&(f.materials=this.materials),this.textures&&this.textures.length&&(f.textures=this.textures),this.samplers&&this.samplers.length&&(f.samplers=this.samplers),this.images&&this.images.length&&(e?(f.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,f.images||(f.images=[]),f.images.push(e))})),l.byteLength=u):f.images=this.images),e||(l.uri=r+".bin"),a?JSON.stringify(f,null,2):JSON.stringify(f)},r.prototype._generateGLTF=function(t){var r=this.generateBinary(),a=this.generateJSON(!1,t,!0),i=new Blob([r],{type:"application/octet-stream"}),n=t+".gltf",o=t+".bin",s=new e.GLTFData;if(s.glTFFiles[n]=a,s.glTFFiles[o]=i,this.imageData)for(var l in this.imageData)s.glTFFiles[l]=new Blob([this.imageData[l].data],{type:this.imageData[l].mimeType});return s},r.prototype.generateBinary=function(){var e=new a(4);return this.createScene(this.babylonScene,e),e.getArrayBuffer()},r.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},r.prototype._generateGLB=function(t){var r=this.generateBinary(),a=this.generateJSON(!0),i=t+".glb",n=a.length,o=0;for(var s in this.imageData)o+=this.imageData[s].data.byteLength;var l=this._getPadding(n),u=this._getPadding(r.byteLength),f=this._getPadding(o),c=28+n+l+r.byteLength+u+o+f,h=new ArrayBuffer(12),d=new DataView(h);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,c,!0);var m=new ArrayBuffer(8+n+l),p=new DataView(m);p.setUint32(0,n+l,!0),p.setUint32(4,1313821514,!0);for(var g=new Uint8Array(m,8),T=0;T<n;++T)g[T]=a.charCodeAt(T);for(var y=new Uint8Array(m,8+n),T=0;T<l;++T)y[T]=32;var v=new ArrayBuffer(8),x=new DataView(v);x.setUint32(0,r.byteLength+o+f,!0),x.setUint32(4,5130562,!0);for(var b=new ArrayBuffer(u),F=new Uint8Array(b),T=0;T<u;++T)F[T]=0;for(var A=new ArrayBuffer(f),_=new Uint8Array(A),T=0;T<f;++T)_[T]=0;var R=[h,m,v,r];for(var s in this.imageData)R.push(this.imageData[s].data.buffer);R.push(b),R.push(A);var C=new Blob(R,{type:"application/octet-stream"}),M=new e.GLTFData;return M.glTFFiles[i]=C,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 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.material?t.material.fillMode:e.Material.TriangleFanDrawMode},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 f=null,c=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,i,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;n=t._GLTFUtilities.CreateBufferView(0,i.getByteOffset(),v,void 0,"Indices - "+l.name),this.bufferViews.push(n),f=this.bufferViews.length-1;for(var x=0,b=y.length;x<b;++x)i.setUInt32(y[x])}}if(l.subMeshes){o=!1;for(var F=0,A=l.subMeshes;F<A.length;F++){for(var _=A[F],R={attributes:{}},C=0,M=u;C<M.length;C++){var p=M[C],g=p.kind,S=l.getVerticesData(g);if(S){var T=this.getVertexBufferFromMesh(g,l);if(T){var V=T.getSize(),B=p.bufferViewIndex;if(void 0!=B){s={min:null,max:null},g==e.VertexBuffer.PositionKind&&(s=t._GLTFUtilities.CalculateMinMaxPositions(S,0,S.length/V,this.convertToRightHandedSystem));var E=t._GLTFUtilities.CreateAccessor(B,g+" - "+a.name,p.accessorType,5126,S.length/V,0,s.min,s.max);this.accessors.push(E),this.setAttributeKind(R,g),null==R.attributes.TEXCOORD_0&&null==R.attributes.TEXCOORD_1||(o=!0)}}}}if(f){var E=t._GLTFUtilities.CreateAccessor(f,"indices - "+a.name,"SCALAR",5125,_.indexCount,4*_.indexStart,null,null);this.accessors.push(E),R.indices=this.accessors.length-1}if(l.material){var w=null;if(l.material instanceof e.StandardMaterial||l.material instanceof e.PBRMetallicRoughnessMaterial||l.material instanceof e.PBRMaterial)w=a.getScene().materials.indexOf(l.material);else if(l.material instanceof e.MultiMaterial){var L=l.material,G=L.subMaterials[_.materialIndex];G&&(w=a.getScene().materials.indexOf(G))}else e.Tools.Warn("Material type "+l.material.getClassName()+" for material "+l.material.name+" is not yet implemented in glTF serializer.");if(null!=w&&Object.keys(R.attributes).length>0){var P=this.babylonScene.materials[w].sideOrientation;if(this.setPrimitiveMode(R,c),this.convertToRightHandedSystem&&P===e.Material.ClockWiseSideOrientation){var N=null!=f?this.bufferViews[f].byteOffset:null;null==N&&(N=0);var I=null;if(null!=f&&(I=l.getIndices()),I)this.reorderIndicesBasedOnPrimitiveMode(_,c,I,N,i);else for(var U=0,O=u;U<O.length;U++){var p=O[U],S=l.getVerticesData(p.kind);if(S){var k=this.bufferViews[h[p.kind]].byteOffset;k||(k=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(_,c,P,p.kind,S,k,i)}}}if(o)t._GLTFMaterial._HasTexturesPresent(this.materials[w])||(delete R.attributes.TEXCOORD_0,delete R.attributes.TEXCOORD_1),R.material=w;else if(t._GLTFMaterial._HasTexturesPresent(this.materials[w])){var D=t._GLTFMaterial._StripTexturesFromMaterial(this.materials[w]);this.materials.push(D),R.material=this.materials.length-1}else R.material=w}}else{var P=this.babylonScene.defaultMaterial.sideOrientation,N=null!=f?this.bufferViews[f].byteOffset:null;null==N&&(N=0);var I=null;if(null!=f&&(I=l.getIndices()),I)P===e.Material.ClockWiseSideOrientation&&this.reorderIndicesBasedOnPrimitiveMode(_,c,I,N,i);else for(var K=0,z=u;K<z.length;K++){var p=z[K],S=l.getVerticesData(p.kind);if(S){var H=this.bufferViews[h[p.kind]].byteOffset;H||(H=0),this.reorderVertexAttributeDataBasedOnPrimitiveMode(_,c,P,p.kind,S,H,i)}}}r.primitives.push(R)}}}},r.prototype.createScene=function(r,a){if(this.setNodeTransformation.length){var i={nodes:[]},n=void 0,o=void 0,s=void 0,l=r.transformNodes.concat(r.meshes);t._GLTFMaterial._ConvertMaterialsToGLTF(r.materials,"image/png",this.images,this.textures,this.samplers,this.materials,this.imageData,!0),this.nodeMap=this.createNodeMapAndAnimations(r,l,this.shouldExportTransformNode,a),this.totalByteLength=a.getByteOffset();for(var u=0,f=l;u<f.length;u++){var c=f[u];if(null!=(n=this.nodeMap[c.uniqueId])&&(o=this.nodes[n],c.parent||(this.shouldExportTransformNode(c)?(this.convertToRightHandedSystem&&(o.translation&&(o.translation[2]*=-1,o.translation[0]*=-1),o.rotation=o.rotation?e.Quaternion.FromArray([0,1,0,0]).multiply(e.Quaternion.FromArray(o.rotation)).asArray():e.Quaternion.FromArray([0,1,0,0]).asArray()),i.nodes.push(n)):e.Tools.Log("Omitting "+c.name+" from scene.")),s=c.getDescendants(!0),!o.children&&s&&s.length)){o.children=[];for(var h=0,d=s;h<d.length;h++){var m=d[h];null!=this.nodeMap[m.uniqueId]&&o.children.push(this.nodeMap[m.uniqueId])}}}i.nodes.length&&this.scenes.push(i)}},r.prototype.createNodeMapAndAnimations=function(e,r,a,i){for(var n,o,s=this,l={},u={name:"runtime animations",channels:[],samplers:[]},f=[],c=0,h=r;c<h.length;c++){var d=h[c];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,f,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),f.forEach((function(e){e.channels.length&&e.samplers.length&&s.animations.push(e)})),e.animationGroups.length&&t._GLTFAnimation._CreateNodeAnimationFromAnimationGroups(e,this.animations,l,this.nodes,i,this.bufferViews,this.accessors,this.convertToRightHandedSystem,this.animationSampleRate),l},r.prototype.createNode=function(e,t){var r={},a={primitives:[]};return e.name&&(r.name=e.name),this.setNodeTransformation(r,e),this.setPrimitiveAttributes(a,e,t),a.primitives.length&&(this.meshes.push(a),r.mesh=this.meshes.length-1),r},r})();t._Exporter=r;var a=(function(){function t(e){this._arrayBuffer=new ArrayBuffer(e),this._dataView=new DataView(this._arrayBuffer),this._byteOffset=0}return t.prototype.resizeBuffer=function(e){for(var t=new ArrayBuffer(e),r=new Uint8Array(this._arrayBuffer),a=new Uint8Array(t),i=0,n=a.byteLength;i<n;++i)a[i]=r[i];this._arrayBuffer=t,this._dataView=new DataView(this._arrayBuffer)},t.prototype.getArrayBuffer=function(){return this.resizeBuffer(this.getByteOffset()),this._arrayBuffer},t.prototype.getByteOffset=function(){return this._byteOffset},t.prototype.setUInt8=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint8(r,t):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+1>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint8(this._byteOffset++,t))},t.prototype.getUInt32=function(t){if(t<this._byteOffset)return this._dataView.getUint32(t,!0);throw e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"),new Error("BinaryWriter: byteoffset is greater than the current binary buffer length!")},t.prototype.getVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0))},t.prototype.setVector3Float32FromRef=function(t,r){r+8>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0))},t.prototype.getVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(t.x=this._dataView.getFloat32(r,!0),t.y=this._dataView.getFloat32(r+4,!0),t.z=this._dataView.getFloat32(r+8,!0),t.w=this._dataView.getFloat32(r+12,!0))},t.prototype.setVector4Float32FromRef=function(t,r){r+12>this._byteOffset?e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._dataView.setFloat32(r,t.x,!0),this._dataView.setFloat32(r+4,t.y,!0),this._dataView.setFloat32(r+8,t.z,!0),this._dataView.setFloat32(r+12,t.w,!0))},t.prototype.setFloat32=function(t,r){isNaN(t)&&e.Tools.Error("Invalid data being written!"),null!=r&&(r<this._byteOffset?this._dataView.setFloat32(r,t,!0):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary length!")),this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setFloat32(this._byteOffset,t,!0),this._byteOffset+=4},t.prototype.setUInt32=function(t,r){null!=r?r<this._byteOffset?this._dataView.setUint32(r,t,!0):e.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!"):(this._byteOffset+4>this._arrayBuffer.byteLength&&this.resizeBuffer(2*this._arrayBuffer.byteLength),this._dataView.setUint32(this._byteOffset,t,!0),this._byteOffset+=4)},t})();t._BinaryWriter=a})(e.GLTF2||(e.GLTF2={}))})(e||(e={}));var e;!(function(e){var t=(function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-1!==e.indexOf(t,e.length-t.length)}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var a=this.glTFFiles[t],i=void 0;e(t,".glb")?i={type:"model/gltf-binary"}:e(t,".bin")?i={type:"application/octet-stream"}:e(t,".gltf")?i={type:"model/gltf+json"}:e(t,".jpeg")?i={type:"image/jpeg"}:e(t,".png")&&(i={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([a],i)),r.click()}},e})();e.GLTFData=t})(e||(e={}));var e;!(function(e){!(function(t){var r=(function(){function t(){}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._ConvertMaterialsToGLTF=function(r,a,i,n,o,s,l,u){for(var f=0,c=r;f<c.length;f++){var h=c[f];h instanceof e.StandardMaterial?t._ConvertStandardMaterial(h,a,i,n,o,s,l,u):h instanceof e.PBRMetallicRoughnessMaterial?t._ConvertPBRMetallicRoughnessMaterial(h,a,i,n,o,s,l,u):h instanceof e.PBRMaterial?t._ConvertPBRMaterial(h,a,i,n,o,s,l,u):e.Tools.Error("Unsupported material type: "+h.name)}},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),f=(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:f}},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._ConvertStandardMaterial=function(r,a,i,n,o,s,l,u){var f=t._ConvertToGLTFPBRMetallicRoughness(r),c={name:r.name};if(null==r.backFaceCulling||r.backFaceCulling||(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),c.doubleSided=!0),u){if(r.diffuseTexture){var h=t._ExportTexture(r.diffuseTexture,a,i,n,o,l);null!=h&&(f.baseColorTexture=h)}if(r.bumpTexture){var h=t._ExportTexture(r.bumpTexture,a,i,n,o,l);h&&(c.normalTexture=h,1!==r.bumpTexture.level&&(c.normalTexture.scale=r.bumpTexture.level))}if(r.emissiveTexture){var d=t._ExportTexture(r.emissiveTexture,a,i,n,o,l);d&&(c.emissiveTexture=d),c.emissiveFactor=[1,1,1]}if(r.ambientTexture){var h=t._ExportTexture(r.ambientTexture,a,i,n,o,l);if(h){var m={index:h.index};c.occlusionTexture=m,m.strength=1}}}(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?c.alphaMode="BLEND":e.Tools.Warn(r.name+": glTF 2.0 does not support alpha mode: "+r.alphaMode.toString())),r.emissiveColor&&!this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),c.pbrMetallicRoughness=f,s.push(c)},t._ConvertPBRMetallicRoughnessMaterial=function(r,a,i,n,o,s,l,u){var 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 c={name:r.name};if(r.doubleSided&&(c.doubleSided=r.doubleSided),u){if(null!=r.baseTexture){var h=t._ExportTexture(r.baseTexture,a,i,n,o,l);null!=h&&(f.baseColorTexture=h)}if(r.normalTexture){var h=t._ExportTexture(r.normalTexture,a,i,n,o,l);h&&(c.normalTexture=h,1!==r.normalTexture.level&&(c.normalTexture.scale=r.normalTexture.level))}if(r.occlusionTexture){var h=t._ExportTexture(r.occlusionTexture,a,i,n,o,l);h&&(c.occlusionTexture=h,null!=r.occlusionStrength&&(c.occlusionTexture.strength=r.occlusionStrength))}if(r.emissiveTexture){var h=t._ExportTexture(r.emissiveTexture,a,i,n,o,l);null!=h&&(c.emissiveTexture=h)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(c.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var d=t._GetAlphaMode(r);d&&"OPAQUE"!==d&&(c.alphaMode=d,"MASK"===d&&(c.alphaCutoff=r.alphaCutOff))}c.pbrMetallicRoughness=f,s.push(c)},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 null;var n=t?t.getScene():r.getScene();if(!n)return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!"),null;var o,s,l=this._ResizeTexturesToSameDimensions(t,r,n),u=l.texture1.getSize(),f=u.width,c=u.height,h=l.texture1.readPixels()
- ;if(!(h instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture1.name),null;if(o=l.texture1.readPixels(),!((h=l.texture2.readPixels())instanceof Uint8Array))return e.Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture2.name),null;s=l.texture2.readPixels();for(var d=s.byteLength,m=new Uint8Array(d),p=new Uint8Array(d),g=e.Color3.Black(),T=0,y=0,v=0;v<c;++v)for(var x=0;x<f;++x){var b=4*(f*v+x),F=e.Color3.FromInts(o[b],o[b+1],o[b+2]).toLinearSpace().multiply(a.diffuseColor),A=e.Color3.FromInts(s[b],s[b+1],s[b+2]).toLinearSpace().multiply(a.specularColor),_=s[b+3]/255*a.glossiness,R={diffuseColor:F,specularColor:A,glossiness:_},C=this._ConvertSpecularGlossinessToMetallicRoughness(R);g.r=Math.max(g.r,C.baseColor.r),g.g=Math.max(g.g,C.baseColor.g),g.b=Math.max(g.b,C.baseColor.b),T=Math.max(T,C.metallic),y=Math.max(y,C.roughness),p[b]=255*C.baseColor.r,p[b+1]=255*C.baseColor.g,p[b+2]=255*C.baseColor.b,p[b+3]=l.texture1.hasAlpha?o[b+3]:255,m[b]=0,m[b+1]=255*C.roughness,m[b+2]=255*C.metallic,m[b+3]=255}for(var M={baseColor:g,metallic:T,roughness:y},S=!1,V=!1,v=0;v<c;++v)for(var x=0;x<f;++x){var B=4*(f*v+x);p[B]/=M.baseColor.r>this._epsilon?M.baseColor.r:1,p[B+1]/=M.baseColor.g>this._epsilon?M.baseColor.g:1,p[B+2]/=M.baseColor.b>this._epsilon?M.baseColor.b:1;var E=e.Color3.FromInts(p[B],p[B+1],p[B+2]),w=E.toGammaSpace();p[B]=255*w.r,p[B+1]=255*w.g,p[B+2]=255*w.b,this.FuzzyEquals(w,e.Color3.White(),this._epsilon)||(V=!0),m[B+1]/=M.roughness>this._epsilon?M.roughness:1,m[B+2]/=M.metallic>this._epsilon?M.metallic:1;var L=e.Color3.FromInts(255,m[B+1],m[B+2]);this.FuzzyEquals(L,e.Color3.White(),this._epsilon)||(S=!0)}if(S){var G=this._CreateBase64FromCanvas(m,f,c,i);M.metallicRoughnessTextureBase64=G}if(V){var P=this._CreateBase64FromCanvas(p,f,c,i);M.baseColorTextureBase64=P}return M},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._ConvertMetalRoughFactorsToMetallicRoughness=function(e,r,a,i,n,o,s,l){var u={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};if(l){if(e.albedoTexture){var f=t._ExportTexture(e.albedoTexture,r,a,i,n,s);f&&(o.baseColorTexture=f)}if(e.metallicTexture){var f=t._ExportTexture(e.metallicTexture,r,a,i,n,s);null!=f&&(o.metallicRoughnessTexture=f)}}return u},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 f={diffuseColor:r.albedoColor||e.Color3.White(),specularColor:r.reflectivityColor||e.Color3.White(),glossiness:r.microSurface||1},c=null,h=this._GetGLTFTextureSampler(r.albedoTexture);if(null!=h.magFilter&&null!=h.minFilter&&null!=h.wrapS&&null!=h.wrapT&&(o.push(h),c=o.length-1),r.reflectivityTexture&&!r.useMicroSurfaceFromReflectivityMapAlpha)return e.Tools.Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported"),null;var d=this._ConvertSpecularGlossinessTexturesToMetallicRoughness(r.albedoTexture,r.reflectivityTexture,f,a);if(d){if(u){if(d.baseColorTextureBase64){var m=t._GetTextureInfoFromBase64(d.baseColorTextureBase64,"bjsBaseColorTexture_"+n.length+".png",a,i,n,r.albedoTexture.coordinatesIndex,c,l);null!=m&&(s.baseColorTexture=m)}if(d.metallicRoughnessTextureBase64){var p=t._GetTextureInfoFromBase64(d.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+n.length+".png",a,i,n,r.reflectivityTexture.coordinatesIndex,c,l);null!=p&&(s.metallicRoughnessTexture=p)}}}else d=this._ConvertSpecularGlossinessToMetallicRoughness(f);return d},t._ConvertPBRMaterial=function(r,a,i,n,o,s,l,u){var f,c={},h={name:r.name};if(f=r.isMetallicWorkflow()?this._ConvertMetalRoughFactorsToMetallicRoughness(r,a,i,n,o,c,l,u):this._ConvertSpecGlossFactorsToMetallicRoughness(r,a,i,n,o,c,l,u)){if(this.FuzzyEquals(f.baseColor,e.Color3.White(),this._epsilon)&&r.alpha>=this._epsilon||(c.baseColorFactor=[f.baseColor.r,f.baseColor.g,f.baseColor.b,r.alpha]),null!=f.metallic&&1!==f.metallic&&(c.metallicFactor=f.metallic),null!=f.roughness&&1!==f.roughness&&(c.roughnessFactor=f.roughness),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."),h.doubleSided=!0),u){if(r.bumpTexture){var d=t._ExportTexture(r.bumpTexture,a,i,n,o,l);d&&(h.normalTexture=d,1!==r.bumpTexture.level&&(h.normalTexture.scale=r.bumpTexture.level))}if(r.ambientTexture){var d=t._ExportTexture(r.ambientTexture,a,i,n,o,l);if(d){var m={index:d.index};h.occlusionTexture=m,r.ambientTextureStrength&&(m.strength=r.ambientTextureStrength)}}if(r.emissiveTexture){var d=t._ExportTexture(r.emissiveTexture,a,i,n,o,l);null!=d&&(h.emissiveTexture=d)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)||(h.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var p=t._GetAlphaMode(r);p&&"OPAQUE"!==p&&(h.alphaMode=p,"MASK"===p&&(h.alphaCutoff=r.alphaCutOff))}h.pbrMetallicRoughness=c,s.push(h)}},t.GetPixelsFromTexture=function(t){return t.textureType,e.Engine.TEXTURETYPE_UNSIGNED_INT,t.readPixels()},t._ExportTexture=function(r,a,i,n,o,s){for(var l=t._GetGLTFTextureSampler(r),u=null,f=null,c=0;c<o.length;++c){var h=o[c];if(h.minFilter===l.minFilter&&h.magFilter===l.magFilter&&h.wrapS===l.wrapS&&h.wrapT===l.wrapT){f=c;break}}null==f?(o.push(l),u=o.length-1):u=f;var d="texture_"+(n.length-1).toString(),m=r.getInternalTexture();null!=m&&(d=m.url||d),d=e.Tools.GetFilename(d);var p=d.split(".")[0],g="";if("image/jpeg"===a)g=".jpg";else{if("image/png"!==a)return e.Tools.Error("Unsupported mime type "+a),null;g=".png"}d=p+g;var T=t.GetPixelsFromTexture(r),y=r.getSize(),v=this._CreateBase64FromCanvas(T,y.width,y.height,a);return this._GetTextureInfoFromBase64(v,d,a,i,n,r.coordinatesIndex,u,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 f=atob(e.split(",")[1]),c=new ArrayBuffer(f.length),h=new Uint8Array(c),d=0,m=f.length;d<m;++d)h[d]=f.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,i.push(u),l={index:i.length-1},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={}))})(e||(e={}));var e;!(function(e){!(function(t){var r;!(function(e){e[e.INTANGENT=0]="INTANGENT",e[e.OUTTANGENT=1]="OUTTANGENT"})(r||(r={}));var a=(function(){function a(){}return a._CreateNodeAnimation=function(t,r,i,n,o,s){var l=[],u=[],f=r.getKeys(),c=a.calculateMinMaxKeyFrames(f),h=a._DeduceInterpolation(f,i,o),d=c.max-c.min,m=h.interpolationType,p=h.shouldBakeAnimation;if(p?a._CreateBakedAnimation(t,r,i,c.min,c.max,r.framePerSecond,s,l,u,c,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,c.min,c.max,r.framePerSecond,s,l,u,c,n,o),l.length&&u.length){return{inputs:l,outputs:u,samplerInterpolation:m,inputsMin:p?c.min:e.Tools.FloatRound(c.min/r.framePerSecond),inputsMax:p?c.max:e.Tools.FloatRound(c.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,f){var c;if(e.animations)for(var h=0,d=e.animations;h<d.length;h++){var m=d[h],p=a._DeduceAnimationInfo(m);p&&(c={name:m.name,samplers:[],channels:[]},a.AddAnimation(""+m.name,m.hasRunningRuntimeAnimations?t:c,e,m,p.dataAccessorType,p.animationChannelTargetPath,i,o,s,l,u,p.useQuaternion,f),c.samplers.length&&c.channels.length&&r.push(c))}},a._CreateNodeAnimationFromAnimationGroups=function(t,r,i,n,o,s,l,u,f){var c;if(t.animationGroups)for(var h=t.animationGroups,d=0,m=h;d<m.length;d++){var p=m[d];c={name:p.name,channels:[],samplers:[]};for(var g=0,T=p.targetedAnimations;g<T.length;g++){var y=T[g],v=y.target,x=y.animation;if(v instanceof e.Mesh||1===v.length&&v[0]instanceof e.Mesh){var b=a._DeduceAnimationInfo(y.animation);if(b){var F=v instanceof e.Mesh?v:v[0];a.AddAnimation(""+x.name,c,F,x,b.dataAccessorType,b.animationChannelTargetPath,i,o,s,l,u,b.useQuaternion,f)}}}c.channels.length&&c.samplers.length&&r.push(c)}},a.AddAnimation=function(e,r,i,n,o,s,l,u,f,c,h,d,m){var p,g,T,y,v,x,b,F=a._CreateNodeAnimation(i,n,s,h,d,m);if(F){var A=l[i.uniqueId],_=4*F.inputs.length;p=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),_,void 0,e+" keyframe data view"),f.push(p),F.inputs.forEach((function(e){u.setFloat32(e)})),g=t._GLTFUtilities.CreateAccessor(f.length-1,e+" keyframes","SCALAR",5126,F.inputs.length,null,[F.inputsMin],[F.inputsMax]),c.push(g),T=c.length-1,v=F.outputs.length,_="VEC3"===o?12*F.outputs.length:16*F.outputs.length,p=t._GLTFUtilities.CreateBufferView(0,u.getByteOffset(),_,void 0,e+" data view"),f.push(p),F.outputs.forEach((function(e){e.forEach((function(e){u.setFloat32(e)}))})),g=t._GLTFUtilities.CreateAccessor(f.length-1,e+" data",o,5126,v,null,null,null),c.push(g),y=c.length-1,x={interpolation:F.samplerInterpolation,input:T,output:y},r.samplers.push(x),b={sampler:r.samplers.length-1,target:{node:A,path:s}},r.channels.push(b)}},a._CreateBakedAnimation=function(t,r,i,n,o,s,l,u,f,c,h,d){var m,p,g=e.Quaternion.Identity(),T=null,y=null,v=null,x=null,b=null,F=null;c.min=e.Tools.FloatRound(n/s);for(var A=r.getKeys(),_=0,R=A.length;_<R;++_){if(F=null,v=A[_],_+1<R)if(x=A[_+1],v.value.equals(x.value)){if(0!==_)continue;F=v.frame}else F=x.frame;else{if(b=A[_-1],v.value.equals(b.value))continue;F=o}if(F)for(var C=v.frame;C<=F;C+=l)(p=e.Tools.FloatRound(C/s))!==T&&(T=p,y=p,m=r._interpolate(C,0,void 0,r.loopMode),a._SetInterpolatedValue(t,m,p,r,i,g,u,f,h,d))}y&&(c.max=y)},a._ConvertFactorToVector3OrQuaternion=function(t,r,i,n,o,s,l){var u,f,c=null,h=a._GetBasePositionRotationOrScale(r,o,s,l);if(n===e.Animation.ANIMATIONTYPE_FLOAT)switch(u=i.targetProperty.split("."),f=u?u[1]:"",c=l?e.Quaternion.FromArray(h).normalize():e.Vector3.FromArray(h),f){case"x":case"y":c[f]=s&&l&&"scale"!==o?-t:t;break;case"z":c[f]=s&&!l&&"scale"!==o?-t:t;break;case"w":c.w=t;break;default:e.Tools.Error('glTFAnimation: Unsupported component type "'+f+'" for scale animation!')}return c},a._SetInterpolatedValue=function(r,a,i,n,o,s,l,u,f,c){var h,d=n.dataType;l.push(i),"number"==typeof a&&(a=this._ConvertFactorToVector3OrQuaternion(a,r,n,d,o,f,c)),a&&("rotation"===o?(c?s=a:(h=a,e.Quaternion.RotationYawPitchRollToRef(h.y,h.x,h.z,s)),f&&(t._GLTFUtilities.GetRightHandedQuaternionFromRef(s),r.parent||(s=e.Quaternion.FromArray([0,1,0,0]).multiply(s))),u.push(s.asArray())):(h=a,f&&"scale"!==o&&(t._GLTFUtilities.GetRightHandedPositionVector3FromRef(h),r.parent||(h.x*=-1,h.z*=-1)),u.push(h.asArray())))},a._CreateLinearOrStepAnimation=function(e,t,r,i,n,o,s,l){for(var u=0,f=t.getKeys();u<f.length;u++){var c=f[u];n.push(c.frame/t.framePerSecond),a._AddKeyframeValue(c,t,o,r,e,s,l)}},a._CreateCubicSplineAnimation=function(e,t,i,n,o,s,l,u){t.getKeys().forEach((function(f){o.push(f.frame/t.framePerSecond),a.AddSplineTangent(e,r.INTANGENT,s,i,"CUBICSPLINE",f,n,u,l),a._AddKeyframeValue(f,t,s,i,e,l,u),a.AddSplineTangent(e,r.OUTTANGENT,s,i,"CUBICSPLINE",f,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,f,c=a.dataType;if(c===e.Animation.ANIMATIONTYPE_VECTOR3){if(u=r.value.asArray(),"rotation"===n){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"===n&&s&&(t._GLTFUtilities.GetRightHandedNormalArray3FromRef(u),o.parent||(u[0]*=-1,u[2]*=-1));i.push(u)}else if(c===e.Animation.ANIMATIONTYPE_FLOAT){if(f=this._ConvertFactorToVector3OrQuaternion(r.value,o,a,c,n,s,l)){if("rotation"===n){var m=l?f:e.Quaternion.RotationYawPitchRoll(f.y,f.x,f.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(f),o.parent||(f.x*=-1,f.z*=-1));i.push(f.asArray())}}else c===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,f,c){var h,d=i===r.INTANGENT?l.inTangent:l.outTangent;if("CUBICSPLINE"===s){if("rotation"===o)if(d){if(f)h=d.scale(u).asArray();else{var m=d.scale(u);h=e.Quaternion.RotationYawPitchRoll(m.y,m.x,m.z).asArray()}c&&(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(),c&&"translation"===o&&(t._GLTFUtilities.GetRightHandedPositionArray3FromRef(h),a.parent||(h[0]*=-1,h[2]*=-1))):h=[0,0,0];n.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={}))})(e||(e={}));var e;return (function(e){!(function(t){var r=(function(){function t(){}return t.CreateBufferView=function(e,t,r,a,i){var n={buffer:e,byteLength:r};return t&&(n.byteOffset=t),i&&(n.name=i),a&&(n.byteStride=a),n},t.CreateAccessor=function(e,t,r,a,i,n,o,s){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return null!=o&&(l.min=o),null!=s&&(l.max=s),null!=n&&(l.byteOffset=n),l},t.CalculateMinMaxPositions=function(r,a,i,n){var o,s,l,u=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0];if(i)for(var c=a,h=a+i;c<h;++c){o=3*c,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>f[d]&&(f[d]=m),++o}}return{min:u,max:f}},t.GetRightHandedPositionVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedPositionVector3FromRef=function(e){e.z*=-1},t.GetRightHandedPositionArray3FromRef=function(e){e[2]*=-1},t.GetRightHandedNormalVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},t.GetRightHandedNormalVector3FromRef=function(e){e.z*=-1},t.GetRightHandedNormalArray3FromRef=function(e){e[2]*=-1},t.GetRightHandedVector4FromRef=function(e){e.z*=-1,e.w*=-1},t.GetRightHandedArray4FromRef=function(e){e[2]*=-1,e[3]*=-1},t.GetRightHandedQuaternionFromRef=function(e){e.x*=-1,e.y*=-1},t.GetRightHandedQuaternionArrayFromRef=function(e){e[0]*=-1,e[1]*=-1},t})();t._GLTFUtilities=r})(e.GLTF2||(e.GLTF2={}))})(e||(e={})),e}));
|