#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2024/04/22 19:35:07 +0900> """ Load wavefront obj file and dump Windows10 x64 22H2 + Python 3.10.10 64bit """ import pywavefront infile = "cube01.obj" # infile = "suzanne01.obj" def dump_material(mat): print() print(f".name = {mat.name}") print(f".vertex_format = {mat.vertex_format}") print(f".vertices = {mat.vertices}") print(f".diffuse = {mat.diffuse}") print(f".ambient = {mat.ambient}") print(f".specular = {mat.specular}") print(f".texture = {mat.texture}") def main(): obj = pywavefront.Wavefront(infile) # obj.parse() print(f"file_name = {obj.file_name}") print(f"mrllibs = {obj.mtllibs}") print(f"vertices = {obj.vertices}") print(f"\nmaterials = {obj.materials}") # for matname, mat in obj.materials.items(): # dump_material(mat) print(f"\nmeshes = {obj.meshes}") # for meshname, mesh in obj.meshes.items(): # print() # print(f"Mesh name = {meshname}") # print(f"name = {mesh.name}") # print(f"faces = {mesh.faces}") # print(f"materials = {mesh.materials}") # print("\n# mesh.materials") # for mat in mesh.materials: # dump_material(mat) print(f"\nmesh_List = {obj.mesh_list}") for mesh in obj.mesh_list: print(f".name = {mesh.name}") print(f".faces = {mesh.faces}") print(f".materials = {mesh.materials}") for mat in mesh.materials: dump_material(mat) if __name__ == "__main__": main()