diff --git a/MCprep_addon/materials/generate.py b/MCprep_addon/materials/generate.py index 9dfc6073..5dc54375 100644 --- a/MCprep_addon/materials/generate.py +++ b/MCprep_addon/materials/generate.py @@ -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 @@ -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) @@ -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) @@ -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 @@ -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( @@ -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 @@ -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"], @@ -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) @@ -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) diff --git a/MCprep_addon/materials/prep.py b/MCprep_addon/materials/prep.py index 7fb48522..1d29993c 100644 --- a/MCprep_addon/materials/prep.py +++ b/MCprep_addon/materials/prep.py @@ -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: @@ -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'}, @@ -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"},