If I do this (excuse the transpose, I'm used to looking at matrices the other way round):
import bpy
from mathutils import Matrix
ob = bpy.context.object
m = Matrix( ([1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 1, 0] ) )
m.transpose()
for vert in ob.data.vertices:
vert.co = m @ vert.co
I get a translation of the mesh by 1 in object-Z. Good. So somewhere, vert.co
must be understood to be (x,y,z,w=1)
, otherwise the translation wouldn't be picked up.
However, if I do this:
import bpy
from mathutils import Matrix
ob = bpy.context.object
m = Matrix( ([1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 1],
[0, 0, 0, 0] ) )
m.transpose()
for vert in ob.data.vertices:
vert.co = m @ vert.co
.. I'm hoping for a basic perspective transform, in which the w
of every coordinate is set to its z
, and then, in normalization, the whole coordinate is divided through by its w
before using its x,y,z
. But, OK, nothing happens.
Is there any way of getting at the implicit 'w' of the homogeneous vector, or do I have to divide it by hand?
Is there a way using matrix multiplication like this to make projections in the API?
It could be my Blender, it could be my math. I don't know....
w -> 0*x + 0*y + 1*z + 0*w
I don't want to add 1 tow
. $\endgroup$w=1
was only meant for the translation, not for the projection. Otherwise you'd be settingw
to zero, which would place the vertex at infinity (and perform a division by zero when attempting to convert to 3D). $\endgroup$