Fixed many small errors in this script.

This is a real mess and should be removed/re-written but until we have a nice clean alignment script and its close to release, have to keep it.
This commit is contained in:
Campbell Barton 2006-07-11 17:59:23 +00:00
parent b54d5809c4
commit 0d9002354f

@ -268,7 +268,7 @@ def Sistema(MM,D):
def GloVrt((x,y,z),M): # Devuelve (vector) coords globs de v def GloVrt((x,y,z),M): # Devuelve (vector) coords globs de v
v=Vector([x,y,z,1]) v=Vector([x,y,z,1])
v=VecMultMat(v,M) v*=M #v=VecMultMat(v,M)
v.resize3D() v.resize3D()
return v return v
@ -278,11 +278,11 @@ def Extremo(lista,M=MId): # Devuelve extremos y pto medio de lista de vectores
for v in lista: for v in lista:
va=Vector(list(v)) va=Vector(list(v))
va.resize4D() va.resize4D()
va=VecMultMat(va,M) va*=M #va=VecMultMat(va,M)
for c in range(3): for c in xrange(3):
o1[c]=min(va[c],o1[c]) o1[c]=min(va[c],o1[c])
o2[c]=max(va[c],o2[c]) o2[c]=max(va[c],o2[c])
return [o1,(o1+o2)/2,o2] return [o1,(o1+o2)*0.5,o2]
def Media(lista): #Media def Media(lista): #Media
ctr=Vector([0,0,0]) ctr=Vector([0,0,0])
@ -537,9 +537,11 @@ def bevent(evt):
global me global me
global BfL,BfR,BfS global BfL,BfR,BfS
#print "Event:",evt #print "Event:",evt
os=Blender.Object.GetSelected() os=Blender.Object.GetSelected()
if os: oa= Blender.Scene.GetCurrent().getActiveObject()
oa=os[0] if not oa:
return
##########MENU BUFFER ##########MENU BUFFER
if evt==80: if evt==80:
@ -661,9 +663,11 @@ BfS[0],BfS[1],BfS[2]]
d=sqrt(DotVecs(v,v)) d=sqrt(DotVecs(v,v))
v1=v*numReal.val v1=v*numReal.val
if movekomo.val==1: if movekomo.val==1:
v1 = oaV+v1/d if d: v1 = oaV+v1*(1/d)
else: v1 = oaV
elif movekomo.val==2: elif movekomo.val==2:
v1 = oV+v1/d if d: v1 = oV+v1*(1/d)
else: v1 = oV
elif movekomo.val==3: elif movekomo.val==3:
v1 = oaV+v1 v1 = oaV+v1
o.setLocation(v1) o.setLocation(v1)
@ -696,6 +700,7 @@ aliZ.val * (2*n*random() - n)])
n[akeplanoXYZ.val-1]=1. n[akeplanoXYZ.val-1]=1.
numObjs=-len(os) numObjs=-len(os)
elif akeplano.val==2: n=oa.matrix[akeplanoXYZ.val-1] #plano local elif akeplano.val==2: n=oa.matrix[akeplanoXYZ.val-1] #plano local
n= Vector(n) # copy
n.resize3D() n.resize3D()
d=Vector([0.,0.,0.]) d=Vector([0.,0.,0.])
@ -716,7 +721,7 @@ aliZ.val * (2*n*random() - n)])
NI=CopyMat(N) NI=CopyMat(N)
NI.invert() NI.invert()
dN=VecMultMat(d,NI.rotationPart()) dN= d*NI.rotationPart() #VecMultMat(d,NI.rotationPart())
if dN[2]==0: if dN[2]==0:
PupMenu('Error%t|Operacion no permitida: la direccion esta en el plano%x1|Illegal operation: plane contains direction%x2') PupMenu('Error%t|Operacion no permitida: la direccion esta en el plano%x1|Illegal operation: plane contains direction%x2')
return return
@ -728,7 +733,7 @@ aliZ.val * (2*n*random() - n)])
v0=Vector([v[0],v[1],v[2]]) v0=Vector([v[0],v[1],v[2]])
v0=GloVrt(v0,M) v0=GloVrt(v0,M)
v0.resize4D() v0.resize4D()
v0=VecMultMat(v0,NI) v0*= NI #=VecMultMat(v0,NI)
v[0] = v0[0] - v0[2]/dN[2] * dN[0] v[0] = v0[0] - v0[2]/dN[2] * dN[0]
v[1] = v0[1] - v0[2]/dN[2] * dN[1] v[1] = v0[1] - v0[2]/dN[2] * dN[1]
v[2] = 0 v[2] = 0
@ -857,28 +862,28 @@ aliZ.val * (2*n*random() - n)])
P=M*MI P=M*MI
maya=o.getData() maya=o.getData()
for v in maya.verts: for v in maya.verts:
w=list(VecMultMat(Vector([v[0],v[1],v[2],1]),P)) w=list(Vector([v[0],v[1],v[2],1]) * P)
for c in range(3): v[c]=w[c]/o.size[c] for c in xrange(3): v[c]=w[c]/o.size[c]
maya.update() maya.update()
if other.val: if other.val:
P.invert() P.invert()
for oo in Blender.Object.Get(): for oo in Scene.GetCurrent().getChildren():
if oo.data.name==maya.name and o!=oo: try: same= oo.getData(mesh=1).name==maya.name and o!=oo
except: same = False
if same:
N=oo.getMatrix() N=oo.getMatrix()
oo.setMatrix(P*N) oo.setMatrix(P*N)
oo.setSize(oo.SizeX*nSizX.val,oo.SizeY*nSizY.val,oo.SizeZ*nSizZ.val) oo.setSize(oo.SizeX*nSizX.val,oo.SizeY*nSizY.val,oo.SizeZ*nSizZ.val)
if((evt==5 or evt==6) and len(os)): # ENCAJA-ABARCA if(evt==5 or evt==6) and len(os) and oa.getType()=='Mesh': # ENCAJA-ABARCA
enc=[encX.val,encY.val,encZ.val] enc=[encX.val,encY.val,encZ.val]
en2=[en2X.val,en2Y.val,en2Z.val] en2=[en2X.val,en2Y.val,en2Z.val]
me=GetRaw(oa.data.name) me=oa.data
meVs=me.verts meVs= me.verts
for v in meVs: me.transform(oa.matrix)
w=GloVrt(v,oa.matrix) for c in xrange(3):
for c in range(3):
v[c]=w[c]
for c in range(3):
if en2[c] or enc[c]: if en2[c] or enc[c]:
if (len(os)>1): if (len(os)>1):
n1=Extremo(os[1].data.verts,os[1].matrix)[0][c] n1=Extremo(os[1].data.verts,os[1].matrix)[0][c]
@ -898,11 +903,17 @@ aliZ.val * (2*n*random() - n)])
print coo[c],n0,m0,n1,m1,n2,m2 print coo[c],n0,m0,n1,m1,n2,m2
for v in meVs: for v in meVs:
A , factor = 0. , 1. A , factor = 0. , 1.
pm2= None
if enc[c]: if enc[c]:
if evt==5: pm2=(n2+m1)/2 if evt==5: pm2=(n2+m1)*0.5
else: pm2=(m2+n1)/2 else: pm2=(m2+n1)*0.5
v[c]+= pm2-pm v[c]+= pm2-pm
if en2[c] and ancho: if en2[c] and ancho:
if pm2==None:
if evt==5: pm2=(n2+m1)*0.5
else: pm2=(m2+n1)*0.5
v[c]+= pm2-pm
if evt==5: factor=(n2-m1)/ancho if evt==5: factor=(n2-m1)/ancho
else: factor=(m2-n1)/ancho else: factor=(m2-n1)/ancho
v[c]=pm2+(v[c]-pm2)*factor v[c]=pm2+(v[c]-pm2)*factor