3b1b / 3b1b/manim

How to use checkerboard pattern for Surface class

未關閉
#2,404 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
93.9k
分支
7.7k
平均合併
2 天 13 小時
30 天內合併 PR
4

描述

### Describe the error
Hi, I'm using manimGL v1.7.2. I recently learned about the Surface class in Manim, I really want to represent surfaces by a checkerboard model (like the old version before). I copied some code to create the checkerboard model to try to reproduce it in the new version. But the rendered image looks weird, is there something I forgot to set up?

### Code and Error
**Code**:
class Test(InteractiveScene):
def construct(self):
# Try add surface by checkerboard colors
frame = self.camera.frame
frame.reorient(
-87, 92, 179, (np.float32(-0.15), np.float32(0.0), np.float32(-0.0)), 2.67
)
sphere = ParametricSurface(
uv_func=lambda u, v: np.array(
[
np.sin(u) * np.cos(v),
np.sin(u) * np.sin(v),
np.cos(u),
]
),
u_range=[0, PI],
v_range=[0, TAU],
resolution=(10, 10),
)

# From def get_u_values_and_v_values(self) in class ParametricSurface
res = tuplify(sphere.resolution)
if len(res) == 1:
u_res = v_res = res[0]
else:
u_res, v_res = res
u_min = sphere.u_range[0]
u_max = sphere.u_range[-1]
v_min = sphere.v_range[0]
v_max = sphere.v_range[-1]
u_values = np.linspace(u_min, u_max, u_res + 1)
v_values = np.linspace(v_min, v_max, v_res + 1)

# From def setup_in_uv_space(self) in class ParametricSurface
faces = VGroup()
for i in range(len(u_values) - 1):
for j in range(len(v_values) - 1):
u1, u2 = u_values[i : i + 2]
v1, v2 = v_values[j : j + 2]
face = VMobject() # Old version: face = ThreeDVMobject()
face.set_points_as_corners(
[
[u1, v1, 0],
[u2, v1, 0],
[u2, v2, 0],
[u1, v2, 0],
[u1, v1, 0],
]
)
face.apply_function(lambda p: sphere.uv_func(p[0], p[1]))
faces.add(face)
face.u_index = i
face.v_index = j
face.u1 = u1
face.u2 = u2
face.v1 = v1
face.v2 = v2

# From def set_fill_by_checkerboard(self, *colors, opacity=None):
faces.set_fill(color=sphere.color, opacity=sphere.opacity)
faces.set_stroke(
color=WHITE,
width=1,
opacity=1,
)
checkerboard_colors = [BLUE_D, BLUE_E]
n_colors = len(checkerboard_colors)
for face in faces:
c_index = (face.u_index + face.v_index) % n_colors
face.set_fill(checkerboard_colors[c_index], opacity=1)
self.add(sphere, faces)

**Error**:

### Environment

Image

**OS System**: Window 11
**manim version**: v1.7.2
**python version**: 3.11.8

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

這個問題是關於 manimGL v1.7.2 中 Surface 類別未能正確渲染棋盤格圖案。先檢查程式碼庫中的 ParametricSurface 類別,特別是 setup_in_uv_space 與 set_fill_by_checkerboard 方法。比較舊實作(使用 ThreeDVMobject)和目前實作(使用 VMobject)。執行提供的程式碼以查看奇怪的渲染,然後除錯面片生成與顏色套用。檢查問題是否與 3D 轉換或 fill/stroke 設定有關。

由索引模型根據 Issue 內容生成。

評估

領域
computer-graphics
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。