- 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.
81 lines
6.9 KiB
Markdown
81 lines
6.9 KiB
Markdown
# Cutout
|
||
|
||
Cutout 从一条图片空间套索生成规则三角基础面,再交给统一的 `O Image Cutout` Geometry Nodes 修改器形成 Surface、Balloon、Depth Balloon 或 Depth Surface。公开节点组用 Shape 菜单路由到四个原有内部节点组;轮廓和 Mesh 始终由 Blender 主线程创建,Server 只在需要时准备 Refine、深度或法线数据。
|
||
|
||
## 对应文件
|
||
|
||
```text
|
||
operators/cutout_tool/
|
||
├── selection_tool.py # 套索交互、设置与 Shape 饼菜单
|
||
├── shape_conversion.py # 本地 / Job 路径选择和任务参数
|
||
├── build_shapes.py # 裁切贴图、Mesh、材质与修改器
|
||
├── shape_types.py # Shape 与节点组映射
|
||
├── mask_regions.py # Alpha 外轮廓与孔洞
|
||
├── planar_mesh.py # 规则采样与约束三角化
|
||
├── balloon_profile.py # Poisson / Teddy profile
|
||
├── depth_calibration.py # Reference 与 Direction
|
||
└── node_assets.py # Cutout 节点资产加载
|
||
|
||
server/
|
||
├── jobs/prepare_geometry_data.py # Cutout / Depth Plane 数据编排
|
||
├── selection/
|
||
│ ├── polygon_mask.py # Polygon 栅格化与选区裁切
|
||
│ └── cutout_images.py # Refine 与 Cutout 局部图片
|
||
└── geometry/normal_texture.py # 相机轴法线编码
|
||
```
|
||
|
||
## 路径选择
|
||
|
||
```mermaid
|
||
flowchart TD
|
||
Lasso["套索 + Shape"] --> Refine{"Refine Selection?"}
|
||
Refine -- "是" --> Ben2["BEN2 × 1"]
|
||
Refine -- "否" --> Selection["套索 Selection"]
|
||
Ben2 --> Selection
|
||
Selection --> NeedMoge{"需要 Depth 或 Normal?"}
|
||
NeedMoge -- "否" --> Mesh["轮廓 → 规则点 → 约束三角化"]
|
||
NeedMoge -- "是" --> Moge["MoGe-2 × 1\\n同一 Prediction"]
|
||
Moge --> Data["Depth Field / Camera Normal"]
|
||
Data --> Mesh
|
||
Mesh --> Profile["计算 o_balloon"]
|
||
Profile --> Nodes["加载 O Image Cutout 并设置 Shape"]
|
||
Nodes --> Bake["按需烘焙最终 Tangent Normal"]
|
||
```
|
||
|
||
Cutout 只接受静态图片。Refine Selection 是网格生成前唯一可选的选区分析:开启时执行一次 BEN2,关闭时直接使用套索 Selection。Surface 与 Balloon 在不需要 Normal 时不运行 MoGe-2;两个 Depth Shape 和任意开启 Normal 的 Shape 都统一使用 MoGe-2。Depth 与 Normal 同时启用时只执行一次推理,同一个 Prediction 同时提供相机点、深度和图片空间法线。
|
||
|
||
Cutout 不使用 DA3。若全局 Depth Model 当前选择 DA3,Cutout 会回退到默认 MoGe-2;选择 MoGe-2 档位时则沿用该档位和 Resolution Level。DA3 仍可用于独立的 Depth Plane 流程。
|
||
|
||
## 选择与局部数据
|
||
|
||
Cutout 复用 `ImageMaskGesture` 的采点和屏幕预览,并复用 `operators/common/image_mask.py` 的可见选区语义:最终几何范围始终是套索、图片边界与源图 `Alpha > 0.1` 区域的交集。套索采用 NONZERO 填充规则,使反向内环可以表达孔洞。`Point Spacing` 先根据完整源图最长边换算为基础 `mesh_detail`;获得裁切 Selection 后,再按 `min(1, max_input_size / crop_long_edge)` 缩放有效 `mesh_detail`。因此只有裁切图超过全局上限时网格才会变稀,Color Image 仍使用原始裁切尺寸。
|
||
|
||
Job 路径将数据拆成三层:源颜色、最终选择和只供模型分析的 RGBA。写出最终选择前会再次以 `Alpha > 0.1` 与源图求交,因此未 Refine、Refine 和双击全图遵循相同边界。`bounds.json` 把可见选区的局部矩形映射回源图,Blender 据此恢复局部平面范围和 UV。未走 Job 时,`build_shapes.py` 在内存中完成相同的求交、裁切与坐标换算。
|
||
|
||
## 基础网格
|
||
|
||
最终 Alpha 先转为带包含关系的外轮廓与孔洞。`planar_mesh.py` 在内部生成近似六角排列的规则点,并用轮廓作为约束进行 Delaunay 三角化。边界按目标间距重采样,短轮廓会提高边界采样密度,内部点仍保持用户设置的间距。
|
||
|
||
四种 Shape 共享同一张单面基础网格、UV 和 `o_balloon` 点属性。创建阶段以目标 Point Spacing 的平方作为一个采样单元面积,再除以 Image Empty 图片平面从局部到世界的面积缩放,得到修改器局部坐标中的 Cleanup 阈值。这个值只取决于工具分辨率和图片尺寸/变换,不受碎片数量或碎面面积分布影响。Balloon Profile 由 Preferences 选择 Poisson 或 Teddy;节点组只消费计算后的属性,不再重复推导轮廓。
|
||
|
||
## 统一修改器与四种 Shape
|
||
|
||
创建结果时始终添加 `O Image Cutout`,并按饼菜单选择写入 Shape。节点组先统一执行 Cleanup,再由 Menu Switch 仅求值当前 Shape 的内部节点组,最后统一执行 Smooth;因此四种 Shape 都可使用 Cleanup、Smooth 和 Smooth Iterations。各分支独有输入直接连接到对应内部组,Blender 4.5 会在修改器中隐藏当前 Shape 不使用的输入。Cleanup 直接比较 Mesh Island 总面积与创建时写入的绝对面积阈值,不再统计当前网格面的中位面积。
|
||
|
||
| Shape | 内部节点组 | 主要几何来源 |
|
||
| --- | --- | --- |
|
||
| Surface | `O Image Surface` | 基础薄片与可调 Thickness |
|
||
| Balloon | `O Image Balloon` | `o_balloon` 鼓起高度 |
|
||
| Depth Balloon | `O Image Depth Balloon` | Balloon profile + 相对基准面的非负深度高度 |
|
||
| Depth Surface | `O Image Depth Surface` | MoGe-2 相机点的完整投影 |
|
||
|
||
四个内部节点组不再标记为 Modifier,也不再各自执行 Cleanup。原本只在 `O Image Depth Surface` 内的 Smooth 后处理已移到公开节点组;统一节点组的 Smooth 默认值为 `1`;外层 `Smooth Iterations` 默认值为 `0`,只有用户增加迭代次数后才执行平滑。两个 Depth 内部节点组也统一使用 `Reference Depth`,总节点组只暴露一个共用输入。
|
||
|
||
两个 Depth 形状把相机点 RGB 写入 Packed 浮点 `_depth.exr`,并以隐藏的 `Uniform Scale` 匹配 Image Empty 尺寸。未启用 Refine 时 Reference 使用固定值,Depth Balloon Direction 使用默认轴向;启用 Refine 后,`calibration_valid` 限制在模型有效区域与最终选择的交集,Reference 使用其深度第 95 百分位,Depth Balloon 还拟合局部基准方向。
|
||
|
||
Depth Balloon 保留图片平面 XY,只使用相机 Z 形成向外高度;Depth Surface 将完整 XYZ 映射到 Cutout 局部轴,因此能表达透视位移。两者都只采样深度 Image 的 RGB,Alpha 仅保存有效性和深度跳变信息。
|
||
|
||
## 法线空间
|
||
|
||
MoGe-2 在 Job 阶段输出图片空间的相机轴法线预测;这一步不依赖 Blender 网格。Depth Surface 在导入时将它重排到 Cutout 对象轴并以 Object Space 使用;Surface、Balloon 与 Depth Balloon 则先创建基础网格并完成 Geometry Nodes 求值,再根据成品网格 UV、法线和切线基底烘成 Tangent Space。也就是说,网格前产生的是模型 Prediction,最终法线贴图的空间转换仍发生在网格生成之后。
|