Created
January 25, 2023 21:58
-
-
Save semagnum/c95a0cd87a15b34cc04bd5c3efc6c2d8 to your computer and use it in GitHub Desktop.
Extracts mesh data to be used for mesh.from_pydata()
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 | |
from mathutils import Vector | |
# prereq: go into your object's edit mode | |
context = bpy.context | |
mesh = context.edit_object.data | |
verts = [v.co for v in mesh.vertices] | |
edges = [[v for v in e.vertices] for e in mesh.edges] | |
faces = [[v for v in p.vertices] for p in mesh.polygons] | |
print(verts) | |
print(edges) | |
print(faces) | |
bpy.ops.object.editmode_toggle() # back to object mode | |
mesh = bpy.data.meshes.new("myBeautifulMesh") # add the new mesh | |
obj = bpy.data.objects.new(mesh.name, mesh) | |
col = bpy.data.collections["Collection"] | |
col.objects.link(obj) | |
context.view_layer.objects.active = obj | |
mesh.from_pydata(verts, edges, faces) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment