Hi all, I was using a python script to move the z position of each vertex of a plane using the luminescence of each pixel of a picture that used to work great, but now using 4.5 does not worked as expected. Is there any change in the python API. The script is the following:
import bpy
import bmesh
import numpy as np
from PIL import Image
img = Image.open("/path/to/image.tiff")
grey_img = img.convert('L')
rgb_img = img.convert('RGB')
max_size = (1000, 1000)
max_height = 80 #z lightness max
min_height = 0 # z lightness min
rgb_img.thumbnail(max_size)
grey_img.thumbnail(max_size)
imageNp = np.array(grey_img)
maxPix = imageNp.max()
minPix = imageNp.min()
(w,h) = grey_img.size
vertices=[]
edges= []
faces=[]
#w = 100
#h = 100
#size = 1
for y in range(h):
for x in range(w):
pixel_intensity = imageNp[y][x]
print(pixel_intensity)
z = (pixel_intensity * max_height) / maxPix
vertices.append((x, y, z))
for x in range(w-1):
for y in range(h-1):
(r, g, b) = rgb_img.getpixel((x,y))
color = (r, g, b)
faces.append(((x + y * w), (x + 1 + y * w), (x + 1 + (y + 1) * w)))
faces.append(((x + y * w), (x + (y + 1) * w), (x + 1 + (y + 1) * w)))
new_mesh=bpy.data.meshes.new("new mesh")
new_mesh.from_pydata(vertices,edges,faces)
new_mesh.update()
#make object from the mesh
new_object = bpy.data.objects.new("new object", new_mesh)
#---------
view_layer=bpy.context.view_layer
view_layer.active_layer_collection.collection.objects.link(new_object)
The plane is created, and some form of the picture can be recognized in the mesh, but the vertices no longer follow a patterns of the luminance of the image.
I reckon is something with the order of the faces’ append, but I am just speculating
any idea,
thanks