I have an obj that I am trying to export and which my client is importing into Houdini. The mesh consists of only verts and edges, no faces. When the obj is imported into Houdini, each edge comes in as a separate mesh. The client says there is nothing that they have tried that works to fix this issue. They also say that similar files exported from 3DS Max do not suffer from the same issue.
I have poked through the exported 3DS Max obj files and found that they have a different format than the ones coming from blender. Specifically, if Blender writes out a file that looks like this:
o FireplaceA_12.375in.001
v 190.664322 44.868816 0.000000
v 190.663208 44.850445 0.000000
v 190.659897 44.832344 0.000000
l 1 2
l 2 3
l 3 1
3DS Max writes out a file that looks like this:
o FireplaceA_12.375in.001
v 190.664322 44.868816 0.000000
v 190.663208 44.850445 0.000000
v 190.659897 44.832344 0.000000
l 1 2 3
Specifically, the edges (as identified by the lines starting with the lowercase letter “L” are all on separate lines in the file written from Blender. But coming from 3DS Max they are all on a single line.
I can hand-edit the file to put them all on a single line and that seems to work for the client. But that is pretty tedious and I will have many files that I will need to fix by hand. I can also write a python script to handle this for me, but then there is a fair bit of testing to make sure I catch the edge cases.
Is there a setting that I am getting wrong inside of Blender that would make the exports conform to the format that Houdini can properly import?
3DS Max seems to remember the edge lines of the faces… but teh blender export (also legacy) seems to store the lines individually.
Anyway: when looking at the exported obj file for the default cube ( in my case also using the slash notiation 1/2/3 at least in 3.6) i noticed:
If you simple chaneg the f to l [ ← with a space ] then there are no faces… but lines. This should be a simple search and replace… [ again: with a space or a regular expression for line start ]…
Yeah, it seems Blender is storing each edge as a separate object. Unfortunately, in my case, there are no faces. Just edges. So I cannot do a search and replace on the faces because they don’t exist.
I used a regular expression to convert the separate edges into a single object
It was something like: \nl( [0-9]+) ([0-9]+) and then I replaced it with \1 . Then I had to add the “l” back at the beginning of the line and move it to a new line. A more sophisticated regular expression could probably do it in one go, but I am not that proficient in them and would rather just do it with a python script. (Technically, I would rather that Blender wrote the obj out correctly in the first place. )
But this process - in addition to being somewhat tedious - is not perfect because it doesn’t properly complete the poly “curve”. I would need to inspect an actual simple case to figure that one out (and most likely use a python script with some smarts to correctly terminate that string… not ideal but hopefully something I can cobble together).
# Blender 4.0.2
# www.blender.org
o MergedPlane
v -1.000000 -1.000000 0.000000
v 1.000000 -1.000000 0.000000
v -1.000000 1.000000 0.000000
v 1.000000 1.000000 0.000000
v -0.578616 -0.578616 0.000000
v -0.578616 0.578616 0.000000
v 0.578616 -0.578616 0.000000
v 0.578616 0.578616 0.000000
l 3 1
l 1 2
l 2 4
l 4 3
l 6 5
l 5 7
l 7 8
l 8 6
But this is how it should be:
# Blender 4.0.2
# www.blender.org
o MergedPlane
v -1.000000 -1.000000 0.000000
v 1.000000 -1.000000 0.000000
v -1.000000 1.000000 0.000000
v 1.000000 1.000000 0.000000
v -0.578616 -0.578616 0.000000
v -0.578616 0.578616 0.000000
v 0.578616 -0.578616 0.000000
v 0.578616 0.578616 0.000000
l 3 1 2 4 3
l 6 5 7 8 6
This represents a mesh that only has vertices and edges. No faces. There re two separate connected sets of verts and edges in the same mesh. You can see that the edges in the original obj are all listed on separate lines which indicates that each of them is a separate mesh. In the correct version each connected set of mesh lines are connected on a single line. To add insult to injury, blender does not write out the edges in order.
Luckily I think I was able to write a tool that can convert from one to the other. This script will convert the broken obj to the fixed obj. All you need to do is update the path to the broken obj on the first line. It will automatically create a second file that is the corrected obj.
Nevermind. The code does not work properly. This is a freaking nightmare.
Ah! Meshlab! I completely forgot about that tool. I am going to give that a go right now! Thanks.
And yes, I think your idea of using n-gons and then deleting the polygons in Houdini is the short-term solution. I just gave it a go and that seems to work as I had hoped. Thanks so much!
In the meantime, apparently there is already a bug report about this behavior (which, to be clear, is not really a bug so much as an undefined behavior. But someone is already looking into it so maybe there will be a slightly better way of handling it in the future).