Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Created January 30, 2023 08:42
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 CGArtPython/42627bf88df26f4f01599b32d8eb0a02 to your computer and use it in GitHub Desktop.
Save CGArtPython/42627bf88df26f4f01599b32d8eb0a02 to your computer and use it in GitHub Desktop.
Beginner Python Exercise in Blender: Make a cube from a list of vertices (tutorial https://www.youtube.com/watch?v=mN3n9b98HMk)
import bpy
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),
(7, 6, 5, 4),
(4, 5, 1, 0),
(7, 4, 0, 3),
(6, 7, 3, 2),
(5, 6, 2, 1),
]
edges = []
# create a mesh from the vert, edge, and face data
mesh_data = bpy.data.meshes.new("cube_data")
mesh_data.from_pydata(verts, edges, faces)
# create a object using the mesh data
mesh_obj = bpy.data.objects.new("cube_object", mesh_data)
bpy.context.collection.objects.link(mesh_obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment