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