From 6fbf07b96cab5d0b82fa931ebe8c87edbc418814 Mon Sep 17 00:00:00 2001 From: Michel Fedde <35878897+Neintonine@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:22:33 +0100 Subject: [PATCH] adds color source --- build/bump_minor.py | 1 - src/__init__.py | 1 - src/operators/bake_to_id_map.py | 18 +++--------------- src/panels/panel_advanced.py | 2 +- src/panels/panel_info.py | 8 ++++++-- src/panels/panel_options.py | 4 ++++ src/properties/bake_to_id.py | 8 ++++++++ src/types/__init__.py | 0 src/types/colors/__init__.py | 24 ++++++++++++++++++++++++ src/types/colors/generated.py | 32 ++++++++++++++++++++++++++++++++ 10 files changed, 78 insertions(+), 20 deletions(-) delete mode 100644 src/types/__init__.py create mode 100644 src/types/colors/__init__.py create mode 100644 src/types/colors/generated.py diff --git a/build/bump_minor.py b/build/bump_minor.py index 95053ae..449da17 100644 --- a/build/bump_minor.py +++ b/build/bump_minor.py @@ -5,4 +5,3 @@ if __name__ == "__main__": currentVersion = versioning.get_version() nextVersion = currentVersion.bump_minor() versioning.save_version(nextVersion) - diff --git a/src/__init__.py b/src/__init__.py index 65b5393..72db146 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -21,7 +21,6 @@ classes = ( BakeToIDMapPanel, BakeToIDInfoPanel, BakeToIDOptionsPanel, - BakeToIDAdvancedMenu, BakeToIDProperties, ) diff --git a/src/operators/bake_to_id_map.py b/src/operators/bake_to_id_map.py index 06f3051..6751d5b 100644 --- a/src/operators/bake_to_id_map.py +++ b/src/operators/bake_to_id_map.py @@ -3,6 +3,7 @@ import math import bpy +from ..types.colors import get_color from .. types.sources import get_source from .. types.targets import get_target @@ -33,21 +34,8 @@ class BakeToIDMapOperator(bpy.types.Operator): if len(targets) < 1: return - totalTargets = len(targets) - colors = [] - - total_hues = props.adv_total_hues - total_satuations = props.adv_total_satuations - total_brightnesses = props.adv_total_brightnesses - - satuations_break_point = math.pow(total_brightnesses, total_hues) - - for i in range(totalTargets): - h = (i / total_hues) % 1 - l = (math.ceil(i / total_hues) % total_brightnesses) / total_brightnesses - s = math.ceil(i / satuations_break_point) / total_satuations - - colors.append(colorsys.hls_to_rgb(h, l, s)) + color = get_color(props.colors) + colors = color.get_colors(props) target = get_target(props.target) self.paint_targets(props, target, targets, colors) diff --git a/src/panels/panel_advanced.py b/src/panels/panel_advanced.py index 9accb61..139923a 100644 --- a/src/panels/panel_advanced.py +++ b/src/panels/panel_advanced.py @@ -21,4 +21,4 @@ class BakeToIDAdvancedMenu(bpy.types.Panel): layout.prop(props, "adv_total_satuations") layout.prop(props, "adv_total_brightnesses") layout.label(text="Max ID-count: " + str( - math.pow(math.pow(props.adv_total_hues, props.adv_total_satuations), props.adv_total_brightnesses))) + )) diff --git a/src/panels/panel_info.py b/src/panels/panel_info.py index 808a5bc..ed79817 100644 --- a/src/panels/panel_info.py +++ b/src/panels/panel_info.py @@ -1,5 +1,6 @@ import bpy +from ..types.colors import get_color from .. types.sources import get_source @@ -20,7 +21,6 @@ class BakeToIDInfoPanel(bpy.types.Panel): if props.selection_mode != 'SINGLE': layout.label(text="Selected Object-Count: " + str(len(context.selected_objects))) - layout.separator() if props.selection_mode == 'SINGLE': layout.label(text="ID-Total: " + str(source.estimate_ids([context.active_object]))) @@ -42,4 +42,8 @@ class BakeToIDInfoPanel(bpy.types.Panel): layout.label(text="Estimated ID-Average: 0") if props.selection_mode == 'MULTIPLE_COMBINED': - layout.label(text="ID-Total: " + str(source.estimate_ids(context.selected_objects))) \ No newline at end of file + layout.label(text="ID-Total: " + str(source.estimate_ids(context.selected_objects))) + + color = get_color(props.colors) + + layout.label(text="Colors available: " + str(color.get_count(props))) diff --git a/src/panels/panel_options.py b/src/panels/panel_options.py index 0da5b42..bc92db5 100644 --- a/src/panels/panel_options.py +++ b/src/panels/panel_options.py @@ -37,3 +37,7 @@ class BakeToIDOptionsPanel(bpy.types.Panel): target_settings_box = layout.box() for setting in target.connected_properties: target_settings_box.prop(props, setting) + + layout.separator() + + layout.prop(props, "colors") diff --git a/src/properties/bake_to_id.py b/src/properties/bake_to_id.py index b777c0f..813c9d0 100644 --- a/src/properties/bake_to_id.py +++ b/src/properties/bake_to_id.py @@ -1,6 +1,7 @@ from bpy.types import (PropertyGroup) from bpy.props import (EnumProperty, BoolProperty, IntProperty, StringProperty) +from src.types.colors import get_color_enum from src.types.sources import get_source_enum from src.types.targets import get_targets_enum @@ -31,6 +32,13 @@ class BakeToIDProperties(PropertyGroup): default=get_targets_enum()[0][0] ) + colors: EnumProperty( + items=get_color_enum(), + name="Color Source", + description="From where to take the colors", + default=get_color_enum()[0][0] + ) + source_materials_remove_all: BoolProperty( name="Remove all source materials", default=False, diff --git a/src/types/__init__.py b/src/types/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/types/colors/__init__.py b/src/types/colors/__init__.py new file mode 100644 index 0000000..81f5434 --- /dev/null +++ b/src/types/colors/__init__.py @@ -0,0 +1,24 @@ +from . import generated + +_colors = [ + generated +] + + +def get_color(id): + for color in _colors: + if color.color_id == id: + return color + + raise Exception("Source not found: " + id) + + +def get_color_enum(): + enum_list = [] + i = 0 + for color in _colors: + enum_list.append((color.color_id, color.name, color.description, i)) + i += 1 + + return enum_list + diff --git a/src/types/colors/generated.py b/src/types/colors/generated.py new file mode 100644 index 0000000..91e7134 --- /dev/null +++ b/src/types/colors/generated.py @@ -0,0 +1,32 @@ +import colorsys +import math + +color_id = 'GENERATED' +name = 'Generated' +description = 'The colors get generated on-the-fly' + +MAX_BRIGHTNESS_STEPS = 8 +MAX_SATURATION_STEPS = 8 +MAX_HUES_STEPS = 8 + +def get_colors(props): + return gen_colors() + + +def get_count(props): + return len(gen_colors()) + + +def gen_colors(): + colors = [] + for brightnessStep in range(0, MAX_BRIGHTNESS_STEPS): + v = 1 - (brightnessStep / MAX_BRIGHTNESS_STEPS) + for satuationStep in range(0, MAX_SATURATION_STEPS): + s = 1 - (satuationStep / MAX_SATURATION_STEPS) + for hueStep in range(0, MAX_HUES_STEPS): + h = hueStep / MAX_HUES_STEPS + + color = colorsys.hsv_to_rgb(h, s, v) + colors.append(color) + + return colors \ No newline at end of file