From 32a083bf3ecfb97f663e1851074144ded641a9fe Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Thu, 31 Oct 2024 15:04:25 +0100 Subject: [PATCH 1/2] Do not export tile if no vertices in it --- addons/io_scene_gltf2/blender/exp/primitive_extract.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/io_scene_gltf2/blender/exp/primitive_extract.py b/addons/io_scene_gltf2/blender/exp/primitive_extract.py index a06945b97..d56a109f5 100644 --- a/addons/io_scene_gltf2/blender/exp/primitive_extract.py +++ b/addons/io_scene_gltf2/blender/exp/primitive_extract.py @@ -705,6 +705,10 @@ def manage_material_info(self): indices = np.where((self.dots[uvmap_name + '0'] >= u) & (self.dots[uvmap_name + '0'] <= (u + 1)) & ( self.dots[uvmap_name + '1'] <= (1 - v)) & (self.dots[uvmap_name + '1'] >= 1 - (v + 1)))[0] + # If no vertex in this tile, continue + if indices.shape[0] == 0: + continue + # Reset UVMap to 0-1 : reset to Blener UVMAP => slide to 0-1 => go to glTF UVMap self.dots[uvmap_name + '1'][indices] -= 1 self.dots[uvmap_name + '1'][indices] *= -1 From 0415298b2ecaac18f8793195544c532f7b1ba674 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Thu, 31 Oct 2024 15:04:44 +0100 Subject: [PATCH 2/2] Fix jpg & webp detection for udim textures --- .../blender/exp/material/encode_image.py | 12 ++++++++++++ addons/io_scene_gltf2/blender/exp/material/image.py | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/io_scene_gltf2/blender/exp/material/encode_image.py b/addons/io_scene_gltf2/blender/exp/material/encode_image.py index 5c5a64578..4e6b3d9ef 100644 --- a/addons/io_scene_gltf2/blender/exp/material/encode_image.py +++ b/addons/io_scene_gltf2/blender/exp/material/encode_image.py @@ -195,6 +195,16 @@ def blender_image(self, export_settings) -> Optional[bpy.types.Image]: for fill in self.fills.values(): return fill.image + + if self.__on_happy_path_udim(): + # Store that this image is fully exported (used to export or not not used images) + for fill in self.fills.values(): + export_settings['exported_images'][fill.image.name] = 1 # Fully used + break + + for fill in self.fills.values(): + return fill.image + return None def __on_happy_path(self) -> bool: @@ -431,6 +441,8 @@ def __encode_from_image_tile(self, udim_image, tile, export_settings): return data # We don't manage UDIM packed image, so this could not happen to be here + # Lets display an error + export_settings['log'].error("UDIM packed images are not supported for export. Please unpack them before exporting.") def _encode_temp_image(tmp_image: bpy.types.Image, file_format: str, export_settings) -> bytes: diff --git a/addons/io_scene_gltf2/blender/exp/material/image.py b/addons/io_scene_gltf2/blender/exp/material/image.py index c67909e00..ff5e00e52 100644 --- a/addons/io_scene_gltf2/blender/exp/material/image.py +++ b/addons/io_scene_gltf2/blender/exp/material/image.py @@ -422,7 +422,7 @@ def __get_image_data_grayscale_anisotropy(sockets, results, export_settings) -> def __is_blender_image_a_jpeg(image: bpy.types.Image) -> bool: - if image.source != 'FILE': + if image.source not in ['FILE', 'TILED']: return False if image.filepath_raw == '' and image.packed_file: return image.packed_file.data[:3] == b'\xff\xd8\xff' @@ -432,7 +432,7 @@ def __is_blender_image_a_jpeg(image: bpy.types.Image) -> bool: def __is_blender_image_a_webp(image: bpy.types.Image) -> bool: - if image.source != 'FILE': + if image.source not in ['FILE', 'TILED']: return False if image.filepath_raw == '' and image.packed_file: return image.packed_file.data[8:12] == b'WEBP'