Skip to content

Instantly share code, notes, and snippets.

@dskjal
Forked from jabe0958/blender_duplicate_spirally.py
Last active February 14, 2018 16:26
Show Gist options
  • Save dskjal/9fc36a4cbf53431e8074ad48142c115c to your computer and use it in GitHub Desktop.
Save dskjal/9fc36a4cbf53431e8074ad48142c115c to your computer and use it in GitHub Desktop.
Blenderで対象のメッシュを螺旋状に複製して統合するPythonスクリプト
import bpy
import math
src_name = 'Cube'
loop = 10
split = 32
width_init = 1
width_incr = 0.01
height_init = 0
height_loop = 0.8
height_incr = height_loop / split
scale = 0.12
remove_src_obj = False
r_step = (2*math.pi) / split
def index_to_location(idx):
width = width_init + idx * width_incr
height = height_init + idx * height_incr
r = idx%split
x = width * math.cos(r * r_step)
y = width * math.sin(r * r_step)
return [x, y, height]
# generate
bpy.ops.object.select_all(action='DESELECT')
mesh = bpy.data.objects[src_name].data.copy()
scn_objects = bpy.context.scene.objects
for i in range(loop*split):
o = bpy.data.objects.new(name='spirally', object_data=mesh)
o.location = index_to_location(i)
o.scale = [scale]*3
o.rotation_euler = (0, -1, (2*math.pi/split)*(i%split))
scn_objects.link(o)
scn_objects[o.name].select = True
scn_objects.active = o
bpy.ops.object.join()
if remove_src_obj:
scn_objects.unlink(bpy.data.objects[src_name])
bpy.context.active_object.name = src_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment