Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved error message when prepping only mats with missing image paths. #611

Merged
merged 1 commit into from
Aug 5, 2024
Merged
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
36 changes: 20 additions & 16 deletions MCprep_addon/materials/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

AnimatedTex = Dict[str, int]

# Error codes used during mat prep
NO_DIFFUSE_NODE = 1
IMG_MISSING = 2


class PackFormat(Enum):
SIMPLE = 0
SEUS = 1
Expand Down Expand Up @@ -1244,16 +1249,16 @@ def matgen_cycles_simple(mat: Material, options: PrepOptions) -> Optional[bool]:

if not image_diff:
print(f"Could not find diffuse image, halting generation: {mat.name}")
return
return NO_DIFFUSE_NODE
elif image_diff.size[0] == 0 or image_diff.size[1] == 0:
if image_diff.source != 'SEQUENCE':
# Common non animated case; this means the image is missing and would
# have already checked for replacement textures by now, so skip.
return
return IMG_MISSING
if not os.path.isfile(bpy.path.abspath(image_diff.filepath)):
# can't check size or pixels as it often is not immediately avaialble
# so instead, check against firs frame of sequence to verify load
return
return IMG_MISSING

mat.use_nodes = True
animated_data = copy_texture_animation_pass_settings(mat)
Expand Down Expand Up @@ -1364,16 +1369,16 @@ def matgen_cycles_principled(mat: Material, options: PrepOptions) -> Optional[bo

if not image_diff:
print(f"Could not find diffuse image, halting generation: {mat.name}")
return
return NO_DIFFUSE_NODE
elif image_diff.size[0] == 0 or image_diff.size[1] == 0:
if image_diff.source != 'SEQUENCE':
# Common non animated case; this means the image is missing and would
# have already checked for replacement textures by now, so skip
return
return IMG_MISSING
if not os.path.isfile(bpy.path.abspath(image_diff.filepath)):
# can't check size or pixels as it often is not immediately avaialble
# so instead, check against first frame of sequence to verify load
return
return IMG_MISSING

mat.use_nodes = True
animated_data = copy_texture_animation_pass_settings(mat)
Expand All @@ -1392,7 +1397,7 @@ def matgen_cycles_principled(mat: Material, options: PrepOptions) -> Optional[bo

# Sets default transparency value
nodeMixTrans.inputs[0].default_value = 1

# Sets default reflective values
if options.use_reflections and checklist(canon, "reflective"):
principled.inputs["Roughness"].default_value = 0
Expand All @@ -1412,11 +1417,11 @@ def matgen_cycles_principled(mat: Material, options: PrepOptions) -> Optional[bo
links.new(nodeMixTrans.outputs["Shader"], nodeOut.inputs[0])

nodeEmit = create_node(
nodes, "ShaderNodeEmission", location=(120, 140))
nodes, "ShaderNodeEmission", location=(120, 140))
nodeEmitCam = create_node(
nodes, "ShaderNodeEmission", location=(120, 260))
nodes, "ShaderNodeEmission", location=(120, 260))
nodeMixEmit = create_node(
nodes, "ShaderNodeMixShader", location=(420, 0))
nodes, "ShaderNodeMixShader", location=(420, 0))
if options.use_emission_nodes:
# Create emission nodes
nodeMixCam = create_node(
Expand All @@ -1425,7 +1430,7 @@ def matgen_cycles_principled(mat: Material, options: PrepOptions) -> Optional[bo
nodes, "ShaderNodeLightFalloff", location=(-80, 320))
nodeLightPath = create_node(
nodes, "ShaderNodeLightPath", location=(-320, 520))

# Set values
nodeFalloff.inputs["Strength"].default_value = 32
nodeEmitCam.inputs["Strength"].default_value = 4
Expand All @@ -1446,7 +1451,6 @@ def matgen_cycles_principled(mat: Material, options: PrepOptions) -> Optional[bo
else:
links.new(principled.outputs[0], nodeMixTrans.inputs[2])


nodeInputs = [
[
principled.inputs["Base Color"],
Expand All @@ -1458,7 +1462,7 @@ def matgen_cycles_principled(mat: Material, options: PrepOptions) -> Optional[bo
[principled.inputs["Metallic"]],
[principled.inputs["Specular IOR Level" if util.min_bv((4, 0, 0)) else "Specular"]],
[principled.inputs["Normal"]]]

if not options.use_emission_nodes:
nodes.remove(nodeEmit)
nodes.remove(nodeEmitCam)
Expand Down Expand Up @@ -1520,16 +1524,16 @@ def matgen_cycles_original(mat: Material, options: PrepOptions):

if not image_diff:
print(f"Could not find diffuse image, halting generation: {mat.name}")
return
return NO_DIFFUSE_NODE
elif image_diff.size[0] == 0 or image_diff.size[1] == 0:
if image_diff.source != 'SEQUENCE':
# Common non animated case; this means the image is missing and would
# have already checked for replacement textures by now, so skip
return
return IMG_MISSING
if not os.path.isfile(bpy.path.abspath(image_diff.filepath)):
# can't check size or pixels as it often is not immediately avaialble
# so instea, check against firs frame of sequence to verify load
return
return IMG_MISSING

mat.use_nodes = True
animated_data = copy_texture_animation_pass_settings(mat)
Expand Down
23 changes: 18 additions & 5 deletions MCprep_addon/materials/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ def execute(self, context):
engine = context.scene.render.engine
count = 0
count_lib_skipped = 0
count_no_prep = 0
count_img_not_found = 0
count_misc_no_prep = 0

print("Orig mat list: ", len(mat_list))

for mat in mat_list:
if not mat:
Expand Down Expand Up @@ -262,6 +265,10 @@ def execute(self, context):
)
if res == 0:
count += 1
elif res == generate.IMG_MISSING:
count_img_not_found += 1
else:
count_misc_no_prep += 1
else:
self.report(
{'ERROR'},
Expand Down Expand Up @@ -296,19 +303,25 @@ def execute(self, context):

has_lib_skipped = count_lib_skipped > 0
has_mat = count > 0

has_missing = count_img_not_found > 0

info = []
if has_mat:
info.append(f"modified {count}")
if has_lib_skipped:
info.append(f"skipped {count_lib_skipped}")

mat_info = ", ".join(x for x in info).capitalize()

if self.skipUsage is True:
pass # Don't report if a meta-call.
elif has_mat or has_lib_skipped:
self.report({"INFO"}, mat_info)
self.report({"INFO"}, mat_info)
elif has_missing:
self.report(
{"ERROR"},
"Nothing modified, due missing image paths - try advanced: Find Missing Textures or File > External Data > Find Missing Files"
)
else:
self.report(
{"ERROR"},
Expand Down