Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Created September 11, 2023 07:10
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/43bf8e43cc0d44d7813ce1978dbbdcdd to your computer and use it in GitHub Desktop.
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)
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