babylon.objSerializer.min.js 1.7 KB

1
  1. var BABYLON;!(function(e){var t=(function(){function e(){}return e.OBJ=function(e,t,r){var u=[],o=e.geometry,i=o.getVerticesData("position"),s=o.getVerticesData("normal"),a=o.getVerticesData("uv"),p=o.getIndices();t&&(r||(r="mat"),u.push("mtllib "+r+".mtl"));for(var n=0;n<i.length;n+=3)u.push("v "+i[n]+" "+i[n+1]+" "+i[n+2]);for(n=0;n<s.length;n+=3)u.push("vn "+s[n]+" "+s[n+1]+" "+s[n+2]);for(n=0;n<a.length;n+=2)u.push("vt "+a[n]+" "+a[n+1]);for(u.push("g gr1"),t&&u.push("usemtl mat1"),n=0;n<p.length;n+=3)u.push("f "+(p[n+2]+1)+"/"+(p[n+2]+1)+"/"+(p[n+2]+1)+" "+(p[n+1]+1)+"/"+(p[n+1]+1)+"/"+(p[n+1]+1)+" "+(p[n]+1)+"/"+(p[n]+1)+"/"+(p[n]+1));var m=u.join("\n");return m},e.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));var u="";r.ambientTexture&&t.push(" map_Ka "+u+r.ambientTexture.name),r.diffuseTexture&&t.push(" map_Kd "+u+r.diffuseTexture.name),r.specularTexture&&t.push(" map_Ks "+u+r.specularTexture.name),r.bumpTexture&&t.push(" map_bump -imfchan z "+u+r.bumpTexture.name),r.opacityTexture&&t.push(" map_d "+u+r.opacityTexture.name);var o=t.join("\n");return o},e})();e.OBJExport=t})(BABYLON||(BABYLON={}));