Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -80,6 +80,7 @@ def _build_mesh(
|
|
| 80 |
base_thickness_mm: float,
|
| 81 |
height_scale_mm: float,
|
| 82 |
bottom_mode: str,
|
|
|
|
| 83 |
) -> MeshData:
|
| 84 |
heightmap = np.clip(heightmap, 0.0, 1.0)
|
| 85 |
height_values = base_thickness_mm + heightmap * height_scale_mm
|
|
@@ -180,6 +181,8 @@ def _build_mesh(
|
|
| 180 |
# Right edge (col cols-1)
|
| 181 |
side_faces([ r * cols + (cols - 1) for r in range(rows)], flip=False)
|
| 182 |
|
|
|
|
|
|
|
| 183 |
flipped_faces = [(a, c, b) for a, b, c in faces]
|
| 184 |
return MeshData(vertices=vertices, faces=flipped_faces)
|
| 185 |
|
|
@@ -257,6 +260,7 @@ def generate_mesh(
|
|
| 257 |
base_thickness_mm,
|
| 258 |
bottom_mode,
|
| 259 |
invert_heightmap,
|
|
|
|
| 260 |
):
|
| 261 |
if file is None:
|
| 262 |
raise gr.Error("ファイルをアップロードしてください。")
|
|
@@ -291,6 +295,7 @@ def generate_mesh(
|
|
| 291 |
base_thickness_mm=float(base_thickness_mm),
|
| 292 |
height_scale_mm=float(height_scale_mm),
|
| 293 |
bottom_mode=resolved_bottom_mode,
|
|
|
|
| 294 |
)
|
| 295 |
|
| 296 |
suffix = ".obj" if output_format == "OBJ" else ".ply"
|
|
@@ -403,12 +408,12 @@ def build_app() -> gr.Blocks:
|
|
| 403 |
with gr.Row():
|
| 404 |
with gr.Column():
|
| 405 |
file_input = gr.File(label="ハイトマップ画像")
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
value=
|
| 411 |
-
|
| 412 |
label="XY解像度",
|
| 413 |
)
|
| 414 |
bottom_mode = gr.Dropdown(
|
|
@@ -421,7 +426,7 @@ def build_app() -> gr.Blocks:
|
|
| 421 |
width_mm = gr.Number(value=100.0, minimum=0.001, label="横サイズ(mm)")
|
| 422 |
height_mm = gr.Number(value=100.0, minimum=0.001, label="縦サイズ(mm)")
|
| 423 |
with gr.Row():
|
| 424 |
-
invert_heightmap = gr.Checkbox(value=False, label="ハイトマップ反転
|
| 425 |
height_ratio_input = gr.Number(
|
| 426 |
value=0.5,
|
| 427 |
minimum=0.0,
|
|
@@ -446,12 +451,13 @@ def build_app() -> gr.Blocks:
|
|
| 446 |
file_input,
|
| 447 |
output_format,
|
| 448 |
height_ratio_input,
|
| 449 |
-
|
| 450 |
width_mm,
|
| 451 |
height_mm,
|
| 452 |
base_thickness,
|
| 453 |
bottom_mode,
|
| 454 |
invert_heightmap,
|
|
|
|
| 455 |
],
|
| 456 |
outputs=output_file,
|
| 457 |
)
|
|
|
|
| 80 |
base_thickness_mm: float,
|
| 81 |
height_scale_mm: float,
|
| 82 |
bottom_mode: str,
|
| 83 |
+
reverse_face: bool,
|
| 84 |
) -> MeshData:
|
| 85 |
heightmap = np.clip(heightmap, 0.0, 1.0)
|
| 86 |
height_values = base_thickness_mm + heightmap * height_scale_mm
|
|
|
|
| 181 |
# Right edge (col cols-1)
|
| 182 |
side_faces([ r * cols + (cols - 1) for r in range(rows)], flip=False)
|
| 183 |
|
| 184 |
+
if reverse_face:
|
| 185 |
+
return MeshData(vertices=vertices, faces=faces)
|
| 186 |
flipped_faces = [(a, c, b) for a, b, c in faces]
|
| 187 |
return MeshData(vertices=vertices, faces=flipped_faces)
|
| 188 |
|
|
|
|
| 260 |
base_thickness_mm,
|
| 261 |
bottom_mode,
|
| 262 |
invert_heightmap,
|
| 263 |
+
reverse_face,
|
| 264 |
):
|
| 265 |
if file is None:
|
| 266 |
raise gr.Error("ファイルをアップロードしてください。")
|
|
|
|
| 295 |
base_thickness_mm=float(base_thickness_mm),
|
| 296 |
height_scale_mm=float(height_scale_mm),
|
| 297 |
bottom_mode=resolved_bottom_mode,
|
| 298 |
+
reverse_face=bool(reverse_face),
|
| 299 |
)
|
| 300 |
|
| 301 |
suffix = ".obj" if output_format == "OBJ" else ".ply"
|
|
|
|
| 408 |
with gr.Row():
|
| 409 |
with gr.Column():
|
| 410 |
file_input = gr.File(label="ハイトマップ画像")
|
| 411 |
+
with gr.Row():
|
| 412 |
+
reverse_face = gr.Checkbox(value=False, label="ポリゴン裏表反転")
|
| 413 |
+
output_format = gr.Radio(["OBJ", "PLY"], value="OBJ", label="出力形式")
|
| 414 |
+
xy_resolution_input = gr.Number(
|
| 415 |
+
value=0.5,
|
| 416 |
+
minimum=0.001,
|
| 417 |
label="XY解像度",
|
| 418 |
)
|
| 419 |
bottom_mode = gr.Dropdown(
|
|
|
|
| 426 |
width_mm = gr.Number(value=100.0, minimum=0.001, label="横サイズ(mm)")
|
| 427 |
height_mm = gr.Number(value=100.0, minimum=0.001, label="縦サイズ(mm)")
|
| 428 |
with gr.Row():
|
| 429 |
+
invert_heightmap = gr.Checkbox(value=False, label="ハイトマップ上下反転")
|
| 430 |
height_ratio_input = gr.Number(
|
| 431 |
value=0.5,
|
| 432 |
minimum=0.0,
|
|
|
|
| 451 |
file_input,
|
| 452 |
output_format,
|
| 453 |
height_ratio_input,
|
| 454 |
+
xy_resolution_input,
|
| 455 |
width_mm,
|
| 456 |
height_mm,
|
| 457 |
base_thickness,
|
| 458 |
bottom_mode,
|
| 459 |
invert_heightmap,
|
| 460 |
+
reverse_face,
|
| 461 |
],
|
| 462 |
outputs=output_file,
|
| 463 |
)
|