forked from KhronosGroup/glTF-Sample-Models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-index.py
executable file
·42 lines (37 loc) · 1.35 KB
/
generate-index.py
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
#!/usr/bin/env python
import json
import os
def generate_index(root):
os.chdir(root)
index = []
for model in sorted(os.listdir(".")):
if not os.path.isdir(model):
continue
os.chdir(model)
model_contents = os.listdir(".")
gltf_variant_dirs = [d for d in model_contents if d.startswith("glTF")]
variants = {}
for variant_dir in gltf_variant_dirs:
model_file = [f for f in os.listdir(variant_dir)
if f.endswith(".glb") or f.endswith(".gltf")][0]
variants[variant_dir] = model_file
if not variants:
print ("WARNING: no model files found for {}".format(model))
else:
model_info = {
"name": model,
"variants": variants,
"screenshot": None
}
if "screenshot" not in model_contents:
print ("WARNING: no screenshot found for {}".format(model))
else:
model_info["screenshot"] = "screenshot/" + [s for s in os.listdir("screenshot") if s.startswith("screenshot.")][0]
index.append(model_info)
os.chdir("..")
with open("model-index.json", "w") as f:
json.dump(index, f, indent=2, sort_keys=True)
f.write("\n")
os.chdir("..")
generate_index("1.0")
generate_index("2.0")