Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import bpy
  2. from math import cos
  3.  
  4. pi = 3.1415
  5.  
  6. lat = bpy.data.lattices['Lattice']
  7. obj = bpy.data.objects['Lattice']
  8.  
  9. # Space
  10.  
  11. def lattice_index_from_uvw(lat, u, v, w):
  12. totu = lat.points_u
  13. totv = lat.points_v
  14. return w * (totu * totv) + (v * totu) + u
  15.  
  16. points = obj.data.points
  17.  
  18. Delta_x = points[lattice_index_from_uvw(lat, 1, 0, 0)].co_deform.x - points[lattice_index_from_uvw(lat, 0, 0, 0)].co_deform.x
  19.  
  20. x0 = [points[lattice_index_from_uvw(lat, u, 0, 0)].co_deform.x for u in range(lat.points_u)]
  21.  
  22. A = Delta_x / 3
  23. Lambda = 10 * Delta_x
  24.  
  25. # Time
  26.  
  27. scn = bpy.context.scene
  28.  
  29. frame_start = scn.frame_start
  30. frame_end = scn.frame_end
  31.  
  32. Delta_t = 1
  33. T = frame_end - frame_start
  34.  
  35.  
  36. def sine_wave(x, t, A, T, Lambda):
  37. return A * cos(2 * pi * ( (t / T) - (x / Lambda)))
  38.  
  39. def update_wave(t):
  40. for u in range(lat.points_u):
  41. for v in range(lat.points_v):
  42. for w in range(lat.points_w):
  43. points[lattice_index_from_uvw(lat, u, v, w)].co_deform.x = x0[u] + sine_wave(x0[u], t, A, T, Lambda)
  44.  
  45. def my_handler(scene):
  46. print(scene.frame_current)
  47. update_wave(scene.frame_current * Delta_t)
  48.  
  49. bpy.app.handlers.frame_change_pre.append(my_handler)
Add Comment
Please, Sign In to add comment