It worked with animation nodes. Now I made a Script, that does the job for me. The Script duplicates an object based on the pixel array and assigns the pixel color to the vertex color.
The object to clone has to be selected.
import bpy
# get image data
img = bpy.data.images["TEXTURE_NAME"]
width = img.size[0]
height = img.size[1]
#get object size for grid (has to be square)
size = bpy.context.active_object.dimensions[0]
#generate grid and match pixeldata to vertex color
countX = 0
countY = 0
countObj = 0
for y in range(height):
countX=0
for x in range(width):
bpy.ops.object.duplicate()
copy = bpy.context.active_object
copy.location = countX*size,countY*size,0
mesh = copy.data
if not mesh.vertex_colors:
mesh.vertex_colors.new()
color_layer = mesh.vertex_colors["Col"]
index = countObj * 4
r = img.pixels[index + 0]
g = img.pixels[index + 1]
b = img.pixels[index + 2]
a = img.pixels[index + 3]
i = 0
for poly in mesh.polygons:
for idx in poly.loop_indices:
rgb = [r,g,b,a]
color_layer.data[i].color = rgb
i += 1
countObj+=1
countX+=1
countY+=1
The material can be made like this:
Now I would like to move the objects directly to a new collection, but I tried it without success. Can anybody help me to:
- create a new collection, if there isn't one called "Artwork"
- move the objects to that collection