1
$\begingroup$

How can I apply a 3x3 or 4x4 transformation matrix to a mesh such that the matrix's transformation is baked into its geometry?

E.g. applying the following matrix...

\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 0.707 & 0.707 & 0\\ 0 & -0.707 & 0.707 & 0\\ 1 & 0 & 0 & 1\\ \end{bmatrix} ...to the cube primitive should yield the result below, only by changing the mesh's vertices. Example of transformation Thus the object-level transformation depicted in the properties panel will remain unchanged.

$\endgroup$
4
$\begingroup$

Mesh.transform

import bpy
from mathutils import Matrix

ob = bpy.context.object
me = ob.data

M = Matrix(((1, 0, 0, 0),
     (0, 0.707, 0.707, 0),
     (0, -0.707, 0.707, 0),
     (1, 0, 0, 1)))

me.transform(M)
me.update()
$\endgroup$
2
  • 1
    $\begingroup$ ..just curious.. how would you kick a 3D view into refreshing, to display the transformed mesh? $\endgroup$ – Robin Betts Jan 24 '19 at 8:23
  • 2
    $\begingroup$ Edited answer, added a call to mesh update. Personally would do this with bmesh operators, this seemed the simplest answer to this q. $\endgroup$ – batFINGER Jan 24 '19 at 9:19
2
$\begingroup$

If you create the cube and select it, and then go to the python console, the following should produce what you are asking for.

ob=bpy.context.object

ob.matrix_world=((1,0,0,0),(0,.707,.707,0),(0,-.707,.707,0),(1,0,0,1))

I don't know that there is a way to manipulate that directly in the UI.

$\endgroup$
4
  • $\begingroup$ Thanks much, this does indeed help! Yet, this method plainly sets the mesh's object-level transformation. I can then, of course, simply bake the object-level transformation to a mesh, but it's a bit tedious for a mesh with a non-identity object-level transformation. I'd have to note down the object-level transformation, zero it out, use the console to input a matrix (for the object-level transformation), apply the current object-level transformation, then re-input the previously noted object-level transformation. Perhaps there is yet a faster way to bake in a matrix transformation? $\endgroup$ – TiberiumFusion Jan 23 '19 at 22:49
  • $\begingroup$ I'm not sure what you mean by 'bake'. Are you wanting to keyframe, perhaps? Or are you wanting to bake in terms of materials? Do you have something you are trying to accomplish by 'baking'? That might help clarify for me how to do what you want. :) $\endgroup$ – Rick Palo Jan 23 '19 at 23:28
  • $\begingroup$ By "bake", I'm referring to the function of the "Apply Object Transform" operation, which takes the object-level transformation and applies it to the vertices of a mesh. In other words, changing the level at which the transformation exists (from object as a whole -> to vertices), so that the object-level transformation resets to zero and the appearance of the geometry is kept unchanged. Moving every individual vertex (by the matrix) instead of moving the object's position as a whole. It's kind of like taring a scale. $\endgroup$ – TiberiumFusion Jan 23 '19 at 23:39
  • $\begingroup$ Run bpy.ops.object.transform_apply(rotation=True) after setting the matrix world. $\endgroup$ – batFINGER Jan 24 '19 at 6:07

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.