Datasets:
Download tool/python/blender_check.py from codepawl/asset-index: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/datasets/codepawl/asset-index/resolve/main/tool/python/blender_check.py
- Command line
-
hf download hf://datasets/codepawl/asset-index/tool/python/blender_check.py
-
curl -L -o blender_check.py https://huggingface.co/datasets/codepawl/asset-index/resolve/main/tool/python/blender_check.py
1.83 kB
| # Imports each GLB listed in a text file into an empty Blender scene and prints one JSON line per file: | |
| # {"file", "ok", "meshes", "triangles", "armatures", "actions", "frames", "error"}. | |
| # A file passes with a mesh, or (a skeleton-only clip) with an armature and an action that has keys. | |
| # Usage: blender -b --factory-startup --python blender_check.py -- <file_list.txt> | |
| import json | |
| import sys | |
| import bpy | |
| sys.stdout.reconfigure(encoding="utf-8", errors="replace") | |
| list_path = sys.argv[sys.argv.index("--") + 1] | |
| with open(list_path, encoding="utf-8") as handle: | |
| file_paths = [line.strip() for line in handle if line.strip()] | |
| for file_path in file_paths: | |
| bpy.ops.wm.read_factory_settings(use_empty=True) | |
| record = {"file": file_path} | |
| try: | |
| bpy.ops.import_scene.gltf(filepath=file_path) | |
| meshes = [item for item in bpy.context.scene.objects if item.type == "MESH"] | |
| record["meshes"] = len(meshes) | |
| record["triangles"] = sum(sum(len(polygon.vertices) - 2 for polygon in item.data.polygons) for item in meshes) | |
| record["armatures"] = sum(1 for item in bpy.context.scene.objects if item.type == "ARMATURE") | |
| record["actions"] = len(bpy.data.actions) | |
| if bpy.data.actions: | |
| start, end = bpy.data.actions[0].frame_range | |
| record["frames"] = int(end - start) + 1 | |
| skeleton_clip = record["armatures"] > 0 and record.get("frames", 0) > 1 | |
| record["ok"] = (record["meshes"] > 0 and record["triangles"] > 0) or skeleton_clip | |
| if not record["ok"]: | |
| record["error"] = "imported without any mesh or animated armature" | |
| except Exception as error: # Blender raises RuntimeError with the importer's message | |
| record["ok"] = False | |
| record["error"] = str(error)[:300] | |
| print(json.dumps(record), flush=True) | |