Thx, but I must transform only a subset of vertex.
This is the code, from Eeshlo (Great Eeshlo!):
import Blender
from math import *
def vecadd(a,b):
return [a[0]+b[0], a[1]+b[1], a[2]+b[2]]
def vecsub(a,b):
return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]
# multiply 3X3 matrix (rotation, scaling) with vector
def mulmatvec3x3(m, v):
r = [0.0, 0.0, 0.0]
r[0] = v[0]*m[0][0] + v[1]*m[1][0] + v[2]*m[2][0]
r[1] = v[0]*m[0][1] + v[1]*m[1][1] + v[2]*m[2][1]
r[2] = v[0]*m[0][2] + v[1]*m[1][2] + v[2]*m[2][2]
return r
# creates full 3D rotation matrix
# rx, ry, rz angles in radians
def makeRotMtx3D(rx, ry, rz):
A, B = sin(rx), cos(rx)
C, D = sin(ry), cos(ry)
E, F = sin(rz), cos(rz)
AC, BC = A*C, B*C
return [[D*F, D*E, -C],
[AC*F-B*E, AC*E+B*F, A*D],
[BC*F+A*E, BC*E-A*F, B*D]]
# The mesh to be rotated, default Plane
ob = Blender.Object.Get('Plane')
me = ob.data
# The rotation point, an Empty
rotp = Blender.Object.Get('Empty').loc
# translate the rotation point to mesh location
rotp = vecsub(rotp, ob.loc)
# make a rotation matrix,
# as a demo here 10 degrees around Z axis
Rmtx = makeRotMtx3D(0, 0, 10.0*pi/180.0)
# now rotate the points
for v in me.verts:
# subtract rotation point
tv = vecsub(v.co, rotp)
# rotate
nv = mulmatvec3x3(Rmtx, tv)
# add the rotation point back again
nv = vecadd(nv, rotp)
# v.co is now rotated around rotp
v.co[0] = nv[0]
v.co[1] = nv[1]
v.co[2] = nv[2]
Blender.NMesh.PutRaw(me, 'Plane')
Blender.Window.RedrawAll()