From 3dea67a3fd7ea7bc37e96635621655e5075444ee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 1 Oct 2010 05:19:40 +0000 Subject: [PATCH] bugfix [#24065] obj export (mtl image path) --- release/scripts/modules/bpy/path.py | 11 +++++++++++ release/scripts/op/io_scene_obj/export_obj.py | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py index 92d2533c2c1..1470c1fda01 100644 --- a/release/scripts/modules/bpy/path.py +++ b/release/scripts/modules/bpy/path.py @@ -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. diff --git a/release/scripts/op/io_scene_obj/export_obj.py b/release/scripts/op/io_scene_obj/export_obj.py index 23d9ab2aa06..abdb07c1a8e 100644 --- a/release/scripts/op/io_scene_obj/export_obj.py +++ b/release/scripts/op/io_scene_obj/export_obj.py @@ -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