Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/LoadLocalModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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]
23 changes: 22 additions & 1 deletion modules/LoadNetworkModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/editing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down