diff --git a/scripts/show_led_geometry.py b/scripts/show_led_geometry.py index f384be3..278000b 100644 --- a/scripts/show_led_geometry.py +++ b/scripts/show_led_geometry.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """LED 配置・サイズ・向きを 3D で確認するビューア. 筐体を半透明にして,各 LED を実サイズ(light.size)の長方形+発光方向の矢印で @@ -14,6 +13,7 @@ # スクリーンショットを 4 アングル保存(画面を開かない) python scripts/show_led_geometry.py --screenshot output/_slide_panels/led_geom """ + from __future__ import annotations import argparse @@ -22,8 +22,8 @@ import numpy as np import pyvista as pv -import sm_tias_lightsim.geometry.loader as G -import sm_tias_lightsim.scene.schema as S +from sm_tias_lightsim.geometry.loader import load_stl +from sm_tias_lightsim.scene.schema import SceneConfig, load_scene_yaml _GROUP_COLORS = {"bottom": "red", "left": "green", "right": "blue"} _ARROW_LEN_MM = 12.0 @@ -54,12 +54,14 @@ half_x = light.size[0] / 2.0 x_hat = np.array([1.0, 0.0, 0.0]) y_hat = np.array([0.0, 1.0, 0.0]) - corners = np.array([ - center - half_x * x_hat - _BUGGY_STRIP_HALF_Y_MM * y_hat, - center + half_x * x_hat - _BUGGY_STRIP_HALF_Y_MM * y_hat, - center + half_x * x_hat + _BUGGY_STRIP_HALF_Y_MM * y_hat, - center - half_x * x_hat + _BUGGY_STRIP_HALF_Y_MM * y_hat, - ]) + corners = np.array( + [ + center - half_x * x_hat - _BUGGY_STRIP_HALF_Y_MM * y_hat, + center + half_x * x_hat - _BUGGY_STRIP_HALF_Y_MM * y_hat, + center + half_x * x_hat + _BUGGY_STRIP_HALF_Y_MM * y_hat, + center - half_x * x_hat + _BUGGY_STRIP_HALF_Y_MM * y_hat, + ] + ) return pv.PolyData(corners, np.array([4, 0, 1, 2, 3])) @@ -71,14 +73,16 @@ return os.path.join("configs", "meshes", base) -def _build_plotter(scene_config: S.SceneConfig, *, off_screen: bool, buggy: bool = False) -> pv.Plotter: +def _build_plotter( + scene_config: SceneConfig, *, off_screen: bool, buggy: bool = False +) -> pv.Plotter: pv.global_theme.allow_empty_mesh = True plotter = pv.Plotter(off_screen=off_screen, window_size=(1400, 1050)) plotter.set_background("white") # 筐体(半透明)・評価板(シアン)・暗い phone/holder for mesh_config in scene_config.geometry.meshes: - loaded = G.load_stl(_resolve_mesh_path(mesh_config.path), "mm") + loaded = load_stl(_resolve_mesh_path(mesh_config.path), "mm") vertices = np.array(loaded.vertices) faces_arr = np.array(loaded.faces) faces = np.hstack([np.full((faces_arr.shape[0], 1), 3), faces_arr]).ravel() @@ -97,7 +101,9 @@ center = np.array(light.center, dtype=float) direction = np.array(light.direction, dtype=float) direction = direction / np.linalg.norm(direction) - plotter.add_mesh(_led_polydata(light, buggy=buggy), color=color, opacity=0.6 if buggy else 1.0) + plotter.add_mesh( + _led_polydata(light, buggy=buggy), color=color, opacity=0.6 if buggy else 1.0 + ) plotter.add_mesh( pv.Arrow(start=center.tolist(), direction=direction.tolist(), scale=_ARROW_LEN_MM), color=color, @@ -106,7 +112,9 @@ # センサ(球+視線矢印) sensor_pos = np.array(scene_config.sensor.position, dtype=float) sensor_target = np.array(scene_config.sensor.target, dtype=float) - plotter.add_mesh(pv.Sphere(radius=_ARROW_LEN_MM * 0.4, center=sensor_pos.tolist()), color="black") + plotter.add_mesh( + pv.Sphere(radius=_ARROW_LEN_MM * 0.4, center=sensor_pos.tolist()), color="black" + ) view_dir = sensor_target - sensor_pos view_dir = view_dir / np.linalg.norm(view_dir) plotter.add_mesh( @@ -126,13 +134,17 @@ size=(0.20, 0.20), ) plotter.show_axes() - plotter.show_bounds(color="gray", location="outer", xtitle="X(mm)", ytitle="Y(mm)", ztitle="Z(mm)") + plotter.show_bounds( + color="gray", location="outer", xtitle="X(mm)", ytitle="Y(mm)", ztitle="Z(mm)" + ) return plotter def main() -> None: parser = argparse.ArgumentParser(description="LED 配置・サイズ・向きを 3D で確認する") - parser.add_argument("--scene", "-s", default="configs/scene_baseline.yaml", help="シーン定義 YAML") + parser.add_argument( + "--scene", "-s", default="configs/scene_baseline.yaml", help="シーン定義 YAML" + ) parser.add_argument( "--screenshot", default=None, @@ -145,10 +157,12 @@ ) args = parser.parse_args() - scene_config = S.load_scene_yaml(args.scene) + scene_config = load_scene_yaml(args.scene) mode = "BUGGY (2m strip)" if args.buggy else "FIXED" - print(f"[{mode}] LED 数: {len(scene_config.lights)} size(mm): {scene_config.lights[0].size} " - f"direction: {scene_config.lights[0].direction}") + print( + f"[{mode}] LED 数: {len(scene_config.lights)} size(mm): {scene_config.lights[0].size} " + f"direction: {scene_config.lights[0].direction}" + ) if args.screenshot: plotter = _build_plotter(scene_config, off_screen=True, buggy=args.buggy)