babylon.objSerializer.min.js 1.7 KB

1
  1. var BABYLON;!(function(e){var t=(function(){function e(){}return e.OBJ=function(e,t,u){var o=[],r=e.geometry,i=r.getVerticesData("position"),s=r.getVerticesData("normal"),a=r.getVerticesData("uv"),p=r.getIndices();t&&(u||(u="mat"),o.push("mtllib "+u+".mtl"));for(var n=0;n<i.length;n+=3)o.push("v "+i[n]+" "+i[n+1]+" "+i[n+2]);for(n=0;n<s.length;n+=3)o.push("vn "+s[n]+" "+s[n+1]+" "+s[n+2]);for(n=0;n<a.length;n+=2)o.push("vt "+a[n]+" "+a[n+1]);for(o.push("g gr1"),t&&o.push("usemtl mat1"),n=0;n<p.length;n+=3)o.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));return o.join("\n")},e.MTL=function(e){var t=[],u=e.material;t.push("newmtl mat1"),t.push(" Ns "+u.specularPower.toFixed(4)),t.push(" Ni 1.5000"),t.push(" d "+u.alpha.toFixed(4)),t.push(" Tr 0.0000"),t.push(" Tf 1.0000 1.0000 1.0000"),t.push(" illum 2"),t.push(" Ka "+u.ambientColor.r.toFixed(4)+" "+u.ambientColor.g.toFixed(4)+" "+u.ambientColor.b.toFixed(4)),t.push(" Kd "+u.diffuseColor.r.toFixed(4)+" "+u.diffuseColor.g.toFixed(4)+" "+u.diffuseColor.b.toFixed(4)),t.push(" Ks "+u.specularColor.r.toFixed(4)+" "+u.specularColor.g.toFixed(4)+" "+u.specularColor.b.toFixed(4)),t.push(" Ke "+u.emissiveColor.r.toFixed(4)+" "+u.emissiveColor.g.toFixed(4)+" "+u.emissiveColor.b.toFixed(4));return u.ambientTexture&&t.push(" map_Ka "+u.ambientTexture.name),u.diffuseTexture&&t.push(" map_Kd "+u.diffuseTexture.name),u.specularTexture&&t.push(" map_Ks "+u.specularTexture.name),u.bumpTexture&&t.push(" map_bump -imfchan z "+u.bumpTexture.name),u.opacityTexture&&t.push(" map_d "+u.opacityTexture.name),t.join("\n")},e})();e.OBJExport=t})(BABYLON||(BABYLON={}));