manim icon indicating copy to clipboard operation
manim copied to clipboard

Fixed surface animations in OpenGL

Open nubDotDev opened this issue 5 months ago • 1 comments

Overview: What does this pull request change?

Previously, there was an error whenever animating a Surface object with OpenGL. Now there is no longer!

Motivation and Explanation: Why and how do your changes improve the library?

The bug occurred because the stroke and fill data of a Surface was not passed to the super class. This caused the conversion to an OpenGL object to create an entry in the data dictionary whose datatype is a float instead of the expected array.

Here is a scene to recreate the bug when rendered with --renderer=opengl:

class Test3D(ThreeDScene):
    def construct(self):
        s = Sphere(resolution=(8, 8))
        self.add(s)
        self.play(s.animate.move_to(UP))

Reviewer Checklist

  • [ ] The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • [ ] If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • [ ] If applicable: newly added functions and classes are tested

nubDotDev avatar Jun 13 '25 22:06 nubDotDev

I have tried to run the example code that triggered the issue and can confirm that it prevented the scene from rendering. By placing a few checks on when certain values are floats I was able to navigate around the problem

# Line 2383 in manim/mobject/opengl/opengl_mobject.py
if isinstance(arr1, float):
    arr1 = [[arr1]]
if isinstance(arr2, float):
    arr2 = [[arr2]]

I think that the PR solve the problem in a much cleaner way.

henrikmidtiby avatar Jun 18 '25 19:06 henrikmidtiby