Skip to content

Commit

Permalink
Fixed opengl Surface with reordering initialization process (#3089)
Browse files Browse the repository at this point in the history
* Fixed opengl Surface with disabling refresh of shader wrapper id in constructor

* Reordered Elements in constructor of opengl_vectorized_mobject to fix initialization dependency issues
  • Loading branch information
MrDiver authored Dec 26, 2022
1 parent d3b96dd commit 7d7c505
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
5 changes: 4 additions & 1 deletion manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2627,12 +2627,15 @@ def set_color_by_xyz_func(
# For shader data

def refresh_shader_wrapper_id(self):
self.shader_wrapper.refresh_id()
self.get_shader_wrapper().refresh_id()
return self

def get_shader_wrapper(self):
from manim.renderer.shader_wrapper import ShaderWrapper

# if hasattr(self, "__shader_wrapper"):
# return self.__shader_wrapper

self.shader_wrapper = ShaderWrapper(
vert_data=self.get_shader_data(),
vert_indices=self.get_shader_vert_indices(),
Expand Down
3 changes: 2 additions & 1 deletion manim/mobject/opengl/opengl_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(
# can crop up in the shaders.
self.epsilon = epsilon

self.triangle_indices = None
super().__init__(
color=color,
opacity=opacity,
Expand Down Expand Up @@ -127,7 +128,7 @@ def init_points(self):
# - Those generated by values nudged by du
# - Those generated by values nudged by dv
point_lists = []
for (du, dv) in [(0, 0), (self.epsilon, 0), (0, self.epsilon)]:
for du, dv in [(0, 0), (self.epsilon, 0), (0, self.epsilon)]:
uv_grid = np.array([[[u + du, v + dv] for v in v_range] for u in u_range])
point_grid = np.apply_along_axis(lambda p: self.uv_func(*p), 2, uv_grid)
point_lists.append(point_grid.reshape((nu * nv, dim)))
Expand Down
12 changes: 6 additions & 6 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def __init__(
self.needs_new_triangulation = True
self.triangulation = np.zeros(0, dtype="i4")
self.orientation = 1
self.fill_data = None
self.stroke_data = None
self.fill_shader_wrapper = None
self.stroke_shader_wrapper = None
self.init_shader_data()

super().__init__(**kwargs)
self.refresh_unit_normal()

Expand All @@ -145,12 +151,6 @@ def __init__(
if stroke_color:
self.stroke_color = Color(stroke_color)

self.fill_data = None
self.stroke_data = None
self.fill_shader_wrapper = None
self.stroke_shader_wrapper = None
self.init_shader_data()

def get_group_class(self):
return OpenGLVGroup

Expand Down
14 changes: 14 additions & 0 deletions tests/opengl/test_opengl_surface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np

from manim.mobject.opengl.opengl_surface import OpenGLSurface
from manim.mobject.opengl.opengl_three_dimensions import OpenGLSurfaceMesh


def test_surface_initialization(using_opengl_renderer):
surface = OpenGLSurface(
lambda u, v: (u, v, u * np.sin(v) + v * np.cos(u)),
u_range=(-3, 3),
v_range=(-3, 3),
)

mesh = OpenGLSurfaceMesh(surface)

0 comments on commit 7d7c505

Please sign in to comment.