mirror of
https://github.com/3b1b/manim.git
synced 2025-07-28 12:32:36 +08:00
Always call super for init_data
This commit is contained in:
@ -4,15 +4,17 @@ import numbers
|
|||||||
|
|
||||||
from manimlib.constants import GREY_C
|
from manimlib.constants import GREY_C
|
||||||
from manimlib.mobject.types.point_cloud_mobject import PMobject
|
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
|
from manimlib.utils.iterables import resize_preserving_order
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_DOT_CLOUD_RADIUS = 0.05
|
||||||
|
|
||||||
|
|
||||||
class DotCloud(PMobject):
|
class DotCloud(PMobject):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"color": GREY_C,
|
"color": GREY_C,
|
||||||
"opacity": 1,
|
"opacity": 1,
|
||||||
"radii": DEFAULT_DOT_RADIUS,
|
"radii": DEFAULT_DOT_CLOUD_RADIUS,
|
||||||
"shader_folder": "true_dot",
|
"shader_folder": "true_dot",
|
||||||
"render_primitive": moderngl.POINTS,
|
"render_primitive": moderngl.POINTS,
|
||||||
"shader_dtype": [
|
"shader_dtype": [
|
||||||
@ -24,15 +26,12 @@ class DotCloud(PMobject):
|
|||||||
|
|
||||||
def __init__(self, points=None, **kwargs):
|
def __init__(self, points=None, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
if points:
|
if points is not None:
|
||||||
self.set_points(points)
|
self.set_points(points)
|
||||||
|
|
||||||
def init_data(self):
|
def init_data(self):
|
||||||
self.data = {
|
super().init_data()
|
||||||
"points": np.zeros((1, 3)),
|
self.data["radii"] = np.zeros((1, 1))
|
||||||
"rgbas": np.zeros((1, 4)),
|
|
||||||
"radii": np.zeros((1, 1))
|
|
||||||
}
|
|
||||||
self.set_radii(self.radii)
|
self.set_radii(self.radii)
|
||||||
|
|
||||||
def set_points_by_grid(self, n_rows, n_cols, height=None, width=None):
|
def set_points_by_grid(self, n_rows, n_cols, height=None, width=None):
|
||||||
|
@ -11,13 +11,8 @@ class PMobject(Mobject):
|
|||||||
"opacity": 1.0,
|
"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):
|
def resize_points(self, size, resize_func=resize_array):
|
||||||
|
# TODO
|
||||||
for key in self.data:
|
for key in self.data:
|
||||||
if len(self.data[key]) != size:
|
if len(self.data[key]) != size:
|
||||||
self.data[key] = resize_array(self.data[key], size)
|
self.data[key] = resize_array(self.data[key], size)
|
||||||
|
@ -213,24 +213,25 @@ class TexturedSurface(ParametricSurface):
|
|||||||
super().__init__(self.uv_func, **kwargs)
|
super().__init__(self.uv_func, **kwargs)
|
||||||
|
|
||||||
def init_data(self):
|
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
|
nu, nv = self.uv_surface.resolution
|
||||||
self.data = {
|
self.set_points(self.uv_surface.get_points())
|
||||||
"points": self.uv_surface.get_points(),
|
self.data["im_coords"] = np.array([
|
||||||
"im_coords": np.array([
|
[u, v]
|
||||||
[u, v]
|
for u in np.linspace(0, 1, nu)
|
||||||
for u in np.linspace(0, 1, nu)
|
for v in np.linspace(1, 0, nv) # Reverse y-direction
|
||||||
for v in np.linspace(1, 0, nv) # Reverse y-direction
|
])
|
||||||
]),
|
|
||||||
"opacity": np.array([self.uv_surface.data["rgbas"][:, 3]]),
|
|
||||||
}
|
|
||||||
|
|
||||||
def init_uniforms(self):
|
def init_uniforms(self):
|
||||||
super().init_uniforms()
|
super().init_uniforms()
|
||||||
self.uniforms["num_textures"] = self.num_textures
|
self.uniforms["num_textures"] = self.num_textures
|
||||||
|
|
||||||
def init_colors(self):
|
def init_colors(self):
|
||||||
# Don't call ParametricSurface color init
|
self.data["opacity"] = np.array([self.uv_surface.data["rgbas"][:, 3]])
|
||||||
pass
|
|
||||||
|
|
||||||
def set_opacity(self, opacity, recurse=True):
|
def set_opacity(self, opacity, recurse=True):
|
||||||
for mob in self.get_family(recurse):
|
for mob in self.get_family(recurse):
|
||||||
|
@ -81,19 +81,21 @@ class VMobject(Mobject):
|
|||||||
return VGroup
|
return VGroup
|
||||||
|
|
||||||
def init_data(self):
|
def init_data(self):
|
||||||
self.data = {
|
super().init_data()
|
||||||
"points": np.zeros((0, 3)),
|
self.data.pop("rgbas")
|
||||||
|
self.data.update({
|
||||||
"fill_rgba": np.zeros((1, 4)),
|
"fill_rgba": np.zeros((1, 4)),
|
||||||
"stroke_rgba": np.zeros((1, 4)),
|
"stroke_rgba": np.zeros((1, 4)),
|
||||||
"stroke_width": np.zeros((1, 1)),
|
"stroke_width": np.zeros((1, 1)),
|
||||||
"unit_normal": np.zeros((1, 3))
|
"unit_normal": np.zeros((1, 3))
|
||||||
}
|
})
|
||||||
|
|
||||||
def set_points(self, points):
|
def set_points(self, points):
|
||||||
old_points = self.get_points()
|
old_points = self.get_points()
|
||||||
super().set_points(points)
|
super().set_points(points)
|
||||||
if not np.all(points == old_points):
|
if not np.all(points == old_points):
|
||||||
self.refresh_triangulation()
|
self.refresh_triangulation()
|
||||||
|
return self
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
def init_colors(self):
|
def init_colors(self):
|
||||||
|
Reference in New Issue
Block a user