babylonjs-serializers
Advanced tools
Comparing version 3.2.0-alphaB to 3.2.0-alphaC
@@ -1,1 +0,1 @@ | ||
var __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)}})();!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.BABYLON=t(e.BABYLON)})(this,(function(e){var e;!(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 h=t[o].geometry;if(h){var f=h.getVerticesData("position"),p=h.getVerticesData("normal"),d=h.getVerticesData("uv"),g=h.getIndices(),m=0;if(f&&p&&d&&g){for(var v=0;v<f.length;v+=3)n.push("v "+f[v]+" "+f[v+1]+" "+f[v+2]),m++;for(v=0;v<p.length;v+=3)n.push("vn "+p[v]+" "+p[v+1]+" "+p[v+2]);for(v=0;v<d.length;v+=2)n.push("vt "+d[v]+" "+d[v+1]);for(v=0;v<g.length;v+=3)n.push("f "+(g[v+2]+s)+"/"+(g[v+2]+s)+"/"+(g[v+2]+s)+" "+(g[v+1]+s)+"/"+(g[v+1]+s)+"/"+(g[v+1]+s)+" "+(g[v]+s)+"/"+(g[v]+s)+"/"+(g[v]+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})(e||(e={}));var e;!(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})(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=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),h=this.convertToRightHandedSystem?r.GetRightHandedVector3(c).asArray():c.asArray(),f=0;f<3;++f){var p=h[f];p<n[f]&&(n[f]=p),p>s[f]&&(s[f]=p),++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 h=c*i,f=[];if(t===e.VertexBuffer.PositionKind||t===e.VertexBuffer.NormalKind){var p=e.Vector3.FromArray(a,h);f=this.convertToRightHandedSystem?r.GetRightHandedVector3(p).asArray():p.asArray()}else if(t===e.VertexBuffer.TangentKind||t===e.VertexBuffer.ColorKind){var p=e.Vector4.FromArray(a,h);f=this.convertToRightHandedSystem&&t!==e.VertexBuffer.ColorKind?r.GetRightHandedVector4(p).asArray():p.asArray()}else t===e.VertexBuffer.UVKind||t===e.VertexBuffer.UV2Kind?f=[a[h],a[h+1]]:e.Tools.Warn("Unsupported Vertex Buffer Type: "+t);for(var d=0;d<f.length;++d)o.setFloat32(l,f[d],!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",h=this.createBufferView(0,s,u.data.length,void 0,c);s+=u.data.buffer.byteLength,this.bufferViews.push(h),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),h=28+n+l+r.byteLength+u+s+c,f=new ArrayBuffer(12),p=new DataView(f);p.setUint32(0,1179937895,!0),p.setUint32(4,2,!0),p.setUint32(8,h,!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),v=0;v<n;++v)m[v]=a.charCodeAt(v);for(var x=new Uint8Array(d,8+n),v=0;v<l;++v)x[v]=32;var T=new ArrayBuffer(8),b=new DataView(T);b.setUint32(0,r.byteLength+s+c,!0),b.setUint32(4,5130562,!0);for(var y=new ArrayBuffer(u),M=new Uint8Array(y),v=0;v<u;++v)M[v]=0;for(var B=new ArrayBuffer(c),w=new Uint8Array(B),v=0;v<c;++v)w[v]=0;var A=[f,d,T,r];for(var o in this.imageData)A.push(this.imageData[o].data.buffer);A.push(y),A.push(B);var F=new Blob(A,{type:"application/octet-stream"}),C=new e._GLTFData;return C.glTFFiles[i]=F,C},r.prototype.setNodeTransformation=function(t,a){a.position.equalsToFloats(0,0,0)||(t.translation=this.convertToRightHandedSystem?r.GetRightHandedVector3(a.position).asArray():a.position.asArray()),a.scaling.equalsToFloats(1,1,1)||(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 h=this.createBufferView(0,a,s,4*c,t+" - "+n.name);a+=s,this.bufferViews.push(h)}}return s},r.prototype.setPrimitiveAttributes=function(r,a,i,n){var s=null;a instanceof e.Mesh?s=a:a instanceof e.InstancedMesh&&(s=a.sourceMesh);var o=[{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"}],l=null;if(s){for(var u=0,c=o;u<c.length;u++){var h=c[u],f=h.kind;s.isVerticesDataPresent(f)&&(i+=this.createBufferViewKind(f,a,i,n),h.bufferViewIndex=this.bufferViews.length-1)}if(s.getTotalIndices()){var p=s.getIndices();if(p)if(n){for(var d=p.length,g=i,m=0;m<d;++m)n.setUint32(g,p[m],!0),g+=4;i=g}else{var v=4*p.length,x=this.createBufferView(0,i,v,void 0,"Indices - "+s.name);i+=v,this.bufferViews.push(x),l=this.bufferViews.length-1}}if(a.subMeshes)for(var T=!1,b=0,y=a.subMeshes;b<y.length;b++){var M=y[b],B={attributes:{}};if(!n){for(var w=0,A=o;w<A.length;w++){var h=A[w],f=h.kind;if(s.isVerticesDataPresent(f)){var F=s.getVertexBuffer(f);if(F){var C=F.getData();if(C){var R=F.getStrideSize(),V=void 0,L=null,S=null,E=h.bufferViewIndex;if(void 0!=E){f==e.VertexBuffer.PositionKind&&(V=this.calculateMinMaxPositions(C,0,C.length/R),L=V.min,S=V.max);var P=this.createAccessor(E,f+" - "+a.name,h.accessorType,5126,C.length/R,0,L,S);switch(this.accessors.push(P),f){case e.VertexBuffer.PositionKind:B.attributes.POSITION=this.accessors.length-1;break;case e.VertexBuffer.NormalKind:B.attributes.NORMAL=this.accessors.length-1;break;case e.VertexBuffer.ColorKind:B.attributes.COLOR_0=this.accessors.length-1;break;case e.VertexBuffer.TangentKind:B.attributes.TANGENT=this.accessors.length-1;break;case e.VertexBuffer.UVKind:B.attributes.TEXCOORD_0=this.accessors.length-1,T=!0;break;case e.VertexBuffer.UV2Kind:B.attributes.TEXCOORD_1=this.accessors.length-1,T=!0;break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+f)}}}}}}if(l){var P=this.createAccessor(l,"indices - "+a.name,"SCALAR",5125,M.indexCount,4*M.indexStart,null,null);this.accessors.push(P),B.indices=this.accessors.length-1}}if(s.material){var _=null;if(s.material instanceof e.StandardMaterial||s.material instanceof e.PBRMetallicRoughnessMaterial||s.material instanceof e.PBRMaterial)_=a.getScene().materials.indexOf(s.material);else if(s.material instanceof e.MultiMaterial){var D=s.material,O=D.subMaterials[M.materialIndex];O&&(_=a.getScene().materials.indexOf(O))}else e.Tools.Warn("Material type "+s.material.getClassName()+" for material "+s.material.name+" is not yet implemented in glTF serializer.");if(null!=_)if(T||!t._GLTFMaterial.HasTexturesPresent(this.materials[_]))B.material=_;else{var G=t._GLTFMaterial.StripTexturesFromMaterial(this.materials[_]);this.materials.push(G),B.material=this.materials.length-1}}r.primitives.push(B)}}return i},r.prototype.createScene=function(r,a){if(r.meshes.length){var i=r.meshes,n={nodes:new Array};t._GLTFMaterial.ConvertMaterialsToGLTF(r.materials,"image/jpeg",this.images,this.textures,this.materials,this.imageData,!0);var s=this.createNodeMap(r,a);this.nodeMap=s.nodeMap,this.totalByteLength=s.byteOffset,this.binaryBuffer=new ArrayBuffer(this.totalByteLength);for(var o=new DataView(this.binaryBuffer),l=0;l<i.length;++l){var u=i[l],c=this.nodeMap[u.uniqueId],h=this.nodes[c];u.parent||(this.options&&void 0!=this.options.shouldExportMesh&&!this.options.shouldExportMesh(u)?e.Tools.Log("Omitting "+u.name+" from scene."):n.nodes.push(c));var f=u.getDescendants(!0);if(!h.children&&f&&f.length){h.children=[];for(var p=0,d=f;p<d.length;p++){var g=d[p];h.children.push(this.nodeMap[g.uniqueId])}}var m={primitives:new Array};a=this.setPrimitiveAttributes(m,u,a,o)}this.scenes.push(n)}return a},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={}))})(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;return (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):c instanceof e.PBRMaterial?t.ConvertPBRMaterial(c,a,i,n,s,o,l):e.Tools.Error("Unsupported material type: "+c.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),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){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)}}else{if(!(t instanceof e.PBRMaterial))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 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 "+i.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 h=t.ExportTexture(r.diffuseTexture,a,i,n,o);null!=h&&(u.baseColorTexture=h)}if(r.bumpTexture){var h=t.ExportTexture(r.bumpTexture,a,i,n,o);h&&(c.normalTexture=h)}if(r.emissiveTexture){var f=t.ExportTexture(r.emissiveTexture,a,i,n,o);f&&(c.emissiveTexture=f),c.emissiveFactor=[1,1,1]}if(r.ambientTexture){var h=t.ExportTexture(r.ambientTexture,a,i,n,o);if(h){var p={index:h.index};c.occlusionTexture=p,p.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&&(c.emissiveFactor=r.emissiveColor.asArray()),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 h=t.GetAlphaMode(e);"OPAQUE"!==h&&(u.alphaMode=h,"BLEND"===h&&(u.alphaCutoff=e.alphaCutOff))}u.pbrMetallicRoughness=l,n.push(u)},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.ConvertPBRMaterial=function(r,a,i,n,s,o,l){var u={},c={name:r.name},h=r.isMetallicWorkflow();if(r){if(h)u.baseColorFactor=[r.albedoColor.r,r.albedoColor.g,r.albedoColor.b,r.alpha],null!=r.metallic&&1!==r.metallic&&(u.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(u.roughnessFactor=r.roughness);else{var f=r.albedoColor||e.Color3.Black(),p=r.reflectionColor||e.Color3.Black(),d=t.GetPerceivedBrightness(f),g=t.GetPerceivedBrightness(p),m=1-t.GetMaxComponent(r.reflectionColor),v=t.SolveMetallic(d,g,m),x=r.microSurface||0,T=f.scale(m/(1-this.dielectricSpecular.r)/Math.max(1-v,this.epsilon)),b=p.subtract(this.dielectricSpecular.scale(1-v)).scale(1/Math.max(v,this.epsilon)),y=e.Color3.Lerp(T,b,v*v);y=y.clampToRef(0,1,y),u.baseColorFactor=[y.r,y.g,y.b,r.alpha],1!==v&&(u.metallicFactor=v),x&&(u.roughnessFactor=1-x)}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.albedoTexture){var M=t.ExportTexture(r.albedoTexture,a,i,n,o);M&&(u.baseColorTexture=M)}if(r.bumpTexture){var M=t.ExportTexture(r.bumpTexture,a,i,n,o);M&&(c.normalTexture=M)}if(r.ambientTexture){var M=t.ExportTexture(r.ambientTexture,a,i,n,o);if(M){var B={index:M.index};c.occlusionTexture=B,r.ambientTextureStrength&&(B.strength=r.ambientTextureStrength)}}if(r.emissiveTexture){var M=t.ExportTexture(r.emissiveTexture,a,i,n,o);null!=M&&(c.emissiveTexture=M)}if(r.metallicTexture){var M=t.ExportTexture(r.metallicTexture,a,i,n,o);null!=M&&(u.metallicRoughnessTexture=M)}}if(r.emissiveColor.equalsFloats(0,0,0)||(c.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var w=t.GetAlphaMode(r);"OPAQUE"!==w&&(c.alphaMode=w,"BLEND"===w&&(c.alphaCutoff=r.alphaCutOff))}}c.pbrMetallicRoughness=u,s.push(c)},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],h="";"image/jpeg"===r?h=".jpg":"image/png"===r?h=".png":e.Tools.Error("Unsupported mime type "+r),l=c+h;var f=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(f),d.putImageData(m,0,0);for(var v=p.toDataURL(r),x=atob(v.split(",")[1]),T=new Uint8Array(x.length),b=0;b<x.length;++b)T[b]=x.charCodeAt(b);var y={data:T,mimeType:r};if(n[l]=y,"image/jpeg"===r){for(var M={uri:l},B=-1,b=0;b<a.length;++b)if(a[b].uri===l){B=b;break}-1===B?(a.push(M),o.source=a.length-1,i.push({source:a.length-1}),s={index:a.length-1}):(o.source=B,s={index:B})}return s},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={})),e})); | ||
var __decorate=this&&this.__decorate||function(e,t,r,a){var i,s=arguments.length,n=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(n=(s<3?i(n):s>3?i(t,r,n):i(t,r))||n);return s>3&&n&&Object.defineProperty(t,r,n),n},__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)}})();!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-serializers",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-serializers"]=t(require("babylonjs")):e.BABYLON=t(e.BABYLON)})(this,(function(e){var e;!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,a,i){var s=[],n=1;r&&(a||(a="mat"),s.push("mtllib "+a+".mtl"));for(var o=0;o<t.length;o++){s.push("g object"+o),s.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 h=t[o].material;h&&s.push("usemtl "+h.id)}var c=t[o].geometry;if(c){var f=c.getVerticesData("position"),p=c.getVerticesData("normal"),d=c.getVerticesData("uv"),g=c.getIndices(),m=0;if(f&&p&&d&&g){for(var x=0;x<f.length;x+=3)s.push("v "+f[x]+" "+f[x+1]+" "+f[x+2]),m++;for(x=0;x<p.length;x+=3)s.push("vn "+p[x]+" "+p[x+1]+" "+p[x+2]);for(x=0;x<d.length;x+=2)s.push("vt "+d[x]+" "+d[x+1]);for(x=0;x<g.length;x+=3)s.push("f "+(g[x+2]+n)+"/"+(g[x+2]+n)+"/"+(g[x+2]+n)+" "+(g[x+1]+n)+"/"+(g[x+1]+n)+"/"+(g[x+1]+n)+" "+(g[x]+n)+"/"+(g[x]+n)+"/"+(g[x]+n));i&&l&&t[o].bakeTransformIntoVertices(l),n+=m}}}return s.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(/\.[^\/.]+$/,""),s=new e.GLTF2._Exporter(t,a);if(t.isReady)return s._generateGLTF(i);throw new Error("glTF Serializer: Scene is not ready!")},t.GLB=function(t,r,a){var i=r.replace(/\.[^\/.]+$/,""),s=new e.GLTF2._Exporter(t,a);if(t.isReady)return s._generateGLB(i);throw new Error("glTF Serializer: Scene is not ready!")},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=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 s={buffer:e,byteLength:r};return t&&(s.byteOffset=t),i&&(s.name=i),a&&(s.byteStride=a),s},r.prototype.createAccessor=function(e,t,r,a,i,s,n,o){var l={name:t,bufferView:e,componentType:a,count:i,type:r};return n&&(l.min=n),o&&(l.max=o),s&&(l.byteOffset=s),l},r.prototype.calculateMinMaxPositions=function(t,a,i){var s=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],o=a+i;if(i)for(var l=a;l<o;++l)for(var u=3*l,h=e.Vector3.FromArray(t,u),c=this.convertToRightHandedSystem?r.GetRightHandedVector3(h).asArray():h.asArray(),f=0;f<3;++f){var p=c[f];p<s[f]&&(s[f]=p),p>n[f]&&(n[f]=p),++u}return{min:s,max:n}},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,s,n,o){for(var l=n,u=a.length/i,h=0;h<u;++h){var c=h*i,f=[];if(t===e.VertexBuffer.PositionKind||t===e.VertexBuffer.NormalKind){var p=e.Vector3.FromArray(a,c);f=this.convertToRightHandedSystem?r.GetRightHandedVector3(p).asArray():p.asArray()}else if(t===e.VertexBuffer.TangentKind||t===e.VertexBuffer.ColorKind){var p=e.Vector4.FromArray(a,c);f=this.convertToRightHandedSystem&&t!==e.VertexBuffer.ColorKind?r.GetRightHandedVector4(p).asArray():p.asArray()}else t===e.VertexBuffer.UVKind||t===e.VertexBuffer.UV2Kind?f=[a[c],a[c+1]]:e.Tools.Warn("Unsupported Vertex Buffer Type: "+t);for(var d=0;d<f.length;++d)o.setFloat32(l,f[d],!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 s=this.images.length,n=this.totalByteLength,o=0;o<s;++o){var l=this.images[o];if(l.uri){var u=this.imageData[l.uri],h=l.uri.split(".")[0]+" image",c=this.createBufferView(0,n,u.data.length,void 0,h);n+=u.data.buffer.byteLength,this.bufferViews.push(c),l.bufferView=this.bufferViews.length-1,l.name=h,l.mimeType=u.mimeType,l.uri=void 0,i.images.push(l)}}a.byteLength=n}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"}),s=t+".gltf",n=t+".bin",o=new e._GLTFData;if(o.glTFFiles[s]=a,o.glTFFiles[n]=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",s=a.length,n=0;for(var o in this.imageData)n+=this.imageData[o].data.byteLength;var l=this._getPadding(s),u=this._getPadding(r.byteLength),h=this._getPadding(n),c=28+s+l+r.byteLength+u+n+h,f=new ArrayBuffer(12),p=new DataView(f);p.setUint32(0,1179937895,!0),p.setUint32(4,2,!0),p.setUint32(8,c,!0);var d=new ArrayBuffer(8+s+l),g=new DataView(d);g.setUint32(0,s+l,!0),g.setUint32(4,1313821514,!0);for(var m=new Uint8Array(d,8),x=0;x<s;++x)m[x]=a.charCodeAt(x);for(var v=new Uint8Array(d,8+s),x=0;x<l;++x)v[x]=32;var T=new ArrayBuffer(8),b=new DataView(T);b.setUint32(0,r.byteLength+n+h,!0),b.setUint32(4,5130562,!0);for(var y=new ArrayBuffer(u),C=new Uint8Array(y),x=0;x<u;++x)C[x]=0;for(var _=new ArrayBuffer(h),M=new Uint8Array(_),x=0;x<h;++x)M[x]=0;var w=[f,d,T,r];for(var o in this.imageData)w.push(this.imageData[o].data.buffer);w.push(y),w.push(_);var B=new Blob(w,{type:"application/octet-stream"}),F=new e._GLTFData;return F.glTFFiles[i]=B,F},r.prototype.setNodeTransformation=function(t,a){a.position.equalsToFloats(0,0,0)||(t.translation=this.convertToRightHandedSystem?r.GetRightHandedVector3(a.position).asArray():a.position.asArray()),a.scaling.equalsToFloats(1,1,1)||(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 s=null,n=0;if(r instanceof e.Mesh?s=r:r instanceof e.InstancedMesh&&(s=r.sourceMesh),s){var o=null,l=null,u=null,h=null;if(s.isVerticesDataPresent(t)&&(o=s.getVertexBuffer(t))&&(l=o.getOffset(),u=o.getData()))if(h=o.getStrideSize(),i&&u)n=this.writeAttributeData(t,u,h,l,a,i),a+=n;else{n=4*u.length;var c=this.createBufferView(0,a,n,4*h,t+" - "+s.name);a+=n,this.bufferViews.push(c)}}return n},r.prototype.setPrimitiveAttributes=function(r,a,i,s){var n=null;a instanceof e.Mesh?n=a:a instanceof e.InstancedMesh&&(n=a.sourceMesh);var o=[{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"}],l=null;if(n){for(var u=0,h=o;u<h.length;u++){var c=h[u],f=c.kind;n.isVerticesDataPresent(f)&&(i+=this.createBufferViewKind(f,a,i,s),c.bufferViewIndex=this.bufferViews.length-1)}if(n.getTotalIndices()){var p=n.getIndices();if(p)if(s){for(var d=p.length,g=i,m=0;m<d;++m)s.setUint32(g,p[m],!0),g+=4;i=g}else{var x=4*p.length,v=this.createBufferView(0,i,x,void 0,"Indices - "+n.name);i+=x,this.bufferViews.push(v),l=this.bufferViews.length-1}}if(a.subMeshes)for(var T=!1,b=0,y=a.subMeshes;b<y.length;b++){var C=y[b],_={attributes:{}};if(!s){for(var M=0,w=o;M<w.length;M++){var c=w[M],f=c.kind;if(n.isVerticesDataPresent(f)){var B=n.getVertexBuffer(f);if(B){var F=B.getData();if(F){var A=B.getStrideSize(),R=void 0,S=null,E=null,V=c.bufferViewIndex;if(void 0!=V){f==e.VertexBuffer.PositionKind&&(R=this.calculateMinMaxPositions(F,0,F.length/A),S=R.min,E=R.max);var L=this.createAccessor(V,f+" - "+a.name,c.accessorType,5126,F.length/A,0,S,E);switch(this.accessors.push(L),f){case e.VertexBuffer.PositionKind:_.attributes.POSITION=this.accessors.length-1;break;case e.VertexBuffer.NormalKind:_.attributes.NORMAL=this.accessors.length-1;break;case e.VertexBuffer.ColorKind:_.attributes.COLOR_0=this.accessors.length-1;break;case e.VertexBuffer.TangentKind:_.attributes.TANGENT=this.accessors.length-1;break;case e.VertexBuffer.UVKind:_.attributes.TEXCOORD_0=this.accessors.length-1,T=!0;break;case e.VertexBuffer.UV2Kind:_.attributes.TEXCOORD_1=this.accessors.length-1,T=!0;break;default:e.Tools.Warn("Unsupported Vertex Buffer Type: "+f)}}}}}}if(l){var L=this.createAccessor(l,"indices - "+a.name,"SCALAR",5125,C.indexCount,4*C.indexStart,null,null);this.accessors.push(L),_.indices=this.accessors.length-1}}if(n.material){var P=null;if(n.material instanceof e.StandardMaterial||n.material instanceof e.PBRMetallicRoughnessMaterial||n.material instanceof e.PBRMaterial)P=a.getScene().materials.indexOf(n.material);else if(n.material instanceof e.MultiMaterial){var G=n.material,D=G.subMaterials[C.materialIndex];D&&(P=a.getScene().materials.indexOf(D))}else e.Tools.Warn("Material type "+n.material.getClassName()+" for material "+n.material.name+" is not yet implemented in glTF serializer.");if(null!=P&&Object.keys(_.attributes).length>0)if(T||!t._GLTFMaterial._HasTexturesPresent(this.materials[P]))_.material=P;else{var O=t._GLTFMaterial._StripTexturesFromMaterial(this.materials[P]);this.materials.push(O),_.material=this.materials.length-1}}r.primitives.push(_)}}return i},r.prototype.createScene=function(r,a){if(r.meshes.length){var i=r.meshes,s={nodes:new Array};t._GLTFMaterial._ConvertMaterialsToGLTF(r.materials,"image/png",this.images,this.textures,this.materials,this.imageData,!0);var n=this.createNodeMap(r,a);this.nodeMap=n.nodeMap,this.totalByteLength=n.byteOffset,this.binaryBuffer=new ArrayBuffer(this.totalByteLength);for(var o=new DataView(this.binaryBuffer),l=0;l<i.length;++l){var u=i[l],h=this.nodeMap[u.uniqueId],c=this.nodes[h];u.parent||(this.options&&void 0!=this.options.shouldExportMesh&&!this.options.shouldExportMesh(u)?e.Tools.Log("Omitting "+u.name+" from scene."):s.nodes.push(h));var f=u.getDescendants(!0);if(!c.children&&f&&f.length){c.children=[];for(var p=0,d=f;p<d.length;p++){var g=d[p];c.children.push(this.nodeMap[g.uniqueId])}}var m={primitives:new Array};a=this.setPrimitiveAttributes(m,u,a,o)}this.scenes.push(s)}return a},r.prototype.createNodeMap=function(e,t){for(var r={},a=0,i=e.meshes;a<i.length;a++){var s=i[a],n=this.createNode(s,t,null);this.nodes.push(n.node),r[s.uniqueId]=this.nodes.length-1,t=n.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={}))})(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;return (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,s,n,o,l){for(var u=0;u<r.length;++u){var h=r[u];if(h instanceof e.StandardMaterial)t._ConvertStandardMaterial(h,a,i,s,n,o,l);else if(h instanceof e.PBRMetallicRoughnessMaterial)t._ConvertPBRMetallicRoughnessMaterial(h,a,i,s,n,o,l);else{if(!(h instanceof e.PBRMaterial))throw new Error("Unsupported material type: "+h.name);t._ConvertPBRMaterial(h,a,i,s,n,o,l)}}},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),s=new e.Vector2(0,.1),n=new e.Vector2(1300,.1),o=t.diffuseColor.toLinearSpace().scale(.5),l=t.alpha,u=e.Scalar.Clamp(t.specularPower,0,this._maxSpecularPower),h=(function(e){return r(Math.pow(e/n.x,.333333),a.y,i.y,s.y,n.y)})(u);return{baseColorFactor:[o.r,o.g,o.b,l],metallicFactor:0,roughnessFactor:h}},t._SolveMetallic=function(r,a,i){if(a<t._dielectricSpecular.r)return t._dielectricSpecular,0;var s=t._dielectricSpecular.r,n=r*i/(1-t._dielectricSpecular.r)+a-2*t._dielectricSpecular.r,o=t._dielectricSpecular.r-a,l=n*n-4*s*o;return e.Scalar.Clamp((-n+Math.sqrt(l))/(2*s),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:throw new Error("Unsupported alpha mode "+a.transparencyMode)}}else{if(!(t instanceof e.PBRMaterial))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 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 "+i.transparencyMode)}}},t._ConvertStandardMaterial=function(r,a,i,s,n,o,l){e.Tools.Warn(r.name+": Standard Material is currently not fully supported/implemented in glTF serializer");var u=t._ConvertToGLTFPBRMetallicRoughness(r),h={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."),h.doubleSided=!0),l){if(r.diffuseTexture){var c=t._ExportTexture(r.diffuseTexture,a,i,s,o);null!=c&&(u.baseColorTexture=c)}if(r.bumpTexture){var c=t._ExportTexture(r.bumpTexture,a,i,s,o);c&&(h.normalTexture=c)}if(r.emissiveTexture){var f=t._ExportTexture(r.emissiveTexture,a,i,s,o);f&&(h.emissiveTexture=f),h.emissiveFactor=[1,1,1]}if(r.ambientTexture){var c=t._ExportTexture(r.ambientTexture,a,i,s,o);if(c){var p={index:c.index};h.occlusionTexture=p,p.strength=1}}}(r.alpha<1||r.opacityTexture)&&(r.alphaMode===e.Engine.ALPHA_COMBINE?h.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)&&(h.emissiveFactor=r.emissiveColor.asArray()),h.pbrMetallicRoughness=u,n.push(h)},t._ConvertPBRMetallicRoughnessMaterial=function(r,a,i,s,n,o,l){var u={};r.baseColor&&(u.baseColorFactor=[r.baseColor.r,r.baseColor.g,r.baseColor.b,r.alpha]),null!=r.metallic&&1!==r.metallic&&(u.metallicFactor=r.metallic),null!=r.roughness&&1!==r.roughness&&(u.roughnessFactor=r.roughness);var h={name:r.name};if(r.doubleSided&&(h.doubleSided=r.doubleSided),l){if(null!=r.baseTexture){var c=t._ExportTexture(r.baseTexture,a,i,s,o);null!=c&&(u.baseColorTexture=c)}if(r.normalTexture){var c=t._ExportTexture(r.normalTexture,a,i,s,o);c&&(h.normalTexture=c)}if(r.occlusionTexture){var c=t._ExportTexture(r.occlusionTexture,a,i,s,o);c&&(h.occlusionTexture=c,null!=r.occlusionStrength&&(h.occlusionTexture.strength=r.occlusionStrength))}if(r.emissiveTexture){var c=t._ExportTexture(r.emissiveTexture,a,i,s,o);null!=c&&(h.emissiveTexture=c)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)&&(h.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var f=t._GetAlphaMode(r);"OPAQUE"!==f&&(h.alphaMode=f,"BLEND"===f&&(h.alphaCutoff=r.alphaCutOff))}h.pbrMetallicRoughness=u,n.push(h)},t._CreateBase64FromCanvas=function(e,t,r,a){var i=document.createElement("canvas");i.id="WriteCanvas";var s=i.getContext("2d");i.width=t,i.height=r;var n=s.createImageData(t,r);return n.data.set(e),s.putImageData(n,0,0),i.toDataURL(a)},t._CreateWhiteTexture=function(t,r,a){for(var i=new Uint8Array(t*r*4),s=0;s<i.length;++s)i[s]=255;return e.RawTexture.CreateRGBATexture(i,t,r,a)},t._ResizeTexturesToSameDimensions=function(t,r,a){var i,s,n=t?t.getSize():{width:0,height:0},o=r?r.getSize():{width:0,height:0};return n.width<o.width?(i=t?e.TextureTools.CreateResizedCopy(t,o.width,o.height,!0):this._CreateWhiteTexture(o.width,o.height,a),s=r):n.width>o.width?(s=r?e.TextureTools.CreateResizedCopy(r,n.width,n.height,!0):this._CreateWhiteTexture(n.width,n.height,a),i=t):(i=t,s=r),{texture1:i,texture2:s}},t._ConvertSpecularGlossinessTexturesToMetallicRoughness=function(t,r,a,i){if(!t&&!r)return null;var s=t?t.getScene():r.getScene();if(!s)throw new Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!");var n,o,l=this._ResizeTexturesToSameDimensions(t,r,s),u=l.texture1.getSize(),h=u.width,c=u.height,f=l.texture1.readPixels();if(!(f instanceof Uint8Array))throw new Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture1.name);if(n=l.texture1.readPixels(),!((f=l.texture2.readPixels())instanceof Uint8Array))throw new Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: "+l.texture2.name);o=l.texture2.readPixels();for(var p=o.byteLength,d=new Uint8Array(p),g=new Uint8Array(p),m=e.Color3.Black(),x=0,v=0,T=0;T<c;++T)for(var b=0;b<h;++b){var y=4*(h*T+b),C=e.Color3.FromInts(n[y],n[y+1],n[y+2]).toLinearSpace().multiply(a.diffuseColor),_=e.Color3.FromInts(o[y],o[y+1],o[y+2]).toLinearSpace().multiply(a.specularColor),M=o[y+3]/255*a.glossiness,w={diffuseColor:C,specularColor:_,glossiness:M},B=this._ConvertSpecularGlossinessToMetallicRoughness(w);m.r=Math.max(m.r,B.baseColor.r),m.g=Math.max(m.g,B.baseColor.g),m.b=Math.max(m.b,B.baseColor.b),x=Math.max(x,B.metallic),v=Math.max(v,B.roughness),g[y]=255*B.baseColor.r,g[y+1]=255*B.baseColor.g,g[y+2]=255*B.baseColor.b,g[y+3]=l.texture1.hasAlpha?n[y+3]:255,d[y]=0,d[y+1]=255*B.roughness,d[y+2]=255*B.metallic,d[y+3]=255}for(var F={baseColor:m,metallic:x,roughness:v},A=!1,R=!1,T=0;T<c;++T)for(var b=0;b<h;++b){var S=4*(h*T+b);g[S]/=F.baseColor.r>this._epsilon?F.baseColor.r:1,g[S+1]/=F.baseColor.g>this._epsilon?F.baseColor.g:1,g[S+2]/=F.baseColor.b>this._epsilon?F.baseColor.b:1;var E=e.Color3.FromInts(g[S],g[S+1],g[S+2]),V=E.toGammaSpace();g[S]=255*V.r,g[S+1]=255*V.g,g[S+2]=255*V.b,this.FuzzyEquals(V,e.Color3.White(),this._epsilon)||(R=!0),d[S+1]/=F.roughness>this._epsilon?F.roughness:1,d[S+2]/=F.metallic>this._epsilon?F.metallic:1;var L=e.Color3.FromInts(255,d[S+1],d[S+2]);this.FuzzyEquals(L,e.Color3.White(),this._epsilon)||(A=!0)}if(A){var P=this._CreateBase64FromCanvas(d,h,c,i);F.metallicRoughnessTextureBase64=P}if(R){var G=this._CreateBase64FromCanvas(g,h,c,i);F.baseColorTextureBase64=G}return F},t._ConvertSpecularGlossinessToMetallicRoughness=function(r){var a=t._GetPerceivedBrightness(r.diffuseColor),i=t._GetPerceivedBrightness(r.specularColor),s=1-t._GetMaxComponent(r.specularColor),n=t._SolveMetallic(a,i,s),o=r.diffuseColor.scale(s/(1-this._dielectricSpecular.r)/Math.max(1-n,this._epsilon)),l=r.specularColor.subtract(this._dielectricSpecular.scale(1-n)).scale(1/Math.max(n,this._epsilon)),u=e.Color3.Lerp(o,l,n*n);return u=u.clampToRef(0,1,u),{baseColor:u,metallic:n,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,s,n,o){var l={baseColor:e.albedoColor,metallic:e.metallic,roughness:e.roughness};if(o){if(e.albedoTexture){var u=t._ExportTexture(e.albedoTexture,r,a,i,n);u&&(s.baseColorTexture=u)}if(e.metallicTexture){var u=t._ExportTexture(e.metallicTexture,r,a,i,n);null!=u&&(s.metallicRoughnessTexture=u)}}return l},t._ConvertSpecGlossFactorsToMetallicRoughness=function(r,a,i,s,n,o,l){var u={diffuseColor:r.albedoColor||e.Color3.White(),specularColor:r.reflectivityColor||e.Color3.White(),glossiness:r.microSurface||1};if(r.reflectivityTexture&&!r.useMicroSurfaceFromReflectivityMapAlpha)throw new Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported");var h=this._ConvertSpecularGlossinessTexturesToMetallicRoughness(r.albedoTexture,r.reflectivityTexture,u,a);if(h){if(l){if(h.baseColorTextureBase64){var c=t._GetTextureInfoFromBase64(h.baseColorTextureBase64,"bjsBaseColorTexture_"+s.length+".png",a,i,s,o);null!=c&&(n.baseColorTexture=c)}if(h.metallicRoughnessTextureBase64){var f=t._GetTextureInfoFromBase64(h.metallicRoughnessTextureBase64,"bjsMetallicRoughnessTexture_"+s.length+".png",a,i,s,o);null!=f&&(n.metallicRoughnessTexture=f)}}}else h=this._ConvertSpecularGlossinessToMetallicRoughness(u);return h},t._ConvertPBRMaterial=function(r,a,i,s,n,o,l){var u,h={},c={name:r.name};if(u=r.isMetallicWorkflow()?this._ConvertMetalRoughFactorsToMetallicRoughness(r,a,i,s,h,o,l):this._ConvertSpecGlossFactorsToMetallicRoughness(r,a,i,s,h,o,l),this.FuzzyEquals(u.baseColor,e.Color3.White(),this._epsilon)&&r.alpha>=this._epsilon||(h.baseColorFactor=[u.baseColor.r,u.baseColor.g,u.baseColor.b,r.alpha]),null!=u.metallic&&1!==u.metallic&&(h.metallicFactor=u.metallic),null!=u.roughness&&1!==u.roughness&&(h.roughnessFactor=u.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."),c.doubleSided=!0),l){if(r.bumpTexture){var f=t._ExportTexture(r.bumpTexture,a,i,s,o);f&&(c.normalTexture=f)}if(r.ambientTexture){var f=t._ExportTexture(r.ambientTexture,a,i,s,o);if(f){var p={index:f.index};c.occlusionTexture=p,r.ambientTextureStrength&&(p.strength=r.ambientTextureStrength)}}if(r.emissiveTexture){var f=t._ExportTexture(r.emissiveTexture,a,i,s,o);null!=f&&(c.emissiveTexture=f)}}if(this.FuzzyEquals(r.emissiveColor,e.Color3.Black(),this._epsilon)||(c.emissiveFactor=r.emissiveColor.asArray()),null!=r.transparencyMode){var d=t._GetAlphaMode(r);"OPAQUE"!==d&&(c.alphaMode=d,"BLEND"===d&&(c.alphaCutoff=r.alphaCutOff))}c.pbrMetallicRoughness=h,n.push(c)},t._ExportTexture=function(t,r,a,i,s){var n="texture_"+(i.length-1).toString(),o=t.getInternalTexture();null!=o&&(n=o.url||n),n=e.Tools.GetFilename(n);var l=n.split(".")[0],u="";if("image/jpeg"===r)u=".jpg";else{if("image/png"!==r)throw new Error("Unsupported mime type "+r);u=".png"}n=l+u;var h=t.readPixels(),c=t.getSize(),f=this._CreateBase64FromCanvas(h,c.width,c.height,r);return this._GetTextureInfoFromBase64(f,n,r,a,i,s)},t._GetTextureInfoFromBase64=function(e,t,r,a,i,s){for(var n=null,o={source:a.length},l=atob(e.split(",")[1]),u=new Uint8Array(l.length),h=0;h<l.length;++h)u[h]=l.charCodeAt(h);var c={data:u,mimeType:r};if(s[t]=c,"image/jpeg"===r||"image/png"===r){for(var f={uri:t},p=-1,h=0;h<a.length;++h)if(a[h].uri===t){p=h;break}-1===p?(a.push(f),o.source=a.length-1,i.push({source:a.length-1}),n={index:a.length-1}):(o.source=p,n={index:p})}return n},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={})),e})); |
@@ -308,19 +308,29 @@ /// <reference types="babylonjs"/> | ||
*/ | ||
private static readonly dielectricSpecular; | ||
private static readonly _dielectricSpecular; | ||
/** | ||
* Allows the maximum specular power to be defined for material calculations. | ||
*/ | ||
private static maxSpecularPower; | ||
private static epsilon; | ||
private static _maxSpecularPower; | ||
/** | ||
* Numeric tolerance value | ||
*/ | ||
private static _epsilon; | ||
/** | ||
* Specifies if two colors are approximately equal in value. | ||
* @param color1 - first color to compare to. | ||
* @param color2 - second color to compare to. | ||
* @param epsilon - threshold value | ||
*/ | ||
private static FuzzyEquals(color1, color2, epsilon); | ||
/** | ||
* Gets the materials from a Babylon scene and converts them to glTF materials. | ||
* @param scene | ||
* @param mimeType | ||
* @param images | ||
* @param textures | ||
* @param materials | ||
* @param imageData | ||
* @param hasTextureCoords | ||
* @param scene - babylonjs scene. | ||
* @param mimeType - texture mime type. | ||
* @param images - array of images. | ||
* @param textures - array of textures. | ||
* @param materials - array of materials. | ||
* @param imageData - mapping of texture names to base64 textures | ||
* @param hasTextureCoords - specifies if texture coordinates are present on the material. | ||
*/ | ||
static ConvertMaterialsToGLTF(babylonMaterials: Material[], mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertMaterialsToGLTF(babylonMaterials: Material[], mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -336,3 +346,3 @@ data: Uint8Array; | ||
*/ | ||
static StripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial; | ||
static _StripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial; | ||
/** | ||
@@ -343,3 +353,3 @@ * Specifies if the material has any texture parameters present. | ||
*/ | ||
static HasTexturesPresent(material: IMaterial): boolean; | ||
static _HasTexturesPresent(material: IMaterial): boolean; | ||
/** | ||
@@ -350,3 +360,3 @@ * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material. | ||
*/ | ||
static ConvertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness; | ||
static _ConvertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness; | ||
/** | ||
@@ -359,3 +369,3 @@ * Computes the metallic factor | ||
*/ | ||
static SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number; | ||
static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number; | ||
/** | ||
@@ -366,3 +376,3 @@ * Gets the glTF alpha mode from the Babylon Material | ||
*/ | ||
static GetAlphaMode(babylonMaterial: Material): MaterialAlphaMode; | ||
static _GetAlphaMode(babylonMaterial: Material): MaterialAlphaMode; | ||
/** | ||
@@ -378,3 +388,3 @@ * Converts a Babylon Standard Material to a glTF Material. | ||
*/ | ||
static ConvertStandardMaterial(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertStandardMaterial(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -395,3 +405,3 @@ data: Uint8Array; | ||
*/ | ||
static ConvertPBRMetallicRoughnessMaterial(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertPBRMetallicRoughnessMaterial(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -403,8 +413,49 @@ data: Uint8Array; | ||
/** | ||
* Converts an image typed array buffer to a base64 image. | ||
* @param buffer - typed array buffer. | ||
* @param width - width of the image. | ||
* @param height - height of the image. | ||
* @param mimeType - mimetype of the image. | ||
* @returns - base64 image string. | ||
*/ | ||
private static _CreateBase64FromCanvas(buffer, width, height, mimeType); | ||
/** | ||
* Generates a white texture based on the specified width and height. | ||
* @param width - width of the texture in pixels. | ||
* @param height - height of the texture in pixels. | ||
* @param scene - babylonjs scene. | ||
* @returns - white texture. | ||
*/ | ||
private static _CreateWhiteTexture(width, height, scene); | ||
/** | ||
* Resizes the two source textures to the same dimensions. If a texture is null, a default white texture is generated. If both textures are null, returns null. | ||
* @param texture1 - first texture to resize. | ||
* @param texture2 - second texture to resize. | ||
* @param scene - babylonjs scene. | ||
* @returns resized textures or null. | ||
*/ | ||
private static _ResizeTexturesToSameDimensions(texture1, texture2, scene); | ||
/** | ||
* Convert Specular Glossiness Textures to Metallic Roughness. | ||
* See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness | ||
* @link https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js | ||
* @param diffuseTexture - texture used to store diffuse information. | ||
* @param specularGlossinessTexture - texture used to store specular and glossiness information. | ||
* @param factors - specular glossiness material factors. | ||
* @param mimeType - the mime type to use for the texture. | ||
* @returns pbr metallic roughness interface or null. | ||
*/ | ||
private static _ConvertSpecularGlossinessTexturesToMetallicRoughness(diffuseTexture, specularGlossinessTexture, factors, mimeType); | ||
/** | ||
* Converts specular glossiness material properties to metallic roughness. | ||
* @param specularGlossiness - interface with specular glossiness material properties. | ||
* @returns - interface with metallic roughness material properties. | ||
*/ | ||
private static _ConvertSpecularGlossinessToMetallicRoughness(specularGlossiness); | ||
/** | ||
* Calculates the surface reflectance, independent of lighting conditions. | ||
* @param color - Color source to calculate brightness from. | ||
* @returns number representing the perceived brightness, or zero if color is undefined. | ||
*/ | ||
static GetPerceivedBrightness(color: Color3): number; | ||
private static _GetPerceivedBrightness(color); | ||
/** | ||
@@ -415,4 +466,28 @@ * Returns the maximum color component value. | ||
*/ | ||
static GetMaxComponent(color: Color3): number; | ||
private static _GetMaxComponent(color); | ||
/** | ||
* Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors. | ||
* @param babylonPBRMaterial - BJS PBR Metallic Roughness Material. | ||
* @param mimeType - mime type to use for the textures. | ||
* @param images - array of glTF image interfaces. | ||
* @param textures - array of glTF texture interfaces. | ||
* @param glTFPbrMetallicRoughness - glTF PBR Metallic Roughness interface. | ||
* @param imageData - map of image file name to data. | ||
* @param hasTextureCoords - specifies if texture coordinates are present on the submesh to determine if textures should be applied. | ||
* @returns - glTF PBR Metallic Roughness factors. | ||
*/ | ||
private static _ConvertMetalRoughFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, glTFPbrMetallicRoughness, imageData, hasTextureCoords); | ||
/** | ||
* Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors. | ||
* @param babylonPBRMaterial - BJS PBR Metallic Roughness Material. | ||
* @param mimeType - mime type to use for the textures. | ||
* @param images - array of glTF image interfaces. | ||
* @param textures - array of glTF texture interfaces. | ||
* @param glTFPbrMetallicRoughness - glTF PBR Metallic Roughness interface. | ||
* @param imageData - map of image file name to data. | ||
* @param hasTextureCoords - specifies if texture coordinates are present on the submesh to determine if textures should be applied. | ||
* @returns - glTF PBR Metallic Roughness factors. | ||
*/ | ||
private static _ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, glTFPbrMetallicRoughness, imageData, hasTextureCoords); | ||
/** | ||
* Converts a Babylon PBR Metallic Roughness Material to a glTF Material. | ||
@@ -427,3 +502,3 @@ * @param babylonPBRMaterial - BJS PBR Metallic Roughness Material. | ||
*/ | ||
static ConvertPBRMaterial(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
static _ConvertPBRMaterial(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
@@ -441,11 +516,17 @@ data: Uint8Array; | ||
* @param imageData - map of image file name and data. | ||
* @return - glTF texture, or null if the texture format is not supported. | ||
* @return - glTF texture info, or null if the texture format is not supported. | ||
*/ | ||
static ExportTexture(babylonTexture: BaseTexture, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], imageData: { | ||
[fileName: string]: { | ||
data: Uint8Array; | ||
mimeType: ImageMimeType; | ||
}; | ||
}): Nullable<ITextureInfo>; | ||
private static _ExportTexture(babylonTexture, mimeType, images, textures, imageData); | ||
/** | ||
* Builds a texture from base64 string. | ||
* @param base64Texture - base64 texture string. | ||
* @param textureName - Name to use for the texture. | ||
* @param mimeType - image mime type for the texture. | ||
* @param images - array of images. | ||
* @param textures - array of textures. | ||
* @param imageData - map of image data. | ||
* @returns - glTF texture info, or null if the texture format is not supported. | ||
*/ | ||
private static _GetTextureInfoFromBase64(base64Texture, textureName, mimeType, images, textures, imageData); | ||
} | ||
} |
@@ -7,3 +7,3 @@ { | ||
"description": "The Babylon.js serializers library is an extension you can use to serialize Babylon scenes.", | ||
"version": "3.2.0-alphaB", | ||
"version": "3.2.0-alphaC", | ||
"repository": { | ||
@@ -31,3 +31,3 @@ "type": "git", | ||
"dependencies": { | ||
"babylonjs-gltf2interface": "3.2.0-alphaB" | ||
"babylonjs-gltf2interface": "3.2.0-alphaC" | ||
}, | ||
@@ -34,0 +34,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
157677
2292
+ Addedbabylonjs-gltf2interface@3.2.0-alphaC(transitive)
- Removedbabylonjs-gltf2interface@3.2.0-alphaB(transitive)