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 e.indexOf(t,e.length-t.length)!==-1}for(var t in this._glTFFiles){var r=document.createElement("a");document.body.appendChild(r),r.setAttribute("type","hidden"),r.download=t;var i=this._glTFFiles[t],s=void 0;e(t,".glb")?s={type:"model/gltf-binary"}:e(t,".bin")?s={type:"application/octet-stream"}:e(t,".gltf")&&(s={type:"model/gltf+json"}),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}));
|