diff --git a/addons/io_hubs_addon/components/definitions/environment_settings.py b/addons/io_hubs_addon/components/definitions/environment_settings.py index c488433b..1590dd07 100644 --- a/addons/io_hubs_addon/components/definitions/environment_settings.py +++ b/addons/io_hubs_addon/components/definitions/environment_settings.py @@ -1,6 +1,5 @@ from bpy.props import FloatProperty, EnumProperty, FloatVectorProperty, PointerProperty, BoolProperty from bpy.types import Image -from ...io.utils import import_component, assign_property, import_image from ..hubs_component import HubsComponent from ..types import Category, PanelType, NodeType from ..utils import is_linked @@ -163,23 +162,3 @@ def gather(self, export_settings, object): } return output - - @classmethod - def gather_import(cls, gltf, blender_host, component_name, component_value, blender_ob=None): - blender_component = import_component( - component_name, blender_host) - - images = {} - for gltf_texture in gltf.data.textures: - blender_image_name, source = import_image(gltf, gltf_texture) - images[source] = blender_image_name - - for property_name, property_value in component_value.items(): - if isinstance(property_value, dict) and property_value['__mhc_link_type'] == "texture": - blender_image_name = images[property_value['index']] - blender_image = bpy.data.images[blender_image_name] - setattr(blender_component, property_name, blender_image) - - else: - assign_property(gltf.vnodes, blender_component, - property_name, property_value) diff --git a/addons/io_hubs_addon/components/definitions/reflection_probe.py b/addons/io_hubs_addon/components/definitions/reflection_probe.py index 8c193fc7..a15c1214 100644 --- a/addons/io_hubs_addon/components/definitions/reflection_probe.py +++ b/addons/io_hubs_addon/components/definitions/reflection_probe.py @@ -9,7 +9,6 @@ from ..hubs_component import HubsComponent from ..types import Category, PanelType, NodeType, MigrationType from ..ui import add_link_indicator -from ...io.utils import import_component, assign_property, import_image from ...utils import rgetattr, rsetattr from ..utils import get_host_reference_message from ..models import reflection_probe @@ -925,22 +924,6 @@ def create_gizmo(cls, ob, gizmo_group): return gizmo - @classmethod - def gather_import(cls, gltf, blender_host, component_name, component_value, blender_ob=None): - blender_component = import_component( - component_name, blender_host) - images = {} - for gltf_texture in gltf.data.textures: - blender_image_name, source = import_image(gltf, gltf_texture) - images[source] = blender_image_name - for property_name, property_value in component_value.items(): - if isinstance(property_value, dict) and property_value['__mhc_link_type'] == "texture": - blender_image_name = images[property_value['index']] - blender_image = bpy.data.images[blender_image_name] - setattr(blender_component, property_name, blender_image) - else: - assign_property(gltf.vnodes, blender_component, - property_name, property_value) @ staticmethod def register(): diff --git a/addons/io_hubs_addon/io/gltf_importer.py b/addons/io_hubs_addon/io/gltf_importer.py index d8a9e3b3..aa0a1392 100644 --- a/addons/io_hubs_addon/io/gltf_importer.py +++ b/addons/io_hubs_addon/io/gltf_importer.py @@ -4,7 +4,7 @@ from io_scene_gltf2.blender.imp.gltf2_blender_material import BlenderMaterial from io_scene_gltf2.blender.imp.gltf2_blender_scene import BlenderScene from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage -from .utils import HUBS_CONFIG, import_image +from .utils import HUBS_CONFIG, import_image, import_all_images from ..components.components_registry import get_component_by_name import traceback @@ -138,6 +138,8 @@ def gather_import_scene_before_hook(self, gltf_scene, blender_scene, gltf): gltf.import_settings['gltf_yup'] = gltf.data.asset.extras[ 'gltf_yup'] + import_all_images(gltf) + def gather_import_scene_after_nodes_hook(self, gltf_scene, blender_scene, gltf): if not self.properties.enabled: return @@ -237,6 +239,7 @@ def patched_BlenderScene_create(gltf): delayed_gathers.clear() import_report.clear() + import_all_images(gltf) orig_BlenderScene_create(gltf) gltf_scene = gltf.data.scenes[gltf.data.scene] blender_object = bpy.data.scenes[gltf.blender_scene] diff --git a/addons/io_hubs_addon/io/utils.py b/addons/io_hubs_addon/io/utils.py index 96cda77d..c49b0eb2 100644 --- a/addons/io_hubs_addon/io/utils.py +++ b/addons/io_hubs_addon/io/utils.py @@ -24,6 +24,8 @@ "gltfExtensionVersion": 4, } +imported_images = {} + # gather_texture/image with HDR support via MOZ_texture_rgbe @@ -407,6 +409,19 @@ def import_image(gltf, gltf_texture): return blender_image_name, source + +def import_all_images(gltf): + global imported_images + imported_images.clear() + + if not gltf.data.textures: + return + + for gltf_texture in gltf.data.textures: + blender_image_name, source = import_image(gltf, gltf_texture) + imported_images[source] = blender_image_name + + def import_component(component_name, blender_object): from ..components.utils import add_component, has_component from ..components.components_registry import get_component_by_name @@ -435,8 +450,14 @@ def assign_property(vnodes, blender_component, property_name, property_value): if isinstance(property_value, dict): if property_value.get('__mhc_link_type'): if len(property_value) == 2: - setattr(blender_component, property_name, - vnodes[property_value['index']].blender_object) + if property_value['__mhc_link_type'] == "node": + setattr(blender_component, property_name, + vnodes[property_value['index']].blender_object) + elif property_value['__mhc_link_type'] == "texture": + global imported_images + blender_image_name = imported_images[property_value['index']] + blender_image = bpy.data.images[blender_image_name] + setattr(blender_component, property_name, blender_image) else: blender_subcomponent = getattr(blender_component, property_name)