Skip to content

Commit

Permalink
Change to use OpenGL* for some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Jul 14, 2024
1 parent 90f6de0 commit 25188bf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions example_scenes/test_new_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def construct(self) -> None:
self.add(s)
self.play(Rotate(s, PI / 2))
self.play(FadeOut(s))
sq = Square()
sq = RegularPolygon(6)
c = Circle()
st = Star()
VGroup(sq, c, st).arrange()
Expand All @@ -18,7 +18,7 @@ def construct(self) -> None:
Create(st),
)
)
self.play(*[FadeOut(mob) for mob in self.mobjects])
self.play(FadeOut(VGroup(*self.mobjects)))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion manim/animation/transform_matching_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get_shape_map(self, mobject: Mobject) -> dict:
key = self.get_mobject_key(sm)
if key not in shape_map:
if config["renderer"] == RendererType.OPENGL:
shape_map[key] = OpenGLVGroup()
shape_map[key] = VGroup()
else:
shape_map[key] = VGroup()
shape_map[key].add(sm)
Expand Down
23 changes: 12 additions & 11 deletions manim/mobject/geometry/polygram.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

from manim.constants import *
from manim.mobject.geometry.arc import ArcBetweenPoints
from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVGroup, OpenGLVMobject
from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobject
from manim.mobject.types.vectorized_mobject import VGroup
from manim.utils.color import BLUE, WHITE, ParsableManimColor
from manim.utils.iterables import adjacent_n_tuples, adjacent_pairs
from manim.utils.space_ops import angle_between_vectors, normalize, regular_vertices
Expand Down Expand Up @@ -247,17 +248,17 @@ def construct(self):

if evenly_distribute_anchors:
# Determine the average length of each curve
nonZeroLengthArcs = [arc for arc in arcs if len(arc.points) > 4]
if len(nonZeroLengthArcs):
non_zero_length_arcs = [arc for arc in arcs if len(arc.points) > 4]
if len(non_zero_length_arcs):
totalArcLength = sum(
[arc.get_arc_length() for arc in nonZeroLengthArcs]
[arc.get_arc_length() for arc in non_zero_length_arcs]
)
totalCurveCount = (
sum([len(arc.points) for arc in nonZeroLengthArcs]) / 4
sum([len(arc.points) for arc in non_zero_length_arcs]) / 4
)
averageLengthPerCurve = totalArcLength / totalCurveCount
average_length_per_curve = totalArcLength / totalCurveCount
else:
averageLengthPerCurve = 1
average_length_per_curve = 1

# To ensure that we loop through starting with last
arcs = [arcs[-1], *arcs[:-1]]
Expand All @@ -271,7 +272,7 @@ def construct(self):
# Make sure anchors are evenly distributed, if necessary
if evenly_distribute_anchors:
line.insert_n_curves(
ceil(line.get_length() / averageLengthPerCurve)
ceil(line.get_length() / average_length_per_curve) # type: ignore
)

new_points.extend(line.points)
Expand Down Expand Up @@ -619,7 +620,7 @@ def __init__(
self.stretch_to_fit_height(height)

v = self.get_vertices()
self.grid_lines = OpenGLVGroup()
self.grid_lines = VGroup()

if grid_xstep or grid_ystep:
from manim.mobject.geometry.line import Line
Expand All @@ -629,7 +630,7 @@ def __init__(
if grid_xstep:
grid_xstep = abs(grid_xstep)
count = int(width / grid_xstep)
grid = OpenGLVGroup(
grid = VGroup(
*(
Line(
v[1] + i * grid_xstep * RIGHT,
Expand All @@ -644,7 +645,7 @@ def __init__(
if grid_ystep:
grid_ystep = abs(grid_ystep)
count = int(height / grid_ystep)
grid = OpenGLVGroup(
grid = VGroup(
*(
Line(
v[1] + i * grid_ystep * DOWN,
Expand Down
8 changes: 4 additions & 4 deletions manim/mobject/three_d/three_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
from manim.mobject.geometry.arc import Circle
from manim.mobject.geometry.polygram import Square
from manim.mobject.mobject import *
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
from manim.mobject.opengl.opengl_mobject import OpenGLMobject
from manim.mobject.types.vectorized_mobject import VectorizedPoint, VGroup, VMobject
from manim.mobject.opengl.opengl_vectorized_mobject import OpenGLVMobject
from manim.mobject.types.vectorized_mobject import VectorizedPoint, VGroup
from manim.utils.color import (
ManimColor,
ParsableManimColor,
Expand All @@ -41,12 +41,12 @@
from manim.utils.space_ops import normalize, perpendicular_bisector, z_to_vector


class ThreeDVMobject(VMobject, metaclass=ConvertToOpenGL):
class ThreeDVMobject(OpenGLVMobject):
def __init__(self, shade_in_3d: bool = True, **kwargs):
super().__init__(shade_in_3d=shade_in_3d, **kwargs)


class Surface(VGroup, metaclass=ConvertToOpenGL):
class Surface(VGroup):
"""Creates a Parametric Surface using a checkerboard pattern.
Parameters
Expand Down
3 changes: 2 additions & 1 deletion manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
if TYPE_CHECKING:
from typing_extensions import Self


# TODO
# - Change cubic curve groups to have 4 points instead of 3
# - Change sub_path idea accordingly
Expand Down Expand Up @@ -1885,7 +1886,7 @@ def __str__(self):
f"submobject{'s' if len(self.submobjects) > 0 else ''}"
)

def add(self, *vmobjects: VMobject):
def add(self, *vmobjects: OpenGLVMobject):
"""Checks if all passed elements are an instance of VMobject and then add them to submobjects
Parameters
Expand Down

0 comments on commit 25188bf

Please sign in to comment.