[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4450] trunk/py/scripts/addons/ io_scene_obj: fix [#34864] Save&Load - Relative Paths ticked, Obj Import and Textures tab uses absolute paths
Campbell Barton
ideasman42 at gmail.com
Fri Apr 5 02:37:20 CEST 2013
Revision: 4450
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4450
Author: campbellbarton
Date: 2013-04-05 00:37:20 +0000 (Fri, 05 Apr 2013)
Log Message:
-----------
fix [#34864] Save&Load - Relative Paths ticked, Obj Import and Textures tab uses absolute paths
use preference for relative paths.
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_obj/__init__.py
trunk/py/scripts/addons/io_scene_obj/import_obj.py
Modified: trunk/py/scripts/addons/io_scene_obj/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/__init__.py 2013-04-04 18:25:22 UTC (rev 4449)
+++ trunk/py/scripts/addons/io_scene_obj/__init__.py 2013-04-05 00:37:20 UTC (rev 4450)
@@ -164,6 +164,10 @@
).to_4x4()
keywords["global_matrix"] = global_matrix
+ if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
+ import os
+ keywords["relpath"] = os.path.dirname((bpy.data.path_resolve("filepath", False).as_bytes()))
+
return import_obj.load(self, context, **keywords)
def draw(self, context):
Modified: trunk/py/scripts/addons/io_scene_obj/import_obj.py
===================================================================
--- trunk/py/scripts/addons/io_scene_obj/import_obj.py 2013-04-04 18:25:22 UTC (rev 4449)
+++ trunk/py/scripts/addons/io_scene_obj/import_obj.py 2013-04-05 00:37:20 UTC (rev 4450)
@@ -74,20 +74,22 @@
return b' '.join(line_split[1:])
-def obj_image_load(imagepath, DIR, recursive):
+def obj_image_load(imagepath, DIR, recursive, relpath):
"""
Mainly uses comprehensiveImageLoad
but tries to replace '_' with ' ' for Max's exporter replaces spaces with underscores.
"""
if b'_' in imagepath:
- image = load_image(imagepath.replace(b'_', b' '), DIR, recursive=recursive)
+ image = load_image(imagepath.replace(b'_', b' '), DIR, recursive=recursive, relpath=relpath)
if image:
return image
- return load_image(imagepath, DIR, recursive=recursive, place_holder=True)
+ return load_image(imagepath, DIR, recursive=recursive, place_holder=True, relpath=relpath)
-def create_materials(filepath, material_libs, unique_materials, unique_material_images, use_image_search, float_func):
+def create_materials(filepath, relpath,
+ material_libs, unique_materials, unique_material_images,
+ use_image_search, float_func):
"""
Create all the used materials in this obj,
assign colors and images to the materials from all referenced material libs
@@ -103,7 +105,7 @@
texture = bpy.data.textures.new(name=type, type='IMAGE')
# Absolute path - c:\.. etc would work here
- image = obj_image_load(imagepath, DIR, use_image_search)
+ image = obj_image_load(imagepath, DIR, use_image_search, relpath)
has_data = False
image_depth = 0
@@ -838,6 +840,7 @@
use_split_groups=True,
use_image_search=True,
use_groups_as_vgroups=False,
+ relpath=None,
global_matrix=None,
):
"""
@@ -1101,7 +1104,7 @@
time_sub = time_new
print('\tloading materials and images...')
- create_materials(filepath, material_libs, unique_materials, unique_material_images, use_image_search, float_func)
+ create_materials(filepath, relpath, material_libs, unique_materials, unique_material_images, use_image_search, float_func)
time_new = time.time()
print("%.4f sec" % (time_new - time_sub))
More information about the Bf-extensions-cvs
mailing list