I am creating a program in blender that makes cubes based on the values of an array. For example, when one of the values is one it creates a cube at a specific point and then it goes on to print another cube until you have "printed" a numpy array. Here is my code:
import bpy
import numpy as np
def print_array(a, size=1):
count = 0
x = 0
for i in a:
y = 0
for j in i:
z = 0
for k in j:
if k == 1:
bpy.ops.mesh.primitive_cube_add(size=size, location=(x, y, z))
count += 1
z += size
y += size
x += size
return count
a = np.ones((3, 3, 3))
print_array(a)
While this does work for smaller numpy arrays blender crashes when I try to "print" larger arrays. Is there a less tasking way to do this without making the arrays smaller?
bmesh.ops.create_cube, or perhapsmesh.from_pydata. Each method will have pros and cons that can be weighed against your specific objective. I'm not experienced enough to comment on blender crashing as a function of object numbers. – Jeremy Hilgar Apr 17 '20 at 23:09for i in range(start, end, step):instead of what you did. If you don't want your computer to stall you must not separate all the objects (ie comment out the last line). Can you achieve your goal with one single object but a multitude of meshes ? – Gorgious Apr 18 '20 at 12:47