为相机网格笔画增加双视图导出

沿用彩色纹理的视图归属、接缝留白和自动页面尺寸。
已验证双视图与单视图 Blender 导出、相关测试及文档门禁。
This commit is contained in:
ykcheungab
2026-10-06 11:01:45 +08:00
parent e8d231ec39
commit afe1ce39cb
16 changed files with 197989 additions and 86 deletions
+28 -21
View File
@@ -63,11 +63,9 @@ 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,
angle_map=None, artifact_prefix="camera_grid_stroke"):
width, height = settings["width"], settings["height"]
nx, ny = settings["nx"], settings["ny"]
seed = settings.get("seed") or 0
def render_stroke_polygons(uv_name, mesh, strokes, width, height, vector,
base):
"""Write the shared raster and vector artwork from UV polygons."""
image_name = f"CameraGridStroke_{uv_name}"
if image_name in bpy.data.images:
bpy.data.images.remove(bpy.data.images[image_name])
@@ -75,21 +73,14 @@ def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio,
pixels = list(image.pixels)
fill_background(pixels, width, height, (0, 0, 0, 1))
mesh_polygons = [_pixel_polygon(poly, width, height) for poly in geometry["mesh"]]
mesh_polygons = [_pixel_polygon(poly, width, height) for poly in mesh]
mesh_polygons = [poly for poly in mesh_polygons if len(poly) >= 3]
for poly in mesh_polygons:
fill_polygon(None, pixels, width, height, poly, (1, 1, 1, 1))
shapes = []
outline_cache = {}
for i, j, fragment, loop_uvs in geometry["camera_fragments"]:
key = (i, j)
if key not in outline_cache:
outline_cache[key] = capsule_in_cell(
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)
for polygon in strokes:
pixel_poly = _pixel_polygon(polygon, width, height)
if len(pixel_poly) < 3:
continue
shapes.append((pixel_poly, (0, 0, 0, 1)))
@@ -97,14 +88,9 @@ def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio,
image.pixels[:] = pixels
image.update()
label = artifact_prefix
if angle_map is not None and artifact_prefix == "camera_grid_stroke":
label += "_optimized"
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)
vector = settings["vector"]
vector_args = (width, height, vector["width_mm"], vector["height_mm"])
write_svg_vector(base.with_suffix(".svg"), *vector_args,
page_mesh, page_shapes, [], (0, 0, 0, 1), uv_name,
@@ -112,7 +98,28 @@ def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio,
write_pdf_vector(base.with_suffix(".pdf"), *vector_args,
page_mesh, page_shapes, [], (0, 0, 0, 1),
artwork_label="stroke")
print(f"{uv_name}: {len(outline_cache)} cells, {len(shapes)} projected fragments")
print(f"{uv_name}: {len(shapes)} projected stroke fragments")
def _render(uv_name, geometry, settings, output_dir, width_ratio, length_ratio,
angle_map=None, artifact_prefix="camera_grid_stroke"):
nx, ny = settings["nx"], settings["ny"]
seed = settings.get("seed") or 0
outline_cache = {}
strokes = []
for i, j, fragment, loop_uvs in geometry["camera_fragments"]:
key = (i, j)
if key not in outline_cache:
outline_cache[key] = capsule_in_cell(
i, j, nx, ny, seed, width_ratio, length_ratio,
angle=None if angle_map is None else float(angle_map[j, i]))
strokes.append(projected_stroke_uv(fragment, loop_uvs, outline_cache[key]))
label = artifact_prefix
if angle_map is not None and artifact_prefix == "camera_grid_stroke":
label += "_optimized"
base = output_dir / f"{label}_{uv_name}"
render_stroke_polygons(uv_name, geometry["mesh"], strokes,
settings["width"], settings["height"], settings["vector"], base)
def main():