babylonjs.serializers.min.js 3.0 KB

1
  1. var BABYLON=BABYLON||"undefined"!=typeof require&&require("babylonjs"),__decorate=this&&this.__decorate||function(e,t,o,r){var i,n=arguments.length,s=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,r);else for(var u=e.length-1;u>=0;u--)(i=e[u])&&(s=(n<3?i(s):n>3?i(t,o,s):i(t,o))||s);return n>3&&s&&Object.defineProperty(t,o,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 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=[],s=1;o&&(r||(r="mat"),n.push("mtllib "+r+".mtl"));for(var u=0;u<t.length;u++){if(n.push("g object"+u),n.push("o object_"+u),i){var a=e.Matrix.Translation(t[u].position.x,t[u].position.y,t[u].position.z),p=e.Matrix.Translation(-t[u].position.x,-t[u].position.y,-t[u].position.z);t[u].bakeTransformIntoVertices(a)}o&&n.push("usemtl "+t[u].material.id);for(var f=t[u].geometry,c=f.getVerticesData("position"),l=f.getVerticesData("normal"),d=f.getVerticesData("uv"),h=f.getIndices(),m=0,x=0;x<c.length;x+=3)n.push("v "+c[x]+" "+c[x+1]+" "+c[x+2]),m++;for(x=0;x<l.length;x+=3)n.push("vn "+l[x]+" "+l[x+1]+" "+l[x+2]);for(x=0;x<d.length;x+=2)n.push("vt "+d[x]+" "+d[x+1]);for(x=0;x<h.length;x+=3)n.push("f "+(h[x+2]+s)+"/"+(h[x+2]+s)+"/"+(h[x+2]+s)+" "+(h[x+1]+s)+"/"+(h[x+1]+s)+"/"+(h[x+1]+s)+" "+(h[x]+s)+"/"+(h[x]+s)+"/"+(h[x]+s));i&&t[u].bakeTransformIntoVertices(p),s+=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){e&&e.BABYLON||("object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.BJSSerializers=t():e.BABYLON=t())})(this,(function(){return BABYLON}));