Last active
August 29, 2015 14:26
-
-
Save zeffii/8efcc53976ed4165d7c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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