babylonjs-serializers
Advanced tools
Comparing version 3.2.0-alpha8 to 3.2.0-alpha9
@@ -1,1 +0,1 @@ | ||
var globalObject="undefined"!=typeof global?global:"undefined"!=typeof window?window:this,babylonDependency=globalObject&&globalObject.BABYLON||BABYLON||"undefined"!=typeof require&&require("babylonjs"),BABYLON=babylonDependency,__decorate=this&&this.__decorate||function(e,t,r,a){var i,n=arguments.length,s=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(n<3?i(s):n>3?i(t,r,s):i(t,r))||s);return n>3&&s&&Object.defineProperty(t,r,s),s},__extends=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])};return function(t,r){function a(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(a.prototype=r.prototype,new a)}})(),BABYLON;!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var n=[],s=1;r&&(a||(a="mat"),n.push("mtllib "+a+".mtl"));for(var o=0;o<t.length;o++){n.push("g object"+o),n.push("o object_"+o);var l=null;if(i){var u=e.Matrix.Translation(t[o].position.x,t[o].position.y,t[o].position.z);l=e.Matrix.Translation(-t[o].position.x,-t[o].position.y,-t[o].position.z),t[o].bakeTransformIntoVertices(u)}if(r){var f=t[o].material;f&&n.push("usemtl "+f.id)}var c=t[o].geometry;if(c){var h=c.getVerticesData("position"),p=c.getVerticesData("normal"),d=c.getVerticesData("uv"),g=c.getIndices(),m=0;if(h&&p&&d&&g){for(var x=0;x<h.length;x+=3)n.push("v "+h[x]+" "+h[x+1]+" "+h[x+2]),m++;for(x=0;x<p.length;x+=3)n.push("vn "+p[x]+" "+p[x+1]+" "+p[x+2]);for(x=0;x<d.length;x+=2)n.push("vt "+d[x]+" "+d[x+1]);for(x=0;x<g.length;x+=3)n.push("f "+(g[x+2]+s)+"/"+(g[x+2]+s)+"/"+(g[x+2]+s)+" "+(g[x+1]+s)+"/"+(g[x+1]+s)+"/"+(g[x+1]+s)+" "+(g[x]+s)+"/"+(g[x]+s)+"/"+(g[x]+s));i&&l&&t[o].bakeTransformIntoVertices(l),s+=m}}}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})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,""),n=new e.GLTF2._Exporter(t,a);if(t.isReady)return n._generateGLTF(i);throw new Error("glTF Serializer: Scene is not ready!")},t.GLB=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,""),n=new e.GLTF2._Exporter(t,a);if(t.isReady)return n._generateGLB(i);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.textures=new Array,this.imageData={},void 0!==t&&(this.options=t);var r=0;r=this.createScene(this.babylonScene,r,null),this.totalByteLength=r}return r.prototype.createBufferView=function(e,t,r,a,i){var n={buffer:e,byteLength:r};return t>0&&(n.byteOffset=t),i&&(n.name=i),a&&(n.byteStride=a),n},r.prototype.createAccessor=function(e,t,r,a,i,n,s,o){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return s&&(l.min=s),o&&(l.max=o),n&&(l.byteOffset=n),l},r.prototype.calculateMinMax=function(e,t,r,a,i){var n=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0],o=t+r;if(r>0)for(var l=t;l<o;++l)for(var u=a*l,f=1,c=0;c<a;++c){c!==a-1||i||(f=-1);var h=f*e[u];h<n[c]&&(n[c]=h),h>s[c]&&(s[c]=h),++u}return{min:n,max:s}},r.prototype.writeAttributeData=function(t,r,a,i,n,s,o){var l=n,u=r.length/a,f=0;switch(t){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var c=0;c<u;++c){var h=c*a;s.setFloat32(l,r[h],!0),l+=4,s.setFloat32(l,r[h+1],!0),l+=4,o?s.setFloat32(l,r[h+2],!0):s.setFloat32(l,-r[h+2],!0),l+=4}f=4*r.length;break;case e.VertexBuffer.TangentKind:for(var c=0;c<u;++c){var h=c*a;s.setFloat32(l,r[h],!0),l+=4,s.setFloat32(l,r[h+1],!0),l+=4,o?s.setFloat32(l,r[h+2],!0):s.setFloat32(l,-r[h+2],!0),l+=4,s.setFloat32(l,r[h+3],!0),l+=4}f=4*r.length;break;case e.VertexBuffer.ColorKind:for(var c=0;c<u;++c){var h=c*a;s.setFloat32(l,r[h],!0),l+=4,s.setFloat32(l,r[h+1],!0),l+=4,s.setFloat32(l,r[h+2],!0),l+=4,s.setFloat32(l,r[h+3],!0),l+=4}f=4*r.length;break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var c=0;c<u;++c){var h=c*a;s.setFloat32(l,r[h],!0),l+=4,s.setFloat32(l,r[h+1],!0),l+=4}f=4*r.length;break;default:throw new Error("Unsupported vertex buffer type: "+t)}return f},r.prototype.generateJSON=function(e,t,r){var a={byteLength:this.totalByteLength},i={asset:this.asset};if(a.byteLength>0&&(i.buffers=[a]),this.nodes&&0!==this.nodes.length&&(i.nodes=this.nodes),this.meshes&&0!==this.meshes.length&&(i.meshes=this.meshes),this.scenes&&0!==this.scenes.length&&(i.scenes=this.scenes,i.scene=0),this.bufferViews&&0!==this.bufferViews.length&&(i.bufferViews=this.bufferViews),this.accessors&&0!==this.accessors.length&&(i.accessors=this.accessors),this.materials&&0!==this.materials.length&&(i.materials=this.materials),this.textures&&0!==this.textures.length&&(i.textures=this.textures),this.images&&0!==this.images.length)if(e){i.images=[];for(var n=this.images.length,s=this.totalByteLength,o=0;o<n;++o){var l=this.images[o];if(void 0!==l.uri){var u=this.imageData[l.uri],f=l.uri.split(".")[0]+" image",c=this.createBufferView(0,s,u.data.length,void 0,f);s+=u.data.buffer.byteLength,this.bufferViews.push(c),l.bufferView=this.bufferViews.length-1,l.name=f,l.mimeType=u.mimeType,l.uri=void 0,i.images.push(l)}}a.byteLength=s}else i.images=this.images;return e||(a.uri=t+".bin"),r?JSON.stringify(i,null,2):JSON.stringify(i)},r.prototype._generateGLTF=function(t){var r=this.generateJSON(!1,t,!0),a=this.generateBinary(),i=new Blob([a],{type:"application/octet-stream"}),n=t+".gltf",s=t+".bin",o=new e._GLTFData;if(o.glTFFiles[n]=r,o.glTFFiles[s]=i,null!==this.imageData)for(var l in this.imageData)o.glTFFiles[l]=new Blob([this.imageData[l].data],{type:this.imageData[l].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),a=this.generateBinary(),i=t+".glb",n=r.length,s=0;for(var o in this.imageData)s+=this.imageData[o].data.byteLength;var l=this._getPadding(n),u=this._getPadding(a.byteLength),f=this._getPadding(s),c=28+n+l+a.byteLength+u+s+f,h=new ArrayBuffer(12),p=new DataView(h);p.setUint32(0,1179937895,!0),p.setUint32(4,2,!0),p.setUint32(8,c,!0);var d=new ArrayBuffer(8+n+l),g=new DataView(d);g.setUint32(0,n+l,!0),g.setUint32(4,1313821514,!0);for(var m=new Uint8Array(d,8),x=0;x<n;++x)m[x]=r.charCodeAt(x);for(var v=new Uint8Array(d,8+n),x=0;x<l;++x)v[x]=32;var b=new ArrayBuffer(8),B=new DataView(b);B.setUint32(0,a.byteLength+s+f,!0),B.setUint32(4,5130562,!0);for(var y=new ArrayBuffer(u),T=new Uint8Array(y),x=0;x<u;++x)T[x]=0;for(var w=new ArrayBuffer(f),V=new Uint8Array(w),x=0;x<f;++x)V[x]=0;var A=[h,d,b,a];for(var o in this.imageData)A.push(this.imageData[o].data.buffer);A.push(y),A.push(w);var F=new Blob(A,{type:"application/octet-stream"}),L=new e._GLTFData;return L.glTFFiles[i]=F,L},r.prototype.setNodeTransformation=function(t,r,a){0===r.position.x&&0===r.position.y&&0===r.position.z||(t.translation=a?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=a?r.scaling.asArray():[r.scaling.x,r.scaling.y,-r.scaling.z]);var i=e.Quaternion.RotationYawPitchRoll(r.rotation.y,r.rotation.x,r.rotation.z);r.rotationQuaternion&&(i=i.multiply(r.rotationQuaternion)),0===i.x&&0===i.y&&0===i.z&&1===i.w||(t.rotation=a?i.asArray():[-i.x,-i.y,i.z,i.w])},r.prototype.createBufferViewKind=function(t,r,a,i,n){var s=null,o=0;if(r instanceof e.Mesh?s=r:r instanceof e.InstancedMesh&&(s=r.sourceMesh),null!==s){var l=null,u=null,f=null,c=null;if(s.getVerticesDataKinds().indexOf(t)>-1)if(l=s.getVertexBuffer(t),u=l.getOffset(),f=l.getData(),c=l.getStrideSize(),n&&f)o=this.writeAttributeData(t,f,c,u,a,n,i),a+=o;else{var h=null;switch(t){case e.VertexBuffer.PositionKind:o=4*f.length,h="Position - "+s.name;break;case e.VertexBuffer.NormalKind:o=4*f.length,h="Normal - "+s.name;break;case e.VertexBuffer.TangentKind:o=4*f.length,h="Tangent - "+s.name;break;case e.VertexBuffer.ColorKind:o=4*f.length,h="Color - "+s.name;break;case e.VertexBuffer.UVKind:o=4*f.length,h="TexCoord 0 - "+s.name;break;case e.VertexBuffer.UV2Kind:o=4*f.length,h="TexCoord 1 - "+s.name;break;default:e.Tools.Warn("Unsupported VertexBuffer kind: "+t)}if(null!==h){var p=this.createBufferView(0,a,o,4*c,h);a+=o,this.bufferViews.push(p)}}}return o},r.prototype.setPrimitiveAttributes=function(t,r,a,i,n){var s=null;r instanceof e.Mesh?s=r:r instanceof e.InstancedMesh&&(s=r.sourceMesh);var o=null,l=null,u=null,f=null,c=null,h=null;if(null!==s&&(s.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.PositionKind,r,a,i,n),o=this.bufferViews.length-1),s.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.NormalKind,r,a,i,n),l=this.bufferViews.length-1),s.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.ColorKind,r,a,i,n),u=this.bufferViews.length-1),s.isVerticesDataPresent(e.VertexBuffer.TangentKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.TangentKind,r,a,i,n),u=this.bufferViews.length-1),s.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.UVKind,r,a,i,n),f=this.bufferViews.length-1),s.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(a+=this.createBufferViewKind(e.VertexBuffer.UV2Kind,r,a,i,n),c=this.bufferViews.length-1),s.getTotalIndices()>0)){var p=s.getIndices();if(n){for(var d=p.length,g=a,m=0;m<d;++m)n.setUint32(g,p[m],!0),g+=4;a=g}else{var x=4*p.length,v=this.createBufferView(0,a,x,void 0,"Indices - "+s.name);a+=x,this.bufferViews.push(v),h=this.bufferViews.length-1}}for(var b=0;b<r.subMeshes.length;++b){var B=r.subMeshes[b],y={attributes:{}};if(null!==s){if(!n){if(null!==o){var T=s.getVertexBuffer(e.VertexBuffer.PositionKind),w=T.getData(),V=T.getStrideSize(),A=this.calculateMinMax(w,0,w.length/V,V,i),F=this.createAccessor(o,"Position","VEC3",5126,w.length/V,0,A.min,A.max);this.accessors.push(F),y.attributes.POSITION=this.accessors.length-1}if(null!==l){var L=s.getVertexBuffer(e.VertexBuffer.NormalKind),S=L.getData(),M=L.getStrideSize(),F=this.createAccessor(l,"Normal","VEC3",5126,S.length/M);this.accessors.push(F),y.attributes.NORMAL=this.accessors.length-1}var F;if(null!==u){var C=s.getVertexBuffer(e.VertexBuffer.ColorKind),O=C.getData(),P=C.getStrideSize(),F=this.createAccessor(u,"Color","VEC4",5126,O.length/P);this.accessors.push(F),y.attributes.COLOR_0=this.accessors.length-1}if(null!==f){var D=s.getVertexBuffer(e.VertexBuffer.UVKind),E=D.getData(),N=D.getStrideSize(),F=this.createAccessor(f,"Texture Coords 0","VEC2",5126,E.length/N);this.accessors.push(F),y.attributes.TEXCOORD_0=this.accessors.length-1}if(null!==c){var _=s.getVertexBuffer(e.VertexBuffer.UV2Kind),K=_.getData(),R=_.getStrideSize(),F=this.createAccessor(c,"Texture Coords 1","VEC2",5126,K.length/R);this.accessors.push(F),y.attributes.TEXCOORD_1=this.accessors.length-1}if(h){var F=this.createAccessor(h,"Indices","SCALAR",5125,B.indexCount,4*B.indexStart);this.accessors.push(F),y.indices=this.accessors.length-1}}if(s.material)if(s.material instanceof e.StandardMaterial||s.material instanceof e.PBRMetallicRoughnessMaterial){var U=r.getScene().materials.indexOf(s.material);y.material=U}else if(s.material instanceof e.MultiMaterial){var G=s.material,j=G.subMaterials[B.materialIndex];if(null!==j){var U=r.getScene().materials.indexOf(j);y.material=U}}else e.Tools.Warn("Material type "+s.material.getClassName()+" for material "+s.material.name+" is not yet implemented in glTF serializer.");t.primitives.push(y)}}return a},r.prototype.createScene=function(e,r,a){if(e.meshes.length>0){var i=e.meshes,n={nodes:new Array};null==a&&t._GLTFMaterial.ConvertMaterialsToGLTF(e.materials,"image/jpeg",this.images,this.textures,this.materials,this.imageData,!0);for(var s=0;s<i.length;++s)if(!this.options||void 0===this.options.shouldExportMesh||this.options.shouldExportMesh(i[s])){var o={mesh:-1},l=i[s],u=l.getScene().useRightHandedSystem;this.setNodeTransformation(o,l,u);var f={primitives:new Array};f.primitives=[],r=this.setPrimitiveAttributes(f,l,r,u,a),this.meshes.push(f),o.mesh=this.meshes.length-1,l.name&&(o.name=l.name),this.nodes.push(o),n.nodes.push(this.nodes.length-1)}this.scenes.push(n)}return r},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-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.ConvertMaterialsToGLTF=function(r,a,i,n,s,o,l){for(var u=0;u<r.length;++u){var f=r[u];f instanceof e.StandardMaterial?t.ConvertStandardMaterial(f,a,i,n,s,o,l):f instanceof e.PBRMetallicRoughnessMaterial&&t.ConvertPBRMetallicRoughnessMaterial(f,a,i,n,s,o,l)}},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),s=new e.Vector2(1300,.1),o=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/s.x,.333333),a.y,i.y,n.y,s.y)})(u);return{baseColorFactor:[o.r,o.g,o.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,s=r*i/(1-t.dielectricSpecular.r)+a-2*t.dielectricSpecular.r,o=t.dielectricSpecular.r-a,l=s*s-4*n*o;return e.Scalar.Clamp((-s+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))throw new Error("Unsupported Babylon material type");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:throw new Error("Unsupported alpha mode "+a.transparencyMode)}},t.ConvertStandardMaterial=function(r,a,i,n,s,o,l){e.Tools.Warn(r.name+": Standard Material is currently not fully supported/implemented in glTF serializer");var u=t.ConvertToGLTFPBRMetallicRoughness(r),f={name:r.name};if(r.backFaceCulling&&(r.twoSidedLighting||e.Tools.Warn(r.name+": Back-face culling enabled and two-sided lighting disabled is not supported in glTF."),f.doubleSided=!0),l){if(r.diffuseTexture){var c=t.ExportTexture(r.diffuseTexture,a,i,n,o);null!=c&&(u.baseColorTexture=c)}if(r.bumpTexture){var c=t.ExportTexture(r.bumpTexture,a,i,n,o);c&&(f.normalTexture=c)}if(r.emissiveTexture){var h=t.ExportTexture(r.emissiveTexture,a,i,n,o);h&&(f.emissiveTexture=h),f.emissiveFactor=[1,1,1]}if(r.ambientTexture){var p=t.ExportTexture(r.ambientTexture,a,i,n,o);p&&(f.occlusionTexture=p)}}(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?f.alphaMode="BLEND":e.Tools.Warn(r.name+": glTF 2.0 does not support alpha mode: "+r.alphaMode.toString())),f.pbrMetallicRoughness=u,s.push(f)},t.ConvertPBRMetallicRoughnessMaterial=function(e,r,a,i,n,s,o){var l={};e.baseColor&&(l.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,e.alpha]),null!=e.metallic&&(l.metallicFactor=e.metallic),null!=e.roughness&&(l.roughnessFactor=e.roughness);var u={name:e.name};if(e.doubleSided&&(u.doubleSided=e.doubleSided),o){if(null!=e.baseTexture){var f=t.ExportTexture(e.baseTexture,r,a,i,s);null!=f&&(l.baseColorTexture=f)}if(e.normalTexture){var f=t.ExportTexture(e.normalTexture,r,a,i,s);f&&(u.normalTexture=f)}if(e.occlusionTexture){var f=t.ExportTexture(e.occlusionTexture,r,a,i,s);f&&(u.occlusionTexture=f,null!=e.occlusionStrength&&(u.occlusionTexture.strength=e.occlusionStrength))}if(e.emissiveTexture){var f=t.ExportTexture(e.emissiveTexture,r,a,i,s);null!=f&&(u.emissiveTexture=f)}}if(e.emissiveColor.equalsFloats(0,0,0)&&(u.emissiveFactor=e.emissiveColor.asArray()),null!=e.transparencyMode){var c=t.GetAlphaMode(e);"OPAQUE"!==c&&(u.alphaMode=c,"BLEND"===c&&(u.alphaCutoff=e.alphaCutOff))}u.pbrMetallicRoughness=l,n.push(u)},t.ExportTexture=function(t,r,a,i,n){var s=null,o={source:a.length},l="texture_"+(i.length-1).toString(),u=t.getInternalTexture();null!=u&&(l=u.url),l=e.Tools.GetFilename(l);var f=l.split(".")[0],c="";"image/jpeg"===r?c=".jpg":"image/png"===r?c=".png":e.Tools.Error("Unsupported mime type "+r),l=f+c;var h=t.readPixels(),p=document.createElement("canvas");p.id="ImageCanvas";var d=p.getContext("2d"),g=t.getSize();p.width=g.width,p.height=g.height;var m=d.createImageData(g.width,g.height);m.data.set(h),d.putImageData(m,0,0);for(var x=p.toDataURL(r),v=atob(x.split(",")[1]),b=new Uint8Array(v.length),B=0;B<v.length;++B)b[B]=v.charCodeAt(B);var y={data:b,mimeType:r};if(n[l]=y,"image/jpeg"===r){for(var T={uri:l},w=-1,B=0;B<a.length;++B)if(a[B].uri===l){w=B;break}-1===w?(a.push(T),o.source=a.length-1,i.push({source:a.length-1}),s={index:a.length-1}):(o.source=w,s={index:w})}return s},t.dielectricSpecular=new e.Color3(.04,.04,.04),t.maxSpecularPower=1024,t})();t._GLTFMaterial=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={})),(function(e,t){var r=t();e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=r:"function"==typeof define&&define.amd?define(["BJSSerializers"],t):"object"==typeof exports?exports.BJSSerializers=r:e.BABYLON=r)})(this,(function(){return BABYLON})); | ||
var globalObject="undefined"!=typeof global?global:"undefined"!=typeof window?window:this,babylonDependency=globalObject&&globalObject.BABYLON||BABYLON||"undefined"!=typeof require&&require("babylonjs"),BABYLON=babylonDependency,__decorate=this&&this.__decorate||function(e,t,r,a){var i,n=arguments.length,s=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(s=(n<3?i(s):n>3?i(t,r,s):i(t,r))||s);return n>3&&s&&Object.defineProperty(t,r,s),s},__extends=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])};return function(t,r){function a(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(a.prototype=r.prototype,new a)}})(),BABYLON;!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var n=[],s=1;r&&(a||(a="mat"),n.push("mtllib "+a+".mtl"));for(var o=0;o<t.length;o++){n.push("g object"+o),n.push("o object_"+o);var l=null;if(i){var u=e.Matrix.Translation(t[o].position.x,t[o].position.y,t[o].position.z);l=e.Matrix.Translation(-t[o].position.x,-t[o].position.y,-t[o].position.z),t[o].bakeTransformIntoVertices(u)}if(r){var c=t[o].material;c&&n.push("usemtl "+c.id)}var f=t[o].geometry;if(f){var h=f.getVerticesData("position"),d=f.getVerticesData("normal"),p=f.getVerticesData("uv"),g=f.getIndices(),m=0;if(h&&d&&p&&g){for(var y=0;y<h.length;y+=3)n.push("v "+h[y]+" "+h[y+1]+" "+h[y+2]),m++;for(y=0;y<d.length;y+=3)n.push("vn "+d[y]+" "+d[y+1]+" "+d[y+2]);for(y=0;y<p.length;y+=2)n.push("vt "+p[y]+" "+p[y+1]);for(y=0;y<g.length;y+=3)n.push("f "+(g[y+2]+s)+"/"+(g[y+2]+s)+"/"+(g[y+2]+s)+" "+(g[y+1]+s)+"/"+(g[y+1]+s)+"/"+(g[y+1]+s)+" "+(g[y]+s)+"/"+(g[y]+s)+"/"+(g[y]+s));i&&l&&t[o].bakeTransformIntoVertices(l),s+=m}}}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})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,""),n=new e.GLTF2._Exporter(t,a);if(t.isReady)return n._generateGLTF(i);throw new Error("glTF Serializer: Scene is not ready!")},t.GLB=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,""),n=new e.GLTF2._Exporter(t,a);if(t.isReady)return n._generateGLB(i);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.textures=new Array,this.imageData={},this.convertToRightHandedSystem=!this.babylonScene.useRightHandedSystem,t&&(this.options=t)}return r.prototype.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},r.prototype.createAccessor=function(e,t,r,a,i,n,s,o){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return s&&(l.min=s),o&&(l.max=o),n&&(l.byteOffset=n),l},r.prototype.calculateMinMaxPositions=function(t,a,i){var n=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0],o=a+i;if(i)for(var l=a;l<o;++l)for(var u=3*l,c=e.Vector3.FromArray(t,u),f=this.convertToRightHandedSystem?r.GetRightHandedVector3(c).asArray():c.asArray(),h=0;h<3;++h){var d=f[h];d<n[h]&&(n[h]=d),d>s[h]&&(s[h]=d),++u}return{min:n,max:s}},r.GetRightHandedVector3=function(t){return new e.Vector3(t.x,t.y,-t.z)},r.GetRightHandedVector4=function(t){return new e.Vector4(t.x,t.y,-t.z,-t.w)},r.GetRightHandedQuaternion=function(t){return new e.Quaternion(-t.x,-t.y,t.z,t.w)},r.prototype.writeAttributeData=function(t,a,i,n,s,o){for(var l=s,u=a.length/i,c=0;c<u;++c){var f=c*i,h=[];if(t===e.VertexBuffer.PositionKind||t===e.VertexBuffer.NormalKind){var d=e.Vector3.FromArray(a,f);h=this.convertToRightHandedSystem?r.GetRightHandedVector3(d).asArray():d.asArray()}else if(t===e.VertexBuffer.TangentKind||t===e.VertexBuffer.ColorKind){var d=e.Vector4.FromArray(a,f);h=this.convertToRightHandedSystem&&t!==e.VertexBuffer.ColorKind?r.GetRightHandedVector4(d).asArray():d.asArray()}else t===e.VertexBuffer.UVKind||t===e.VertexBuffer.UV2Kind?h=[a[f],a[f+1]]:e.Tools.Warn("Unsupported Vertex Buffer Type: "+t);for(var p=0;p<h.length;++p)o.setFloat32(l,h[p],!0),l+=4}return 4*a.length},r.prototype.generateJSON=function(e,t,r){var a={byteLength:this.totalByteLength},i={asset:this.asset};if(a.byteLength&&(i.buffers=[a]),this.nodes&&this.nodes.length&&(i.nodes=this.nodes),this.meshes&&this.meshes.length&&(i.meshes=this.meshes),this.scenes&&this.scenes.length&&(i.scenes=this.scenes,i.scene=0),this.bufferViews&&this.bufferViews.length&&(i.bufferViews=this.bufferViews),this.accessors&&this.accessors.length&&(i.accessors=this.accessors),this.materials&&this.materials.length&&(i.materials=this.materials),this.textures&&this.textures.length&&(i.textures=this.textures),this.images&&this.images.length)if(e){i.images=[];for(var n=this.images.length,s=this.totalByteLength,o=0;o<n;++o){var l=this.images[o];if(l.uri){var u=this.imageData[l.uri],c=l.uri.split(".")[0]+" image",f=this.createBufferView(0,s,u.data.length,void 0,c);s+=u.data.buffer.byteLength,this.bufferViews.push(f),l.bufferView=this.bufferViews.length-1,l.name=c,l.mimeType=u.mimeType,l.uri=void 0,i.images.push(l)}}a.byteLength=s}else i.images=this.images;return e||(a.uri=t+".bin"),r?JSON.stringify(i,null,2):JSON.stringify(i)},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",s=t+".bin",o=new e._GLTFData;if(o.glTFFiles[n]=a,o.glTFFiles[s]=i,this.imageData)for(var l in this.imageData)o.glTFFiles[l]=new Blob([this.imageData[l].data],{type:this.imageData[l].mimeType});return o},r.prototype.generateBinary=function(){var e=0;return e=this.createScene(this.babylonScene,e),this.binaryBuffer},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,s=0;for(var o in this.imageData)s+=this.imageData[o].data.byteLength;var l=this._getPadding(n),u=this._getPadding(r.byteLength),c=this._getPadding(s),f=28+n+l+r.byteLength+u+s+c,h=new ArrayBuffer(12),d=new DataView(h);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,f,!0);var p=new ArrayBuffer(8+n+l),g=new DataView(p);g.setUint32(0,n+l,!0),g.setUint32(4,1313821514,!0);for(var m=new Uint8Array(p,8),y=0;y<n;++y)m[y]=a.charCodeAt(y);for(var v=new Uint8Array(p,8+n),y=0;y<l;++y)v[y]=32;var b=new ArrayBuffer(8),x=new DataView(b);x.setUint32(0,r.byteLength+s+c,!0),x.setUint32(4,5130562,!0);for(var T=new ArrayBuffer(u),B=new Uint8Array(T),y=0;y<u;++y)B[y]=0;for(var w=new ArrayBuffer(c),A=new Uint8Array(w),y=0;y<c;++y)A[y]=0;var V=[h,p,b,r];for(var o in this.imageData)V.push(this.imageData[o].data.buffer);V.push(T),V.push(w);var L=new Blob(V,{type:"application/octet-stream"}),M=new e._GLTFData;return M.glTFFiles[i]=L,M},r.prototype.setNodeTransformation=function(t,a){0===a.position.x&&0===a.position.y&&0===a.position.z||(t.translation=this.convertToRightHandedSystem?r.GetRightHandedVector3(a.position).asArray():a.position.asArray()),1===a.scaling.x&&1===a.scaling.y&&1===a.scaling.z||(t.scale=a.scaling.asArray());var i=e.Quaternion.RotationYawPitchRoll(a.rotation.y,a.rotation.x,a.rotation.z);a.rotationQuaternion&&(i=i.multiply(a.rotationQuaternion)),0===i.x&&0===i.y&&0===i.z&&1===i.w||(t.rotation=this.convertToRightHandedSystem?r.GetRightHandedQuaternion(i).asArray():i.asArray())},r.prototype.createBufferViewKind=function(t,r,a,i){var n=null,s=0;if(r instanceof e.Mesh?n=r:r instanceof e.InstancedMesh&&(n=r.sourceMesh),n){var o=null,l=null,u=null,c=null;if(n.isVerticesDataPresent(t)&&(o=n.getVertexBuffer(t))&&(l=o.getOffset(),u=o.getData()))if(c=o.getStrideSize(),i&&u)s=this.writeAttributeData(t,u,c,l,a,i),a+=s;else{s=4*u.length;var f=this.createBufferView(0,a,s,4*c,t+" - "+n.name);a+=s,this.bufferViews.push(f)}}return s},r.prototype.setPrimitiveAttributes=function(t,r,a,i){var n=null;r instanceof e.Mesh?n=r:r instanceof e.InstancedMesh&&(n=r.sourceMesh);var s=[{kind:e.VertexBuffer.PositionKind,accessorType:"VEC3"},{kind:e.VertexBuffer.NormalKind,accessorType:"VEC3"},{kind:e.VertexBuffer.ColorKind,accessorType:"VEC4"},{kind:e.VertexBuffer.TangentKind,accessorType:"VEC4"},{kind:e.VertexBuffer.UVKind,accessorType:"VEC2"},{kind:e.VertexBuffer.UV2Kind,accessorType:"VEC2"}],o=null;if(n){for(var l=0,u=s;l<u.length;l++){var c=u[l],f=c.kind;n.isVerticesDataPresent(f)&&(a+=this.createBufferViewKind(f,r,a,i),c.bufferViewIndex=this.bufferViews.length-1)}if(n.getTotalIndices()){var h=n.getIndices();if(h)if(i){for(var d=h.length,p=a,g=0;g<d;++g)i.setUint32(p,h[g],!0),p+=4;a=p}else{var m=4*h.length,y=this.createBufferView(0,a,m,void 0,"Indices - "+n.name);a+=m,this.bufferViews.push(y),o=this.bufferViews.length-1}}if(r.subMeshes)for(var v=0,b=r.subMeshes;v<b.length;v++){var x=b[v],T={attributes:{}};if(!i){for(var B=0,w=s;B<w.length;B++){var c=w[B],f=c.kind;if(n.isVerticesDataPresent(f)){var A=n.getVertexBuffer(f);if(A){var V=A.getData();if(V){var L=A.getStrideSize(),M=void 0,F=null,O=null,S=c.bufferViewIndex;if(void 0!=S){f==e.VertexBuffer.PositionKind&&(M=this.calculateMinMaxPositions(V,0,V.length/L),F=M.min,O=M.max);var C=this.createAccessor(S,f+" - "+r.name,c.accessorType,5126,V.length/L,0,F,O);switch(this.accessors.push(C),f){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: "+f)}}}}}}if(o){var C=this.createAccessor(o,"indices - "+r.name,"SCALAR",5125,x.indexCount,4*x.indexStart,null,null);this.accessors.push(C),T.indices=this.accessors.length-1}}if(n.material)if(n.material instanceof e.StandardMaterial||n.material instanceof e.PBRMetallicRoughnessMaterial){var R=r.getScene().materials.indexOf(n.material);T.material=R}else if(n.material instanceof e.MultiMaterial){var E=n.material,N=E.subMaterials[x.materialIndex];if(N){var R=r.getScene().materials.indexOf(N);T.material=R}}else e.Tools.Warn("Material type "+n.material.getClassName()+" for material "+n.material.name+" is not yet implemented in glTF serializer.");t.primitives.push(T)}}return a},r.prototype.createScene=function(e,r){if(e.meshes.length){var a=e.meshes,i={nodes:new Array};t._GLTFMaterial.ConvertMaterialsToGLTF(e.materials,"image/jpeg",this.images,this.textures,this.materials,this.imageData,!0);var n=this.createNodeMap(e,r);this.nodeMap=n.nodeMap,this.totalByteLength=n.byteOffset,this.binaryBuffer=new ArrayBuffer(this.totalByteLength);for(var s=new DataView(this.binaryBuffer),o=0;o<a.length;++o)if(!this.options||void 0==this.options.shouldExportMesh||this.options.shouldExportMesh(a[o])){var l=a[o],u=this.nodeMap[l.uniqueId],c=this.nodes[u];l.parent||i.nodes.push(u);var f=l.getDescendants(!0);if(!c.children&&f&&f.length){c.children=[];for(var h=0,d=f;h<d.length;h++){var p=d[h];c.children.push(this.nodeMap[p.uniqueId])}}var g={primitives:new Array};r=this.setPrimitiveAttributes(g,l,r,s)}this.scenes.push(i)}return r},r.prototype.createNodeMap=function(e,t){for(var r={},a=0,i=e.meshes;a<i.length;a++){var n=i[a],s=this.createNode(n,t,null);this.nodes.push(s.node),r[n.uniqueId]=this.nodes.length-1,t=s.byteOffset}return{nodeMap:r,byteOffset:t}},r.prototype.createNode=function(e,t,r){var a={};e.name&&(a.name=e.name),this.setNodeTransformation(a,e);var i={primitives:new Array};return i.primitives=[],t=this.setPrimitiveAttributes(i,e,t,r),i.primitives.length&&(this.meshes.push(i),a.mesh=this.meshes.length-1),{node:a,byteOffset: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-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.ConvertMaterialsToGLTF=function(r,a,i,n,s,o,l){for(var u=0;u<r.length;++u){var c=r[u];c instanceof e.StandardMaterial?t.ConvertStandardMaterial(c,a,i,n,s,o,l):c instanceof e.PBRMetallicRoughnessMaterial&&t.ConvertPBRMetallicRoughnessMaterial(c,a,i,n,s,o,l)}},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),s=new e.Vector2(1300,.1),o=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/s.x,.333333),a.y,i.y,n.y,s.y)})(u);return{baseColorFactor:[o.r,o.g,o.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,s=r*i/(1-t.dielectricSpecular.r)+a-2*t.dielectricSpecular.r,o=t.dielectricSpecular.r-a,l=s*s-4*n*o;return e.Scalar.Clamp((-s+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))throw new Error("Unsupported Babylon material type");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:throw new Error("Unsupported alpha mode "+a.transparencyMode)}},t.ConvertStandardMaterial=function(r,a,i,n,s,o,l){e.Tools.Warn(r.name+": Standard Material is currently not fully supported/implemented in glTF serializer");var u=t.ConvertToGLTFPBRMetallicRoughness(r),c={name:r.name};if(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),l){if(r.diffuseTexture){var f=t.ExportTexture(r.diffuseTexture,a,i,n,o);null!=f&&(u.baseColorTexture=f)}if(r.bumpTexture){var f=t.ExportTexture(r.bumpTexture,a,i,n,o);f&&(c.normalTexture=f)}if(r.emissiveTexture){var h=t.ExportTexture(r.emissiveTexture,a,i,n,o);h&&(c.emissiveTexture=h),c.emissiveFactor=[1,1,1]}if(r.ambientTexture){var d=t.ExportTexture(r.ambientTexture,a,i,n,o);d&&(c.occlusionTexture=d)}}(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())),c.pbrMetallicRoughness=u,s.push(c)},t.ConvertPBRMetallicRoughnessMaterial=function(e,r,a,i,n,s,o){var l={};e.baseColor&&(l.baseColorFactor=[e.baseColor.r,e.baseColor.g,e.baseColor.b,e.alpha]),null!=e.metallic&&(l.metallicFactor=e.metallic),null!=e.roughness&&(l.roughnessFactor=e.roughness);var u={name:e.name};if(e.doubleSided&&(u.doubleSided=e.doubleSided),o){if(null!=e.baseTexture){var c=t.ExportTexture(e.baseTexture,r,a,i,s);null!=c&&(l.baseColorTexture=c)}if(e.normalTexture){var c=t.ExportTexture(e.normalTexture,r,a,i,s);c&&(u.normalTexture=c)}if(e.occlusionTexture){var c=t.ExportTexture(e.occlusionTexture,r,a,i,s);c&&(u.occlusionTexture=c,null!=e.occlusionStrength&&(u.occlusionTexture.strength=e.occlusionStrength))}if(e.emissiveTexture){var c=t.ExportTexture(e.emissiveTexture,r,a,i,s);null!=c&&(u.emissiveTexture=c)}}if(e.emissiveColor.equalsFloats(0,0,0)&&(u.emissiveFactor=e.emissiveColor.asArray()),null!=e.transparencyMode){var f=t.GetAlphaMode(e);"OPAQUE"!==f&&(u.alphaMode=f,"BLEND"===f&&(u.alphaCutoff=e.alphaCutOff))}u.pbrMetallicRoughness=l,n.push(u)},t.ExportTexture=function(t,r,a,i,n){var s=null,o={source:a.length},l="texture_"+(i.length-1).toString(),u=t.getInternalTexture();null!=u&&(l=u.url),l=e.Tools.GetFilename(l);var c=l.split(".")[0],f="";"image/jpeg"===r?f=".jpg":"image/png"===r?f=".png":e.Tools.Error("Unsupported mime type "+r),l=c+f;var h=t.readPixels(),d=document.createElement("canvas");d.id="ImageCanvas";var p=d.getContext("2d"),g=t.getSize();d.width=g.width,d.height=g.height;var m=p.createImageData(g.width,g.height);m.data.set(h),p.putImageData(m,0,0);for(var y=d.toDataURL(r),v=atob(y.split(",")[1]),b=new Uint8Array(v.length),x=0;x<v.length;++x)b[x]=v.charCodeAt(x);var T={data:b,mimeType:r};if(n[l]=T,"image/jpeg"===r){for(var B={uri:l},w=-1,x=0;x<a.length;++x)if(a[x].uri===l){w=x;break}-1===w?(a.push(B),o.source=a.length-1,i.push({source:a.length-1}),s={index:a.length-1}):(o.source=w,s={index:w})}return s},t.dielectricSpecular=new e.Color3(.04,.04,.04),t.maxSpecularPower=1024,t})();t._GLTFMaterial=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={})),(function(e,t){var r=t();"object"==typeof exports&&"object"==typeof module?module.exports=r:"function"==typeof define&&define.amd?define("babylonjs-serializers",["BABYLON"],t):"object"==typeof exports?exports["babylonjs-serializers"]=r:e.BABYLON=r})(this,(function(){return BABYLON})); |
/// <reference types="babylonjs"/> | ||
/// <reference types="babylonjs-gltf2interface"/> | ||
@@ -7,252 +8,3 @@ | ||
} | ||
declare module BABYLON.GLTF2 { | ||
const enum AccessorComponentType { | ||
BYTE = 5120, | ||
UNSIGNED_BYTE = 5121, | ||
SHORT = 5122, | ||
UNSIGNED_SHORT = 5123, | ||
UNSIGNED_INT = 5125, | ||
FLOAT = 5126, | ||
} | ||
const enum AccessorType { | ||
SCALAR = "SCALAR", | ||
VEC2 = "VEC2", | ||
VEC3 = "VEC3", | ||
VEC4 = "VEC4", | ||
MAT2 = "MAT2", | ||
MAT3 = "MAT3", | ||
MAT4 = "MAT4", | ||
} | ||
const enum AnimationChannelTargetPath { | ||
TRANSLATION = "translation", | ||
ROTATION = "rotation", | ||
SCALE = "scale", | ||
WEIGHTS = "weights", | ||
} | ||
const enum AnimationSamplerInterpolation { | ||
LINEAR = "LINEAR", | ||
STEP = "STEP", | ||
CUBICSPLINE = "CUBICSPLINE", | ||
} | ||
const enum CameraType { | ||
PERSPECTIVE = "perspective", | ||
ORTHOGRAPHIC = "orthographic", | ||
} | ||
const enum ImageMimeType { | ||
JPEG = "image/jpeg", | ||
PNG = "image/png", | ||
} | ||
const enum MaterialAlphaMode { | ||
OPAQUE = "OPAQUE", | ||
MASK = "MASK", | ||
BLEND = "BLEND", | ||
} | ||
const enum MeshPrimitiveMode { | ||
POINTS = 0, | ||
LINES = 1, | ||
LINE_LOOP = 2, | ||
LINE_STRIP = 3, | ||
TRIANGLES = 4, | ||
TRIANGLE_STRIP = 5, | ||
TRIANGLE_FAN = 6, | ||
} | ||
const enum TextureMagFilter { | ||
NEAREST = 9728, | ||
LINEAR = 9729, | ||
} | ||
const enum TextureMinFilter { | ||
NEAREST = 9728, | ||
LINEAR = 9729, | ||
NEAREST_MIPMAP_NEAREST = 9984, | ||
LINEAR_MIPMAP_NEAREST = 9985, | ||
NEAREST_MIPMAP_LINEAR = 9986, | ||
LINEAR_MIPMAP_LINEAR = 9987, | ||
} | ||
const enum TextureWrapMode { | ||
CLAMP_TO_EDGE = 33071, | ||
MIRRORED_REPEAT = 33648, | ||
REPEAT = 10497, | ||
} | ||
interface IProperty { | ||
extensions?: { | ||
[key: string]: any; | ||
}; | ||
extras?: any; | ||
} | ||
interface IChildRootProperty extends IProperty { | ||
name?: string; | ||
} | ||
interface IAccessorSparseIndices extends IProperty { | ||
bufferView: number; | ||
byteOffset?: number; | ||
componentType: AccessorComponentType; | ||
} | ||
interface IAccessorSparseValues extends IProperty { | ||
bufferView: number; | ||
byteOffset?: number; | ||
} | ||
interface IAccessorSparse extends IProperty { | ||
count: number; | ||
indices: IAccessorSparseIndices; | ||
values: IAccessorSparseValues; | ||
} | ||
interface IAccessor extends IChildRootProperty { | ||
bufferView?: number; | ||
byteOffset?: number; | ||
componentType: AccessorComponentType; | ||
normalized?: boolean; | ||
count: number; | ||
type: AccessorType; | ||
max?: number[]; | ||
min?: number[]; | ||
sparse?: IAccessorSparse; | ||
} | ||
interface IAnimationChannel extends IProperty { | ||
sampler: number; | ||
target: IAnimationChannelTarget; | ||
} | ||
interface IAnimationChannelTarget extends IProperty { | ||
node: number; | ||
path: AnimationChannelTargetPath; | ||
} | ||
interface IAnimationSampler extends IProperty { | ||
input: number; | ||
interpolation?: AnimationSamplerInterpolation; | ||
output: number; | ||
} | ||
interface IAnimation extends IChildRootProperty { | ||
channels: IAnimationChannel[]; | ||
samplers: IAnimationSampler[]; | ||
} | ||
interface IAsset extends IChildRootProperty { | ||
copyright?: string; | ||
generator?: string; | ||
version: string; | ||
minVersion?: string; | ||
} | ||
interface IBuffer extends IChildRootProperty { | ||
uri?: string; | ||
byteLength: number; | ||
} | ||
interface IBufferView extends IChildRootProperty { | ||
buffer: number; | ||
byteOffset?: number; | ||
byteLength: number; | ||
byteStride?: number; | ||
} | ||
interface ICameraOrthographic extends IProperty { | ||
xmag: number; | ||
ymag: number; | ||
zfar: number; | ||
znear: number; | ||
} | ||
interface ICameraPerspective extends IProperty { | ||
aspectRatio: number; | ||
yfov: number; | ||
zfar: number; | ||
znear: number; | ||
} | ||
interface ICamera extends IChildRootProperty { | ||
orthographic?: ICameraOrthographic; | ||
perspective?: ICameraPerspective; | ||
type: CameraType; | ||
} | ||
interface IImage extends IChildRootProperty { | ||
uri?: string; | ||
mimeType?: ImageMimeType; | ||
bufferView?: number; | ||
} | ||
interface IMaterialNormalTextureInfo extends ITextureInfo { | ||
scale?: number; | ||
} | ||
interface IMaterialOcclusionTextureInfo extends ITextureInfo { | ||
strength?: number; | ||
} | ||
interface IMaterialPbrMetallicRoughness { | ||
baseColorFactor?: number[]; | ||
baseColorTexture?: ITextureInfo; | ||
metallicFactor?: number; | ||
roughnessFactor?: number; | ||
metallicRoughnessTexture?: ITextureInfo; | ||
} | ||
interface IMaterial extends IChildRootProperty { | ||
pbrMetallicRoughness?: IMaterialPbrMetallicRoughness; | ||
normalTexture?: IMaterialNormalTextureInfo; | ||
occlusionTexture?: IMaterialOcclusionTextureInfo; | ||
emissiveTexture?: ITextureInfo; | ||
emissiveFactor?: number[]; | ||
alphaMode?: MaterialAlphaMode; | ||
alphaCutoff?: number; | ||
doubleSided?: boolean; | ||
} | ||
interface IMeshPrimitive extends IProperty { | ||
attributes: { | ||
[name: string]: number; | ||
}; | ||
indices?: number; | ||
material?: number; | ||
mode?: MeshPrimitiveMode; | ||
targets?: { | ||
[name: string]: number; | ||
}[]; | ||
} | ||
interface IMesh extends IChildRootProperty { | ||
primitives: IMeshPrimitive[]; | ||
weights?: number[]; | ||
} | ||
interface INode extends IChildRootProperty { | ||
camera?: number; | ||
children?: number[]; | ||
skin?: number; | ||
matrix?: number[]; | ||
mesh?: number; | ||
rotation?: number[]; | ||
scale?: number[]; | ||
translation?: number[]; | ||
weights?: number[]; | ||
} | ||
interface ISampler extends IChildRootProperty { | ||
magFilter?: TextureMagFilter; | ||
minFilter?: TextureMinFilter; | ||
wrapS?: TextureWrapMode; | ||
wrapT?: TextureWrapMode; | ||
} | ||
interface IScene extends IChildRootProperty { | ||
nodes: number[]; | ||
} | ||
interface ISkin extends IChildRootProperty { | ||
inverseBindMatrices?: number; | ||
skeleton?: number; | ||
joints: number[]; | ||
} | ||
interface ITexture extends IChildRootProperty { | ||
sampler?: number; | ||
source: number; | ||
} | ||
interface ITextureInfo { | ||
index: number; | ||
texCoord?: number; | ||
} | ||
interface IGLTF extends IProperty { | ||
accessors?: IAccessor[]; | ||
animations?: IAnimation[]; | ||
asset: IAsset; | ||
buffers?: IBuffer[]; | ||
bufferViews?: IBufferView[]; | ||
cameras?: ICamera[]; | ||
extensionsUsed?: string[]; | ||
extensionsRequired?: string[]; | ||
images?: IImage[]; | ||
materials?: IMaterial[]; | ||
meshes?: IMesh[]; | ||
nodes?: INode[]; | ||
samplers?: ISampler[]; | ||
scene?: number; | ||
scenes?: IScene[]; | ||
skins?: ISkin[]; | ||
textures?: ITexture[]; | ||
} | ||
} | ||
declare module BABYLON { | ||
@@ -367,2 +119,14 @@ class OBJExport { | ||
/** | ||
* Stores a map of the unique id of a node to its index in the node array. | ||
*/ | ||
private nodeMap; | ||
/** | ||
* Stores the binary buffer used to store geometry data. | ||
*/ | ||
private binaryBuffer; | ||
/** | ||
* Specifies if the Babylon scene should be converted to right-handed on export. | ||
*/ | ||
private convertToRightHandedSystem; | ||
/** | ||
* Creates a glTF Exporter instance, which can accept optional exporter options. | ||
@@ -385,23 +149,39 @@ * @param babylonScene - Babylon scene object | ||
* Creates an accessor based on the supplied arguments | ||
* @param bufferviewIndex | ||
* @param name | ||
* @param type | ||
* @param componentType | ||
* @param count | ||
* @param min | ||
* @param max | ||
* @param bufferviewIndex - The index of the bufferview referenced by this accessor. | ||
* @param name - The name of the accessor. | ||
* @param type - The type of the accessor. | ||
* @param componentType - The datatype of components in the attribute. | ||
* @param count - The number of attributes referenced by this accessor. | ||
* @param byteOffset - The offset relative to the start of the bufferView in bytes. | ||
* @param min - Minimum value of each component in this attribute. | ||
* @param max - Maximum value of each component in this attribute. | ||
* @returns - accessor for glTF | ||
*/ | ||
private createAccessor(bufferviewIndex, name, type, componentType, count, byteOffset?, min?, max?); | ||
private createAccessor(bufferviewIndex, name, type, componentType, count, byteOffset, min, max); | ||
/** | ||
* Calculates the minimum and maximum values of an array of floats, based on stride | ||
* @param buff - Data to check for min and max values. | ||
* @param vertexStart - Start offset to calculate min and max values. | ||
* Calculates the minimum and maximum values of an array of position floats. | ||
* @param positions - Positions array of a mesh. | ||
* @param vertexStart - Starting vertex offset to calculate min and max values. | ||
* @param vertexCount - Number of vertices to check for min and max values. | ||
* @param stride - Offset between consecutive attributes. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @returns - min number array and max number array. | ||
*/ | ||
private calculateMinMax(buff, vertexStart, vertexCount, stride, useRightHandedSystem); | ||
private calculateMinMaxPositions(positions, vertexStart, vertexCount); | ||
/** | ||
* Converts a vector3 array to right-handed. | ||
* @param vector - vector3 Array to convert to right-handed. | ||
* @returns - right-handed Vector3 array. | ||
*/ | ||
private static GetRightHandedVector3(vector); | ||
/** | ||
* Converts a vector4 array to right-handed. | ||
* @param vector - vector4 Array to convert to right-handed. | ||
* @returns - right-handed vector4 array. | ||
*/ | ||
private static GetRightHandedVector4(vector); | ||
/** | ||
* Converts a quaternion to right-handed. | ||
* @param quaternion - Source quaternion to convert to right-handed. | ||
*/ | ||
private static GetRightHandedQuaternion(quaternion); | ||
/** | ||
* Writes mesh attribute data to a data buffer. | ||
@@ -414,6 +194,5 @@ * Returns the bytelength of the data. | ||
* @param dataBuffer - The buffer to write the binary data to. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @returns - Byte length of the attribute data. | ||
*/ | ||
private writeAttributeData(vertexBufferKind, meshAttributeArray, strideSize, vertexBufferOffset, byteOffset, dataBuffer, useRightHandedSystem); | ||
private writeAttributeData(vertexBufferKind, meshAttributeArray, strideSize, vertexBufferOffset, byteOffset, dataBuffer); | ||
/** | ||
@@ -455,5 +234,4 @@ * Generates glTF json data | ||
* @param babylonMesh - Babylon mesh used as the source for the transformation data. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
*/ | ||
private setNodeTransformation(node, babylonMesh, useRightHandedSystem); | ||
private setNodeTransformation(node, babylonMesh); | ||
/** | ||
@@ -464,7 +242,6 @@ * Creates a bufferview based on the vertices type for the Babylon mesh | ||
* @param byteOffset - The offset from the buffer to start indexing from. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @param dataBuffer - The buffer to write the bufferview data to. | ||
* @returns bytelength of the bufferview data. | ||
*/ | ||
private createBufferViewKind(kind, babylonMesh, byteOffset, useRightHandedSystem, dataBuffer); | ||
private createBufferViewKind(kind, babylonMesh, byteOffset, dataBuffer); | ||
/** | ||
@@ -475,7 +252,6 @@ * Sets data for the primitive attributes of each submesh | ||
* @param byteOffset - The offset in bytes of the buffer data. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @param dataBuffer - Buffer to write the attribute data to. | ||
* @returns - bytelength of the primitive attributes plus the passed in byteOffset. | ||
*/ | ||
private setPrimitiveAttributes(mesh, babylonMesh, byteOffset, useRightHandedSystem, dataBuffer); | ||
private setPrimitiveAttributes(mesh, babylonMesh, byteOffset, dataBuffer); | ||
/** | ||
@@ -486,6 +262,20 @@ * Creates a glTF scene based on the array of meshes. | ||
* @param byteOffset - Offset to start from in bytes. | ||
* @param dataBuffer - Buffer to write geometry data to. | ||
* @returns bytelength + byteoffset | ||
*/ | ||
private createScene(babylonScene, byteOffset, dataBuffer); | ||
private createScene(babylonScene, byteOffset); | ||
/** | ||
* Creates a mapping of Node unique id to node index | ||
* @param scene - Babylon Scene. | ||
* @param byteOffset - The initial byte offset. | ||
* @returns - Node mapping of unique id to index. | ||
*/ | ||
private createNodeMap(scene, byteOffset); | ||
/** | ||
* Creates a glTF node from a Babylon mesh. | ||
* @param babylonMesh - Source Babylon mesh. | ||
* @param byteOffset - The initial byte offset. | ||
* @param dataBuffer - Buffer for storing geometry data. | ||
* @returns - Object containing an INode and byteoffset. | ||
*/ | ||
private createNode(babylonMesh, byteOffset, dataBuffer); | ||
} | ||
@@ -492,0 +282,0 @@ } |
@@ -7,3 +7,3 @@ { | ||
"description": "The Babylon.js serializers library is an extension you can use to serialize Babylon scenes.", | ||
"version": "3.2.0-alpha8", | ||
"version": "3.2.0-alpha9", | ||
"repository": { | ||
@@ -30,2 +30,5 @@ "type": "git", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"babylonjs-gltf2interface": "3.2.0-alpha9" | ||
}, | ||
"peerDependencies": { | ||
@@ -32,0 +35,0 @@ "babylonjs": ">=3.2.0-alpha" |
Sorry, the diff of this file is too big to display
109835
2
1679
+ Addedbabylonjs-gltf2interface@3.2.0-alpha9(transitive)