diff --git a/__init__.py b/__init__.py index f4e6f9a..78c074a 100644 --- a/__init__.py +++ b/__init__.py @@ -1,8 +1,6 @@ """NodeForge Blender addon package.""" -NODEFORGE_VERSION = (0, 95, 0) - - +NODEFORGE_VERSION = (0, 96, 0) bl_info = { "name": "NodeForge", "author": "nachitima", diff --git a/blender/geometry.py b/blender/geometry.py index fe8e350..1dfbba4 100644 --- a/blender/geometry.py +++ b/blender/geometry.py @@ -466,7 +466,7 @@ def _capture_attribute_geometry(group, geometry, value, *, selection, domain, da socket_type_to_value_type = {token: typ for typ, token in CAPTURE_ITEM_TYPES.items()} socket_type = (data_type.upper() if data_type else CAPTURE_ITEM_TYPES.get(value.typ)) if socket_type not in socket_type_to_value_type: - raise CompileError("capture_attribute() supports Float, Int, Bool and Vector values (also Color)") + raise CompileError("capture_attribute() supports Float, Int, Bool and Vector values (also Color and Rotation)") domain = normalize_attribute_domain(domain, "capture_attribute()") if selection is not None and (not isinstance(selection, Value) or selection.typ != TYPE_BOOL): raise CompileError("capture_attribute() selection= must be a Bool expression") diff --git a/blender/group_backend.py b/blender/group_backend.py index 52936a0..d5092cb 100644 --- a/blender/group_backend.py +++ b/blender/group_backend.py @@ -391,6 +391,7 @@ def _sync_capture_attribute_dynamic_items(src_group, node_map): "BOOLEAN": "BOOLEAN", "FLOAT_VECTOR": "VECTOR", "FLOAT_COLOR": "RGBA", + "QUATERNION": "ROTATION", } for src_node in src_group.nodes: if getattr(src_node, "bl_idname", None) != "GeometryNodeCaptureAttribute": @@ -423,6 +424,11 @@ def _sync_capture_attribute_dynamic_items(src_group, node_map): f"Capture copy: restored item contract differs on {src_node.name!r}: " f"expected {source_items!r}, got {actual!r}" ) + # Dynamic sockets only exist after item reconstruction; the generic + # node-property copier has already run, so restore their defaults here. + for item_name, _persisted_type in source_items: + _copy_socket_default(src_node.inputs[item_name], dst_node.inputs[item_name]) + _copy_socket_default(src_node.outputs[item_name], dst_node.outputs[item_name]) def _sync_repeat_zone_dynamic_items(src_group, node_map): diff --git a/blender_manifest.toml b/blender_manifest.toml index 4c4cb38..95fcbb7 100644 --- a/blender_manifest.toml +++ b/blender_manifest.toml @@ -1,6 +1,6 @@ schema_version = "1.0.0" id = "nodeforge" -version = "0.95.0" +version = "0.96.0" name = "NodeForge" tagline = "Compile a procedural DSL into Blender Geometry Nodes" maintainer = "nachitima" diff --git a/dev/CHANGELOG.md b/dev/CHANGELOG.md index ca8d40a..4fb96bb 100644 --- a/dev/CHANGELOG.md +++ b/dev/CHANGELOG.md @@ -785,4 +785,9 @@ lifecycle. - Resolve exact ordered runtime result types during semantic analysis and transport them through existing typed Call IR to the Python backend. - Validate dynamic extension results against call-specific IR arity, NF types, socket direction, physical type and current-group ownership before publishing generated candidates. - Preserved fixed result declarations, semantic extension modes, owner snapshots, and existing root-tree physical extension restrictions. -- Documented invocation-dependent extension result declarations, resolver arguments and validation, backend result types, and package requirements. \ No newline at end of file +- Documented invocation-dependent extension result declarations, resolver arguments and validation, backend result types, and package requirements. + +## 0.96.0 + +- Supported Rotation Capture Attribute items in core semantic typing, Blender materialization and transactional group/root copying, including persisted QUATERNION item reconstruction and dynamic socket defaults. +- Added Rotation Capture regression coverage for item sockets, group copying, updates and mixed fields. diff --git a/semantic/builtin_calls.py b/semantic/builtin_calls.py index f92dd4a..dfaa033 100644 --- a/semantic/builtin_calls.py +++ b/semantic/builtin_calls.py @@ -1154,7 +1154,7 @@ def _capture_result_type(value_typ: NFType, data_type: str | None) -> NFType: else: result = {token: typ for typ, token in CAPTURE_ITEM_TYPES.items()}.get(data_type.upper()) if result is None: - raise CompileError("capture_attribute() supports Float, Int, Bool and Vector values (also Color)") + raise CompileError("capture_attribute() supports Float, Int, Bool and Vector values (also Color and Rotation)") return result diff --git a/tests/blender/test_capture_attribute.py b/tests/blender/test_capture_attribute.py index f36ad62..1c69a8c 100644 --- a/tests/blender/test_capture_attribute.py +++ b/tests/blender/test_capture_attribute.py @@ -105,6 +105,7 @@ def nf_fixture(): ('FLOAT', 'FLOAT', 'NodeSocketFloat'), ('VECTOR', 'FLOAT_VECTOR', 'NodeSocketVector'), ('RGBA', 'FLOAT_COLOR', 'NodeSocketColor'), + ('ROTATION', 'QUATERNION', 'NodeSocketRotation'), ]) @pytest.mark.parametrize('role', ['backup', 'cutover']) @pytest.mark.parametrize('linked', [True, False]) @@ -130,17 +131,19 @@ def test_capture_copy_preserves_linked_and_unlinked_item_contract( assert all(link.is_valid for link in dst.links) -def test_capture_copy_fails_on_unknown_data_type_without_modifying_authoritative_source(): - """An unsupported, unlinked item aborts rather than silently disappearing.""" - src = bpy.data.node_groups.new('NFTest_capture_bad_source','GeometryNodeTree') +def test_capture_copy_restores_persisted_quaternion_without_modifying_source(): + """A persisted QUATERNION item recreates via ROTATION, even without links.""" + src = bpy.data.node_groups.new('NFTest_capture_rotation_source', 'GeometryNodeTree') cap = src.nodes.new('GeometryNodeCaptureAttribute') - cap.capture_items.new('ROTATION','UnsupportedNow') - assert cap.capture_items[0].data_type == 'QUATERNION' - dst = bpy.data.node_groups.new('NFTest_capture_bad_destination','GeometryNodeTree') - with pytest.raises(CompileError, match='unsupported persisted data type'): - blender_group_backend._copy_group_contents(src,dst,copy_role='backup') - assert len(cap.capture_items)==1 + cap.capture_items.new('ROTATION', 'Spin') assert cap.capture_items[0].data_type == 'QUATERNION' + dst = bpy.data.node_groups.new('NFTest_capture_rotation_destination', 'GeometryNodeTree') + blender_group_backend._copy_group_contents(src, dst, copy_role='backup') + copied, = [node for node in dst.nodes if node.bl_idname == 'GeometryNodeCaptureAttribute'] + assert [(item.name, item.data_type) for item in copied.capture_items] == [('Spin', 'QUATERNION')] + assert copied.inputs['Spin'].bl_idname == 'NodeSocketRotation' + assert copied.outputs['Spin'].bl_idname == 'NodeSocketRotation' + assert [(item.name, item.data_type) for item in cap.capture_items] == [('Spin', 'QUATERNION')] def test_capture_root_update_reconstruction_uses_same_checked_helper(): @@ -149,9 +152,118 @@ def test_capture_root_update_reconstruction_uses_same_checked_helper(): src = bpy.data.node_groups.new('NFTest_capture_root_reconstruct','GeometryNodeTree') old=src.nodes.new('GeometryNodeCaptureAttribute') old.capture_items.new('RGBA','Tint') + old.capture_items.new('ROTATION','Spin') backup = bpy.data.node_groups.new('NFTest_capture_backup','GeometryNodeTree') cloned=backup.nodes.new('GeometryNodeCaptureAttribute') cloned.name=old.name root_update._sync_capture_attribute_dynamic_items(src, {old.name:cloned}) - assert [(item.name,item.data_type) for item in cloned.capture_items] == [('Tint','FLOAT_COLOR')] + assert [(item.name,item.data_type) for item in cloned.capture_items] == [('Tint','FLOAT_COLOR'), ('Spin','QUATERNION')] assert cloned.outputs['Tint'].bl_idname == 'NodeSocketColor' + assert cloned.inputs['Spin'].bl_idname == 'NodeSocketRotation' + assert cloned.outputs['Spin'].bl_idname == 'NodeSocketRotation' + + +def test_rotation_capture_builtin_infers_and_accepts_explicit_type(): + """The existing Capture builtin returns a Rotation field with native sockets.""" + for token in ('', ', type="ROTATION"'): + group = compile_group(f''' +def nf_fixture(value: Rotation): + geo = grid(2, 2) + geo, rotation = capture_attribute(geo, value{token}) + return geo, rotation +''', 'NFTest_capture_native_rotation') + capture, = _capture_nodes(group) + assert capture.capture_items[0].data_type == 'QUATERNION' + assert capture.inputs['Value'].bl_idname == 'NodeSocketRotation' + assert capture.outputs['Value'].bl_idname == 'NodeSocketRotation' + assert all(link.is_valid for link in group.links) + expect_compile_error(''' +def nf_fixture(value: Rotation): + geo = grid(2, 2) + geo, rotation = capture_attribute(geo, value, type="QUATERNION") + return geo, rotation +''', 'NFTest_capture_wrong_rotation_constructor') + + +def test_rotation_capture_group_copy_preserves_mixed_items_links_and_defaults(): + """Transaction copy recreates Rotation and neighbors with per-item defaults.""" + from NodeForge.blender.group_backend import _copy_group_contents + src = bpy.data.node_groups.new('NFTest_capture_rotation_mixed', 'GeometryNodeTree') + cap = src.nodes.new('GeometryNodeCaptureAttribute') + for token, name in (('FLOAT', 'Weight'), ('ROTATION', 'Spin'), ('VECTOR', 'Offset')): + cap.capture_items.new(token, name) + cap.inputs['Weight'].default_value = 0.25 + cap.inputs['Spin'].default_value = (0.1, 0.2, 0.3) + cap.inputs['Offset'].default_value = (1.0, 2.0, 3.0) + src.interface.new_socket(name='Spin',in_out='OUTPUT',socket_type='NodeSocketRotation') + group_output = src.nodes.new('NodeGroupOutput') + src.links.new(cap.outputs['Spin'],group_output.inputs['Spin']) + assert all(link.is_valid for link in src.links) + for role in ('backup', 'cutover'): + dst=bpy.data.node_groups.new('NFTest_capture_rotation_copy_'+role, 'GeometryNodeTree') + _copy_group_contents(src, dst, copy_role=role) + copied, = _capture_nodes(dst) + assert [(i.name,i.data_type) for i in copied.capture_items] == [ + ('Weight','FLOAT'),('Spin','QUATERNION'),('Offset','FLOAT_VECTOR')] + for name, physical in (('Weight','NodeSocketFloat'),('Spin','NodeSocketRotation'), + ('Offset','NodeSocketVector')): + assert copied.inputs[name].bl_idname == physical + assert copied.outputs[name].bl_idname == physical + for name, expected in (('Weight',(0.25,)),('Spin',(0.1,0.2,0.3)), + ('Offset',(1.0,2.0,3.0))): + actual=copied.inputs[name].default_value + if name=='Weight': actual=(actual,) + assert all(abs(float(a)-b)<1e-4 for a,b in zip(actual,expected)) + assert len(dst.links)==1 and all(link.is_valid for link in dst.links) + assert dst.links[0].from_socket.bl_idname=='NodeSocketRotation' + + +def test_capture_rotation_group_update_and_failed_update_keep_contract(): + """Selected group update copies Rotation-backed old state and commits replacement.""" + def source(typ, token=''): + return f''' +def nf_fixture(value: {typ}): + geo = grid(2,2) + geo, captured = capture_attribute(geo, value{token}) + return geo, captured +''' + group=compile_group(source('Rotation'), 'NFTest_capture_update_rotation') + pointer=group.as_pointer() + assert _capture_nodes(group)[0].capture_items[0].data_type == 'QUATERNION' + with pytest.raises(CompileError): + compiler.update_expression_group(group, source('Rotation', ', type="QUATERNION"')) + assert _capture_nodes(group)[0].capture_items[0].data_type == 'QUATERNION' + compiler.update_expression_group(group, source('Rotation', ', type="ROTATION"')) + assert group.as_pointer() == pointer + assert _capture_nodes(group)[0].capture_items[0].data_type == 'QUATERNION' + compiler.update_expression_group(group, source('Rotation')) + assert _capture_nodes(group)[0].capture_items[0].data_type == 'QUATERNION' + assert all(link.is_valid for link in group.links) + + +def test_rotation_capture_root_update_rollback_restores_links(monkeypatch): + """Root rollback reconstructs a previous linked QUATERNION item.""" + from NodeForge.blender import root_update + root = bpy.data.node_groups.new('NFTest_capture_root_rotation', 'GeometryNodeTree') + root.interface.new_socket(name='Geometry', in_out='INPUT',socket_type='NodeSocketGeometry') + root.interface.new_socket(name='Geometry', in_out='OUTPUT',socket_type='NodeSocketGeometry') + root.interface.new_socket(name='Spin', in_out='OUTPUT',socket_type='NodeSocketRotation') + inlet=root.nodes.new('NodeGroupInput') + outlet=root.nodes.new('NodeGroupOutput') + cap=root.nodes.new('GeometryNodeCaptureAttribute') + cap.capture_items.new('FLOAT', 'Weight') + cap.capture_items.new('ROTATION', 'Spin') + cap.capture_items.new('VECTOR', 'Offset') + root.links.new(inlet.outputs['Geometry'],cap.inputs['Geometry']) + root.links.new(cap.outputs['Geometry'],outlet.inputs['Geometry']) + root.links.new(cap.outputs['Spin'],outlet.inputs['Spin']) + original=[(i.name,i.data_type) for i in cap.capture_items] + def fail(*args, **kwargs): + raise RuntimeError('Capture root rollback injection') + monkeypatch.setattr(root_update,'_reconnect_boundary',fail) + with pytest.raises(root_update.RootUpdateError,match='Capture root rollback injection'): + compiler.update_source_in_tree('a = cube(2)\n',root) + restored, = _capture_nodes(root) + assert [(i.name,i.data_type) for i in restored.capture_items]==original + assert restored.outputs['Spin'].bl_idname=='NodeSocketRotation' + assert len(root.links)==3 and all(link.is_valid for link in root.links) diff --git a/tests/unit/test_builtin_call_semantics.py b/tests/unit/test_builtin_call_semantics.py index 017c400..6117963 100644 --- a/tests/unit/test_builtin_call_semantics.py +++ b/tests/unit/test_builtin_call_semantics.py @@ -624,6 +624,19 @@ def test_ir_capable_builtin_families_have_blender_independent_success_contracts( assert all(operand.typ in {TYPE_BOOL, TYPE_BUNDLE, TYPE_FLOAT, TYPE_GEOMETRY, TYPE_INT, TYPE_MATERIAL, TYPE_STRING, TYPE_VECTOR} for operand in analyzed.operands) +def test_capture_attribute_rotation_inference_and_explicit_override(): + """Rotation remains a real NFType; explicit token selects the same exact result.""" + for source in ('capture_attribute(geo, rot)', + 'capture_attribute(geo, rot, type="ROTATION")'): + analyzed = _analyze('capture_attribute', source, + types={'geo': TYPE_GEOMETRY, 'rot': TYPE_ROTATION}) + assert isinstance(analyzed.result, TupleCallResult) + assert analyzed.result.types == (TYPE_GEOMETRY, TYPE_ROTATION) + with pytest.raises(CompileError, match='supports Float'): + _analyze('capture_attribute', 'capture_attribute(geo, rot, type="QUATERNION")', + types={'geo': TYPE_GEOMETRY, 'rot': TYPE_ROTATION}) + + def test_capture_attribute_success_is_structural_and_typed_without_blender(): analyzed = _analyze( "capture_attribute", diff --git a/tests/unit/test_color_type_contracts.py b/tests/unit/test_color_type_contracts.py index 5bcc08f..55195a4 100644 --- a/tests/unit/test_color_type_contracts.py +++ b/tests/unit/test_color_type_contracts.py @@ -38,6 +38,7 @@ def test_supported_operation_tokens_match_pre_color_contract(): assert dict(CAPTURE_ITEM_TYPES) == { NFType.FLOAT: 'FLOAT', NFType.INT: 'INT', NFType.BOOL: 'BOOLEAN', NFType.VECTOR: 'VECTOR', NFType.COLOR: 'RGBA', + NFType.ROTATION: 'ROTATION', } assert dict(ATTRIBUTE_DATA_TYPES) == { NFType.FLOAT: 'FLOAT', NFType.INT: 'INT', NFType.VECTOR: 'FLOAT_VECTOR', diff --git a/tests/unit/test_rotation_type_contracts.py b/tests/unit/test_rotation_type_contracts.py index 29bd7d5..5355b39 100644 --- a/tests/unit/test_rotation_type_contracts.py +++ b/tests/unit/test_rotation_type_contracts.py @@ -125,9 +125,11 @@ def test_rotation_public_token_does_not_expand_other_operation_capabilities(): SWITCH_INPUT_TYPES, REPEAT_ITEM_TYPES, CAPTURE_ITEM_TYPES, ATTRIBUTE_DATA_TYPES, ) + assert CAPTURE_ITEM_TYPES[NFType.ROTATION] == "ROTATION" + for capability in (SWITCH_INPUT_TYPES, REPEAT_ITEM_TYPES, ATTRIBUTE_DATA_TYPES): + assert NFType.ROTATION not in capability for capability in (SWITCH_INPUT_TYPES, REPEAT_ITEM_TYPES, CAPTURE_ITEM_TYPES, ATTRIBUTE_DATA_TYPES): - assert NFType.ROTATION not in capability assert NFType.VECTOR in capability assert NFType.COLOR in SWITCH_INPUT_TYPES assert NFType.COLOR in ATTRIBUTE_DATA_TYPES diff --git a/type_capabilities.py b/type_capabilities.py index 2be0b54..13fdd51 100644 --- a/type_capabilities.py +++ b/type_capabilities.py @@ -34,6 +34,7 @@ NFType.BOOL: "BOOLEAN", NFType.VECTOR: "VECTOR", NFType.COLOR: "RGBA", + NFType.ROTATION: "ROTATION", }) ATTRIBUTE_DATA_TYPES = MappingProxyType({