Skip to content

Commit 4710e9a

Browse files
Merge pull request #13 from sethgi/feature/asset_path
Asset Path Update such that user now needs to run register_asset_path.py to register an assets path in a json file.
2 parents ed3e592 + 59431ad commit 4710e9a

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed

config/register_asset_path.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import sys
3+
import json
4+
5+
def main():
6+
if len(sys.argv) != 2:
7+
print("Usage: python register_asset_path.py <path_to_assets>")
8+
sys.exit(1)
9+
10+
asset_path = sys.argv[1]
11+
12+
if not os.path.exists(asset_path):
13+
print(f"Error: Provided path does not exist: {asset_path}")
14+
sys.exit(1)
15+
16+
json_data = {"asset_path": os.path.abspath(asset_path)}
17+
oceansim_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
18+
json_path = os.path.join(oceansim_root, 'isaacsim', 'oceansim', 'utils', 'asset_path.json')
19+
20+
with open(json_path, 'w') as f:
21+
json.dump(json_data, f, indent=2)
22+
23+
print(f"Asset path registered successfully: {json_data['asset_path']}")
24+
25+
if __name__ == "__main__":
26+
main()

docs/subsections/installation.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ git clone https://github.com/umfieldrobotics/OceanSim.git
1919

2020
Download `OceanSim_assets` from [Google Drive](https://drive.google.com/drive/folders/1qg4-Y_GMiybnLc1BFjx0DsWfR0AgeZzA?usp=sharing) which contains USD assets of robot and environment.
2121

22-
And change function `get_oceansim_assets_path()` in [~/isaacsim/extsUser/OceanSim/isaacsim/oceansim/utils/assets_utils.py](../../isaacsim/oceansim/utils/assets_utils.py) to return the path to the installed assets folder.
22+
Then, run the following to configure OceanSim to point to your asset path:
23+
2324
```bash
24-
def get_oceansim_assets_path() -> str:
25-
return "/path/to/downloaded/assets/OceanSim_assets"
25+
cd /path/to/OceanSim
26+
python3 config/register_asset_path.py /path/to/OceanSim_assets
2627
```
2728

2829
Launch Isaac Sim following this [guide](https://docs.isaacsim.omniverse.nvidia.com/latest/installation/install_workstation.html#isaac-sim-short-app-selector).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"asset_path": null
3+
}
Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
import os
2+
import json
3+
4+
OCEANSIM_ASSET_PATH=None
5+
16
def get_oceansim_assets_path() -> str:
2-
# return "/home/haoyu/Desktop/OceanSim_assets"
3-
return "/home/haoyu-ma/Desktop/OceanSim_assets"
7+
global OCEANSIM_ASSET_PATH
8+
9+
if OCEANSIM_ASSET_PATH is not None:
10+
return OCEANSIM_ASSET_PATH
11+
12+
json_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'asset_path.json'))
13+
14+
if not os.path.isfile(json_path):
15+
raise FileNotFoundError(
16+
f"'asset_path.json' not found at {json_path}. "
17+
"Run 'register_asset_path.py <path_to_assets>' to register the asset path."
18+
)
19+
20+
try:
21+
with open(json_path, 'r') as f:
22+
json_data = json.load(f)
23+
except json.JSONDecodeError as e:
24+
raise ValueError(f"'asset_path.json' is not valid JSON: {e}")
25+
26+
if "asset_path" not in json_data:
27+
raise KeyError(
28+
f"'asset_path.json' at {json_path} does not contain the required 'asset_path' key."
29+
)
30+
31+
asset_path = json_data["asset_path"]
32+
33+
if not os.path.isdir(asset_path):
34+
raise FileNotFoundError(f"The provided asset path does not exist: {asset_path}. "
35+
"Run /path/to/oceansim/config/register_asset_path.py /path/to/assets as described in the ReadMe.")
36+
37+
OCEANSIM_ASSET_PATH = asset_path
38+
return asset_path
39+
40+
# Run once to validate on import
41+
get_oceansim_assets_path()
42+
43+
if __name__ == "__main__":
44+
print("OceanSim Assets are configured at", get_oceansim_assets_path())

0 commit comments

Comments
 (0)