Datasets:
Add Coaster 01, Multi-purpose Vessel II and V
Browse files- .gitattributes +3 -0
- README.md +73 -0
- coaster_01/coaster_01.glb +3 -0
- coaster_01/preview.png +3 -0
- metadata.jsonl +3 -0
- multi_purpose_vessel_ii/multi_purpose_vessel_ii.glb +3 -0
- multi_purpose_vessel_ii/preview.png +3 -0
- multi_purpose_vessel_v/multi_purpose_vessel_v.glb +3 -0
- multi_purpose_vessel_v/preview.png +3 -0
- schema.json +158 -0
- tools/preview.py +104 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
coaster_01/coaster_01.glb filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
multi_purpose_vessel_ii/multi_purpose_vessel_ii.glb filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
multi_purpose_vessel_v/multi_purpose_vessel_v.glb filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: SeaShapes
|
| 3 |
+
license:
|
| 4 |
+
- cc-by-4.0
|
| 5 |
+
tags:
|
| 6 |
+
- 3d
|
| 7 |
+
- glb
|
| 8 |
+
- maritime
|
| 9 |
+
- ships
|
| 10 |
+
- synthetic-data
|
| 11 |
+
size_categories:
|
| 12 |
+
- n<1K
|
| 13 |
+
configs:
|
| 14 |
+
- config_name: default
|
| 15 |
+
data_files:
|
| 16 |
+
- "*/preview.png"
|
| 17 |
+
- metadata.jsonl
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# SeaShapes
|
| 21 |
+
|
| 22 |
+
3D models of maritime objects, each with its real-world size and its source. One folder per asset, holding the model and a preview. `metadata.jsonl` describes every asset, one row each, and `schema.json` defines the fields.
|
| 23 |
+
|
| 24 |
+
## Query
|
| 25 |
+
|
| 26 |
+
In the Data Studio SQL console, or anywhere DuckDB runs:
|
| 27 |
+
|
| 28 |
+
```sql
|
| 29 |
+
SELECT id, category, length_m, width_m, licence
|
| 30 |
+
FROM 'hf://datasets/SEA-AI/seashapes/metadata.jsonl'
|
| 31 |
+
WHERE list_contains(tags, 'containers') AND length_m BETWEEN 80 AND 100;
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Pin a file by commit, never by branch:
|
| 35 |
+
|
| 36 |
+
```
|
| 37 |
+
https://huggingface.co/datasets/SEA-AI/seashapes/resolve/<commit>/<id>/<id>.glb
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
## Fields
|
| 41 |
+
|
| 42 |
+
| Field | Meaning |
|
| 43 |
+
|---|---|
|
| 44 |
+
| `id` | Folder name |
|
| 45 |
+
| `file_name` | Preview image, `<id>/preview.png` |
|
| 46 |
+
| `title`, `author`, `source_url`, `licence` | Attribution; `licence` is an SPDX identifier |
|
| 47 |
+
| `category`, `tags`, `description` | What the object is; `tags` are free filters |
|
| 48 |
+
| `length_m`, `width_m`, `height_m` | Real overall size, keel to top for a vessel |
|
| 49 |
+
| `size_source` | How the real size is known; model units are arbitrary |
|
| 50 |
+
| `file`, `format`, `size_bytes`, `sha256` | The file |
|
| 51 |
+
| `front_axis` | Where the front points in the file; omitted when it is glTF's `+z` |
|
| 52 |
+
| `triangles`, `textures`, `texture_max_px` | Mesh detail |
|
| 53 |
+
| `modified` | Whether the file differs from what the source offers |
|
| 54 |
+
| `added` | Date added |
|
| 55 |
+
|
| 56 |
+
`schema.json` is the authority; a row that fails it is not added.
|
| 57 |
+
|
| 58 |
+
## Adding an asset
|
| 59 |
+
|
| 60 |
+
1. Put the file in `<id>/` and add its row to `metadata.jsonl`; `schema.json` must accept it.
|
| 61 |
+
2. Render its preview from the dataset root: `uv run tools/preview.py <id>`. Every preview shows the front quarter from starboard, framed the same way.
|
| 62 |
+
|
| 63 |
+
## Licences
|
| 64 |
+
|
| 65 |
+
Each file keeps its author's licence, given per row in `metadata.jsonl`. Credit the author and link the source when you share a file or work made from it.
|
| 66 |
+
|
| 67 |
+
| Asset | Author | Source | Licence |
|
| 68 |
+
|---|---|---|---|
|
| 69 |
+
| Coaster 01 | [gogiart](https://sketchfab.com/agt14032013) | [Sketchfab](https://sketchfab.com/3d-models/e7cd3749189445fa8a0b928e5fb95814) | [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) |
|
| 70 |
+
| Multi-purpose Vessel II | [gogiart](https://sketchfab.com/agt14032013) | [Sketchfab](https://sketchfab.com/3d-models/e212591a799d4b568cf4df9279444adb) | [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) |
|
| 71 |
+
| Multi-purpose Vessel V | [gogiart](https://sketchfab.com/agt14032013) | [Sketchfab](https://sketchfab.com/3d-models/2f685e27d6a14e3fb65a12b9316b399f) | [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) |
|
| 72 |
+
|
| 73 |
+
The models are the GLBs Sketchfab offers for download, unmodified. Each `preview.png` is a render of its model made for this dataset, under the model's licence and attribution.
|
coaster_01/coaster_01.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:021333ff336f774fb752f31039860d472e5468281ab98c3b6ca4618272ec7a33
|
| 3 |
+
size 42469544
|
coaster_01/preview.png
ADDED
|
Git LFS Details
|
metadata.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"id": "coaster_01", "file_name": "coaster_01/preview.png", "title": "Coaster 01", "category": "container ship", "tags": ["vessel", "merchant", "coaster", "short-sea", "containers", "bridge-aft"], "description": "Small coaster with one tier of 20 ft containers stowed athwartships, bridge aft.", "length_m": 62.4, "width_m": 12.9, "height_m": 16.3, "size_source": "ISO 668 20 ft containers measured in the mesh (length and height agree within 2 %)", "triangles": 821196, "source_url": "https://sketchfab.com/3d-models/e7cd3749189445fa8a0b928e5fb95814", "file": "coaster_01/coaster_01.glb", "format": "glb", "size_bytes": 42469544, "sha256": "021333ff336f774fb752f31039860d472e5468281ab98c3b6ca4618272ec7a33", "textures": 54, "texture_max_px": 2048, "author": "gogiart", "licence": "CC-BY-4.0", "modified": false, "added": "2026-10-09"}
|
| 2 |
+
{"id": "multi_purpose_vessel_ii", "file_name": "multi_purpose_vessel_ii/preview.png", "title": "Multi-purpose Vessel II", "category": "general cargo ship", "tags": ["vessel", "merchant", "multipurpose", "containers", "cranes", "bridge-aft"], "description": "Multipurpose cargo ship carrying 20 ft containers, two deck cranes, bridge aft.", "length_m": 122.6, "width_m": 19.3, "height_m": 41.9, "size_source": "ISO 668 20 ft containers measured in the mesh (length and height agree within 0.2 %)", "triangles": 336146, "source_url": "https://sketchfab.com/3d-models/e212591a799d4b568cf4df9279444adb", "file": "multi_purpose_vessel_ii/multi_purpose_vessel_ii.glb", "format": "glb", "size_bytes": 21786012, "sha256": "138d9fcb2547cfcd089e4e21d7d14ebabe4389139b9dab9eff570d9ce7db7edc", "textures": 37, "texture_max_px": 1024, "author": "gogiart", "licence": "CC-BY-4.0", "modified": false, "added": "2026-10-09"}
|
| 3 |
+
{"id": "multi_purpose_vessel_v", "file_name": "multi_purpose_vessel_v/preview.png", "title": "Multi-purpose Vessel V", "category": "general cargo ship", "tags": ["vessel", "merchant", "multipurpose", "short-sea", "containers", "cranes", "bridge-forward"], "description": "Short-sea multipurpose ship carrying 20 ft containers, box cranes, bridge forward.", "length_m": 89.75, "width_m": 12.8, "height_m": 22.3, "size_source": "Damen Combi Freighter 3850, 89.75 m overall (damen.com); 20 ft containers in the mesh agree", "triangles": 322533, "source_url": "https://sketchfab.com/3d-models/2f685e27d6a14e3fb65a12b9316b399f", "file": "multi_purpose_vessel_v/multi_purpose_vessel_v.glb", "format": "glb", "size_bytes": 22706176, "sha256": "7eaaffea5e75661349c242e1c378c14ce090259576c7f406e01d655d832cb274", "textures": 48, "texture_max_px": 1024, "author": "gogiart", "licence": "CC-BY-4.0", "modified": false, "added": "2026-10-09"}
|
multi_purpose_vessel_ii/multi_purpose_vessel_ii.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:138d9fcb2547cfcd089e4e21d7d14ebabe4389139b9dab9eff570d9ce7db7edc
|
| 3 |
+
size 21786012
|
multi_purpose_vessel_ii/preview.png
ADDED
|
Git LFS Details
|
multi_purpose_vessel_v/multi_purpose_vessel_v.glb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7eaaffea5e75661349c242e1c378c14ce090259576c7f406e01d655d832cb274
|
| 3 |
+
size 22706176
|
multi_purpose_vessel_v/preview.png
ADDED
|
Git LFS Details
|
schema.json
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"title": "3D asset",
|
| 4 |
+
"description": "One line of metadata.jsonl: one asset, stored in the folder named by its id.",
|
| 5 |
+
"type": "object",
|
| 6 |
+
"additionalProperties": false,
|
| 7 |
+
"required": [
|
| 8 |
+
"id",
|
| 9 |
+
"file_name",
|
| 10 |
+
"title",
|
| 11 |
+
"category",
|
| 12 |
+
"file",
|
| 13 |
+
"format",
|
| 14 |
+
"size_bytes",
|
| 15 |
+
"sha256",
|
| 16 |
+
"triangles",
|
| 17 |
+
"author",
|
| 18 |
+
"source_url",
|
| 19 |
+
"licence",
|
| 20 |
+
"modified"
|
| 21 |
+
],
|
| 22 |
+
"dependentRequired": {
|
| 23 |
+
"length_m": [
|
| 24 |
+
"size_source"
|
| 25 |
+
],
|
| 26 |
+
"width_m": [
|
| 27 |
+
"size_source"
|
| 28 |
+
],
|
| 29 |
+
"height_m": [
|
| 30 |
+
"size_source"
|
| 31 |
+
]
|
| 32 |
+
},
|
| 33 |
+
"properties": {
|
| 34 |
+
"id": {
|
| 35 |
+
"type": "string",
|
| 36 |
+
"pattern": "^[a-z0-9_]+$",
|
| 37 |
+
"description": "Folder name; unique."
|
| 38 |
+
},
|
| 39 |
+
"file_name": {
|
| 40 |
+
"type": "string",
|
| 41 |
+
"pattern": "^[a-z0-9_]+/preview\\.png$",
|
| 42 |
+
"description": "Preview image: <id>/preview.png. The Hub shows it beside the row."
|
| 43 |
+
},
|
| 44 |
+
"title": {
|
| 45 |
+
"type": "string",
|
| 46 |
+
"minLength": 1,
|
| 47 |
+
"description": "The author's title."
|
| 48 |
+
},
|
| 49 |
+
"category": {
|
| 50 |
+
"type": "string",
|
| 51 |
+
"minLength": 1,
|
| 52 |
+
"description": "What the object is, lower case: 'general cargo ship', 'lateral mark'."
|
| 53 |
+
},
|
| 54 |
+
"tags": {
|
| 55 |
+
"type": "array",
|
| 56 |
+
"items": {
|
| 57 |
+
"type": "string",
|
| 58 |
+
"pattern": "^[a-z0-9-]+$"
|
| 59 |
+
},
|
| 60 |
+
"uniqueItems": true,
|
| 61 |
+
"description": "Free filters: 'containers', 'photogrammetry', 'low-poly'."
|
| 62 |
+
},
|
| 63 |
+
"description": {
|
| 64 |
+
"type": "string"
|
| 65 |
+
},
|
| 66 |
+
"length_m": {
|
| 67 |
+
"type": "number",
|
| 68 |
+
"exclusiveMinimum": 0,
|
| 69 |
+
"description": "Real overall length, metres."
|
| 70 |
+
},
|
| 71 |
+
"width_m": {
|
| 72 |
+
"type": "number",
|
| 73 |
+
"exclusiveMinimum": 0,
|
| 74 |
+
"description": "Real overall width (beam), metres."
|
| 75 |
+
},
|
| 76 |
+
"height_m": {
|
| 77 |
+
"type": "number",
|
| 78 |
+
"exclusiveMinimum": 0,
|
| 79 |
+
"description": "Real overall height, lowest to highest point (keel to top for a vessel), metres."
|
| 80 |
+
},
|
| 81 |
+
"size_source": {
|
| 82 |
+
"type": "string",
|
| 83 |
+
"minLength": 1,
|
| 84 |
+
"description": "How the real size is known: a reference object, a standard part measured in the mesh, or native units."
|
| 85 |
+
},
|
| 86 |
+
"file": {
|
| 87 |
+
"type": "string",
|
| 88 |
+
"pattern": "^[a-z0-9_]+/[^/]+$",
|
| 89 |
+
"description": "Path of the main file in the repo: <id>/<name>."
|
| 90 |
+
},
|
| 91 |
+
"format": {
|
| 92 |
+
"enum": [
|
| 93 |
+
"glb",
|
| 94 |
+
"gltf",
|
| 95 |
+
"fbx",
|
| 96 |
+
"obj",
|
| 97 |
+
"usdz"
|
| 98 |
+
]
|
| 99 |
+
},
|
| 100 |
+
"front_axis": {
|
| 101 |
+
"enum": [
|
| 102 |
+
"+z",
|
| 103 |
+
"-z",
|
| 104 |
+
"+x",
|
| 105 |
+
"-x"
|
| 106 |
+
],
|
| 107 |
+
"default": "+z",
|
| 108 |
+
"description": "Axis of the file the object's front (a vessel's bow) points along. glTF's convention is +z; set it only when the file departs from it."
|
| 109 |
+
},
|
| 110 |
+
"size_bytes": {
|
| 111 |
+
"type": "integer",
|
| 112 |
+
"exclusiveMinimum": 0
|
| 113 |
+
},
|
| 114 |
+
"sha256": {
|
| 115 |
+
"type": "string",
|
| 116 |
+
"pattern": "^[0-9a-f]{64}$"
|
| 117 |
+
},
|
| 118 |
+
"triangles": {
|
| 119 |
+
"type": "integer",
|
| 120 |
+
"exclusiveMinimum": 0
|
| 121 |
+
},
|
| 122 |
+
"textures": {
|
| 123 |
+
"type": "integer",
|
| 124 |
+
"minimum": 0,
|
| 125 |
+
"description": "Number of images."
|
| 126 |
+
},
|
| 127 |
+
"texture_max_px": {
|
| 128 |
+
"type": "integer",
|
| 129 |
+
"exclusiveMinimum": 0,
|
| 130 |
+
"description": "Longest side of the largest image."
|
| 131 |
+
},
|
| 132 |
+
"author": {
|
| 133 |
+
"type": "string",
|
| 134 |
+
"minLength": 1
|
| 135 |
+
},
|
| 136 |
+
"source_url": {
|
| 137 |
+
"type": "string",
|
| 138 |
+
"pattern": "^https://",
|
| 139 |
+
"description": "Page the asset was taken from."
|
| 140 |
+
},
|
| 141 |
+
"licence": {
|
| 142 |
+
"enum": [
|
| 143 |
+
"CC0-1.0",
|
| 144 |
+
"CC-BY-3.0",
|
| 145 |
+
"CC-BY-4.0"
|
| 146 |
+
],
|
| 147 |
+
"description": "SPDX identifier."
|
| 148 |
+
},
|
| 149 |
+
"modified": {
|
| 150 |
+
"type": "boolean",
|
| 151 |
+
"description": "True if the file differs from what the source offers."
|
| 152 |
+
},
|
| 153 |
+
"added": {
|
| 154 |
+
"type": "string",
|
| 155 |
+
"format": "date"
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
}
|
tools/preview.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# requires-python = "==3.13.*"
|
| 3 |
+
# dependencies = ["bpy>=5.2", "pillow"]
|
| 4 |
+
# ///
|
| 5 |
+
"""Render <id>/preview.png for each asset id given: the front quarter, from starboard.
|
| 6 |
+
|
| 7 |
+
uv run tools/preview.py coaster_01 multi_purpose_vessel_v
|
| 8 |
+
|
| 9 |
+
Run from the dataset root. Every preview gets the same view of its object and the
|
| 10 |
+
same framing, so thumbnails compare at a glance.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import json
|
| 14 |
+
import math
|
| 15 |
+
import sys
|
| 16 |
+
import tempfile
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
import bpy
|
| 20 |
+
from mathutils import Vector
|
| 21 |
+
from PIL import Image
|
| 22 |
+
|
| 23 |
+
OUT = (1024, 576)
|
| 24 |
+
MARGIN = 0.06 # of the width, on every side
|
| 25 |
+
AZIMUTH_DEG = 40.0 # from the front towards starboard
|
| 26 |
+
ELEVATION_DEG = 20.0
|
| 27 |
+
# glTF axis -> Blender axis, as Blender's glTF importer turns Y-up into Z-up.
|
| 28 |
+
AXES = {"+z": (0, -1, 0), "-z": (0, 1, 0), "+x": (1, 0, 0), "-x": (-1, 0, 0)}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def render(glb: Path, front_axis: str, out: Path) -> None:
|
| 32 |
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
| 33 |
+
bpy.ops.import_scene.gltf(filepath=str(glb))
|
| 34 |
+
for obj in [o for o in bpy.data.objects if o.type in {"CAMERA", "LIGHT"}]:
|
| 35 |
+
bpy.data.objects.remove(obj)
|
| 36 |
+
bpy.context.view_layer.update()
|
| 37 |
+
# An empty's bound_box is a point at its origin: measure meshes only.
|
| 38 |
+
pts = [
|
| 39 |
+
o.matrix_world @ Vector(c)
|
| 40 |
+
for o in bpy.data.objects
|
| 41 |
+
if o.type == "MESH"
|
| 42 |
+
for c in o.bound_box
|
| 43 |
+
]
|
| 44 |
+
lo = Vector([min(p[i] for p in pts) for i in range(3)])
|
| 45 |
+
hi = Vector([max(p[i] for p in pts) for i in range(3)])
|
| 46 |
+
centre, radius = (lo + hi) / 2, (hi - lo).length / 2
|
| 47 |
+
|
| 48 |
+
front = Vector(AXES[front_axis])
|
| 49 |
+
starboard = front.cross(Vector((0, 0, 1)))
|
| 50 |
+
az, el = math.radians(AZIMUTH_DEG), math.radians(ELEVATION_DEG)
|
| 51 |
+
view = (front * math.cos(az) + starboard * math.sin(az)) * math.cos(el)
|
| 52 |
+
view.z = math.sin(el)
|
| 53 |
+
|
| 54 |
+
sc = bpy.context.scene
|
| 55 |
+
sc.render.engine = "BLENDER_EEVEE"
|
| 56 |
+
# Twice the output, so the crop below has pixels to spare.
|
| 57 |
+
sc.render.resolution_x, sc.render.resolution_y = OUT[0] * 2, OUT[1] * 2
|
| 58 |
+
sc.render.film_transparent = True
|
| 59 |
+
sc.view_settings.view_transform = "Standard"
|
| 60 |
+
sc.world = bpy.data.worlds.new("world")
|
| 61 |
+
sc.world.use_nodes = True
|
| 62 |
+
background = sc.world.node_tree.nodes["Background"]
|
| 63 |
+
background.inputs["Color"].default_value = (0.8, 0.82, 0.85, 1)
|
| 64 |
+
sun = bpy.data.objects.new("sun", bpy.data.lights.new("sun", "SUN"))
|
| 65 |
+
sun.data.energy = 3.0
|
| 66 |
+
sun.rotation_euler = (math.radians(40), 0, math.radians(150))
|
| 67 |
+
sc.collection.objects.link(sun)
|
| 68 |
+
|
| 69 |
+
cam = bpy.data.objects.new("cam", bpy.data.cameras.new("cam"))
|
| 70 |
+
sc.collection.objects.link(cam)
|
| 71 |
+
sc.camera = cam
|
| 72 |
+
cam.data.lens = 50
|
| 73 |
+
cam.data.clip_end = radius * 100
|
| 74 |
+
# Far enough that the bounding sphere fits the frame's short side; the crop
|
| 75 |
+
# below does the real framing.
|
| 76 |
+
half_fov = math.atan(cam.data.sensor_width * OUT[1] / OUT[0] / 2 / cam.data.lens)
|
| 77 |
+
cam.location = centre + view * (radius / math.sin(half_fov) * 1.1)
|
| 78 |
+
cam.rotation_euler = (-view).to_track_quat("-Z", "Y").to_euler()
|
| 79 |
+
|
| 80 |
+
with tempfile.TemporaryDirectory() as tmp:
|
| 81 |
+
sc.render.filepath = str(Path(tmp) / "raw.png")
|
| 82 |
+
bpy.ops.render.render(write_still=True)
|
| 83 |
+
raw = Image.open(sc.render.filepath)
|
| 84 |
+
raw.load()
|
| 85 |
+
|
| 86 |
+
# Frame on the pixels: crop to the object, centre it, fit it inside the margin.
|
| 87 |
+
obj = raw.crop(raw.getchannel("A").getbbox())
|
| 88 |
+
room = (OUT[0] * (1 - 2 * MARGIN), OUT[1] - 2 * MARGIN * OUT[0])
|
| 89 |
+
k = min(room[0] / obj.width, room[1] / obj.height)
|
| 90 |
+
obj = obj.resize(
|
| 91 |
+
(round(obj.width * k), round(obj.height * k)), Image.Resampling.LANCZOS
|
| 92 |
+
)
|
| 93 |
+
canvas = Image.new("RGBA", OUT, (0, 0, 0, 0))
|
| 94 |
+
canvas.alpha_composite(obj, ((OUT[0] - obj.width) // 2, (OUT[1] - obj.height) // 2))
|
| 95 |
+
canvas.save(out)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
rows = {
|
| 99 |
+
r["id"]: r for r in map(json.loads, Path("metadata.jsonl").read_text().splitlines())
|
| 100 |
+
}
|
| 101 |
+
for asset in sys.argv[1:]:
|
| 102 |
+
row = rows[asset]
|
| 103 |
+
render(Path(row["file"]), row.get("front_axis", "+z"), Path(row["file_name"]))
|
| 104 |
+
print(row["file_name"])
|