Skip to content

OpenGLSurface using colorscale changes surface color as it is moved #3115

@alembcke

Description

@alembcke

Description of bug / unexpected behavior

When an OpenGLSurface is created using colorscale the surface changes color as it is moved.

Why is this happening?
When an OpenGLSurface is created using colorscale a copy of the axes the surface is created on is passed to OpenGLSurface to calculate the colors of the surface. When the surface is moved the colors are recalculated based on that copy of the axes.

Why does OpenGLSurface need a copy of the axes?
Unlike a Surface in Cairo, the points and colors of an OpenGLSurface are recalculated whenever anything about the surface is changed, including movements and rotations. To recalculate the colors using colorscale, the [x, y, z] values of each point relative to the axes needs to be known.

How do we fix this?
That is what I am asking. I can submit a PR fixing this issue, but how should it be fixed? Should we have some sort of pointer to the axes, so that when the colors are refreshed the updated axes is known? Or should we add a private attribute to OpenGLSurface to keep track of the original [x, y, z] values of the surface relative to the axes? Are there any other possible solultions?

Expected behavior

The colors of an OpenGLSurface should stay consistent when the surface is moved.

How to reproduce the issue

Code for reproducing the problem
from manim import *
from manim.opengl import *
import numpy as np

class Test(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=-107 * DEGREES)

        axes = ThreeDAxes(
                x_range=[-3, 3, 1],
                y_range=[-3, 3, 1],
                z_range=[-1, 1, 1],
                )

        def func(x, y):
            return np.cos(x) * np.sin(y)

        surface = axes.plot_surface(
            function=func,
            u_range = (-3, 3),
            v_range = (-3, 3),
            resolution = (42, 42),
            fill_opacity = 0.6,
            colorscale = ['#482173', '#2e6f8e', '#29af7f', '#bddf26']
        )

        surface_mobjects = OpenGLGroup(axes, surface)
        surface_mobjects.scale(0.8)

        self.add(surface_mobjects)
        self.play(surface_mobjects.animate.shift(4 * IN))
        self.play(surface_mobjects.animate.shift(8 * OUT))
        self.play(surface_mobjects.animate.shift(4 * IN))

Additional media files

Images/GIFs
Test.mp4

Logs

Terminal output
PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)):
  • RAM:
  • Python version (python/py/python3 --version):
  • Installed modules (provide output from pip list):
PASTE HERE
LaTeX details
  • LaTeX distribution (e.g. TeX Live 2020):
  • Installed LaTeX packages:
FFMPEG

Output of ffmpeg -version:

PASTE HERE

Additional comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions