babylonjs-serializers
Advanced tools
Comparing version 3.2.0-alpha4 to 3.2.0-alpha6
@@ -1,1 +0,1 @@ | ||
var globalObject="undefined"!=typeof global?global:"undefined"!=typeof window?window:this,babylonDependency=globalObject&&globalObject.BABYLON||BABYLON||"undefined"!=typeof require&&require("babylonjs"),BABYLON=babylonDependency,__decorate=this&&this.__decorate||function(e,t,r,i){var s,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(a=(n<3?s(a):n>3?s(t,r,a):s(t,r))||a);return n>3&&a&&Object.defineProperty(t,r,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 r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function i(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}})(),BABYLON;!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,i,s){var n=[],a=1;r&&(i||(i="mat"),n.push("mtllib "+i+".mtl"));for(var o=0;o<t.length;o++){n.push("g object"+o),n.push("o object_"+o);var u=null;if(s){var f=e.Matrix.Translation(t[o].position.x,t[o].position.y,t[o].position.z);u=e.Matrix.Translation(-t[o].position.x,-t[o].position.y,-t[o].position.z),t[o].bakeTransformIntoVertices(f)}if(r){var c=t[o].material;c&&n.push("usemtl "+c.id)}var h=t[o].geometry;if(h){var l=h.getVerticesData("position"),p=h.getVerticesData("normal"),d=h.getVerticesData("uv"),v=h.getIndices(),g=0;if(l&&p&&d&&v){for(var b=0;b<l.length;b+=3)n.push("v "+l[b]+" "+l[b+1]+" "+l[b+2]),g++;for(b=0;b<p.length;b+=3)n.push("vn "+p[b]+" "+p[b+1]+" "+p[b+2]);for(b=0;b<d.length;b+=2)n.push("vt "+d[b]+" "+d[b+1]);for(b=0;b<v.length;b+=3)n.push("f "+(v[b+2]+a)+"/"+(v[b+2]+a)+"/"+(v[b+2]+a)+" "+(v[b+1]+a)+"/"+(v[b+1]+a)+"/"+(v[b+1]+a)+" "+(v[b]+a)+"/"+(v[b]+a)+"/"+(v[b]+a));s&&u&&t[o].bakeTransformIntoVertices(u),a+=g}}}return n.join("\n")},t.MTL=function(e){var t=[],r=e.material;t.push("newmtl mat1"),t.push(" Ns "+r.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+r.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+r.ambientColor.r.toFixed(4)+" "+r.ambientColor.g.toFixed(4)+" "+r.ambientColor.b.toFixed(4)),t.push(" Kd "+r.diffuseColor.r.toFixed(4)+" "+r.diffuseColor.g.toFixed(4)+" "+r.diffuseColor.b.toFixed(4)),t.push(" Ks "+r.specularColor.r.toFixed(4)+" "+r.specularColor.g.toFixed(4)+" "+r.specularColor.b.toFixed(4)),t.push(" Ke "+r.emissiveColor.r.toFixed(4)+" "+r.emissiveColor.g.toFixed(4)+" "+r.emissiveColor.b.toFixed(4));return r.ambientTexture&&t.push(" map_Ka "+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+r.opacityTexture.name),t.join("\n")},t})();e.OBJExport=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r){var i=r.replace(/\.[^\/.]+$/,"");return new e._GLTF2Exporter(t)._generateGLTF(i)},t.GLB=function(t,r){var i=r.replace(/\.[^\/.]+$/,"");return new e._GLTF2Exporter(t)._generateGLB(i)},t})();e.GLTF2Export=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(e){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;var t=0;t=this.createScene(this.babylonScene,t),this.totalByteLength=t}return t.prototype.createBufferView=function(e,t,r){var i={buffer:e,byteLength:r};return t>0&&(i.byteOffset=t),i},t.prototype.createAccessor=function(e,t,r,i,s,n,a){var o={name:t,bufferView:e,componentType:i,count:s,type:r};return n&&(o.min=n),a&&(o.max=a),o},t.prototype.calculateMinMax=function(e,t,r,i,s){var n=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0],o=t+r;if(r>0)for(var u=t;u<o;++u)for(var f=s*u,c=0;c<s;++c)e[f]<n[c]&&(n[c]=e[f]),e[f]>a[c]&&(a[c]=e[f]),++f;return{min:n,max:a}},t.prototype.writeAttributeData=function(t,r,i,s,n,a,o){var u=n,f=r.verticesStart+r.verticesCount,c=0;switch(t){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var h=r.verticesStart;h<f;++h){var l=h*s;a.setFloat32(u,i[l],!0),u+=4,a.setFloat32(u,i[l+1],!0),u+=4,o?a.setFloat32(u,i[l+2],!0):a.setFloat32(u,-i[l+2],!0),u+=4}c=12*r.verticesCount;break;case e.VertexBuffer.TangentKind:for(var h=r.indexStart;h<f;++h){var l=h*s;a.setFloat32(u,i[l],!0),u+=4,a.setFloat32(u,i[l+1],!0),u+=4,o?a.setFloat32(u,i[l+2],!0):a.setFloat32(u,-i[l+2],!0),u+=4,a.setFloat32(u,i[l+3],!0),u+=4}c=16*r.verticesCount;break;case e.VertexBuffer.ColorKind:for(var h=r.verticesStart;h<f;++h){var l=h*s;a.setFloat32(u,i[l],!0),u+=4,a.setFloat32(u,i[l+1],!0),u+=4,a.setFloat32(u,i[l+2],!0),u+=4,a.setFloat32(u,i[l+3],!0),u+=4}c=16*r.verticesCount;break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var h=r.verticesStart;h<f;++h){var l=h*s;a.setFloat32(u,i[l],!0),u+=4,a.setFloat32(u,i[l+1],!0),u+=4}c=8*r.verticesCount;break;default:throw new Error("Unsupported vertex buffer type: "+t)}return c},t.prototype.generateJSON=function(e,t,r){var i={byteLength:this.totalByteLength},s={buffers:[i],asset:this.asset,meshes:this.meshes,scenes:this.scenes,nodes:this.nodes,bufferViews:this.bufferViews,accessors:this.accessors};return this.scenes.length>0&&(s.scene=0),e||(i.uri=t+".bin"),r?JSON.stringify(s,null,2):JSON.stringify(s)},t.prototype._generateGLTF=function(t){var r=this.generateJSON(!1,t,!0),i=this.generateBinary(),s=new Blob([i],{type:"application/octet-stream"}),n=t+".gltf",a=t+".bin",o=new e._GLTFData;return o._glTFFiles[n]=r,o._glTFFiles[a]=s,o},t.prototype.generateBinary=function(){var e=0,t=new ArrayBuffer(this.totalByteLength),r=new DataView(t);return e=this.createScene(this.babylonScene,e,r),t},t.prototype._generateGLB=function(t){var r=this.generateJSON(!0),i=this.generateBinary(),s=t+".glb",n=r.length,a=n%4,o=i.byteLength%4,u=0===a?a:4-a,f=0===o?o:4-o,c=28+n+u+i.byteLength+f,h=new ArrayBuffer(12),l=new DataView(h);l.setUint32(0,1179937895,!0),l.setUint32(4,2,!0),l.setUint32(8,c,!0);var p=new ArrayBuffer(8+n+u),d=new DataView(p);d.setUint32(0,n+u,!0),d.setUint32(4,1313821514,!0);for(var v=new Uint8Array(p,8),g=0;g<n;++g)v[g]=r.charCodeAt(g);for(var b=new Uint8Array(p,8+n),g=0;g<u;++g)b[g]=32;var B=new ArrayBuffer(8),y=new DataView(B);y.setUint32(0,i.byteLength,!0),y.setUint32(4,5130562,!0);for(var x=new ArrayBuffer(f),V=new Uint8Array(x),g=0;g<f;++g)V[g]=0;var w=new Blob([h,p,B,i,x],{type:"application/octet-stream"}),m=new e._GLTFData;return m._glTFFiles[s]=w,m},t.prototype.setNodeTransformation=function(t,r,i){0===r.position.x&&0===r.position.y&&0===r.position.z||(t.translation=i?r.position.asArray():[r.position.x,r.position.y,-r.position.z]),1===r.scaling.x&&1===r.scaling.y&&1===r.scaling.z||(t.scale=i?r.scaling.asArray():[r.scaling.x,r.scaling.y,-r.scaling.z]);var s=e.Quaternion.RotationYawPitchRoll(r.rotation.y,r.rotation.x,r.rotation.z);r.rotationQuaternion&&(s=s.multiply(r.rotationQuaternion)),0===s.x&&0===s.y&&0===s.z&&1===s.w||(t.rotation=i?s.asArray():[-s.x,-s.y,s.z,s.w])},t.prototype.setPrimitiveAttributes=function(t,r,i,s,n){for(var a=0;a<r.subMeshes.length;++a){var o=null,u=r.subMeshes[a],f={attributes:{}};if(r instanceof e.Mesh?o=r:r instanceof e.InstancedMesh&&(o=r.sourceMesh),o.isVerticesDataPresent(e.VertexBuffer.PositionKind)){var c=o.getVertexBuffer(e.VertexBuffer.PositionKind),h=c.getOffset(),l=c.getData(),p=c.getStrideSize();if(n)i+=this.writeAttributeData(e.VertexBuffer.PositionKind,u,l,p,i,n,s);else{var d=12*u.verticesCount,v=this.createBufferView(0,i,d);i+=d,this.bufferViews.push(v);var g=this.calculateMinMax(l,u.verticesStart,u.verticesCount,h,p),b=this.createAccessor(this.bufferViews.length-1,"Position","VEC3",5126,u.verticesCount,g.min,g.max);this.accessors.push(b),f.attributes.POSITION=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.NormalKind)){var B=o.getVertexBuffer(e.VertexBuffer.NormalKind),y=B.getData(),x=B.getStrideSize();if(n)i+=this.writeAttributeData(e.VertexBuffer.NormalKind,u,y,x,i,n,s);else{var d=12*u.verticesCount,v=this.createBufferView(0,i,d);i+=d,this.bufferViews.push(v);var b=this.createAccessor(this.bufferViews.length-1,"Normal","VEC3",5126,u.verticesCount);this.accessors.push(b),f.attributes.NORMAL=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.TangentKind)){var V=o.getVertexBuffer(e.VertexBuffer.TangentKind),w=V.getData(),m=V.getStrideSize();if(n)i+=this.writeAttributeData(e.VertexBuffer.TangentKind,u,w,m,i,n,s);else{var d=16*u.verticesCount,v=this.createBufferView(0,i,d);i+=d,this.bufferViews.push(v);var b=this.createAccessor(this.bufferViews.length-1,"Tangent","VEC4",5126,u.verticesCount);this.accessors.push(b),f.attributes.TANGENT=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.ColorKind)){var A=o.getVertexBuffer(e.VertexBuffer.ColorKind),C=A.getData(),F=A.getStrideSize();if(n)i+=this.writeAttributeData(e.VertexBuffer.ColorKind,u,C,F,i,n,s);else{var d=16*u.verticesCount,v=this.createBufferView(0,i,d);i+=d,this.bufferViews.push(v);var b=this.createAccessor(this.bufferViews.length-1,"Color","VEC4",5126,u.verticesCount);this.accessors.push(b),f.attributes.COLOR_0=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.UVKind)){var T=o.getVertexBuffer(e.VertexBuffer.UVKind),O=T.getData(),L=T.getStrideSize();if(n)i+=this.writeAttributeData(e.VertexBuffer.UVKind,u,O,L,i,n,s);else{var d=8*u.verticesCount,v=this.createBufferView(0,i,d);i+=d,this.bufferViews.push(v);var b=this.createAccessor(this.bufferViews.length-1,"Texture Coords","VEC2",5126,u.verticesCount);this.accessors.push(b),f.attributes.TEXCOORD_0=this.accessors.length-1}}if(o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)){var _=o.getVertexBuffer(e.VertexBuffer.UV2Kind),S=_.getData(),N=_.getStrideSize();if(n)i+=this.writeAttributeData(e.VertexBuffer.UV2Kind,u,S,N,i,n,s);else{var d=8*u.verticesCount,v=this.createBufferView(0,i,d);i+=d,this.bufferViews.push(v);var b=this.createAccessor(this.bufferViews.length-1,"Texture Coords","VEC2",5126,u.verticesCount);this.accessors.push(b),f.attributes.TEXCOORD_1=this.accessors.length-1}}if(o.getTotalIndices()>0)if(n){for(var D=o.getIndices(),K=u.indexStart,U=u.indexCount+K,P=i,Y=K;Y<U;Y+=3)n.setUint32(P,D[Y],!0),P+=4,n.setUint32(P,D[Y+1],!0),P+=4,n.setUint32(P,D[Y+2],!0),P+=4;var d=4*u.indexCount;i+=d}else{var j=u.indexCount,d=4*j,v=this.createBufferView(0,i,d);i+=d,this.bufferViews.push(v);var b=this.createAccessor(this.bufferViews.length-1,"Indices","SCALAR",5125,j);this.accessors.push(b),f.indices=this.accessors.length-1}o.material,t.primitives.push(f)}return i},t.prototype.createScene=function(e,t,r){if(e.meshes.length>0){for(var i=e.meshes,s={nodes:new Array},n=0;n<i.length;++n){var a={mesh:-1},o=i[n],u=o.getScene().useRightHandedSystem;this.setNodeTransformation(a,o,u);var f={primitives:new Array};f.primitives=[],t=this.setPrimitiveAttributes(f,o,t,u,r),this.meshes.push(f),a.mesh=this.meshes.length-1,o.name&&(a.name=o.name),this.nodes.push(a),s.nodes.push(this.nodes.length-1)}this.scenes.push(s)}return t},t})();e._GLTF2Exporter=t})(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 i=this._glTFFiles[t],s=void 0;e(t,".glb")?s={type:"model/gltf-binary"}:e(t,".bin")?s={type:"application/octet-stream"}:e(t,".gltf")&&(s={type:"model/gltf+json"}),r.href=window.URL.createObjectURL(new Blob([i],s)),r.click()}},e})();e._GLTFData=t})(BABYLON||(BABYLON={})),(function(e,t){var r=t();e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=r:"function"==typeof define&&define.amd?define(["BJSSerializers"],t):"object"==typeof exports?exports.BJSSerializers=r:e.BABYLON=r)})(this,(function(){return BABYLON})); | ||
var globalObject="undefined"!=typeof global?global:"undefined"!=typeof window?window:this,babylonDependency=globalObject&&globalObject.BABYLON||BABYLON||"undefined"!=typeof require&&require("babylonjs"),BABYLON=babylonDependency,__decorate=this&&this.__decorate||function(e,t,r,i){var a,s=arguments.length,n=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,i);else for(var o=e.length-1;o>=0;o--)(a=e[o])&&(n=(s<3?a(n):s>3?a(t,r,n):a(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 i(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}})(),BABYLON;!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,r,i,a){var s=[],n=1;r&&(i||(i="mat"),s.push("mtllib "+i+".mtl"));for(var o=0;o<t.length;o++){s.push("g object"+o),s.push("o object_"+o);var l=null;if(a){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 f=t[o].geometry;if(f){var c=f.getVerticesData("position"),p=f.getVerticesData("normal"),g=f.getVerticesData("uv"),d=f.getIndices(),m=0;if(c&&p&&g&&d){for(var x=0;x<c.length;x+=3)s.push("v "+c[x]+" "+c[x+1]+" "+c[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<g.length;x+=2)s.push("vt "+g[x]+" "+g[x+1]);for(x=0;x<d.length;x+=3)s.push("f "+(d[x+2]+n)+"/"+(d[x+2]+n)+"/"+(d[x+2]+n)+" "+(d[x+1]+n)+"/"+(d[x+1]+n)+"/"+(d[x+1]+n)+" "+(d[x]+n)+"/"+(d[x]+n)+"/"+(d[x]+n));a&&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})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function t(){}return t.GLTF=function(t,r,i){var a=r.replace(/\.[^\/.]+$/,""),s=new e.GLTF2._Exporter(t,i);if(t.isReady)return s._generateGLTF(a);throw new Error("glTF Serializer: Scene is not ready!")},t.GLB=function(t,r,i){var a=r.replace(/\.[^\/.]+$/,""),s=new e.GLTF2._Exporter(t,i);if(t.isReady)return s._generateGLB(a);throw new Error("glTF Serializer: Scene is not ready!")},t})();e.GLTF2Export=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function r(e,t){this.asset={generator:"BabylonJS",version:"2.0"},this.babylonScene=e,this.bufferViews=new Array,this.accessors=new Array,this.meshes=new Array,this.scenes=new Array,this.nodes=new Array,this.images=new Array,this.materials=new Array,this.textures=new Array,this.imageData={},void 0!==t&&(this.options=t);var r=0;r=this.createScene(this.babylonScene,r,null),this.totalByteLength=r}return r.prototype.createBufferView=function(e,t,r,i,a){var s={buffer:e,byteLength:r};return t>0&&(s.byteOffset=t),a&&(s.name=a),i&&(s.byteStride=i),s},r.prototype.createAccessor=function(e,t,r,i,a,s,n,o){var l={name:t,bufferView:e,componentType:i,count:a,type:r};return n&&(l.min=n),o&&(l.max=o),s&&(l.byteOffset=s),l},r.prototype.calculateMinMax=function(e,t,r,i,a){var s=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],o=t+r;if(r>0)for(var l=t;l<o;++l)for(var u=i*l,h=1,f=0;f<i;++f){f!==i-1||a||(h=-1);var c=h*e[u];c<s[f]&&(s[f]=c),c>n[f]&&(n[f]=c),++u}return{min:s,max:n}},r.prototype.writeAttributeData=function(t,r,i,a,s,n,o){var l=s,u=r.length/i,h=0;switch(t){case e.VertexBuffer.PositionKind:case e.VertexBuffer.NormalKind:for(var f=0;f<u;++f){var c=f*i;n.setFloat32(l,r[c],!0),l+=4,n.setFloat32(l,r[c+1],!0),l+=4,o?n.setFloat32(l,r[c+2],!0):n.setFloat32(l,-r[c+2],!0),l+=4}h=4*r.length;break;case e.VertexBuffer.TangentKind:for(var f=0;f<u;++f){var c=f*i;n.setFloat32(l,r[c],!0),l+=4,n.setFloat32(l,r[c+1],!0),l+=4,o?n.setFloat32(l,r[c+2],!0):n.setFloat32(l,-r[c+2],!0),l+=4,n.setFloat32(l,r[c+3],!0),l+=4}h=4*r.length;break;case e.VertexBuffer.ColorKind:for(var f=0;f<u;++f){var c=f*i;n.setFloat32(l,r[c],!0),l+=4,n.setFloat32(l,r[c+1],!0),l+=4,n.setFloat32(l,r[c+2],!0),l+=4,n.setFloat32(l,r[c+3],!0),l+=4}h=4*r.length;break;case e.VertexBuffer.UVKind:case e.VertexBuffer.UV2Kind:for(var f=0;f<u;++f){var c=f*i;n.setFloat32(l,r[c],!0),l+=4,n.setFloat32(l,r[c+1],!0),l+=4}h=4*r.length;break;default:throw new Error("Unsupported vertex buffer type: "+t)}return h},r.prototype.generateJSON=function(e,t,r){var i={byteLength:this.totalByteLength},a={asset:this.asset};if(i.byteLength>0&&(a.buffers=[i]),this.nodes&&0!==this.nodes.length&&(a.nodes=this.nodes),this.meshes&&0!==this.meshes.length&&(a.meshes=this.meshes),this.scenes&&0!==this.scenes.length&&(a.scenes=this.scenes,a.scene=0),this.bufferViews&&0!==this.bufferViews.length&&(a.bufferViews=this.bufferViews),this.accessors&&0!==this.accessors.length&&(a.accessors=this.accessors),this.materials&&0!==this.materials.length&&(a.materials=this.materials),this.textures&&0!==this.textures.length&&(a.textures=this.textures),this.images&&0!==this.images.length)if(e){a.images=[];for(var s=this.images.length,n=this.totalByteLength,o=0;o<s;++o){var l=this.images[o];if(void 0!==l.uri){var u=this.imageData[l.uri],h=l.uri.split(".")[0]+" image",f=this.createBufferView(0,n,u.data.length,void 0,h);n+=u.data.buffer.byteLength,this.bufferViews.push(f),l.bufferView=this.bufferViews.length-1,l.name=h,l.mimeType=u.mimeType,l.uri=void 0,a.images.push(l)}}i.byteLength=n}else a.images=this.images;return e||(i.uri=t+".bin"),r?JSON.stringify(a,null,2):JSON.stringify(a)},r.prototype._generateGLTF=function(t){var r=this.generateJSON(!1,t,!0),i=this.generateBinary(),a=new Blob([i],{type:"application/octet-stream"}),s=t+".gltf",n=t+".bin",o=new e._GLTFData;if(o.glTFFiles[s]=r,o.glTFFiles[n]=a,null!==this.imageData)for(var l in this.imageData)o.glTFFiles[l]=new Blob([this.imageData[l].data],{type:this.imageData[l].mimeType});return o},r.prototype.generateBinary=function(){var e=0,t=new ArrayBuffer(this.totalByteLength),r=new DataView(t);return e=this.createScene(this.babylonScene,e,r),t},r.prototype._getPadding=function(e){var t=e%4;return 0===t?t:4-t},r.prototype._generateGLB=function(t){var r=this.generateJSON(!0),i=this.generateBinary(),a=t+".glb",s=r.length,n=0;for(var o in this.imageData)n+=this.imageData[o].data.byteLength;var l=this._getPadding(s),u=this._getPadding(i.byteLength),h=this._getPadding(n),f=28+s+l+i.byteLength+u+n+h,c=new ArrayBuffer(12),p=new DataView(c);p.setUint32(0,1179937895,!0),p.setUint32(4,2,!0),p.setUint32(8,f,!0);var g=new ArrayBuffer(8+s+l),d=new DataView(g);d.setUint32(0,s+l,!0),d.setUint32(4,1313821514,!0);for(var m=new Uint8Array(g,8),x=0;x<s;++x)m[x]=r.charCodeAt(x);for(var v=new Uint8Array(g,8+s),x=0;x<l;++x)v[x]=32;var b=new ArrayBuffer(8),B=new DataView(b);B.setUint32(0,i.byteLength+n+h,!0),B.setUint32(4,5130562,!0);for(var y=new ArrayBuffer(u),T=new Uint8Array(y),x=0;x<u;++x)T[x]=0;for(var w=new ArrayBuffer(h),V=new Uint8Array(w),x=0;x<h;++x)V[x]=0;var A=[c,g,b,i];for(var o in this.imageData)A.push(this.imageData[o].data.buffer);A.push(y),A.push(w);var L=new Blob(A,{type:"application/octet-stream"}),F=new e._GLTFData;return F.glTFFiles[a]=L,F},r.prototype.setNodeTransformation=function(t,r,i){0===r.position.x&&0===r.position.y&&0===r.position.z||(t.translation=i?r.position.asArray():[r.position.x,r.position.y,-r.position.z]),1===r.scaling.x&&1===r.scaling.y&&1===r.scaling.z||(t.scale=i?r.scaling.asArray():[r.scaling.x,r.scaling.y,-r.scaling.z]);var a=e.Quaternion.RotationYawPitchRoll(r.rotation.y,r.rotation.x,r.rotation.z);r.rotationQuaternion&&(a=a.multiply(r.rotationQuaternion)),0===a.x&&0===a.y&&0===a.z&&1===a.w||(t.rotation=i?a.asArray():[-a.x,-a.y,a.z,a.w])},r.prototype.exportTexture=function(e,t){void 0===t&&(t="image/jpeg");var r,i=null;r={source:this.images.length};var a=e.getInternalTexture().url;if(-1!==a.search("/")){var s=a.split("/");a=s[s.length-1];var n=a.split(".")[0],o=a.split(".")[1];if("image/jpeg"===t)o=".jpg";else{if("image/png"!==t)throw new Error("Unsupported mime type "+t);o=".png"}a=n+o}var l=e.readPixels(),u=document.createElement("canvas");u.id="ImageCanvas";var h=u.getContext("2d"),f=e.getSize();u.width=f.width,u.height=f.height;var c=h.createImageData(f.width,f.height);c.data.set(l),h.putImageData(c,0,0);for(var p=u.toDataURL(t),g=atob(p.split(",")[1]),d=new Uint8Array(g.length),m=0;m<g.length;++m)d[m]=g.charCodeAt(m);var x={data:d,mimeType:t};if(this.imageData[a]=x,"image/jpeg"===t){for(var v={uri:a},b=-1,m=0;m<this.images.length;++m)if(this.images[m].uri===a){b=m;break}-1===b?(this.images.push(v),r.source=this.images.length-1,this.textures.push({source:this.images.length-1}),i={index:this.images.length-1}):(r.source=b,i={index:b})}return i},r.prototype.createBufferViewKind=function(t,r,i,a,s){var n=null,o=0;if(r instanceof e.Mesh?n=r:r instanceof e.InstancedMesh&&(n=r.sourceMesh),null!==n){var l=null,u=null,h=null,f=null;if(n.getVerticesDataKinds().indexOf(t)>-1)if(l=n.getVertexBuffer(t),u=l.getOffset(),h=l.getData(),f=l.getStrideSize(),s&&h)o=this.writeAttributeData(t,h,f,u,i,s,a),i+=o;else{var c=null;switch(t){case e.VertexBuffer.PositionKind:o=4*h.length,c="Position - "+n.name;break;case e.VertexBuffer.NormalKind:o=4*h.length,c="Normal - "+n.name;break;case e.VertexBuffer.TangentKind:o=4*h.length,c="Tangent - "+n.name;break;case e.VertexBuffer.ColorKind:o=4*h.length,c="Color - "+n.name;break;case e.VertexBuffer.UVKind:o=4*h.length,c="TexCoord 0 - "+n.name;break;case e.VertexBuffer.UV2Kind:o=4*h.length,c="TexCoord 1 - "+n.name;break;default:console.warn("Unsupported VertexBuffer kind: "+t)}if(null!==c){var p=this.createBufferView(0,i,o,4*f,c);i+=o,this.bufferViews.push(p)}}}return o},r.prototype.setPrimitiveAttributes=function(r,i,a,s,n){var o=null;i instanceof e.Mesh?o=i:i instanceof e.InstancedMesh&&(o=i.sourceMesh);var l=null,u=null,h=null,f=null,c=null,p=null;if(null!==o&&(o.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.PositionKind,i,a,s,n),l=this.bufferViews.length-1),o.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.NormalKind,i,a,s,n),u=this.bufferViews.length-1),o.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.ColorKind,i,a,s,n),h=this.bufferViews.length-1),o.isVerticesDataPresent(e.VertexBuffer.TangentKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.TangentKind,i,a,s,n),h=this.bufferViews.length-1),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(a+=this.createBufferViewKind(e.VertexBuffer.UVKind,i,a,s,n),f=this.bufferViews.length-1),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(a+=this.createBufferViewKind(e.VertexBuffer.UV2Kind,i,a,s,n),c=this.bufferViews.length-1),o.getTotalIndices()>0)){var g=o.getIndices();if(n){for(var d=g.length,m=a,x=0;x<d;++x)n.setUint32(m,g[x],!0),m+=4;a=m}else{var v=4*g.length,b=this.createBufferView(0,a,v,void 0,"Indices - "+o.name);a+=v,this.bufferViews.push(b),p=this.bufferViews.length-1}}for(var B=0;B<i.subMeshes.length;++B){var y=i.subMeshes[B],T={attributes:{}};if(null!==o){if(!n){if(null!==l){var w=o.getVertexBuffer(e.VertexBuffer.PositionKind),V=w.getData(),A=w.getStrideSize(),L=this.calculateMinMax(V,0,V.length/A,A,s),F=this.createAccessor(l,"Position","VEC3",5126,V.length/A,0,L.min,L.max);this.accessors.push(F),T.attributes.POSITION=this.accessors.length-1}if(null!==u){var C=o.getVertexBuffer(e.VertexBuffer.NormalKind),S=C.getData(),M=C.getStrideSize(),F=this.createAccessor(u,"Normal","VEC3",5126,S.length/M);this.accessors.push(F),T.attributes.NORMAL=this.accessors.length-1}var F;if(null!==h){var O=o.getVertexBuffer(e.VertexBuffer.ColorKind),D=O.getData(),P=O.getStrideSize(),F=this.createAccessor(h,"Color","VEC4",5126,D.length/P);this.accessors.push(F),T.attributes.COLOR_0=this.accessors.length-1}if(null!==f){var K=o.getVertexBuffer(e.VertexBuffer.UVKind),_=K.getData(),N=K.getStrideSize(),F=this.createAccessor(f,"Texture Coords 0","VEC2",5126,_.length/N);this.accessors.push(F),T.attributes.TEXCOORD_0=this.accessors.length-1}if(null!==c){var E=o.getVertexBuffer(e.VertexBuffer.UV2Kind),R=E.getData(),U=E.getStrideSize(),F=this.createAccessor(c,"Texture Coords 1","VEC2",5126,R.length/U);this.accessors.push(F),T.attributes.TEXCOORD_1=this.accessors.length-1}if(p){var F=this.createAccessor(p,"Indices","SCALAR",5125,y.indexCount,4*y.indexStart);this.accessors.push(F),T.indices=this.accessors.length-1}}if(o.material)if(o.material instanceof e.StandardMaterial){console.warn("Standard Material is currently not fully supported/implemented in glTF serializer");var j=o.material,G=t._GLTFMaterial.ConvertToGLTFPBRMetallicRoughness(j),z={name:j.name};if(j.backFaceCulling||(z.doubleSided=!0),j.diffuseTexture&&o.isVerticesDataPresent(e.VertexBuffer.UVKind)){var Y=this.exportTexture(j.diffuseTexture);null!==Y&&(G.baseColorTexture=Y)}if(j.bumpTexture&&o.isVerticesDataPresent(e.VertexBuffer.UVKind)){var Y=this.exportTexture(j.bumpTexture);Y&&(z.normalTexture=Y)}if(j.emissiveTexture&&o.isVerticesDataPresent(e.VertexBuffer.UVKind)){var I=this.exportTexture(j.emissiveTexture);I&&(z.emissiveTexture=I),z.emissiveFactor=[1,1,1]}if(j.ambientTexture&&o.isVerticesDataPresent(e.VertexBuffer.UVKind)){var k=this.exportTexture(j.ambientTexture);k&&(z.occlusionTexture=k)}(j.alpha<1||j.opacityTexture)&&(j.alphaMode===e.Engine.ALPHA_COMBINE?z.alphaMode="BLEND":console.warn("glTF 2.0 does not support alpha mode: "+j.alphaMode.toString())),z.pbrMetallicRoughness=G,this.materials.push(z),T.material=this.materials.length-1}else if(o.material instanceof e.PBRMetallicRoughnessMaterial){var J=o.material,G={};if(J.baseColor&&(G.baseColorFactor=[J.baseColor.r,J.baseColor.g,J.baseColor.b,J.alpha]),void 0!==J.baseTexture){var Y=this.exportTexture(J.baseTexture);null!==Y&&(G.baseColorTexture=Y),G.baseColorTexture}void 0!==J.metallic&&(G.metallicFactor=J.metallic),void 0!==J.roughness&&(G.roughnessFactor=J.roughness);var z={name:J.name};if(J.doubleSided&&(z.doubleSided=J.doubleSided),J.normalTexture){var Y=this.exportTexture(J.normalTexture);Y&&(z.normalTexture=Y)}if(J.occlusionTexture){var Y=this.exportTexture(J.occlusionTexture);Y&&(z.occlusionTexture=Y,void 0!==J.occlusionStrength&&(z.occlusionTexture.strength=J.occlusionStrength))}if(J.emissiveTexture){var Y=this.exportTexture(J.emissiveTexture);null!==Y&&(z.emissiveTexture=Y)}if(J.emissiveColor.equals(new e.Color3(0,0,0))||(z.emissiveFactor=J.emissiveColor.asArray()),J.transparencyMode){var Q=t._GLTFMaterial.GetAlphaMode(J);"OPAQUE"!==Q&&(z.alphaMode=Q,"BLEND"===Q&&(z.alphaCutoff=J.alphaCutOff))}z.pbrMetallicRoughness=G,this.materials.push(z),T.material=this.materials.length-1}else console.warn("Material type is not yet implemented in glTF serializer: "+o.material.name);r.primitives.push(T)}}return a},r.prototype.createScene=function(e,t,r){if(e.meshes.length>0){for(var i=e.meshes,a={nodes:new Array},s=0;s<i.length;++s)if(!this.options||void 0===this.options.shouldExportMesh||this.options.shouldExportMesh(i[s])){var n={mesh:-1},o=i[s],l=o.getScene().useRightHandedSystem;this.setNodeTransformation(n,o,l);var u={primitives:new Array};u.primitives=[],t=this.setPrimitiveAttributes(u,o,t,l,r),this.meshes.push(u),n.mesh=this.meshes.length-1,o.name&&(n.name=o.name),this.nodes.push(n),a.nodes.push(this.nodes.length-1)}this.scenes.push(a)}return t},r})();t._Exporter=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){var t=(function(){function e(){this.glTFFiles={}}return e.prototype.downloadFiles=function(){function e(e,t){return-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 i=this.glTFFiles[t],a=void 0;e(t,".glb")?a={type:"model/gltf-binary"}:e(t,".bin")?a={type:"application/octet-stream"}:e(t,".gltf")?a={type:"model/gltf+json"}:e(t,".jpeg")?a={type:"image/jpeg"}:e(t,".png")&&(a={type:"image/png"}),r.href=window.URL.createObjectURL(new Blob([i],a)),r.click()}},e})();e._GLTFData=t})(BABYLON||(BABYLON={}));var BABYLON;!(function(e){!(function(t){var r=(function(){function t(){}return t.ConvertToGLTFPBRMetallicRoughness=function(r){var i={diffuse:r.diffuseColor,opacity:r.alpha,specular:r.specularColor||e.Color3.Black(),glossiness:r.specularPower/256};r.specularTexture;var a=t._ConvertToMetallicRoughness(i);return{baseColorFactor:[a.baseColor.r,a.baseColor.g,a.baseColor.b,a.opacity],metallicFactor:a.metallic,roughnessFactor:a.roughness}},t._ConvertToMetallicRoughness=function(r){var i=r.diffuse,a=r.opacity,s=r.specular,n=e.Scalar.Clamp(r.glossiness),o=1-Math.max(s.r,Math.max(s.g,s.b)),l=t.PerceivedBrightness(i),u=t.PerceivedBrightness(s),h=t.SolveMetallic(l,u,o),f=o/(1-this.dielectricSpecular.r)/Math.max(1-h,this.epsilon),c=i.scale(f),p=s.subtract(this.dielectricSpecular.scale(1-h)).scale(1/Math.max(h,this.epsilon)),g=e.Color3.Lerp(c,p,h*h),d=new e.Color3;return g.clampToRef(0,1,d),{baseColor:d,opacity:a,metallic:h,roughness:1-n}},t.PerceivedBrightness=function(e){return Math.sqrt(.299*e.r*e.r+.587*e.g*e.g+.114*e.b*e.b)},t.SolveMetallic=function(t,r,i){if(r<this.dielectricSpecular.r)return 0;var a=this.dielectricSpecular.r,s=t*i/(1-this.dielectricSpecular.r)+r-2*this.dielectricSpecular.r,n=this.dielectricSpecular.r-r,o=s*s-4*a*n;return e.Scalar.Clamp((-s+Math.sqrt(o))/(2*a))},t.GetAlphaMode=function(t){if(t instanceof e.StandardMaterial){var r=t;return 1!=r.alpha||null!=r.diffuseTexture&&r.diffuseTexture.hasAlpha||null!=r.opacityTexture?"BLEND":"OPAQUE"}if(!(t instanceof e.PBRMetallicRoughnessMaterial))throw new Error("Unsupported Babylon material type");var i=t;switch(i.transparencyMode){case e.PBRMaterial.PBRMATERIAL_OPAQUE:return"OPAQUE";case e.PBRMaterial.PBRMATERIAL_ALPHABLEND:return"BLEND";case e.PBRMaterial.PBRMATERIAL_ALPHATEST:return"MASK";case e.PBRMaterial.PBRMATERIAL_ALPHATESTANDBLEND:return console.warn("GLTF Exporter | Alpha test and blend mode not supported in glTF. Alpha blend used instead."),"BLEND";default:throw new Error("Unsupported alpha mode "+i.transparencyMode)}},t.dielectricSpecular=new e.Color3(.04,.04,.04),t.epsilon=1e-6,t})();t._GLTFMaterial=r})(e.GLTF2||(e.GLTF2={}))})(BABYLON||(BABYLON={})),(function(e,t){var r=t();e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=r:"function"==typeof define&&define.amd?define(["BJSSerializers"],t):"object"==typeof exports?exports.BJSSerializers=r:e.BABYLON=r)})(this,(function(){return BABYLON})); |
@@ -17,44 +17,117 @@ /// <reference types="babylonjs"/> | ||
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 a Mesh array in .gltf file format. | ||
* If glb is set to true, exports as .glb. | ||
* @param meshes | ||
* @param materials | ||
* | ||
* @returns {[fileName: string]: string | Blob} Returns an object with a .gltf, .glb and associates textures | ||
* 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: BABYLON.Scene, filename: string): _GLTFData; | ||
static GLTF(scene: Scene, filePrefix: string, options?: IExporterOptions): _GLTFData; | ||
/** | ||
* | ||
* @param meshes | ||
* @param filename | ||
* | ||
* @returns {[fileName: string]: string | Blob} Returns an object with a .glb filename as key and data as value | ||
* 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: BABYLON.Scene, filename: string): _GLTFData; | ||
static GLB(scene: Scene, filePrefix: string, options?: IExporterOptions): _GLTFData; | ||
} | ||
} | ||
declare module BABYLON { | ||
class _GLTF2Exporter { | ||
/** | ||
* 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; | ||
constructor(babylonScene: BABYLON.Scene); | ||
/** | ||
* 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; | ||
/** | ||
* 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 | ||
* @param byteOffset | ||
* @param byteLength | ||
* | ||
* @returns {_IGLTFBufferView} | ||
* @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); | ||
private createBufferView(bufferIndex, byteOffset, byteLength, byteStride?, name?); | ||
/** | ||
@@ -69,46 +142,39 @@ * Creates an accessor based on the supplied arguments | ||
* @param max | ||
* | ||
* @returns {_IGLTFAccessor} | ||
* @returns - accessor for glTF | ||
*/ | ||
private createAccessor(bufferviewIndex, name, type, componentType, count, min?, max?); | ||
private createAccessor(bufferviewIndex, name, type, componentType, count, byteOffset?, min?, max?); | ||
/** | ||
* Calculates the minimum and maximum values of an array of floats, based on stride | ||
* @param buff | ||
* @param vertexStart | ||
* @param vertexCount | ||
* @param arrayOffset | ||
* @param stride | ||
* | ||
* @returns {min: number[], max: number[]} min number array and max number array | ||
* @param buff - Data to check for min and max values. | ||
* @param vertexStart - Start offset to calculate min and max values. | ||
* @param vertexCount - Number of vertices to check for min and max values. | ||
* @param stride - Offset between consecutive attributes. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @returns - min number array and max number array. | ||
*/ | ||
private calculateMinMax(buff, vertexStart, vertexCount, arrayOffset, stride); | ||
private calculateMinMax(buff, vertexStart, vertexCount, stride, useRightHandedSystem); | ||
/** | ||
* Write mesh attribute data to buffer. | ||
* Writes mesh attribute data to a data buffer. | ||
* Returns the bytelength of the data. | ||
* @param vertexBufferType | ||
* @param submesh | ||
* @param meshAttributeArray | ||
* @param strideSize | ||
* @param byteOffset | ||
* @param dataBuffer | ||
* @param useRightHandedSystem | ||
* | ||
* @returns {number} byte length | ||
* @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. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @returns - Byte length of the attribute data. | ||
*/ | ||
private writeAttributeData(vertexBufferType, submesh, meshAttributeArray, strideSize, byteOffset, dataBuffer, useRightHandedSystem); | ||
private writeAttributeData(vertexBufferKind, meshAttributeArray, strideSize, vertexBufferOffset, byteOffset, dataBuffer, useRightHandedSystem); | ||
/** | ||
* Generates glTF json data | ||
* @param glb | ||
* @param glTFPrefix | ||
* @param prettyPrint | ||
* | ||
* @returns {string} json data as string | ||
* @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(glb, glTFPrefix?, prettyPrint?); | ||
private generateJSON(shouldUseGlb, glTFPrefix?, prettyPrint?); | ||
/** | ||
* Generates data for .gltf and .bin files based on the glTF prefix string | ||
* @param glTFPrefix | ||
* | ||
* @returns {[x: string]: string | Blob} object with glTF json tex filename | ||
* and binary file name as keys and their data as values | ||
* @param glTFPrefix - Text to use when prefixing a glTF file. | ||
* @returns - GLTFData with glTF file data. | ||
*/ | ||
@@ -118,14 +184,16 @@ _generateGLTF(glTFPrefix: string): _GLTFData; | ||
* Creates a binary buffer for glTF | ||
* | ||
* @returns {ArrayBuffer} | ||
* @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 jsonText | ||
* @param binaryBuffer | ||
* @param glTFPrefix | ||
* | ||
* @returns {[glbFileName: string]: Blob} object with glb filename as key and data as value | ||
* @returns - object with glb filename as key and data as value | ||
*/ | ||
@@ -135,32 +203,47 @@ _generateGLB(glTFPrefix: string): _GLTFData; | ||
* Sets the TRS for each node | ||
* @param node | ||
* @param babylonMesh | ||
* @param useRightHandedSystem | ||
* @param node - glTF Node for storing the transformation data. | ||
* @param babylonMesh - Babylon mesh used as the source for the transformation data. | ||
* @param useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
*/ | ||
private setNodeTransformation(node, babylonMesh, useRightHandedSystem); | ||
/** | ||
* Sets data for the primitive attributes of each submesh | ||
* @param mesh | ||
* @param babylonMesh | ||
* @param byteOffset | ||
* @param useRightHandedSystem | ||
* @param dataBuffer | ||
* | ||
* @returns {number} bytelength of the primitive attributes plus the passed in byteOffset | ||
* @param babylonTexture - Babylon texture to extract. | ||
* @param mimeType - Mime Type of the babylonTexture. | ||
* @return - glTF texture, or null if the texture format is not supported. | ||
*/ | ||
private setPrimitiveAttributes(mesh, babylonMesh, byteOffset, useRightHandedSystem, dataBuffer?); | ||
private exportTexture(babylonTexture, mimeType?); | ||
/** | ||
* 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 useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @param dataBuffer - The buffer to write the bufferview data to. | ||
* @returns bytelength of the bufferview data. | ||
*/ | ||
private createBufferViewKind(kind, babylonMesh, byteOffset, useRightHandedSystem, dataBuffer); | ||
/** | ||
* 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 useRightHandedSystem - Indicates whether the data should be modified for a right or left handed coordinate system. | ||
* @param dataBuffer - Buffer to write the attribute data to. | ||
* @returns - bytelength of the primitive attributes plus the passed in byteOffset. | ||
*/ | ||
private setPrimitiveAttributes(mesh, babylonMesh, byteOffset, useRightHandedSystem, dataBuffer); | ||
/** | ||
* Creates a glTF scene based on the array of meshes. | ||
* Returns the the total byte offset. | ||
* @param gltf | ||
* @param byteOffset | ||
* @param buffer | ||
* @param dataBuffer | ||
* | ||
* @returns {number} bytelength + byteoffset | ||
* @param babylonScene - Babylon scene to get the mesh data from. | ||
* @param byteOffset - Offset to start from in bytes. | ||
* @param dataBuffer - Buffer to write geometry data to. | ||
* @returns bytelength + byteoffset | ||
*/ | ||
private createScene(babylonScene, byteOffset, dataBuffer?); | ||
private createScene(babylonScene, byteOffset, dataBuffer); | ||
} | ||
} | ||
declare module BABYLON { | ||
@@ -171,8 +254,14 @@ /** | ||
class _GLTFData { | ||
_glTFFiles: { | ||
/** | ||
* 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 glTF data. | ||
* Downloads the glTF data as files based on their names and data. | ||
*/ | ||
@@ -182,1 +271,51 @@ 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; | ||
/** | ||
* Epsilon value, used as a small tolerance value for a numeric value. | ||
*/ | ||
private static readonly epsilon; | ||
/** | ||
* Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material. | ||
* @param babylonStandardMaterial | ||
* @returns - glTF Metallic Roughness Material representation | ||
*/ | ||
static ConvertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness; | ||
/** | ||
* Converts Specular Glossiness to Metallic Roughness. This is based on the algorithm used in the Babylon glTF 3ds Max Exporter. | ||
* {@link https://github.com/BabylonJS/Exporters/blob/master/3ds%20Max/Max2Babylon/Exporter/BabylonExporter.GLTFExporter.Material.cs} | ||
* @param babylonSpecularGlossiness - Babylon specular glossiness parameters | ||
* @returns - Babylon metallic roughness values | ||
*/ | ||
private static _ConvertToMetallicRoughness(babylonSpecularGlossiness); | ||
/** | ||
* Returns the perceived brightness value based on the provided color | ||
* @param color - color used in calculating the perceived brightness | ||
* @returns - perceived brightness value | ||
*/ | ||
private static PerceivedBrightness(color); | ||
/** | ||
* 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; | ||
} | ||
} |
@@ -7,3 +7,3 @@ { | ||
"description": "The Babylon.js serializers library is an extension you can use to serialize Babylon scenes.", | ||
"version": "3.2.0-alpha4", | ||
"version": "3.2.0-alpha6", | ||
"repository": { | ||
@@ -35,5 +35,3 @@ "type": "git", | ||
"node": "*" | ||
}, | ||
"_id": "babylonjs-serializers@3.1.0-alpha1", | ||
"_from": "babylonjs-serializers@" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
109668
1632