#!/usr/bin/env python3 import hashlib import json import pathlib import sys import bpy TEXT_NAME = "WBV2-P1-002-SceneIRContract" CONTRACT_ID = "workflow:unify_sceneir_stable_ids_and_binary_deltas" def contract(): return { "schemaVersion": 1, "contractId": CONTRACT_ID, "stableIds": { "objectId": "object:WBV2P1002CubeObject", "meshId": "mesh:WBV2P1002CubeMesh", }, "binaryDelta": { "schemaVersion": 1, "baseRevision": 1, "generation": 1, "patches": [{"field": "positions", "byteOffset": 0, "byteLength": 12}], }, "extensions": {"futureField": {"kind": "opaque", "value": "preserve-me"}}, } def main(output): bpy.ops.wm.read_factory_settings(use_empty=True) mesh = bpy.data.meshes.new("WBV2P1002CubeMesh") mesh.from_pydata( [(-1, -1, -1), (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, 1), (1, -1, 1), (1, 1, 1), (-1, 1, 1)], [], [(0, 1, 2, 3), (4, 7, 6, 5), (0, 4, 5, 1), (1, 5, 6, 2), (2, 6, 7, 3), (4, 0, 3, 7)], ) mesh.update() obj = bpy.data.objects.new("WBV2P1002CubeObject", mesh) bpy.context.collection.objects.link(obj) text = bpy.data.texts.new(TEXT_NAME) text.write(json.dumps(contract(), sort_keys=True, separators=(",", ":"))) text.use_fake_user = True bpy.ops.wm.save_as_mainfile(filepath=str(output.resolve()), check_existing=False, compress=True) if __name__ == "__main__": arguments = sys.argv[sys.argv.index("--") + 1 :] if len(arguments) != 1: raise SystemExit("usage: blender -b --factory-startup --python WBV2-P1-002.py -- OUTPUT") main(pathlib.Path(arguments[0]))