-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ManimCE Doesn't Recognize Text
Object's changes When Rerunning The Scene Due to Old Cache
#4096
Comments
The problem is easily reproducible with the following compact snippet. The problem must be that the color class SceneTest(Scene):
def construct(self):
oa_txt = Text(text="Hello Amazing World!", font="", width=6.5, gradient=[RED, WHITE, BLUE])
ob_txt = Text(text="Hello Amazing World!", font="", width=6.5, gradient=[GREEN, WHITE, BLUE])
ob_txt.next_to(oa_txt,DOWN)
self.add(oa_txt,ob_txt) I would suggest to deprecate the use of class SceneTest2(Scene):
def construct(self):
oa_txt = Text(text="Hello Amazing World!", font="", width=6.5)
ob_txt = Text(text="Hello Amazing World!", font="", width=6.5)
ob_txt.next_to(oa_txt,DOWN)
oa_txt = Union(*oa_txt).set_fill(opacity=1,color=[RED,WHITE,BLUE]).set_stroke(width=0)
ob_txt = Union(*ob_txt).set_fill(opacity=1,color=[GREEN,WHITE,BLUE]).set_stroke(width=0)
self.add(oa_txt,ob_txt) |
Thanks for the quick reply!! Regarding the "pango, not hash" part of your reply ... Is there a way that I can know this in the code? Let me rephrase my question: what's the internal manim code/class/method/etc. that I have to check , in order to deduce that something is implemented using pango vs hashing? I'm asking this to know a way for me to mentally-connect future errors like this with the pango/hash issue. Regarding your actual code snippet workaround, I honestly don't understand how it achieves the same result, but probably that's due to my limited experience in manim (I'm on mobile now so hard to search) ... Thanks again for the help! 🙌 |
Something similar is done with Both of these caching methods are not affected by the commandline switch In my snippet, both class SceneTest(Scene):
def construct(self):
oa_txt = Text(text="Hello Amazing World!", font="", font_size=30, width=6.5, gradient=[RED, WHITE, BLUE])
ob_txt = Text(text="Hello Amazing World!", font="", font_size=31, width=6.5, gradient=[GREEN, WHITE, BLUE])
ob_txt.next_to(oa_txt,DOWN)
self.add(oa_txt,ob_txt) |
Here is the relevant part of the code, generating the unique filename - as you can see all different attributes are considered, but not the color gradient... The fix is actually quite simple, and thanks to the nature of Python you could monkey-patch your own Manim quite easily: import hashlib
def _text2hash(self, color: ManimColor):
"""Generates ``sha256`` hash for file name."""
settings = (
"PANGO" + self.font + self.slant + self.weight + str(color)
) # to differentiate Text and CairoText
settings += str(self.t2f) + str(self.t2s) + str(self.t2w) + str(self.t2c)
settings += str(self.line_spacing) + str(self._font_size)
settings += str(self.disable_ligatures)
settings += str(self.gradient) # add gradient to hashed properties
id_str = self.text + settings
hasher = hashlib.sha256()
hasher.update(id_str.encode())
return hasher.hexdigest()[:16]
Text._text2hash = _text2hash
class SceneTest3(Scene):
def construct(self):
oa_txt = Text(text="Hello Amazing World!", font="", font_size=30, width=6.5, gradient=[RED, WHITE, BLUE])
ob_txt = Text(text="Hello Amazing World!", font="", font_size=30, width=6.5, gradient=[GREEN, WHITE, BLUE])
ob_txt.next_to(oa_txt,DOWN)
self.add(oa_txt,ob_txt) |
This was probably the most comprehensive/thorough reply I've received on GitHub 😅 I've understood everything, and have nothing else to say (I was going to suggest adding this final monkey-patch fix to manim's actual codebase, but I think this issue is so obscure no one else will care if it's added or not XD) Thank you so much for your time/explanations! |
I agree that this should be added to the code base and I would have done so, if I currently had a development environment on my computer... I hope some of the other developers will pick up this solution, we also should check if there are other attributes which should be included... |
Description of bug / unexpected behavior
Given the below code [1] , I rerun
manim src\manim_odyash_playground\scene.py
->1
command after changinggradient
to(GREEN, ...)
instead of(RED, ...)
, yet the scene gets rendered with RED color [2].Note: This always happens, but if I change
text
,font
, or apparently any other str-related argument ---> the issue gets fixed! --> I.e., the scene gets rendered with GREEN color!(so changing
width
doesn't fix the issue either)[1]:
[2]:
Expected behavior
Any update that I do in any argument of
Text
Mobject should make it refreshed (i.e., updated) when I rerun the script!How to reproduce the issue
Provided in [1] above.
Also, these are the project's requirements till now [3]:
Code for reproducing the problem
Provided in [1] above.
Additional media files
Images/GIFs
Provided in [2] above.
Logs
Terminal output
This is the log (after changing RED to GREEN):
System specifications
System Details
python/py/python3 --version
): 3.11pip list
): provided in [3] above, I just pip installed thoseLaTeX details
Note: I don't think this section is relevant, as the code doesn't use latex.
pdftex --version
command.tlmgr : The term 'tlmgr' is not recognized
error when runningtlmgr list --only-installed
Additional comments
None.
The text was updated successfully, but these errors were encountered: