pywavefront / PyWavefront

Python library for importing Wavefront .obj files
BSD 3-Clause "New" or "Revised" License
312 stars 80 forks source link

expose 'normals' in Wavefront object #111

Closed hananbeer closed 4 years ago

hananbeer commented 4 years ago

I couldn't find how to access 'normals' in the doc. looking at the code it seems they are parsed but not exposed;

eventually I managed to access it by 'obj.parser.normals' but it isn't trivial. also I'm not sure about the format, shouldn't they be per mesh/material, and not global?

edit: I'm not too familiar with the format, but this seems incorrect: obj.meshes[None].materials[0].vertices

gives an UNORDERED list of normals, not vertices, definitely not obj.vertices (which produces correct results)

einarf commented 4 years ago

It needs to be documented, but searching in the issues here you can find : https://github.com/pywavefront/PyWavefront/issues/87#issuecomment-464348971

hananbeer commented 4 years ago

I continued playing with this object a bit more and I observed the following: (edited original comment)

I'm not too familiar with the format, but this seems incorrect: obj.meshes[None].materials[0].vertices

gives an UNORDERED list of normals, not vertices, definitely not obj.vertices (which produces correct results)

edit: ah, I see in the issue you posted, material[].vertices provides ALL information, including UV, normals, etc... kinda unclear imo. thanks.

ok got it :)

einarf commented 4 years ago

Yep. You just have to look at the format string. The attributes are always in the same order, so its simple to check what attributes are present with a couple of "N3F" in format.

einarf commented 4 years ago

Closing and duping this with #103