Apply Transformation Matrix to Existing Mesh

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. Thus the object-level transformation depicted in the properties panel will remain unchanged.

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()

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

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.

• 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? – TiberiumFusion Jan 23 '19 at 22:49
• 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. :) – Rick Palo Jan 23 '19 at 23:28
• 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. – TiberiumFusion Jan 23 '19 at 23:39
• Run bpy.ops.object.transform_apply(rotation=True) after setting the matrix world. – batFINGER Jan 24 '19 at 6:07