python - Manim:在现有对象后面创建对象(在创建时强制 z-index)
问题描述
我正在使用 Manim CE 0.8.0,并且试图淡入场景中现有对象后面的轴;我发现没有办法做到这一点。这是一个 POC:
from manim import *
class FadeBehind(Scene):
def construct(self):
myDot = Dot(
point = [0, 0, 0],
radius = 3,
color = RED,
)
self.play(
FadeIn(myDot),
)
myLine = Line(
start = [-5, 0, 0],
end = [5, 0, 0],
stroke_color = BLUE,
stroke_width = 30,
)
myLine.z_index = myDot.z_index - 1
self.play(
FadeIn(myLine) # works as expected (the blue line is shown behind the dot)
)
self.wait()
ax = Axes(
x_range=[-7, 7, 1],
y_range=[-5, 5, 1],
)
ax.z_index = myLine.z_index - 1
self.play(
FadeIn(ax) # doesn't work as expected (the axes are overlayed on top of everything in the scene)
)
解决方案
问题是,默认 z_index 为 0:print(myDot.z_index)
给出 0。z_index 必须为正。这是有效的脚本:
class FadeBehind(Scene):
def construct(self):
myDot = Dot(
point = [0, 0, 0],
radius = 2,
color = RED,
)
self.play(
FadeIn(myDot),
)
myDot.z_index=1
myLine = Line(
start = [-5, 0, 0],
end = [5, 0, 0],
stroke_color = BLUE,
stroke_width = 30,
)
myLine.z_index = 0
self.play(
FadeIn(myLine) # works as expected (the blue line is shown behind the dot)
)
ax = Axes(
x_range=[-7, 7, 1],
y_range=[-5, 5, 1],
)
ax.z_index = 0
self.play(
FadeIn(ax) # doesn't work as expected (the axes are overlayed on top of everything in the scene)
)
推荐阅读
- r - 使用 R 将四次核热图转换为大多边形
- python-3.x - InvalidSchema("没有为 {!r} 找到连接适配器".format(url))
- firebase - 未定义的类“FirebaseUser”,即使在更改它之后,FirebaseAuth.instance 中的 iget 错误
- laravel - 澄清 Laravel 队列中的 afterCommit
- visual-studio-code - vscodce 的 IntelliSense 不适用于“:”作为片段的前缀
- flutter - 用于 Web 服务的 Flutter 格式说明符
- spring-boot - 无法使用自定义身份验证入口点更改响应。弹簧靴
- locking - 为专用 Actor 锁定消息队列
- pandas - Pandas 根据每列趋势绘制多条线
- sql - AWS DMS。复制实例中的端点连接失败(错误:1020912)