1 |
- var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,i){var s=r.replace(/\.[^\/.]+$/,""),a=new e.GLTF2._Exporter(t,i);if(t.isReady)return a._generateGLTF(s);throw new Error("glTF Serializer: Scene is not ready!")},t.GLB=function(t,r,i){var s=r.replace(/\.[^\/.]+$/,""),a=new e.GLTF2._Exporter(t,i);if(t.isReady)return a._generateGLB(s);throw new Error("glTF Serializer: Scene is not ready!")},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=new Array,this.accessors=new Array,this.meshes=new Array,this.scenes=new Array,this.nodes=new Array,this.images=new Array,this.materials=new Array,this.imageData={},void 0!==t&&(this.options=t);var r=0;r=this.createScene(this.babylonScene,r),this.totalByteLength=r}return r.prototype.createBufferView=function(e,t,r,i){var s={buffer:e,byteLength:r};return t>0&&(s.byteOffset=t),i&&(s.name=i),s},r.prototype.createAccessor=function(e,t,r,i,s,a,n){var o={name:t,bufferView:e,componentType:i,count:s,type:r};return a&&(o.min=a),n&&(o.max=n),o},r.prototype.calculateMinMax=function(e,t,r,i,s){var a=[1/0,1/0,1/0],n=[-(1/0),-(1/0),-(1/0)],o=t+r;if(r>0)for(var u=t;u<o;++u)for(var l=s*u,h=0;h<s;++h)e[l]<a[h]&&(a[h]=e[l]),e[l]>n[h]&&(n[h]=e[l]),++l;return{min:a,max:n}},r.prototype.writeAttributeData=function(t,r,i,s,a,n,o){var u=a,l=r.verticesStart+r.verticesCount,h=0;switch(t){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var c=r.verticesStart;c<l;++c){var f=c*s;n.setFloat32(u,i[f],!0),u+=4,n.setFloat32(u,i[f+1],!0),u+=4,o?n.setFloat32(u,i[f+2],!0):n.setFloat32(u,-i[f+2],!0),u+=4}h=12*r.verticesCount;break;case e.VertexBuffer.TangentKind:for(var c=r.indexStart;c<l;++c){var f=c*s;n.setFloat32(u,i[f],!0),u+=4,n.setFloat32(u,i[f+1],!0),u+=4,o?n.setFloat32(u,i[f+2],!0):n.setFloat32(u,-i[f+2],!0),u+=4,n.setFloat32(u,i[f+3],!0),u+=4}h=16*r.verticesCount;break;case e.VertexBuffer.ColorKind:for(var c=r.verticesStart;c<l;++c){var f=c*s;n.setFloat32(u,i[f],!0),u+=4,n.setFloat32(u,i[f+1],!0),u+=4,n.setFloat32(u,i[f+2],!0),u+=4,n.setFloat32(u,i[f+3],!0),u+=4}h=16*r.verticesCount;break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var c=r.verticesStart;c<l;++c){var f=c*s;n.setFloat32(u,i[f],!0),u+=4,n.setFloat32(u,i[f+1],!0),u+=4}h=8*r.verticesCount;break;default:throw new Error("Unsupported vertex buffer type: "+t)}return h},r.prototype.generateJSON=function(e,t,r){var i={byteLength:this.totalByteLength},s={asset:this.asset};if(i.byteLength>0&&(s.buffers=[i]),this.nodes&&0!==this.nodes.length&&(s.nodes=this.nodes),this.meshes&&0!==this.meshes.length&&(s.meshes=this.meshes),this.scenes&&0!==this.scenes.length&&(s.scenes=this.scenes,s.scene=0),this.bufferViews&&0!==this.bufferViews.length&&(s.bufferViews=this.bufferViews),this.accessors&&0!==this.accessors.length&&(s.accessors=this.accessors),this.materials&&0!==this.materials.length&&(s.materials=this.materials),this.textures&&0!==this.textures.length&&(s.textures=this.textures),this.images&&0!==this.images.length)if(e){s.images=[];for(var a=this.images.length,n=this.totalByteLength,o=0;o<a;++o){var u=this.images[o];if(void 0!==u.uri){var l=this.imageData[u.uri],h=u.uri.split(".")[0]+" image",c=this.createBufferView(0,n,l.data.length,h);n+=l.data.buffer.byteLength,this.bufferViews.push(c),u.bufferView=this.bufferViews.length-1,u.name=h,u.mimeType=l.mimeType,u.uri=void 0,s.images.push(u)}}i.byteLength=n}else s.images=this.images;return e||(i.uri=t+".bin"),r?JSON.stringify(s,null,2):JSON.stringify(s)},r.prototype._generateGLTF=function(t){var r=this.generateJSON(!1,t,!0),i=this.generateBinary(),s=new Blob([i],{type:"application/octet-stream"}),a=t+".gltf",n=t+".bin",o=new e._GLTFData;if(o.glTFFiles[a]=r,o.glTFFiles[n]=s,null!==this.imageData)for(var u in this.imageData)o.glTFFiles[u]=new Blob([this.imageData[u].data],{type:this.imageData[u].mimeType});return o},r.prototype.generateBinary=function(){var e=0,t=new ArrayBuffer(this.totalByteLength),r=new DataView(t);return e=this.createScene(this.babylonScene,e,r),t},r.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},r.prototype._generateGLB=function(t){var r=this.generateJSON(!0),i=this.generateBinary(),s=t+".glb",a=r.length,n=0;for(var o in this.imageData)n+=this.imageData[o].data.byteLength;var u=this._getPadding(a),l=this._getPadding(i.byteLength),h=28+a+u+i.byteLength+l+n,c=new ArrayBuffer(12),f=new DataView(c);f.setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,h,!0);var g=new ArrayBuffer(8+a+u),p=new DataView(g);p.setUint32(0,a+u,!0),p.setUint32(4,1313821514,!0);for(var d=new Uint8Array(g,8),v=0;v<a;++v)d[v]=r.charCodeAt(v);for(var m=new Uint8Array(g,8+a),v=0;v<u;++v)m[v]=32;var x=new ArrayBuffer(8),b=new DataView(x);b.setUint32(0,i.byteLength+n,!0),b.setUint32(4,5130562,!0);for(var B=new ArrayBuffer(l),w=new Uint8Array(B),v=0;v<l;++v)w[v]=0;var y=[c,g,x,i];for(var o in this.imageData)y.push(this.imageData[o].data.buffer);y.push(B);var T=new Blob(y,{type:"application/octet-stream"}),V=new e._GLTFData;return V.glTFFiles[s]=T,V},r.prototype.setNodeTransformation=function(t,r,i){0===r.position.x&&0===r.position.y&&0===r.position.z||(t.translation=i?r.position.asArray():[r.position.x,r.position.y,-r.position.z]),1===r.scaling.x&&1===r.scaling.y&&1===r.scaling.z||(t.scale=i?r.scaling.asArray():[r.scaling.x,r.scaling.y,-r.scaling.z]);var s=e.Quaternion.RotationYawPitchRoll(r.rotation.y,r.rotation.x,r.rotation.z);r.rotationQuaternion&&(s=s.multiply(r.rotationQuaternion)),0===s.x&&0===s.y&&0===s.z&&1===s.w||(t.rotation=i?s.asArray():[-s.x,-s.y,s.z,s.w])},r.prototype.exportTexture=function(e,t){void 0===t&&(t="image/jpeg");var r,i=null;r={source:this.images.length};var s=e.getInternalTexture().url;if(s.search("/")!==-1){var a=s.split("/");s=a[a.length-1];var n=s.split(".")[0],o=s.split(".")[1];if("image/jpeg"===t)o=".jpg";else{if("image/png"!==t)throw new Error("Unsupported mime type "+t);o=".png"}s=n+o}var u=e.readPixels(),l=document.createElement("canvas");l.id="ImageCanvas";var h=l.getContext("2d"),c=e.getSize();l.width=c.width,l.height=c.height;var f=h.createImageData(c.width,c.height);f.data.set(u),h.putImageData(f,0,0);for(var g=l.toDataURL(t),p=atob(g.split(",")[1]),d=new Uint8Array(p.length),v=0;v<p.length;++v)d[v]=p.charCodeAt(v);var m={data:d,mimeType:t};if(this.imageData[s]=m,"image/jpeg"===t){for(var x={uri:s},b=-1,v=0;v<this.images.length;++v)if(this.images[v].uri===s){b=v;break}b===-1?(this.images.push(x),r.source=this.images.length-1,this.textures.push({source:this.images.length-1}),i={index:this.images.length-1}):(r.source=b,i={index:b})}return i},r.prototype.setPrimitiveAttributes=function(r,i,s,a,n){for(var o=0;o<i.subMeshes.length;++o){var u=null,l=i.subMeshes[o],h={attributes:{}};if(i instanceof e.Mesh?u=i:i instanceof e.InstancedMesh&&(u=i.sourceMesh),u.isVerticesDataPresent(e.VertexBuffer.PositionKind)){var c=u.getVertexBuffer(e.VertexBuffer.PositionKind),f=c.getOffset(),g=c.getData(),p=c.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.PositionKind,l,g,p,s,n,a);else{var d=12*l.verticesCount,v=this.createBufferView(0,s,d,"Positions");s+=d,this.bufferViews.push(v);var m=this.calculateMinMax(g,l.verticesStart,l.verticesCount,f,p),x=this.createAccessor(this.bufferViews.length-1,"Position","VEC3",5126,l.verticesCount,m.min,m.max);this.accessors.push(x),h.attributes.POSITION=this.accessors.length-1}}if(u.isVerticesDataPresent(e.VertexBuffer.NormalKind)){var b=u.getVertexBuffer(e.VertexBuffer.NormalKind),B=b.getData(),w=b.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.NormalKind,l,B,w,s,n,a);else{var d=12*l.verticesCount,v=this.createBufferView(0,s,d,"Normals");s+=d,this.bufferViews.push(v);var x=this.createAccessor(this.bufferViews.length-1,"Normal","VEC3",5126,l.verticesCount);this.accessors.push(x),h.attributes.NORMAL=this.accessors.length-1}}if(u.isVerticesDataPresent(e.VertexBuffer.TangentKind)){var y=u.getVertexBuffer(e.VertexBuffer.TangentKind),T=y.getData(),V=y.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.TangentKind,l,T,V,s,n,a);else{var d=16*l.verticesCount,v=this.createBufferView(0,s,d,"Tangents");s+=d,this.bufferViews.push(v);var x=this.createAccessor(this.bufferViews.length-1,"Tangent","VEC4",5126,l.verticesCount);this.accessors.push(x),h.attributes.TANGENT=this.accessors.length-1}}if(u.isVerticesDataPresent(e.VertexBuffer.ColorKind)){var A=u.getVertexBuffer(e.VertexBuffer.ColorKind),C=A.getData(),L=A.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.ColorKind,l,C,L,s,n,a);else{var d=16*l.verticesCount,v=this.createBufferView(0,s,d,"Colors");s+=d,this.bufferViews.push(v);var x=this.createAccessor(this.bufferViews.length-1,"Color","VEC4",5126,l.verticesCount);this.accessors.push(x),h.attributes.COLOR_0=this.accessors.length-1}}if(u.isVerticesDataPresent(e.VertexBuffer.UVKind)){var S=u.getVertexBuffer(e.VertexBuffer.UVKind),F=S.getData(),M=S.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.UVKind,l,F,M,s,n,a);else{var d=8*l.verticesCount,v=this.createBufferView(0,s,d,"Texture Coords0");s+=d,this.bufferViews.push(v);var x=this.createAccessor(this.bufferViews.length-1,"Texture Coords","VEC2",5126,l.verticesCount);this.accessors.push(x),h.attributes.TEXCOORD_0=this.accessors.length-1}}if(u.isVerticesDataPresent(e.VertexBuffer.UV2Kind)){var D=u.getVertexBuffer(e.VertexBuffer.UV2Kind),P=D.getData(),E=D.getStrideSize();if(n)s+=this.writeAttributeData(e.VertexBuffer.UV2Kind,l,P,E,s,n,a);else{var d=8*l.verticesCount,v=this.createBufferView(0,s,d,"Texture Coords 1");s+=d,this.bufferViews.push(v);var x=this.createAccessor(this.bufferViews.length-1,"Texture Coords","VEC2",5126,l.verticesCount);this.accessors.push(x),h.attributes.TEXCOORD_1=this.accessors.length-1}}if(u.getTotalIndices()>0)if(n){for(var R=u.getIndices(),N=l.indexStart,O=l.indexCount+N,U=s,G=N;G<O;G+=3)n.setUint32(U,R[G],!0),U+=4,n.setUint32(U,R[G+1],!0),U+=4,n.setUint32(U,R[G+2],!0),U+=4;var d=4*l.indexCount;s+=d}else{var K=l.indexCount,d=4*K,v=this.createBufferView(0,s,d,"Indices");s+=d,this.bufferViews.push(v);var x=this.createAccessor(this.bufferViews.length-1,"Indices","SCALAR",5125,K);this.accessors.push(x),h.indices=this.accessors.length-1}if(u.material)if(u.material instanceof e.StandardMaterial){var _=u.material,z={name:_.name};if(_.backFaceCulling||(z.doubleSided=!0),_.bumpTexture){var I=this.exportTexture(_.bumpTexture);I&&(z.normalTexture=I)}if(_.emissiveTexture){var Y=this.exportTexture(_.emissiveTexture);Y&&(z.emissiveTexture=Y),z.emissiveFactor=[1,1,1]}if(_.ambientTexture){var j=this.exportTexture(_.ambientTexture);j&&(z.occlusionTexture=j)}var k=t._GLTFMaterial.ConvertToGLTFPBRMetallicRoughness(_);z.pbrMetallicRoughness=k,this.materials.push(z),h.material=this.materials.length-1}else if(u.material instanceof e.PBRMetallicRoughnessMaterial){this.textures||(this.textures=new Array);var Q=u.material,k={};if(Q.baseColor&&(k.baseColorFactor=[Q.baseColor.r,Q.baseColor.g,Q.baseColor.b,Q.alpha]),void 0!==Q.baseTexture){var I=this.exportTexture(Q.baseTexture);null!==I&&(k.baseColorTexture=I),k.baseColorTexture}void 0!==Q.metallic&&(k.metallicFactor=Q.metallic),void 0!==Q.roughness&&(k.roughnessFactor=Q.roughness);var z={name:Q.name};if(Q.doubleSided&&(z.doubleSided=Q.doubleSided),Q.normalTexture){var I=this.exportTexture(Q.normalTexture);I&&(z.normalTexture=I)}if(Q.occlusionTexture){var I=this.exportTexture(Q.occlusionTexture);I&&(z.occlusionTexture=I,void 0!==Q.occlusionStrength&&(z.occlusionTexture.strength=Q.occlusionStrength))}if(Q.emissiveTexture){var I=this.exportTexture(Q.emissiveTexture);null!==I&&(z.emissiveTexture=I)}if(Q.emissiveColor.equals(new e.Color3(0,0,0))||(z.emissiveFactor=Q.emissiveColor.asArray()),Q.transparencyMode){var J=t._GLTFMaterial.GetAlphaMode(Q);"OPAQUE"!==J&&(z.alphaMode=J,"BLEND"===J&&(z.alphaCutoff=Q.alphaCutOff))}z.pbrMetallicRoughness=k,this.materials.push(z),h.material=this.materials.length-1}r.primitives.push(h)}return s},r.prototype.createScene=function(e,t,r){if(e.meshes.length>0){for(var i=e.meshes,s={nodes:new Array},a=0;a<i.length;++a)if(!this.options||void 0===this.options.shouldExportMesh||this.options.shouldExportMesh(i[a])){var n={mesh:-1},o=i[a],u=o.getScene().useRightHandedSystem;this.setNodeTransformation(n,o,u);var l={primitives:new Array};l.primitives=[],t=this.setPrimitiveAttributes(l,o,t,u,r),this.meshes.push(l),n.mesh=this.meshes.length-1,o.name&&(n.name=o.name),this.nodes.push(n),s.nodes.push(this.nodes.length-1)}this.scenes.push(s)}return t},r})();t._Exporter=r})(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 e.indexOf(t,e.length-t.length)!==-1}for(var t in this.glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var i=this.glTFFiles[t],s=void 0;e(t,".glb")?s={type:"model/gltf-binary"}:e(t,".bin")?s={type:"application/octet-stream"}:e(t,".gltf")?s={type:"model/gltf+json"}:e(t,".jpeg")?s={type:"image/jpeg"}:e(t,".png")&&(s={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([i],s)),r.click()}},e})();e._GLTFData=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function t(){}return t.ConvertToGLTFPBRMetallicRoughness=function(r){var i={diffuse:r.diffuseColor,opacity:r.alpha,specular:r.specularColor||e.Color3.Black(),glossiness:r.specularPower/256};r.specularTexture;var s=t._ConvertToMetallicRoughness(i);return{baseColorFactor:[s.baseColor.r,s.baseColor.g,s.baseColor.b,s.opacity],metallicFactor:s.metallic,roughnessFactor:s.roughness}},t._ConvertToMetallicRoughness=function(r){var i=r.diffuse,s=r.opacity,a=r.specular,n=r.glossiness,o=1-Math.max(a.r,Math.max(a.g,a.b)),u=t.PerceivedBrightness(i),l=t.PerceivedBrightness(a),h=t.SolveMetallic(u,l,o),c=o/(1-this.dielectricSpecular.r)/Math.max(1-h,this.epsilon),f=i.scale(c),g=a.subtract(this.dielectricSpecular.scale(1-h)).scale(1/Math.max(h,this.epsilon)),p=e.Color3.Lerp(f,g,h*h),d=new e.Color3;return p.clampToRef(0,1,d),{baseColor:d,opacity:s,metallic:h,roughness:1-n}},t.PerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},t.SolveMetallic=function(t,r,i){if(r<this.dielectricSpecular.r)return 0;var s=this.dielectricSpecular.r,a=t*i/(1-this.dielectricSpecular.r)+r-2*this.dielectricSpecular.r,n=this.dielectricSpecular.r-r,o=a*a-4*s*n;return e.Scalar.Clamp((-a+Math.sqrt(o))/(2*s))},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))throw new Error("Unsupported Babylon material type");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 console.warn("GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:throw new Error("Unsupported alpha mode "+i.transparencyMode)}},t.dielectricSpecular=new e.Color3(.04,.04,.04),t.epsilon=1e-6,t})();t._GLTFMaterial=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));
|