Created
January 30, 2023 08:42
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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