Files
AIGame/Tools/model_tools/bl_inspect_mixamo_trial.py

31 lines
1.9 KiB
Python

"""Inventory local Mixamo FBX files without editing or exporting the inputs."""
import json
import sys
from pathlib import Path
import bpy
src, out = map(Path, sys.argv[sys.argv.index('--')+1:])
results = []
for path in sorted(src.glob('*.fbx')):
bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_scene.fbx(filepath=str(path))
item = {'file': str(path), 'fps': bpy.context.scene.render.fps, 'objects': [],
'actions': [{'name': a.name, 'frames': list(a.frame_range)} for a in bpy.data.actions]}
for obj in bpy.context.scene.objects:
entry = {'name': obj.name, 'type': obj.type, 'matrix_world': [list(row) for row in obj.matrix_world]}
if obj.type == 'ARMATURE':
entry['bones'] = {b.name: {'head': list(obj.matrix_world @ b.head_local), 'tail': list(obj.matrix_world @ b.tail_local),
'parent': b.parent.name if b.parent else None} for b in obj.data.bones}
entry['action'] = obj.animation_data.action.name if obj.animation_data and obj.animation_data.action else None
elif obj.type == 'MESH':
coords = [obj.matrix_world @ v.co for v in obj.data.vertices]
entry.update(vertices=len(coords), triangles=sum(len(p.vertices)-2 for p in obj.data.polygons),
bounds=[[min(p[i] for p in coords) for i in range(3)], [max(p[i] for p in coords) for i in range(3)]],
groups=len(obj.vertex_groups), modifiers=[{'type': m.type, 'target': m.object.name if m.type == 'ARMATURE' and m.object else None} for m in obj.modifiers])
item['objects'].append(entry)
results.append(item)
print('INVENTORY', path.name, item['fps'], item['actions'], [(o['type'], o['name'], o.get('triangles'), len(o.get('bones', {}))) for o in item['objects']])
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(results, indent=2), encoding='utf-8')