1.7.0
Automated MLOD optimized material fix
This commit is contained in:
BIN
Blender/_Release/L1960_Tools_1_7_0.zip
Normal file
BIN
Blender/_Release/L1960_Tools_1_7_0.zip
Normal file
Binary file not shown.
BIN
Blender/_Source/L1960_Tools_1_7_0/ColorPalette_01.png
Normal file
BIN
Blender/_Source/L1960_Tools_1_7_0/ColorPalette_01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
Blender/_Source/L1960_Tools_1_7_0/ColorPalette_02.png
Normal file
BIN
Blender/_Source/L1960_Tools_1_7_0/ColorPalette_02.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
94
Blender/_Source/L1960_Tools_1_7_0/CubeProjection.py
Normal file
94
Blender/_Source/L1960_Tools_1_7_0/CubeProjection.py
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import bpy
|
||||||
|
from math import pi
|
||||||
|
|
||||||
|
L1960_Arr_PlainData = [
|
||||||
|
["Proj_Empty_01", (0, 0, 2), (0, 0, 0)],
|
||||||
|
["Proj_Empty_02", (2, 0, 0), ((pi * 90 / 180), 0, (pi * 90 / 180))],
|
||||||
|
["Proj_Empty_03", (0, 2, 0), ((pi * 90 / 180), 0, (pi * 180 / 180))],
|
||||||
|
["Proj_Empty_04", (0, 0, -2), ((pi * 180 / 180), 0, 0)],
|
||||||
|
["Proj_Empty_05", (-2, 0, 0), ((pi * 90 / 180), 0, (pi * -90 / 180))],
|
||||||
|
["Proj_Empty_06", (0, -2, 0), ((pi * 90 / 180), 0, 0)]
|
||||||
|
]
|
||||||
|
|
||||||
|
class MESH_OT_add_auto_cube_projection(bpy.types.Operator):
|
||||||
|
"""Check Empty´s for projecting, if not existing create new one´s"""
|
||||||
|
|
||||||
|
bl_idname = "mesh.add_auto_cube_projection"
|
||||||
|
bl_label = "Add Plain_Axes to scene"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
scene = bpy.context.scene
|
||||||
|
oldSelection = bpy.context.selected_objects
|
||||||
|
oldActive = bpy.context.active_object
|
||||||
|
|
||||||
|
for EmptyData in L1960_Arr_PlainData:
|
||||||
|
|
||||||
|
EmptyName = EmptyData[0]
|
||||||
|
EmptyLocation = EmptyData[1]
|
||||||
|
EmptyRotation = EmptyData[2]
|
||||||
|
|
||||||
|
if not scene.objects.get(EmptyName):
|
||||||
|
bpy.ops.object.empty_add(type='PLAIN_AXES', align='WORLD', location=EmptyLocation, scale=(1, 1, 1), rotation=EmptyRotation)
|
||||||
|
empty = bpy.context.active_object
|
||||||
|
empty.name = EmptyName
|
||||||
|
empty.hide_select = True
|
||||||
|
empty.hide_set(True)
|
||||||
|
|
||||||
|
#Change back to old selection and select old active
|
||||||
|
for obj in oldSelection:
|
||||||
|
obj.select_set(True)
|
||||||
|
bpy.context.view_layer.objects.active = oldActive
|
||||||
|
|
||||||
|
self.report({'INFO'}, 'Added/Fixed Emptys for Projection to Scene')
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
class MESH_OT_add_modifier_to_mesh(bpy.types.Operator):
|
||||||
|
"""Add Modifier to selected Mesh´s and prepare UV-Maps"""
|
||||||
|
|
||||||
|
bl_idname = "mesh.add_modifier_to_mesh"
|
||||||
|
bl_label = "Add Modifier to selected Mesh"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
newModifierName = "CubeTexModifier"
|
||||||
|
Arr_obj = bpy.context.selected_objects
|
||||||
|
if len(Arr_obj) < 1:
|
||||||
|
self.report({'WARNING'}, 'Select a mesh to add the UVProject-Modifier')
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
empty_objs = [emp_obj for emp_obj in bpy.context.scene.objects if emp_obj.name.startswith("Proj_Empty")]
|
||||||
|
if len(empty_objs) < 6:
|
||||||
|
self.report({'WARNING'}, 'Create/Recreate projectors, they need to be set up first!')
|
||||||
|
return {"CANCELLED"};
|
||||||
|
|
||||||
|
for obj in Arr_obj:
|
||||||
|
|
||||||
|
if obj.data.uv_layers.get("UVMap"):
|
||||||
|
obj.data.uv_layers['UVMap'].name = 'UVMap0'
|
||||||
|
|
||||||
|
if not obj.data.uv_layers.get("UVMap0"):
|
||||||
|
obj.data.uv_layers.new(name = 'UVMap0')
|
||||||
|
|
||||||
|
if not obj.data.uv_layers.get("UVMap1"):
|
||||||
|
obj.data.uv_layers.new(name = 'UVMap1')
|
||||||
|
|
||||||
|
|
||||||
|
if obj.type == "MESH" and newModifierName not in obj.modifiers:
|
||||||
|
obj.modifiers.new(type='UV_PROJECT', name=newModifierName)
|
||||||
|
mod = obj.modifiers[newModifierName]
|
||||||
|
mod.uv_layer = "UVMap1"
|
||||||
|
mod.projector_count = 6
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
for p in mod.projectors:
|
||||||
|
p.object = bpy.data.objects[L1960_Arr_PlainData[i][0]]
|
||||||
|
i = i+1
|
||||||
|
else:
|
||||||
|
self.report({'INFO'}, 'UVProject-Modifier allready set')
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
self.report({'INFO'}, 'Added UVProject-Modifier to mesh')
|
||||||
|
return {"FINISHED"}
|
||||||
48
Blender/_Source/L1960_Tools_1_7_0/Materials.py
Normal file
48
Blender/_Source/L1960_Tools_1_7_0/Materials.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import bpy
|
||||||
|
|
||||||
|
class MESH_OT_fix_material_names(bpy.types.Operator):
|
||||||
|
"""Fixes the material naming, if duplicated are present e.g. Material.001, Material.002 ..."""
|
||||||
|
|
||||||
|
bl_idname = "mesh.fix_material_names"
|
||||||
|
bl_label = "Fixes the material naming, if duplicated are present"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
#Remove all duplicated materials
|
||||||
|
self.merge_duplicated_materials()
|
||||||
|
|
||||||
|
#Merge material slots for every mesh in the scene
|
||||||
|
#for obj in bpy.context.scene.objects:
|
||||||
|
#if obj.type == "MESH":
|
||||||
|
#self.merge_material_slots(obj)
|
||||||
|
|
||||||
|
self.report({'INFO'}, 'All duplicated Materials fixed')
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def merge_duplicated_materials(self):
|
||||||
|
for material in bpy.data.materials:
|
||||||
|
if material.name[-3].isnumeric():
|
||||||
|
opti_matName = material.name[:-4]
|
||||||
|
if bpy.data.materials.get(opti_matName): #check if og_mat exists
|
||||||
|
material.user_remap(bpy.data.materials.get(opti_matName))
|
||||||
|
print("Removed Material: " + material.name)
|
||||||
|
bpy.data.materials.remove(material)
|
||||||
|
else:
|
||||||
|
material.name = opti_matName
|
||||||
|
|
||||||
|
def merge_material_slots(self, obj):
|
||||||
|
duplicated_material_list = []
|
||||||
|
|
||||||
|
#create list with indexes of material slots with the same name
|
||||||
|
for og_slot in obj.material_slots:
|
||||||
|
for slot in obj.material_slots:
|
||||||
|
if slot.name == og_slot.name:
|
||||||
|
if slot.slot_index == og_slot.slot_index:
|
||||||
|
continue
|
||||||
|
if og_slot.slot_index in duplicated_material_list:
|
||||||
|
continue
|
||||||
|
duplicated_material_list.append(int(slot.slot_index))
|
||||||
|
|
||||||
|
#delete all material slots within list
|
||||||
|
for slot_index in sorted(duplicated_material_list, reverse=True):
|
||||||
|
obj.data.materials.pop(index = slot_index)
|
||||||
128
Blender/_Source/L1960_Tools_1_7_0/PrepareLods.py
Normal file
128
Blender/_Source/L1960_Tools_1_7_0/PrepareLods.py
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
import bpy
|
||||||
|
import os
|
||||||
|
|
||||||
|
### GENRATE MLOD ###
|
||||||
|
|
||||||
|
plugin_dir = bpy.utils.user_resource('SCRIPTS')
|
||||||
|
plugin_path = "addons\L1960Tools"
|
||||||
|
|
||||||
|
L1960_path = os.path.join(plugin_dir, plugin_path)
|
||||||
|
colorpalettes = [
|
||||||
|
"ColorPalette_01.png",
|
||||||
|
"ColorPalette_02.png"
|
||||||
|
]
|
||||||
|
|
||||||
|
enum_palettes = []
|
||||||
|
for file in colorpalettes:
|
||||||
|
enum_palettes.append((file, file[:-4], "Select " + file[:-4] + " for MLOD"))
|
||||||
|
|
||||||
|
class EnumColorPalettes(bpy.types.PropertyGroup):
|
||||||
|
mlod_enum_selection: bpy.props.EnumProperty(
|
||||||
|
name="Color Palettes for MLOD",
|
||||||
|
items=enum_palettes,
|
||||||
|
description="Choose a palette",
|
||||||
|
default=0
|
||||||
|
)
|
||||||
|
|
||||||
|
class MESH_OT_set_up_mlod(bpy.types.Operator):
|
||||||
|
"""Set´s up a material to be used for MLOD´s"""
|
||||||
|
|
||||||
|
bl_idname = "mesh.set_up_mlod"
|
||||||
|
bl_label = "Set´s up a material to be used for MLOD´s"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
#Load Color Palettes
|
||||||
|
self.import_palettes_textures()
|
||||||
|
|
||||||
|
#Selected Mesh
|
||||||
|
obj = bpy.context.active_object
|
||||||
|
|
||||||
|
if obj not in bpy.context.selected_objects or obj.type != "MESH":
|
||||||
|
self.report({'WARNING'}, 'Select a Mesh to continue')
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
arr_layers = obj.data.uv_layers
|
||||||
|
if not arr_layers.get("MLOD") or len(arr_layers) > 1:
|
||||||
|
for uv_layer in reversed(arr_layers):
|
||||||
|
arr_layers.remove(uv_layer)
|
||||||
|
arr_layers.new(name = 'MLOD')
|
||||||
|
|
||||||
|
|
||||||
|
texture_filepath = os.path.join(L1960_path, colorpalettes[1])
|
||||||
|
|
||||||
|
if not len(obj.data.materials) == 0:
|
||||||
|
obj.data.materials.clear()
|
||||||
|
|
||||||
|
palette_enum_selection = context.scene.color_palettes.mlod_enum_selection
|
||||||
|
mlod_material_name = "MLOD_" + palette_enum_selection[:-4]
|
||||||
|
|
||||||
|
if not bpy.data.materials.get(mlod_material_name):
|
||||||
|
material = bpy.data.materials.new(name=mlod_material_name)
|
||||||
|
material.use_nodes = True
|
||||||
|
bsdf_node = material.node_tree.nodes["Principled BSDF"]
|
||||||
|
texImage = material.node_tree.nodes.new('ShaderNodeTexImage')
|
||||||
|
texImage.image = bpy.data.images.get(palette_enum_selection)
|
||||||
|
|
||||||
|
material.node_tree.links.new(bsdf_node.inputs['Base Color'], texImage.outputs['Color'])
|
||||||
|
|
||||||
|
obj.data.materials.append(bpy.data.materials.get(mlod_material_name))
|
||||||
|
|
||||||
|
|
||||||
|
self.report({'INFO'}, 'Mesh configured like MLOD')
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def import_palettes_textures(self):
|
||||||
|
for image_name in colorpalettes:
|
||||||
|
texture_name = image_name.split(".")[0]
|
||||||
|
if texture_name not in bpy.data.textures:
|
||||||
|
texture = bpy.data.textures.new(name=texture_name, type='IMAGE')
|
||||||
|
else:
|
||||||
|
texture = bpy.data.textures.get(texture_name)
|
||||||
|
if image_name not in bpy.data.images:
|
||||||
|
image = bpy.data.images.load(os.path.join(L1960_path, image_name))
|
||||||
|
else:
|
||||||
|
image = bpy.data.images.get(image_name)
|
||||||
|
texture.image = image
|
||||||
|
|
||||||
|
### PREPARE LODS ###
|
||||||
|
|
||||||
|
class MESH_OT_prepare_lods_decimate(bpy.types.Operator):
|
||||||
|
"""Copy current Mesh and apply decimate Modifier"""
|
||||||
|
|
||||||
|
bl_idname = "mesh.prepare_lods_decimate"
|
||||||
|
bl_label = "Copy current Mesh and apply decimate Modifier"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
|
||||||
|
#Selected Mesh
|
||||||
|
obj = bpy.context.active_object
|
||||||
|
|
||||||
|
if obj not in bpy.context.selected_objects or obj.type != "MESH":
|
||||||
|
self.report({'WARNING'}, 'Select a Mesh to continue')
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
if not obj.name[:-1].endswith('LOD'):
|
||||||
|
obj.name = obj.name + '_LOD0'
|
||||||
|
|
||||||
|
LODnumber = context.scene.lod_slider #Get from Slider
|
||||||
|
startLODcount = int(obj.name[-1])
|
||||||
|
endLODcount = startLODcount + LODnumber
|
||||||
|
|
||||||
|
for i in range (startLODcount + 1, endLODcount):
|
||||||
|
new_obj = obj.copy()
|
||||||
|
new_obj.data = obj.data.copy()
|
||||||
|
new_obj.name = obj.name[:-1] + str(i)
|
||||||
|
bpy.context.collection.objects.link(new_obj)
|
||||||
|
|
||||||
|
for t in range (startLODcount, i):
|
||||||
|
newModifierName = 'LOD_Decimate_' + str(t)
|
||||||
|
new_obj.modifiers.new(type='DECIMATE', name=newModifierName)
|
||||||
|
mod = new_obj.modifiers[newModifierName]
|
||||||
|
mod.ratio = 0.49
|
||||||
|
mod.use_collapse_triangulate = True
|
||||||
|
|
||||||
|
self.report({'INFO'}, 'LOD´s created')
|
||||||
|
return {"FINISHED"}
|
||||||
113
Blender/_Source/L1960_Tools_1_7_0/__init__.py
Normal file
113
Blender/_Source/L1960_Tools_1_7_0/__init__.py
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
bl_info = {
|
||||||
|
"name": "L1960 Tools",
|
||||||
|
"author": "Prodeath21",
|
||||||
|
"version": (1, 7, 0),
|
||||||
|
"blender": (2, 80, 0),
|
||||||
|
"location": "3D Viewport > Sidebar > 1960Life category",
|
||||||
|
"description": "Set´s up the Projection-Modifier automatically and add´s in the Emptys if not allready created.",
|
||||||
|
"category": "Object",
|
||||||
|
}
|
||||||
|
|
||||||
|
# ----------------------------------------------
|
||||||
|
# Import modules
|
||||||
|
# ----------------------------------------------
|
||||||
|
if "bpy" in locals():
|
||||||
|
import imp
|
||||||
|
imp.reload(CubeProjection)
|
||||||
|
imp.reload(Materials)
|
||||||
|
imp.reload(PrepareLods)
|
||||||
|
print("L1960 Tools: Reloaded multifiles")
|
||||||
|
else:
|
||||||
|
from . import CubeProjection
|
||||||
|
from . import Materials
|
||||||
|
from . import PrepareLods
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
from . CubeProjection import MESH_OT_add_auto_cube_projection, MESH_OT_add_modifier_to_mesh
|
||||||
|
from . Materials import MESH_OT_fix_material_names
|
||||||
|
from . PrepareLods import MESH_OT_prepare_lods_decimate, MESH_OT_set_up_mlod, EnumColorPalettes
|
||||||
|
|
||||||
|
class L1960_PT_tools(bpy.types.Panel):
|
||||||
|
pass
|
||||||
|
#where to add the panel
|
||||||
|
bl_space_type = "VIEW_3D"
|
||||||
|
bl_region_type = "UI"
|
||||||
|
|
||||||
|
#add labels
|
||||||
|
bl_label = "1960-Life Tools"
|
||||||
|
bl_category = "1960-Life"
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
"""define the layout of the panel"""
|
||||||
|
box = self.layout.box()
|
||||||
|
# UV-Project helper
|
||||||
|
box.label(text="UV-Projection")
|
||||||
|
row = box.row()
|
||||||
|
row.operator("mesh.add_auto_cube_projection", text="Set up Projectors")
|
||||||
|
row = box.row()
|
||||||
|
row.operator("mesh.add_modifier_to_mesh", text="Add Modifier to Mesh")
|
||||||
|
self.layout.separator()
|
||||||
|
# Materials helper
|
||||||
|
box = self.layout.box()
|
||||||
|
box.label(text="Materials")
|
||||||
|
row = box.row()
|
||||||
|
row.operator("mesh.fix_material_names", text="Fix Material Name´s")
|
||||||
|
self.layout.separator()
|
||||||
|
# Generate LODs
|
||||||
|
box = self.layout.box()
|
||||||
|
box.label(text="LOD´s")
|
||||||
|
row = box.row()
|
||||||
|
row.operator("mesh.prepare_lods_decimate", text="Create LOD´s")
|
||||||
|
box.prop(context.scene, "lod_slider", text="Amount")
|
||||||
|
box = self.layout.box()
|
||||||
|
box.prop(context.scene.color_palettes, "mlod_enum_selection", expand=True)
|
||||||
|
row = box.row()
|
||||||
|
row.operator("mesh.set_up_mlod", text="Set up MLOD")
|
||||||
|
self.layout.separator()
|
||||||
|
###############################
|
||||||
|
# Enfusion Blender Tools Linked
|
||||||
|
box = self.layout.box()
|
||||||
|
box.label(text="EBT Linked")
|
||||||
|
row = box.row()
|
||||||
|
row.operator("view3d.ebt_sort", text="Sort Objects")
|
||||||
|
# colliders setup is allowed in both OBJECT and EDIT mode
|
||||||
|
row = box.row()
|
||||||
|
row.operator("view3d.ebt_colliders_setup", text=" Colliders Setup")
|
||||||
|
row = box.row()
|
||||||
|
# Light Setup
|
||||||
|
row.operator("view3d.ebt_setup_light", text=" Light Setup")
|
||||||
|
row = box.row()
|
||||||
|
col = row.column(align=True)
|
||||||
|
# Update Materials
|
||||||
|
col.operator("scene.ebt_update_enf_materials",)
|
||||||
|
row = box.row()
|
||||||
|
col = row.column(align=True)
|
||||||
|
|
||||||
|
|
||||||
|
#register the panel with blender
|
||||||
|
modules = [ L1960_PT_tools,
|
||||||
|
MESH_OT_add_auto_cube_projection,
|
||||||
|
MESH_OT_add_modifier_to_mesh,
|
||||||
|
MESH_OT_fix_material_names,
|
||||||
|
MESH_OT_prepare_lods_decimate,
|
||||||
|
MESH_OT_set_up_mlod,
|
||||||
|
EnumColorPalettes
|
||||||
|
]
|
||||||
|
|
||||||
|
def register():
|
||||||
|
for mod in modules:
|
||||||
|
bpy.utils.register_class(mod)
|
||||||
|
|
||||||
|
bpy.types.Scene.lod_slider = bpy.props.IntProperty(name="LOD Number", default=3, min=0, max=10)
|
||||||
|
bpy.types.Scene.color_palettes = bpy.props.PointerProperty(type=EnumColorPalettes)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
for mod in modules:
|
||||||
|
bpy.utils.unregister_class(mod)
|
||||||
|
|
||||||
|
del bpy.types.Scene.lod_slider
|
||||||
|
del bpy.types.Scene.color_palettes
|
||||||
|
|
||||||
|
if __name__== "__main__":
|
||||||
|
register()
|
||||||
Reference in New Issue
Block a user