Skip to content

Commit d69deaa

Browse files
Merge pull request #44 from LouRohanNV/fixAssetPath
Fix the stage path from convert() when layer_structure=False
2 parents d60de48 + 000c47c commit d69deaa

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

tests/testConverter.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 The Newton Developers
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Newton Developers
22
# SPDX-License-Identifier: Apache-2.0
33
import pathlib
44
import shutil
@@ -153,3 +153,16 @@ def test_ros_packages(self):
153153

154154
# Check material texture.
155155
# TODO: Here we need to make sure that the reference to the usd file is correct after the texture is loaded.
156+
157+
def test_asset_identifer(self):
158+
model = pathlib.Path("tests/data/prismatic_joints.urdf")
159+
model_name = model.stem
160+
output_dir = pathlib.Path(self.tmpDir()) / model_name
161+
usdc_path = output_dir / f"{model_name}.usdc"
162+
163+
asset_identifier = urdf_usd_converter.Converter(layer_structure=False).convert(model, output_dir)
164+
self.assertTrue(usdc_path.exists())
165+
166+
# check that the asset identifier returned from convert() is the same as the usdc path
167+
flattened_usdc_path = pathlib.Path(asset_identifier.path).absolute().as_posix()
168+
self.assertEqual(flattened_usdc_path, usdc_path.absolute().as_posix())

urdf_usd_converter/_impl/_flatten.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 The Newton Developers
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Newton Developers
22
# SPDX-License-Identifier: Apache-2.0
33
import pathlib
44
import shutil
@@ -11,7 +11,7 @@
1111
from .utils import get_authoring_metadata
1212

1313

14-
def export_flattened(asset_stage: Usd.Stage, output_dir: str, asset_dir: str, asset_stem: str, asset_format: str, comment: str):
14+
def export_flattened(asset_stage: Usd.Stage, output_dir: str, asset_dir: str, asset_stem: str, asset_format: str, comment: str) -> str:
1515
output_path = pathlib.Path(output_dir)
1616
layer: Sdf.Layer = asset_stage.Flatten()
1717
asset_identifier = f"{output_path.absolute().as_posix()}/{asset_stem}.{asset_format}"
@@ -40,3 +40,4 @@ def export_flattened(asset_stage: Usd.Stage, output_dir: str, asset_dir: str, as
4040
Tf.Status(f"Copied textures from {temp_textures_dir} to {output_textures_dir}")
4141

4242
shutil.rmtree(asset_dir, ignore_errors=True)
43+
return asset_identifier

urdf_usd_converter/_impl/convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 The Newton Developers
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Newton Developers
22
# SPDX-License-Identifier: Apache-2.0
33
import pathlib
44
import tempfile
@@ -145,7 +145,7 @@ def convert(self, input_file: str, output_dir: str) -> Sdf.AssetPath:
145145

146146
# optionally flatten the asset
147147
if not self.params.layer_structure:
148-
export_flattened(asset_stage, output_dir, asset_dir, asset_stem, asset_format, self.params.comment)
148+
asset_identifier = export_flattened(asset_stage, output_dir, asset_dir, asset_stem, asset_format, self.params.comment)
149149
else:
150150
usdex.core.saveStage(asset_stage, comment=self.params.comment)
151151

0 commit comments

Comments
 (0)