ManimCommunity / manim

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

render problem 3d camera distance #975

Open n-0 opened 3 years ago

n-0 commented 3 years ago

Description of bug / unexpected behavior

If setting the distance in camera orientation too close to 3d axes white frames are rendered and the axes are curved.

This can be bypassed by setting the distance further away or probably with some tricks in scaling, but can be surprising and hard to debug also.

Expected behavior

Distance of 3d camera shouldn't create rendering problems and not bend the axes.

How to reproduce the issue

Code for reproducing the problem ```py def construct(self): self.set_camera_orientation( phi=80 * DEGREES, theta=45*DEGREES, distance=2 # causes trouble ) axes = ThreeDAxes() s = Sphere() self.add(axes) self.play(Write(s)) self.begin_ambient_camera_rotation(rate=0.2) self.wait(10) ```

Additional media files

Images/GIFs ![bug_distance_camera](https://user-images.githubusercontent.com/11498317/106166145-280a2000-618c-11eb-89fb-908aeca0535c.gif)

Logs

Everything goes fine even with log level debug.

System specifications

System Details - OS Fedora 33 - RAM: 16GB - Python version: 3.9.1
FFMPEG Output of `ffmpeg -version`: 4.3.1
huguesdevimeux commented 3 years ago

Thanks for the report! Sorry to be so late to respond.

This is in fact very weird, probably related to how manim handles rotation in 3d. This an hard issue.

Just a question, are the kinf of flashs in the gif you provided intentional?

n-0 commented 3 years ago

No worries as stated you can trick yourself around this issue.

The flashes weren't intentional and only existent if the distance was too small. They seem similar to the ones, which are produced if the camera is inside an object. Maybe the camera is hitting the axis or the ball.

huguesdevimeux commented 3 years ago

Thanks for the clarification. I don't know if this will be fixed soon, I hope you found a workaround

andryandrew commented 3 years ago

I think the distance property might just not be what it seems (see: https://github.com/ManimCommunity/manim/issues/899#issuecomment-782264077).

Anyway, the flashing issue and curved axes are caused by having objects in the scene with z value too close to the distance value, and can be fixed by setting exponential_projection=True which smooths them out:

class DebugCamera(ThreeDScene):
    def construct(self):

        self.renderer.camera.exponential_projection=True

        self.set_camera_orientation(phi=80*DEGREES, theta=45*DEGREES, distance=2)

        axes = ThreeDAxes()
        s = Sphere()

        self.add(axes, s)
        self.begin_ambient_camera_rotation(rate=0.2)
        self.wait(10)
Click for Video https://user-images.githubusercontent.com/29781022/108549256-2ea03900-72ed-11eb-942a-385a96d2df45.mp4