How to use bmesh.ops.transform?

I could not find an example for the Bmesh function:

bmesh.ops.transform(bm, matrix = matrix, space, verts_extrude_b1)


What is the matrix argument and what do you pass it?

bmesh.ops.transform() expects a 3x3 rotation matrix or 4x4 transformation matrix each for matrix and space.

• matrix specifies the desired transformation, which can be anything with a 4x4 matrix (translation, rotation, scaling, skewing, mirroring etc.).

• space specifies the space in which this transformation is supposed to happen in. If not specified, the transformation will happen in local space (object space). If you give it the object's matrix_world, the transformation will happen in global space (world space). But you can give it any desired space if necessary (e.g. to rotate around an arbitrary point in space instead of the object's origin).

Simple example:
Translation in local and global space of an rotated object

1. Mesh with no transformation applied yet. The object is rotated by 45° around X.
2. Translate mesh 1 unit up on Z-axis in local space:
bmesh.ops.transform(bm, matrix=Matrix.Translation((0,0,1)), verts=bm.verts)
3. Same as 1.
4. Translate mesh 1 unit up on Z-axis, but using matrix_world of the object to perform the transformation in global space:
bmesh.ops.transform(bm, matrix=Matrix.Translation((0,0,1)), space=bpy.context.object.matrix_world, verts=bm.verts)

Giving a space-matrix is the same as multiplying the inverse of the transformation space matrix by the transformation matrix and the transformation space matrix:

matrix_world = bpy.context.object.matrix_world
bmesh.ops.transform(bm, matrix=matrix_world.inverted() * Matrix.Translation((0,0,1)) * matrix_world, verts=bm.verts)

• it would appear that the command has been modified ! – Ricky Jul 15 '14 at 17:17
• bmesh.ops.transform(bm, matrix, space, verts)¶ and now need to add space inside the command - now im tryng to make a new primitive and the space ob does not exist yet so how do u deal with that ? thanks happy bl – Ricky Jul 15 '14 at 17:18
• I have no idea what you mean. If you don't need a certain transformation space, leave it out. – CodeManX Jul 15 '14 at 17:22
• I'm making a new primitive with Bmesh and need to transform some verts unless there is another command to do it looks to me that the examples given are for existing ob not while making a new primitive ! thanks – Ricky Jul 15 '14 at 17:33
• It has nothing to do with objects or meshes, existing or not-yet-existing. Bmesh operations are solely performed on bmesh objects, or rather a subset of its geometrical elements - whatever you pass to the bmesh op. – CodeManX Jul 15 '14 at 19:29

A matrix is a 2dimensional array (often 4x4) of values that contains the information needed to perform a transform. One matrix can combine location, rotation and scale information to be applied to an object.

Most of the matrix functions are in mathutils. This page should get you started.

• I know how to use the matrix part – Ricky Jul 15 '14 at 13:13
• but wondering the other one for Space var! what is it how do u set it up – Ricky Jul 15 '14 at 13:14