This module gives access to low level bmesh operations.
Most operators take input and return output, they can be chained together to perform useful operations.
Note
This API us new in 2.65 and not yet well tested.
This script shows how operators can be used to model a link of a chain.
# This script uses bmesh operators to make 2 links of a chain.
import bpy
import bmesh
import math
import mathutils
# Make a new BMesh
bm = bmesh.new()
# Add a circle XXX, should return all geometry created, not just verts.
bmesh.ops.create_circle(
bm,
cap_ends=False,
diameter=0.2,
segments=8)
# Spin and deal with geometry on side 'a'
edges_start_a = bm.edges[:]
geom_start_a = bm.verts[:] + edges_start_a
ret = bmesh.ops.spin(
bm,
geom=geom_start_a,
angle=math.radians(180.0),
steps=8,
axis=(1.0, 0.0, 0.0),
cent=(0.0, 1.0, 0.0))
edges_end_a = [ele for ele in ret["geom_last"]
if isinstance(ele, bmesh.types.BMEdge)]
del ret
# Extrude and create geometry on side 'b'
ret = bmesh.ops.extrude_edge_only(
bm,
edges=edges_start_a)
geom_extrude_mid = ret["geom"]
del ret
# Collect the edges to spin XXX, 'extrude_edge_only' could return this.
verts_extrude_b = [ele for ele in geom_extrude_mid
if isinstance(ele, bmesh.types.BMVert)]
edges_extrude_b = [ele for ele in geom_extrude_mid
if isinstance(ele, bmesh.types.BMEdge) and ele.is_boundary]
bmesh.ops.translate(
bm,
verts=verts_extrude_b,
vec=(0.0, 0.0, 1.0))
# Create the circle on side 'b'
ret = bmesh.ops.spin(
bm,
geom=verts_extrude_b + edges_extrude_b,
angle=-math.radians(180.0),
steps=8,
axis=(1.0, 0.0, 0.0),
cent=(0.0, 1.0, 1.0))
edges_end_b = [ele for ele in ret["geom_last"]
if isinstance(ele, bmesh.types.BMEdge)]
del ret
# Bridge the resulting edge loops of both spins 'a & b'
bmesh.ops.bridge_loops(
bm,
edges=edges_end_a + edges_end_b)
# Now we have made a links of the chain, make a copy and rotate it
# (so this looks something like a chain)
ret = bmesh.ops.duplicate(
bm,
geom=bm.verts[:] + bm.edges[:] + bm.faces[:])
geom_dupe = ret["geom"]
verts_dupe = [ele for ele in geom_dupe if isinstance(ele, bmesh.types.BMVert)]
del ret
# position the new link
bmesh.ops.translate(
bm,
verts=verts_dupe,
vec=(0.0, 0.0, 2.0))
bmesh.ops.rotate(
bm,
verts=verts_dupe,
cent=(0.0, 1.0, 0.0),
matrix=mathutils.Matrix.Rotation(math.radians(90.0), 3, 'Z'))
# Done with creating the mesh, simply link it into the scene so we can see it
# Finish up, write the bmesh into a new mesh
me = bpy.data.meshes.new("Mesh")
bm.to_mesh(me)
bm.free()
# Add the mesh to the scene
scene = bpy.context.scene
obj = bpy.data.objects.new("Object", me)
scene.objects.link(obj)
# Select and make active
scene.objects.active = obj
obj.select = True
Vertex Smooth.
Smooths vertices by using a basic vertex averaging scheme.
Parameters: |
|
---|
Vertext Smooth Laplacian.
Smooths vertices by using Laplacian smoothing propose by. Desbrun, et al. Implicit Fairing of Irregular Meshes using Diffusion and Curvature Flow.
Parameters: |
|
---|
Right-Hand Faces.
Computes an “outside” normal for the specified input faces.
Parameters: |
|
---|
Region Extend.
used to implement the select more/less tools. this puts some geometry surrounding regions of geometry in geom into geom.out.
if use_faces is 0 then geom.out spits out verts and edges, otherwise it spits out faces.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Edge Rotate.
Rotates edges topologically. Also known as “spin edge” to some people. Simple example: [/] becomes [|] then [\].
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Reverse Faces.
Reverses the winding (vertex order) of faces. This has the effect of flipping the normal.
Parameters: |
|
---|
Edge Bisect.
Splits input edges (but doesn’t do anything else). This creates a 2-valence vert.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Mirror.
Mirrors geometry along an axis. The resulting geometry is welded on using merge_dist. Pairs of original/mirrored vertices are welded using the merge_dist parameter (which defines the minimum distance for welding to happen).
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Find Doubles.
Takes input verts and find vertices they should weld to. Outputs a mapping slot suitable for use with the weld verts bmop.
If keep_verts is used, vertices outside that set can only be merged with vertices in that set.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Remove Doubles.
Finds groups of vertices closer then dist and merges them together, using the weld verts bmop.
Parameters: |
|
---|
Auto Merge.
Finds groups of vertices closer then dist and merges them together, using the weld verts bmop. The merges must go from a vert not in verts to one in verts.
Parameters: |
|
---|
Collapse Connected.
Collapses connected vertices
Parameters: |
|
---|
Face-Data Point Merge.
Merge uv/vcols at a specific vertex.
Parameters: |
|
---|
Average Vertices Facevert Data.
Merge uv/vcols associated with the input vertices at the bounding box center. (I know, it’s not averaging but the vert_snap_to_bb_center is just too long).
Parameters: |
|
---|
Point Merge.
Merge verts together at a point.
Parameters: |
|
---|
Collapse Connected UV’s.
Collapses connected UV vertices.
Parameters: |
|
---|
Weld Verts.
Welds verts together (kind-of like remove doubles, merge, etc, all of which use or will use this bmop). You pass in mappings from vertices to the vertices they weld with.
Parameters: |
|
---|
Make Vertex.
Creates a single vertex; this bmop was necessary for click-create-vertex.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Join Triangles.
Tries to intelligently join triangles according to various settings and stuff.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Contextual Create.
This is basically F-key, it creates new faces from vertices, makes stuff from edge nets, makes wire edges, etc. It also dissolves faces.
Three verts become a triangle, four become a quad. Two become a wire edge.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Bridge edge loops with faces.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Grid Fill.
Create faces defined by 2 disconnected edge loops (which share edges).
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Fill Holes.
Fill boundary edges with faces, copying surrounding customdata.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Face Attribute Fill.
Fill in faces with data from adjacent faces.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Edge Loop Fill.
Create faces defined by one or more non overlapping edge loops.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Edge Net Fill.
Create faces defined by enclosed edges.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Edgenet Prepare.
Identifies several useful edge loop cases and modifies them so they’ll become a face when edgenet_fill is called. The cases covered are:
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Rotate.
Rotate vertices around a center, using a 3x3 rotation matrix.
Parameters: |
|
---|
Translate.
Translate vertices by an offset.
Parameters: |
|
---|
Scale.
Scales vertices by an offset.
Parameters: |
|
---|
Transform.
Transforms a set of vertices by a matrix. Multiplies the vertex coordinates with the matrix.
Parameters: |
|
---|
Object Load BMesh.
Loads a bmesh into an object/mesh. This is a “private” bmop.
Parameters: |
|
---|
BMesh to Mesh.
Converts a bmesh to a Mesh. This is reserved for exiting editmode.
Parameters: |
|
---|
Mesh to BMesh.
Load the contents of a mesh into the bmesh. this bmop is private, it’s reserved exclusively for entering editmode.
Parameters: |
|
---|
Individual Face Extrude.
Extrudes faces individually.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Extrude Only Edges.
Extrudes Edges into faces, note that this is very simple, there’s no fancy winged extrusion.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Individual Vertex Extrude.
Extrudes wire edges from vertices.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Connect Verts.
Split faces by adding edges that connect verts.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Connect Verts Across non Planer Faces.
Split faces by connecting edges along non planer faces.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Connect Verts.
Split faces by adding edges that connect verts.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Extrude Faces.
Extrude operator (does not transform)
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Dissolve Verts.
Parameters: |
|
---|
Dissolve Edges.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Dissolve Faces.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Limited Dissolve.
Dissolve planar faces and co-linear edges.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Degenerate Dissolve.
Dissolve edges with no length, faces with no area.
Parameters: |
|
---|
Triangulate.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Un-Subdivide.
Reduce detail in geometry containing grids.
Parameters: |
|
---|
Subdivide Edges.
Advanced operator for subdividing edges with options for face patterns, smoothing and randomization.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Subdivide Edge-Ring.
Take an edge-ring, and supdivide with interpolation options.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Bisect Plane.
Bisects the mesh by a plane (cut the mesh in half).
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Delete Geometry.
Utility operator to delete geometry.
Parameters: |
|
---|
Duplicate Geometry.
Utility operator to duplicate geometry, optionally into a destination mesh.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Split Off Geometry.
Disconnect geometry from adjacent edges and faces, optionally into a destination mesh.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Spin.
Extrude or duplicate geometry a number of times, rotating and possibly translating after each step
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Similar Faces Search.
Find similar faces (area/material/perimeter, ...).
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Similar Edges Search.
Find similar edges (length, direction, edge, seam, ...).
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Similar Verts Search.
Find similar vertices (normal, face, vertex group, ...).
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
UV Rotation.
Cycle the loop UV’s
Parameters: |
|
---|
UV Reverse.
Reverse the UV’s
Parameters: |
|
---|
Color Rotation.
Cycle the loop colors
Parameters: |
|
---|
Color Reverse
Reverse the loop colors.
Parameters: |
|
---|
Edge Split.
Disconnects faces along input edges.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Create Grid.
Creates a grid with a variable number of subdivisions
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Create UV Sphere.
Creates a grid with a variable number of subdivisions
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Create Ico-Sphere.
Creates a grid with a variable number of subdivisions
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Create Suzanne.
Creates a monkey (standard blender primitive).
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Create Cone.
Creates a cone with variable depth at both ends
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Creates a Circle.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Create Cube
Creates a cube.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Bevel.
Bevels edges and vertices
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Beautify Fill.
Rotate edges to create more evenly spaced triangles.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Triangle Fill.
Fill edges with triangles
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Solidify.
Turns a mesh into a shell with thickness
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Face Inset (Individual).
Insets individual faces.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Face Inset (Regions).
Inset or outset face regions.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Wire Frame.
Makes a wire-frame copy of faces.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Pokes a face.
Splits a face into a triangle fan.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Convex Hull
Builds a convex hull from the vertices in ‘input’.
If ‘use_existing_faces’ is true, the hull will not output triangles that are covered by a pre-existing face.
All hull vertices, faces, and edges are added to ‘geom.out’. Any input elements that end up inside the hull (i.e. are not used by an output face) are added to the ‘interior_geom’ slot. The ‘unused_geom’ slot will contain all interior geometry that is completely unused. Lastly, ‘holes_geom’ contains edges and faces that were in the input and are part of the hull.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |
Symmetrize.
Makes the mesh elements in the “input” slot symmetrical. Unlike normal mirroring, it only copies in one direction, as specified by the “direction” slot. The edges and faces that cross the plane of symmetry are split as needed to enforce symmetry.
All new vertices, edges, and faces are added to the “geom.out” slot.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict with string keys |