bugfix [#24065] obj export (mtl image path)

This commit is contained in:
Campbell Barton 2010-10-01 05:19:40 +00:00
parent 4ab6881617
commit 3dea67a3fd
2 changed files with 15 additions and 0 deletions

@ -52,6 +52,17 @@ def relpath(path, start=None):
return path
def is_subdir(path, directory):
"""
Returns true if *path* in a subdirectory of *directory*.
Both paths must be absolute.
"""
from os.path import normpath, normcase
path = normpath(normcase(path))
directory = normpath(normcase(directory))
return path.startswith(directory)
def clean_name(name, replace="_"):
"""
Returns a name with characters replaced that may cause problems under various circumstances, such as writing to a file.

@ -40,12 +40,16 @@ def write_mtl(scene, filepath, copy_images, mtl_dict):
def copy_image(image):
fn = bpy.path.abspath(image.filepath)
fn = os.path.normpath(fn)
fn_strip = os.path.basename(fn)
if copy_images:
rel = fn_strip
fn_abs_dest = os.path.join(dest_dir, fn_strip)
if not os.path.exists(fn_abs_dest):
shutil.copy(fn, fn_abs_dest)
elif bpy.path.is_subdir(fn, dest_dir):
rel = os.path.relpath(fn, dest_dir)
else:
rel = fn