Support case where mtl file is missing
This commit is contained in:
parent
705df01207
commit
7a9e1a741e
|
@ -5,6 +5,7 @@ from .mesh import Material, MeshPart
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
import os.path
|
import os.path
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def is_obj(filename):
|
def is_obj(filename):
|
||||||
|
@ -15,6 +16,7 @@ class OBJParser(ModelParser):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.current_material = None
|
self.current_material = None
|
||||||
|
self.mtl = None
|
||||||
|
|
||||||
def parse_line(self, string):
|
def parse_line(self, string):
|
||||||
if string == '':
|
if string == '':
|
||||||
|
@ -24,12 +26,15 @@ class OBJParser(ModelParser):
|
||||||
first = split[0]
|
first = split[0]
|
||||||
split = split[1:]
|
split = split[1:]
|
||||||
|
|
||||||
if first == 'usemtl':
|
if first == 'usemtl' and self.mtl is not None:
|
||||||
self.current_material = self.mtl[split[0]]
|
self.current_material = self.mtl[split[0]]
|
||||||
elif first == 'mtllib':
|
elif first == 'mtllib':
|
||||||
path = os.path.join(os.path.dirname(self.path), split[0])
|
path = os.path.join(os.path.dirname(self.path), split[0])
|
||||||
self.mtl = MTLParser(self)
|
if os.path.isfile(path):
|
||||||
self.mtl.parse_file(path)
|
self.mtl = MTLParser(self)
|
||||||
|
self.mtl.parse_file(path)
|
||||||
|
else:
|
||||||
|
print('Warning : ' + path + 'not found ', file=sys.stderr)
|
||||||
elif first == 'v':
|
elif first == 'v':
|
||||||
self.add_vertex(Vertex().from_array(split))
|
self.add_vertex(Vertex().from_array(split))
|
||||||
elif first == 'vn':
|
elif first == 'vn':
|
||||||
|
|
Loading…
Reference in New Issue