FelipeBaltazar

Babylon objects to .obj file

Recommended Posts

Hi, I have a problem with export an .obj file using custom mesh. Should it work with this kind of mesh? I created a geometry which is displayed correctly in canvas and after console.log the list of vertexes is empty. I tested that with a standard cube and it worked correctly.
Here is how I am doing it (more or less):
 

this.customMesh = new BABYLON.Mesh("custom", this.scene);   

//... a lot of "positions.push"
   
var normals = [];
var vertexData = new BABYLON.VertexData();
BABYLON.VertexData.ComputeNormals(positions, indices, normals);
vertexData.positions = positions;
vertexData.indices = indices;
vertexData.normals = normals;
vertexData.applyToMesh(this.customMesh);

var mat = new BABYLON.StandardMaterial("mat", scene);
this.customMesh.material = mat;

var obj = BABYLON.OBJExport.OBJ([this.customMesh],true,'birdie');
var objlink = BABYLON.Tools.FileAsURL(obj);
var mtl = BABYLON.OBJExport.MTL(this.customMesh,true);
var mtllink = BABYLON.Tools.FileAsURL(mtl);

console.log("obj = ", obj);
console.log("objlink = ", objlink);

console.log("mtl = ", mtl);
console.log("mtllink = ", mtllink);

 

Share this post


Link to post
Share on other sites

Ok, I have found why my string was empty when I console.log my custom mesh. I do not have UV data in my model and in OBJExport.OBJ() method there is a condition which skips such meshes:

if (!trunkVerts || !trunkNormals || !trunkUV || !trunkFaces) {
    continue;
}

 

Share this post


Link to post
Share on other sites

good hour. english not my native.

i have not a good result use

//some code before

download(BABYLON.OBJExport.OBJ(exportobjects,true,"wheelmaterials",false),"scene.obj","text/plain");

function download(text, name, type) {
	var a = document.getElementById("a");
	var file = new Blob([text], {type: type});
	a.href = URL.createObjectURL(file);
	a.download = name;
  }

syntax. After this i try to open->export (scene.obj) file uses freecad and meshlab under linux(not think this is major), and as you can see the model exported wrong way.

Hope i can solve this, with your help.

objexportbug.png

Share this post


Link to post
Share on other sites

solved , by using

mesh.bakeCurrentTransformIntoVertices();

but now some parts of exported model need to set two side lighting, or parts always black. And way to create these parts(meshes) is similar, but different only final angle of rotation around axis. Little insane feeling inside...not perfect result : |

 

onetwo.png

Share this post


Link to post
Share on other sites
On 5/29/2018 at 7:15 AM, Deltakosh said:

Feel free to open an issue on the repo. We will try to fix the OBJ exporter if you can provide a repro case

what should i do to provide a repro case?

is link on repository on github with program , which include this , is enough ? Because the result exported file is close to 100mb size wavefront obj

 

... insane behavior... my email place forum answer notification mail into spam, but before i create the filter especially for this forum and place it first in order... 😐

Share this post


Link to post
Share on other sites
4 hours ago, Deltakosh said:

It would be great to have a simpler scene (perhaps just a part of the initial mesh) that can highlight the problem

i create this folder in repo. Hope this will be enough.

github repo folder with issue description

can you create the issue ? i can try but don't know the right form of this, and english is not my native.

Share this post


Link to post
Share on other sites
2 hours ago, Deltakosh said:

Me neither, I'm french :)

I need you to create a repro in the Playground and I can take care of it from there

inside my app i use my own handmaded lib written in haxe, and then exported to javascript

https://github.com/3dformortals/data/blob/master/trash/objexportissue/web/js/geo.js

4426 lines. And looks like i need to create playground in one file... plus my app depend from gui html(but it possible to cut off all except few numbers). copy all libs to giant js file looks very insane for me. Are you sure this is good idea?

Share this post


Link to post
Share on other sites

not good... i try export scene to glTF format , then import into blender, and result is similar. Some meshes is broked , not coloring and look different when i rotate the view. Looks like something bad with exporters mathematics, or both exporters have same coding way. Because all my meshes created uses for loop, and later some of thier only moved + rotated into new scene position.

Feels like some of meshes stay turned inside out, after exporting. I detect something similar when i try use threejs earlier, but threejs show this on scene. But babylonjs only do this in time of export. Is it possible when you recode or use part of threejs algorithm (part of code base)... I hope you don't do this, because threejs is terrible in compare with babylon js

Share this post


Link to post
Share on other sites

i found the way how manually fix this issue inside freecad. Need reverse normals inside mesh designer for every black part and then it stay normal colored etc. this can be math hole inside exporter algorithm, or mesh rotation algorithm (but on screen it look normal , and this direct to exporter as potentially reason of issue)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.