Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/8efcc53976ed4165d7c7 to your computer and use it in GitHub Desktop.
Save zeffii/8efcc53976ed4165d7c7 to your computer and use it in GitHub Desktop.
import bpy
# # slow
# for x in range(-25, 25):
# for y in range(-25, 25):
# bpy.ops.mesh.primitive_cube_add(radius=0.2, location=(x, y, 0))
#
# faster, much faster
import bmesh
ctx = bpy.context
for x in range(-25, 25):
for y in range(-25, 25):
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=0.2)
me = bpy.data.meshes.new('Cube')
bm.to_mesh(me)
bm.free() # free and prevent further access
obj = bpy.data.objects.new('Cube', me)
obj.location = (x, y, 0)
ctx.scene.objects.link(obj)
# faster, much faster
import bpy
import bmesh
ctx = bpy.context
objs = []
add = objs.append
for x in range(-25, 25):
for y in range(-25, 25):
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=0.2)
me = bpy.data.meshes.new('Cube')
bm.to_mesh(me)
bm.free() # free and prevent further access
obj = bpy.data.objects.new('Cube', me)
obj.location = (x, y, 0)
add(obj)
for obj in objs:
ctx.scene.objects.link(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment