Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import colorsys
- # Define the category names
- hue_categories = ["Red", "Yellow", "Green", "Cyan", "Blue", "Purple"]
- saturation_categories = ["Pale", "Normal", "Vibrant"]
- value_categories = ["Dark", "Normal", "Light"] # <-- Reverse the order of the value categories
- # Iterate over all selected objects
- for obj in bpy.context.selected_objects:
- # Iterate over all materials assigned to the object
- for mat in obj.data.materials:
- # Get the base color of the material
- base_color = mat.diffuse_color
- # Convert the base color's RGB values to HSV values
- h, s, v = colorsys.rgb_to_hsv(base_color[0], base_color[1], base_color[2])
- # Calculate the hue category
- hue_index = int((h+1/6)*5)
- hue_category = hue_categories[hue_index]
- # Calculate the saturation category
- if s < 0.33:
- saturation_category = saturation_categories[0]
- elif s < 0.66:
- saturation_category = saturation_categories[1]
- else:
- saturation_category = saturation_categories[2]
- # Calculate the value category
- if v < 0.33:
- value_category = value_categories[0]
- elif v < 0.66:
- value_category = value_categories[1]
- else:
- value_category = value_categories[2]
- # Set the name of the material to the combination of categories
- mat.name = hue_category + " " + saturation_category + " " + value_category
Advertisement
Add Comment
Please, Sign In to add comment