I create a BMesh from a list of vertices like that:

mesh = bpy.data.meshes.new(str(self.shape) + "_Mesh")
obj  = bpy.data.objects.new(str(self.shape) + "_Object", mesh)

bm = bmesh.new()
for v in self.shape.vertices:

It works, the mesh is created, but the rotation is set to 0,0,0.

enter image description here

Any idea how I can set the roation by the rotation of the first face for instance.

I know I can get the normal like this




1 Answer 1


See this answer for an explanation of how to determine the axis you want to rotate around. For example if you have two selected vertices, v1 and v2, this code will generate the necessary axis

axis = (v2.co - v1.co).normalized()

If you want to use the bounding box center of your mesh as the center of rotation you can use

from mathutils import Vector
center = sum((Vector(b) for b in object.bound_box), Vector())
center /= 8

replacing object with whatever object reference you are using.

The mechanism for rotating a bmesh around a standard axis is demonstrated by this code

from mathutils import Matrix, Vector
from math import radians
rotation_X = Matrix.Rotation(radians(45), 4, 'X')
bmesh.ops.rotate(bm, cent=center, matrix=rotation_X, verts=bm.verts)

Replace the quoted X with axis computed above to use an arbitrary axis.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .