Continue Blender Web parity task handoff
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

This commit is contained in:
mes123456
2026-08-23 05:47:21 -04:00
parent 0a22992a13
commit 9f43244982
962 changed files with 60772 additions and 297 deletions

View File

@@ -0,0 +1,158 @@
#!/usr/bin/env python3
import hashlib
import json
import os
import pathlib
import shutil
import sys
import tempfile
import bpy
ARMATURE_NAME = "WebGapArmatureDuplicateArmature"
OBJECT_NAME = "WebGapArmatureDuplicateObject"
SOURCE_BONE = "WebGapArmatureDuplicateSource"
OTHER_BONE = "WebGapArmatureDuplicateOther"
DUPLICATE_BONE = "WebGapArmatureDuplicateSource.001"
EXPECTED_AFTER = [SOURCE_BONE, OTHER_BONE, DUPLICATE_BONE]
def ensure_edit_mode():
obj = bpy.data.objects.get(OBJECT_NAME)
armature = bpy.data.armatures.get(ARMATURE_NAME)
if armature is None or obj is None or obj.type != "ARMATURE" or obj.data != armature:
raise RuntimeError("armature.duplicate fixture is missing")
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
if obj.mode != "EDIT":
bpy.ops.object.mode_set(mode="EDIT")
return armature
def bone_report(bone):
return {
"name": bone.name,
"selected": bool(bone.select),
"selectHead": bool(bone.select_head),
"selectTail": bool(bone.select_tail),
"parent": bone.parent.name if bone.parent else None,
"connected": bool(bone.use_connect),
"head": [round(value, 6) for value in bone.head],
"tail": [round(value, 6) for value in bone.tail],
}
def state_report():
armature = ensure_edit_mode()
return {
"object": OBJECT_NAME,
"armature": ARMATURE_NAME,
"activeBone": armature.edit_bones.active.name if armature.edit_bones.active else None,
"bones": [bone_report(bone) for bone in armature.edit_bones],
}
def validate_input(before):
names = [bone["name"] for bone in before["bones"]]
if names == [SOURCE_BONE, OTHER_BONE]:
source, other = before["bones"]
if before["activeBone"] != SOURCE_BONE:
raise RuntimeError(f"unexpected armature.duplicate active bone: {before}")
if not source["selected"] or not source["selectHead"] or not source["selectTail"]:
raise RuntimeError(f"unexpected armature.duplicate source selection: {before}")
if other["selected"] or other["selectHead"] or other["selectTail"]:
raise RuntimeError(f"unexpected armature.duplicate other selection: {before}")
return False
if names == EXPECTED_AFTER:
if before["activeBone"] != DUPLICATE_BONE:
raise RuntimeError(f"unexpected armature.duplicate completed active bone: {before}")
selected = [bone["name"] for bone in before["bones"] if bone["selected"]]
if selected != [DUPLICATE_BONE]:
raise RuntimeError(f"unexpected armature.duplicate completed selection: {before}")
return True
raise RuntimeError(f"unexpected armature.duplicate bones: {before}")
def run_operator(already_duplicated):
ensure_edit_mode()
poll = bool(bpy.ops.armature.duplicate.poll())
if not already_duplicated:
if not poll:
raise RuntimeError("ARMATURE_OT_duplicate poll failed")
result = bpy.ops.armature.duplicate()
if result != {"FINISHED"}:
raise RuntimeError(f"ARMATURE_OT_duplicate returned {result}")
return poll, not already_duplicated
def validate_after(after):
if [bone["name"] for bone in after["bones"]] != EXPECTED_AFTER:
raise RuntimeError(f"armature.duplicate did not create the expected copy: {after}")
source, other, duplicate = after["bones"]
if after["activeBone"] != DUPLICATE_BONE:
raise RuntimeError(f"armature.duplicate active bone drift: {after}")
if source["selected"] or other["selected"] or not duplicate["selected"]:
raise RuntimeError(f"armature.duplicate selection drift: {after}")
if duplicate["parent"] is not None or duplicate["connected"]:
raise RuntimeError(f"armature.duplicate changed duplicate parent state: {after}")
if source["head"] != duplicate["head"] or source["tail"] != duplicate["tail"]:
raise RuntimeError(f"armature.duplicate geometry mismatch: {after}")
if other["head"] != [2.0, 0.0, 0.0] or other["tail"] != [2.0, 1.0, 0.0]:
raise RuntimeError(f"armature.duplicate changed independent bone: {after}")
def main():
arguments = sys.argv[sys.argv.index("--") + 1 :]
if len(arguments) != 2:
raise SystemExit(
"usage: blender -b --factory-startup --python check-action-armature-duplicate-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 = state_report()
already_duplicated = validate_input(before)
poll, changed = run_operator(already_duplicated)
after = state_report()
validate_after(after)
bpy.ops.object.mode_set(mode="OBJECT")
descriptor, temporary = tempfile.mkstemp(prefix="m16-armature-duplicate-reopen-", suffix=".blend")
os.close(descriptor)
temporary_path = pathlib.Path(temporary)
try:
bpy.ops.wm.save_as_mainfile(filepath=str(temporary_path), check_existing=False, compress=True)
bpy.ops.wm.open_mainfile(filepath=str(temporary_path), load_ui=False)
reopened = state_report()
if reopened != after:
raise RuntimeError(f"armature.duplicate save/reopen drift: {after} != {reopened}")
shutil.copyfile(temporary_path, fixture)
report = {
"schemaVersion": 1,
"task": "M16-GAP-00236",
"operation": "ARMATURE_DUPLICATE_DESKTOP",
"fixture": str(fixture),
"fixtureSha256": hashlib.sha256(fixture.read_bytes()).hexdigest(),
"before": before,
"after": reopened,
"sourceBone": SOURCE_BONE,
"duplicateBone": DUPLICATE_BONE,
"poll": poll,
"operatorStatus": "FINISHED" if changed else "SKIPPED_ALREADY_APPLIED",
"mainMutation": "SELECTED_BONE_DUPLICATED" if changed else "SELECTED_BONE_ALREADY_DUPLICATED",
"saveReopen": "EXACT",
"blenderVersion": bpy.app.version_string,
}
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text(json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8")
print(f"armature-duplicate-desktop-ok duplicate={DUPLICATE_BONE} saveReopen=exact")
finally:
temporary_path.unlink(missing_ok=True)
if __name__ == "__main__":
try:
main()
except Exception as error:
print(f"armature-duplicate-desktop-failed: {error}")
raise SystemExit(1)