From 36e42ad73601c8d90adc86f0b801ab1aa394ce4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Br=C3=BCckner?= Date: Mon, 25 Oct 2021 19:43:13 +0200 Subject: [PATCH] Fix exporting textures from linked libraries --- blender/arm/material/cycles.py | 4 ++++ blender/arm/utils.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/blender/arm/material/cycles.py b/blender/arm/material/cycles.py index 91c1c47b..c0c70328 100644 --- a/blender/arm/material/cycles.py +++ b/blender/arm/material/cycles.py @@ -737,7 +737,9 @@ def node_name(s: str) -> str: ## + def make_texture(image_node: bpy.types.ShaderNodeTexImage, tex_name: str, matname: str = None) -> Optional[Dict[str, Any]]: + """Creates a texture reference for the export data for a given texture node.""" tex = {'name': tex_name} if matname is None: @@ -768,6 +770,8 @@ def make_texture(image_node: bpy.types.ShaderNodeTexImage, tex_name: str, matnam else: log.warn(matname + '/' + image.name + ' - invalid file path') return None + else: + filepath = arm.utils.to_absolute_path(filepath, image.library) # Reference image name texpath = arm.utils.asset_path(filepath) diff --git a/blender/arm/utils.py b/blender/arm/utils.py index 1b4d7543..6d00775e 100755 --- a/blender/arm/utils.py +++ b/blender/arm/utils.py @@ -104,7 +104,8 @@ def blend_name(): def build_dir(): return 'build_' + safestr(blend_name()) -def get_fp(): + +def get_fp() -> str: wrd = bpy.data.worlds['Arm'] if wrd.arm_project_root != '': return bpy.path.abspath(wrd.arm_project_root) @@ -127,9 +128,22 @@ def get_fp(): s += os.path.sep return s + def get_fp_build(): return os.path.join(get_fp(), build_dir()) + +def to_absolute_path(path: str, from_library: Optional[bpy.types.Library] = None) -> str: + """Convert the given absolute or relative path into an absolute path. + + - If `from_library` is not set (default), a given relative path will be + interpreted as relative to the project directory. + - If `from_library` is set, a given relative path will be interpreted as + relative to the filepath of the specified library. + """ + return os.path.normpath(bpy.path.abspath(path, start=get_fp(), library=from_library)) + + def get_os() -> str: s = platform.system() if s == 'Windows':