Files
AnyImage/docs/internals/runtime.md
nan 4c902ed7db feat(node_assets): add image plane geometry nodes and validation scripts
- Implemented `image_plane.py` to build the Image Plane Geometry Nodes group with customizable parameters for geometry, subdivide, and thickness.
- Created `image_plane_validation.py` to validate the functionality of the image plane, ensuring correct geometry generation and material assignment.
- Developed `material_layers.py` to construct shader node groups for image materials, including depth and normal handling.
- Authored `plane_layouts.py` to define node arrangements for image geometry assets.
- Introduced `shadeless.py` to create a shadeless shader node group that displays color without scene lighting while preserving shadows and reflections.
2026-09-08 23:24:27 +08:00

2.9 KiB
Raw Blame History

Job Runtime 与 Server

runtime.py 配置 BlendJob JobRuntime 和独立 Python 3.12 Environment。server/app.py 注册 Job,model_manager.py 作为 model_manager Resource 管理下载文件与缓存 Session。

flowchart TD
    A[Operator request] --> B[JobRuntime]
    B --> C[Server 单 Worker 队列]
    C --> D[Job 调用媒体与模型模块]
    D --> E[写入 jobs/job-id 目录]
    E --> F[主线程 response]

Job 在阶段和帧边界检查取消,进度通过 context.progress() 返回。视频临时帧由 media/input.py 的上下文管理器清理,Blender 导出的临时输入由对应 Operator 清理。

Job 与数据模块

Job 实现与用途
download-model、download-required-models app.py 调用 ModelManager 下载单个或缺失模型
remove-background jobs/remove_background.py,生成 BEN2 前景
upscale-image jobs/upscale.py,生成 2× 图像或序列
generate-depth-plane-geometry jobs/depth_plane.py,复制整图颜色并生成深度、元数据与切线法线
generate-cutout-artifacts jobs/cutout.py,按请求生成 Cutout 深度和法线

media/ 处理单图、序列、视频与输入尺寸。Depth Plane 和 Cutout 按单张静态图片工作;Remove Background 与 Upscale 逐帧处理动画输入。

geometry/prediction_artifacts.py 将限尺寸后的 RGBA 合成到黑底,运行一次 MoGe-2,再调用深度、法线和元数据写入器。Cutout 的深度分支通过 edge_depth.py 延展轮廓附近的深度;法线使用原预测。文件字段见 Job 产物。

模型与缓存

用途 模型 Session 分类
Depth 与 Normal MoGe-2 ViT-S / ViT-B / ViT-L Normal geometry
Remove Background BEN2 ben2
Upscale Real-ESRGAN WDN、SAFMN、Real-ESRGAN x4plus、PiSA-SR upscale

model_catalog.py 声明文件来源、许可、大小和 SHA-256。model_download.py 下载文件并校验;ModelManager 按模型路径和设备缓存各类最近使用的 Session,切换模型或设备时释放对应类别。

flowchart TD
    A[取得缓存 Session] --> B[运行单图、多帧或 tile]
    B --> C[最后一次推理]
    C --> D[CUDA 收缩空闲 arena]
    D --> E[保留 Session 供后续复用]
    E --> F[Clear Models 或关闭 Server 时释放]

Windows 默认 DirectML,macOS arm64 默认 CPU 并支持选择 CoreML。MoGe-2 为 CoreML 配置静态 shape 分区,其余计算由 CPU 执行。PiSA-SR 在 CoreML 上返回明确的支持限制;其分阶段 Session 在切换阶段、取消和清理时关闭。

Environment 与存储

首次安装通过 post_install() 下载默认 MoGe-2、BEN2 与 Real-ESRGAN WDN。Storage Root 默认 ~/.anyimage,其中保存 .venv/、models/、jobs/ 及环境状态和日志。设置入口与安装流程见 AI 环境管理。