#!/bin/bash
######################################################################
#Copyright (C) 2024 Kris Occhipinti
#https://filmsbykris.com
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation version 3 of the License.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see .
######################################################################
[[ $1 ]] || exit
[[ -f "$1" ]] || exit
convert "$1" text:- |grep -v '^#'|awk '{print $1,$4}'|sed 's/: srgba(/,/g'|tr -d ')'|while read line
do
line="$(echo $line|sed 's/: black/,0,0,0,1/g')"
pos="$(echo $line|cut -d\, -f1,2)"
if [[ "$line" != *"none"* ]]
then
r="$(echo $line|cut -d\, -f3)"
r="$(echo "scale=6; $r/255"| bc -l)"
g="$(echo $line|cut -d\, -f4)"
g="$(echo "scale=6; $g/255"| bc -l)"
b="$(echo $line|cut -d\, -f5)"
b="$(echo "scale=6; $b/255"| bc -l)"
color="$r,$g,$b"
name="Material.$RANDOM.$RANDOM"
echo "
bpy.ops.mesh.primitive_cube_add(enter_editmode=False, align='WORLD', location=($pos, 0), scale=(.5, .5, .5))
mat = bpy.data.materials.new('$name')
mat.use_nodes = True
bpy.data.materials['$name'].node_tree.nodes['Principled BSDF'].inputs[0].default_value = ($color, 1)
bpy.context.object.active_material = mat"
fi
done