Skip to content

Commit c8e70c5

Browse files
committed
Add disambiguation messages
1 parent 154465c commit c8e70c5

File tree

6 files changed

+61
-30
lines changed

6 files changed

+61
-30
lines changed

blender/LilySurfaceScraper/CyclesMaterialData.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,27 @@
77
import bpy
88
from bpy_extras.node_shader_utils import PrincipledBSDFWrapper
99
from .MaterialData import MaterialData
10-
from .cycles_utils import getCyclesImage, autoAlignNodes, findColorSpace
10+
from .cycles_utils import getCyclesImage, autoAlignNodes
1111
from .preferences import getPreferences
1212

13+
def listAvailableColorSpaces(image):
14+
# Warning: hack ahead
15+
try:
16+
image.colorspace_settings.name = ''
17+
except TypeError as e:
18+
s = str(e)
19+
return eval(s[s.find('('):])
20+
21+
def findColorSpace(image, key):
22+
"""This is important for custom OCIO config"""
23+
availableColorSpaces = listAvailableColorSpaces(image)
24+
if key in availableColorSpaces:
25+
return key
26+
for cs in availableColorSpaces:
27+
if key in cs:
28+
return cs
29+
return availableColorSpaces[0]
30+
1331
class CyclesMaterialData(MaterialData):
1432
# Translate our internal map names into cycles principled inputs
1533
input_tr = {

blender/LilySurfaceScraper/CyclesWorldData.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def createWorld(self):
5050
if img is not None:
5151
texture_node = nodes.new(type="ShaderNodeTexEnvironment")
5252
texture_node.image = getCyclesImage(img)
53-
color_space = guessColorSpaceFromExtension(texture_node.image, img)
53+
color_space = guessColorSpaceFromExtension(img)
5454
texture_node.image.colorspace_settings.name = color_space["name"]
5555
if hasattr(texture_node, "color_space"):
5656
texture_node.color_space = color_space["old_name"]

blender/LilySurfaceScraper/ScrapedData.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# from a single URL
2323

2424
from .settings import UNSUPPORTED_PROVIDER_ERR
25+
from .ScrapersManager import ScrapersManager
2526

2627

2728
class ScrapedData():
@@ -55,7 +56,10 @@ def __init__(self, url, texture_root="", asset_name=None, scraping_type=None):
5556
self.reinstall = False
5657

5758
if self._scraper is None:
58-
self.error = UNSUPPORTED_PROVIDER_ERR
59+
self.error = scraping_type.capitalize() + " " + UNSUPPORTED_PROVIDER_ERR
60+
for S in ScrapersManager.getScrapersList():
61+
if S.canHandleUrl(self.url) and S.scraped_type:
62+
self.error = f"This URL corresponds to a {next(iter(S.scraped_type)).lower()} but you are trying to import it as a {scraping_type.lower()}"
5963
else:
6064
self._scraper.texture_root = texture_root
6165
self._scraper.metadata.scrape_type = scraping_type

blender/LilySurfaceScraper/cycles_utils.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,34 +126,16 @@ def __init__(self, world):
126126
elif self.node_out is None and n.type == "OUTPUT_WORLD":
127127
self.node_out = n
128128

129-
def listAvailableColorSpaces(image):
130-
# Warning: hack ahead
131-
try:
132-
image.colorspace_settings.name = ''
133-
except TypeError as e:
134-
s = str(e)
135-
return eval(s[s.find('('):])
136-
137-
def findColorSpace(image, key):
138-
"""This is important for custom OCIO config"""
139-
availableColorSpaces = listAvailableColorSpaces(image)
140-
if key in availableColorSpaces:
141-
return key
142-
for cs in availableColorSpaces:
143-
if key in cs:
144-
return cs
145-
return availableColorSpaces[0]
146-
147-
def guessColorSpaceFromExtension(image, image_filename):
129+
def guessColorSpaceFromExtension(img):
148130
"""Guess the most appropriate color space from filename extension"""
149-
name = image_filename.lower()
150-
if name.endswith(".jpg") or name.endswith(".jpeg") or name.endswith(".png"):
131+
img = img.lower()
132+
if img.endswith(".jpg") or img.endswith(".jpeg") or img.endswith(".png"):
151133
return {
152-
"name": findColorSpace(image, 'sRGB'),
134+
"name": "sRGB",
153135
"old_name": "COLOR", # mostly for backward compatibility
154136
}
155137
else:
156138
return {
157-
"name": findColorSpace(image, 'Non-Color'),
139+
"name": "Linear",
158140
"old_name": "NONE",
159141
}

blender/LilySurfaceScraper/frontend.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ def invoke(self, context, event):
148148
return self.execute(context)
149149

150150
def execute(self, context):
151-
bpy.ops.object.lily_surface_import('EXEC_DEFAULT', url=bpy.context.window_manager.clipboard)
151+
try:
152+
bpy.ops.object.lily_surface_import('EXEC_DEFAULT', url=bpy.context.window_manager.clipboard)
153+
except RuntimeError as err:
154+
msg = err.args[0]
155+
if msg.startswith("Invalid Input Error: "):
156+
error = msg[len("Invalid Input Error: "):]
157+
self.report({'ERROR_INVALID_INPUT'}, error)
158+
return {'CANCELLED'}
159+
else:
160+
raise err
152161
return {'FINISHED'}
153162

154163
def list_variant_enum(self, context):
@@ -306,7 +315,16 @@ def invoke(self, context, event):
306315
return self.execute(context)
307316

308317
def execute(self, context):
309-
bpy.ops.object.lily_world_import('EXEC_DEFAULT', url=bpy.context.window_manager.clipboard)
318+
try:
319+
bpy.ops.object.lily_world_import('EXEC_DEFAULT', url=bpy.context.window_manager.clipboard)
320+
except RuntimeError as err:
321+
msg = err.args[0]
322+
if msg.startswith("Invalid Input Error: "):
323+
error = msg[len("Invalid Input Error: "):]
324+
self.report({'ERROR_INVALID_INPUT'}, error)
325+
return {'CANCELLED'}
326+
else:
327+
raise err
310328
return {'FINISHED'}
311329

312330
def list_variant_enum(self, context):
@@ -425,7 +443,16 @@ def invoke(self, context, event):
425443
return self.execute(context)
426444

427445
def execute(self, context):
428-
bpy.ops.object.lily_light_import('EXEC_DEFAULT', url=bpy.context.window_manager.clipboard)
446+
try:
447+
bpy.ops.object.lily_light_import('EXEC_DEFAULT', url=bpy.context.window_manager.clipboard)
448+
except RuntimeError as err:
449+
msg = err.args[0]
450+
if msg.startswith("Invalid Input Error: "):
451+
error = msg[len("Invalid Input Error: "):]
452+
self.report({'ERROR_INVALID_INPUT'}, error)
453+
return {'CANCELLED'}
454+
else:
455+
raise err
429456
return {'FINISHED'}
430457

431458
# -------------------------------------------------------------------

blender/LilySurfaceScraper/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
## Constants
2525

2626
TEXTURE_DIR = "LilySurface"
27-
UNSUPPORTED_PROVIDER_ERR = "Material provider not supported. See the documentation for a list of supported material providers."
27+
UNSUPPORTED_PROVIDER_ERR = "provider not supported. See the documentation for a list of supported providers."

0 commit comments

Comments
 (0)