File size: 7,585 Bytes
926bcd5
9466dee
680610a
 
 
 
 
9466dee
 
 
 
 
 
 
 
e724072
926bcd5
 
9466dee
 
 
 
 
926bcd5
 
4041d56
 
6829da0
3cf794d
e8096b1
3cf794d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f05399
 
926bcd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3cf794d
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
---
pretty_name: OpenSCAD
configs:
- config_name: default
  data_files:
  - split: train
    path: dataset.parquet
tags:
- 3d
- text
- open-scad
- cad
- glb
- code
- hf
- datasets
size_categories:
- 10K<n<100K
license: other
task_categories:
- text-to-3d
language:
- en
---

<video video controls loop muted plays inline preload="metadata" width="100%" src="https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/uXLm9OIWINJt_HyvUqaDw.mp4"></video>

# **OpenSCAD-Code-to-3D-HF**

**OpenSCAD-Code-to-3D-HF** is a dataset built on top of [CodeCAD-HF-v2](https://huggingface.co/datasets/prithivMLmods/CodeCAD-HF-v2). It pairs natural language prompts with their corresponding OpenSCAD parametric code and references to rendered GLB (GL Transmission Format Binary) 3D model files. The dataset provides text-based descriptions, procedural 3D modeling code, and corresponding 3D assets. The GLB files are distributed separately in a ZIP archive, `glb.zip`, with **~53,172 mapped data entries** identified through file mapping between the dataset records and the archived GLB files. The OpenSCAD code-to-GLB conversion infrastructure is powered by Hugging Face and HF Jobs, enabling the conversion of OpenSCAD parametric code into rendered GLB 3D model assets.

## Dataset Statistics

| Property | Value |
|----------|-------|
| Dataset Repository | `prithivMLmods/OpenSCAD-Code-to-3D-HF` |
| Number of Mapped Data Entries | ~53,172 |
| GLB Storage | `glb.zip` |
| Main Dataset File | `dataset.parquet` |
| Data Format | Parquet + ZIP archive |
| Modalities | Text, 3D |

## Dataset Structure

| Column | Type | Description |
|--------|------|-------------|
| `Prompt` | string | Natural language description of the 3D model |
| `Code` | string | OpenSCAD parametric code that generates the model |
| `3d_glb` | string | File path reference to the corresponding rendered `.glb` 3D model inside the ZIP archive |

## GLB File Mapping

The GLB assets are stored in `glb.zip` rather than as individual files directly in the dataset repository. The `3d_glb` column contains references that can be mapped to the corresponding files in the archive.

The dataset mapping procedure identifies matching GLB files by filename and generates the following reports:

- `mapped_data.txt`: Dataset rows successfully mapped to GLB files in the ZIP archive.
- `unmapped_data.txt`: Dataset rows with empty GLB references or references to files that were not found in the archive.
- `zip_only_data.txt`: GLB archive filenames that are not referenced by any dataset row.

A total of **53,172 mapped data entries** were identified through this process.

## Usage

Install the required dependencies:

```bash
pip install -U datasets pandas pyarrow
```

Load the dataset:

```python
from datasets import load_dataset

ds = load_dataset(
    "prithivMLmods/OpenSCAD-Code-to-3D-HF",
    data_files="dataset.parquet"
)

print(ds["train"][0])
```

To access the GLB assets, download `glb.zip` from the dataset repository and extract the archive. The `3d_glb` references can then be matched to the extracted files using the mapping procedure.

## Dataset and GLB File Mapping

```
pip install -U huggingface_hub
```

```py
import os
import subprocess
import pandas as pd
from collections import defaultdict
from huggingface_hub import hf_hub_download

REPO_ID  = "prithivMLmods/OpenSCAD-Code-to-3D-HF"
WORK_DIR = "openscad_check"
EXTRACT  = os.path.join(WORK_DIR, "extracted")
MAPPED   = "mapped_data.txt"
UNMAPPED = "unmapped_data.txt"
ZIP_ONLY = "zip_only_data.txt"

os.makedirs(EXTRACT, exist_ok=True)

# 1. Download
parquet_path = hf_hub_download(repo_id=REPO_ID, filename="dataset.parquet",
                               repo_type="dataset", local_dir=WORK_DIR)
zip_path     = hf_hub_download(repo_id=REPO_ID, filename="glb.zip",
                               repo_type="dataset", local_dir=WORK_DIR)

# 2. Unzip using native system unzip command
print(f"Extracting {zip_path} via system unzip...")
try:
    subprocess.run(["unzip", "-o", "-q", zip_path, "-d", EXTRACT], check=True)
    print("Extraction complete.")
except subprocess.CalledProcessError as e:
    print(f"System unzip failed: {e}")

# 3. Index every file in the extracted folder by FILE NAME
zip_index = defaultdict(list)
for root, _, files in os.walk(EXTRACT):
    for fn in files:
        rel = os.path.relpath(os.path.join(root, fn), EXTRACT).replace("\\", "/")
        zip_index[fn].append(rel)

total_zip_files = sum(len(v) for v in zip_index.values())
print(f"Files in zip folder : {total_zip_files}")
print(f"Unique file names   : {len(zip_index)}")

# 4. Load parquet
df = pd.read_parquet(parquet_path)
total_rows = len(df)
print(f"Rows in parquet     : {total_rows}")
print(f"Columns             : {list(df.columns)}")

# 5. Map 3d_glb file names -> zip file names
mapped, unmapped = [], []
empty_count   = 0   # 3d_glb is null / empty
missing_count = 0   # 3d_glb has a value but file not found in zip
used_names    = set()
glb_name_counts = defaultdict(int)

for idx, val in df["3d_glb"].items():
    if val is None or (isinstance(val, float) and pd.isna(val)) or str(val).strip() == "":
        unmapped.append((idx, "<EMPTY>"))
        empty_count += 1
        continue

    col_path = str(val).strip().replace("\\", "/")
    fname    = os.path.basename(col_path)
    glb_name_counts[fname] += 1

    if fname in zip_index:
        used_names.add(fname)
        mapped.append((idx, col_path, ", ".join(zip_index[fname])))
    else:
        unmapped.append((idx, col_path))
        missing_count += 1

# 6. Files in zip that no row points to
zip_only = sorted(set(zip_index.keys()) - used_names)

# 7. Write outputs
with open(MAPPED, "w", encoding="utf-8") as f:
    for idx, col_path, zip_rel in mapped:
        f.write(f"{idx}\t{col_path}\t{zip_rel}\n")

with open(UNMAPPED, "w", encoding="utf-8") as f:
    for idx, col_path in unmapped:
        f.write(f"{idx}\t{col_path}\n")

with open(ZIP_ONLY, "w", encoding="utf-8") as f:
    for fn in zip_only:
        f.write(f"{fn}\n")

# 8. Summary
mapped_n   = len(mapped)
unmapped_n = len(unmapped)
non_empty  = total_rows - empty_count
dup_rows   = sum(c for c in glb_name_counts.values() if c > 1)
dup_names  = sum(1 for c in glb_name_counts.values() if c > 1)

def pct(n, d):
    return f"{(n / d * 100):.2f}%" if d else "n/a"

print("\n===== SUMMARY =====")
print(f"Total rows                      : {total_rows}")
print(f"MAPPED (file found in zip)      : {mapped_n}  ({pct(mapped_n, total_rows)})")
print(f"UNMAPPED (total)                : {unmapped_n}  ({pct(unmapped_n, total_rows)})")
print(f"   - 3d_glb empty / null        : {empty_count}")
print(f"   - file name not in zip       : {missing_count}")
print(f"Non-empty 3d_glb rows           : {non_empty}")
print(f"Mapped among non-empty rows     : {mapped_n}/{non_empty}  ({pct(mapped_n, non_empty)})")
print(f"Unique zip files used           : {len(used_names)}")
print(f"Zip files not in any row        : {len(zip_only)}")
print(f"Rows sharing a GLB file name    : {dup_rows}  (across {dup_names} file names)")
print(f"\nSaved -> {MAPPED}   (row_index | 3d_glb value | path in zip folder)")
print(f"Saved -> {UNMAPPED}   (row_index | 3d_glb value)")
print(f"Saved -> {ZIP_ONLY}   (file names present in zip but not referenced)")
```

## Source Dataset

This dataset is derived from [CodeCAD-HF-v2](https://huggingface.co/datasets/prithivMLmods/CodeCAD-HF-v2).

## License

Please refer to the original [CodeCAD paper](https://dl.acm.org/doi/10.1145/3770855.3817592) for source data license terms.