Files
workinf_Blender_Wasm/tools/web/generate-nla-evaluation-golden.py
mes123456 0fe8d2bb56
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Advance M8-M11 parity workflows
2026-08-17 04:37:07 -04:00

78 lines
2.5 KiB
Python

import hashlib
import json
import pathlib
import sys
import bpy
def strip_summary(strip):
return {
"id": strip.name,
"action": strip.action.name if strip.action is not None else None,
"frameStart": strip.frame_start,
"frameEnd": strip.frame_end,
"actionFrameStart": strip.action_frame_start,
"actionFrameEnd": strip.action_frame_end,
"scale": strip.scale,
"repeat": strip.repeat,
"blendIn": strip.blend_in,
"blendOut": strip.blend_out,
"influence": strip.influence,
"blendMode": strip.blend_type,
"extrapolation": strip.extrapolation,
"muted": strip.mute,
"reverse": strip.use_reverse,
}
def main(blend_path: str, output_path: str) -> None:
blend = pathlib.Path(blend_path).resolve()
bpy.ops.wm.open_mainfile(filepath=str(blend), load_ui=False)
scene = bpy.context.scene
object_name = "M10_NLA_TimeMapping"
obj = bpy.data.objects.get(object_name)
if obj is None or obj.animation_data is None:
raise RuntimeError("M10 NLA fixture object or AnimData is missing")
frames = [1, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70]
samples = []
for frame in frames:
scene.frame_set(frame)
depsgraph = bpy.context.evaluated_depsgraph_get()
evaluated = obj.evaluated_get(depsgraph)
samples.append({
"frame": frame,
"worldMatrix": [value for row in evaluated.matrix_world for value in row],
})
tracks = []
for track in obj.animation_data.nla_tracks:
tracks.append({
"name": track.name,
"muted": track.mute,
"solo": track.is_solo,
"strips": [strip_summary(strip) for strip in track.strips],
})
result = {
"schemaVersion": 1,
"fixture": f"tests/files/web/{blend.name}",
"fixtureSha256": hashlib.sha256(blend.read_bytes()).hexdigest(),
"blenderVersion": bpy.app.version_string,
"object": object_name,
"mesh": obj.data.name,
"tracks": tracks,
"frames": samples,
"tolerance": {"maxMatrixError": 1e-5},
}
pathlib.Path(output_path).write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8")
if __name__ == "__main__":
if "--" not in sys.argv or len(sys.argv) <= sys.argv.index("--") + 2:
raise SystemExit("usage: blender -b --python generate-nla-evaluation-golden.py -- input.blend output.json")
arguments = sys.argv[sys.argv.index("--") + 1:]
main(arguments[0], arguments[1])