ManimCommunity / manim

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

Objects aren't displayed in front of each other correctly #2644

Open lk-kit opened 2 years ago

lk-kit commented 2 years ago

Description of bug / unexpected behavior

In the attached animation, the cubes in the background jump to the front while the rotation is being displayed

Expected behavior

Correct displaying of the order of the cubes

How to reproduce the issue

Code for reproducing the problem ```py from manim import * class Main(ThreeDScene): def construct(self): self.set_camera_orientation(50 * DEGREES, -50 * DEGREES) cubes = [Cube(1).set_opacity(1).move_to(OUT + LEFT + DOWN), Cube(1).set_opacity(1).move_to(OUT + RIGHT + DOWN), Cube(1).set_opacity(1).move_to(OUT + UP + RIGHT), Cube(1).set_opacity(1).move_to(OUT + UP + LEFT), Cube(1).set_opacity(1).move_to(IN + LEFT + DOWN), Cube(1).set_opacity(1).move_to(IN + RIGHT + DOWN), Cube(1).set_opacity(1).move_to(IN + RIGHT + UP), Cube(1).set_opacity(1).move_to(IN + UP + LEFT)] self.play(Create(VGroup(*cubes))) self.play(Rotate(cubes[4])) self.wait(1) ```

Additional media files

Images/GIFs https://user-images.githubusercontent.com/56817341/161098235-9e16821c-d27e-43a2-afb6-c408ec04a352.mp4

Logs

Terminal output ``` [03/31/22 17:59:11] DEBUG Hashing ... hashing.py:343 DEBUG Hashing done in 0.033465 s. hashing.py:355 DEBUG Hash generated : 3415900677_1391804517_223132457 hashing.py:358 INFO Animation 0 : Using cached data (hash : 3415900677_1391804517_223132457) cairo_renderer.py:75 DEBUG List of the first few animation hashes of the scene: ['3415900677_1391804517_223132457'] cairo_renderer.py:84 DEBUG Hashing ... hashing.py:343 DEBUG Hashing done in 0.047306 s. hashing.py:355 DEBUG Hash generated : 4137296323_734229617_1121976359 hashing.py:358 INFO Animation 1 : Using cached data (hash : 4137296323_734229617_1121976359) cairo_renderer.py:75 DEBUG List of the first few animation hashes of the scene: ['3415900677_1391804517_223132457', '4137296323_734229617_1121976359'] cairo_renderer.py:84 DEBUG Animation with empty mobject animation.py:164 DEBUG Hashing ... hashing.py:343 DEBUG Hashing done in 0.032809 s. hashing.py:355 DEBUG Hash generated : 4137296323_2471300832_1971687172 hashing.py:358 INFO Animation 2 : Using cached data (hash : 4137296323_2471300832_1971687172) cairo_renderer.py:75 DEBUG List of the first few animation hashes of the scene: ['3415900677_1391804517_223132457', '4137296323_734229617_1121976359', '4137296323_2471300832_1971687172'] cairo_renderer.py:84 [03/31/22 17:59:12] INFO Combining to Movie file. scene_file_writer.py:594 DEBUG Partial movie files to combine (3 files): ['C:\\Users\\...\\PycharmProjects\\test\\media\\videos\\test\\1080p60\\partial_movie_files\\Main\\3415900677_1391804517_223132457.mp4', scene_file_writer.py:537 'C:\\Users\\...\\PycharmProjects\\test\\media\\videos\\test\\1080p60\\partial_movie_files\\Main\\4137296323_734229617_1121976359.mp4', 'C:\\Users\\...\\PycharmProjects\\test\\media\\videos\\test\\1080p60\\partial_movie_files\\Main\\4137296323_2471300832_1971687172.mp4'] INFO scene_file_writer.py:715 File ready at 'C:\Users\...\PycharmProjects\test\media\videos\test\1080p60\Main.mp4' INFO Rendered Main scene.py:240 Played 3 animations INFO Previewed File at: 'C:\Users\...\PycharmProjects\test\media\videos\test\1080p60\Main.mp4' ```

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Windows 10 21H2 - RAM: 16 GB - Python version (`python/py/python3 --version`): 3.9 - Installed modules (provide output from `pip list`): ``` Package Version ------------------------- --------- backports.cached-property 1.0.1 certifi 2021.10.8 charset-normalizer 2.0.6 click 8.0.2 click-default-group 1.2.2 cloup 0.7.1 colorama 0.4.4 colour 0.1.5 commonmark 0.9.1 decorator 5.1.0 glcontext 2.3.4 idna 3.2 isosurfaces 0.1.0 manim 0.15.1 ManimPango 0.4.1 mapbox-earcut 0.12.10 moderngl 5.6.4 moderngl-window 2.4.0 multipledispatch 0.6.0 networkx 2.6.3 numpy 1.21.2 Pillow 9.0.1 pip 22.0.4 pycairo 1.20.1 pydub 0.25.1 pyglet 1.5.21 Pygments 2.10.0 pyrr 0.10.3 requests 2.26.0 rich 10.12.0 scipy 1.8.0 screeninfo 0.8 setuptools 57.0.0 six 1.16.0 skia-pathops 0.7.1 srt 3.5.2 stockfish 3.17.0 tqdm 4.62.3 urllib3 1.26.7 watchdog 2.1.6 wheel 0.36.2 ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): MiKTeX + Installed LaTeX packages: Pretty much all of them
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 2021-10-11-git-90a0da9f14-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 10.3.0 (Rev5, 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-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --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-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint libavutil 57. 7.100 / 57. 7.100 libavcodec 59. 12.100 / 59. 12.100 libavformat 59. 6.100 / 59. 6.100 libavdevice 59. 0.101 / 59. 0.101 libavfilter 8. 12.100 / 8. 12.100 libswscale 6. 1.100 / 6. 1.100 libswresample 4. 0.100 / 4. 0.100 libpostproc 56. 0.100 / 56. 0.100 ```
lk-kit commented 2 years ago

I have found a solution to this, by suggestion of LastPrimeNumber on reddit. I don't know why this works, but adding self.begin_ambient_camera_rotation() before playing anything solves this issue. If I understand this correctly, this rotates the camera around the origin, but even setting the rotation rate to 0 solves the issue while not making any visible difference. I will still leave the issue open, since this is a rather hacky way of solving it and a proper solution would be much nicer.

chenyq266 commented 2 years ago

I have found a solution to this, by suggestion of LastPrimeNumber on reddit. I don't know why this works, but adding self.begin_ambient_camera_rotation() before playing anything solves this issue. If I understand this correctly, this rotates the camera around the origin, but even setting the rotation rate to 0 solves the issue while not making any visible difference. I will still leave the issue open, since this is a rather hacky way of solving it and a proper solution would be much nicer.

During each frame of the animation, object which updates its state are rendered at last. But when the camara is rotating, every object updates. I think that may be the reason.

lk-kit commented 2 years ago

Yes, that makes sense, but that is very much not how it is supposed to be.