babylonjs-serializers
Advanced tools
Comparing version 3.2.0-alpha0 to 3.2.0-alpha10
@@ -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,o,r){var i,n=arguments.length,a=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(n<3?i(a):n>3?i(t,o,a):i(t,o))||a);return n>3&&a&&Object.defineProperty(t,o,a),a},__extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])};return function(t,o){function r(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(r.prototype=o.prototype,new r)}})(),BABYLON;!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,o,r,i){var n=[],a=1;o&&(r||(r="mat"),n.push("mtllib "+r+".mtl"));for(var s=0;s<t.length;s++){n.push("g object"+s),n.push("o object_"+s);var u=null;if(i){var p=e.Matrix.Translation(t[s].position.x,t[s].position.y,t[s].position.z);u=e.Matrix.Translation(-t[s].position.x,-t[s].position.y,-t[s].position.z),t[s].bakeTransformIntoVertices(p)}if(o){var l=t[s].material;l&&n.push("usemtl "+l.id)}var f=t[s].geometry;if(f){var c=f.getVerticesData("position"),d=f.getVerticesData("normal"),h=f.getVerticesData("uv"),b=f.getIndices(),m=0;if(c&&d&&h&&b){for(var x=0;x<c.length;x+=3)n.push("v "+c[x]+" "+c[x+1]+" "+c[x+2]),m++;for(x=0;x<d.length;x+=3)n.push("vn "+d[x]+" "+d[x+1]+" "+d[x+2]);for(x=0;x<h.length;x+=2)n.push("vt "+h[x]+" "+h[x+1]);for(x=0;x<b.length;x+=3)n.push("f "+(b[x+2]+a)+"/"+(b[x+2]+a)+"/"+(b[x+2]+a)+" "+(b[x+1]+a)+"/"+(b[x+1]+a)+"/"+(b[x+1]+a)+" "+(b[x]+a)+"/"+(b[x]+a)+"/"+(b[x]+a));i&&u&&t[s].bakeTransformIntoVertices(u),a+=m}}}return n.join("\n")},t.MTL=function(e){var t=[],o=e.material;t.push("newmtl mat1"),t.push(" Ns "+o.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+o.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+o.ambientColor.r.toFixed(4)+" "+o.ambientColor.g.toFixed(4)+" "+o.ambientColor.b.toFixed(4)),t.push(" Kd "+o.diffuseColor.r.toFixed(4)+" "+o.diffuseColor.g.toFixed(4)+" "+o.diffuseColor.b.toFixed(4)),t.push(" Ks "+o.specularColor.r.toFixed(4)+" "+o.specularColor.g.toFixed(4)+" "+o.specularColor.b.toFixed(4)),t.push(" Ke "+o.emissiveColor.r.toFixed(4)+" "+o.emissiveColor.g.toFixed(4)+" "+o.emissiveColor.b.toFixed(4));return o.ambientTexture&&t.push(" map_Ka "+o.ambientTexture.name),o.diffuseTexture&&t.push(" map_Kd "+o.diffuseTexture.name),o.specularTexture&&t.push(" map_Ks "+o.specularTexture.name),o.bumpTexture&&t.push(" map_bump -imfchan z "+o.bumpTexture.name),o.opacityTexture&&t.push(" map_d "+o.opacityTexture.name),t.join("\n")},t})();e.OBJExport=t})(BABYLON||(BABYLON={})),(function(e,t){var o=t();e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=o:"function"==typeof define&&define.amd?define(["BJSSerializers"],t):"object"==typeof exports?exports.BJSSerializers=o:e.BABYLON=o)})(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"/> | ||
declare module 'babylonjs-serializers' { | ||
@@ -13,1 +15,384 @@ export = BABYLON; | ||
} | ||
declare module BABYLON { | ||
/** | ||
* Holds a collection of exporter options and parameters | ||
*/ | ||
interface IExporterOptions { | ||
/** | ||
* Function which indicates whether a babylon mesh should be exported or not. | ||
* @param mesh - source Babylon mesh. It is used to check whether it should be | ||
* exported to glTF or not. | ||
* @returns boolean, which indicates whether the mesh should be exported (true) or not (false) | ||
*/ | ||
shouldExportMesh?(mesh: AbstractMesh): boolean; | ||
} | ||
/** | ||
* Class for generating glTF data from a Babylon scene. | ||
*/ | ||
class GLTF2Export { | ||
/** | ||
* Exports the geometry of the scene to .gltf file format. | ||
* @param scene - Babylon scene with scene hierarchy information. | ||
* @param filePrefix - File prefix to use when generating the glTF file. | ||
* @param options - Exporter options. | ||
* @returns - Returns an object with a .gltf file and associates texture names | ||
* as keys and their data and paths as values. | ||
*/ | ||
static GLTF(scene: Scene, filePrefix: string, options?: IExporterOptions): _GLTFData; | ||
/** | ||
* Exports the geometry of the scene to .glb file format. | ||
* @param scene - Babylon scene with scene hierarchy information. | ||
* @param filePrefix - File prefix to use when generating glb file. | ||
* @param options - Exporter options. | ||
* @returns - Returns an object with a .glb filename as key and data as value | ||
*/ | ||
static GLB(scene: Scene, filePrefix: string, options?: IExporterOptions): _GLTFData; | ||
} | ||
} | ||
/** | ||
* Module for the Babylon glTF 2.0 exporter. Should ONLY be used internally. | ||
* @ignore - capitalization of GLTF2 module. | ||
*/ | ||
declare module BABYLON.GLTF2 { | ||
/** | ||
* Converts Babylon Scene into glTF 2.0. | ||
*/ | ||
class _Exporter { | ||
/** | ||
* Stores all generated buffer views, which represents views into the main glTF buffer data. | ||
*/ | ||
private bufferViews; | ||
/** | ||
* Stores all the generated accessors, which is used for accessing the data within the buffer views in glTF. | ||
*/ | ||
private accessors; | ||
/** | ||
* Stores all the generated nodes, which contains transform and/or mesh information per node. | ||
*/ | ||
private nodes; | ||
/** | ||
* Stores the glTF asset information, which represents the glTF version and this file generator. | ||
*/ | ||
private asset; | ||
/** | ||
* Stores all the generated glTF scenes, which stores multiple node hierarchies. | ||
*/ | ||
private scenes; | ||
/** | ||
* Stores all the generated mesh information, each containing a set of primitives to render in glTF. | ||
*/ | ||
private meshes; | ||
/** | ||
* Stores all the generated material information, which represents the appearance of each primitive. | ||
*/ | ||
private materials; | ||
/** | ||
* Stores all the generated texture information, which is referenced by glTF materials. | ||
*/ | ||
private textures; | ||
/** | ||
* Stores all the generated image information, which is referenced by glTF textures. | ||
*/ | ||
private images; | ||
/** | ||
* Stores the total amount of bytes stored in the glTF buffer. | ||
*/ | ||
private totalByteLength; | ||
/** | ||
* Stores a reference to the Babylon scene containing the source geometry and material information. | ||
*/ | ||
private babylonScene; | ||
/** | ||
* Stores the exporter options, which are optionally passed in from the glTF serializer. | ||
*/ | ||
private options?; | ||
/** | ||
* Stores a map of the image data, where the key is the file name and the value | ||
* is the image data. | ||
*/ | ||
private imageData; | ||
/** | ||
* 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. | ||
* @param babylonScene - Babylon scene object | ||
* @param options - Options to modify the behavior of the exporter. | ||
*/ | ||
constructor(babylonScene: Scene, options?: IExporterOptions); | ||
/** | ||
* Creates a buffer view based on teh supplied arguments | ||
* @param bufferIndex - index value of the specified buffer | ||
* @param byteOffset - byte offset value | ||
* @param byteLength - byte length of the bufferView | ||
* @param byteStride - byte distance between conequential elements. | ||
* @param name - name of the buffer view | ||
* @returns - bufferView for glTF | ||
*/ | ||
private createBufferView(bufferIndex, byteOffset, byteLength, byteStride?, name?); | ||
/** | ||
* Creates an accessor based on the supplied arguments | ||
* @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); | ||
/** | ||
* 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. | ||
* @returns - min number array and max number array. | ||
*/ | ||
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. | ||
* Returns the bytelength of the data. | ||
* @param vertexBufferKind - Indicates what kind of vertex data is being passed in. | ||
* @param meshAttributeArray - Array containing the attribute data. | ||
* @param strideSize - Represents the offset between consecutive attributes | ||
* @param byteOffset - The offset to start counting bytes from. | ||
* @param dataBuffer - The buffer to write the binary data to. | ||
* @returns - Byte length of the attribute data. | ||
*/ | ||
private writeAttributeData(vertexBufferKind, meshAttributeArray, strideSize, vertexBufferOffset, byteOffset, dataBuffer); | ||
/** | ||
* Generates glTF json data | ||
* @param shouldUseGlb - Indicates whether the json should be written for a glb file. | ||
* @param glTFPrefix - Text to use when prefixing a glTF file. | ||
* @param prettyPrint - Indicates whether the json file should be pretty printed (true) or not (false). | ||
* @returns - json data as string | ||
*/ | ||
private generateJSON(shouldUseGlb, glTFPrefix?, prettyPrint?); | ||
/** | ||
* Generates data for .gltf and .bin files based on the glTF prefix string | ||
* @param glTFPrefix - Text to use when prefixing a glTF file. | ||
* @returns - GLTFData with glTF file data. | ||
*/ | ||
_generateGLTF(glTFPrefix: string): _GLTFData; | ||
/** | ||
* Creates a binary buffer for glTF | ||
* @returns - array buffer for binary data | ||
*/ | ||
private generateBinary(); | ||
/** | ||
* Pads the number to a multiple of 4 | ||
* @param num - number to pad | ||
* @returns - padded number | ||
*/ | ||
private _getPadding(num); | ||
/** | ||
* Generates a glb file from the json and binary data. | ||
* Returns an object with the glb file name as the key and data as the value. | ||
* @param glTFPrefix | ||
* @returns - object with glb filename as key and data as value | ||
*/ | ||
_generateGLB(glTFPrefix: string): _GLTFData; | ||
/** | ||
* Sets the TRS for each node | ||
* @param node - glTF Node for storing the transformation data. | ||
* @param babylonMesh - Babylon mesh used as the source for the transformation data. | ||
*/ | ||
private setNodeTransformation(node, babylonMesh); | ||
/** | ||
* Creates a bufferview based on the vertices type for the Babylon mesh | ||
* @param kind - Indicates the type of vertices data. | ||
* @param babylonMesh - The Babylon mesh to get the vertices data from. | ||
* @param byteOffset - The offset from the buffer to start indexing from. | ||
* @param dataBuffer - The buffer to write the bufferview data to. | ||
* @returns bytelength of the bufferview data. | ||
*/ | ||
private createBufferViewKind(kind, babylonMesh, byteOffset, dataBuffer); | ||
/** | ||
* Sets data for the primitive attributes of each submesh | ||
* @param mesh - glTF Mesh object to store the primitive attribute information. | ||
* @param babylonMesh - Babylon mesh to get the primitive attribute data from. | ||
* @param byteOffset - The offset in bytes of the buffer data. | ||
* @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, dataBuffer); | ||
/** | ||
* Creates a glTF scene based on the array of meshes. | ||
* Returns the the total byte offset. | ||
* @param babylonScene - Babylon scene to get the mesh data from. | ||
* @param byteOffset - Offset to start from in bytes. | ||
* @returns bytelength + byteoffset | ||
*/ | ||
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); | ||
} | ||
} | ||
declare module BABYLON { | ||
/** | ||
* Class for holding and downloading glTF file data | ||
*/ | ||
class _GLTFData { | ||
/** | ||
* Object which contains the file name as the key and its data as the value. | ||
*/ | ||
glTFFiles: { | ||
[fileName: string]: string | Blob; | ||
}; | ||
/** | ||
* Initializes the glTF file object. | ||
*/ | ||
constructor(); | ||
/** | ||
* Downloads the glTF data as files based on their names and data. | ||
*/ | ||
downloadFiles(): void; | ||
} | ||
} | ||
declare module BABYLON.GLTF2 { | ||
/** | ||
* Utility methods for working with glTF material conversion properties. This class should only be used internally. | ||
*/ | ||
class _GLTFMaterial { | ||
/** | ||
* Represents the dielectric specular values for R, G and B. | ||
*/ | ||
private static readonly dielectricSpecular; | ||
/** | ||
* Allows the maximum specular power to be defined for material calculations. | ||
*/ | ||
private static maxSpecularPower; | ||
/** | ||
* 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 | ||
*/ | ||
static ConvertMaterialsToGLTF(babylonMaterials: Material[], mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
data: Uint8Array; | ||
mimeType: ImageMimeType; | ||
}; | ||
}, hasTextureCoords: boolean): void; | ||
/** | ||
* Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material. | ||
* @param babylonStandardMaterial | ||
* @returns - glTF Metallic Roughness Material representation | ||
*/ | ||
static ConvertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness; | ||
/** | ||
* Computes the metallic factor | ||
* @param diffuse - diffused value | ||
* @param specular - specular value | ||
* @param oneMinusSpecularStrength - one minus the specular strength | ||
* @returns - metallic value | ||
*/ | ||
static SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number; | ||
/** | ||
* Gets the glTF alpha mode from the Babylon Material | ||
* @param babylonMaterial - Babylon Material | ||
* @returns - The Babylon alpha mode value | ||
*/ | ||
static GetAlphaMode(babylonMaterial: Material): MaterialAlphaMode; | ||
/** | ||
* Converts a Babylon Standard Material to a glTF Material. | ||
* @param babylonStandardMaterial - BJS Standard 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 materials - array of glTF material interfaces. | ||
* @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. | ||
*/ | ||
static ConvertStandardMaterial(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
data: Uint8Array; | ||
mimeType: ImageMimeType; | ||
}; | ||
}, hasTextureCoords: boolean): void; | ||
/** | ||
* Converts a Babylon PBR Metallic Roughness Material to a glTF Material. | ||
* @param babylonPBRMetalRoughMaterial - 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 materials - array of glTF material interfaces. | ||
* @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. | ||
*/ | ||
static ConvertPBRMetallicRoughnessMaterial(babylonPBRMetalRoughMaterial: PBRMetallicRoughnessMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], materials: IMaterial[], imageData: { | ||
[fileName: string]: { | ||
data: Uint8Array; | ||
mimeType: ImageMimeType; | ||
}; | ||
}, hasTextureCoords: boolean): void; | ||
/** | ||
* Extracts a texture from a Babylon texture into file data and glTF data. | ||
* @param babylonTexture - Babylon texture to extract. | ||
* @param mimeType - Mime Type of the babylonTexture. | ||
* @param images - Array of glTF images. | ||
* @param textures - Array of glTF textures. | ||
* @param imageData - map of image file name and data. | ||
* @return - glTF texture, 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>; | ||
} | ||
} |
@@ -7,3 +7,3 @@ { | ||
"description": "The Babylon.js serializers library is an extension you can use to serialize Babylon scenes.", | ||
"version": "3.2.0-alpha0", | ||
"version": "3.2.0-alpha10", | ||
"repository": { | ||
@@ -30,10 +30,11 @@ "type": "git", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"babylonjs-gltf2interface": "3.2.0-alpha10" | ||
}, | ||
"peerDependencies": { | ||
"babylonjs": ">=3.1.0-alpha" | ||
"babylonjs": ">=3.2.0-alpha" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"_id": "babylonjs-serializers@3.1.0-alpha1", | ||
"_from": "babylonjs-serializers@" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109837
1679
2
1
+ Addedbabylonjs-gltf2interface@3.2.0-alpha10(transitive)