Fix #104401: Import .ase files with swatch groups #104405

Merged
Antonio Vazquez merged 2 commits from :main into main 2023-02-13 10:45:15 +01:00
2 changed files with 38 additions and 26 deletions

View File

@ -2,8 +2,8 @@
bl_info = { bl_info = {
"name": "Import Palettes", "name": "Import Palettes",
"author": "Antonio Vazquez", "author": "Antonio Vazquez, Kevin C. Burke (@blastframe)",
"version": (1, 0, 0), "version": (1, 0, 1),
"blender": (2, 81, 6), "blender": (2, 81, 6),
"location": "File > Import", "location": "File > Import",
"description": "Import Palettes", "description": "Import Palettes",

View File

@ -99,16 +99,9 @@ def parse(filename):
return [c for c in parse_chunk(data)] return [c for c in parse_chunk(data)]
def load(context, filepath): def create_color(data):
output = parse(filepath)
(path, filename) = os.path.split(filepath)
pal = None
for elm in output:
valid = False valid = False
data = elm['data']
color = [0, 0, 0] color = [0, 0, 0]
val = data['values'] val = data['values']
@ -128,12 +121,31 @@ def load(context, filepath):
color[1] = (1.0 - val[1]) * (1.0 - val[3]) color[1] = (1.0 - val[1]) * (1.0 - val[3])
color[2] = (1.0 - val[2]) * (1.0 - val[3]) color[2] = (1.0 - val[2]) * (1.0 - val[3])
# Create palette color
if valid: if valid:
return color
def load(context, filepath):
output = parse(filepath)
(path, filename) = os.path.split(filepath)
pal = None
for elm in output:
colors = []
if "data" in elm:
colors.append(create_color(elm['data']))
if "swatches" in elm:
for swatch in elm['swatches']:
colors.append(create_color(swatch["data"]))
# Create Palette # Create Palette
if pal is None: if pal is None:
pal = bpy.data.palettes.new(name=filename) pal = bpy.data.palettes.new(name=filename)
for color in colors:
# Create Color # Create Color
col = pal.colors.new() col = pal.colors.new()
col.color[0] = color[0] col.color[0] = color[0]