Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

March 26, 2014

Note to self BMesh

small note to self: useful snippets for debugging mesh editing tools. and then

Removing Edges

From my understanding of this (may be wrong, still experimenting): say I have edges with indices [0,1,2,3,4,5,6,7] and I delete an edge with index 4.
  • I won't get [0,1,2,3, 5,6,7]
  • But will become [0,1,2,3,4,5,6].
    Don't assume that there's a direct remap happening, like: (5->4, 6->5, 7->6). Indices may be jumbled up.
  • In the case of removing multiple edges from a list, ordering your edge indices from highest to lowest won't guarantee that you are deleting the right edge.

Using bmesh.ops.remove()

As per this post on StackExchange. Using any other method has given me unexpected results. So whether you need to remove 1 or multiple edges, the bmesh.ops.remove method will happily take a list of edges and remove them without the headache of bookkeeping or tagging.

May 29, 2013

Adding geometry to existing geometry using BMesh

I resist asking questions until that feeling starts to kick where there has to be a fast but illusive answer. I want to see blender.stackexchange progress out of beta, it has been pretty useful already!
import bpy, bmesh

obj = bpy.context.object
bm = bmesh.from_edit_mesh(obj.data)

bm.verts.new((2.0, 2.0, 2.0))
bm.verts.new((-2.0, 2.0, 2.0))
bm.verts.new((-2.0, -2.0, 2.0))

bm.faces.new((bm.verts[i] for i in range(-3,0)))

bm.verts.new((2.0, 2.0, -2.0))
bm.verts.new((-2.0, 2.0, -2.0))
bm.verts.new((-2.0, -2.0, -2.0))
bm.verts.new((2.0, -2.0, -2.0))

bm.faces.new((bm.verts[i] for i in range(-4,0)))

# update, while in edit mode
# thanks to ideasman42 for making this clear
# http://blender.stackexchange.com/questions/414/
bmesh.update_edit_mesh(obj.data)
Adding edges is also similar
# let's add two verts and connect them as an edge
bm.verts.new((0.0, 1.0, 1.0))
bm.verts.new((0.0, 0.0, 1.0))
bm.edges.new((bm.verts[-2], bm.verts[-1]))

# remember to do a    bmesh.update_edit_mesh(obj.data)