ratcave / wavefront_reader

A basic Wavefront .obj and .mtl reader module for Python
MIT License
12 stars 10 forks source link

MTL reader cannot parse string value property #5

Open chongkong opened 5 years ago

chongkong commented 5 years ago

Current implementation assumes every mtl property is either integer, float, or array of float. This prevents the parser from getting texture filename from map_Kd, map_Ks, etc.

https://github.com/ratcave/wavefront_reader/blob/c515164a3952d6b85f8044f429406fddd862bfd0/wavefront_reader/reading.py#L83-L93

This should be fixed as

 elif materials: 
     if data: 
         split_data = data.strip().split(' ') 

         if len(split_data) > 1: 
             material[prefix] = tuple(float(d) for d in split_data) 
         else: 
             try: 
                 material[prefix] = int(data) 
             except ValueError:
                 try:
                     material[prefix] = float(data) 
                 except ValueError:
                     material[prefix] = data  # accept string value

This is also a direct solution to #1