babylonjs.serializers.min.js 3.2 KB

1
  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}));