2
$\begingroup$

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?

$\endgroup$
4
$\begingroup$

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

Matrix Transformation Space example

  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)

Matrix tutorial:
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

$\endgroup$
  • $\begingroup$ it would appear that the command has been modified ! $\endgroup$ – Ricky Jul 15 '14 at 17:17
  • $\begingroup$ 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 $\endgroup$ – Ricky Jul 15 '14 at 17:18
  • $\begingroup$ I have no idea what you mean. If you don't need a certain transformation space, leave it out. $\endgroup$ – CoDEmanX Jul 15 '14 at 17:22
  • $\begingroup$ 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 $\endgroup$ – Ricky Jul 15 '14 at 17:33
  • $\begingroup$ 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. $\endgroup$ – CoDEmanX Jul 15 '14 at 19:29
1
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.