Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

July 08, 2011

creating a mesh using primitives, polysphere


import bpy
import math

# constant
r90 = math.radians(90)

# variables
subdiv = 7

# add an new MESH object, place it in 'EDIT' mode
bpy.ops.object.add(type='MESH')
bpy.context.object.name = 'PolySphere'
bpy.ops.object.mode_set(mode='EDIT')

# define locations and rotations of the mesh grid objects
loc_list = (0, 0, 1), (0, 0, -1), (1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0)
rot_list = (0, 0, 0),(0, r90*2, 0),(0, r90, 0),(0, -r90, 0),(-r90, 0, 0), (r90, 0, 0)

# add 6 faces
for i in range(6):
bpy.ops.mesh.primitive_grid_add( x_subdivisions=subdiv,
y_subdivisions=subdiv,
size=1,
view_align=False,
enter_editmode=True,
location=loc_list[i],
rotation=rot_list[i])

# select all verts, and remove doubles, end up with neat cube
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.remove_doubles(limit=0.0001)

# set
bpy.ops.transform.tosphere(value=1)
bpy.ops.mesh.vertices_smooth(repeat=20, xaxis=True, yaxis=True, zaxis=True)
bpy.ops.transform.tosphere(value=1)

No comments:

Post a Comment

Please use Blender.StackExchange.com for python scripting questions unrelated to this post.