FelipeBaltazar

Members
  • Content Count

    10
  • Joined

  • Last visited

About FelipeBaltazar

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. @damian2taylor This is fantastic! Are great points, congratulations! Please, if you finish part of materials, tell me plz! I'm working on it too.
  2. @Deltakosh sorry... im a complete newbie in development (in english too... sorry again) https://github.com/felipebaltazar/Babylon.js/blob/8efbe08b024f13017330ade4e993ff325e860caf/serializers/src/OBJ/babylon.objSerializer.ts @jschwuch You are absolutely right! I made this option, "selectable". globalposition define this. public static OBJ(mesh: Mesh[], materials?: boolean, matlibname?: string, globalposition?:boolean) In your scene, yours meshes will remain normal. Because this: var lastMatrix = BABYLON.Matrix.Translation(-(mesh[j].position.x),-(mesh[j].position.y),-(mesh[j].position.z)); I bring back de original matrix... if(globalposition){ mesh.bakeTransformIntoVertices(lastMatrix); } thks everyone
  3. @Deltakosh Done! But, i have not solved the materials yet https://github.com/felipebaltazar/Babylon.js/blob/b683beced1e42b907d67581d9e0b916a4d01b969/serializers/src/OBJ/babylon.objSerializer.ts
  4. @jschwuch Woa! That's great! This was exactly what I needed! I'll work on the materials now! The "babylon.objSerializer.js" already has this, but not for more than one mesh. Thank you very much for the explanations! part of code: //Exports the material(s) of a mesh in .MTL file format (text) OBJExport.MTL = function (mesh) { var output = []; var m = mesh.material; output.push("newmtl mat1"); output.push(" Ns " + m.specularPower.toFixed(4)); output.push(" Ni 1.5000"); output.push(" d " + m.alpha.toFixed(4)); output.push(" Tr 0.0000"); output.push(" Tf 1.0000 1.0000 1.0000"); output.push(" illum 2"); output.push(" Ka " + m.ambientColor.r.toFixed(4) + " " + m.ambientColor.g.toFixed(4) + " " + m.ambientColor.b.toFixed(4)); output.push(" Kd " + m.diffuseColor.r.toFixed(4) + " " + m.diffuseColor.g.toFixed(4) + " " + m.diffuseColor.b.toFixed(4)); output.push(" Ks " + m.specularColor.r.toFixed(4) + " " + m.specularColor.g.toFixed(4) + " " + m.specularColor.b.toFixed(4)); output.push(" Ke " + m.emissiveColor.r.toFixed(4) + " " + m.emissiveColor.g.toFixed(4) + " " + m.emissiveColor.b.toFixed(4)); //TODO: uv scale, offset, wrap //TODO: UV mirrored in Blender? second UV channel? lightMap? reflection textures? var uvscale = ""; if (m.ambientTexture) { output.push(" map_Ka " + uvscale + m.ambientTexture.name); } if (m.diffuseTexture) { output.push(" map_Kd " + uvscale + m.diffuseTexture.name); //TODO: alpha testing, opacity in diffuse texture alpha channel (diffuseTexture.hasAlpha -> map_d) } if (m.specularTexture) { output.push(" map_Ks " + uvscale + m.specularTexture.name); /* TODO: glossiness = specular highlight component is in alpha channel of specularTexture. (???) if (m.useGlossinessFromSpecularMapAlpha) { output.push(" map_Ns "+uvscale + m.specularTexture.name); } */ } /* TODO: emissive texture not in .MAT format (???) if (m.emissiveTexture) { output.push(" map_d "+uvscale+m.emissiveTexture.name); } */ if (m.bumpTexture) { output.push(" map_bump -imfchan z " + uvscale + m.bumpTexture.name); } if (m.opacityTexture) { output.push(" map_d " + uvscale + m.opacityTexture.name); } var text = output.join("\n"); return (text); };
  5. @jschwuch great! Dammit! I forget that detail on indices loop. My bad! You applied the global position with mesh matrix.... What is the difference of your example and the "bake" of babylon? var matrix = BABYLON.Matrix.Translation(mesh.position.x,mesh.position.y,mesh.position.z);mesh.bakeTransformIntoVertices(matrix); Thx
  6. I did this in my example. "Selecteditems" is an array of meshes. But I still have problems with the indexes of the faces.
  7. Worked fine! This is what I needed. Thanks!
  8. Hi! Thanks for reply! I used this code to inspire me, but the world position is wrong. how can i incorporate this? using matrix maybe?
  9. Hello! I need to export my objects to obj. I found an example that I could adapt. But I can not incorporate the position of the object in the scene. Any idea? note: I'm a beginner*** BABYLON.Mesh.prototype.exportOBJ = function() { var output=[]; output.push("mtllib savedFile.mtl"); for(var i2 = 0; i2< selectedItems.length; i2++) { output.push("g object"+i2); output.push("o object_"+i2); output.push("usemtl material"+i2); var g = window[selectedItem[i2]].geometry; console.log(selectedItem[i2]); trunkVerts = g.getVerticesData('position'); trunkNormals = g.getVerticesData('normal'); trunkUV = g.getVerticesData('uv'); trunkFaces = g.getIndices(); for(var i=0;i<trunkVerts.length;i+=3){ output.push("v "+trunkVerts[i]+" "+trunkVerts[i+1]+" "+trunkVerts[i+2]); } for(i=0;i<trunkNormals.length;i+=3){ output.push("vn "+trunkNormals[i]+" "+trunkNormals[i+1]+" "+trunkNormals[i+2]); } for(i=0;i<trunkUV.length;i+=2){ output.push("vt "+trunkUV[i]+" "+trunkUV[i+1]); } for(i=0;i<trunkFaces.length;i+=3) { output.push( "f "+(trunkFaces[i+2]+1)+"/"+(trunkFaces[i+2]+1)+"/"+(trunkFaces[i+2]+1)+ " "+(trunkFaces[i+1]+1)+"/"+(trunkFaces[i+1]+1)+"/"+(trunkFaces[i+1]+1)+ " "+(trunkFaces[i]+1)+"/"+(trunkFaces[i]+1)+"/"+(trunkFaces[i]+1) ); } } var text = output.join("\n"); var fileBlob; try{ fileBlob=new Blob([text]); }catch(e){ var blobBuilder=window.BlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder; var bb=new blobBuilder(); bb.append([text]); fileBlob=bb.getBlob(); } var URL=window.URL || window.webkitURL; var link=URL.createObjectURL(fileBlob); return link; }