diff --git a/modules/LoadLocalModel.py b/modules/LoadLocalModel.py index d942b7f..be20e6a 100644 --- a/modules/LoadLocalModel.py +++ b/modules/LoadLocalModel.py @@ -84,6 +84,7 @@ def execute(self, context: Context) -> Set[str]: # so that an existing importer Operator can be wrapped at run-time # with a wrapper function that supplied other import arguments + logger.info(f"LoadLocalModel.execute self.mimetype: {self.mimetype}") try: handler, handler_name = handler_for_mimetype(self.mimetype) except KeyError: @@ -153,7 +154,7 @@ class ImportGLTF2; function set_debug_log def handler_for_mimetype( mimetype:str) -> Tuple[Callable[..., Set[str]] , str] : """ - return 2-tuple (func, label) + return 2-tuple (func, label), or raises KeyError function is the callable, may be Blender defined operator call such as bpy.ops.import_scene.gltf label a string used only for logging messages @@ -166,8 +167,7 @@ def handler_for_mimetype( mimetype:str) -> Tuple[Callable[..., Set[str]] , str] mimetype_importer_dict = { "model/gltf-binary" : GLTF_IMPORTER, - "model/gltf+json" : GLTF_IMPORTER, - "application/octet-stream" : GLTF_IMPORTER + "model/gltf+json" : GLTF_IMPORTER } return mimetype_importer_dict[mimetype] diff --git a/modules/LoadNetworkModel.py b/modules/LoadNetworkModel.py index 49e809b..452f0e5 100644 --- a/modules/LoadNetworkModel.py +++ b/modules/LoadNetworkModel.py @@ -9,6 +9,9 @@ from bpy.props import StringProperty from bpy.types import Context, Operator +from .LoadLocalModel import handler_for_mimetype +from .editing.models import mimetype_from_extension + import logging logger = logging.getLogger("iiif.import_network_model") @@ -84,8 +87,26 @@ def execute(self, context: Context) -> Set[str]: # URL data downloaded to local_filepath and # http_mimetype set to the Content-Type (or to "") + # logic for figuring out a mimetype to decode the resource as a 3D asset + def choose_mimetype(): + for mime_choice in (http_mimetype, self.mimetype): + try: + handler_for_mimetype( mime_choice) + except KeyError: + continue + return mime_choice + + # if neither http_mimetype, self.mimetype are supported, + # try to get somethinf from the extension on the model_basename + try: + return mimetype_from_extension( model_basename ) + except Exception: + pass - mimetype = self.mimetype or http_mimetype + # if all else fails, return mimetype for glb as the default: + return "model/gltf-binary" + + mimetype = choose_mimetype() # call the ImportLocalModel Operator to import the contents # of the local_filepath file into Blender as a Blender Object diff --git a/modules/editing/models.py b/modules/editing/models.py index 0439099..e2aa76a 100644 --- a/modules/editing/models.py +++ b/modules/editing/models.py @@ -63,6 +63,7 @@ def configure_model( new_model : Object, if "format" in resource_data and resource_data["format"] != mimetype: message=f'resource format ${resource_data["format"]} does not match ${mimetype}' logger.warn(message) + resource_data["format"] = mimetype new_model["iiif_type"] = "Model" new_model["iiif_json"] = json.dumps(resource_data)