Advance M8-M11 parity workflows
This commit is contained in:
51
tools/web/generate-curve-toggle-golden.py
Normal file
51
tools/web/generate-curve-toggle-golden.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
def main():
|
||||
arguments = sys.argv[sys.argv.index("--") + 1 :] if "--" in sys.argv else []
|
||||
if len(arguments) != 2:
|
||||
raise SystemExit("usage: blender -b fixture.blend --python generate-curve-toggle-golden.py -- fixture.blend output.json")
|
||||
fixture = os.path.abspath(arguments[0])
|
||||
output = os.path.abspath(arguments[1])
|
||||
curve = bpy.data.curves.get("WebCurveData")
|
||||
if curve is None or len(curve.splines) < 1:
|
||||
raise RuntimeError("WebCurveData fixture is missing its first spline")
|
||||
before = [spline.use_cyclic_u for spline in curve.splines]
|
||||
spline_types = [spline.type for spline in curve.splines]
|
||||
spline_point_counts = [len(spline.bezier_points) if spline.type == "BEZIER" else len(spline.points) for spline in curve.splines]
|
||||
curve.splines[0].use_cyclic_u = not curve.splines[0].use_cyclic_u
|
||||
after = [spline.use_cyclic_u for spline in curve.splines]
|
||||
with tempfile.TemporaryDirectory(prefix="m9-05-curve-toggle-") as temporary:
|
||||
saved = os.path.join(temporary, "curve-toggle.blend")
|
||||
bpy.ops.wm.save_as_mainfile(filepath=saved, check_existing=False)
|
||||
bpy.ops.wm.open_mainfile(filepath=saved)
|
||||
reopened = [spline.use_cyclic_u for spline in bpy.data.curves["WebCurveData"].splines]
|
||||
with open(fixture, "rb") as source:
|
||||
fixture_sha256 = hashlib.sha256(source.read()).hexdigest()
|
||||
payload = {
|
||||
"schemaVersion": 1,
|
||||
"operator": "TOGGLE_CYCLIC",
|
||||
"fixture": "tests/files/web/nonmesh_scene.blend",
|
||||
"fixtureSha256": fixture_sha256,
|
||||
"blenderVersion": ".".join(str(value) for value in bpy.app.version),
|
||||
"curveName": "WebCurveData",
|
||||
"splineIndex": 0,
|
||||
"splineTypes": spline_types,
|
||||
"splinePointCounts": spline_point_counts,
|
||||
"beforeCyclicU": before,
|
||||
"afterCyclicU": after,
|
||||
"reopenedCyclicU": reopened,
|
||||
}
|
||||
with open(output, "w", encoding="utf-8") as destination:
|
||||
json.dump(payload, destination, indent=2, sort_keys=True)
|
||||
destination.write("\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user