mirror of
https://github.com/3b1b/manim.git
synced 2026-04-26 03:00:23 -04:00
Add set_image_coords_by_uv_func to TextureSurface
This commit is contained in:
@@ -349,6 +349,20 @@ class TexturedSurface(Surface):
|
||||
for v in np.linspace(1, 0, nv) # Reverse y-direction
|
||||
])
|
||||
|
||||
@Mobject.affects_data
|
||||
def set_image_coords_by_uv_func(self, uv_func) -> Self:
|
||||
"""
|
||||
uv_func takes in a pair (u, v), and returns a new pair (u', v') used
|
||||
for coordinates when reading from the texture
|
||||
"""
|
||||
nu, nv = self.uv_surface.resolution
|
||||
self.data["im_coords"][:] = np.array([
|
||||
uv_func(u, v)
|
||||
for u in np.linspace(0, 1, nu)
|
||||
for v in np.linspace(1, 0, nv) # Reverse y-direction
|
||||
])
|
||||
return self
|
||||
|
||||
def init_uniforms(self):
|
||||
super().init_uniforms()
|
||||
self.uniforms["num_textures"] = self.num_textures
|
||||
|
||||
Reference in New Issue
Block a user