Bug fixes

This commit is contained in:
Grant Sanderson
2020-06-07 12:24:54 -07:00
parent 4968c7a8a1
commit 046caa7632

View File

@ -5,6 +5,7 @@ from PIL import Image
from manimlib.constants import * from manimlib.constants import *
from manimlib.mobject.mobject import Mobject from manimlib.mobject.mobject import Mobject
from manimlib.utils.bezier import interpolate
from manimlib.utils.color import color_to_rgba from manimlib.utils.color import color_to_rgba
from manimlib.utils.images import get_full_raster_image_path from manimlib.utils.images import get_full_raster_image_path
from manimlib.utils.space_ops import normalize_along_axis from manimlib.utils.space_ops import normalize_along_axis
@ -68,6 +69,8 @@ class ParametricSurface(Mobject):
# normals, this returns an Nx3 array whose rows are elements from this grid # normals, this returns an Nx3 array whose rows are elements from this grid
# in such such a way that successive triplets of points form triangles covering # in such such a way that successive triplets of points form triangles covering
# the grid. # the grid.
if array.size == 0:
return array
dim = array.shape[1] dim = array.shape[1]
nu, nv = self.resolution nu, nv = self.resolution
assert(array.shape == (nu * nv, dim)) assert(array.shape == (nu * nv, dim))
@ -100,15 +103,14 @@ class ParametricSurface(Mobject):
) )
return normalize_along_axis(normals, 1) return normalize_along_axis(normals, 1)
def set_color(self, color, opacity=1.0, gloss=None, family=True): def set_color(self, color, opacity=1.0, family=True):
# TODO, allow for multiple colors # TODO, allow for multiple colors
rgba = color_to_rgba(color, opacity) rgba = color_to_rgba(color, opacity)
self.rgbas = np.array([rgba]) self.rgbas = np.array([rgba])
if gloss is not None:
self.set_gloss(gloss)
if family: if family:
for submob in self.submobjects: for submob in self.submobjects:
submob.set_color(color, opacity, gloss, family) submob.set_color(color, opacity, family)
return self
def set_opacity(self, opacity, family=True): def set_opacity(self, opacity, family=True):
self.rgbas[:, 3] = opacity self.rgbas[:, 3] = opacity
@ -117,6 +119,10 @@ class ParametricSurface(Mobject):
sm.set_opacity(opacity, family) sm.set_opacity(opacity, family)
return self return self
def interpolate_color(self, mobject1, mobject2, alpha):
self.rgbas = interpolate(mobject1.rgbas, mobject2.rgbas, alpha)
return self
def get_shader_data(self): def get_shader_data(self):
s_points, du_points, dv_points = [ s_points, du_points, dv_points = [
self.get_triangle_ready_array(array) self.get_triangle_ready_array(array)
@ -138,7 +144,8 @@ class ParametricSurface(Mobject):
class SGroup(ParametricSurface): class SGroup(ParametricSurface):
def __init__(self, *parametric_surfaces, **kwargs): def __init__(self, *parametric_surfaces, **kwargs):
super().__init__(**kwargs) # TODO, separate out the surface type...again
super().__init__(uv_func=None, **kwargs)
self.add(*parametric_surfaces) self.add(*parametric_surfaces)
def init_points(self): def init_points(self):