Verify cartesian helper translation behavior
This commit is contained in:
parent
58d5515763
commit
9229884f19
4 changed files with 202 additions and 0 deletions
|
|
@ -124,6 +124,10 @@ First completed translation entry:
|
|||
opened `.blend` file into JSON. It records group interfaces, nodes, simple node
|
||||
properties, sockets, links, and modifier users.
|
||||
|
||||
`tools/verify_cartesian_helper_behavior.py` verifies the first translated helper
|
||||
against its source group by wrapping both graphs in the same evaluator graph and
|
||||
comparing evaluated mesh vertices.
|
||||
|
||||
Generated node groups must be referenced by an object/modifier or marked with
|
||||
`use_fake_user = True` before saving a `.blend`; otherwise Blender discards the
|
||||
orphaned group on save. Very normal behavior, if your filing cabinet hates you.
|
||||
|
|
|
|||
|
|
@ -123,6 +123,41 @@ The generated group has fewer nodes than the source because it omits three
|
|||
`NodeReroute` layout nodes and one reroute link. The computational nodes match
|
||||
the source mechanism.
|
||||
|
||||
Behavior verification:
|
||||
|
||||
```powershell
|
||||
& 'C:\Program Files (x86)\Steam\steamapps\common\Blender\blender.exe' --background '.\experiments\source-blends\shriinivas-cartesian.blend' --python '.\tools\verify_cartesian_helper_behavior.py'
|
||||
```
|
||||
|
||||
The verification harness wraps both the source helper and the Geometry Script
|
||||
helper in the same graph:
|
||||
|
||||
```text
|
||||
helper Curve + helper Vector -> Set Position -> Curve to Mesh
|
||||
```
|
||||
|
||||
It evaluates both generated meshes with:
|
||||
|
||||
```text
|
||||
Count = 25
|
||||
Start = (-0.45, 0.0, 0.0)
|
||||
End = (0.45, 0.0, 0.0)
|
||||
r = 0.6
|
||||
Value = 1.25
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
```text
|
||||
source_vertex_count = 200
|
||||
translated_vertex_count = 200
|
||||
max_vertex_delta = 0.0
|
||||
mean_vertex_delta = 0.0
|
||||
```
|
||||
|
||||
This verifies that the translated helper retained the source helper's evaluated
|
||||
behavior for the tested parameter set, not merely its rough node vocabulary.
|
||||
|
||||
## Lessons
|
||||
|
||||
- The local generated Geometry Script docs should be checked before writing each
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@
|
|||
{"ts": "2026-05-04T11:55:00+00:00", "type": "research", "status": "ok", "note": "Local Geometry Script 5.1 generated docs are the authoritative node-signature source for this workspace. The prior grid().mesh_to_points() probe failed because grid() returns a result object with mesh and uv_map; the valid chain is grid(...).mesh.mesh_to_points(...)."}
|
||||
{"ts": "2026-05-04T12:11:47+00:00", "type": "research", "status": "accepted", "note": "Public Geometry Nodes learning material is mostly screenshots, videos, and downloadable .blend files. VibeGeometry should build durable Geometry Script knowledge by inspecting source .blend node groups, mapping one graph at a time in prose, then recreating and smoke-testing with local Geometry Script 5.1 signatures."}
|
||||
{"ts": "2026-05-04T12:21:06+00:00", "type": "implementation", "status": "accepted", "note": "Completed first Geometry Nodes translation corpus entry: inspected Shriinivas/cartesian.blend NodeGroup.001, mapped its curve/vector field flow, recreated it as examples/geometry_script/shriinivas_cartesian_helper.py, and smoke-tested generation/save/reinspection in Blender 5.1.1. Generated node groups need fake users or real users before saving."}
|
||||
{"ts": "2026-05-04T12:24:11+00:00", "type": "verification", "status": "accepted", "note": "Verified translated Shriinivas cartesian helper behavior against source NodeGroup.001 by wrapping both helpers as Curve+Vector -> Set Position -> Curve to Mesh and comparing evaluated mesh vertices. Test used Count=25, Start=(-0.45,0,0), End=(0.45,0,0), r=0.6, Value=1.25; source and translation both produced 200 vertices with max delta 0.0."}
|
||||
|
|
|
|||
162
tools/verify_cartesian_helper_behavior.py
Normal file
162
tools/verify_cartesian_helper_behavior.py
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
"""Compare source and Geometry Script cartesian helper behavior.
|
||||
|
||||
Run with Blender from the repository root:
|
||||
|
||||
blender --background experiments/source-blends/shriinivas-cartesian.blend --python tools/verify_cartesian_helper_behavior.py
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import math
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
TRANSLATION = ROOT / "examples" / "geometry_script" / "shriinivas_cartesian_helper.py"
|
||||
|
||||
TEST_INPUTS = {
|
||||
"Count": 25,
|
||||
"Start": (-0.45, 0.0, 0.0),
|
||||
"End": (0.45, 0.0, 0.0),
|
||||
"r": 0.6,
|
||||
"Value": 1.25,
|
||||
}
|
||||
|
||||
|
||||
def _load_translation() -> None:
|
||||
spec = importlib.util.spec_from_file_location("vg_cartesian_helper_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 _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 _socket_by_name(sockets, name: str):
|
||||
for socket in sockets:
|
||||
if socket.name == name:
|
||||
return socket
|
||||
raise KeyError(name)
|
||||
|
||||
|
||||
def _set_input_defaults(group_node, values: dict[str, object]) -> None:
|
||||
for name, value in values.items():
|
||||
socket = _socket_by_name(group_node.inputs, name)
|
||||
socket.default_value = value
|
||||
|
||||
|
||||
def _build_wrapper(name: str, helper_group: bpy.types.GeometryNodeTree) -> bpy.types.GeometryNodeTree:
|
||||
wrapper = _new_geometry_group(name)
|
||||
nodes = wrapper.nodes
|
||||
links = wrapper.links
|
||||
|
||||
group_input = nodes.new("NodeGroupInput")
|
||||
group_input.location = (-900, 0)
|
||||
group_output = nodes.new("NodeGroupOutput")
|
||||
group_output.location = (500, 0)
|
||||
|
||||
helper = nodes.new("GeometryNodeGroup")
|
||||
helper.node_tree = helper_group
|
||||
helper.location = (-700, 0)
|
||||
_set_input_defaults(helper, TEST_INPUTS)
|
||||
|
||||
set_position = nodes.new("GeometryNodeSetPosition")
|
||||
set_position.location = (-350, 0)
|
||||
profile = nodes.new("GeometryNodeCurvePrimitiveCircle")
|
||||
profile.location = (-350, -220)
|
||||
_socket_by_name(profile.inputs, "Resolution").default_value = 8
|
||||
_socket_by_name(profile.inputs, "Radius").default_value = 0.01
|
||||
|
||||
curve_to_mesh = nodes.new("GeometryNodeCurveToMesh")
|
||||
curve_to_mesh.location = (80, 0)
|
||||
|
||||
links.new(_socket_by_name(helper.outputs, "Curve"), _socket_by_name(set_position.inputs, "Geometry"))
|
||||
links.new(_socket_by_name(helper.outputs, "Vector"), _socket_by_name(set_position.inputs, "Position"))
|
||||
links.new(_socket_by_name(set_position.outputs, "Geometry"), _socket_by_name(curve_to_mesh.inputs, "Curve"))
|
||||
links.new(_socket_by_name(profile.outputs, "Curve"), _socket_by_name(curve_to_mesh.inputs, "Profile Curve"))
|
||||
links.new(_socket_by_name(curve_to_mesh.outputs, "Mesh"), _socket_by_name(group_output.inputs, "Geometry"))
|
||||
return wrapper
|
||||
|
||||
|
||||
def _evaluated_vertices(group: bpy.types.GeometryNodeTree) -> list[tuple[float, float, float]]:
|
||||
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 [tuple(vertex.co) for vertex in evaluated_mesh.vertices]
|
||||
finally:
|
||||
evaluated.to_mesh_clear()
|
||||
|
||||
|
||||
def _bounds(vertices: list[tuple[float, float, float]]) -> dict[str, list[float]]:
|
||||
return {
|
||||
"min": [min(vertex[i] for vertex in vertices) for i in range(3)],
|
||||
"max": [max(vertex[i] for vertex in vertices) for i in range(3)],
|
||||
}
|
||||
|
||||
|
||||
def _compare(source_vertices, translated_vertices) -> dict[str, object]:
|
||||
if len(source_vertices) != len(translated_vertices):
|
||||
return {
|
||||
"ok": False,
|
||||
"reason": "vertex_count_mismatch",
|
||||
"source_vertex_count": len(source_vertices),
|
||||
"translated_vertex_count": len(translated_vertices),
|
||||
}
|
||||
max_delta = 0.0
|
||||
total_delta = 0.0
|
||||
for source, translated in zip(source_vertices, translated_vertices):
|
||||
delta = math.dist(source, translated)
|
||||
max_delta = max(max_delta, delta)
|
||||
total_delta += delta
|
||||
return {
|
||||
"ok": max_delta <= 1e-6,
|
||||
"source_vertex_count": len(source_vertices),
|
||||
"translated_vertex_count": len(translated_vertices),
|
||||
"max_vertex_delta": max_delta,
|
||||
"mean_vertex_delta": total_delta / len(source_vertices) if source_vertices else 0.0,
|
||||
"source_bounds": _bounds(source_vertices),
|
||||
"translated_bounds": _bounds(translated_vertices),
|
||||
}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
source_helper = bpy.data.node_groups.get("NodeGroup.001")
|
||||
if source_helper is None:
|
||||
raise RuntimeError("Source helper node group 'NodeGroup.001' was not found.")
|
||||
|
||||
_load_translation()
|
||||
translated_helper = bpy.data.node_groups.get("VG Cartesian Helper")
|
||||
if translated_helper is None:
|
||||
raise RuntimeError("Translated helper node group 'VG Cartesian Helper' was not found.")
|
||||
|
||||
source_wrapper = _build_wrapper("VG Verify Source Cartesian Helper", source_helper)
|
||||
translated_wrapper = _build_wrapper("VG Verify Translated Cartesian Helper", translated_helper)
|
||||
result = _compare(_evaluated_vertices(source_wrapper), _evaluated_vertices(translated_wrapper))
|
||||
print("VG_CARTESIAN_HELPER_BEHAVIOR " + json.dumps(result, sort_keys=True))
|
||||
return 0 if result["ok"] else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Loading…
Reference in a new issue