ManimCommunity / manim

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

Certain shapes in SVGs generated by chemfig are not getting animated properly #2600

Open Ashvin-Ranjan opened 2 years ago

Ashvin-Ranjan commented 2 years ago

Description of bug / unexpected behavior

When using <: to generate a dashed triangle bond a line is animated. Which is similar to - which is a single bond in chemfig.

Expected behavior

The expected behavior is that it should instead animate a dashed triangle, which is in the SVG but not the final video. (example in media)

How to reproduce the issue

While I am using my own fork of chanim at the moment, this issue is reproducable just using the chemfig LaTeX package and I will include both ways that I have found

Code for reproducing the problem ```py from chanim import * from manim import * class ChemDraw(Scene): def construct(self): chem = ChemObject("A<:B") self.play(Write(chem)) self.wait() ``` or alternatively one can do ```py from manim import * class ChemDraw(Scene): def construct(self): template = TexTemplate() template.add_to_preamble(r"\usepackage{chemfig}") chem = MathTex(r"\chemfig{A<:B}", tex_template=template) self.play(Write(chem)) self.wait() ```

Additional media files

Images/GIFs Generated SVG: ![1dc07a32371e8051](https://user-images.githubusercontent.com/49772172/156944434-c8774915-8d04-4bd0-a036-5735fc17726e.svg) Output: https://user-images.githubusercontent.com/49772172/156944453-6795ae88-d645-4467-bc3c-400b85989dbc.mp4

Logs

Terminal output ``` Manim Community v0.15.0 [03/06/22 14:16:20] INFO Writing \chemfig{A<:B} to media\Tex\1dc07a32371e8051.tex tex_file_writing.py:87 [03/06/22 14:16:22] DEBUG Hashing ... hashing.py:343 DEBUG Hashing done in 0.024713 s. hashing.py:355 DEBUG Hash generated : 450974505_3335814269_223132457 hashing.py:358 DEBUG List of the first few animation hashes of the scene: ['450974505_3335814269_223132457'] cairo_renderer.py:84 [03/06/22 14:16:24] INFO Animation 0 : Partial movie file written in 'C:\Users\Ashvin scene_file_writer.py:500 Ranjan\Desktop\manim\media\videos\chem\1080p60\partial_movie_files\ChemDraw\450974505_3335814269_223132457.mp4' DEBUG Animation with empty mobject animation.py:164 DEBUG Hashing ... hashing.py:343 DEBUG Hashing done in 0.014859 s. hashing.py:355 DEBUG Hash generated : 34786186_3638504700_991896719 hashing.py:358 DEBUG List of the first few animation hashes of the scene: ['450974505_3335814269_223132457', '34786186_3638504700_991896719'] cairo_renderer.py:84 [03/06/22 14:16:25] INFO Animation 1 : Partial movie file written in 'C:\Users\Ashvin scene_file_writer.py:500 Ranjan\Desktop\manim\media\videos\chem\1080p60\partial_movie_files\ChemDraw\34786186_3638504700_991896719.mp4' INFO Combining to Movie file. scene_file_writer.py:594 DEBUG Partial movie files to combine (2 files): ['C:\\Users\\Ashvin scene_file_writer.py:537 Ranjan\\Desktop\\manim\\media\\videos\\chem\\1080p60\\partial_movie_files\\ChemDraw\\450974505_3335814269_223132457.mp4', 'C:\\Users\\Ashvin Ranjan\\Desktop\\manim\\media\\videos\\chem\\1080p60\\partial_movie_files\\ChemDraw\\34786186_3638504700_991896719.mp4'] INFO scene_file_writer.py:715 File ready at 'C:\Users\Ashvin Ranjan\Desktop\manim\media\videos\chem\1080p60\ChemDraw.mp4' INFO Rendered ChemDraw scene.py:240 Played 2 animations [03/06/22 14:16:26] INFO Previewed File at: 'C:\Users\Ashvin Ranjan\Desktop\manim\media\videos\chem\1080p60\ChemDraw.mp4' ```

System specifications

System Details - OS: Windows 10 Home 10.0.19043 Build 19043 - RAM: 16 GB - Python version: 3.9.1 - Installed modules: ```absl-py 0.13.0 aiofile 3.5.0 aiohttp 3.7.4.post0 altgraph 0.17 antlr4-python3-runtime 4.9 appdirs 1.4.4 asgiref 3.3.4 astroid 2.4.2 astunparse 1.6.3 async-timeout 3.0.1 attrs 20.3.0 auto-py-to-exe 2.7.11 backports.cached-property 1.0.1 beautifulsoup4 4.9.3 black 22.1.0 bottle 0.12.19 bottle-websocket 0.2.9 bs4 0.0.1 CacheControl 0.12.10 cachetools 4.2.2 cachy 0.3.0 caio 0.8.0 certifi 2020.12.5 cffi 1.14.4 chanim 1.0.2.1 chardet 3.0.4 charset-normalizer 2.0.4 clang 5.0 cleo 0.8.1 click 8.0.1 click-default-group 1.2.2 clikit 0.6.2 cloup 0.7.1 colorama 0.4.4 colour 0.1.5 commonmark 0.9.1 crashtest 0.3.1 dataclasses 0.6 decorator 5.1.0 discord 1.0.1 discord.py 1.7.3 discord-webhook 0.14.0 discordhelp 1.0.5 distlib 0.3.4 dnspython 2.1.0 EditorConfig 0.12.3 Eel 0.12.4 emoji 0.6.0 emojis 0.6.0 EZPaginator 1.3.4 filelock 3.4.2 Flask 2.0.1 Flask-Cors 3.0.10 flatbuffers 1.12 future 0.18.2 gast 0.4.0 gevent 21.1.2 gevent-websocket 0.10.1 glcontext 2.3.4 google-auth 1.35.0 google-auth-oauthlib 0.4.5 google-pasta 0.2.0 googletrans 4.0.0rc1 greenlet 1.0.0 grpcio 1.39.0 gTTS 2.2.1 h11 0.9.0 h2 3.2.0 h5py 3.1.0 hiredis 2.0.0 hpack 3.0.0 hstspreload 2020.12.22 html5lib 1.1 httpcore 0.9.1 httpx 0.13.3 hyperframe 5.2.0 idna 2.10 isort 5.7.0 isosurfaces 0.1.0 itsdangerous 2.0.1 Jinja2 3.0.1 joblib 1.0.1 jsbeautifier 1.14.0 keras 2.6.0 Keras-Preprocessing 1.1.2 keyring 21.8.0 lark 0.11.1 lark-parser 0.11.2 lazy-object-proxy 1.4.3 lockfile 0.12.2 loguru 0.5.3 manim 0.15.0 ManimPango 0.4.0.post2 mapbox-earcut 0.12.10 Markdown 3.3.4 MarkupSafe 2.0.1 mathterpreter 1.1.2 mccabe 0.6.1 moderngl 5.6.4 moderngl-window 2.4.0 motor 2.4.0 msgpack 1.0.2 multidict 5.1.0 multipledispatch 0.6.0 mypy-extensions 0.4.3 nanoleaf 0.4.1 nanoleafapi 2.0.0 nbtlib 1.12.0 networkx 2.6.3 nltk 3.6.2 numpy 1.19.5 oauthlib 3.1.1 openai 0.3.0 opencv-python 4.5.4.60 opt-einsum 3.3.0 packaging 20.9 pastel 0.2.1 pathspec 0.9.0 pefile 2019.4.18 pexpect 4.8.0 Pillow 9.0.1 pip 22.0.3 pkginfo 1.8.2 platformdirs 2.4.1 poetry 1.1.12 poetry-core 1.0.7 protobuf 3.17.3 ptyprocess 0.7.0 pyasn1 0.4.8 pyasn1-modules 0.2.8 pycairo 1.20.1 pycparser 2.20 pydub 0.25.1 pyglet 1.5.21 Pygments 2.10.0 pyinstaller 4.2 pyinstaller-hooks-contrib 2021.1 pylev 1.4.0 pylint 2.6.0 pymongo 3.12.0 pyparsing 3.0.7 pyrr 0.10.3 Python-NBT 1.2.0 pytube 11.0.2 pywin32-ctypes 0.2.0 redis 3.5.3 regex 2021.3.17 requests 2.26.0 requests-oauthlib 1.3.0 requests-toolbelt 0.9.1 rfc3986 1.4.0 rich 10.12.0 rsa 4.7.2 rstr 2.2.6 scipy 1.8.0 screeninfo 0.8 setuptools 60.9.3 shellingham 1.4.0 six 1.15.0 skia-pathops 0.7.1 sniffio 1.2.0 soupsieve 2.2.1 srt 3.5.2 sseclient 0.0.27 structlog 21.5.0 tensorboard 2.6.0 tensorboard-data-server 0.6.1 tensorboard-plugin-wit 1.8.0 tensorflow 2.6.0 tensorflow-estimator 2.6.0 termcolor 1.1.0 tflearn 0.5.0 toml 0.10.2 tomli 2.0.1 tomlkit 0.9.0 tqdm 4.63.0 typed-ast 1.4.2 typing_extensions 4.1.1 ujson 4.0.2 urllib3 1.26.5 virtualenv 20.13.1 waitress 2.0.0 watchdog 2.1.6 webencodings 0.5.1 websockets 9.1 Werkzeug 2.0.1 wheel 0.37.0 whichcraft 0.6.1 win32-setctime 1.0.3 wrapt 1.12.1 yarl 1.6.3 zalgo-text 0.6 zope.event 4.5.0 zope.interface 5.2.0 ```
LaTeX details + LaTeX distribution: `MiKTeX Package Manager 4.2 (MiKTeX 22.1)` + Installed LaTeX packages: ``` i 00609 6211653 amsfonts i 00010 264547 amsmath i 00155 1063117 arabi i 00002 24708 atbegshi i 00002 19336 atveryend i 00175 1224330 avantgar i 00700 2054196 babel i 00009 26404 babel-english i 00002 31735335 biber-windows-x64 i 00119 2382509 biblatex i 00012 184284 bibtex i 00002 47295 blindtext i 00211 1389763 bookman i 00011 267269 cbcoptic i 00003 119944 chemfig i 00201 889884 cm i 00184 1258125 courier i 00259 427180 csfonts i 00083 694149 csplain i 00005 228036 dehyph i 00029 291149 doublestroke i 00005 134603 dvipdfmx i 00077 360113 dvips i 01233 2573583 ec i 00004 55934 elhyphen i 00041 168694 enctex i 00002 4378 environ i 00003 18279 epstopdf-pkg i 00003 49224 etoolbox i 00003 5428 everyshi i 00034 65485 fontconfig i 00006 319117 fontspec i 00004 206680 fundus-calligra i 00214 1401722 ghostscript i 00021 105234 graphics i 00004 4638 graphics-cfg i 00007 82572 graphics-def i 00340 2456296 helvetic i 00031 784199 hyperref i 00341 9954809 hyph-utf8 i 00007 10283 iftex i 00020 39219 jknappen i 00026 129229 knuth-lib i 00008 199847 l3backend i 00024 1372422 l3kernel i 00010 249736 l3packages i 00004 12752 latex-firstaid i 00055 123937 latex-fonts i 00046 355927 latex-tools i 00008 563013 listings i 01079 41294456 lm i 00166 2197214 ltxbase i 00037 700981 lualibs i 00091 7487370 luaotfload i 00002 5870 luatex85 i 00063 204500 make4ht i 00007 25902 metafont i 00083 246563 metapost i 00030 454637 microtype i 00002 245432 miktex-arctrl-bin-x64-2.9 i 00002 5156313 miktex-asymptote-bin-x64-2.9 i 00004 181841 miktex-autosp-bin-x64-2.9 i 00002 141737 miktex-axohelp-bin-x64-2.9 i 00002 249160 miktex-bibarts-bin-x64-2.9 i 00002 315096 miktex-bibtex-bin-x64-2.9 i 00003 443685 miktex-bibtex8bit-bin-x64-2.9 i 00002 106216 miktex-bzip2-bin-x64-2.9 i 00002 1217190 miktex-cairo-bin-x64-2.9 i 00002 140004 miktex-chktex-bin-x64-2.9 i 00009 472093 miktex-cjkutils-bin-x64-2.9 i 00066 52579 miktex-config-2.9 i 00003 2231062 miktex-console-bin-x64-2.9 i 00002 570473 miktex-curl-bin-x64-2.9 i 00003 282925 miktex-cweb-bin-x64-2.9 i 00002 108278 miktex-devnag-bin-x64-2.9 i 00005 3470604 miktex-dict-british i 00007 583103 miktex-dict-english i 00004 1392137 miktex-dict-french i 00010 4347300 miktex-dict-german i 00002 214243 miktex-dvicopy-bin-x64-2.9 i 00009 39776 miktex-dvipdfmx i 00003 1085197 miktex-dvipdfmx-bin-x64-2.9 i 00002 165809 miktex-dvipng-bin-x64-2.9 i 00004 17891 miktex-dvips i 00003 459008 miktex-dvips-bin-x64-2.9 i 00002 9666813 miktex-dvisvgm-bin-x64-2.9 i 00002 467173 miktex-epstopdf-bin-x64-2.9 i 00002 177057 miktex-expat-bin-x64-2.9 i 00002 125152 miktex-findtexmf-bin-x64-2.9 i 00002 271094 miktex-fmt-bin-x64-2.9 i 00003 10349 miktex-fontconfig i 00011 1064081 miktex-fontconfig-bin-x64-2.9 i 00003 413398 miktex-fonts-bin-x64-2.9 i 00002 364344 miktex-freeglut-bin-x64-2.9 i 00002 819690 miktex-freetype2-bin-x64-2.9 i 00002 143093 miktex-fribidixetex-bin-x64-2.9 i 00002 509117 miktex-gd-bin-x64-2.9 i 00006 18659487 miktex-ghostscript-bin-x64 i 00002 236228 miktex-graphite2-bin-x64-2.9 i 00002 891325 miktex-gregorio-bin-x64-2.9 i 00002 179920 miktex-gsf2pk-bin-x64-2.9 i 00002 3859884 miktex-harfbuzz-bin-x64-2.9 i 00002 739272 miktex-hunspell-bin-x64-2.9 i 00004 30619719 miktex-icu-bin-x64 i 00002 362759 miktex-jpeg-bin-x64-2.9 i 00002 88310 miktex-kpathsea-bin-x64-2.9 i 00002 131255 miktex-lacheck-bin-x64-2.9 i 00004 2056 miktex-latex i 00012 4802789 miktex-lcdf-typetools-bin-x64-2.9 i 00002 2004891 miktex-libressl-bin-x64-2.9 i 00004 2499973 miktex-log4cxx-bin-x64-2.9 i 00004 385368 miktex-lua53-bin-x64-2.9 i 00005 137705 miktex-luatex i 00004 19432097 miktex-luatex-bin-x64-2.9 i 00002 217806 miktex-lzma-bin-x64-2.9 i 00002 194977 miktex-m-tx-bin-x64-2.9 i 00002 160008 miktex-makeindex-bin-x64-2.9 i 00002 41204 miktex-md5-bin-x64-2.9 i 00002 732 miktex-metafont i 00002 742623 miktex-metafont-bin-x64-2.9 i 00003 1095384 miktex-metapost-bin-x64-2.9 i 00005 699695 miktex-mfware-bin-x64-2.9 i 00027 119541 miktex-misc i 00006 1018295 miktex-mktex-bin-x64-2.9 i 00004 1590049 miktex-mo-bin-x64-2.9 i 00002 518028 miktex-mpfr-bin-x64-2.9 i 00002 324870 miktex-mpmcli-bin-x64-2.9 i 00002 118571 miktex-mspack-bin-x64-2.9 i 00002 179409 miktex-mthelp-bin-x64-2.9 i 00002 201944 miktex-mtprint-bin-x64-2.9 i 00009 1435591 miktex-omegaware-bin-x64-2.9 i 00002 173724 miktex-patgen-bin-x64 i 00006 2800 miktex-pdftex i 00004 4339506 miktex-pdftex-bin-x64-2.9 i 00002 887705 miktex-pixman-bin-x64-2.9 i 00003 777345 miktex-pmx-bin-x64-2.9 i 00002 260960 miktex-png-bin-x64-2.9 i 00015 7567669 miktex-poppler-bin-x64-2.9 i 00002 81801 miktex-popt-bin-x64-2.9 i 00003 142669 miktex-posix-bin-x64-2.9 i 00003 294089 miktex-ps2pk-bin-x64-2.9 i 00009 593833 miktex-psutils-bin-x64-2.9 i 00014 5157574 miktex-ptex-bin-x64 i 00015 31084062 miktex-qt5-bin-x64 i 00025 8686846 miktex-runtime-bin-x64-2.9 i 00002 214750 miktex-synctex-bin-x64-2.9 i 00002 273137 miktex-tdsutil-bin-x64 i 00002 276216 miktex-teckit-bin-x64-2.9 i 00003 842 miktex-tex i 00002 636621 miktex-tex-bin-x64-2.9 i 00002 86760 miktex-tex2xindy-bin-x64-2.9 i 00003 26711 miktex-tex4ht i 00003 282383 miktex-tex4ht-bin-x64-2.9 i 00002 286925 miktex-texify-bin-x64-2.9 i 00005 696637 miktex-texware-bin-x64-2.9 i 00002 7683334 miktex-texworks-bin-x64-2.9 i 00003 344380 miktex-ttf2pk2-bin-x64-2.9 i 00044 2095801 miktex-ucrt-bin-x64 i 00002 228562 miktex-upmendex-bin-x64 i 00002 128911 miktex-uriparser-bin-x64-2.9 i 00024 13651902 miktex-vc140-bin-x64 i 00003 380606 miktex-web-bin-x64-2.9 i 00003 3914 miktex-xetex i 00002 1271524 miktex-xetex-bin-x64-2.9 i 00003 5119516 miktex-xindy-bin-x64 i 00002 210165 miktex-xml2pmx-bin-x64 i 00004 2769376 miktex-yap-bin-x64-2.9 i 00003 361496 miktex-zip-bin-x64 i 00002 129447 miktex-zlib-bin-x64-2.9 i 00002 58105 miktex-zzip-bin-x64-2.9 i 00002 97582 modes i 00007 154504 mptopdf i 00003 9742 ms i 00155 912870 ncntrsbk i 00047 331411 oberdiek i 00246 1167385 palatino i 00006 226571 pdftex i 00003 29536 pdftexcmds i 00501 4965915 pgf i 00110 3520904 pgfplots i 00005 287118 physics i 00011 105166 plain i 00010 29730 preview i 00002 9244 ragged2e i 00005 324966 relsize i 00018 101828 rsfs i 00028 223320 ruhyphen i 00004 23947 setspace i 00006 341890 simplekv i 00005 64763 standalone i 00014 70529 symbol i 00024 549234 tcolorbox i 00032 117863 tetex i 00010 11095 tex-ini-files i 06924 15575559 tex4ht i 00240 1508359 times i 00181 23377956 tipa i 00002 1380 trimspaces i 00022 132016 ukrhyph i 00019 3167880 unicode-data i 00003 13058 url i 00024 458895 wasy i 00007 190181 wasysym i 00005 73367 xcolor i 00008 394169 xetex i 00015 61159 xkeyval i 00032 175798 zapfchan i 00011 70264 zapfding ```
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version git-2019-12-29-e20c6d9 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 9.2.1 (GCC) 20191125 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf libavutil 56. 38.100 / 56. 38.100 libavcodec 58. 65.100 / 58. 65.100 libavformat 58. 35.101 / 58. 35.101 libavdevice 58. 9.101 / 58. 9.101 libavfilter 7. 70.100 / 7. 70.100 libswscale 5. 6.100 / 5. 6.100 libswresample 3. 6.100 / 3. 6.100 libpostproc 55. 6.100 / 55. 6.100 ```

Additional comments

This issue was also discussed in one of the issues in chanim, specifically only the first part, there is was ruled out to be a problem with manim, not a problem with the software.

kilacoda-old commented 2 years ago

This is a problem with how manim handles (or rather the fact that it doesn't handle) the stroke-dasharray attribute present in the SVGs with those hatched bonds. There was some discussion and work on it in #1565, but unfortunately that never led anywhere.

At some point in the future we might be refactoring the entire way manim parses SVGs and thus work on this, but for now hatched bonds are simply not correctly renderable.