Files
AnyImage/docs/internals/operators/convert-to-plane.md
nan 32bcd45d7b Add new node asset scripts for geometry and shader operations
- Implemented `build_mesh_plane.py` to create a geometry node group for mesh planes with customizable parameters.
- Created `build_shadeless.py` for a shader node group that displays color without scene lighting while preserving shadows and reflections.
- Added `validate.py` to validate the integrity of the newly created node groups and their inputs.
- Introduced `validate_cutout.py` to ensure the functionality of cutout node groups and their dependencies.
- Developed `validate_mesh_plane.py` to test the mesh plane creation and its modifier settings.
2026-08-30 00:17:29 +08:00

3.4 KiB
Raw Blame History

Plane 转换

Plane 转换包含两条路径:普通 Plane 在 Blender 内同步完成;Depth Plane 先通过 prepare-geometry-data Job 取得深度场,再回到 Blender 构建面片。两者共享图片命名、材质与基础四边形能力,但使用不同的 Geometry Nodes。

对应文件

operators/convert_to_plane/
├── __init__.py    # 对外导出
├── conversion.py  # 两个入口 Operator 与 Depth Job
├── build.py       # 颜色、深度场、材质和对象导入
├── mesh_plane.py  # 基础四边形与 O Mesh Plane 修改器
└── nodes.py       # 运行时 O Image Depth Plane 节点图

server/
├── jobs/prepare_geometry_data.py
├── models/da3.py
├── models/moge2.py
└── geometry/projection.py

总体流程

flowchart TD
    Empty["Image Empty"] --> Kind{"转换类型"}
    Kind -- "Plane" --> Copy["复制 Image 与材质"]
    Copy --> Quad["创建四边形 + O Mesh Plane"]
    Kind -- "Depth Plane" --> Input["准备颜色与分析输入"]
    Input --> Job["prepare-geometry-data"]
    Job --> Field["image.0001 + field.npz"]
    Field --> Anchor["按 Empty 范围锚定相机点"]
    Anchor --> Depth["创建深度 Image + 材质 + 节点修改器"]
    Quad --> Replace["替换源 Empty"]
    Depth --> Replace

普通 Plane

ConvertToPlane 复制当前 Image 数据,保留 Movie / Sequence 的 Image User 设置,创建与 Image Empty 显示范围一致的四边形,再加载内置 O Mesh Plane 节点组。原始 Mesh 始终只有一个四边形;Subdivide、Thickness 和材质赋值由修改器执行。

对象继承源 Empty 的 matrix_world。转换完成后删除源 Empty,并让新 Plane 沿用对象名称。剪贴板的 Plane 导入复用同一构建函数,因此两种入口得到一致的基础网格与修改器。

Depth Plane

ConvertToDepthPlane 当前只接受静态图片。深度模型和分辨率来自扩展 Preferences:MoGe-2 使用 Resolution Level,DA3 使用按原图尺寸换算并对齐到模型 Patch 的处理分辨率。

GenerateDepthPlane 把颜色输入、分析输入和模型参数提交给 prepare-geometry-data。Server 将模型结果统一为 GeometryFrame,写出包含相机点、深度、内参、有效区域和参考深度的 field.npz。这一步不创建网格。 max_input_size 同时传入 Job;Server 通过 media/resolution.py 在模型推理前限制分析图长边,默认 2048。颜色输入仍由未缩放的原图复制,受限分析图不会成为材质 Color。

Blender 响应阶段执行三件事:

  1. 根据 Image Empty 的平面范围、相机内参和参考深度,把相机点等比锚定到对象局部空间。
  2. 将锚定点的局部 Z 写入 Packed 浮点 _depth.exr Image,并创建颜色材质。
  3. 创建基础四边形和运行时 O Image Depth Plane 节点组,以 UV 采样深度并移动正面。

Depth 节点组先复用 O Mesh Plane 完成细分与材质,再生成背面厚度、限制正面向内穿透,最后在 Thickness 为零时删除背面和侧面。Depth Amount 控制位移强度;Depth Image 与 Material 是由插件填入的内部输入。

与 Cutout 的 Depth Surface 不同,Depth Plane 只使用锚定后的 Z 高度,不在 Geometry Nodes 中重建完整相机空间 XYZ。它强调一张图上的可编辑浮雕,而不是局部透视表面。