Generation op will abort if diffuse texture isn't found + options for failing silently or with error message. TODO: found out how to create a pop-up panel with error message that fades away if not interacted with for a couple seconds...
This commit is contained in:
parent
45782f9a2f
commit
d359975bd6
|
@ -11,6 +11,8 @@ from bpy.props import BoolProperty, EnumProperty, StringProperty
|
||||||
from bpy.types import Operator, Menu
|
from bpy.types import Operator, Menu
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
# FillSWBFMaterialProperties
|
# FillSWBFMaterialProperties
|
||||||
|
|
||||||
|
@ -42,7 +44,8 @@ class FillSWBFMaterialProperties(bpy.types.Operator):
|
||||||
if link_node.type != 'TEX_IMAGE':
|
if link_node.type != 'TEX_IMAGE':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tex_name = link_node.image.name
|
tex_name = link_node.image.filepath
|
||||||
|
print(tex_name)
|
||||||
|
|
||||||
i = tex_name.find(".tga")
|
i = tex_name.find(".tga")
|
||||||
|
|
||||||
|
@ -97,23 +100,27 @@ to provide an exact emulation"""
|
||||||
description = "Name of material whose SWBF properties the generated nodes will emulate."
|
description = "Name of material whose SWBF properties the generated nodes will emulate."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fail_silently: BoolProperty(
|
||||||
|
name = "Fail Silently"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
|
||||||
material = bpy.data.materials[self.material_name]
|
material = bpy.data.materials[self.material_name]
|
||||||
|
|
||||||
|
|
||||||
if material and material.swbf_msh_mat:
|
if material and material.swbf_msh_mat:
|
||||||
|
|
||||||
material.use_nodes = True
|
|
||||||
mat_props = material.swbf_msh_mat
|
mat_props = material.swbf_msh_mat
|
||||||
|
|
||||||
material.node_tree.nodes.clear()
|
|
||||||
|
|
||||||
bsdf = material.node_tree.nodes.new("ShaderNodeBsdfPrincipled")
|
|
||||||
|
|
||||||
diffuse_texture_path = mat_props.diffuse_map
|
diffuse_texture_path = mat_props.diffuse_map
|
||||||
if diffuse_texture_path:
|
if diffuse_texture_path and os.path.exists(diffuse_texture_path):
|
||||||
|
|
||||||
|
material.use_nodes = True
|
||||||
|
material.node_tree.nodes.clear()
|
||||||
|
|
||||||
|
bsdf = material.node_tree.nodes.new("ShaderNodeBsdfPrincipled")
|
||||||
|
|
||||||
texImage = material.node_tree.nodes.new('ShaderNodeTexImage')
|
texImage = material.node_tree.nodes.new('ShaderNodeTexImage')
|
||||||
texImage.image = bpy.data.images.load(diffuse_texture_path)
|
texImage.image = bpy.data.images.load(diffuse_texture_path)
|
||||||
texImage.image.alpha_mode = 'CHANNEL_PACKED'
|
texImage.image.alpha_mode = 'CHANNEL_PACKED'
|
||||||
|
@ -128,9 +135,16 @@ to provide an exact emulation"""
|
||||||
|
|
||||||
material.use_backface_culling = not bool(mat_props.doublesided)
|
material.use_backface_culling = not bool(mat_props.doublesided)
|
||||||
|
|
||||||
|
output = material.node_tree.nodes.new("ShaderNodeOutputMaterial")
|
||||||
|
material.node_tree.links.new(output.inputs['Surface'], bsdf.outputs['BSDF'])
|
||||||
|
|
||||||
output = material.node_tree.nodes.new("ShaderNodeOutputMaterial")
|
else:
|
||||||
material.node_tree.links.new(output.inputs['Surface'], bsdf.outputs['BSDF'])
|
|
||||||
|
# Todo: figure out some way to raise an error but continue operator execution...
|
||||||
|
if self.fail_silently:
|
||||||
|
return {'CANCELLED'}
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"Diffuse texture at path: '{diffuse_texture_path}' was not found.")
|
||||||
|
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
|
@ -297,4 +297,5 @@ class MaterialPropertiesPanel(bpy.types.Panel):
|
||||||
|
|
||||||
op_props = layout.operator("swbf_msh.generate_material_nodes", text="Generate Nodes")
|
op_props = layout.operator("swbf_msh.generate_material_nodes", text="Generate Nodes")
|
||||||
op_props.material_name = context.material.name
|
op_props.material_name = context.material.name
|
||||||
|
op_props.fail_silently = False
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ def find_texture_path(folder_path : str, name : str) -> str:
|
||||||
if os.path.exists(possible_path):
|
if os.path.exists(possible_path):
|
||||||
return possible_path
|
return possible_path
|
||||||
|
|
||||||
return ""
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ def swbf_material_to_blend(material_name : str, material : Material, folder_path
|
||||||
|
|
||||||
fill_material_props(material, new_mat.swbf_msh_mat, folder_path)
|
fill_material_props(material, new_mat.swbf_msh_mat, folder_path)
|
||||||
|
|
||||||
bpy.ops.swbf_msh.generate_material_nodes('EXEC_DEFAULT', material_name=new_mat.name)
|
bpy.ops.swbf_msh.generate_material_nodes('EXEC_DEFAULT', material_name=new_mat.name, fail_silently=True)
|
||||||
|
|
||||||
return new_mat
|
return new_mat
|
||||||
|
|
||||||
|
@ -122,10 +122,10 @@ def _fill_material_props_texture_maps(material, material_properties, folder_path
|
||||||
t2path = find_texture_path(folder_path, material.texture2)
|
t2path = find_texture_path(folder_path, material.texture2)
|
||||||
t3path = find_texture_path(folder_path, material.texture3)
|
t3path = find_texture_path(folder_path, material.texture3)
|
||||||
|
|
||||||
material_properties.texture_0 = t0path if t0path else material.texture0
|
material_properties.texture_0 = t0path
|
||||||
material_properties.texture_1 = t1path if t1path else material.texture1
|
material_properties.texture_1 = t1path
|
||||||
material_properties.texture_2 = t2path if t2path else material.texture2
|
material_properties.texture_2 = t2path
|
||||||
material_properties.texture_3 = t3path if t3path else material.texture3
|
material_properties.texture_3 = t3path
|
||||||
|
|
||||||
material_properties.diffuse_map = t0path
|
material_properties.diffuse_map = t0path
|
||||||
material_properties.distortion_map = t1path
|
material_properties.distortion_map = t1path
|
||||||
|
|
Loading…
Reference in New Issue