mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Revert "Merge :class:~.OpenGLMobject and :class:~.Mobject (#1167)"
This reverts commit e18db42ae1.
This commit is contained in:
parent
d8d9a01b9a
commit
39d432e2cd
10 changed files with 1802 additions and 822 deletions
|
|
@ -54,42 +54,13 @@ class InteractiveDevelopment(Scene):
|
|||
# always(circle.move_to, self.mouse_point)
|
||||
|
||||
|
||||
class SquareToCircle(Scene):
|
||||
def construct(self):
|
||||
square = OpenGLSquare()
|
||||
circle = OpenGLCircle()
|
||||
|
||||
self.add(square)
|
||||
self.wait()
|
||||
|
||||
self.play(Transform(square, circle))
|
||||
self.wait()
|
||||
|
||||
|
||||
class UpdaterTest(Scene):
|
||||
def construct(self):
|
||||
squares = OpenGLVGroup()
|
||||
for _ in range(9):
|
||||
squares.add(OpenGLSquare(1, stroke_opacity=0).set_fill(WHITE, 0.5))
|
||||
squares.arrange_in_grid(3, 3, buff=0)
|
||||
|
||||
def line():
|
||||
return OpenGLLine(ORIGIN, squares.get_corner(UL))
|
||||
|
||||
self.add(always_redraw(line))
|
||||
self.play(squares.animate.to_edge(UP))
|
||||
self.play(squares.animate.to_edge(DR))
|
||||
self.play(squares.animate.shift(LEFT * 10))
|
||||
self.wait()
|
||||
|
||||
|
||||
class SurfaceExample(Scene):
|
||||
def construct(self):
|
||||
surface_text = Tex("For 3d scenes, try using surfaces")
|
||||
surface_text.fix_in_frame()
|
||||
surface_text.to_edge(UP)
|
||||
self.add(surface_text)
|
||||
self.wait(0.1)
|
||||
# surface_text = Text("For 3d scenes, try using surfaces")
|
||||
# surface_text.fix_in_frame()
|
||||
# surface_text.to_edge(UP)
|
||||
# self.add(surface_text)
|
||||
# self.wait(0.1)
|
||||
|
||||
torus1 = OpenGLTorus(r1=1, r2=1)
|
||||
torus2 = OpenGLTorus(r1=3, r2=1)
|
||||
|
|
@ -152,6 +123,7 @@ class SurfaceExample(Scene):
|
|||
# light_text = Text("You can move around the light source")
|
||||
# light_text.move_to(surface_text)
|
||||
# light_text.fix_in_frame()
|
||||
|
||||
# self.play(FadeTransform(surface_text, light_text))
|
||||
light = self.camera.light_source
|
||||
self.add(light)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from ..mobject import mobject
|
|||
from ..mobject import opengl_mobject
|
||||
from ..mobject.mobject import Mobject
|
||||
from ..utils.rate_functions import smooth
|
||||
from ..mobject.opengl_mobject import OpenGLMobject
|
||||
|
||||
DEFAULT_ANIMATION_RUN_TIME: float = 1.0
|
||||
DEFAULT_ANIMATION_LAG_RATIO: float = 0.0
|
||||
|
|
@ -63,7 +64,9 @@ class Animation:
|
|||
def _typecheck_input(self, mobject: Mobject) -> None:
|
||||
if mobject is None:
|
||||
logger.debug("creating dummy animation")
|
||||
elif not isinstance(mobject, Mobject):
|
||||
elif not isinstance(mobject, Mobject) and not isinstance(
|
||||
mobject, OpenGLMobject
|
||||
):
|
||||
raise TypeError("Animation only works on Mobjects")
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
|
@ -229,6 +232,9 @@ def prepare_animation(
|
|||
if isinstance(anim, mobject._AnimationBuilder):
|
||||
return anim.build()
|
||||
|
||||
if isinstance(anim, opengl_mobject._AnimationBuilder):
|
||||
return anim.build()
|
||||
|
||||
if isinstance(anim, Animation):
|
||||
return anim
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import numpy as np
|
|||
from ..animation.animation import Animation
|
||||
from ..constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME, DEGREES, OUT
|
||||
from ..mobject.mobject import Group, Mobject
|
||||
from ..mobject.opengl_mobject import OpenGLMobject
|
||||
from ..utils.paths import path_along_arc, straight_path
|
||||
from ..utils.rate_functions import smooth, squish_rate_func
|
||||
|
||||
|
|
@ -217,7 +218,7 @@ class ApplyMethod(Transform):
|
|||
"Whoops, looks like you accidentally invoked "
|
||||
"the method you want to animate"
|
||||
)
|
||||
assert isinstance(method.__self__, Mobject)
|
||||
assert isinstance(method.__self__, (Mobject, OpenGLMobject))
|
||||
|
||||
def create_target(self) -> Mobject:
|
||||
method = self.method
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -214,7 +214,7 @@ class OpenGLArc(OpenGLTipableVMobject):
|
|||
self.arc_center = arc_center
|
||||
OpenGLVMobject.__init__(self, **kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.set_points(
|
||||
OpenGLArc.create_quadratic_bezier_points(
|
||||
angle=self.angle,
|
||||
|
|
@ -383,7 +383,7 @@ class OpenGLAnnularSector(OpenGLArc):
|
|||
**kwargs
|
||||
)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
inner_arc, outer_arc = [
|
||||
OpenGLArc(
|
||||
start_angle=self.start_angle,
|
||||
|
|
@ -429,7 +429,7 @@ class OpenGLAnnulus(OpenGLCircle):
|
|||
**kwargs
|
||||
)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.radius = self.outer_radius
|
||||
outer_circle = OpenGLCircle(radius=self.outer_radius)
|
||||
inner_circle = OpenGLCircle(radius=self.inner_radius)
|
||||
|
|
@ -447,7 +447,7 @@ class OpenGLLine(OpenGLTipableVMobject):
|
|||
self.set_start_and_end_attrs(start, end)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.set_points_by_ends(self.start, self.end, self.buff, self.path_arc)
|
||||
|
||||
def set_points_by_ends(self, start, end, buff=0, path_arc=0):
|
||||
|
|
@ -460,7 +460,7 @@ class OpenGLLine(OpenGLTipableVMobject):
|
|||
|
||||
def set_path_arc(self, new_value):
|
||||
self.path_arc = new_value
|
||||
self.generate_points()
|
||||
self.init_points()
|
||||
|
||||
def account_for_buff(self, buff):
|
||||
if buff == 0:
|
||||
|
|
@ -773,7 +773,7 @@ class OpenGLPolygon(OpenGLVMobject):
|
|||
self.vertices = vertices
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
verts = self.vertices
|
||||
self.set_points_as_corners([*verts, verts[0]])
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -32,7 +32,7 @@ class OpenGLSurfaceMesh(OpenGLVGroup):
|
|||
**kwargs
|
||||
)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
uv_surface = self.uv_surface
|
||||
|
||||
full_nu, full_nv = uv_surface.resolution
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from manim.mobject.mobject import Mobject
|
||||
import numpy as np
|
||||
import moderngl
|
||||
|
||||
from ...constants import *
|
||||
from ...mobject.opengl_mobject import OpenGLMobject
|
||||
from ...utils.bezier import integer_interpolate
|
||||
from ...utils.bezier import interpolate
|
||||
from ...utils.images import get_full_raster_image_path
|
||||
|
|
@ -11,7 +11,7 @@ from ...utils.color import *
|
|||
from ...utils.space_ops import normalize_along_axis
|
||||
|
||||
|
||||
class OpenGLSurface(Mobject):
|
||||
class OpenGLSurface(OpenGLMobject):
|
||||
shader_dtype = [
|
||||
("point", np.float32, (3,)),
|
||||
("du_point", np.float32, (3,)),
|
||||
|
|
@ -67,11 +67,12 @@ class OpenGLSurface(Mobject):
|
|||
self.compute_triangle_indices()
|
||||
|
||||
def uv_func(self, u, v):
|
||||
# To be implemented in subclasses
|
||||
if self.passed_uv_func:
|
||||
return self.passed_uv_func(u, v)
|
||||
return (u, v, 0.0)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
dim = self.dim
|
||||
nu, nv = self.resolution
|
||||
u_range = np.linspace(*self.u_range, nu)
|
||||
|
|
@ -210,7 +211,7 @@ class OpenGLSurfaceGroup(OpenGLSurface):
|
|||
super().__init__(uv_func=None, **kwargs)
|
||||
self.add(*parametric_surfaces)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
pass # Needed?
|
||||
|
||||
|
||||
|
|
@ -253,7 +254,7 @@ class OpenGLTexturedSurface(OpenGLSurface):
|
|||
self.data["im_coords"] = np.zeros((0, 2))
|
||||
self.data["opacity"] = np.zeros((0, 1))
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
nu, nv = self.uv_surface.resolution
|
||||
self.set_points(self.uv_surface.get_points())
|
||||
self.data["im_coords"] = np.array(
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ import moderngl
|
|||
import numpy as np
|
||||
|
||||
from ...constants import *
|
||||
from ...mobject.mobject import Mobject
|
||||
from ...mobject.opengl_mobject import OpenGLPoint
|
||||
from ...mobject.opengl_mobject import OpenGLMobject, OpenGLPoint
|
||||
|
||||
# from manimlib.utils.bezier import get_smooth_quadratic_bezier_handle_points
|
||||
from ...utils.bezier import (
|
||||
|
|
@ -41,7 +40,7 @@ JOINT_TYPE_MAP = {
|
|||
}
|
||||
|
||||
|
||||
class OpenGLVMobject(Mobject):
|
||||
class OpenGLVMobject(OpenGLMobject):
|
||||
fill_dtype = [
|
||||
("point", np.float32, (3,)),
|
||||
("unit_normal", np.float32, (3,)),
|
||||
|
|
@ -116,6 +115,11 @@ class OpenGLVMobject(Mobject):
|
|||
super().__init__(**kwargs)
|
||||
self.refresh_unit_normal()
|
||||
|
||||
#
|
||||
# def get_group_class(self):
|
||||
# return VGroup
|
||||
#
|
||||
|
||||
def init_data(self):
|
||||
super().init_data()
|
||||
self.data.pop("rgbas")
|
||||
|
|
@ -641,7 +645,7 @@ class OpenGLVMobject(Mobject):
|
|||
if not recompute:
|
||||
return self.data["unit_normal"][0]
|
||||
|
||||
if len(self.points) < 3:
|
||||
if len(self.data["points"]) < 3:
|
||||
return OUT
|
||||
|
||||
area_vect = self.get_area_vector()
|
||||
|
|
@ -1003,7 +1007,7 @@ class OpenGLVMobject(Mobject):
|
|||
}
|
||||
|
||||
def get_stroke_shader_data(self):
|
||||
points = self.points
|
||||
points = self.data["points"]
|
||||
stroke_data = np.zeros(len(points), dtype=OpenGLVMobject.stroke_dtype)
|
||||
|
||||
nppc = self.n_points_per_curve
|
||||
|
|
@ -1020,7 +1024,7 @@ class OpenGLVMobject(Mobject):
|
|||
return stroke_data
|
||||
|
||||
def get_fill_shader_data(self):
|
||||
points = self.points
|
||||
points = self.data["points"]
|
||||
fill_data = np.zeros(len(points), dtype=OpenGLVMobject.fill_dtype)
|
||||
fill_data["vert_index"][:, 0] = range(len(points))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,20 @@
|
|||
from manim.mobject.mobject import Mobject
|
||||
from manim.utils.exceptions import EndSceneEarlyException
|
||||
from manim.utils.caching import handle_caching_play
|
||||
from manim.renderer.cairo_renderer import handle_play_like_call
|
||||
from manim.utils.color import color_to_rgba
|
||||
import moderngl
|
||||
from .opengl_renderer_window import Window
|
||||
from .shader_wrapper import ShaderWrapper
|
||||
import numpy as np
|
||||
from ..mobject.types.vectorized_mobject import VMobject
|
||||
import itertools as it
|
||||
import time
|
||||
from .. import logger
|
||||
from ..constants import *
|
||||
from ..utils.space_ops import (
|
||||
cross2d,
|
||||
earclip_triangulation,
|
||||
z_to_vector,
|
||||
quaternion_mult,
|
||||
quaternion_from_angle_axis,
|
||||
rotation_matrix_transpose_from_quaternion,
|
||||
|
|
@ -19,13 +24,13 @@ from ..utils.space_ops import (
|
|||
from ..utils.simple_functions import clip
|
||||
|
||||
from ..mobject import opengl_geometry
|
||||
from ..mobject.opengl_mobject import OpenGLPoint
|
||||
from ..mobject.opengl_mobject import OpenGLMobject, OpenGLPoint
|
||||
from PIL import Image
|
||||
from manim import config
|
||||
from ..scene.scene_file_writer import SceneFileWriter
|
||||
|
||||
|
||||
class OpenGLCamera(Mobject):
|
||||
class OpenGLCamera(OpenGLMobject):
|
||||
def __init__(
|
||||
self,
|
||||
frame_shape=None,
|
||||
|
|
@ -69,7 +74,7 @@ class OpenGLCamera(Mobject):
|
|||
self.data["euler_angles"] = np.array(self.euler_angles, dtype=float)
|
||||
self.refresh_rotation_matrix()
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.set_points([ORIGIN, LEFT, RIGHT, DOWN, UP])
|
||||
self.set_width(self.frame_shape[0], stretch=True)
|
||||
self.set_height(self.frame_shape[1], stretch=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue