3b1b / manim

Animation engine for explanatory math videos
MIT License
68.72k stars 6.1k forks source link

Weird line drawing and improper text sizing using manim's example_scenes.py #1405

Closed mrmcsoftware closed 1 year ago

mrmcsoftware commented 3 years ago

ex1 ex2 ex3 ex4

Describe the bug

The first two images show a weird line drawing problem I'm having while running manim's supplied example_scenes.py file. Instead of drawing lines, it draws triangles. I can't imagine that's intended, but let me know if it is. This problem happens in the other example scenes.

The last two images show another problem - the text doesn't fit on the screen correctly. I can change the font to something that will fit, but I probably shouldn't have to. Plus, I imagine the grid should be showing the complete range of -10 to 10 instead of only part of it. So, I guess it's really an image scaling problem and not a text problem. Changing resolution doesn't solve it.

Also, ControlsExample doesn't seem to do anything.

Code: Just refer to example_scenes.py

Additional context

I'm using Python 3.8 on Ubuntu 20.10

mrmcsoftware commented 3 years ago

I tried some other scene (from one of the reported issues that shows what it's supposed to look like) and the results are even worse. BTW, adding to my issue report, to be more precise, my version of Python is 3.8.6

ex5

acnq commented 3 years ago

I am also working around installing the master branch of manim, but my Problem seems more serious Firstly, the mis-size of the text still exist in my version USUN1)0GKNC7 K{1}EQAL1V secondly, a lot of grid in OpeningManimExample is missing, GK~O{~O4Q1LHYR)6`)@}%E8 so does the coordinates in the next Animation ARAVTX_Z1PR_05$ UEA(6E just like the problem reported in issue #1399 https://github.com/3b1b/manim/issues/1399 For other animation "AnimatingMethods", "TextExample", "TexTransformExample", there are always elements as border or grid missing. Though the main part is OK 5GCOUQ627O)AUZ@8SQR4XF7

Finally, the Scene "ControlsExample" can't run with a RecursionError: maximum recursion depth exceeded while calling a Python object LS9XD$~3Q{H2VBF0 (6UN}Q

mrmcsoftware commented 3 years ago

@acnq I have had some success in getting better results by using manim (instead of manimgl) as is mentioned in the comments of example_scenes.py. I had previously tried manim but got very serious errors. But recently I tried fixing the errors (adding an import line to example_scenes.py, commenting out things it said didn't exist, etc.). However, there are still some big errors with some of the scenes. One scene which worked flawlessly in manimgl didn't work at all in manim. And now the modified example_scenes.py won't work in manimgl, IIRC.

lilium724 commented 3 years ago

I had the same problem with the text not fitting, found a temporary fix by changing two lines in manimlib/mobject/svg/text_mobject.py

in

class Text(SVGMobject):
    CONFIG = {
        # Mobject
        "color": WHITE,
        "height": None,
        "stroke_width": 0,
        # Text
        "font": '',
        "gradient": None,
        "lsh": -1,
        "size": 1,
        "font_size": 48,
        "tab_width": 4,
        "slant": NORMAL,
        "weight": NORMAL,
        "t2c": {},
        "t2f": {},
        "t2g": {},
        "t2s": {},
        "t2w": {},
        "disable_ligatures": True,
    }

replace

        "lsh": -1,
        "size": 1,

with

        "lsh": 1,
        "size": 0.68702290076,

It has something to do with the windows scale not being right, and for some reason it only affects Text mobjects (probably something to do with manimpango, idk)

For the rest (ex: the triangles), I'd suggest checking your OpenGL version (with something like glxinfo | grep "OpenGL version"). manimgl uses OpenGL 3.3, so make sure you have at least that.

mrmcsoftware commented 3 years ago

@lilou724 That seems to solve the text problem. But I do wonder what the viewable range of the graph is supposed to be (I'm getting -7 to 7 range on x).

OpenGL version might be the problem on this particular machine. I could try on another system, but that'll be another day :-)

lilium724 commented 3 years ago

@mrmcsoftware -7 to 7 range on x is normal, you can check the OpeningManimExample video at https://3b1b.github.io/manim/getting_started/example_scenes.html to compare if you want

mrmcsoftware commented 3 years ago

@lilou724 Thanks for the link and the info. That's good that the range in correct.

Shafagh777 commented 3 years ago

@lilou724 and @mrmcsoftware I have checked my OpenGL which is version 4.6 and my graphic card is intel UHD graphic and have the same issue with the line. I have run the following code and nothing demonstrated.

from manimlib import *

class shape(Scene):
    def construct(self):
        circle = Circle()
        square = Square()
        self.play(ShowCreation(circle))
        self.play(ShowCreation(square))
        self.wait()

Also, the set_stroke is not working. i have tried the following code and can not change the config of stroke.

from manimlib import *

class shape(Scene):
    def construct(self):
        circle = Circle()
        circle.set_fill(BLUE, opacity=0.5)
        circle.set_stroke(YELLOW, width=7)

        self.play(ShowCreation(circle))
        self.wait()

Please update us if you have any new solutions.

mrmcsoftware commented 3 years ago

@Shafagh777 I also have problems with your examples (lines made up of triangles or other weird shapes), but with your second example, I do get yellow (but with misshapen lines of course). BTW, in the past, many (or some - I don't know how vast the problems were) Intel graphics chipsets were blacklisted by many programs/libraries (WebGL for example) because of problems. I don't know anything about your particular model, but if it's running OpenGL 4.6, it should be new enough that hopefully they fixed the bugs with the chipset. Though I guess it's possible that you could be running software emulation of missing features. I think for me, I'll just have to use manim (not manimgl) to avoid the problems (but I therefore won't get the ability to see the results as it's creating them).

fmq03 commented 3 years ago

I have a problem probably the same as yours. When I use manimgl, I find all texts I render are strange.

For example, I run these in windows cmd( I tried render to a video file ,but it still wrong ):

text=Text("This is a Text")
add(text)

2021-05-01_115332

It happens all the time and has nothing to do with the content of the Text.

Also, there is another problem. When I run the example SquareToCircle, the Circle it render is strange:

circle = Circle()
        square = Square()
        square.flip(RIGHT)
        square.rotate(-3 * TAU / 8)
        circle.set_fill(PINK, opacity=0.5)

        self.play(ShowCreation(square))
        self.play(Transform(square, circle))

2021-05-01_114547

I have not tried some more complex example, so there may be other things wrong that I haven't discoverd.

However, when I use earlier manim version which uses pycairo, everything is fine in my test. I also tried using manimgl on another computer, problems above didn't happen. So I think opengl may be the cause. The problem may be due to my graphics card driver. But I have no idea how to deal with it. My laptop's OEM driver is too old and has no update. The drivers from Intel and NVDIA seem not working on my laptop. Maybe the best solution to me is using the manim with pycairo instead of manim with pyopengl.

Some Information May Help

OS Systrem: Windows8.1 x64.

I tried python3.7.4 and python 3.8.8 in Anaconda environment (In both python versions the problem happens). PyOpengl version is 3.1.5.

CPU: Core i5 4200M,

GPU: Intel HD Ghraphics 4600. It also has NVDIA GeForce 840M. Drivers are from OEM support, not Intel or NVDIA.

The computer successfully run manimgl: Win10 x64 CPU:core i7 7th gen(I can't remember the detail),GPU: maybe Intel nItegrated graphics card, no Discrete graphics card.

mrmcsoftware commented 3 years ago

@fmq03 Mine screws up SquareToCircle, but not in the same way as yours. I seem to be using pycairo (since it is installed), and pyopengl isn't installed (unless it was put in some other directory). I don't know what to tell you, other than make sure your opengl is at least 3.3 (the opengl standard, not necessarily the python version number (I hope I said that right)).

llwanghong commented 1 year ago

Just following MacOS installation instructions and running OpeningManimExample, it's terrible, all texts with glitches...

Any help appreciated~

brew update
brew upgrade
brew install ffmpeg mactex

conda create -n manim python=3.8
conda activate manim

git clone https://github.com/3b1b/manim.git
cd manim
pip install -e .
manimgl example_scenes.py OpeningManimExample

Environment infomation: OS Systrem: macOS Big Sur version 11.3.1 CPU: 2.6GHz 6-Core Intel Core i7 Graphics: Intel HD Ghraphics 630 1536MB Python: 3.8.16 FFmpeg: 5.1.2 Latex: pdfTeX 3.141592653-2.6-1.40.24 (TeX Live 2022) pyopengl: 3.1.6

Attached first 10s split of the example running video due to the upload limit.

SuperKogito commented 1 year ago

I have the same issue as @llwanghong on ArchLinux.

llwanghong commented 1 year ago

@3b1b could you please provide any help about the glitches issue? thanks.

3b1b commented 1 year ago

Interesting, and bizarre, I'm not seeing that.

Just to confirm, when did you clone the repo? It's possible some rendering changes I made a few days ago were hastily merged before issues got fixed, but if this is what shows up after pulling the most recent changes to master it is a bit of a mystery.

SuperKogito commented 1 year ago

I cloned the repo last Sunday. If you can share which commit I should checkout to (before the changes), I can test the older version to compare and confirm if it is due to the last changes or not (at least on my machine).

3b1b commented 1 year ago

Okay, thank you. If you have a moment, can you tell me how it looks on this commit: 161bf7377d6fbebe78ffe1c90bb71edd90478066

And also, can you confirm that it still looks messed up with the most recent changes?

3b1b commented 1 year ago

I have a small theory for what might be happening, are either of you able to check of this proposed fix works on your system?

SuperKogito commented 1 year ago

It seems to be working now, at least it does for me. Thank you for your work, this was fast <3 Here is how it looks on my system:

https://user-images.githubusercontent.com/15731839/215928107-877abace-70cb-455e-bab4-eb13dcf62a46.mp4

https://user-images.githubusercontent.com/15731839/215928127-19f96a9b-697c-427d-a30d-a2d1db3db468.mp4

https://user-images.githubusercontent.com/15731839/215928146-574c19df-e68f-4817-a212-9231100f0470.mp4

llwanghong commented 1 year ago

Thanks. The last commit in my cloned repo is https://github.com/3b1b/manim/commit/f296dd8df5fb458766d11a454ef55360f5794f85 on Last Friday (Jan 27).

I tried each commit, looks much better, while there are still some black glitch shadow behind texts, each video seems same as @SuperKogito.

① split first 15s video for https://github.com/3b1b/manim/commit/161bf7377d6fbebe78ffe1c90bb71edd90478066, while there are too much coordinate grids.

3b1b commented 1 year ago

Thanks for taking the time to share those. I'll look into the shadow glitches.

3b1b commented 1 year ago

It should be fixed now.

llwanghong commented 1 year ago

Thanks @3b1b , I try the latest master https://github.com/3b1b/manim/commit/c062592684dfdc13f94f9fbef3cf7e2b68deaa10, while it errors out when running manimgl example_scenes.py OpeningManimExample, seems Self type was introduced till python 3.11, after creating new conda env with python 3.11, it is OK now.

Maybe it is better to update project README to specify the Python version to 3.11~

(manim) ➜  manim git:(master) ✗ manimgl example_scenes.py OpeningManimExample
Traceback (most recent call last):
  File "/Users/hong/opt/anaconda3/envs/manim/bin/manimgl", line 5, in <module>
    from manimlib.__main__ import main
  File "/Users/hong/Projects/Learning/manim/manimlib/__init__.py", line 36, in <module>
    from manimlib.mobject.interactive import *
  File "/Users/hong/Projects/Learning/manim/manimlib/mobject/interactive.py", line 20, in <module>
    from manimlib.mobject.value_tracker import ValueTracker
  File "/Users/hong/Projects/Learning/manim/manimlib/mobject/value_tracker.py", line 4, in <module>
    from typing import Self
ImportError: cannot import name 'Self' from 'typing' (/Users/hong/opt/anaconda3/envs/manim/lib/python3.8/typing.py)

The latest dump video, for frame@3s, seems still little black glitch for character w and u, same to frame@13s for character C.

SuperKogito commented 1 year ago

I have the same issue with Self on python 3.8. @llwanghong Thank you for pointing this out.

3b1b commented 1 year ago

Adding an update here: https://github.com/3b1b/manim/pull/1984

SuperKogito commented 1 year ago

now it works perfectly for me <3 thank you for your hard work <3

llwanghong commented 1 year ago

it is perfect now, thanks @3b1b 🎉