Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Blender Mesh/Curve Ring Generator
- import bpy
- import math
- detail = 2 # [0-2]
- maxRing = 28 # [0-28]
- checkers = True
- curve = False
- rooms = True
- emptySize = 120
- ringRadius = [236.800459869903,
- 255.644913604649,
- 274.87006337444,
- 294.483600008267,
- 314.493369705404,
- 334.9073771742,
- 355.733788834285,
- 376.980936083462,
- 398.657318630603,
- 420.771607895867,
- 443.332650479622,
- 466.349471701433,
- 489.831279210552,
- 513.787466669351,
- 538.227617511157,
- 563.161508774008,
- 588.599115011867,
- 614.550612284834,
- 641.026382229982,
- 668.037016214426,
- 695.593319572293,
- 723.706315927289,
- 752.387251602588,
- 781.647600119812,
- 811.499066788899,
- 841.99966606518,
- 873.070366389729,
- 904.768757629926,
- 937.107520410328]
- ringWidth = [25,
- 27,
- 27,
- 60,
- 60,
- 60,
- 60,
- 60,
- 60,
- 27,
- 27,
- 27,
- 27,
- 27,
- 60,
- 60,
- 27,
- 27,
- 27,
- 27,
- 27,
- 60,
- 60,
- 27,
- 27,
- 27,
- 27,
- 27,
- 27]
- ringHeight = [16.4712962350476,
- 18.8444537347455,
- 19.225149769791,
- 19.6135366338271,
- 20.0097696971367,
- 20.414007468796,
- 20.8264116600848,
- 21.2471472491775,
- 21.6763825471405,
- 22.1142892652646,
- 22.5610425837548,
- 23.0168212218106,
- 23.4818075091198,
- 23.9561874587991,
- 24.440150841805,
- 24.9338912628517,
- 25.4376062378587,
- 25.951497272967,
- 26.4757699451482,
- 27.0106339844441,
- 27.5563033578673,
- 28.1129963549959,
- 28.6809356752989,
- 29.2603485172241,
- 29.8514666690868,
- 30.5005992762809,
- 31.070700324549,
- 31.6983912401965,
- 32.3387627804025]
- ringMaxRooms = [14,
- 7,
- 8,
- 9,
- 9,
- 10,
- 11,
- 11,
- 12,
- 25,
- 26,
- 28,
- 29,
- 31,
- 1,
- 1,
- 36,
- 37,
- 39,
- 41,
- 42,
- 1,
- 1,
- 48,
- 49,
- 51,
- 53,
- 55,
- 57]
- ringHalfRotFr = [450,
- 468,
- 486,
- 504,
- 522,
- 539,
- 556,
- 573,
- 590,
- 606,
- 623,
- 639,
- 655,
- 671,
- 688,
- 704,
- 720,
- 736,
- 752,
- 768,
- 784,
- 799,
- 815,
- 831,
- 847,
- 863,
- 879,
- 895,
- 911]
- bpy.context.scene.unit_settings.system='METRIC'
- bpy.context.scene.frame_end = max(ringHalfRotFr)*2
- for i in range(0,maxRing+1):
- # Animation
- bpy.ops.object.empty_add(type='PLAIN_AXES')
- bpy.context.object.empty_draw_size = emptySize
- bpy.context.object.name = "RING "+str(i)+" Controller"
- bpy.context.scene.frame_current = 1
- bpy.ops.anim.keyframe_insert_menu(type='Rotation')
- bpy.context.scene.frame_current = ringHalfRotFr[i]
- bpy.context.object.rotation_euler[2] = math.pi
- bpy.ops.anim.keyframe_insert_menu(type='Rotation')
- # Area type juggling
- # Save old area type
- old_type = bpy.context.area.type
- # Switch to graph editor
- bpy.context.area.type = 'GRAPH_EDITOR'
- # Do some graph stuff, e.g.
- bpy.ops.graph.interpolation_type(type='LINEAR')
- bpy.ops.graph.select_all_toggle(invert=False)
- bpy.ops.graph.select_all_toggle(invert=False)
- bpy.ops.graph.extrapolation_type(type='LINEAR')
- # Switch back again
- bpy.context.area.type = old_type
- if curve:
- # Create circle curve
- bpy.ops.curve.primitive_bezier_circle_add(radius=ringRadius[i])
- bpy.context.object.data.resolution_u = 128
- bpy.context.object.data.extrude = ringWidth[i]
- elif rooms:
- if i not in [14,15,21,22]: # Special case for PUB rings
- bpy.ops.mesh.primitive_cylinder_add(vertices=ringMaxRooms[i], radius=ringRadius[i], depth=ringWidth[i], end_fill_type='NOTHING')
- else: # Create circle mesh
- bpy.ops.mesh.primitive_cylinder_add(vertices=4, radius=ringRadius[i], depth=ringWidth[i], end_fill_type='NOTHING')
- if checkers and not curve:
- # Checkers materials
- bpy.context.object.data.materials.append(bpy.data.materials['white'])
- bpy.context.object.data.materials.append(bpy.data.materials['black'])
- bpy.ops.object.mode_set(mode='EDIT')
- bpy.ops.mesh.select_nth()
- bpy.context.object.active_material_index = 1
- bpy.ops.object.material_slot_assign()
- bpy.ops.object.mode_set(mode='OBJECT')
- else:
- # Mesh circle with constant resolution
- bpy.ops.mesh.primitive_cylinder_add(vertices=128, radius=ringRadius[i], depth=ringWidth[i], end_fill_type='NOTHING')
- if rooms and not curve:
- # Make meshes perfect circles
- sublvl = 1+detail if (i == 0) else 2+detail if (0 < i < 9) else 1+detail if (i not in [14,15,21,22]) else 5+detail
- bpy.ops.object.modifier_add(type='SUBSURF')
- bpy.context.object.modifiers["Subsurf"].levels = sublvl
- bpy.context.object.modifiers["Subsurf"].render_levels = sublvl
- bpy.ops.object.modifier_add(type='CAST')
- bpy.context.object.modifiers["Cast"].cast_type = 'CYLINDER'
- bpy.context.object.modifiers["Cast"].use_z = False
- bpy.context.object.modifiers["Cast"].factor = 1
- bpy.context.object.modifiers["Cast"].radius = ringRadius[i]
- bpy.ops.object.modifier_add(type='SOLIDIFY')
- bpy.context.object.modifiers["Solidify"].thickness = ringHeight[i]
- bpy.context.object.modifiers["Solidify"].use_quality_normals = True
- bpy.context.object.modifiers["Solidify"].use_even_offset = True
- bpy.ops.object.modifier_add(type='EDGE_SPLIT')
- bpy.ops.object.shade_smooth()
- bpy.context.object.name = "RING "+str(i)
- # Parent to controller empty for animation
- bpy.context.object.parent = bpy.data.objects["RING "+str(i)+" Controller"]
Add Comment
Please, Sign In to add comment