diff --git a/manimlib/mobject/types/dot_cloud.py b/manimlib/mobject/types/dot_cloud.py index 6df532fc..28b1713b 100644 --- a/manimlib/mobject/types/dot_cloud.py +++ b/manimlib/mobject/types/dot_cloud.py @@ -4,15 +4,17 @@ import numbers from manimlib.constants import GREY_C from manimlib.mobject.types.point_cloud_mobject import PMobject -from manimlib.mobject.geometry import DEFAULT_DOT_RADIUS from manimlib.utils.iterables import resize_preserving_order +DEFAULT_DOT_CLOUD_RADIUS = 0.05 + + class DotCloud(PMobject): CONFIG = { "color": GREY_C, "opacity": 1, - "radii": DEFAULT_DOT_RADIUS, + "radii": DEFAULT_DOT_CLOUD_RADIUS, "shader_folder": "true_dot", "render_primitive": moderngl.POINTS, "shader_dtype": [ @@ -24,15 +26,12 @@ class DotCloud(PMobject): def __init__(self, points=None, **kwargs): super().__init__(**kwargs) - if points: + if points is not None: self.set_points(points) def init_data(self): - self.data = { - "points": np.zeros((1, 3)), - "rgbas": np.zeros((1, 4)), - "radii": np.zeros((1, 1)) - } + super().init_data() + self.data["radii"] = np.zeros((1, 1)) self.set_radii(self.radii) def set_points_by_grid(self, n_rows, n_cols, height=None, width=None): diff --git a/manimlib/mobject/types/point_cloud_mobject.py b/manimlib/mobject/types/point_cloud_mobject.py index 616e83ca..e2ef6461 100644 --- a/manimlib/mobject/types/point_cloud_mobject.py +++ b/manimlib/mobject/types/point_cloud_mobject.py @@ -11,13 +11,8 @@ class PMobject(Mobject): "opacity": 1.0, } - def init_data(self): - self.data = { - "points": np.zeros((0, 3)), - "rgbas": np.zeros((0, 4)), - } - def resize_points(self, size, resize_func=resize_array): + # TODO for key in self.data: if len(self.data[key]) != size: self.data[key] = resize_array(self.data[key], size) diff --git a/manimlib/mobject/types/surface.py b/manimlib/mobject/types/surface.py index feecb34f..c988a54c 100644 --- a/manimlib/mobject/types/surface.py +++ b/manimlib/mobject/types/surface.py @@ -213,24 +213,25 @@ class TexturedSurface(ParametricSurface): super().__init__(self.uv_func, **kwargs) def init_data(self): + super().init_data() + self.data["im_coords"] = np.zeros((0, 2)) + self.data["opacity"] = np.zeros((0, 1)) + + def init_points(self): nu, nv = self.uv_surface.resolution - self.data = { - "points": self.uv_surface.get_points(), - "im_coords": np.array([ - [u, v] - for u in np.linspace(0, 1, nu) - for v in np.linspace(1, 0, nv) # Reverse y-direction - ]), - "opacity": np.array([self.uv_surface.data["rgbas"][:, 3]]), - } + self.set_points(self.uv_surface.get_points()) + self.data["im_coords"] = np.array([ + [u, v] + for u in np.linspace(0, 1, nu) + for v in np.linspace(1, 0, nv) # Reverse y-direction + ]) def init_uniforms(self): super().init_uniforms() self.uniforms["num_textures"] = self.num_textures def init_colors(self): - # Don't call ParametricSurface color init - pass + self.data["opacity"] = np.array([self.uv_surface.data["rgbas"][:, 3]]) def set_opacity(self, opacity, recurse=True): for mob in self.get_family(recurse): diff --git a/manimlib/mobject/types/vectorized_mobject.py b/manimlib/mobject/types/vectorized_mobject.py index 33282ccc..8d8051f6 100644 --- a/manimlib/mobject/types/vectorized_mobject.py +++ b/manimlib/mobject/types/vectorized_mobject.py @@ -81,19 +81,21 @@ class VMobject(Mobject): return VGroup def init_data(self): - self.data = { - "points": np.zeros((0, 3)), + super().init_data() + self.data.pop("rgbas") + self.data.update({ "fill_rgba": np.zeros((1, 4)), "stroke_rgba": np.zeros((1, 4)), "stroke_width": np.zeros((1, 1)), "unit_normal": np.zeros((1, 3)) - } + }) def set_points(self, points): old_points = self.get_points() super().set_points(points) if not np.all(points == old_points): self.refresh_triangulation() + return self # Colors def init_colors(self):