Repository navigation
TW 02 Runtime Model
English · 简体中文 · 繁體中文 · 日本語 · 한국어 · हिन्दी · Español · Português · Français · Deutsch · Русский
RTM 不驅動 ManimCE 的 Scene.render();錄製器在內部調用一個顯式的生命週期:
scene.setup()
scene.construct()
scene.tear_down()
實現見 record.scene_lifecycle()。用户只寫 construct(),在其中:
- 創建
MLWindow; -
win.scene = self綁定場景; -
self.add(...)放靜態內容; -
win.play(...)播放動畫 / 等待; -
win.close()收尾(錄製時還會結束編碼)。
MLWindow 的註冊表保證一個進程只允許一個活動窗口;第二個窗口會直接報錯,因為原生 Vulkan 狀態是進程全局的。
MLWindow.__init__ 大致做這些事:
- 找到並
ctypes.CDLL加載vulkan_core.dll/vulkan_core.dylib; - 綁定導出函數(
Vulkan_Init、AddRect、AddImageQuad、AddMesh...); - 調用
Vulkan_InitEx(w, h, hidden)創建 instance/surface/device/swapchain; - 失敗時先
Vulkan_Shutdown()再拋異常,避免留下半初始化狀態。
with MLWindow(...) as win: 會在退出塊時 close();進程退出時還有 atexit 兜底,但顯式 close() 才能完成手動 fast record 並報告編碼錯誤。
MLWindow 有一個類級 _schedule_mode:
win.play(*animations, run_time=...):
- 解析動畫時長、
Wait是否凍結; - 為這一組動畫構建
Timeline; - 按幀循環:
timeline.evaluate(t)→sync(scene)→tick(); - 結束時執行每個動畫的
finish()/clean_up_from_scene(); - 推進
_cursor。
FrameServer 臨時把 _schedule_mode = True 再執行 construct():
-
win.play(...)不畫,只把動畫追加到win._sched; -
_cursor累加,形成全局時間軸; -
construct()結束後window.build_timeline()一次性finalize(); - 之後任意
render_frame(t)只做evaluate+ 繪製。
這就是「一次 construct,任意幀」的來源。
實時:play → Timeline → 每幀 evaluate + sync + tick
調度:play → _sched(只記錄) → build_timeline() → FrameServer.render_frame(t)
MLWindow.sync(scene) 是 Python 側每幀的入口,負責:
- 發佈相機(
camera_state:frame center、height、rotation、focal distance、light source); - 發佈背景色;
- 判斷是否可以使用靜態層;
- 收集場景根、計算 paint order;
- 提交顯式 mesh / 場景中的
MeshMobject; - 把 painter 圖元交給 native 命令列表。
tick() 觸發原生 Vulkan_Tick:錄製命令緩衝、提交、present(或讀回)。
- 2D 場景沒有旋轉矩陣:投影是仿射的,paint order 退回文檔順序 +
z_index。 - 3D 場景(
ThreeDCamera/set_camera_orientation)發佈旋轉矩陣:發送器按相機空間投影,paint order 按相機深度排序。 -
fixed_in_frame_mobjects不參與旋轉,保持屏幕座標(字幕、標題)。
close() 先停止錄製線程 / fast record,再 Vulkan_Shutdown()。順序不能反:錄製線程還在讀 swapchain 時關閉 Vulkan 會崩。
record._AutoRecord 在真正的 close() 之前插入 _finish_fast_record() / stop_record(),所以錄製場景中寫普通的 win.close() 就會完成編碼。
-
real_time_manim/window/core.py:窗口構造、DLL 綁定、sync -
real_time_manim/window/play.py:play循環、時間線渲染 -
real_time_manim/window/recording.py:close、錄製生命週期 -
real_time_manim/record.py:scene_lifecycle -
real_time_manim/frames.py:調度模式與FrameServer
English · 简体中文 · 繁體中文 · 日本語 · 한국어 · हिन्दी · Español · Português · Français · Deutsch · Русский
English
- Home
- 01 Overview & Architecture
- 02 Runtime Model
- 03 Timeline & Frame Addressing
- 04 Paint Queue & Ordering
- 05 The Native Vulkan Layer
- 06 Recording & Parallelism
- 07 Meshes & 3D
- 08 Caching, Performance & Limits
- 09 Performance by Scene Type
- 10 The llms.txt Strategy
中文
- 首页
- 01 总览与架构
- 02 运行模型
- 03 时间线与帧寻址
- 04 绘制队列与顺序
- 05 原生 Vulkan 层
- 06 录制与并行
- 07 网格与 3D
- 08 缓存、性能与边界
- 09 场景类型性能基准
- 10 llms.txt 的策略
Other languages: open the Home page of a language from the bar above — its chapter lists live there.