From f6e4f112561b5534cd390d45ef7519badc6c34d2 Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Tue, 24 Dec 2019 20:08:39 -0800 Subject: [PATCH] Fix annoying missing texture issue When getting/setting texel density, use currently open image if object has no image assigned to it --- op_texel_density_get.py | 16 +++++++++++----- op_texel_density_set.py | 16 ++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/op_texel_density_get.py b/op_texel_density_get.py index 7d9f3da..788cf7a 100644 --- a/op_texel_density_get.py +++ b/op_texel_density_get.py @@ -66,10 +66,12 @@ def get_texel_density(self, context): if image: object_images[obj] = image - # Warning: No valid images - if len(object_images) == 0: - self.report({'ERROR_INVALID_INPUT'}, "No Texture found. Assign Checker map or texture first." ) - return + fallback_image = None + for area in bpy.context.screen.areas: + if area.type == 'IMAGE_EDITOR': + fallback_image = area.spaces[0].image + break + sum_area_vt = 0 sum_area_uv = 0 @@ -82,7 +84,11 @@ def get_texel_density(self, context): obj.select_set( state = True, view_layer = None) # Find image of object - image = object_images[obj] + if obj in object_images: + image = object_images[obj] + else: + image = fallback_image + if image: bpy.ops.object.mode_set(mode='EDIT') bm = bmesh.from_edit_mesh(obj.data) diff --git a/op_texel_density_set.py b/op_texel_density_set.py index 31c6ab3..5cd1bf6 100644 --- a/op_texel_density_set.py +++ b/op_texel_density_set.py @@ -72,11 +72,11 @@ def set_texel_density(self, context, mode, density): if image: object_images[obj] = image - # Warning: No valid images - if len(object_images) == 0: - self.report({'ERROR_INVALID_INPUT'}, - "No Texture found. Assign Checker map or texture.") - return + fallback_image = None + for area in bpy.context.screen.areas: + if area.type == 'IMAGE_EDITOR': + fallback_image = area.spaces[0].image + break for obj in object_faces: bpy.ops.object.mode_set(mode='OBJECT') @@ -85,7 +85,11 @@ def set_texel_density(self, context, mode, density): obj.select_set(state=True, view_layer=None) # Find image of object - image = object_images[obj] + if obj in object_images: + image = object_images[obj] + else: + image = fallback_image + if image: bpy.ops.object.mode_set(mode='EDIT') bpy.context.scene.tool_settings.use_uv_select_sync = False