Skip to content

Commit

Permalink
fix: remove gltf-transform dependency and update model download (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwagnerdev authored Feb 24, 2025
1 parent 133e50f commit f1a2bda
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 84 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/push_nova_rerun_bridge_image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install GLTF Transform CLI
run: npm install -g @gltf-transform/cli
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ This library provides an SDK for the Wandelbots NOVA API.

The SDK will help you to build your own apps and services on top of NOVA and makes programming a robot as easy as possible.



https://github.com/user-attachments/assets/0416151f-1304-46e2-a4ab-485fcda766fc



## Prerequisites

- A running Nova instance (get access at [wandelbots.com](https://www.wandelbots.com/))
Expand All @@ -30,8 +26,7 @@ wandelbots-nova = { version = ">=0.12", extras = ["nova-rerun-bridge"] }
```
```bash
# Download the latest robot models (depends on gltf-transform)
npm install -g @gltf-transform/cli
# Download the latest robot models
poetry run download-models
```
Expand Down Expand Up @@ -122,7 +117,6 @@ You need to download the robot models to visualize the robot models in the rerun
You can download the models by running the following command:
```bash
npm install -g @gltf-transform/cli
poetry run download-models
```
Expand Down Expand Up @@ -172,11 +166,13 @@ When having feature branches or forks, or might be helpful to test the library a
Poetry allows to pull the library from different sources. See the [Poetry Doc](https://python-poetry.org/docs/dependency-specification/#git-rev-project) for more information.
Poetry Version < 2:
```toml
wandelbots-nova = { git = "https://github.com/wandelbotsgmbh/wandelbots-nova.git", branch = "fix/http-prefix" }
```
Poetry Version >=2
```toml
wandelbots-nova @ git+https://github.com/wandelbotsgmbh/wandelbots-nova.git@fix/http-prefix
```
Expand Down
3 changes: 0 additions & 3 deletions nova_rerun_bridge/helper_scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
After installing the library, you need to download the robot models:

```bash
# Install the gltf-transform-cli, needed to unpack the models
npm install -g @gltf-transform/cli

# If installed via poetry
poetry run download-models

Expand Down
77 changes: 18 additions & 59 deletions nova_rerun_bridge/helper_scripts/download_models.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import subprocess
import tempfile
from pathlib import Path
from zipfile import ZipFile

import requests

"""
This script downloads the latest robot models from the wandelbots-js-react-components repository
and processes them using gltf-transform to make them compatible with the Wandelbots SDK.
Install gltf-transform with: npm install -g @gltf-transform/cli
This script downloads the pre-processed robot models from the wandelbots-js-react-components repository.
These models are already optimized and don't require additional processing.
"""


def get_project_root() -> Path:
"""Get the root directory of the user's project"""
# Start from current working directory and look for common project markers
cwd = Path.cwd()
markers = ["pyproject.toml", "setup.py", ".git"]

Expand All @@ -24,7 +21,6 @@ def get_project_root() -> Path:
return current
current = current.parent

# Fallback to cwd if no project root found
return cwd


Expand All @@ -45,55 +41,25 @@ def get_latest_release_version() -> str:
return response.json()["tag_name"].lstrip("v")


def download_and_extract(version: str, tmp_dir: Path) -> Path:
zip_url = f"https://github.com/wandelbotsgmbh/wandelbots-js-react-components/archive/refs/tags/v{version}.zip"
def download_and_extract(version: str, models_dir: Path) -> None:
"""Download and extract pre-processed models directly to models directory"""
zip_url = f"https://github.com/wandelbotsgmbh/wandelbots-js-react-components/releases/download/v{version}/no-draco-models.zip"
print(f"Downloading {zip_url}...")

response = requests.get(zip_url)
if response.status_code != 200:
raise Exception(f"Failed to download: {response.status_code}")

zip_path = tmp_dir / f"{version}.zip"
zip_path.write_bytes(response.content)

with ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(tmp_dir)

return tmp_dir / f"wandelbots-js-react-components-{version}/public/models"


def check_gltf_transform():
try:
subprocess.run(["gltf-transform", "--version"], check=True, capture_output=True)
except (subprocess.CalledProcessError, FileNotFoundError):
raise RuntimeError(
"gltf-transform not found. Install with: npm install -g @gltf-transform/cli"
)


def decompress_glb(input_path: Path, output_path: Path):
"""Process GLB using gltf-transform"""
temp_path = output_path.with_suffix(".temp.glb")

# First decompress draco
subprocess.run(
["gltf-transform", "dedup", str(input_path), str(temp_path)],
check=True,
capture_output=True,
)

# Then convert to unlit
subprocess.run(
["gltf-transform", "unlit", str(temp_path), str(output_path)],
check=True,
capture_output=True,
)
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
zip_path = tmp_path / "models.zip"
zip_path.write_bytes(response.content)

temp_path.unlink()
with ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(models_dir)


def update_robot_models():
check_gltf_transform()
version = get_latest_release_version()
models_dir = Path.cwd() / "models"
current_version = get_current_version(models_dir)
Expand All @@ -102,23 +68,16 @@ def update_robot_models():
print("Models are up to date")
return

with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
new_models_dir = download_and_extract(version, tmp_path)

# Create models directory if it doesn't exist
models_dir.mkdir(parents=True, exist_ok=True)
# Create models directory if it doesn't exist
models_dir.mkdir(parents=True, exist_ok=True)

# Process all GLB files
for glb_file in new_models_dir.rglob("*.glb"):
output_path = models_dir / glb_file.name
print(f"Processing {glb_file.name}...")
decompress_glb(glb_file, output_path)
# Download and extract pre-processed models
download_and_extract(version, models_dir)

# Write version file
(models_dir / "version.txt").write_text(version)
# Write version file
(models_dir / "version.txt").write_text(version)

print(f"Successfully updated robot models {current_version}{version}")
print(f"Successfully updated robot models {current_version}{version}")


if __name__ == "__main__":
Expand Down
9 changes: 0 additions & 9 deletions nova_rerun_bridge/helper_scripts/unpack_models.sh

This file was deleted.

0 comments on commit f1a2bda

Please sign in to comment.