Jump to content
  • Advertisement
Sign in to follow this  
Sik_the_hedgehog

Problem with a custom OBJ exporter

This topic is 1004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This has been driving me nuts for quite a while and I'm getting tired. I made an exporter from my own mesh format to OBJ (for the sake of testing until I have a proper model viewer), but when I try to import the resulting OBJ into MeshLab, this happens:

 

2mdKqxJ.png

 

It looks like for whatever reason all normals end up the same? I know MeshLab has no problems with other OBJ models so that obviously isn't the issue. But on the other hand I can't spot any obvious problem in the generated OBJ either:

v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v 1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
f 1/1/1 2/2/2 3/3/3
f 3/3/3 4/4/4 1/1/1
f 5/5/5 6/6/6 7/7/7
f 7/7/7 8/8/8 5/5/5
f 9/9/9 10/10/10 11/11/11
f 11/11/11 12/12/12 9/9/9
f 13/13/13 14/14/14 15/15/15
f 15/15/15 16/16/16 13/13/13
f 17/17/17 18/18/18 19/19/19
f 19/19/19 20/20/20 17/17/17
f 21/21/21 22/22/22 23/23/23
f 23/23/23 24/24/24 21/21/21

Can somebody here help me find out what obvious stupid thing I'm overlooking?

Share this post


Link to post
Share on other sites
Advertisement

The normals seem to work fine for me. Maybe it's a weird bug in older version of MeshLab or something? I tested with version 1.3.3 on Linux.

Share this post


Link to post
Share on other sites
I viewed in with this viewer and the only problem I could spot were that some normals were flipped.
http://masc.cs.gmu.edu/wiki/ObjViewer

I would try importing the obj into blender to see if blender can load it correctly. If it does, then re-export from blender into MeshLab. If mesh lab still has messed up normals you know it isn't your bug. If the normals work then you can compare the output of the blend file to yours and see if you can spot the issue.

Share this post


Link to post
Share on other sites

MeshLab 1.3.2 here... ouch.

 

OK I'm horribly confused. MeshLab breaks here, but the next revision apparently gets it right. Blender for me gets it right (albeit trying to move a corner was a mistake), and I think it's probably ignoring the normals, but for a friend it gives the same result as MeshLab does for me. Somebody else tried his own importer and got the same broken result. Now HappyCoder says it works, but with flipped normals (but that'd be easy to fix).

 

I have no idea what's going on by this point. The few cases that seem to read the normals at least seem to indicate they're in the right direction (whether the sense is forwards or backwards is a minor detail), so that'd imply the source file is not invalid after all, which is nice.

 

EDIT: OK nevermind there seem to be some winding issues with the cube (I built it by hand, OK? =P)... but all these inconsistencies certainly are driving me nuts

 

EDIT 2: problem solved! The Z convention wasn't consistent between faces o_O Now it works as intended. How come it never occured me to check the winding is beyond me (probably because MeshLab had it disabled by default so I assumed it was correct)

 

Here's the fixed cube, if anybody is curious:

v -1.000000 -1.000000 1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v -1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 1.000000 1.000000
v 1.000000 1.000000 1.000000
v 1.000000 1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 0.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 1.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.000000 -1.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 0.000000 -1.000000 0.000000
f 1/1/1 2/2/2 3/3/3
f 3/3/3 4/4/4 1/1/1
f 5/5/5 6/6/6 7/7/7
f 7/7/7 8/8/8 5/5/5
f 9/9/9 10/10/10 11/11/11
f 11/11/11 12/12/12 9/9/9
f 13/13/13 14/14/14 15/15/15
f 15/15/15 16/16/16 13/13/13
f 17/17/17 18/18/18 19/19/19
f 19/19/19 20/20/20 17/17/17
f 21/21/21 22/22/22 23/23/23
f 23/23/23 24/24/24 21/21/21

EDIT 3 (sorry!): spoke too soon, that only fixed the autogenerated face normals, not the actual vertex normals in MeshLab. But ObjViewer seems to not have problem with it, and since MeshLab 1.3.3 behaves differently, maybe I just hit another bug as well? Oh well.

Edited by Sik_the_hedgehog

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!