Validating Assets Automatically
A team agrees on naming, budgets and import settings, writes them in a wiki page, and three weeks later half the assets break the rules. Not out of malice: nobody remembers a wiki page while they work. The fix is the same as for code style: a script that checks every asset, run when an artist exports and again in CI, with a clear message for each problem.
What to check
| Rule | Why | Where the data comes from |
|---|---|---|
Naming convention (SM_, T_, M_ prefixes, no spaces) |
searchable, sortable, script-friendly | file names |
| Triangle budget per asset category | performance | Blender / engine mesh stats |
| Texture size is a power of two and within a maximum | mipmaps and compression work best; memory | image headers |
| Texture set complete (BaseColor + Normal + ORM) | consistent materials | file names |
| Scale applied (1, 1, 1) and rotation zero | see Units, Axes & Scale | object transforms |
| Material count per mesh | each material is usually a separate draw call | mesh data |
| UV channel present | textures need UVs, baked lighting needs a second set | mesh data |
Step 1: export a manifest from Blender
The checks themselves shouldn't depend on Blender: export the facts to JSON, then check JSON anywhere. A small bpy script collects them:
# tools/asset_manifest.py
# blender --background art/props.blend --python tools/asset_manifest.py -- build/manifest.json
import json
import sys
import bpy
out_path = sys.argv[sys.argv.index("--") + 1]
assets = []
for obj in bpy.data.objects:
if obj.type != 'MESH':
continue
mesh = obj.data
triangles = sum(len(poly.vertices) - 2 for poly in mesh.polygons) # fan triangulation count
assets.append({
"name": obj.name,
"triangles": triangles,
"materials": len(mesh.materials),
"uv_layers": len(mesh.uv_layers),
"scale": [round(s, 4) for s in obj.scale],
"rotation": [round(r, 4) for r in obj.rotation_euler],
})
images = [{"name": img.name, "size": list(img.size)} for img in bpy.data.images if img.size[0] > 0]
with open(out_path, "w") as f:
json.dump({"meshes": assets, "textures": images}, f, indent=2)
print(f"wrote {len(assets)} meshes, {len(images)} textures to {out_path}")(A polygon with n vertices becomes n − 2 triangles, so the triangle count is known without actually triangulating.)
Step 2: check the manifest
This part is ordinary Python, so it runs here. The manifest is inline; in a project you'd json.load the file the Blender script wrote.
import json, re
manifest = json.loads('''{
"meshes": [
{"name": "SM_Crate", "triangles": 412, "materials": 1, "uv_layers": 2, "scale": [1, 1, 1], "rotation": [0, 0, 0]},
{"name": "SM_Barrel_01", "triangles": 1880, "materials": 2, "uv_layers": 1, "scale": [1, 1, 1], "rotation": [0, 0, 0]},
{"name": "Lamp Post", "triangles": 950, "materials": 1, "uv_layers": 1, "scale": [2, 2, 2], "rotation": [0, 0, 0]},
{"name": "SM_Statue", "triangles": 48210, "materials": 4, "uv_layers": 0, "scale": [1, 1, 1], "rotation": [1.5708, 0, 0]}
],
"textures": [
{"name": "T_Crate_BaseColor", "size": [1024, 1024]},
{"name": "T_Crate_Normal", "size": [1024, 1024]},
{"name": "T_Crate_ORM", "size": [1024, 1024]},
{"name": "T_Barrel_BaseColor", "size": [1000, 1000]},
{"name": "T_Barrel_Normal", "size": [4096, 4096]}
]
}''')
RULES = {"max_tris": {"SM_": 5000}, "max_materials": 2, "max_texture": 2048}
MESH_NAME = re.compile(r"^SM_[A-Z][A-Za-z0-9]*(_\d{2})?quot;)
TEX_NAME = re.compile(r"^T_([A-Z][A-Za-z0-9]*)_(BaseColor|Normal|ORM)quot;)
def is_pow2(n):
return n > 0 and n & (n - 1) == 0
problems = []
for m in manifest["meshes"]:
n = m["name"]
if not MESH_NAME.match(n):
problems.append((n, "name must look like SM_Name or SM_Name_01"))
if m["triangles"] > RULES["max_tris"]["SM_"]:
problems.append((n, f"{m['triangles']} triangles > budget {RULES['max_tris']['SM_']}"))
if m["materials"] > RULES["max_materials"]:
problems.append((n, f"{m['materials']} materials > {RULES['max_materials']}"))
if m["uv_layers"] == 0:
problems.append((n, "no UV map"))
if m["scale"] != [1, 1, 1] or any(abs(r) > 1e-4 for r in m["rotation"]):
problems.append((n, "transforms not applied"))
sets = {}
for t in manifest["textures"]:
w, h = t["size"]
match = TEX_NAME.match(t["name"])
if not match:
problems.append((t["name"], "bad texture name"))
continue
sets.setdefault(match.group(1), set()).add(match.group(2))
if not (is_pow2(w) and is_pow2(h)):
problems.append((t["name"], f"{w}x{h} is not a power of two"))
if max(w, h) > RULES["max_texture"]:
problems.append((t["name"], f"{w}x{h} exceeds {RULES['max_texture']}"))
for base, kinds in sorted(sets.items()):
missing = {"BaseColor", "Normal", "ORM"} - kinds
if missing:
problems.append((f"T_{base}_*", "missing " + ", ".join(sorted(missing))))
for name, msg in problems:
print(f"FAIL {name:<20} {msg}")
print(f"{len(problems)} problem(s) in {len(manifest['meshes'])} meshes and {len(manifest['textures'])} textures")FAIL Lamp Post name must look like SM_Name or SM_Name_01
FAIL Lamp Post transforms not applied
FAIL SM_Statue 48210 triangles > budget 5000
FAIL SM_Statue 4 materials > 2
FAIL SM_Statue no UV map
FAIL SM_Statue transforms not applied
FAIL T_Barrel_BaseColor 1000x1000 is not a power of two
FAIL T_Barrel_Normal 4096x4096 exceeds 2048
FAIL T_Barrel_* missing ORM
9 problem(s) in 4 meshes and 5 textures
Each message names the asset and says what to do. That matters more than the number of rules: a check that prints "validation failed" gets disabled within a week.
Where to run it
- In Blender, as an add-on button ("Validate & Export"), so artists see problems before committing.
- In a pre-commit hook or a pre-submit trigger (Perforce), for fast feedback.
- In CI on every push, failing the build with a non-zero exit code (
sys.exit(1)whenproblemsis not empty). - In the engine too: Unity's
AssetPostprocessor(OnPreprocessTexture,OnPostprocessModel), Unreal's import hooks and Editor Utility scripts, and Godot'sEditorScenePostImportscripts can enforce import settings per folder. The engine courses cover these.
Start with three or four rules that catch real problems in your project, and add more only when a mistake actually happens twice.
Test yourself
Why export a JSON manifest from Blender instead of writing all checks inside Blender?
- JSON is faster than bpy
- The checks then run anywhere (CI, hooks, tests) without Blender installed
- Blender can't read names
- It's required by glTF
How many triangles does a polygon with 6 vertices produce?
- 6
- 4
- 3
- 2
What makes a validation message useful?
- A short 'validation failed'
- It names the asset and says what is wrong and what the limit is
- A stack trace
- A colour code