Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active November 16, 2015 08:25
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/3392c986dd759b8f3ddf to your computer and use it in GitHub Desktop.
Save zeffii/3392c986dd759b8f3ddf to your computer and use it in GitHub Desktop.
import bpy
import bmesh
verts = [
(1.0, 1.0, -1.0),
(1.0, -1.0, -1.0),
(-1.0, -1.0, -1.0),
(-1.0, 1.0, -1.0),
(1.0, 1.0, 1.0),
(1.0, -1.0, 1.0),
(-1.0, -1.0, 1.0),
(-1.0, 1.0, 1.0)]
faces = [
(0, 1, 2, 3),
(4, 5, 6, 7), # reversed
(0, 4, 5, 1),
(1, 5, 6, 2),
(2, 6, 7, 3),
(4, 0, 3, 7)]
def make_object(name, verts, faces, normal_recalc=True):
scn = bpy.context.scene
mesh = bpy.data.meshes.new(name + "_Mesh")
mesh.from_pydata(verts, [], faces)
mesh.update()
if normal_recalc:
bm = bmesh.new()
bm.from_mesh(mesh)
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
bm.to_mesh(mesh)
bm.free()
ob = bpy.data.objects.new(name, mesh)
scn.objects.link(ob)
make_object('my_cube', verts, faces)
# make_object(name, verts, faces, normal_recalc=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment