Very beta, I started working on that yesterday night after midnight.
Surpisingly enough duh to the time, it works always for the location, and sometimes for rotation.
I’ll post the code if anyone wants to have a look, but don’t expect much from the code (criptic and uncommented, at least there’s some error handling).
import Blender
from vecf import *
print "
START
"
objL = Blender.Object.GetSelected()
if len(objL) < 2: raise Exception("Must select at least two object")
for obj in objL:
if obj.data.block_type != "NMesh": raise Exception("Must select only Meshes")
for obj in objL:
if len(obj.data.getSelectedFaces()) != 1: raise Exception("Must have only one face selected")
ObjVecL = []
for obj in objL:
vec = [0,0,0]
nor = [0,0,0]
tot = 0
for vert in obj.data.getSelectedFaces()[0]:
vec = vecadd(vec, vert.co)
nor = vecadd(nor, vert.no)
tot += 1
vec = vecmul(vec,1.0/tot)
nor = vecmul(nor,1.0/tot)
vnorm(nor)
ObjVecL.append([obj, vec, mulmatvec4x3(obj.mat,vec),nor, mulmatvec3x3(obj.mat,nor)])
target = ObjVecL.pop(0)
for ObjVec in ObjVecL:
obj = ObjVec[0]
vec = ObjVec[1:3]
nor = ObjVec[3:]
finalloc = vecadd(vecadd(vec[1],proj(vecsub(target[2],vec[1]),target[4])), vecmul(target[4],veclen(vec[0])))
obj.LocX = finalloc[0]
obj.LocY = finalloc[1]
obj.LocZ = finalloc[2]
tmpvec = vecnorm(crossp(target[4],nor[1]))
mat = [target[4],crossp(target[4],tmpvec),tmpvec]
mat1 = transp3x3(mat)
matrot = makeRotMtx("Z",acos(vdot(nor[1],target[4])) + pi)
matini = obj.mat
matini = mulmat(matini,mat,3)
matini = mulmat(matini,matrot,3)
matini = mulmat(matini,mat1,3)
rot = mat2euler_rot(matini)
obj.RotX = rot[0]
obj.RotY = rot[1]
obj.RotZ = rot[2]
Blender.Redraw()
using the vecf module, as always: http://clubinfo.bdeb.qc.ca/~theeth/vecf.py
there’s surely something wrong with the matricial operations, but I was too tired to fix it. Probably tomorrow or next week.
Martin