-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to access faces? #87
Comments
Hello, thanks for trying out pywavefront! Can you point me to the code and data you used generate this view? Is this a Python object viewer you are using? Is it free, e.g. can you point me to where you downloaded it? |
Seems they are in As far as I remember face lists are located in the mesh while vertices (positions) are located in materials. I'm guessing an index lookup using the face data should at least be simple if the obj file has one object and one material. Faces are also always triangulated as this has always been default in this project so far. This is probably not ideal but grouping vertices together per material made it much easier to load and display almost any obj file. There are so many weird corner cases with the obj format. Probably something that needs improvement in the future. Proper info per mesh is a good start. |
Hi, thank you for the response! The code I used was just Thank you! |
Thank you for your response! |
Quick test program: test.obj o Simple
v 1.0 2.0 3.0
v 3.0 5.0 6.0
v 7.0 8.0 9.0
vt 0.0 1.0
vt 1.0 0.0
vt 0.0 0.0
vn 0.0 0.0 1.0
f 2/3/1 1/2/1 3/1/1 test.py import pywavefront
scene = pywavefront.Wavefront(
"test.obj",
create_materials=True,
collect_faces=True,
)
print("Faces:", scene.mesh_list[0].faces)
print("Vertices:", scene.vertices)
print("Format:", scene.mesh_list[0].materials[0].vertex_format)
print("Vertices:", scene.mesh_list[0].materials[0].vertices) Output: Faces: [[1, 0, 2]]
Vertices: [(1.0, 2.0, 3.0), (3.0, 5.0, 6.0), (7.0, 8.0, 9.0)]
Format: T2F_N3F_V3F
< UV > < Normal > < Position >
Vertices: [0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 6.0, # Vertex 1 T2F_N3F_V3F
1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 2.0, 3.0, # Vertex 2 T2F_N3F_V3F
0.0, 1.0, 0.0, 0.0, 1.0, 7.0, 8.0, 9.0] # Vertex 3 T2F_N3F_V3F The first vertex list is the raw vertices from the obj file. The second vertex list represents the interleaved vertex data with the format specified in the material. Faces will always be triangulized (no quads) |
Thank you!!! I can access it with the command you provided scene.mesh_list[0].faces, I was not familiar with it before. |
No problem. I opened #88 related to this. It's not always entirely clear how to access the parsed data at this moment. |
@einarf getting vertices with scene.vertices gives me array of shape (43436, 3) ,and I've checked on my .obj vertices are 43436 but when I get them with scene.mesh_list[0].materials[0].vertices and reshape it (n,8) (8 for 2 texture + 3 normal + 3 position ) it resulted vertices with shape (257490, 3) |
The vertices in the material itself is currently repeated based on the face list. It's interleaved data (with the specified The vertices in the root is just the vertices in the order they appear in the obj file. A lot of these things certainly needs to change in 2.0. |
So there is no way to get UV vectors in order they appear in obj file ? Similar to mesh.vertices |
I think you can obtain them from the parser at the moment. https://github.com/pywavefront/PyWavefront/blob/master/pywavefront/obj.py#L76-L78 Otherwise the are already interleaved in the material.vertices (see |
Again thank you |
No problem! Hoping to sort this out in 2.0 very soon with excellent documentation as well. |
I can't seem to read faces. I thought it might be my .objs or code, but after trying this example smile obj with scene.mesh_list[0].faces, the array is always empty, has_faces is always false. Any thoughts? Many thanks |
Hello,
How can I access objects' faces?
When I open the file using
object = pywavefront.Wavefront("object.obj", create_materials = True, collect_faces=True)
I can access the vertices simply by using object.vertices, but when it comes to the faces it is under either 2 folders, meshes or mesh_list, but the folders 0 and None are not accessible:

Thank you
The text was updated successfully, but these errors were encountered: