加入摄像机网格笔画方向优化实验
用邻域差异筛选方向并保留原随机模式。已通过单元测试、纹理重现检查和多分辨率光流探针。
This commit is contained in:
@@ -15,6 +15,7 @@ import bpy
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
from camera_grid_stroke_geometry import capsule_in_cell, projected_stroke_uv
|
||||
from camera_grid_stroke_optimizer import optimize_angles
|
||||
from patch_geometry import clip_rect
|
||||
from patch_projection import build_patch_geometry
|
||||
from random_patch_dd02c import (
|
||||
@@ -31,6 +32,10 @@ def _args():
|
||||
parser.add_argument("--output-dir", type=Path, required=True)
|
||||
parser.add_argument("--width-ratio", type=float, default=0.42)
|
||||
parser.add_argument("--length-ratio", type=float, default=0.84)
|
||||
parser.add_argument("--orientation-mode", choices=("random", "optimized"),
|
||||
default="random", help="Use seeded random or experimental optimized angles")
|
||||
parser.add_argument("--proposals", type=int, default=100000,
|
||||
help="Angle changes attempted in optimized mode")
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
@@ -39,7 +44,8 @@ def _pixel_polygon(uv_polygon, width, height):
|
||||
for u, v in clip_rect(uv_polygon, 0.0, 1.0, 0.0, 1.0)]
|
||||
|
||||
|
||||
def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio):
|
||||
def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio,
|
||||
angle_map=None):
|
||||
width, height = settings["width"], settings["height"]
|
||||
nx, ny = settings["nx"], settings["ny"]
|
||||
seed = settings.get("seed") or 0
|
||||
@@ -61,7 +67,8 @@ def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio):
|
||||
key = (i, j)
|
||||
if key not in outline_cache:
|
||||
outline_cache[key] = capsule_in_cell(
|
||||
i, j, nx, ny, seed, width_ratio, length_ratio)
|
||||
i, j, nx, ny, seed, width_ratio, length_ratio,
|
||||
angle=None if angle_map is None else float(angle_map[j, i]))
|
||||
uv_poly = projected_stroke_uv(fragment, loop_uvs, outline_cache[key])
|
||||
pixel_poly = _pixel_polygon(uv_poly, width, height)
|
||||
if len(pixel_poly) < 3:
|
||||
@@ -71,7 +78,8 @@ def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio):
|
||||
|
||||
image.pixels[:] = pixels
|
||||
image.update()
|
||||
base = output_dir / f"camera_grid_stroke_{uv_name}"
|
||||
label = "camera_grid_stroke_optimized" if angle_map is not None else "camera_grid_stroke"
|
||||
base = output_dir / f"{label}_{uv_name}"
|
||||
save_png_image(image, base.with_suffix(".png"))
|
||||
page_mesh = _clipped_polygons(mesh_polygons, width, height)
|
||||
page_shapes = _clipped_shapes(shapes, width, height)
|
||||
@@ -99,6 +107,15 @@ def main():
|
||||
_require_uv_layer(obj, name)
|
||||
args.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
args.output_dir = args.output_dir.resolve()
|
||||
angle_map = None
|
||||
if args.orientation_mode == "optimized":
|
||||
angle_map, report = optimize_angles(
|
||||
settings["nx"], settings["ny"], settings.get("seed") or 0,
|
||||
args.width_ratio, args.length_ratio, args.proposals,
|
||||
)
|
||||
report_path = args.output_dir / "camera_grid_stroke_optimization.json"
|
||||
report_path.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
|
||||
print(f"Camera-grid optimization: {report}")
|
||||
geometry = build_patch_geometry(
|
||||
obj, cam, bpy.context.scene, bpy.context.evaluated_depsgraph_get(),
|
||||
names, settings["nx"], settings["ny"], settings["edge_sample_grid"],
|
||||
@@ -106,7 +123,7 @@ def main():
|
||||
)
|
||||
for name in names:
|
||||
_render(name, geometry[name], settings, args.output_dir,
|
||||
args.width_ratio, args.length_ratio)
|
||||
args.width_ratio, args.length_ratio, angle_map)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user