ManimCommunity / ManimCommunity/manim
2D Mobjects being rendered above 3D Mobjects even if they have a lower z-coordinate and z_index.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 40.9k
- Forks
- 3.1k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 25
Description
An example of this issue is with a tetrahedron (Tetrahedron()) and a 2D plane (Square()), where, if you rotate the plane, it would overlay above the tetrahedron even if the tetrahedron has a higher z-coordinate:
`
from manim import *
class Scene(ThreeDScene):
def construct(self):
tetra = Tetrahedron()
plane = Square(side_length=5, color=WHITE, fill_opacity=0.4)
_3D = ThreeDAxes()
self.add(_3D)
self.move_camera(phi=65*DEGREES, theta=-45*DEGREES)
self.play(FadeIn(plane))
self.play(FadeIn(tetra.shift([0,0,1])))
self.play(Rotate(plane, 90*DEGREES, about_point=ORIGIN))
self.wait()
`
This will output:
The Square Mobject overlays itself over the Tetrahedron when the rotation animation plays.
z_index() does not affect this outcome, I've attempted to give the Square Mobject a lower z_index multiple times with the same result.
The only way I've found to fix this is by defining the plane as a Polyhedron():
`
from manim import *
class Scene(ThreeDScene):
def construct(self):
vertices = [
[-2.5,2.5,0],
[2.5,2.5,0],
[2.5,-2.5,0],
[-2.5,-2.5,0]
]
plane = Polyhedron(vertices, [[0,1,2,3]])
for i in range(0,4,1):
plane.graph[i].scale(0)
plane.set_color(WHITE)
tetra = Tetrahedron()
_3D = ThreeDAxes()
plane.set_z_index(tetra.get_z_index()-1)
self.add(_3D)
self.move_camera(phi=65*DEGREES, theta=-45*DEGREES)
self.play(FadeIn(tetra.shift([0,0,1])))
self.play(FadeIn(plane))
self.play(Rotate(plane, 90*DEGREES, about_point=ORIGIN))
self.wait()
`
This outputs what I was looking for:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied ThreeDScene example with Tetrahedron, Square, ThreeDAxes, camera movement, and plane rotation to reproduce the incorrect overlay. Trace how 2D and 3D mobjects are ordered during rendering and how z-coordinate and z_index are applied; done means the rotated Square renders behind the higher tetrahedron as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100