Skip to content

Commit b3fc92e

Browse files
committed
refactored parameters, log functions
1 parent b0c0734 commit b3fc92e

File tree

8 files changed

+294
-146
lines changed

8 files changed

+294
-146
lines changed

README.md

Lines changed: 81 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
This repo contains a shell script (bash) for uploading scene files to the Cognitive3D platform.
44

5-
## Scene Upload Script
6-
7-
This script uploads a set of 3D scene files to the Cognitive3D API.
5+
## Requirements
86

9-
### Requirements
10-
11-
* Bash (macOS/Linux)
7+
* Bash (macOS / Linux / Windows Subsystem for Linux (WSL))
128
* `curl`
139
* `jq`
1410

15-
### Installation
11+
### Installation of required dependencies
1612

1713
Make sure the following tools are installed:
1814

@@ -22,59 +18,60 @@ sudo apt install jq curl # Ubuntu/Debian
2218
dnf install jq curl # Fedora/RHEL
2319
```
2420

25-
### Usage
21+
### Environment Variables
22+
23+
You must set your Cognitive3D Developer API key as an environment variable:
2624

2725
```bash
28-
./scene-upload.sh <scene_directory> [environment] [scene_id]
26+
export C3D_DEVELOPER_API_KEY="your_api_key"
2927
```
3028

31-
#### Parameters
32-
33-
* `<scene_directory>` (required): Path to a folder containing:
34-
35-
* `scene.bin`
36-
* `scene.gltf`
37-
* `screenshot.png`
38-
* `settings.json`
29+
You can get your developer API key from the Cognitive3D web dashboard. Look for the "Manage developer key" option in the settings (gear icon) menu.
3930

40-
* `[environment]` (optional): Either `prod` (default) or `dev`
31+
> Note: We strongly recommend you _do not_ store your developer API key in version control.
4132
42-
* `[scene_id]` (optional): Scene ID to append to the API endpoint to upload a new version of an existing scene
33+
## Scene Upload Script
4334

44-
#### Environment Variables
35+
This script uploads a set of 3D scene files to the Cognitive3D platform using our API.
4536

46-
You must set your Cognitive3D developer API key as an environment variable:
37+
### Usage
4738

4839
```bash
49-
export C3D_DEVELOPER_API_KEY="your_api_key"
40+
./upload-scene.sh --scene_dir <scene_directory> [--env <prod|dev>] [--scene_id <scene_id_from_dashboard>]
5041
```
5142

52-
You can get your developer API key from the Cognitive3D web dashboard. Look for the "Manage developer key" option in the settings (gear icon) menu.
43+
#### Parameters
5344

54-
> Note: We strongly recommend you _do not_ store your developer API key in version control.
45+
* `--scene_dir <scene_directory>` (required): Path to a folder containing:
46+
* `scene.bin`
47+
* `scene.gltf`
48+
* `screenshot.png`
49+
* `settings.json`
50+
* `[--env <prod/dev>]` (optional): Either `prod` (default) or `dev`
51+
* `[--scene_id <scene_id_from_dashboard>]` (optional): Scene ID to append to the API endpoint to upload a new version of an existing scene
5552

5653
### Example
5754

5855
For the first time you upload your scene you won't have a scene ID, so we don't pass that parameter. The first time you run this script, without a scene ID, it creates the scene and returns the new scene ID (output to the console at the end of the script.)
5956

6057
```bash
61-
export C3D_DEVELOPER_API_KEY="abc123xyz"
62-
./scene-upload.sh ./TestScene prod
58+
export C3D_DEVELOPER_API_KEY=<abc123xyz>
59+
./upload-scene.sh --scene_dir ./TestScene --env prod
6360
```
6461

6562
For subsequent (new) versions of the same scene, pass in your scene ID as the third parameter to the script. This will upload the scene assets again and the platform will auto-increment the scene version.
6663

6764
You can find the scene ID on the Cognitive3D dashboard on the Scenes page. Look for the "information" icon (letter 'i' in a circle) and hover over it.
6865

6966
```bash
70-
export C3D_DEVELOPER_API_KEY="abc123xyz"
71-
./scene-upload.sh ./TestScene prod my-scene-id
67+
export C3D_DEVELOPER_API_KEY=<abc123xyz>
68+
./upload-scene.sh --scene_dir ./TestScene --env prod --scene_id my_scene_id
7269
```
7370

7471
### Behavior
7572

7673
* Reads the SDK version from `sdk-version.txt` in the same directory as the script.
77-
* Replaces the `sdkVersion` field inside `settings.json` using `jq`.
74+
* Replaces the `sdkVersion` field inside `settings.json` file in the scene directory using `jq`.
7875
* Uploads the four files to the correct API endpoint.
7976
* Verifies API response and prints success or error.
8077

@@ -83,23 +80,19 @@ export C3D_DEVELOPER_API_KEY="abc123xyz"
8380
To see usage information:
8481

8582
```bash
86-
./scene-upload.sh --help
83+
./upload-scene.sh --help
8784
```
8885

8986
## Dynamic object uploader script
9087

9188
This Bash script uploads dynamic 3D object assets to the Cognitive3D platform, supporting GLTF + BIN files, optional textures, and thumbnail metadata. It supports both development and production environments.
9289

93-
### Dynamic object uploader requirements
94-
95-
* Bash 4+
96-
* `curl`
97-
* A Cognitive3D Developer API key (set as an environment variable)
90+
Uploading a scene to the platform is required before you can upload any dynamic object models. The scene_id is a required parameter.
9891

9992
### Dynamic object uploader usage
10093

10194
```bash
102-
./upload-dynamic-object.sh \
95+
./upload-object.sh \
10396
--scene_id <scene-uuid> \
10497
--object_filename <object-name> \
10598
--object_dir <path-to-object-directory> \
@@ -114,10 +107,10 @@ This Bash script uploads dynamic 3D object assets to the Cognitive3D platform, s
114107
* `--scene_id`: The Scene ID UUID where the object will be uploaded.
115108
* `--object_filename`: The base filename (no extension) of the object, used to find `.gltf` and `.bin` files.
116109
* `--object_dir`: The directory containing the object files.
117-
* `--object_id`: If specified, uploads as a new version of an existing object.
118110

119111
#### Optional Parameters
120112

113+
* `--object_id`: If specified, uploads as a new version of an existing object.
121114
* `--env`: Target environment (`prod` or `dev`). Defaults to `prod`.
122115
* `--verbose`: Enables detailed logging.
123116
* `--dry_run`: Prints the constructed `curl` command but skips execution.
@@ -132,16 +125,16 @@ The following files must exist in the `--object_dir`:
132125

133126
* `<object_filename>.gltf`
134127
* `<object_filename>.bin`
135-
* (Optional, recommended) `cvr_object_thumbnail.png`
128+
* (Optional, recommended) `cvr_object_thumbnail.png`, a representative screenshot of the object; used by the dashboard
136129
* (Optional) Any additional `.png` textures used by the model
137130

138131
### Dynamic object uploader example
139132

140133
```bash
141-
export C3D_DEVELOPER_API_KEY="your-api-key"
134+
export C3D_DEVELOPER_API_KEY=<your-api-key>
142135

143-
./object-upload.sh \
144-
--scene_id scene_id_goes_here \
136+
./upload-object.sh \
137+
--scene_id <scene_id_goes_here> \
145138
--object_filename cube \
146139
--object_dir object-test \
147140
--env prod \
@@ -161,13 +154,53 @@ export C3D_DEVELOPER_API_KEY="your-api-key"
161154
* `--dry_run` shows the `curl` command without executing it
162155
* Colored output highlights info, warnings, errors, and debug details
163156

164-
### Examples
157+
### Uploading the object manifest
158+
159+
After uploading the dynamic object asset files (mesh, textures) you must upload the dynamic object manifest file to display the objects on the Cognitive3D dashboard for your project and scene.
160+
161+
### Dynamic object manifest uploader usage
162+
163+
The dynamic object manifest for your scene and object is created automatically after successfully uploading the dynamic object assets. It will be in a file named `<scene_id>_object_manifest.json`.
165164

166165
```bash
167-
./object-upload.sh \
168-
--scene_id fea64809-2a44-4b0c-acc1-a66f371521a8 \
169-
--env dev \
170-
--object_dir lantern-test \
171-
--object_filename Lantern \
172-
--object_id Lantern
166+
./upload-object-manifest.sh \
167+
--scene_id <scene-uuid> \
168+
[--env dev|prod] \
169+
[--verbose] \
173170
```
171+
172+
#### Dynamic object manifest uploader required parameters
173+
174+
* `--scene_id`: The Scene ID UUID where the object will be uploaded.
175+
176+
#### Object manifest uploader optional parameters
177+
178+
* `--object_id`: If specified, uploads as a new version of an existing object.
179+
* `--env`: Target environment (`prod` or `dev`). Defaults to `prod`.
180+
* `--verbose`: Enables detailed logging.
181+
* `--dry_run`: Prints the constructed `curl` command but skips execution.
182+
183+
### Dynamic object manifest uploader environment variables
184+
185+
* `C3D_DEVELOPER_API_KEY`: Your Cognitive3D Developer API key (required).
186+
187+
### Dynamic object manifest uploader file requirements
188+
189+
The following files must exist in the same directory where you are calling the script from:
190+
191+
* `<scene_id>_object_manifest.json`, which is automatically created after successfully uploading your dynamic object meshes
192+
193+
### Dynamic object manifest uploader example
194+
195+
```bash
196+
export C3D_DEVELOPER_API_KEY=<your-api-key>
197+
198+
./upload-object-manifest.sh \
199+
--scene_id <scene_id_goes_here> \
200+
--env prod \
201+
--verbose
202+
```
203+
204+
The reason we don't automatically upload the manifest after uploading the object assets is to allow you to modify the manifest JSON before uploading.
205+
206+
If you have any questions or problems using these scripts contact our customer support team using the Intercom button (public circle) on any Cognitive3D web page.

list-objects.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ debug() {
2424
}
2525

2626
usage() {
27-
echo "Usage: $0 --sceneId <scene_id> --env <prod|dev> [--verbose] [--debug]"
27+
echo "Usage: $0 --scene_id <scene_id> --env <prod|dev> [--verbose] [--debug]"
2828
exit 1
2929
}
3030

@@ -43,7 +43,7 @@ fi
4343
while [[ $# -gt 0 ]]; do
4444
key="$1"
4545
case $key in
46-
--sceneId)
46+
--scene_id)
4747
SCENE_ID="$2"
4848
shift; shift
4949
;;

scene-test/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"scale": 1,
3-
"sceneName": "Test scene 1",
4-
"sdkVersion": "0.1.1"
3+
"sceneName": "Test scene 5",
4+
"sdkVersion": "0.1.3"
55
}

sdk-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.2
1+
0.1.3

test-all.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# usage: test-all.sh <scene_id> <env>
4+
# This script runs a series of upload and list commands for a given scene and environment.
5+
6+
# Required: Run `./upload-scene.sh` script with no scene_id first; use that scene_id for this script.
7+
8+
# get SCENE_ID from the first argument
9+
SCENE_ID="$1"
10+
11+
# get ENV from the second argument
12+
ENV="$2"
13+
14+
echo "Running tests for scene ID: $SCENE_ID in environment: $ENV"
15+
## wait for enter key
16+
read -p "Press Enter to continue..."
17+
18+
./upload-scene.sh --scene_id $SCENE_ID --scene_dir scene-test --env $ENV --verbose
19+
20+
./upload-object.sh --scene_id $SCENE_ID --object_filename cube --object_id cube --object_dir object-test --env $ENV --verbose
21+
22+
./upload-object-manifest.sh --scene_id $SCENE_ID --env $ENV --verbose
23+
24+
./upload-object.sh --scene_id $SCENE_ID --object_filename Lantern --object_id Lantern --object_dir lantern-test --env $ENV --verbose
25+
26+
./upload-object-manifest.sh --scene_id $SCENE_ID --env $ENV --verbose
27+
28+
./list-objects.sh --scene_id $SCENE_ID --env $ENV --verbose

0 commit comments

Comments
 (0)