babylon.objSerializer.min.js 2.0 KB

1
  1. var BABYLON;!(function(e){var t=(function(){function t(){}return t.OBJ=function(t,o,i,r){var s=[],u=1;o&&(i||(i="mat"),s.push("mtllib "+i+".mtl"));for(var a=0;a<t.length;a++){if(s.push("g object"+a),s.push("o object_"+a),r){var n=e.Matrix.Translation(t[a].position.x,t[a].position.y,t[a].position.z),p=e.Matrix.Translation(-t[a].position.x,-t[a].position.y,-t[a].position.z);t[a].bakeTransformIntoVertices(n)}o&&s.push("usemtl "+t[a].material.id);for(var l=t[a].geometry,m=l.getVerticesData("position"),h=l.getVerticesData("normal"),x=l.getVerticesData("uv"),f=l.getIndices(),d=0,c=0;c<m.length;c+=3)s.push("v "+m[c]+" "+m[c+1]+" "+m[c+2]),d++;for(c=0;c<h.length;c+=3)s.push("vn "+h[c]+" "+h[c+1]+" "+h[c+2]);for(c=0;c<x.length;c+=2)s.push("vt "+x[c]+" "+x[c+1]);for(c=0;c<f.length;c+=3)s.push("f "+(f[c+2]+u)+"/"+(f[c+2]+u)+"/"+(f[c+2]+u)+" "+(f[c+1]+u)+"/"+(f[c+1]+u)+"/"+(f[c+1]+u)+" "+(f[c]+u)+"/"+(f[c]+u)+"/"+(f[c]+u));r&&t[a].bakeTransformIntoVertices(p),u+=d}return s.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={}));