Support Blender 4.0

This commit is contained in:
2024-03-06 20:36:45 +09:00
parent 91cb6a9356
commit 9913ae8c35
4 changed files with 62 additions and 66 deletions
+5 -12
View File
@@ -1,5 +1,5 @@
'''
Copyright (C) 2021 Akaneyu
Copyright (C) 2021 - 2024 Akaneyu
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
@@ -15,24 +15,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import bpy
import numpy as np
def read_pixels_from_image(img):
width, height = img.size[0], img.size[1]
if bpy.app.version >= (2, 83, 0):
pixels = np.empty(len(img.pixels), dtype=np.float32);
img.pixels.foreach_get(pixels)
return np.reshape(pixels, (height, width, 4))
else:
return np.reshape(img.pixels[:], (height, width, 4))
pixels = np.empty(len(img.pixels), dtype=np.float32);
img.pixels.foreach_get(pixels)
return np.reshape(pixels, (height, width, 4))
def write_pixels_to_image(img, pixels):
if bpy.app.version >= (2, 83, 0):
img.pixels.foreach_set(np.reshape(pixels, -1))
else:
img.pixels = np.reshape(pixels, -1)
img.pixels.foreach_set(np.reshape(pixels, -1))
if img.preview:
img.preview.reload()