Reorg + use generation operator when initially creating Blender materials + make all texture fields in SWBF materials properties paths

This commit is contained in:
William Herald Snyder
2022-09-28 08:47:43 -04:00
parent 8974131550
commit 9bd8479e31
5 changed files with 173 additions and 179 deletions

View File

@@ -63,8 +63,8 @@ from .msh_material_properties import *
from .msh_skeleton_properties import *
from .msh_collision_prim_properties import *
from .msh_to_blend import *
from .msh_material_operators import *
from .zaa_to_blend import *
from .material_props_to_nodes_op import GenerateMaterialFromSWBFProperties
class ExportMSH(Operator, ExportHelper):
@@ -203,63 +203,6 @@ def menu_func_import(self, context):
class FillSWBFMaterialProperties(bpy.types.Operator):
bl_idname = "swbf_msh.fill_mat_props"
bl_label = "Fill SWBF Material Properties"
bl_description = ("Fill in SWBF properties of all materials used by selected objects.\n"
"Only considers materials that use nodes.\n"
"Please see 'Materials > Materials Operators' in the docs for more details.")
def execute(self, context):
slots = sum([list(ob.material_slots) for ob in bpy.context.selected_objects if ob.type == 'MESH'],[])
mats = [slot.material for slot in slots if (slot.material and slot.material.node_tree)]
for mat in mats:
try:
for BSDF_node in [n for n in mat.node_tree.nodes if n.type == 'BSDF_PRINCIPLED']:
base_col = BSDF_node.inputs['Base Color']
for link in base_col.links :
link_node = link.from_node
if link_node.type != 'TEX_IMAGE':
continue
tex_name = link_node.image.name
i = tex_name.find(".tga")
# Get rid of trailing number in case one is present
if i > 0:
tex_name = tex_name[0:i+4]
mat.swbf_msh_mat.rendertype = 'NORMAL_BF2'
mat.swbf_msh_mat.diffuse_map = tex_name
break
except:
# Many chances for null ref exceptions. None if user reads doc section...
pass
return {'FINISHED'}
class VIEW3D_MT_SWBF(bpy.types.Menu):
bl_label = "SWBF"
def draw(self, _context):
layout = self.layout
layout.operator("swbf_msh.fill_mat_props", text="Fill SWBF Material Properties")
def draw_matfill_menu(self, context):
layout = self.layout
layout.separator()
layout.menu("VIEW3D_MT_SWBF")
def register():
bpy.utils.register_class(CollisionPrimitiveProperties)
@@ -283,7 +226,7 @@ def register():
bpy.utils.register_class(VIEW3D_MT_SWBF)
bpy.types.VIEW3D_MT_object_context_menu.append(draw_matfill_menu)
bpy.utils.register_class(GenerateMaterialFromSWBFProperties)
bpy.utils.register_class(GenerateMaterialNodesFromSWBFProperties)
@@ -307,7 +250,7 @@ def unregister():
bpy.utils.unregister_class(VIEW3D_MT_SWBF)
bpy.types.VIEW3D_MT_object_context_menu.remove(draw_matfill_menu)
bpy.utils.unregister_class(GenerateMaterialFromSWBFProperties)
bpy.utils.unregister_class(GenerateMaterialNodesFromSWBFProperties)