diff --git a/manim/mobject/opengl/opengl_mobject.py b/manim/mobject/opengl/opengl_mobject.py index c02ddd5c72..08473f3ee3 100644 --- a/manim/mobject/opengl/opengl_mobject.py +++ b/manim/mobject/opengl/opengl_mobject.py @@ -10,11 +10,13 @@ import moderngl import numpy as np +from colour import Color from manim import config, logger from manim.constants import * from manim.utils.bezier import integer_interpolate, interpolate from manim.utils.color import * +from manim.utils.color import Colors from manim.utils.config_ops import _Data, _Uniforms # from ..utils.iterables import batch_by_property @@ -144,7 +146,7 @@ def __init__( self.init_updaters() # self.init_event_listners() self.init_points() - self.color = ManimColor.parse(color) + self.color = Color(color) if color else None self.init_colors() self.shader_indices = None @@ -201,10 +203,10 @@ def set_default(cls, **kwargs): >>> from manim import Square, GREEN >>> Square.set_default(color=GREEN, fill_opacity=0.25) >>> s = Square(); s.color, s.fill_opacity - (ManimColor('#83C167'), 0.25) + (, 0.25) >>> Square.set_default() >>> s = Square(); s.color, s.fill_opacity - (ManimColor('#FFFFFF'), 0.0) + (, 0.0) .. manim:: ChangedDefaultTextcolor :save_last_frame: @@ -1969,12 +1971,12 @@ def set_rgba_array_direct(self, rgbas: np.ndarray, name="rgbas", recurse=True): for mob in self.get_family(recurse): mob.data[name] = rgbas.copy() - def set_color(self, color: ParsableManimColor | None, opacity=None, recurse=True): + def set_color(self, color, opacity=None, recurse=True): self.set_rgba_array(color, opacity, recurse=False) # Recurse to submobjects differently from how set_rgba_array # in case they implement set_color differently if color is not None: - self.color: ManimColor = ManimColor.parse(color) + self.color = Color(color) if opacity is not None: self.opacity = opacity if recurse: @@ -2035,7 +2037,7 @@ def set_shadow(self, shadow, recurse=True): # Background rectangle def add_background_rectangle( - self, color: ParsableManimColor | None = None, opacity: float = 0.75, **kwargs + self, color: Colors | None = None, opacity: float = 0.75, **kwargs ): # TODO, this does not behave well when the mobject has points, # since it gets displayed on top @@ -2315,6 +2317,8 @@ def align_data(self, mobject): continue arr1 = mob1.data[key] arr2 = mob2.data[key] + if arr1 is None or arr2 is None: + continue # Or handle this case in a manner appropriate for your program if len(arr2) > len(arr1): mob1.data[key] = resize_preserving_order(arr1, len(arr2)) elif len(arr1) > len(arr2): @@ -2399,7 +2403,7 @@ def construct(self): for key in self.data: if key in self.locked_data_keys: continue - if len(self.data[key]) == 0: + if self.data[key] is None or len(self.data[key]) == 0: continue if key not in mobject1.data or key not in mobject2.data: continue @@ -2723,7 +2727,7 @@ def throw_error_if_no_points(self): class OpenGLGroup(OpenGLMobject): def __init__(self, *mobjects, **kwargs): - if not all(isinstance(m, OpenGLMobject) for m in mobjects): + if not all([isinstance(m, OpenGLMobject) for m in mobjects]): raise Exception("All submobjects must be of type OpenGLMobject") super().__init__(**kwargs) self.add(*mobjects) diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py index d486dc5c76..23ee740e0d 100644 --- a/manim/mobject/opengl/opengl_vectorized_mobject.py +++ b/manim/mobject/opengl/opengl_vectorized_mobject.py @@ -714,7 +714,8 @@ def get_bezier_tuples_from_points(self, points): nppc = self.n_points_per_curve remainder = len(points) % nppc points = points[: len(points) - remainder] - return points.reshape((-1, nppc, 3)) + points_np = np.array(points) + return points_np.reshape((-1, nppc, 3)) def get_bezier_tuples(self): return self.get_bezier_tuples_from_points(self.points) @@ -1301,7 +1302,11 @@ def interpolate(self, mobject1, mobject2, alpha, *args, **kwargs): if self.has_fill(): tri1 = mobject1.get_triangulation() tri2 = mobject2.get_triangulation() - if len(tri1) != len(tri2) or not np.all(tri1 == tri2): + if ( + len(tri1) != len(tri2) + or tri1.shape != tri2.shape + or not np.all(tri1 == tri2) + ): self.refresh_triangulation() return self