import Blender from math import sqrt,sin,pow,pi dpi=2*pi ######### SECCION DE OBJETOS ######## BARCO=1 # Los objetos flotantes deben Llamarse "Barco..." y, # para provocar olas, su coordenada Z debe estar # entre -Hmin y Hmin / # Floating object names must be "Barco..." and, in # order to make ripples, their Z coord must be # btw -Hmin and Hmin visco=2.5 # "Viscosidad" del fluido / Fluid "viscosity" Dmin=0.41 # Sumando corrector >0!! / Correction >0!! veloc=1 # VELOCIDAD de viaje/VELOCITY interv=10 # Ultimos frames a usar en calculo/Num.of frames to consider in the calculus ampl=2 # Amplitud/Amplitude Lon=0.3 # Multiplicador de Long de onda/Wavelenght multiplicator Hmin=1 # Z maxima para que el objeto toque en la superf/Max. Z over Zplane ######### SECCION DE VERTICES ######### ORILLA=1 OLIKAS=1 # Los vertices que aportan olas circulares deben # estar en un grupo llamado "olikas". Los que # aporten olas rectas (se mueven en direccion de su # normal) deben estar en un grupo llamado "orilla". # La fuerza aportada es proporcional a su 'Weight' / # Each circular source vertex must be into a vertex # group called "olikas". The along-normal ripples # emmiters must be in a group called "orilla". # Contributed force is proportional to its 'Weight' visco2=2.3 # "Viscosidad" del fluido / Fluid "viscosity" Dmin2=1.3 # Sumando corrector >0!! / Correction >0!! veloc2=-0.025 # Velocidad:'-'invierte sentido ampl2=0.3 # Amplitud Lon2=4 # Multiplicador de Long de onda/Wavelenght multiplicator sc=Blender.Scene.getCurrent() frame=sc.currentFrame() print "\nComenzando en frame",frame o=Blender.link #o=Blender.Object.Get('Yamamoto') print "Generando olas sobre",o.name me=o.getData() vs=me.verts ol=o.getLocation() os=Blender.Object.Get() def f(o): return o.getName()[:5]=="Barco" and BARCO def peso(grupo,v): #Devuelve 'weight' o 0 si no esta en el grupo i=me.verts.index(v) VI=me.getVertexInfluences(i) for Influ in VI: if Influ[0]==grupo: return Influ[1] return 0 def dist(v,(x,y)): return sqrt((v.co[0]-x)**2+(v.co[1]-y)**2) def dis2(v,(x,y),n): nx,ny=n[0],n[1] return abs(nx*v.co[0]+ny*v.co[1]-(nx*x+ny*y))/sqrt(nx**2+ny**2) print "Buscando barcos..." for o in filter(f,os): print"\tUsando",o.name,"como barco" IPOc=o.ipo for v in vs: suma=0 for a in range(frame)[-interv:]: z=IPOc.EvaluateCurveOn(2,a) if abs(z)(D/veloc): #HA LLEGADO LA OLA AL VERTICE?? xm,ym,zm=IPOc.EvaluateCurveOn(0,a-0.005),IPOc.EvaluateCurveOn(1,a-0.005),IPOc.EvaluateCurveOn(2,a-0.005) xM,yM,zM=IPOc.EvaluateCurveOn(0,a+0.005),IPOc.EvaluateCurveOn(1,a+0.005),IPOc.EvaluateCurveOn(2,a+0.005) vx,vy,vz=xM-xm,yM-ym,zM-zm VB=100*sqrt(vx*vx+vy*vy+vz*vz) # VELOC DEL BARCO suma=suma+sqrt(VB)*sin(dpi*(D-(frame-a)*veloc)/(Lon*ampl))/pow((D+Dmin),visco) v.co[2]=v.co[2]-suma*ampl/interv print "Buscando vertices..." nv1,nv2=0,0 for i in range(len(me.verts)): oV=me.verts[i] VI=me.getVertexInfluences(i) for Influ in VI: x,y=oV.co[0],oV.co[1] SIRVE=0 if Influ[0]=="olikas" and OLIKAS: nv1=nv1+1 SIRVE=1 if Influ[0]=="orilla" and ORILLA: nv2=nv2+1 SIRVE=1 if SIRVE: peso=Influ[1] for v in vs: Dreal=dist(v,(x,y)) if Influ[0]=="olikas": D=Dreal if Influ[0]=="orilla": D=dis2(v,(x,y),oV.no) v.co[2]=v.co[2]-ampl2*peso*sin(dpi*(D-frame*veloc2)/(Lon2*ampl2*peso))/pow((Dreal+Dmin2),visco2) print "*", else: print "-", print"\tUsados",nv1,"emisores circulares y",nv2,"lineales" Blender.NMesh.PutRaw(me,me.name+".Olas")