load material library file relative to object file location

This commit is contained in:
Josh Holtrop 2012-07-15 18:45:26 -04:00
parent d00b6a0d4e
commit 63695755b0

View File

@ -1,5 +1,6 @@
import types
import os
class WFObj(object):
def __init__(self, source, fileloader=None):
@ -10,6 +11,7 @@ class WFObj(object):
self.faces = {}
self.materials = {}
if type(source) == types.StringType:
self.source_path = source
if self.fileloader is not None:
fh = self.fileloader(source)
self.load(fh)
@ -18,6 +20,7 @@ class WFObj(object):
self.load(fh)
fh.close()
else:
self.source_path = ''
self.load(source)
def load(self, fh):
@ -106,6 +109,9 @@ class WFObj(object):
self.shininess = 50
def load_material_library(self, name):
dn = os.path.dirname(self.source_path)
if dn != '':
name = dn + os.path.sep + name
if self.fileloader is not None:
fh = self.fileloader(name)
else: