Skip to content

Commit

Permalink
VC limit reached warning
Browse files Browse the repository at this point in the history
Some bake modes use internally a custom Vertex Color layer which is removed once the bake finishes. If the maximum number of VC layers are in use in an object to be baked from (that is, 8), warn about it and gray out the Bake button to avoid an exception.

Additionally, make sure materials without node tree don't make the addon UI refresh fail in the search of UDIMs, writing an error in the Console..
  • Loading branch information
franMarz committed Oct 18, 2021
1 parent 94600d5 commit 6ee6224
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
12 changes: 7 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,13 @@ def get_UDIM_image():
for i in range(len(obj.material_slots)):
slot = obj.material_slots[i]
if slot.material:
nodes = slot.material.node_tree.nodes
if nodes:
for node in nodes:
if node.type == 'TEX_IMAGE' and node.image and node.image.source =='TILED':
return node.image
tree = slot.material.node_tree
if tree:
nodes = tree.nodes
if nodes:
for node in nodes:
if node.type == 'TEX_IMAGE' and node.image and node.image.source =='TILED':
return node.image
return None

if bpy.context.scene.texToolsSettings.UDIMs_source == 'OBJECT':
Expand Down
33 changes: 25 additions & 8 deletions op_bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def poll(cls, context):
settings.bake_error = ""
return True

if modes[bake_mode].material == "":
if modes[bake_mode].setVColor or not modes[bake_mode].material:
def is_bakeable(obj):
if len(obj.data.materials) <= 0: # There are no material slots
settings.bake_error = "Materials needed"
Expand All @@ -113,16 +113,33 @@ def is_bakeable(obj):
# return False
settings.bake_error = ""
return True


def is_vc_ready(obj):
if len(obj.data.vertex_colors) > 7:
settings.bake_error = "An empty VC layer needed"
return False
settings.bake_error = ""
return True

for bset in settings.sets:
if (len(bset.objects_high) + len(bset.objects_float)) == 0:
for obj in bset.objects_low:
if not is_bakeable(obj):
return False
if not modes[bake_mode].material:
for obj in bset.objects_low:
if not is_bakeable(obj):
return False
if modes[bake_mode].setVColor:
for obj in bset.objects_low:
if not is_vc_ready(obj):
return False
else:
for obj in (bset.objects_high+bset.objects_float):
if not is_bakeable(obj):
return False
if not modes[bake_mode].material:
for obj in (bset.objects_high + bset.objects_float):
if not is_bakeable(obj):
return False
if modes[bake_mode].setVColor:
for obj in (bset.objects_high + bset.objects_float):
if not is_vc_ready(obj):
return False

settings.bake_error = ""
return True
Expand Down

0 comments on commit 6ee6224

Please sign in to comment.