⚠️ Note: An updated API example is available at RapidPipeline API Sample. While this script remains functional, we recommend checking out the new example for the latest features and best practices.
A scripting tool for the RapidCompact REST API, based on Python and acting as a command line tool.
This script should serve as demonstration and starting point for your own API-based integration of RapidCompact.
The script's usage of the RapidCompact Upload Endpoint does not allow for "loose" files and whenever a 3D format has more than one self-contained file (e.g. glTF with bin file and textures) these need to be in a zip compressed package. In addition the script currently does not support sub-directories (e.g. input/myfile/myfile.glb).
To optimize one or multiple 3D models, to one or multiple target resolutions, simply perform the following steps:
-
Make sure you have Python 3 installed.
-
Edit "credentials.json" and enter your API token.
-
Edit the "variants.json" file to specify the desired resolution and output formats for your models (or keep it as-is for a first test run).
-
Execute a command line (for example, using Windows PowerShell) to invoke the
rpdc.py
script. Example:
python3 rpdc.py input
This will optimize all 3D models in directory "input" to all desired variants (see configuration of variants in previous step), creating a directory "output" with the results. Alternatively, instead of using an input directory, you can also optimize single input files (example:python3 rpdc.py input/teapot.glb
).
-
That's it! The resulting optimized models should show up in directory "output".
Feel free to use this script as a basis for your own API-based integration, as well as to submit feature requests or pull requests for your changes right here.
To learn more about the available parameters of the script, use the "help" function:
python3 rpdc.py -h
or python rpdc.py -h
(depending on your Python setup)
Also, feel free to browse the documented source code, which also helps you to set up your own RapidCompact API integration.
If you want to use your variants.json with the CLI version of RapidCompact, you need to translate it first to the CLI format. For this you can use the rpdt script in the utils directory of this repository.
-
Make sure you have Python 3 installed.
-
Edit "credentials.json" and enter your API token.
-
Edit the "variants.json" file to specify the desired resolution and output formats for your models (or keep it as-is for a first test run).
-
Open a command line (for example, using Windows PowerShell) to invoke the
rpdt.py
script.
Example:python3 utils/rpdt.py
This will request a translated version of your variants.json configuration and place the CLI configuration of it in the output folder.
-
Open the folders in the output directory to retrieve your cli commands