Support Blender 4.0
This commit is contained in:
+5
-12
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user