mirror of
https://github.com/Squareville/lu-toolbox.git
synced 2026-02-15 01:05:23 -06:00
Compare commits
11 Commits
v2.0-alpha
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd02e3240e | ||
|
|
bbdfafc2b6 | ||
| 473879e900 | |||
|
|
5c0c04e4a0 | ||
| 9a9b5fe58e | |||
|
|
f9ce932bed | ||
|
|
1b3f6672e9 | ||
|
|
7a9a8e2cbb | ||
|
|
61ba3c69dd | ||
|
|
88e6159f40 | ||
| 6ac59d4be3 |
@@ -1,4 +1,4 @@
|
|||||||
[](https://download.blender.org/release/Blender2.93/)
|
[](https://download.blender.org/release/Blender3.1/)
|
||||||
[](https://github.com/30350n/lu-toolbox/blob/master/LICENSE)
|
[](https://github.com/30350n/lu-toolbox/blob/master/LICENSE)
|
||||||
# LEGO Universe Toolbox
|
# LEGO Universe Toolbox
|
||||||
A Blender Add-on which adds a bunch of useful tools to prepare models for use in LEGO Universe.
|
A Blender Add-on which adds a bunch of useful tools to prepare models for use in LEGO Universe.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "LU Toolbox",
|
"name": "LU Toolbox",
|
||||||
"author": "Bobbe",
|
"author": "Bobbe",
|
||||||
"version": (2, 0, 0),
|
"version": (2, 4, 0),
|
||||||
"blender": (2, 93, 0),
|
"blender": (2, 93, 0),
|
||||||
"location": "3D View -> Sidebar -> LU Toolbox",
|
"location": "3D View -> Sidebar -> LU Toolbox",
|
||||||
"category": "Import-Export",
|
"category": "Import-Export",
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ class LUTB_OT_setup_icon_render(bpy.types.Operator):
|
|||||||
return context.mode == "OBJECT"
|
return context.mode == "OBJECT"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
# we will only increase the sample count for rendering if we need to (currently only if there are any transparent pieces) - jamie
|
||||||
|
increase_samples = False
|
||||||
|
|
||||||
scene = context.scene
|
scene = context.scene
|
||||||
|
|
||||||
for collection in scene.collection.children:
|
for collection in scene.collection.children:
|
||||||
@@ -112,8 +115,18 @@ class LUTB_OT_setup_icon_render(bpy.types.Operator):
|
|||||||
name = material.name.rsplit(".", 1)[0]
|
name = material.name.rsplit(".", 1)[0]
|
||||||
if name in MATERIALS_OPAQUE:
|
if name in MATERIALS_OPAQUE:
|
||||||
mesh.materials[i] = get_lutb_ir_opaque_mat(self)
|
mesh.materials[i] = get_lutb_ir_opaque_mat(self)
|
||||||
|
# another hack to change a material setting, for the same reasons as the comment below...
|
||||||
|
# anyway, it was deemed that having this enabled was making the plastic look too soft and washed-out in many scenarios - jamie
|
||||||
|
if mesh.materials[i].node_tree:
|
||||||
|
for node in mesh.materials[i].node_tree.nodes:
|
||||||
|
if node.type == "BSDF_PRINCIPLED":
|
||||||
|
node.inputs["Subsurface"].default_value = 0
|
||||||
elif name in MATERIALS_TRANSPARENT:
|
elif name in MATERIALS_TRANSPARENT:
|
||||||
mesh.materials[i] = get_lutb_ir_transparent_mat(self)
|
mesh.materials[i] = get_lutb_ir_transparent_mat(self)
|
||||||
|
# next two lines are a silly hacky fix cause i dont wanna mess with the magical mystery box that is resources.blend, and hollis didnt know why it was broken anyway - jamie
|
||||||
|
mesh.materials[i].blend_method = "HASHED"
|
||||||
|
mesh.materials[i].shadow_method = "HASHED"
|
||||||
|
increase_samples = True
|
||||||
elif name in MATERIALS_METALLIC:
|
elif name in MATERIALS_METALLIC:
|
||||||
mesh.materials[i] = get_lutb_ir_metal_mat(self)
|
mesh.materials[i] = get_lutb_ir_metal_mat(self)
|
||||||
|
|
||||||
@@ -147,6 +160,9 @@ class LUTB_OT_setup_icon_render(bpy.types.Operator):
|
|||||||
if area.type == "VIEW_3D":
|
if area.type == "VIEW_3D":
|
||||||
area.spaces[0].shading.type = "RENDERED"
|
area.spaces[0].shading.type = "RENDERED"
|
||||||
|
|
||||||
|
if increase_samples:
|
||||||
|
bpy.context.scene.eevee.taa_render_samples = 1024
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
class LUTB_PT_icon_render(bpy.types.Panel):
|
class LUTB_PT_icon_render(bpy.types.Panel):
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ LUTB_IR_MATS = (LUTB_IR_OPAQUE_MAT, LUTB_IR_TRANSPARENT_MAT, LUTB_IR_METAL_MAT)
|
|||||||
|
|
||||||
LUTB_IR_SCENE = "ItemRender"
|
LUTB_IR_SCENE = "ItemRender"
|
||||||
|
|
||||||
|
# COLORS HERE ARE EXPECTED TO BE IN LINEAR COLOR SPACE
|
||||||
|
# IF YOU INPUT AN SRGB COLOR LIKE LU/LDD USE IT MUST BE CONVERTED TO LINEAR EITHER MANUALLY OR BY CALLING SRGB2LIN AS YOU WILL OCCASIONALLY SEE BELOW
|
||||||
|
# SIGNED, JAMIE (WHO WAS A SMIDGE ANNOYED AT THIS BUT ULTIMATELY PASSES NO JUDGEMENT ON THE AUTHORS OF THIS TOOL)
|
||||||
|
|
||||||
# Solid/Opaque
|
# Solid/Opaque
|
||||||
MATERIALS_OPAQUE = {
|
MATERIALS_OPAQUE = {
|
||||||
"1" : (0.904661, 0.904661, 0.904661, 1.0),
|
"1" : (0.904661, 0.904661, 0.904661, 1.0),
|
||||||
@@ -122,21 +126,21 @@ MATERIALS_OPAQUE["325"] = MATERIALS_OPAQUE["222"]
|
|||||||
|
|
||||||
# Transparent
|
# Transparent
|
||||||
MATERIALS_TRANSPARENT = {
|
MATERIALS_TRANSPARENT = {
|
||||||
"20" : (0.930111, 0.672443, 0.250158, 1.0),
|
"20" : (0.930111, 0.672443, 0.250158, 1.0),
|
||||||
"40" : (0.854993, 0.854993, 0.854993, 1.0),
|
"40" : (0.854993, 0.854993, 0.854993, 1.0),
|
||||||
"41" : (0.745405, 0.023153, 0.022174, 1.0),
|
"41" : srgb2lin((0.674509, 0.0, 0.0, 1.0)),
|
||||||
"42" : (0.244106, 0.720966, 0.772058, 1.0),
|
"42" : srgb2lin((0.244106, 0.720966, 0.772058, 1.0)),
|
||||||
"43" : (0.031372, 0.285668, 0.643137, 1.0),
|
"43" : srgb2lin((0.031372, 0.285668, 0.643137, 1.0)),
|
||||||
"44" : (0.947307, 0.863157, 0.141263, 1.0),
|
"44" : srgb2lin((0.858, 0.771375, 0.0, 1.0)),
|
||||||
"47" : (0.791298, 0.132868, 0.059511, 1.0),
|
"47" : srgb2lin((0.986, 0.336526, 0.120035, 1.0)),
|
||||||
"48" : (0.0, 0.391, 0.0, 1.0),
|
"48" : srgb2lin((0.0, 0.391, 0.0, 1.0)),
|
||||||
"49" : (0.697, 1.0, 0.0, 1.0),
|
"49" : srgb2lin((0.697, 1.0, 0.0, 1.0)),
|
||||||
"111" : (0.496933, 0.445201, 0.341914, 1.0),
|
"111" : srgb2lin((0.741177, 0.670588, 0.639216, 1.0)),
|
||||||
"113" : (0.754717, 0.060520, 0.541647, 1.0),
|
"113" : srgb2lin((0.754717, 0.060520, 0.541647, 1.0)),
|
||||||
"126" : (0.113399, 0.034649, 0.504, 1.0),
|
"126" : srgb2lin((0.267974, 0.196078, 0.627451, 1.0)),
|
||||||
"143" : (0.218464, 0.484717, 0.809, 1.0),
|
"143" : srgb2lin((0.325985, 0.551358, 0.821, 1.0)),
|
||||||
"182" : (0.8388, 0.181164, 0.004391, 1.0),
|
"182" : srgb2lin((0.913726, 0.524575, 0.0156863, 1.0)),
|
||||||
"311" : (0.42869, 0.64448, 0.061246, 1.0),
|
"311" : srgb2lin((0.454640, 0.788235, 0.0980392, 1.0)),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Duplicate Transparent
|
# Duplicate Transparent
|
||||||
|
|||||||
@@ -75,12 +75,15 @@ class LUTB_OT_process_model(bpy.types.Operator):
|
|||||||
if not scene.lutb_keep_uvs:
|
if not scene.lutb_keep_uvs:
|
||||||
self.clear_uvs(all_objects)
|
self.clear_uvs(all_objects)
|
||||||
|
|
||||||
|
if scene.lutb_reset_orientation:
|
||||||
|
self.reset_orientation(all_objects)
|
||||||
|
|
||||||
if scene.lutb_apply_vertex_colors:
|
if scene.lutb_apply_vertex_colors:
|
||||||
if scene.lutb_correct_colors:
|
if scene.lutb_correct_colors:
|
||||||
self.correct_colors(context, all_objects)
|
self.correct_colors(context, all_objects)
|
||||||
|
|
||||||
if scene.lutb_use_color_variation:
|
if scene.lutb_use_color_variation:
|
||||||
self.apply_color_variation(context, all_objects)
|
self.apply_color_variation(context, scene.collection.children)
|
||||||
|
|
||||||
self.apply_vertex_colors(context, all_objects)
|
self.apply_vertex_colors(context, all_objects)
|
||||||
|
|
||||||
@@ -117,6 +120,15 @@ class LUTB_OT_process_model(bpy.types.Operator):
|
|||||||
for uv_layer in reversed(obj.data.uv_layers):
|
for uv_layer in reversed(obj.data.uv_layers):
|
||||||
obj.data.uv_layers.remove(uv_layer)
|
obj.data.uv_layers.remove(uv_layer)
|
||||||
|
|
||||||
|
def reset_orientation(self, objects):
|
||||||
|
for obj in objects:
|
||||||
|
obj.select_set(True)
|
||||||
|
bpy.ops.object.transform_apply()
|
||||||
|
obj.rotation_euler = (radians(-90), 0, 0)
|
||||||
|
bpy.ops.object.transform_apply()
|
||||||
|
obj.rotation_euler = (radians(90), 0, 0)
|
||||||
|
obj.select_set(False)
|
||||||
|
|
||||||
def combine_objects(self, context, collections):
|
def combine_objects(self, context, collections):
|
||||||
scene = context.scene
|
scene = context.scene
|
||||||
|
|
||||||
@@ -168,19 +180,25 @@ class LUTB_OT_process_model(bpy.types.Operator):
|
|||||||
elif color := MATERIALS_TRANSPARENT.get(name):
|
elif color := MATERIALS_TRANSPARENT.get(name):
|
||||||
material.diffuse_color = color
|
material.diffuse_color = color
|
||||||
|
|
||||||
def apply_color_variation(self, context, objects):
|
def apply_color_variation(self, context, collections):
|
||||||
|
initial_state = random.getstate()
|
||||||
variation = context.scene.lutb_color_variation
|
variation = context.scene.lutb_color_variation
|
||||||
for obj in objects:
|
|
||||||
for material in obj.data.materials:
|
|
||||||
color = Color(material.diffuse_color[:3])
|
|
||||||
gamma = color.v ** (1 / 2.224)
|
|
||||||
|
|
||||||
custom_variation = CUSTOM_VARIATION.get(material.name.rsplit(".", 1)[0])
|
for collection in collections:
|
||||||
var = variation if custom_variation is None else variation * custom_variation
|
for lod_collection in collection.children:
|
||||||
gamma += random.uniform(-var / 200, var / 200)
|
random.setstate(initial_state)
|
||||||
|
for obj in list(lod_collection.objects):
|
||||||
|
if obj.type == "MESH":
|
||||||
|
for material in obj.data.materials:
|
||||||
|
color = Color(material.diffuse_color[:3])
|
||||||
|
gamma = color.v ** (1 / 2.224)
|
||||||
|
|
||||||
color.v = min(max(0, gamma), 1) ** 2.224
|
custom_variation = CUSTOM_VARIATION.get(material.name.rsplit(".", 1)[0])
|
||||||
material.diffuse_color = (*color, 1.0)
|
var = variation if custom_variation is None else variation * custom_variation
|
||||||
|
gamma += random.uniform(-var / 200, var / 200)
|
||||||
|
|
||||||
|
color.v = min(max(0, gamma), 1) ** 2.224
|
||||||
|
material.diffuse_color = (*color, 1.0)
|
||||||
|
|
||||||
def apply_vertex_colors(self, context, objects):
|
def apply_vertex_colors(self, context, objects):
|
||||||
scene = context.scene
|
scene = context.scene
|
||||||
@@ -453,6 +471,8 @@ class LUTB_PT_process_model(LUToolboxPanel, bpy.types.Panel):
|
|||||||
|
|
||||||
layout.prop(scene, "lutb_keep_uvs")
|
layout.prop(scene, "lutb_keep_uvs")
|
||||||
|
|
||||||
|
layout.prop(scene, "lutb_reset_orientation")
|
||||||
|
|
||||||
class LUTB_PT_apply_vertex_colors(LUToolboxPanel, bpy.types.Panel):
|
class LUTB_PT_apply_vertex_colors(LUToolboxPanel, bpy.types.Panel):
|
||||||
bl_label = "Apply Vertex Colors"
|
bl_label = "Apply Vertex Colors"
|
||||||
bl_parent_id = "LUTB_PT_process_model"
|
bl_parent_id = "LUTB_PT_process_model"
|
||||||
@@ -567,6 +587,8 @@ def register():
|
|||||||
"Combine transparent bricks")
|
"Combine transparent bricks")
|
||||||
bpy.types.Scene.lutb_keep_uvs = BoolProperty(name="Keep UVs", default=False, description=""\
|
bpy.types.Scene.lutb_keep_uvs = BoolProperty(name="Keep UVs", default=False, description=""\
|
||||||
"Keep the original mesh UVs. Disabling this results in a model with no UVs")
|
"Keep the original mesh UVs. Disabling this results in a model with no UVs")
|
||||||
|
bpy.types.Scene.lutb_reset_orientation = BoolProperty(name="Reset Orientation", default=True, description=""\
|
||||||
|
"Reset the orientation so the model is properly upright for visual effects.")
|
||||||
|
|
||||||
bpy.types.Scene.lutb_correct_colors = BoolProperty(name="Correct Colors", default=False, description=""\
|
bpy.types.Scene.lutb_correct_colors = BoolProperty(name="Correct Colors", default=False, description=""\
|
||||||
"Remap model colors to LU color palette. "\
|
"Remap model colors to LU color palette. "\
|
||||||
@@ -625,6 +647,7 @@ def unregister():
|
|||||||
del bpy.types.Scene.lutb_combine_objects
|
del bpy.types.Scene.lutb_combine_objects
|
||||||
del bpy.types.Scene.lutb_combine_transparent
|
del bpy.types.Scene.lutb_combine_transparent
|
||||||
del bpy.types.Scene.lutb_keep_uvs
|
del bpy.types.Scene.lutb_keep_uvs
|
||||||
|
del bpy.types.Scene.lutb_reset_orientation
|
||||||
|
|
||||||
del bpy.types.Scene.lutb_correct_colors
|
del bpy.types.Scene.lutb_correct_colors
|
||||||
del bpy.types.Scene.lutb_use_color_variation
|
del bpy.types.Scene.lutb_use_color_variation
|
||||||
|
|||||||
Reference in New Issue
Block a user