1 |
- var BABYLON;!(function(C){var e=(function(){function e(){}return e.OBJ=function(e,o,t,r){var i=[],s=1;o&&(t||(t="mat"),i.push("mtllib "+t+".mtl"));for(var n=0;n<e.length;n++){i.push("g object"+n),i.push("o object_"+n);var a=null;if(r){var u=C.Matrix.Translation(e[n].position.x,e[n].position.y,e[n].position.z);a=C.Matrix.Translation(-e[n].position.x,-e[n].position.y,-e[n].position.z),e[n].bakeTransformIntoVertices(u)}if(o){var p=e[n].material;p&&i.push("usemtl "+p.id)}var l=e[n].geometry;if(l){var m=l.getVerticesData("position"),h=l.getVerticesData("normal"),f=l.getVerticesData("uv"),x=l.getIndices(),d=0;if(m&&x){for(var c=0;c<m.length;c+=3)i.push("v "+m[c]+" "+m[c+1]+" "+m[c+2]),d++;if(null!=h)for(c=0;c<h.length;c+=3)i.push("vn "+h[c]+" "+h[c+1]+" "+h[c+2]);if(null!=f)for(c=0;c<f.length;c+=2)i.push("vt "+f[c]+" "+f[c+1]);for(c=0;c<x.length;c+=3){var v=[String(x[c+2]+s),String(x[c+1]+s),String(x[c]+s)],T=["","",""],g=v,b=null!=f?v:T,F=null!=h?v:T;i.push("f "+g[0]+"/"+b[0]+"/"+F[0]+" "+g[1]+"/"+b[1]+"/"+F[1]+" "+g[2]+"/"+b[2]+"/"+F[2])}r&&a&&e[n].bakeTransformIntoVertices(a),s+=d}else C.Tools.Warn("There are no position vertices or indices on the mesh!")}else C.Tools.Warn("No geometry is present on the mesh")}return i.join("\n")},e.MTL=function(e){var o=[],t=e.material;o.push("newmtl mat1"),o.push(" Ns "+t.specularPower.toFixed(4)),o.push(" Ni 1.5000"),o.push(" d "+t.alpha.toFixed(4)),o.push(" Tr 0.0000"),o.push(" Tf 1.0000 1.0000 1.0000"),o.push(" illum 2"),o.push(" Ka "+t.ambientColor.r.toFixed(4)+" "+t.ambientColor.g.toFixed(4)+" "+t.ambientColor.b.toFixed(4)),o.push(" Kd "+t.diffuseColor.r.toFixed(4)+" "+t.diffuseColor.g.toFixed(4)+" "+t.diffuseColor.b.toFixed(4)),o.push(" Ks "+t.specularColor.r.toFixed(4)+" "+t.specularColor.g.toFixed(4)+" "+t.specularColor.b.toFixed(4)),o.push(" Ke "+t.emissiveColor.r.toFixed(4)+" "+t.emissiveColor.g.toFixed(4)+" "+t.emissiveColor.b.toFixed(4));return t.ambientTexture&&o.push(" map_Ka "+t.ambientTexture.name),t.diffuseTexture&&o.push(" map_Kd "+t.diffuseTexture.name),t.specularTexture&&o.push(" map_Ks "+t.specularTexture.name),t.bumpTexture&&o.push(" map_bump -imfchan z "+t.bumpTexture.name),t.opacityTexture&&o.push(" map_d "+t.opacityTexture.name),o.join("\n")},e})();C.OBJExport=e})(BABYLON||(BABYLON={}));
|