|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | +import numpy as np |
1 | 4 | import pytest |
2 | 5 | import trimesh |
3 | | -import numpy as np |
4 | | -import os |
5 | | -from huggingface_hub import snapshot_download |
6 | 6 |
|
7 | 7 | import genesis as gs |
8 | | -import genesis.utils.mesh as mu |
9 | 8 | import genesis.utils.gltf as gltf_utils |
| 9 | +import genesis.utils.mesh as mu |
10 | 10 | import genesis.utils.usda as usda_utils |
11 | 11 |
|
12 | | -from .utils import get_hf_assets, assert_allclose, assert_array_equal |
| 12 | +from .utils import assert_allclose, assert_array_equal, get_hf_assets |
13 | 13 |
|
14 | 14 | VERTICES_TOL = 1e-05 # Transformation loses a little precision in vertices |
15 | 15 | NORMALS_TOL = 1e-02 # Conversion from .usd to .glb loses a little precision in normals |
@@ -292,3 +292,73 @@ def test_usd_parse(usd_filename): |
292 | 292 | check_gs_textures( |
293 | 293 | gs_glb_material.emissive_texture, gs_usd_material.emissive_texture, 0.0, material_name, "emissive" |
294 | 294 | ) |
| 295 | + |
| 296 | + |
| 297 | +@pytest.mark.required |
| 298 | +def test_urdf_with_existing_glb(tmp_path, show_viewer): |
| 299 | + assets = Path(gs.utils.get_assets_dir()) |
| 300 | + glb_path = assets / "usd" / "sneaker_airforce.glb" |
| 301 | + urdf_path = tmp_path / "model.urdf" |
| 302 | + urdf_path.write_text( |
| 303 | + f"""<robot name="shoe"> |
| 304 | + <link name="base"> |
| 305 | + <visual> |
| 306 | + <geometry><mesh filename="{glb_path}"/></geometry> |
| 307 | + </visual> |
| 308 | + </link> |
| 309 | + </robot> |
| 310 | + """ |
| 311 | + ) |
| 312 | + scene = gs.Scene( |
| 313 | + show_viewer=show_viewer, |
| 314 | + show_FPS=False, |
| 315 | + ) |
| 316 | + scene.build() |
| 317 | + scene.step() |
| 318 | + |
| 319 | + |
| 320 | +@pytest.mark.required |
| 321 | +@pytest.mark.parametrize( |
| 322 | + "n_channels, float_type", |
| 323 | + [ |
| 324 | + (1, np.float32), # grayscale → H×W |
| 325 | + (2, np.float64), # L+A → H×W×2 |
| 326 | + ], |
| 327 | +) |
| 328 | +def test_urdf_with_float_texture_glb(tmp_path, show_viewer, n_channels, float_type): |
| 329 | + vertices = np.array( |
| 330 | + [[-0.5, -0.5, 0.0], [0.5, -0.5, 0.0], [0.5, 0.5, 0.0], [-0.5, 0.5, 0.0]], |
| 331 | + dtype=np.float32, |
| 332 | + ) |
| 333 | + faces = np.array([[0, 1, 2], [0, 2, 3]], dtype=np.uint32) |
| 334 | + |
| 335 | + mesh = trimesh.Trimesh(vertices, faces, process=False) |
| 336 | + |
| 337 | + H = W = 16 |
| 338 | + if n_channels == 1: |
| 339 | + img = np.random.rand(H, W).astype(float_type) |
| 340 | + else: |
| 341 | + img = np.random.rand(H, W, n_channels).astype(float_type) |
| 342 | + |
| 343 | + mesh.visual = trimesh.visual.texture.TextureVisuals( |
| 344 | + uv=np.array([[0, 0], [1, 0], [1, 1], [0, 1]], dtype=np.float32), |
| 345 | + material=trimesh.visual.material.SimpleMaterial(image=img), |
| 346 | + ) |
| 347 | + |
| 348 | + glb_path = tmp_path / f"tex_{n_channels}c.glb" |
| 349 | + urdf_path = tmp_path / f"tex_{n_channels}c.urdf" |
| 350 | + trimesh.Scene([mesh]).export(glb_path) |
| 351 | + |
| 352 | + urdf_path.write_text( |
| 353 | + f"""<robot name="tex{n_channels}c"> |
| 354 | + <link name="base"> |
| 355 | + <visual> |
| 356 | + <geometry><mesh filename="{glb_path}"/></geometry> |
| 357 | + </visual> |
| 358 | + </link> |
| 359 | + </robot> |
| 360 | + """ |
| 361 | + ) |
| 362 | + scene = gs.Scene(show_viewer=show_viewer, show_FPS=False) |
| 363 | + scene.build() |
| 364 | + scene.step() |
0 commit comments