Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""NodeForge Blender addon package."""

NODEFORGE_VERSION = (0, 95, 0)


NODEFORGE_VERSION = (0, 96, 0)
bl_info = {
"name": "NodeForge",
"author": "nachitima",
Expand Down
2 changes: 1 addition & 1 deletion blender/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions blender/group_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion blender_manifest.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 6 additions & 1 deletion dev/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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.
2 changes: 1 addition & 1 deletion semantic/builtin_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
132 changes: 122 additions & 10 deletions tests/blender/test_capture_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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():
Expand All @@ -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)
13 changes: 13 additions & 0 deletions tests/unit/test_builtin_call_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_color_type_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_rotation_type_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions type_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
NFType.BOOL: "BOOLEAN",
NFType.VECTOR: "VECTOR",
NFType.COLOR: "RGBA",
NFType.ROTATION: "ROTATION",
})

ATTRIBUTE_DATA_TYPES = MappingProxyType({
Expand Down
Loading