File size: 2,834 Bytes
fb5f375 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Shared utilities for object asset management scripts.
"""
import json
from pathlib import Path
from typing import Any, Dict, List
from robolab.constants import OBJECT_CATALOG_PATH, OBJECT_DIR
from robolab.core.utils.file_utils import find_usd_files
def iter_object_files(root: Path = Path(OBJECT_DIR)) -> List[Path]:
"""
Return all USD files under the root directory.
Excludes:
- Subfolders starting with '_'
- 'materials' directories
Args:
root: Root directory to search (defaults to OBJECT_DIR)
Returns:
List of paths to USD files
"""
return find_usd_files(root, recursive=True, exclude_underscore_dirs=True, exclude_materials=True)
def load_catalog(catalog_path: Path = Path(OBJECT_CATALOG_PATH)) -> List[Dict[str, Any]]:
"""
Load the object catalog JSON file.
Args:
catalog_path: Path to object_catalog.json
Returns:
List of object dictionaries
"""
with open(catalog_path, 'r') as f:
return json.load(f)
def get_dataset_from_path(usd_path: str) -> str:
"""
Extract the dataset name from a USD file path.
Given a path like '.../objects/vomp/object.usd', returns 'vomp'.
Args:
usd_path: Path to USD file
Returns:
Dataset name string
"""
parts = str(usd_path).replace("\\", "/").split("/")
if "objects" in parts:
idx = parts.index("objects")
if idx + 1 < len(parts):
return parts[idx + 1]
return "unknown"
def print_object_info(object_info: Dict[str, Any], usd_path: Path) -> None:
"""Print object info dictionary in a readable format."""
print(f"Object: {usd_path.name}, usd_path: {usd_path}")
for key, value in object_info.items():
if isinstance(value, (list, tuple)) and len(value) > 0:
if isinstance(value[0], (int, float)):
formatted_value = f"[{', '.join(f'{v:.4f}' if isinstance(v, float) else str(v) for v in value)}]"
else:
formatted_value = str(value)
else:
formatted_value = str(value)
print(f" {key:20s}: {formatted_value}")
def resolve_usd_path(relative_path: str) -> str:
"""
Resolve a relative usd_path from the catalog to an absolute path.
The catalog stores paths relative to PACKAGE_DIR (e.g., 'assets/objects/ycb/banana.usd').
This function converts them to absolute paths.
Args:
relative_path: Path relative to PACKAGE_DIR
Returns:
Absolute path string
"""
from robolab.constants import resolve_catalog_path
return resolve_catalog_path(relative_path)
|