From a7e4d76d05e9ac7d9088ac882d15221936052010 Mon Sep 17 00:00:00 2001 From: Tim Kuipers Date: Thu, 24 Oct 2019 18:36:25 +0200 Subject: [PATCH] make lithophane alpha channel control total final width multiplier. That way the picture is not always square. We can use the alpha channel to encode the actual shape --- plugins/ImageReader/ImageReader.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/ImageReader/ImageReader.py b/plugins/ImageReader/ImageReader.py index d6c2827d16..7fb13e915c 100644 --- a/plugins/ImageReader/ImageReader.py +++ b/plugins/ImageReader/ImageReader.py @@ -5,7 +5,7 @@ import numpy import math -from PyQt5.QtGui import QImage, qRed, qGreen, qBlue +from PyQt5.QtGui import QImage, qRed, qGreen, qBlue, qAlpha from PyQt5.QtCore import Qt from UM.Mesh.MeshReader import MeshReader @@ -138,6 +138,11 @@ class ImageReader(MeshReader): height_data *= scale_vector.y height_data += base_height + if img.hasAlphaChannel(): + for x in range(0, width): + for y in range(0, height): + height_data[y, x] *= qAlpha(img.pixel(x, y)) / 255.0 + heightmap_face_count = 2 * height_minus_one * width_minus_one total_face_count = heightmap_face_count + (width_minus_one * 2) * (height_minus_one * 2) + 2