pywavefront / PyWavefront

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

how to get the vertices, faces and texturecoord from the Wavefront object #129

Open nhanminhnhat1998 opened 3 years ago

nhanminhnhat1998 commented 3 years ago

Hello everyone,

I am trying to use your library to open the .obj with the .mtl as the texture file

here is my attempt. I could not find a way to get the faces out of it :((

import pywavefront
import logging

pywavefront.configure_logging(
    logging.DEBUG,
    formatter=logging.Formatter('%(name)s-%(levelname)s: %(message)s')
)

file_name = '/home/duma/Documents/RTT_stuffs/camera_calibration/3D_model/scene_mesh_textured.obj'
waveFrontObj = pywavefront.Wavefront(file_name, strict=True, encoding="iso-8859-1", parse=False,collect_faces=True)
waveFrontObj.parse()  # Explicit call to parse() needed when parse=False

for name, material in waveFrontObj.materials.items():
    print("#### Name: ",name)
    temp = vars(material)
    for item in temp:
        if item== "vertices" :
            print("vertices : ") 
            continue
        if item=="texture": print("texture.image : ",type(temp[item].path),temp[item].path)
        print(item, ':', temp[item])
        # print(item, ':')
    print("----------------------")

Thank you for your help

einarf commented 3 years ago

I'll try to remember to include some info in readme about this. Meanwhile see : https://github.com/pywavefront/PyWavefront/issues/87#issuecomment-464348971