53 lines
2.2 KiB
Python
53 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import sys
|
|
import tempfile
|
|
|
|
import bpy
|
|
|
|
|
|
def report():
|
|
texture = bpy.data.textures.get("WebGapTexture")
|
|
if texture is None:
|
|
raise RuntimeError("WebGapTexture is missing")
|
|
return {
|
|
"id": "texture:" + texture.name,
|
|
"name": texture.name,
|
|
"type": {"NONE": 0, "CLOUDS": 1, "WOOD": 2, "MARBLE": 3, "MAGIC": 4, "BLEND": 5, "STUCCI": 6, "NOISE": 7, "IMAGE": 8, "MUSGRAVE": 9, "VORONOI": 10, "DISTORTED_NOISE": 11}.get(texture.type, 0),
|
|
"noiseScale": float(texture.noise_scale),
|
|
"noiseDepth": int(texture.noise_depth),
|
|
"intensity": float(texture.intensity),
|
|
"contrast": float(texture.contrast),
|
|
"saturation": float(texture.saturation),
|
|
}
|
|
|
|
|
|
def main():
|
|
arguments = sys.argv[sys.argv.index("--") + 1 :]
|
|
if len(arguments) != 2:
|
|
raise SystemExit("usage: blender -b --python check-texture-desktop.py -- FIXTURE REPORT")
|
|
fixture, output = (pathlib.Path(value).resolve() for value in arguments)
|
|
bpy.ops.wm.open_mainfile(filepath=str(fixture), load_ui=False)
|
|
before = report()
|
|
descriptor, temporary = tempfile.mkstemp(prefix="m16-texture-reopen-", suffix=".blend", dir=fixture.parent)
|
|
os.close(descriptor)
|
|
try:
|
|
bpy.ops.wm.save_as_mainfile(filepath=temporary, check_existing=False, compress=True)
|
|
bpy.ops.wm.open_mainfile(filepath=temporary, load_ui=False)
|
|
after = report()
|
|
finally:
|
|
pathlib.Path(temporary).unlink(missing_ok=True)
|
|
if before != after:
|
|
raise RuntimeError(f"texture save/reopen drift: {before} != {after}")
|
|
value = {"schemaVersion": 1, "task": "M16-GAP-00025", "operation": "TEXTURE_DATABLOCK_DESKTOP", "fixture": str(fixture), "fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(), "texture": after, "saveReopen": "EXACT", "blenderVersion": bpy.app.version_string}
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
output.write_text(json.dumps(value, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
print(f"texture-desktop-ok id={after['id']} type={after['type']} saveReopen=exact")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|