diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-03-30 09:43:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-03-30 09:43:33 +0400 |
commit | 6711870cabdc8e180c38aff8b98d8373e673c7f6 (patch) | |
tree | 69f78ed55f85af27fc376c1a4cfbb4a63975af96 /release | |
parent | 79871ded0bd3e9cd5d7693ba683724cdb07121c3 (diff) |
updated add mesh template for bmesh. thanks to PKHG for initial conversion.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/templates/operator_mesh_add.py | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/release/scripts/templates/operator_mesh_add.py b/release/scripts/templates/operator_mesh_add.py index d89b7e82f77..3228e3c4d62 100644 --- a/release/scripts/templates/operator_mesh_add.py +++ b/release/scripts/templates/operator_mesh_add.py @@ -1,4 +1,5 @@ import bpy +import bmesh def add_box(width, height, depth): @@ -7,31 +8,29 @@ def add_box(width, height, depth): no actual mesh data creation is done here. """ - vertices = [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, - 4, 7, 6, 5, - 0, 4, 5, 1, - 1, 5, 6, 2, - 2, 6, 7, 3, - 4, 0, 3, 7, + 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), + (4, 7, 6, 5), + (0, 4, 5, 1), + (1, 5, 6, 2), + (2, 6, 7, 3), + (4, 0, 3, 7), ] # apply size - for i in range(0, len(vertices), 3): - vertices[i] *= width - vertices[i + 1] *= depth - vertices[i + 2] *= height + for i, v in enumerate(verts): + verts[i] = v[0] * width, v[1] * depth, v[2] * height - return vertices, faces + return verts, faces from bpy.props import FloatProperty, BoolProperty, FloatVectorProperty @@ -85,11 +84,15 @@ class AddBox(bpy.types.Operator): mesh = bpy.data.meshes.new("Box") - mesh.vertices.add(len(verts_loc) // 3) - mesh.faces.add(len(faces) // 4) + bm = bmesh.new() - mesh.vertices.foreach_set("co", verts_loc) - mesh.faces.foreach_set("vertices_raw", faces) + for v_co in verts_loc: + bm.verts.new(v_co) + + for f_idx in faces: + bm.faces.new([bm.verts[i] for i in f_idx]) + + bm.to_mesh(mesh) mesh.update() # add the mesh as an object into the scene with this utility module |