diff options
author | Vilem Duha <vilem.duha@gmail.com> | 2019-06-13 01:21:29 +0300 |
---|---|---|
committer | Vilem Duha <vilem.duha@gmail.com> | 2019-06-13 01:22:31 +0300 |
commit | 9df44aaff67d72f06d4d6e8a66a7f3cb19a85d42 (patch) | |
tree | 32694f380f29bbdad61ae60660727d72a97088ce /blenderkit | |
parent | b35189e003e14301df22c264d6c762d6acaa9e2f (diff) |
BlenderKit: fix transparent materials for eevee on upload time
Diffstat (limited to 'blenderkit')
-rw-r--r-- | blenderkit/__init__.py | 3 | ||||
-rw-r--r-- | blenderkit/overrides.py | 32 | ||||
-rw-r--r-- | blenderkit/upload.py | 18 |
3 files changed, 50 insertions, 3 deletions
diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py index e2b6445a..a96ffa2e 100644 --- a/blenderkit/__init__.py +++ b/blenderkit/__init__.py @@ -375,6 +375,8 @@ def name_update(self, context): nname = nname.lower() nname = nname[0].upper() + nname[1:] props.name = nname + asset = utils.get_active_asset() + asset.name = nname def update_tags(self, context): @@ -402,6 +404,7 @@ def update_tags(self, context): props.tags = ns + class BlenderKitCommonUploadProps(object): id: StringProperty( name="Asset Version Id", diff --git a/blenderkit/overrides.py b/blenderkit/overrides.py index 348a3d21..df9b1729 100644 --- a/blenderkit/overrides.py +++ b/blenderkit/overrides.py @@ -147,6 +147,34 @@ def modelProxy(): return False +eevee_transp_nodes = [ + 'BSDF_GLASS', + 'BSDF_REFRACTION', + 'BSDF_TRANSPARENT', + 'PRINCIPLED_VOLUME', + 'VOLUME_ABSORPTION', + 'VOLUME_SCATTER' +] + + +def ensure_eevee_transparency(m): + ''' ensures alpha for transparent materials when the user didn't set it up correctly''' + # if the blend mode is opaque, it means user probably ddidn't know or forgot to + # set up material properly + if m.blend_method == 'OPAQUE': + alpha = False + for n in m.node_tree.nodes: + if n.type in eevee_transp_nodes: + alpha = True + elif n.type == 'BSDF_PRINCIPLED': + i = n.inputs['Transmission'] + if i.default_value > 0 or len(i.links) > 0: + alpha = True + if alpha: + m.blend_method = 'HASHED' + m.shadow_method = 'HASHED' + + class BringToScene(Operator): """Bring linked object hierarchy to scene and make it editable.""" @@ -215,7 +243,7 @@ class BringToScene(Operator): class ModelProxy(Operator): - """Tooltip""" + """Attempt to create proxy armature from the asset""" bl_idname = "object.blenderkit_make_proxy" bl_label = "BlenderKit Make Proxy" @@ -231,7 +259,7 @@ class ModelProxy(Operator): class ColorCorrector(Operator): - """Tooltip""" + """Add color corector to the asset. """ bl_idname = "object.blenderkit_color_corrector" bl_label = "Add color corrector" diff --git a/blenderkit/upload.py b/blenderkit/upload.py index b38e8269..49aced95 100644 --- a/blenderkit/upload.py +++ b/blenderkit/upload.py @@ -28,8 +28,10 @@ if "bpy" in locals(): version_checker = reload(version_checker) search = reload(search) ui_panels = reload(ui_panels) + overrides = reload(overrides) else: - from blenderkit import asset_inspector, paths, utils, bg_blender, autothumb, version_checker, search, ui_panels + from blenderkit import asset_inspector, paths, utils, bg_blender, autothumb, version_checker, search, ui_panels, \ + overrides import tempfile, os, subprocess, json, re @@ -524,7 +526,17 @@ def check_storage_quota(props): return False +def auto_fix(asset_type=''): + #this applies various procedures to ensure coherency in the database. + asset = utils.get_active_asset() + props = utils.get_upload_props() + if asset_type == 'MATERIAL': + overrides.ensure_eevee_transparency(asset) + asset.name = props.name + + def start_upload(self, context, asset_type, as_new, metadata_only): + '''start upload process, by processing data''' props = utils.get_upload_props() storage_quota_ok = check_storage_quota(props) if not storage_quota_ok: @@ -533,9 +545,13 @@ def start_upload(self, context, asset_type, as_new, metadata_only): location = get_upload_location(props) props.upload_state = 'preparing upload' + + auto_fix(asset_type = asset_type) + # do this for fixing long tags in some upload cases props.tags = props.tags[:] + props.name = props.name.strip() # TODO move this to separate function # check for missing metadata |