1.8.4 Hotfix
This commit is contained in:
Binary file not shown.
@@ -15,7 +15,7 @@ def get_uv_layers(self, context):
|
||||
return items
|
||||
|
||||
class UVEnumProperties(bpy.types.PropertyGroup):
|
||||
uv_enum: bpy.props.EnumProperty(name="UV Map", description="Select UV-Layer", items=get_uv_layers, default=0)
|
||||
uv_enum: bpy.props.EnumProperty(name="MASK UV Map", description="Select Mask UV-Layer", items=get_uv_layers, default=0)
|
||||
|
||||
class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
"""Merges 4 Materials into one Material (Mask)"""
|
||||
@@ -26,11 +26,15 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
scene = context.scene
|
||||
ts = scene.tool_settings
|
||||
arr_obj = context.selected_objects
|
||||
activeObj = context.active_object
|
||||
|
||||
# Get all inputs from user
|
||||
selected_uv = context.scene.settings_uv_enum_props.uv_enum
|
||||
ignore_custom = context.scene.settings_multi_ignor
|
||||
island_margin_custom = context.scene.uv_island_margin_slider
|
||||
mat_nameing = context.scene.settings_mat_nameing
|
||||
island_margin_custom = context.scene.settings_uv_island_margin_slider
|
||||
|
||||
# Scale and offset for UV allignment
|
||||
SCALE = 0.5
|
||||
@@ -42,8 +46,7 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
]
|
||||
IGNORE = ["glass", "glas", "grass", "gras", "atlas"]
|
||||
if ignore_custom.strip():
|
||||
CUSTOM_IGNORE = ignore_custom.split(",")
|
||||
IGNORE.extend(CUSTOM_IGNORE)
|
||||
IGNORE.extend(ignore_custom.split(","))
|
||||
|
||||
# No Mesh selected
|
||||
if not arr_obj:
|
||||
@@ -56,7 +59,6 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
return {"CANCELLED"}
|
||||
|
||||
obj = arr_obj[0]
|
||||
selected_uv = context.scene.uv_enum_props.uv_enum
|
||||
|
||||
# UV Maps present?
|
||||
if not obj.data.uv_layers or not selected_uv:
|
||||
@@ -65,8 +67,13 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
|
||||
obj.data.uv_layers.active_index = int(selected_uv)
|
||||
|
||||
# Deactivate uv Select Sync in UV Editor. Makes Problems
|
||||
old_ts_state = ts.use_uv_select_sync
|
||||
ts.use_uv_select_sync = False
|
||||
|
||||
skip = 0
|
||||
idx_multi = None
|
||||
idx_multi_name = 1
|
||||
delete = []
|
||||
|
||||
# Loop through all Materials
|
||||
@@ -123,7 +130,8 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
mat["1. Black "] = mat.name
|
||||
|
||||
# Change name and use as base to merge
|
||||
mat.name = "Multi_" + mat.name
|
||||
mat.name = str(mat_nameing).replace("$MeshName", obj.name.replace("L1960_", "").replace("KB3D_AMC_", "")) + "_" + str(idx_multi_name)
|
||||
idx_multi_name += 1
|
||||
idx_multi = i
|
||||
self.report({'INFO'}, f'Material "{mat.name}" created.')
|
||||
continue
|
||||
@@ -162,6 +170,9 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
for i, layer in enumerate(uv_layers):
|
||||
layer.name = f"UVMap{i + 1}"
|
||||
|
||||
# Activate Select Sync in UV Editor
|
||||
ts.use_uv_select_sync = old_ts_state
|
||||
|
||||
self.report({'INFO'}, 'Merged Materials to Multitextures.')
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -190,9 +201,13 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
def put_UV_first(self, obj, target_index):
|
||||
target_index = int(target_index)
|
||||
mesh = obj.data
|
||||
uv_layers = mesh.uv_layers
|
||||
|
||||
if target_index < 0 or target_index >= len(uv_layers):
|
||||
return
|
||||
|
||||
if len(uv_layers) <= 1:
|
||||
return
|
||||
|
||||
@@ -200,7 +215,7 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
if obj.mode != 'OBJECT':
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# UV-Daten + Namen sichern
|
||||
# Backup aller UV-Layer
|
||||
uv_backup = []
|
||||
for layer in uv_layers:
|
||||
uv_backup.append({
|
||||
@@ -208,9 +223,10 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
"data": [loop.uv.copy() for loop in layer.data]
|
||||
})
|
||||
|
||||
# Neue Reihenfolge
|
||||
indices = list(range(len(uv_layers)))
|
||||
new_order = [i for i in indices if i != target_index]
|
||||
# Neue Reihenfolge: target_index zuerst
|
||||
new_order = [target_index] + [
|
||||
i for i in range(len(uv_layers)) if i != target_index
|
||||
]
|
||||
|
||||
# Alle UV-Layer löschen (rückwärts!)
|
||||
for i in range(len(uv_layers) - 1, -1, -1):
|
||||
@@ -223,5 +239,6 @@ class MESH_OT_merge_materials_to_mask(bpy.types.Operator):
|
||||
for i, uv in enumerate(info["data"]):
|
||||
new_layer.data[i].uv = uv
|
||||
|
||||
# Ersten UV-Layer aktiv setzen
|
||||
# Ersten UV-Layer aktiv & render setzen
|
||||
uv_layers.active_index = 0
|
||||
uv_layers[0].active_render = True
|
||||
@@ -83,10 +83,11 @@ class L1960_PT_dekogon(bpy.types.Panel):
|
||||
emboss=False)
|
||||
if context.scene.section2:
|
||||
row = box.row()
|
||||
props = context.scene.uv_enum_props
|
||||
row.prop(props, "uv_enum", text="Use UV")
|
||||
props = context.scene.settings_uv_enum_props
|
||||
row.prop(props, "uv_enum", text="UV Mask")
|
||||
box.prop(context.scene, "settings_multi_ignor", text="Ignore")
|
||||
box.prop(context.scene, "uv_island_margin_slider", text="Island Margin")
|
||||
box.prop(context.scene, "settings_mat_nameing", text="Naming")
|
||||
box.prop(context.scene, "settings_uv_island_margin_slider", text="Island Margin")
|
||||
|
||||
class L1960_PT_tools(bpy.types.Panel):
|
||||
#where to add the panel
|
||||
@@ -194,9 +195,10 @@ def register():
|
||||
bpy.types.Scene.dekogon_settings_prefix = bpy.props.StringProperty(name="Prefix", default="TX")
|
||||
bpy.types.Scene.dekogon_settings_suffix = bpy.props.StringProperty(name="Suffix", default="ALB")
|
||||
bpy.types.Scene.dekogon_settings_filetype = bpy.props.StringProperty(name="File Type", default="tga")
|
||||
bpy.types.Scene.settings_multi_ignor = bpy.props.StringProperty(name="Ignore", default="", description="Ignore material when string is in name (split by comma)")
|
||||
bpy.types.Scene.uv_enum_props = bpy.props.PointerProperty(type=UVEnumProperties)
|
||||
bpy.types.Scene.uv_island_margin_slider = bpy.props.FloatProperty(name="Island Margin", default=0.02, min=0.01, max=0.1)
|
||||
bpy.types.Scene.settings_mat_nameing = bpy.props.StringProperty(name="Naming", default="Multi_$MeshName", description="Naming for new multi materials, use $MeshName as placeholder")
|
||||
bpy.types.Scene.settings_multi_ignor = bpy.props.StringProperty(name="Ignore", default="", description="Ignore material when string is in name (split by comma) | Default: grass, glass, atlas")
|
||||
bpy.types.Scene.settings_uv_enum_props = bpy.props.PointerProperty(type=UVEnumProperties)
|
||||
bpy.types.Scene.settings_uv_island_margin_slider = bpy.props.FloatProperty(name="Island Margin", default=0.02, min=0.01, max=0.1)
|
||||
|
||||
def unregister():
|
||||
for mod in modules:
|
||||
@@ -211,9 +213,10 @@ def unregister():
|
||||
del bpy.types.Scene.dekogon_settings_prefix
|
||||
del bpy.types.Scene.dekogon_settings_suffix
|
||||
del bpy.types.Scene.dekogon_settings_filetype
|
||||
del bpy.types.Scene.settings_mat_nameing
|
||||
del bpy.types.Scene.settings_multi_ignor
|
||||
del bpy.types.Scene.uv_enum_props
|
||||
del bpy.types.Scene.uv_island_margin_slider
|
||||
del bpy.types.Scene.settings_uv_enum_props
|
||||
del bpy.types.Scene.settings_uv_island_margin_slider
|
||||
|
||||
if __name__== "__main__":
|
||||
register()
|
||||
Reference in New Issue
Block a user