Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- from math import cos
- pi = 3.1415
- lat = bpy.data.lattices['Lattice']
- obj = bpy.data.objects['Lattice']
- # Space
- def lattice_index_from_uvw(lat, u, v, w):
- totu = lat.points_u
- totv = lat.points_v
- return w * (totu * totv) + (v * totu) + u
- points = obj.data.points
- 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
- x0 = [points[lattice_index_from_uvw(lat, u, 0, 0)].co_deform.x for u in range(lat.points_u)]
- A = Delta_x / 3
- Lambda = 10 * Delta_x
- # Time
- scn = bpy.context.scene
- frame_start = scn.frame_start
- frame_end = scn.frame_end
- Delta_t = 1
- T = frame_end - frame_start
- def sine_wave(x, t, A, T, Lambda):
- return A * cos(2 * pi * ( (t / T) - (x / Lambda)))
- def update_wave(t):
- for u in range(lat.points_u):
- for v in range(lat.points_v):
- for w in range(lat.points_w):
- points[lattice_index_from_uvw(lat, u, v, w)].co_deform.x = x0[u] + sine_wave(x0[u], t, A, T, Lambda)
- def my_handler(scene):
- print(scene.frame_current)
- update_wave(scene.frame_current * Delta_t)
- bpy.app.handlers.frame_change_pre.append(my_handler)
Add Comment
Please, Sign In to add comment