Always call super for init_data

This commit is contained in:
Grant Sanderson
2021-01-14 01:01:13 -10:00
parent 098b939ec0
commit d53dbba346
4 changed files with 25 additions and 28 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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([
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
]),
"opacity": np.array([self.uv_surface.data["rgbas"][:, 3]]),
}
])
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):

View File

@ -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):