Last active
October 31, 2022 06:00
-
-
Save CGArtPython/b5f6786c5d8fec0cd64a1da480e4079e to your computer and use it in GitHub Desktop.
Beginner Blender Python Tutorial: Python Classes step by step version Example 1 (used in tutorial: https://youtu.be/t2KEolkhIoA)
This file contains hidden or 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 | |
| ####################################################################### | |
| # create a cube with square faces | |
| ####################################################################### | |
| # define the coordinates of each vertex | |
| 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), | |
| ] | |
| # define faces using the indexes of the vertices | |
| 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