diff --git a/docs/research/geonodes-translation-corpus.md b/docs/research/geonodes-translation-corpus.md index 2e6d946..e22499f 100644 --- a/docs/research/geonodes-translation-corpus.md +++ b/docs/research/geonodes-translation-corpus.md @@ -121,6 +121,13 @@ Completed pie chart entry: - Verification: translated segment and three-slice chart match evaluated source geometry with sorted max vertex delta `0.0` in Blender 5.1.1. +Completed field value helper entry: + +- `docs/research/translations/shriinivas-fieldvalue-digit-at.md` +- Source group: `Digit At` +- Verification: translated scalar helper matches source behavior across four + number/position cases by driving `Mesh Line.Count` with the result. + ## Extraction Workflow 1. Download one source `.blend` into an ignored experiment folder. diff --git a/docs/research/procedural-doctrine.md b/docs/research/procedural-doctrine.md index 5003636..0cecdbd 100644 --- a/docs/research/procedural-doctrine.md +++ b/docs/research/procedural-doctrine.md @@ -114,6 +114,20 @@ the end angle forward. This is the pattern for cumulative structures: charts, stairs, chains, segmented shells, stacked floors, ribs, vertebrae, and anything where part N+1 depends on where part N stopped. +## Values Need Harnesses + +Some node groups are value transducers rather than shape makers. They transform +numbers, booleans, vectors, rotations, or strings so larger graph organs can use +them later. + +The `Digit At` translation extracts a single digit from a number. To verify it, +the value output is wired into `Mesh Line.Count`; the number of evaluated +vertices becomes the observable behavior. + +Metaphor: if a graph only whispers a number, build a little megaphone around it. +The verifier's job is not to be beautiful. It is to make the invisible output +hard to lie about. + ## Stack Abstractions Carefully There are two abstraction layers available: diff --git a/docs/research/translations/shriinivas-fieldvalue-digit-at.md b/docs/research/translations/shriinivas-fieldvalue-digit-at.md new file mode 100644 index 0000000..e9ded9e --- /dev/null +++ b/docs/research/translations/shriinivas-fieldvalue-digit-at.md @@ -0,0 +1,75 @@ +# Translation: Shriinivas Field Value Digit At + +## Source + +- Repository: https://github.com/Shriinivas/geometrynodes +- Source file: `fieldvalue.blend` +- Source group: `Digit At` +- Geometry Script recreation: + `examples/geometry_script/shriinivas_fieldvalue.py` + +## Why This Graph + +`fieldvalue.blend` contains a large seven-segment field display system. The full +`Field Value` graph has 176 nodes, so the first honest target is a scalar helper: +`Digit At`. + +This group does not make visible geometry. It extracts a digit from a number at +a requested decimal position. That makes it useful for learning how value-only +node groups support larger procedural systems. + +## Graph Map + +Inputs: + +- `Number` +- `Position` + +Output: + +- `Result` + +Mechanism: + +- Shift `Position` by one. +- Divide `Number` by `10^(Position + 1)`. +- Take the fractional part. +- Multiply by 10 to isolate the digit window. +- Scale by `10^Position`, round, then divide back down. +- If `Position == 0`, round the result. +- Otherwise, floor the result. + +Metaphor: the group is a little inspection window sliding over a number. It +moves to the requested decimal place, crops the surrounding digits away, then +decides whether to round or floor the exposed digit. + +## Verification + +Run: + +```powershell +& 'C:\Program Files (x86)\Steam\steamapps\common\Blender\blender.exe' --background '.\experiments\source-blends\shriinivas-fieldvalue.blend' --python '.\tools\verify_fieldvalue_translations.py' +``` + +The verifier wraps both source and translated `Digit At` groups in a mesh-line +graph where the digit output drives vertex count. This turns a scalar output +into geometry Blender can evaluate and compare. + +Results from Blender 5.1.1: + +| Number | Position | Source Count | Translated Count | Status | +| ---: | ---: | ---: | ---: | --- | +| 1234.0 | 0 | 4 | 4 | accepted | +| 1234.0 | 1 | 3 | 3 | accepted | +| 98765.0 | 2 | 7 | 7 | accepted | +| 120305.0 | 3 | 0 | 0 | accepted | + +## Lessons + +- Not every useful node group emits final geometry. Some are value transducers. +- Value-only graph behavior can still be verified in Blender by embedding the + value output inside a small geometry-producing harness. +- Digit extraction is windowing: scale, crop with fraction/floor/round, then + normalize. +- Large procedural display systems should be built from tiny tested scalar + helpers before composing visible glyph geometry. diff --git a/examples/geometry_script/shriinivas_fieldvalue.py b/examples/geometry_script/shriinivas_fieldvalue.py new file mode 100644 index 0000000..1c26428 --- /dev/null +++ b/examples/geometry_script/shriinivas_fieldvalue.py @@ -0,0 +1,68 @@ +"""Geometry Script recreation of a scalar helper from Shriinivas/fieldvalue.blend.""" + +try: + from tools.geometry_script_loader import load_repo_geometry_script +except ModuleNotFoundError: + import sys + from pathlib import Path + + sys.path.insert(0, str(Path(__file__).resolve().parents[2])) + from tools.geometry_script_loader import load_repo_geometry_script + +load_repo_geometry_script() + +from geometry_script import * # noqa: F403 - Geometry Script exposes node functions as DSL globals. + + +@tree("VG Digit At") +def vg_digit_at(number: Float = 0.0, position: Int = 0): + shifted_position = math(operation=Math.Operation.ADD, value=(position, 1.0)) + upper_scale = math(operation=Math.Operation.POWER, value=(10.0, shifted_position)) + shifted_number = math(operation=Math.Operation.DIVIDE, value=(number, upper_scale)) + fractional_window = math(operation=Math.Operation.FRACT, value=shifted_number) + digit_window = math(operation=Math.Operation.MULTIPLY, value=(10.0, fractional_window)) + + position_scale = math(operation=Math.Operation.POWER, value=(10.0, position)) + rounded_scaled_window = math( + operation=Math.Operation.ROUND, + value=math(operation=Math.Operation.MULTIPLY, value=(digit_window, position_scale)), + ) + digit_value = math(operation=Math.Operation.DIVIDE, value=(rounded_scaled_window, position_scale)) + + is_ones_position = compare( + operation=Compare.Operation.EQUAL, + data_type=Compare.DataType.INT, + mode=Compare.Mode.ELEMENT, + a=position, + b=0, + ) + return switch( + input_type=Switch.InputType.INT, + switch=is_ones_position, + false=math(operation=Math.Operation.FLOOR, value=digit_value), + true=math(operation=Math.Operation.ROUND, value=digit_value), + ) + + +def _finalize_groups(): + import bpy + + group = bpy.data.node_groups.get("VG Digit At") + if not group: + return [] + group.use_fake_user = True + return [group] + + +_finalize_groups() + + +if __name__ == "__main__": + for group in _finalize_groups(): + print( + "VG_FIELDVALUE_GROUP", + group.name, + len(group.nodes), + len(group.links), + sorted(set(node.bl_idname for node in group.nodes)), + ) diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 16b045d..bb3fd2f 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -39,6 +39,10 @@ The completed pie chart translation is `docs/research/translations/shriinivas-piechart.md`. It covers `NodeGroup` and `Pie Chart` from `piechart.blend`. +The completed field-value helper translation is +`docs/research/translations/shriinivas-fieldvalue-digit-at.md`. It covers +`Digit At` from `fieldvalue.blend`. + `docs/research/procedural-doctrine.md` now stores the current intuitive model for mapping geometric ideas to Geometry Script: curves as rails, fields as weather, `Set Position` as the hinge, profiles as body, attributes as optional @@ -49,9 +53,9 @@ group reuse. See `docs/research/geometry-script-fork-notes.md`. Run `.\tools\setup_geometry_script_clone.ps1` if `external/geometry-script` is missing in a fresh workspace. -The current next action is to select the next Tier 1 source graph from -`Shriinivas/geometrynodes`, preferably `fieldvalue.blend`, inspect its node -groups, and add the next doctrine-backed translation entry. +The current next action is to continue `fieldvalue.blend` by translating the +next bounded seven-segment display helper, likely `Create Decimal` or +`Create Segment`, before attempting the full `Field Value` graph. ## Important Invariants diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 95e39e0..6fe48bb 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -7,3 +7,4 @@ {"ts": "2026-05-04T12:42:20+00:00", "type": "implementation", "status": "accepted", "note": "Translated and verified all four inspected Shriinivas/cartesian.blend graph groups: helper, line, parabola, and circle. Verification compares evaluated meshes in Blender 5.1.1; helper/line/parabola match direct vertex order with max delta 0.0, circle matches sorted vertex set with max sorted delta 0.0."} {"ts": "2026-05-04T12:42:20+00:00", "type": "tooling", "status": "accepted", "note": "Reverted direct AppData Geometry Script surgery. Cloned upstream Geometry Script into ignored external/geometry-script, committed local branch vibegeometry/blender-5-nested-tree-groups with nested @tree group fix, stored patch under patches/geometry-script, and added setup_geometry_script_clone.ps1 plus loader so VibeGeometry uses the repo-local patched clone."} {"ts": "2026-05-04T12:48:18+00:00", "type": "implementation", "status": "accepted", "note": "Translated and verified Shriinivas/piechart.blend small graph family: NodeGroup -> VG Pie Segment and Pie Chart -> VG Pie Chart. Segment and chart evaluated mesh comparisons both passed in Blender 5.1.1 with sorted max vertex delta 0.0. Doctrine added: reusable groups can pass invisible scalar state such as End angle alongside visible geometry."} +{"ts": "2026-05-04T12:50:55+00:00", "type": "implementation", "status": "accepted", "note": "Translated and verified Shriinivas/fieldvalue.blend Digit At scalar helper as VG Digit At. Verification wraps source and translation by driving Mesh Line.Count and matches four number/position cases, including zero output. Doctrine added: value-only node groups need geometry-producing verification harnesses."} diff --git a/state/map.yaml b/state/map.yaml index 9ee1716..98ec104 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -82,5 +82,5 @@ data_flow: - If state grows faster than understanding, cut it back. current_status: - summary: VibeGeometry has an initial persistence scaffold plus verified Geometry Script translations for the inspected Shriinivas cartesian and pie chart graph families. - next_action: Select the next Tier 1 source graph from Shriinivas/geometrynodes, preferably `fieldvalue.blend`, inspect its node groups, and add the next doctrine-backed translation entry. + summary: VibeGeometry has an initial persistence scaffold plus verified Geometry Script translations for inspected Shriinivas cartesian, pie chart, and field-value helper graph families. + next_action: Continue fieldvalue.blend by translating the next bounded seven-segment display helper, likely `Create Decimal` or `Create Segment`, before attempting the full `Field Value` graph. diff --git a/tools/verify_fieldvalue_translations.py b/tools/verify_fieldvalue_translations.py new file mode 100644 index 0000000..686d801 --- /dev/null +++ b/tools/verify_fieldvalue_translations.py @@ -0,0 +1,110 @@ +"""Compare Shriinivas fieldvalue scalar helpers against Geometry Script translations.""" + +from __future__ import annotations + +import importlib.util +import json +import sys +from pathlib import Path + +import bpy + + +ROOT = Path(__file__).resolve().parents[1] +TRANSLATION = ROOT / "examples" / "geometry_script" / "shriinivas_fieldvalue.py" + +CASES = [ + {"Number": 1234.0, "Position": 0}, + {"Number": 1234.0, "Position": 1}, + {"Number": 98765.0, "Position": 2}, + {"Number": 120305.0, "Position": 3}, +] + + +def _load_translation() -> None: + spec = importlib.util.spec_from_file_location("vg_fieldvalue_translation", TRANSLATION) + if spec is None or spec.loader is None: + raise RuntimeError(f"Could not load translation script: {TRANSLATION}") + module = importlib.util.module_from_spec(spec) + sys.modules[spec.name] = module + spec.loader.exec_module(module) + + +def _socket_by_name(sockets, name: str): + for socket in sockets: + if socket.name == name: + return socket + raise KeyError(name) + + +def _new_geometry_group(name: str) -> bpy.types.GeometryNodeTree: + if name in bpy.data.node_groups: + bpy.data.node_groups.remove(bpy.data.node_groups[name]) + group = bpy.data.node_groups.new(name, "GeometryNodeTree") + group.is_modifier = True + group.interface.new_socket(name="Geometry", in_out="INPUT", socket_type="NodeSocketGeometry") + group.interface.new_socket(name="Geometry", in_out="OUTPUT", socket_type="NodeSocketGeometry") + return group + + +def _build_count_wrapper(name: str, digit_group: bpy.types.GeometryNodeTree, inputs: dict[str, object]): + wrapper = _new_geometry_group(name) + nodes = wrapper.nodes + links = wrapper.links + digit = nodes.new("GeometryNodeGroup") + digit.node_tree = digit_group + for socket in digit.inputs: + if socket.name in inputs: + socket.default_value = inputs[socket.name] + + line = nodes.new("GeometryNodeMeshLine") + line.mode = "OFFSET" + line.count_mode = "TOTAL" + _socket_by_name(line.inputs, "Offset").default_value = (1.0, 0.0, 0.0) + links.new(_socket_by_name(digit.outputs, "Result"), _socket_by_name(line.inputs, "Count")) + + group_output = nodes.new("NodeGroupOutput") + links.new(_socket_by_name(line.outputs, "Mesh"), _socket_by_name(group_output.inputs, "Geometry")) + return wrapper + + +def _evaluated_vertex_count(group: bpy.types.GeometryNodeTree) -> int: + mesh = bpy.data.meshes.new(group.name + " Input Mesh") + obj = bpy.data.objects.new(group.name + " Object", mesh) + bpy.context.collection.objects.link(obj) + modifier = obj.modifiers.new(group.name + " Modifier", "NODES") + modifier.node_group = group + depsgraph = bpy.context.evaluated_depsgraph_get() + evaluated = obj.evaluated_get(depsgraph) + evaluated_mesh = evaluated.to_mesh() + try: + return len(evaluated_mesh.vertices) + finally: + evaluated.to_mesh_clear() + + +def main() -> int: + _load_translation() + source = bpy.data.node_groups["Digit At"] + translated = bpy.data.node_groups["VG Digit At"] + results = [] + for index, inputs in enumerate(CASES): + source_count = _evaluated_vertex_count(_build_count_wrapper(f"VG Verify Source Digit {index}", source, inputs)) + translated_count = _evaluated_vertex_count( + _build_count_wrapper(f"VG Verify Translated Digit {index}", translated, inputs) + ) + results.append( + { + "case": inputs, + "source_count": source_count, + "translated_count": translated_count, + "ok": source_count == translated_count, + } + ) + ok = all(result["ok"] for result in results) + print("VG_FIELDVALUE_TRANSLATION_BEHAVIOR " + json.dumps({"ok": ok, "results": results}, sort_keys=True)) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main())