Newer
Older
SmTIAS-LightSim / tests / render / conftest.py
"""render テスト共通フィクスチャ.

球体 STL の一時生成と最小シーン YAML 文字列を提供する.
"""

from __future__ import annotations

from pathlib import Path

import pytest
import trimesh


@pytest.fixture
def sphere_stl_in_cwd(tmp_path: Path) -> Path:
    """球体 STL を tmp_path / "sphere.stl" に書き出してそのパスを返す.

    trimesh.creation.icosphere で生成する小球体(半径 5mm 相当).
    render テストの project_root として tmp_path を使うため,
    STL パスは tmp_path 配下に置く.
    """
    mesh = trimesh.creation.icosphere(subdivisions=1, radius=5.0)
    path = tmp_path / "sphere.stl"
    mesh.export(str(path))
    return path


@pytest.fixture
def minimal_scene_yaml(sphere_stl_in_cwd: Path) -> str:
    """球体 1 個+拡散材料+点光源+センサ+render(spp=4) の YAML 文字列.

    64x64 の小解像度・低 spp で smoke テストを高速化する.
    STL パスは sphere_stl_in_cwd の絶対パスを埋め込む.
    """
    stl_path = sphere_stl_in_cwd.as_posix()
    return f"""\
name: smoke_test
geometry:
  meshes:
    - id: sphere
      path: {stl_path}
      unit: mm
      material: white
materials:
  white:
    type: diffuse
    reflectance: 0.9
lights:
  - id: led_top
    type: point
    position: [0.0, 0.0, 50.0]
    intensity: 10.0
    profile: lambertian
sensor:
  type: perspective
  position: [0.0, 0.0, 100.0]
  target: [0.0, 0.0, 0.0]
  up: [0.0, 1.0, 0.0]
  fov_deg: 60.0
  film:
    width: 64
    height: 64
    rfilter: gaussian
render:
  variant: llvm_ad_rgb
  integrator: path
  max_depth: 4
  spp: 4
"""