Created
September 11, 2023 07:10
-
-
Save CGArtPython/43bf8e43cc0d44d7813ce1978dbbdcdd to your computer and use it in GitHub Desktop.
Creating an icosphere using the Bmesh Blender Python module. (video tutorial here: https://youtu.be/N3U2noAHgBo)
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 | |
import bmesh | |
obj_name = "my_shape" | |
# create the mesh data | |
mesh_data = bpy.data.meshes.new(f"{obj_name}_data") | |
# create the mesh object using the mesh data | |
mesh_obj = bpy.data.objects.new(obj_name, mesh_data) | |
# add the mesh object into the scene | |
bpy.context.scene.collection.objects.link(mesh_obj) | |
#### | |
#### | |
# create a new bmesh | |
bm = bmesh.new() | |
# create a icosphere | |
bmesh.ops.create_icosphere(bm, subdivisions=1, radius=2.0) | |
# writes the bmesh data into the mesh data | |
bm.to_mesh(mesh_data) | |
# [Optional] update the mesh data (helps with redrawing the mesh in the viewport) | |
mesh_data.update() | |
# clean up/free memory that was allocated for the bmesh | |
bm.free() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment