Skip to content

Instantly share code, notes, and snippets.

@zeffii

zeffii/as_a_func.py

Last active Nov 16, 2015
Embed
What would you like to do?
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