ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
24.55k stars 1.72k forks source link

OpenGL insert_n_curves_to_point_list Method points Type Error #3038

Open fangjunzhou opened 1 year ago

fangjunzhou commented 1 year ago

Description of bug / unexpected behavior

Using the latest main branch, run manim render --renderer opengl -p .\example_scenes\basic.py OpeningManim to render the example scene with OpenGL, an error occurs.

Expected behavior

The animation should render successfully.

How to reproduce the issue

Code for reproducing the problem ```py class OpeningManim(Scene): def construct(self): title = Tex(r"This is some \LaTeX") basel = MathTex(r"\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}") VGroup(title, basel).arrange(DOWN) self.play( Write(title), FadeIn(basel, shift=DOWN), ) self.wait() transform_title = Tex("That was a transform") transform_title.to_corner(UP + LEFT) self.play( Transform(title, transform_title), LaggedStart(*(FadeOut(obj, shift=DOWN) for obj in basel)), ) self.wait() grid = NumberPlane() grid_title = Tex("This is a grid", font_size=72) grid_title.move_to(transform_title) self.add(grid, grid_title) # Make sure title is on top of grid self.play( FadeOut(title), FadeIn(grid_title, shift=UP), Create(grid, run_time=3, lag_ratio=0.1), ) self.wait() grid_transform_title = Tex( r"That was a non-linear function \\ applied to the grid", ) grid_transform_title.move_to(grid_title, UL) grid.prepare_for_nonlinear_transform() self.play( grid.animate.apply_function( lambda p: p + np.array( [ np.sin(p[1]), np.sin(p[0]), 0, ], ), ), run_time=3, ) self.wait() self.play(Transform(grid_title, grid_transform_title)) self.wait() ```

Additional media files

Images/GIFs

Logs

Terminal output ``` (manim-py3.10) PS D:\Python Projects\manim-exercise\manim> manim render --renderer opengl -p .\example_scenes\basic.py OpeningManim Manim Community v0.16.0.post0 ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ D:\Python Projects\manim-exercise\manim\manim\cli\render\commands.py:97 in render │ │ │ │ 94 │ │ │ │ for SceneClass in scene_classes_from_file(file): │ │ 95 │ │ │ │ │ with tempconfig({}): │ │ 96 │ │ │ │ │ │ scene = SceneClass(renderer) │ │ ❱ 97 │ │ │ │ │ │ rerun = scene.render() │ │ 98 │ │ │ │ │ if rerun or config["write_all"]: │ │ 99 │ │ │ │ │ │ renderer.num_plays = 0 │ │ 100 │ │ │ │ │ │ continue │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\scene\scene.py:223 in render │ │ │ │ 220 │ │ """ │ │ 221 │ │ self.setup() │ │ 222 │ │ try: │ │ ❱ 223 │ │ │ self.construct() │ │ 224 │ │ except EndSceneEarlyException: │ │ 225 │ │ │ pass │ │ 226 │ │ except RerunSceneException as e: │ │ │ │ D:\Python Projects\manim-exercise\manim\example_scenes\basic.py:31 in construct │ │ │ │ 28 │ │ │ │ 29 │ │ transform_title = Tex("That was a transform") │ │ 30 │ │ transform_title.to_corner(UP + LEFT) │ │ ❱ 31 │ │ self.play( │ │ 32 │ │ │ Transform(title, transform_title), │ │ 33 │ │ │ LaggedStart(*(FadeOut(obj, shift=DOWN) for obj in basel)), │ │ 34 │ │ ) │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\scene\scene.py:1033 in play │ │ │ │ 1030 │ │ │ return │ │ 1031 │ │ │ │ 1032 │ │ start_time = self.renderer.time │ │ ❱ 1033 │ │ self.renderer.play(self, *args, **kwargs) │ │ 1034 │ │ run_time = self.renderer.time - start_time │ │ 1035 │ │ if subcaption: │ │ 1036 │ │ │ if subcaption_duration is None: │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\utils\caching.py:65 in wrapper │ │ │ │ 62 │ │ │ "List of the first few animation hashes of the scene: %(h)s", │ │ 63 │ │ │ {"h": str(self.animations_hashes[:5])}, │ │ 64 │ │ ) │ │ ❱ 65 │ │ func(self, scene, *args, **kwargs) │ │ 66 │ │ │ 67 │ return wrapper │ │ 68 │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\renderer\opengl_renderer.py:424 in play │ │ │ │ 421 │ │ self.file_writer.begin_animation(not self.skip_animations) │ │ 422 │ │ │ │ 423 │ │ scene.compile_animation_data(*args, **kwargs) │ │ ❱ 424 │ │ scene.begin_animations() │ │ 425 │ │ if scene.is_current_animation_frozen_frame(): │ │ 426 │ │ │ self.update_frame(scene) │ │ 427 │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\scene\scene.py:1163 in begin_animations │ │ │ │ 1160 │ │ """Start the animations of the scene.""" │ │ 1161 │ │ for animation in self.animations: │ │ 1162 │ │ │ animation._setup_scene(self) │ │ ❱ 1163 │ │ │ animation.begin() │ │ 1164 │ │ │ │ 1165 │ │ if config.renderer == RendererType.CAIRO: │ │ 1166 │ │ │ # Paint all non-moving objects onto the screen, so they don't │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\animation\transform.py:201 in begin │ │ │ │ 198 │ │ # Note, this potentially changes the structure │ │ 199 │ │ # of both mobject and target_mobject │ │ 200 │ │ if config.renderer == RendererType.OPENGL: │ │ ❱ 201 │ │ │ self.mobject.align_data_and_family(self.target_copy) │ │ 202 │ │ else: │ │ 203 │ │ │ self.mobject.align_data(self.target_copy) │ │ 204 │ │ super().begin() │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\mobject\opengl\opengl_mobject.py:2306 in │ │ align_data_and_family │ │ │ │ 2303 │ │ │ 2304 │ def align_data_and_family(self, mobject): │ │ 2305 │ │ self.align_family(mobject) │ │ ❱ 2306 │ │ self.align_data(mobject) │ │ 2307 │ │ │ 2308 │ def align_data(self, mobject): │ │ 2309 │ │ # In case any data arrays get resized when aligned to shader data │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\mobject\opengl\opengl_mobject.py:2314 in │ │ align_data │ │ │ │ 2311 │ │ for mob1, mob2 in zip(self.get_family(), mobject.get_family()): │ │ 2312 │ │ │ # Separate out how points are treated so that subclasses │ │ 2313 │ │ │ # can handle that case differently if they choose │ │ ❱ 2314 │ │ │ mob1.align_points(mob2) │ │ 2315 │ │ │ for key in mob1.data.keys() & mob2.data.keys(): │ │ 2316 │ │ │ │ if key == "points": │ │ 2317 │ │ │ │ │ continue │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\mobject\opengl\opengl_vectorized_mobject.py:1220 │ │ in align_points │ │ │ │ 1217 │ │ │ sp2 = get_nth_subpath(subpaths2, n) │ │ 1218 │ │ │ diff1 = max(0, (len(sp2) - len(sp1)) // nppc) │ │ 1219 │ │ │ diff2 = max(0, (len(sp1) - len(sp2)) // nppc) │ │ ❱ 1220 │ │ │ sp1 = self.insert_n_curves_to_point_list(diff1, sp1) │ │ 1221 │ │ │ sp2 = self.insert_n_curves_to_point_list(diff2, sp2) │ │ 1222 │ │ │ new_subpaths1.append(sp1) │ │ 1223 │ │ │ new_subpaths2.append(sp2) │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\mobject\opengl\opengl_vectorized_mobject.py:1271 │ │ in insert_n_curves_to_point_list │ │ │ │ 1268 │ │ if len(points) == 1: │ │ 1269 │ │ │ return np.repeat(points, nppc * n, 0) │ │ 1270 │ │ │ │ ❱ 1271 │ │ bezier_groups = self.get_bezier_tuples_from_points(points) │ │ 1272 │ │ norms = np.array([np.linalg.norm(bg[nppc - 1] - bg[0]) for bg in bezier_groups]) │ │ 1273 │ │ total_norm = sum(norms) │ │ 1274 │ │ # Calculate insertions per curve (ipc) │ │ │ │ D:\Python Projects\manim-exercise\manim\manim\mobject\opengl\opengl_vectorized_mobject.py:717 in │ │ get_bezier_tuples_from_points │ │ │ │ 714 │ │ nppc = self.n_points_per_curve │ │ 715 │ │ remainder = len(points) % nppc │ │ 716 │ │ points = points[: len(points) - remainder] │ │ ❱ 717 │ │ return points.reshape((-1, nppc, 3)) │ │ 718 │ │ │ 719 │ def get_bezier_tuples(self): │ │ 720 │ │ return self.get_bezier_tuples_from_points(self.points) │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ AttributeError: 'list' object has no attribute 'reshape' ```

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Windows Version 10.0.19045 Build 19045 - RAM: 32G - Python version (`python/py/python3 --version`): Python 3.10.6 - Installed modules (provide output from `pip list`): ``` Package Version Editable project location ----------------------------- ------------ --------------------------------------- alabaster 0.7.12 astor 0.8.1 astroid 2.11.7 atomicwrites 1.4.1 attrs 22.1.0 Babel 2.10.3 beautifulsoup4 4.11.1 black 22.10.0 certifi 2022.9.24 cffi 1.15.1 cfgv 3.3.1 charset-normalizer 2.1.1 click 8.1.3 click-default-group 1.2.2 cloup 0.13.1 colorama 0.4.5 colour 0.1.5 commonmark 0.9.1 coverage 6.5.0 cycler 0.11.0 data-science-types 0.2.23 decorator 5.1.1 Deprecated 1.2.13 dill 0.3.5.1 distlib 0.3.6 docutils 0.17.1 execnet 1.9.0 filelock 3.8.0 flake8 3.9.2 flake8-bugbear 21.11.29 flake8-builtins 1.5.3 flake8-comprehensions 3.10.0 flake8-docstrings 1.6.0 flake8-plugin-utils 1.3.2 flake8-pytest-style 1.6.0 flake8-rst-docstrings 0.2.7 flake8-simplify 0.14.6 fonttools 4.37.4 furo 2022.9.29 gitdb 4.0.9 GitPython 3.1.28 glcontext 2.3.6 identify 2.5.6 idna 3.4 imagesize 1.4.1 iniconfig 1.1.1 isort 5.10.1 isosurfaces 0.1.0 Jinja2 3.1.2 kiwisolver 1.4.4 lazy-object-proxy 1.7.1 manim 0.16.0.post0 D:\Python Projects\manim-exercise\manim ManimPango 0.4.1 mapbox-earcut 1.0.0 markdown-it-py 2.1.0 MarkupSafe 2.1.1 matplotlib 3.5.3 mccabe 0.6.1 mdit-py-plugins 0.3.1 mdurl 0.1.2 moderngl 5.6.4 moderngl-window 2.4.2 multipledispatch 0.6.0 mypy 0.931 mypy-extensions 0.4.3 myst-parser 0.17.2 networkx 2.6.3 nodeenv 1.7.0 numpy 1.21.6 packaging 21.3 pathspec 0.10.1 Pillow 9.3.0 pip 22.3.1 platformdirs 2.5.2 pluggy 1.0.0 pre-commit 2.20.0 psutil 5.9.2 psutil-wheels 5.8.0 py 1.11.0 pycairo 1.21.0 pycodestyle 2.7.0 pycparser 2.21 pydocstyle 6.1.1 pydub 0.25.1 pyflakes 2.3.1 PyGithub 1.55 pyglet 2.0a4 Pygments 2.13.0 PyJWT 2.5.0 pylint 2.13.9 PyNaCl 1.5.0 pyparsing 3.0.9 pyrr 0.10.3 pytest 6.2.5 pytest-cov 3.0.0 pytest-forked 1.4.0 pytest-xdist 2.5.0 python-dateutil 2.8.2 pytz 2022.4 PyYAML 6.0 recommonmark 0.7.1 requests 2.28.1 restructuredtext-lint 1.4.0 rich 12.6.0 scipy 1.7.3 screeninfo 0.8.1 setuptools 65.4.1 setuptools-scm 6.4.2 six 1.16.0 skia-pathops 0.7.2 smmap 5.0.0 snowballstemmer 2.2.0 soupsieve 2.3.2.post1 Sphinx 4.5.0 sphinx-basic-ng 1.0.0b1 sphinx-copybutton 0.4.0 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.0 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-programoutput 0.17 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 sphinxext-opengraph 0.5.1 srt 3.5.2 svgelements 1.8.4 toml 0.10.2 tomli 2.0.1 tqdm 4.64.1 types-decorator 0.1.7 types-docutils 0.19.1 types-Pillow 8.3.11 types-protobuf 3.20.4 types-Pygments 2.13.1 types-requests 2.28.11.2 types-setuptools 57.4.18 types-urllib3 1.26.25 typing_extensions 4.4.0 urllib3 1.26.12 virtualenv 20.16.5 watchdog 2.1.9 wheel 0.38.4 wrapt 1.14.1 ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): MikTeX + Installed LaTeX packages:
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 2022-08-22-git-f23e3ce858-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers built with gcc 12.1.0 (Rev2, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband libavutil 57. 33.101 / 57. 33.101 libavcodec 59. 42.102 / 59. 42.102 libavformat 59. 30.100 / 59. 30.100 libavdevice 59. 8.101 / 59. 8.101 libavfilter 8. 46.103 / 8. 46.103 libswscale 6. 8.103 / 6. 8.103 libswresample 4. 8.100 / 4. 8.100 libpostproc 56. 7.100 / 56. 7.100 ```

Additional comments

It seems that the points should be numpy array, but in the error message the type is list.

behackl commented 1 year ago

Looks like this would be fixed by #2972