Skip to content

Commit 0250d1a

Browse files
committed
blender: Restore foreach_set() workaround for <4.1
It was removed in 8a4ce9b, but Triton, my web server, runs Ubuntu, and that ships old versions of things, it currently has Blender 4.0.2. Add version checking and apply the fix for versions < 4.1.
1 parent 0b29ec3 commit 0250d1a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

integrations/blender/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
StringProperty,
5555
)
5656

57+
# Breaking changes are quite common in Blender's Python API, unfortunately.
58+
major, minor, patch = bpy.app.version
59+
5760
class CrayRenderSettings(bpy.types.PropertyGroup):
5861
samples: IntProperty(
5962
name="Samples",
@@ -477,6 +480,10 @@ def view_update(self, context, depsgraph):
477480

478481
def display_bitmap(self, bm):
479482
floats = np.frombuffer(bm.data, np.float32)
483+
if (major, minor) < (4, 1):
484+
# convert [r,g,b,a,r,g,b,a,...] to [(r,g,b,a),(r,g,b,a),...]
485+
# For context, see f1516d46a570, 8a4ce9b3fd07c66, and https://developer.blender.org/docs/release_notes/4.1/python_api/#foreach
486+
floats = floats.reshape(-1, 4)
480487
result = self.begin_result(0, 0, bm.width, bm.height)
481488
r_pass = result.layers[0].passes["Combined"]
482489
r_pass.rect.foreach_set(floats)

0 commit comments

Comments
 (0)