3131# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232# POSSIBILITY OF SUCH DAMAGE.
3333# ----------------------------------------------------------------------------
34+ import os
3435
3536import pywavefront .material
3637import pywavefront .mesh
3738import pywavefront .parser
3839
40+
3941class PywavefrontException (Exception ):
4042 pass
4143
44+
4245class Wavefront (object ):
4346 """Import a wavefront .obj file."""
4447 def __init__ (self , file_name ):
@@ -58,18 +61,20 @@ def add_mesh(self, the_mesh):
5861 self .mesh_list .append (the_mesh )
5962 self .meshes [the_mesh .name ] = the_mesh
6063
64+
6165class ObjParser (parser .Parser ):
6266 """This parser parses lines from .obj files."""
67+
6368 def __init__ (self , wavefront , file_name ):
64- # unfortunately we can't escape from external effects on the
65- # wavefront object
69+ super (ObjParser , self ).__init__ (file_name )
6670 self .wavefront = wavefront
71+
6772 self .mesh = None
6873 self .material = None
6974 self .vertices = [[0. , 0. , 0. ]]
7075 self .normals = [[0. , 0. , 0. ]]
7176 self .tex_coords = [[0. , 0. ]]
72- self .read_file (file_name )
77+ self .read_file ()
7378
7479 # methods for parsing types of wavefront lines
7580 def parse_v (self , args ):
@@ -82,7 +87,7 @@ def parse_vt(self, args):
8287 self .tex_coords .append (list (map (float , args [0 :2 ])))
8388
8489 def parse_mtllib (self , args ):
85- [ mtllib ] = args
90+ mtllib = os . path . join ( self . dir , " " . join ( args ))
8691 materials = material .MaterialParser (mtllib ).materials
8792 for material_name , material_object in materials .items ():
8893 self .wavefront .materials [material_name ] = material_object
@@ -121,7 +126,6 @@ def parse_f(self, args):
121126 # For fan triangulation, remember first and latest vertices
122127 v1 = None
123128 vlast = None
124- points = []
125129 for i , v in enumerate (args [0 :]):
126130 if type (v ) is bytes :
127131 v = v .decode ()
0 commit comments