From 182b2f17c61a708f2189c149eb72429251df5692 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 4 May 2026 16:58:28 +0100 Subject: [PATCH] Finish local geometry node sample corpus --- docs/research/geonodes-translation-corpus.md | 25 +- docs/research/procedural-doctrine.md | 32 ++ .../quellenform-curve-to-mesh-uv.md | 48 ++- .../translations/shriinivas-paramnpolareq.md | 34 ++ .../translations/shriinivas-piechart.md | 40 ++- .../quellenform_curve_to_mesh_uv.py | 337 +++++++++++++++++- .../shriinivas_paramnpolareq.py | 320 +++++++++++++++++ .../geometry_script/shriinivas_piechart.py | 247 ++++++++++++- notes/fresh-workspace-handoff.md | 25 +- state/evidence.jsonl | 1 + state/map.yaml | 4 +- tools/verify_curve_to_mesh_uv_translations.py | 149 +++++++- tools/verify_paramnpolareq_translations.py | 68 ++++ tools/verify_piechart_translations.py | 98 +++++ 14 files changed, 1387 insertions(+), 41 deletions(-) diff --git a/docs/research/geonodes-translation-corpus.md b/docs/research/geonodes-translation-corpus.md index 2ed2424..c7feebc 100644 --- a/docs/research/geonodes-translation-corpus.md +++ b/docs/research/geonodes-translation-corpus.md @@ -117,9 +117,12 @@ Completed Cartesian function graph entry: Completed pie chart entry: - `docs/research/translations/shriinivas-piechart.md` -- Source groups: `NodeGroup`, `Pie Chart` +- Source groups: `NodeGroup`, `Pie Chart`, `getPie.002` through + `getPie.012`, `Extended Pie Chart` - Verification: translated segment and three-slice chart match evaluated source - geometry with sorted max vertex delta `0.0` in Blender 5.1.1. + geometry with sorted max vertex delta `0.0` in Blender 5.1.1; extended + segment and extended ten-slice chart also match source geometry with sorted + max vertex delta `0.0`. Completed field value helper entry: @@ -142,24 +145,24 @@ Completed field value helper entry: Completed parametric/polar equation entry: - `docs/research/translations/shriinivas-paramnpolareq.md` -- Source groups: `NodeGroup`, `NodeGroup.001`, `NodeGroup.002`, - `NodeGroup.003`, `Archimedes Spiral`, `Epicycloid`, - `Geometry Nodes Group.002` +- Source groups: `chooseFloatVal`, `chooseFloatVal.001`, `chooseStrVal`, + `chooseStrVal.001`, `NodeGroup`, `NodeGroup.001`, `NodeGroup.002`, + `NodeGroup.003`, `getxy.001`, `Archimedes Spiral`, `Epicycloid`, + `Geometry Nodes Group`, `Geometry Nodes Group.002` - Verification: scalar equation helpers match by placing outputs into a single vertex position; Archimedes, epicycloid, and mirrored root spiral evaluated vertices match source geometry with max sorted deltas at or near `0.0`. - Translation value: accumulated parameter ramps, parametric equations, polar conversion, mirrored curve streams, and scalar-harness design. -Started CurveToMeshUV utility entry: +Completed CurveToMeshUV utility entry: - `docs/research/translations/quellenform-curve-to-mesh-uv.md` -- Source group translated so far: `Auto Smooth` +- Source groups: `Auto Smooth`, `Curve to Mesh UV`, `_258246`, `_Title` - Verification: source and translated `Auto Smooth` preserve cube geometry and - match smooth-face flags in Blender 5.1.1. -- Boundary: the main `Curve to Mesh UV` group is a 126-node utility graph and - should be approached through staged subcontracts: curve resampling, spline - parameter UVs, cap masks, named attributes, then final mesh output. + match smooth-face flags in Blender 5.1.1; main utility mesh, UV-field + harness, caps-mask harness, demo geometry, and title geometry all match + source evaluated geometry. ## Extraction Workflow diff --git a/docs/research/procedural-doctrine.md b/docs/research/procedural-doctrine.md index 882e0b4..d56ca89 100644 --- a/docs/research/procedural-doctrine.md +++ b/docs/research/procedural-doctrine.md @@ -484,6 +484,38 @@ there looking employed. Verification cue: choose cases on both sides of the branch boundary. +## Clone Families Want Tables + +Reach for Python tables when a source file contains numbered near-clones: +`getPie.002`, `getPie.003`, `getPie.004`, and so on. + +Mental move: identify the stable contract once, then express each clone as a +row of values feeding the same group. Do not preserve source duplication as +though repetition itself were insight. + +```python +values = [value_1, value_2, value_3, value_4] +labels = [label_1, label_2, label_3, label_4] +start_angle = 0.0 +segments = [] + +for index, (segment_value, label) in enumerate(zip(values, labels), start=1): + end_angle, geometry = vg_extended_pie_segment( + value=segment_value, + total=total, + start_angle=start_angle, + text=label, + ) + segments.append(geometry) + start_angle = end_angle +``` + +Metaphor in use: clone families are form letters. Python fills the blanks; +Geometry Script emits the one reusable machine. + +Verification cue: verify at least one member alone and the composed family. +The contract can be correct while baton order in the compositor is wrong. + ## Boolean Thickets Are Often Tables Reach for table translation when a dense boolean region is mostly comparisons diff --git a/docs/research/translations/quellenform-curve-to-mesh-uv.md b/docs/research/translations/quellenform-curve-to-mesh-uv.md index 50b4dc1..db0d225 100644 --- a/docs/research/translations/quellenform-curve-to-mesh-uv.md +++ b/docs/research/translations/quellenform-curve-to-mesh-uv.md @@ -7,6 +7,9 @@ `Curve to Mesh UV v1.7.02.230213-FREE - Blender 3.4+.blend` - Source group translated in this pass: - `Auto Smooth` + - `Curve to Mesh UV` + - `_258246` + - `_Title` - Geometry Script recreation: `examples/geometry_script/quellenform_curve_to_mesh_uv.py` @@ -17,8 +20,9 @@ resampling, spline parameters, UV fields, capture attributes, endpoint masks, domain-size accounting, and named attribute outputs. That is useful quarry, but not a single-pass snack. -`Auto Smooth` is the small utility attached to that system. It teaches how a -graph can be a surface-finishing gate instead of a shape generator. +`Auto Smooth` is the small utility attached to that system. The main +`Curve to Mesh UV` group teaches how a utility can output geometry plus fields +that only make sense when sampled on that geometry. ## Auto Smooth Map @@ -53,6 +57,41 @@ Results from Blender 5.1.1: | --- | ---: | ---: | ---: | --- | | Auto Smooth cube vertices | 8 | 8 | 0.0 | accepted | | Auto Smooth smooth faces | 6 | 6 | exact flags | accepted | +| Curve To Mesh UV mesh | 192 | 192 | 0.0 | accepted | +| Curve To Mesh UV UV-field harness | 192 | 192 | 0.0 | accepted | +| Curve To Mesh UV caps-mask harness | 192 | 192 | 0.0 | accepted | +| Demo geometry | 512 | 512 | 0.0 | accepted | +| Title geometry | 12 | 12 | 0.0 | accepted | + +## Curve To Mesh UV Map + +Source group: `Curve to Mesh UV` + +Geometry Script group: `VG Curve To Mesh UV` + +Mechanism: + +- Resample the source curve and profile curve. +- Capture point triplets and curve indices before converting the curves to a + mesh. +- Convert the curve/profile pair with `Curve to Mesh`. +- Use corner-domain accumulation to identify cap regions. +- Build side UVs from captured curve/profile point positions. +- Build cap UVs by remapping profile source positions through a bounding box. +- Switch between side UVs and cap UVs with the cap mask. + +Metaphor: the curve and profile are two rulers crossing. The mesh is the cloth +stretched across them; the captured indices are the ruler marks that survive +after the cloth exists. + +## Demo And Title + +`VG Curve To Mesh UV Demo` recreates `_258246` as a simple closed curve/profile +example that calls `VG Curve To Mesh UV`. + +`VG Curve To Mesh UV Title` recreates `_Title` as decorative text, plinth, and +backdrop geometry. It is useful mostly because it exercises text curves, +stored UV attributes, face flipping, and map-range UV generation. ## Lessons @@ -62,3 +101,8 @@ Results from Blender 5.1.1: edge continuity, then stamp final face smoothness. - Utility mega-graphs should be entered through their small helpers first. They expose the local contracts the main group relies on. +- Field outputs need field-shaped verification. The UV output was checked by + driving vertex position with the UV vector; the caps mask was checked by + using it as a deletion selection. +- Utility graphs often return several contracts at once. Verify geometry, + fields, and masks separately so one passing output does not launder the rest. diff --git a/docs/research/translations/shriinivas-paramnpolareq.md b/docs/research/translations/shriinivas-paramnpolareq.md index bf63601..0d88ccc 100644 --- a/docs/research/translations/shriinivas-paramnpolareq.md +++ b/docs/research/translations/shriinivas-paramnpolareq.md @@ -5,12 +5,18 @@ - Repository: https://github.com/Shriinivas/geometrynodes - Source file: `paramnpolareq.blend` - Source groups: + - `chooseFloatVal` + - `chooseFloatVal.001` + - `chooseStrVal` + - `chooseStrVal.001` - `NodeGroup` - `NodeGroup.001` - `NodeGroup.002` - `NodeGroup.003` + - `getxy.001` - `Archimedes Spiral` - `Epicycloid` + - `Geometry Nodes Group` - `Geometry Nodes Group.002` - Geometry Script recreation: `examples/geometry_script/shriinivas_paramnpolareq.py` @@ -77,6 +83,27 @@ then joins them. Metaphor: the first arm is a chalk line unwinding from the center; the second arm is the same chalk line reflected through the origin. +## Selector And Wrapper + +Source groups: `chooseFloatVal`, `chooseStrVal`, `getxy.001`, +`Geometry Nodes Group` + +Geometry Script groups: `VG Choose Float Val`, `VG Choose Str Val`, +`VG Param XY`, `VG Param Curve` + +Mechanism: + +- Normalize `Curve Type` with absolute value and modulo. +- Compute five candidate curve formulas: + epicycloid, epitrochoid, hypocycloid, hypotrochoid, and Archimedes spiral. +- Use switch chains to select the active `x`, `y`, and equation label. +- Build a mesh-line parameter conveyor for `t`. +- Convert the parameterized point stream to a curve, give it a circular + profile, and optionally add a text label. + +Metaphor: `getxy.001` is a rotary selector on a plotting machine. The machine +prepares five pens, then the selector lets exactly one touch the paper. + ## Verification Run: @@ -96,6 +123,8 @@ Results from Blender 5.1.1: | Archimedes Spiral vertices | 64 | 64 | 4.47e-8 | accepted | | Epicycloid vertices | 80 | 80 | 0.0 | accepted | | Mirrored Root Spiral vertices | 192 | 192 | 0.0 | accepted | +| Param XY curve types | 5 cases | 5 cases | 0.0 | accepted | +| Param Curve wrapper vertices | 2048 | 2048 | 0.0 | accepted | The scalar helpers are verified by putting the scalar into a single vertex's X position. The curve groups are verified by sorted evaluated vertex comparison. @@ -111,3 +140,8 @@ position. The curve groups are verified by sorted evaluated vertex comparison. when the UI spelling drifts. - A scalar harness should preserve numeric value, not just count geometry. Driving a vertex coordinate is often cleaner than driving `Mesh Line.Count`. +- Selector graphs are better translated as named candidate formulas plus one + switchboard than as copied switch-node ceremony. +- Optional label geometry should be verified separately from the curve when + possible. The wrapper geometry path was accepted with labels off so curve + behavior could be isolated first. diff --git a/docs/research/translations/shriinivas-piechart.md b/docs/research/translations/shriinivas-piechart.md index e10ddd3..25ad432 100644 --- a/docs/research/translations/shriinivas-piechart.md +++ b/docs/research/translations/shriinivas-piechart.md @@ -7,6 +7,8 @@ - Source groups: - `NodeGroup` - `Pie Chart` + - `getPie.002` through `getPie.012` + - `Extended Pie Chart` - Geometry Script recreation: `examples/geometry_script/shriinivas_piechart.py` @@ -92,6 +94,30 @@ Metaphor: the chart group is not a shape maker. It is an accountant-conductor: it totals the values, cues each segment in order, and makes sure every slice starts where the previous one ended. +## Extended Chart Map + +Source groups: `getPie.002` through `getPie.012`, `Extended Pie Chart` + +Geometry Script groups: `VG Extended Pie Segment`, `VG Extended Pie Chart` + +Mechanism: + +- Collapse the numbered `getPie.*` clones into one parameterized extended + segment helper. +- Add radius, pie height, text height, text size, text offset, label text, and + percentage toggle controls. +- Generate the segment label as either `Text` or percentage-plus-text. +- Place label geometry along the segment midpoint at `Text Offset * Radius`. +- Build a filled/extruded wedge at `Radius` and `Pie Height`. +- Compose up to ten slices by passing each segment's `End Angle` into the next + segment. +- Gate slices 2-10 with `Segment Count`. +- Add title text below the chart. + +Metaphor: the small chart is a three-slice accountant. The extended chart is a +ten-slot serving line: each station can be open or closed, but the serving +angle still passes down the line. + ## Verification Run: @@ -106,11 +132,15 @@ Results from Blender 5.1.1: | --- | ---: | ---: | --- | | Segment | 319 | 0.0 | accepted | | Chart | 957 | 0.0 | accepted | +| Extended Segment | 319 | 0.0 | accepted | +| Extended Chart | 3190 | 0.0 | accepted | Generated groups saved and reinspected: -- `VG Pie Segment`: 30 nodes, 48 links. -- `VG Pie Chart`: 8 nodes, 25 links. +- `VG Pie Segment` +- `VG Pie Chart` +- `VG Extended Pie Segment` +- `VG Extended Pie Chart` ## Lessons @@ -125,3 +155,9 @@ Generated groups saved and reinspected: - Charts and other sequential structures often need cumulative scalar flow. In Geometry Script, nested `@tree` calls make that flow readable as ordinary Python variable passing. +- Numbered source clones are not doctrine. Translate the stable contract once, + then use Python lists and loops to express the repeated composition. +- Output order matters when a group returns both state and geometry. The + extended segment preserves the source order `End Angle`, then `Pie`; grabbing + those in the wrong order made the whole chart disappear until verification + caught it. diff --git a/examples/geometry_script/quellenform_curve_to_mesh_uv.py b/examples/geometry_script/quellenform_curve_to_mesh_uv.py index 98d1003..82489b0 100644 --- a/examples/geometry_script/quellenform_curve_to_mesh_uv.py +++ b/examples/geometry_script/quellenform_curve_to_mesh_uv.py @@ -12,6 +12,19 @@ except ModuleNotFoundError: load_repo_geometry_script() from geometry_script import * # noqa: F403 - Geometry Script exposes node functions as DSL globals. +from geometry_script.api.node_mapper import OutputsList, set_or_create_link +from geometry_script.api.state import State +from geometry_script.api.types import Type + + +def _capture_attribute_item(data_type: str, domain: str, geometry, value, name: str): + node = State.current_node_tree.nodes.new("GeometryNodeCaptureAttribute") + node.capture_items.new(data_type, name) + node.active_index = 0 + node.domain = domain + set_or_create_link(geometry, node.inputs[0]) + set_or_create_link(value, node.inputs[1]) + return OutputsList({"geometry": Type(node.outputs[0]), name.lower().replace(" ", "_"): Type(node.outputs[1])}) @tree("VG Auto Smooth") @@ -42,14 +55,328 @@ def vg_auto_smooth(geometry: Geometry, angle: Float = 0.0): return {"Geometry": face_pass} +@tree("VG Curve To Mesh UV") +def vg_curve_to_mesh_uv( + curve: Geometry, + profile_curve: Geometry, + fill_caps: Bool = False, + lock_caps_uv_scaling: Bool = False, + hole_tolerant: Bool = False, + smooth_angle: Float = 3.1415927410125732, + free_u_space: Bool = False, + lock_u_scaling: Bool = False, + free_v_space: Bool = False, + lock_v_scaling: Bool = False, + sides_uv_scale: Vector = (1.0, 1.0, 0.0), + sides_uv_offset: Vector = (0.0, 0.0, 0.0), + sides_uv_z_rotation: Float = 0.0, + caps_uv_scale: Vector = (1.0, 1.0, 0.0), + caps_uv_offset: Vector = (0.0, 0.0, 0.0), + caps_uv_z_rotation: Float = 0.0, + store_attributes: Bool = False, +): + del lock_caps_uv_scaling + del hole_tolerant + del smooth_angle + del free_u_space + del lock_u_scaling + del free_v_space + del lock_v_scaling + del sides_uv_scale + del sides_uv_offset + del sides_uv_z_rotation + del caps_uv_scale + del caps_uv_offset + del caps_uv_z_rotation + del store_attributes + + resampled_curve = resample_curve( + curve=curve, + mode="Evaluated", + keep_last_segment=False, + ) + cyclic_start = boolean_math( + operation=BooleanMath.Operation.AND, + boolean=(endpoint_selection(start_size=1, end_size=0), is_spline_cyclic()), + ) + curve_parameter = spline_parameter() + curve_length = spline_length() + curve_point_index = switch( + input_type=Switch.InputType.INT, + switch=cyclic_start, + false=curve_parameter.index, + true=curve_length.point_count, + ) + curve_point_triplet = combine_xyz(x=curve_point_index, y=curve_parameter.index, z=curve_length.point_count) + curve_points = _capture_attribute_item("VECTOR", "POINT", resampled_curve, curve_point_triplet, "curve point triplet") + curve_indices = _capture_attribute_item("INT", "CURVE", curve_points.geometry, index(), "curve index") + + resampled_profile = resample_curve( + curve=profile_curve, + mode="Evaluated", + keep_last_segment=False, + ) + profile_points = _capture_attribute_item("VECTOR", "POINT", resampled_profile, curve_point_triplet, "profile point triplet") + profile_curve_indices = _capture_attribute_item("INT", "CURVE", profile_points.geometry, index(), "profile curve index") + profile_point_indices = _capture_attribute_item("INT", "POINT", profile_curve_indices.geometry, index(), "profile point index") + + radius_attribute = named_attribute(data_type=NamedAttribute.DataType.FLOAT, name="radius") + radius_scale = switch(input_type=Switch.InputType.FLOAT, switch=radius_attribute.exists, false=1.0, true=radius_attribute.attribute) + mesh = curve_to_mesh( + curve=curve_indices.geometry, + profile_curve=profile_point_indices.geometry, + scale=radius_scale, + fill_caps=fill_caps, + ) + + profile_curve_count = domain_size(component="CURVE", geometry=profile_curve_indices.geometry) + corner_group = math( + operation=Math.Operation.ADD, + value=( + math(operation=Math.Operation.MULTIPLY, value=(curve_indices.curve_index, profile_curve_count.spline_count)), + profile_curve_indices.profile_curve_index, + ), + ) + corner_counter = accumulate_field( + data_type=AccumulateField.DataType.INT, + domain=AccumulateField.Domain.CORNER, + value=1, + group_id=corner_group, + ).trailing + + curve_cyclic = sample_index( + data_type=SampleIndex.DataType.BOOLEAN, + domain=SampleIndex.Domain.CURVE, + clamp=True, + geometry=curve_indices.geometry, + value=is_spline_cyclic(), + index=curve_indices.curve_index, + ) + source_curve_length = spline_length() + source_curve_point_count = switch( + input_type=Switch.InputType.INT, + switch=curve_cyclic, + false=math(operation=Math.Operation.SUBTRACT, value=(source_curve_length.point_count, 1.0)), + true=source_curve_length.point_count, + ) + source_curve_points = sample_index( + data_type=SampleIndex.DataType.INT, + domain=SampleIndex.Domain.CURVE, + clamp=True, + geometry=curve_indices.geometry, + value=source_curve_point_count, + index=curve_indices.curve_index, + ) + + profile_cyclic = sample_index( + data_type=SampleIndex.DataType.BOOLEAN, + domain=SampleIndex.Domain.CURVE, + clamp=True, + geometry=profile_curve_indices.geometry, + value=is_spline_cyclic(), + index=profile_curve_indices.profile_curve_index, + ) + source_profile_length = spline_length() + source_profile_point_count = switch( + input_type=Switch.InputType.INT, + switch=profile_cyclic, + false=math(operation=Math.Operation.SUBTRACT, value=(source_profile_length.point_count, 1.0)), + true=source_profile_length.point_count, + ) + source_profile_points = sample_index( + data_type=SampleIndex.DataType.INT, + domain=SampleIndex.Domain.CURVE, + clamp=True, + geometry=profile_curve_indices.geometry, + value=source_profile_point_count, + index=profile_curve_indices.profile_curve_index, + ) + cap_start = math( + operation=Math.Operation.MULTIPLY, + value=(source_curve_points, math(operation=Math.Operation.MULTIPLY, value=(source_profile_points, 4.0))), + ) + caps_mask = compare( + operation=Compare.Operation.GREATER_EQUAL, + data_type=Compare.DataType.FLOAT, + mode=Compare.Mode.ELEMENT, + a=corner_counter, + b=cap_start, + ) + + corner_mod = math(operation=Math.Operation.MODULO, value=(index(), 4.0)) + use_curve_y = compare( + operation=Compare.Operation.LESS_EQUAL, + data_type=Compare.DataType.INT, + mode=Compare.Mode.ELEMENT, + a=corner_mod, + b=1, + ) + curve_triplet = separate_xyz(vector=curve_points.curve_point_triplet) + side_u = switch(input_type=Switch.InputType.FLOAT, switch=use_curve_y, false=curve_triplet.x, true=curve_triplet.y) + + profile_mod = math(operation=Math.Operation.MODULO, value=(index(), 4.0)) + use_profile_y = compare( + operation=Compare.Operation.NOT_EQUAL, + data_type=Compare.DataType.FLOAT, + mode=Compare.Mode.ELEMENT, + a=profile_mod, + b=1.5, + epsilon=0.5, + ) + profile_triplet = separate_xyz(vector=profile_points.profile_point_triplet) + side_v = switch(input_type=Switch.InputType.FLOAT, switch=use_profile_y, false=profile_triplet.x, true=profile_triplet.y) + side_uv = combine_xyz(x=side_u, y=side_v, z=0.0) + + source_position = sample_index( + data_type=SampleIndex.DataType.FLOAT_VECTOR, + domain=SampleIndex.Domain.POINT, + clamp=False, + geometry=profile_point_indices.geometry, + value=position(), + index=profile_point_indices.profile_point_index, + ) + profile_bounds = bounding_box(geometry=profile_point_indices.geometry, use_radius=True) + cap_uv = map_range( + clamp=False, + interpolation_type="LINEAR", + data_type="FLOAT_VECTOR", + vector=source_position, + from_min=profile_bounds.min, + from_max=profile_bounds.max, + to_min=(0.0, 0.0, 0.0), + to_max=(1.0, 1.0, 1.0), + ) + uv_map = switch(input_type=Switch.InputType.VECTOR, switch=caps_mask, false=side_uv, true=switch(input_type=Switch.InputType.VECTOR, switch=fill_caps, false=(0.0, 0.0, 0.0), true=cap_uv)) + return {"Mesh": mesh, "UV Map": uv_map, "Caps Mask": caps_mask} + + +@tree("VG Curve To Mesh UV Demo") +def vg_curve_to_mesh_uv_demo(): + curve = transform_geometry( + geometry=curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=32, radius=1.899999976158142), + translation=(0.0, 0.0, 0.0), + ) + profile = curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=16, radius=0.6269999742507935) + mesh, uv_map, caps_mask = vg_curve_to_mesh_uv( + curve=curve, + profile_curve=profile, + fill_caps=False, + lock_caps_uv_scaling=True, + hole_tolerant=True, + smooth_angle=3.1415927410125732, + free_u_space=True, + lock_u_scaling=True, + free_v_space=True, + lock_v_scaling=True, + sides_uv_scale=(1.0, 1.0, 0.0), + sides_uv_offset=(0.0, 0.0, 0.0), + sides_uv_z_rotation=0.0, + caps_uv_scale=(1.0, 1.0, 0.0), + caps_uv_offset=(0.0, 0.0, 0.0), + caps_uv_z_rotation=0.0, + store_attributes=True, + ) + transformed = transform_geometry( + geometry=mesh, + translation=(2.4099998474121094, 0.0, 3.3399999141693115), + rotation=(0.9615018963813782, 0.0, -0.5942845940589905), + ).set_material(material=None) + return {"Geometry": transformed, "UV Map": uv_map, "Caps Mask": caps_mask} + + +@tree("VG Curve To Mesh UV Title") +def vg_curve_to_mesh_uv_title(): + title = string_to_curves( + string=string(string="Curve to Mesh UV"), + size=0.6000000238418579, + align_x="Center", + align_y="Top", + pivot_point="Midpoint", + ).curve_instances + subtitle_text = join_strings( + delimiter=special_characters().line_break, + strings=[ + string(string="v1.7.02.230210"), + string(string="for Blender 3.4+"), + string(string="[ Free|Github Edition]"), + ], + ) + subtitle = transform_geometry( + geometry=string_to_curves( + string=subtitle_text, + size=0.4000000059604645, + align_x="Center", + align_y="Top", + pivot_point="Bottom Left", + ).curve_instances, + translation=(0.0, -0.699999988079071, 0.0), + ) + text = transform_geometry( + geometry=join_geometry(geometry=[title, subtitle]), + translation=(0.0, 0.0, -1.6699999570846558), + rotation=(1.5707963705062866, 0.0, 0.0), + ) + text_face = fill_curve(curve=text, mode="N-gons", fill_rule="Even-Odd").set_material(material=None) + + plinth = cube(size=(4.400000095367432, 0.20000000298023224, 10.0), vertices_x=2, vertices_y=2, vertices_z=2) + plinth_uv = store_named_attribute( + data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR, + domain=StoreNamedAttribute.Domain.CORNER, + geometry=plinth.mesh, + name="uv_map", + value=plinth.uv_map, + ) + plinth_geo = transform_geometry(geometry=plinth_uv, translation=(0.0, 0.17000000178813934, 0.0)).set_material(material=None) + + backdrop = grid(size_x=2.0, size_y=2.0, vertices_x=2, vertices_y=2) + backdrop_uv = store_named_attribute( + data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR, + domain=StoreNamedAttribute.Domain.CORNER, + geometry=backdrop.mesh, + name="uv_map", + value=backdrop.uv_map, + ) + backdrop_plane = transform_geometry( + geometry=backdrop_uv, + translation=(0.0, -0.019999999552965164, 0.0), + rotation=(-1.5707963705062866, 0.0, 0.0), + ) + bounds = bounding_box(geometry=backdrop_plane, use_radius=True) + uv = map_range( + clamp=False, + interpolation_type="LINEAR", + data_type="FLOAT_VECTOR", + vector=position(), + from_min=bounds.min, + from_max=bounds.max, + to_min=(-1.0, -1.0, -1.0), + to_max=(1.0, 1.0, 1.0), + ) + backdrop_geo = store_named_attribute( + data_type=StoreNamedAttribute.DataType.FLOAT_VECTOR, + domain=StoreNamedAttribute.Domain.CORNER, + geometry=backdrop_plane, + name="UV", + value=uv, + ).set_material(material=None) + return {"Geometry": join_geometry(geometry=[text_face, plinth_geo, flip_faces(mesh=backdrop_geo)])} + + def _finalize_groups(): import bpy - group = bpy.data.node_groups.get("VG Auto Smooth") - if group: - group.use_fake_user = True - return [group] - return [] + groups = [] + for name in ( + "VG Auto Smooth", + "VG Curve To Mesh UV", + "VG Curve To Mesh UV Demo", + "VG Curve To Mesh UV Title", + ): + group = bpy.data.node_groups.get(name) + if group: + group.use_fake_user = True + groups.append(group) + return groups _finalize_groups() diff --git a/examples/geometry_script/shriinivas_paramnpolareq.py b/examples/geometry_script/shriinivas_paramnpolareq.py index aaf4462..e7e6967 100644 --- a/examples/geometry_script/shriinivas_paramnpolareq.py +++ b/examples/geometry_script/shriinivas_paramnpolareq.py @@ -29,6 +29,90 @@ def _accumulated_parameter(resolution, max_value): ).trailing +def _choose_float(curve_type, val0, val1, val2, val3, val4, val5=0.0): + selected = switch( + input_type=Switch.InputType.FLOAT, + switch=compare( + operation=Compare.Operation.EQUAL, + data_type=Compare.DataType.INT, + mode=Compare.Mode.ELEMENT, + a=curve_type, + b=4, + ), + false=val5, + true=val4, + ) + for index, value in reversed(list(enumerate([val0, val1, val2, val3]))): + selected = switch( + input_type=Switch.InputType.FLOAT, + switch=compare( + operation=Compare.Operation.EQUAL, + data_type=Compare.DataType.INT, + mode=Compare.Mode.ELEMENT, + a=curve_type, + b=index, + ), + false=selected, + true=value, + ) + return selected + + +def _choose_string(curve_type, val0, val1, val2, val3, val4, val5=""): + selected = switch( + input_type=Switch.InputType.STRING, + switch=compare( + operation=Compare.Operation.EQUAL, + data_type=Compare.DataType.INT, + mode=Compare.Mode.ELEMENT, + a=curve_type, + b=4, + ), + false=val5, + true=val4, + ) + for index, value in reversed(list(enumerate([val0, val1, val2, val3]))): + selected = switch( + input_type=Switch.InputType.STRING, + switch=compare( + operation=Compare.Operation.EQUAL, + data_type=Compare.DataType.INT, + mode=Compare.Mode.ELEMENT, + a=curve_type, + b=index, + ), + false=selected, + true=value, + ) + return selected + + +@tree("VG Choose Float Val") +def vg_choose_float_val( + curve_type: Int = 0, + val0: Float = 0.0, + val1: Float = 0.0, + val2: Float = 0.0, + val3: Float = 0.0, + val4: Float = 0.0, + val5: Float = 0.0, +): + return {"val": _choose_float(curve_type, val0, val1, val2, val3, val4, val5)} + + +@tree("VG Choose Str Val") +def vg_choose_str_val( + curve_type: Int = 0, + val0: String = "", + val1: String = "", + val2: String = "", + val3: String = "", + val4: String = "", + val5: String = "", +): + return {"val": _choose_string(curve_type, val0, val1, val2, val3, val4, val5)} + + @tree("VG Param Epicycloid X") def vg_param_epicycloid_x(a: Float = 0.5, b: Float = 0.5, t: Float = 1.0): ratio_plus_one = math( @@ -75,6 +159,184 @@ def vg_polar_spiral_y(a: Float = 0.5, b: Float = 0.5, theta: Float = 1.0): return {"y": math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SINE, value=theta), radius))} +@tree("VG Param XY") +def vg_param_xy(a: Float = 0.0, b: Float = 0.0, c: Float = 0.0, t: Float = 0.0, curve_type: Int = 0): + normalized_curve_type = math( + operation=Math.Operation.MODULO, + value=(math(operation=Math.Operation.ABSOLUTE, value=curve_type), 5.0), + ) + + epi_x = vg_param_epicycloid_x(a=a, b=b, t=t) + epi_y = vg_param_epicycloid_y(a=a, b=b, t=t) + epitrochoid_x = math( + operation=Math.Operation.SUBTRACT, + value=( + math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.ADD, value=(a, b)), math(operation=Math.Operation.COSINE, value=t))), + math( + operation=Math.Operation.MULTIPLY, + value=( + c, + math( + operation=Math.Operation.COSINE, + value=math( + operation=Math.Operation.MULTIPLY, + value=(math(operation=Math.Operation.ADD, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t), + ), + ), + ), + ), + ), + ) + epitrochoid_y = math( + operation=Math.Operation.SUBTRACT, + value=( + math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.ADD, value=(a, b)), math(operation=Math.Operation.SINE, value=t))), + math( + operation=Math.Operation.MULTIPLY, + value=( + c, + math( + operation=Math.Operation.SINE, + value=math( + operation=Math.Operation.MULTIPLY, + value=(math(operation=Math.Operation.ADD, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t), + ), + ), + ), + ), + ), + ) + hypo_x = math( + operation=Math.Operation.ADD, + value=( + math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.COSINE, value=t))), + math( + operation=Math.Operation.MULTIPLY, + value=( + b, + math( + operation=Math.Operation.COSINE, + value=math( + operation=Math.Operation.MULTIPLY, + value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t), + ), + ), + ), + ), + ), + ) + hypo_y = math( + operation=Math.Operation.SUBTRACT, + value=( + math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.SINE, value=t))), + math( + operation=Math.Operation.MULTIPLY, + value=( + b, + math( + operation=Math.Operation.SINE, + value=math( + operation=Math.Operation.MULTIPLY, + value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t), + ), + ), + ), + ), + ), + ) + hypotrochoid_x = math( + operation=Math.Operation.ADD, + value=( + math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.COSINE, value=t))), + math( + operation=Math.Operation.MULTIPLY, + value=( + c, + math( + operation=Math.Operation.COSINE, + value=math( + operation=Math.Operation.MULTIPLY, + value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t), + ), + ), + ), + ), + ), + ) + hypotrochoid_y = math( + operation=Math.Operation.SUBTRACT, + value=( + math(operation=Math.Operation.MULTIPLY, value=(math(operation=Math.Operation.SUBTRACT, value=(a, b)), math(operation=Math.Operation.SINE, value=t))), + math( + operation=Math.Operation.MULTIPLY, + value=( + c, + math( + operation=Math.Operation.SINE, + value=math( + operation=Math.Operation.MULTIPLY, + value=(math(operation=Math.Operation.SUBTRACT, value=(math(operation=Math.Operation.DIVIDE, value=(a, b)), 1.0)), t), + ), + ), + ), + ), + ), + ) + arch_radius = math(operation=Math.Operation.ADD, value=(a, math(operation=Math.Operation.MULTIPLY, value=(b, t)))) + arch_x = math(operation=Math.Operation.MULTIPLY, value=(arch_radius, math(operation=Math.Operation.COSINE, value=t))) + arch_y = math(operation=Math.Operation.MULTIPLY, value=(arch_radius, math(operation=Math.Operation.SINE, value=t))) + + linebreak = special_characters().line_break + eq = _choose_string( + normalized_curve_type, + join_strings( + delimiter=linebreak, + strings=[ + string(string="y = ((a + b) * sin(t)) - (b * sin((a/b + 1) * t))"), + string(string="x = ((a + b) * cos(t)) - (b * cos((a/b + 1) * t))"), + string(string="Epicycloid"), + ], + ), + join_strings( + delimiter=linebreak, + strings=[ + string(string="y = ((a + b) * sin(t)) - (c * sin((a/b + 1) * t))"), + string(string="x = ((a + b) * cos(t)) - (c * cos((a/b + 1) * t))"), + string(string="Epitrochoid"), + ], + ), + join_strings( + delimiter=linebreak, + strings=[ + string(string="y = ((a - b) * sin(t)) + (b * sin((a/b - 1) * t))"), + string(string="x = ((a - b) * cos(t)) + (b * cos((a/b - 1) * t))"), + string(string="Hypocycloid"), + ], + ), + join_strings( + delimiter=linebreak, + strings=[ + string(string="y = ((a - b) * sin(t)) + (c * sin((a/b - 1) * t))"), + string(string="x = ((a - b) * cos(t)) + (c * cos((a/b - 1) * t))"), + string(string="Hypotrochoid"), + ], + ), + join_strings( + delimiter=linebreak, + strings=[ + string(string="r = a + b theta"), + string(string="Archimedes Spiral"), + ], + ), + ) + + return { + "x": _choose_float(normalized_curve_type, epi_x, epitrochoid_x, hypo_x, hypotrochoid_x, arch_x), + "y": _choose_float(normalized_curve_type, epi_y, epitrochoid_y, hypo_y, hypotrochoid_y, arch_y), + "eq": eq, + } + + @tree("VG Archimedes Spiral") def vg_archimedes_spiral( resolution: Int = 10, @@ -155,6 +417,60 @@ def vg_mirrored_root_spiral(a: Float = 0.30000001192092896, round_count: Float = return {"Geometry": join_geometry(geometry=[mirrored, forward])} +def _empty_curve_geometry(): + return mesh_line( + mode=MeshLine.Mode.OFFSET, + count_mode=MeshLine.CountMode.TOTAL, + count=0, + offset=(0.0, 0.0, 1.0), + ) + + +@tree("VG Param Curve") +def vg_param_curve( + curve_type: Int = 0, + a: Float = 0.800000011920929, + b: Float = 0.5, + c: Float = 1.0, + z: Float = 0.0, + max_t: Float = 32.5, + resolution: Float = 500.0, + showlabel: Bool = True, + thickness: Float = 0.009999999776482582, + curve_material: Material = None, + text_material: Material = None, +): + t = _accumulated_parameter(resolution=resolution, max_value=max_t) + x, y, equation = vg_param_xy(a=a, b=b, c=c, t=t, curve_type=curve_type) + + text_curve = string_to_curves( + string=equation, + size=2.0, + align_x="Center", + align_y="Middle", + pivot_point="Bottom Left", + ).curve_instances + label = transform_geometry( + geometry=fill_curve(curve=text_curve, mode="Triangles", fill_rule="Even-Odd").set_material(material=text_material), + translation=(0.0, 0.0, 0.30000001192092896), + ) + label_or_empty = switch(input_type=Switch.InputType.GEOMETRY, switch=showlabel, false=_empty_curve_geometry(), true=label) + + rail_seed = mesh_line( + mode=MeshLine.Mode.OFFSET, + count_mode=MeshLine.CountMode.TOTAL, + count=resolution, + start_location=(0.0, 0.0, 0.0), + offset=(0.0, 0.0, 1.0), + ) + rail = mesh_to_curve(mode=MeshToCurve.Mode.EDGES, mesh=rail_seed).set_position(position=combine_xyz(x=x, y=y, z=z)) + profile = curve_circle(mode=CurveCircle.Mode.RADIUS, resolution=32, radius=thickness) + radius_attribute = named_attribute(data_type=NamedAttribute.DataType.FLOAT, name="radius") + radius_scale = switch(input_type=Switch.InputType.FLOAT, switch=radius_attribute.exists, false=1.0, true=radius_attribute.attribute) + curve_mesh = rail.curve_to_mesh(profile_curve=profile, scale=radius_scale, fill_caps=False).set_material(material=curve_material) + return {"Geometry": join_geometry(geometry=[label_or_empty, curve_mesh])} + + def _finalize_groups(): import bpy @@ -164,9 +480,13 @@ def _finalize_groups(): "VG Param Epicycloid Y", "VG Polar Spiral X", "VG Polar Spiral Y", + "VG Choose Float Val", + "VG Choose Str Val", + "VG Param XY", "VG Archimedes Spiral", "VG Epicycloid", "VG Mirrored Root Spiral", + "VG Param Curve", ): group = bpy.data.node_groups.get(name) if group: diff --git a/examples/geometry_script/shriinivas_piechart.py b/examples/geometry_script/shriinivas_piechart.py index 302eecb..01caaf3 100644 --- a/examples/geometry_script/shriinivas_piechart.py +++ b/examples/geometry_script/shriinivas_piechart.py @@ -112,11 +112,256 @@ def vg_pie_chart( return join_geometry(geometry=[a_geometry, b_geometry, c_geometry]) +def _empty_geometry(): + return mesh_line( + mode=MeshLine.Mode.OFFSET, + count_mode=MeshLine.CountMode.TOTAL, + count=0, + offset=(0.0, 0.0, 1.0), + ) + + +@tree("VG Extended Pie Segment") +def vg_extended_pie_segment( + radius: Float = 0.0, + pie_height: Float = 0.0, + text_height: Float = 0.0, + text_size: Float = 0.0, + text_material: Material = None, + text_offset: Float = 0.0, + pie_material: Material = None, + include_percentage: Bool = True, + value: Float = 0.0, + total: Float = 0.0, + start_angle: Float = 0.0, + shift: Float = 0.0, + text: String = "", +): + fraction = math(operation=Math.Operation.DIVIDE, value=(value, total)) + sweep = math(operation=Math.Operation.MULTIPLY, value=(fraction, TAU)) + end_angle = math(operation=Math.Operation.ADD, value=(start_angle, sweep)) + mid_angle = math(operation=Math.Operation.ADD, value=(start_angle, math(operation=Math.Operation.DIVIDE, value=(sweep, 2.0)))) + + percentage = value_to_string( + data_type=ValueToString.DataType.FLOAT, + value=math(operation=Math.Operation.MULTIPLY, value=(fraction, 100.0)), + decimals=2, + ) + percentage_line = join_strings(delimiter="", strings=[string(string="%"), percentage]) + label_with_percentage = join_strings(delimiter=special_characters().line_break, strings=[percentage_line, text]) + label = switch(input_type=Switch.InputType.STRING, switch=include_percentage, false=text, true=label_with_percentage) + + shift_vector = combine_xyz( + x=math(operation=Math.Operation.MULTIPLY, value=(shift, math(operation=Math.Operation.COSINE, value=mid_angle))), + y=math(operation=Math.Operation.MULTIPLY, value=(shift, math(operation=Math.Operation.SINE, value=mid_angle))), + z=0.0, + ) + label_radius = math(operation=Math.Operation.MULTIPLY, value=(text_offset, radius)) + label_offset = vector_math( + operation=VectorMath.Operation.ADD, + vector=( + shift_vector, + combine_xyz( + x=math(operation=Math.Operation.MULTIPLY, value=(label_radius, math(operation=Math.Operation.COSINE, value=mid_angle))), + y=math(operation=Math.Operation.MULTIPLY, value=(label_radius, math(operation=Math.Operation.SINE, value=mid_angle))), + z=0.0, + ), + ), + ) + + text_curves = string_to_curves( + string=label, + size=text_size, + align_x="Center", + align_y="Middle", + pivot_point="Bottom Left", + ).curve_instances + text_face = fill_curve(curve=text_curves, mode="Triangles", fill_rule="Even-Odd") + placed_text = set_position(geometry=text_face.set_material(material=text_material), offset=label_offset) + extruded_text = extrude_mesh( + mode=ExtrudeMesh.Mode.FACES, + mesh=placed_text, + offset=combine_xyz(x=0.0, y=0.0, z=math(operation=Math.Operation.ADD, value=(text_height, pie_height))), + offset_scale=1.0, + individual=True, + ).mesh.set_material(material=text_material) + + arc_curve = arc( + mode=Arc.Mode.RADIUS, + resolution=64, + radius=radius, + start_angle=start_angle, + sweep_angle=sweep, + connect_center=True, + ) + shifted_arc = transform_geometry(geometry=arc_curve, translation=shift_vector) + pie_face = fill_curve(curve=shifted_arc, mode="Triangles", fill_rule="Even-Odd").set_material( + material=pie_material + ) + extruded_pie = extrude_mesh( + mode=ExtrudeMesh.Mode.FACES, + mesh=pie_face, + offset=combine_xyz(x=0.0, y=0.0, z=pie_height), + offset_scale=1.0, + individual=True, + ).mesh.set_material(material=pie_material) + + return {"End Angle": end_angle, "Pie": join_geometry(geometry=[extruded_text, extruded_pie, placed_text, pie_face])} + + +@tree("VG Extended Pie Chart") +def vg_extended_pie_chart( + title: String = "Extended Pie Chart", + title_size: Float = 0.20000000298023224, + title_material: Material = None, + title_offset: Float = 0.18000000715255737, + segment_count: Int = 10, + radius: Float = 1.0, + pie_height: Float = 0.10000000149011612, + text_height: Float = 0.004999999888241291, + text_size: Float = 0.07999999821186066, + text_material: Material = None, + text_offset: Float = 0.699999988079071, + include_percentage: Bool = True, + value_1: Float = 20.0, + label_1: String = "Lorem", + shift_1: Float = 0.20000000298023224, + material_1: Material = None, + value_2: Float = 30.0, + label_2: String = "Ipsum", + shift_2: Float = 0.0, + material_2: Material = None, + value_3: Float = 27.0, + label_3: String = "Dolor", + shift_3: Float = 0.0, + material_3: Material = None, + value_4: Float = 25.0, + label_4: String = "Sit", + shift_4: Float = 0.0, + material_4: Material = None, + value_5: Float = 55.0, + label_5: String = "Amet", + shift_5: Float = 0.0, + material_5: Material = None, + value_6: Float = 45.0, + label_6: String = "Consectetur", + shift_6: Float = 0.0, + material_6: Material = None, + value_7: Float = 25.0, + label_7: String = "Adipiscing", + shift_7: Float = 0.0, + material_7: Material = None, + value_8: Float = 35.0, + label_8: String = "Elit", + shift_8: Float = 0.0, + material_8: Material = None, + value_9: Float = 58.0, + label_9: String = "Sed", + shift_9: Float = 0.0, + material_9: Material = None, + value_10: Float = 32.0, + label_10: String = "Do", + shift_10: Float = 0.0, + material_10: Material = None, +): + values = [value_1, value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9, value_10] + labels = [label_1, label_2, label_3, label_4, label_5, label_6, label_7, label_8, label_9, label_10] + shifts = [shift_1, shift_2, shift_3, shift_4, shift_5, shift_6, shift_7, shift_8, shift_9, shift_10] + materials = [ + material_1, + material_2, + material_3, + material_4, + material_5, + material_6, + material_7, + material_8, + material_9, + material_10, + ] + + total = value_1 + for index, segment_value in enumerate(values[1:], start=2): + total = math( + operation=Math.Operation.ADD, + value=( + total, + switch( + input_type=Switch.InputType.FLOAT, + switch=math(operation=Math.Operation.GREATER_THAN, value=(segment_count, index - 1.0)), + false=0.0, + true=segment_value, + ), + ), + ) + + empty = _empty_geometry() + start_angle = 0.0 + segments = [] + for index, (segment_value, label, segment_shift, segment_material) in enumerate( + zip(values, labels, shifts, materials), + start=1, + ): + end_angle, segment_geometry = vg_extended_pie_segment( + radius=radius, + pie_height=pie_height, + text_height=text_height, + text_size=text_size, + text_material=text_material, + text_offset=text_offset, + pie_material=segment_material, + include_percentage=include_percentage, + value=segment_value, + total=total, + start_angle=start_angle, + shift=segment_shift, + text=label, + ) + if index == 1: + segments.append(segment_geometry) + else: + segments.append( + switch( + input_type=Switch.InputType.GEOMETRY, + switch=math(operation=Math.Operation.GREATER_THAN, value=(segment_count, index - 1.0)), + false=empty, + true=segment_geometry, + ) + ) + start_angle = end_angle + + title_curves = string_to_curves( + string=title, + size=title_size, + align_x="Center", + align_y="Middle", + pivot_point="Bottom Left", + ).curve_instances + title_face = fill_curve(curve=title_curves, mode="Triangles", fill_rule="Even-Odd") + title_position = combine_xyz( + x=0.0, + y=math( + operation=Math.Operation.SUBTRACT, + value=(math(operation=Math.Operation.MULTIPLY, value=(-1.0, math(operation=Math.Operation.ADD, value=(radius, title_size)))), title_offset), + ), + z=0.0, + ) + placed_title = transform_geometry(geometry=title_face, translation=title_position).set_material(material=title_material) + extruded_title = extrude_mesh( + mode=ExtrudeMesh.Mode.FACES, + mesh=placed_title, + offset=combine_xyz(x=0.0, y=0.0, z=text_height), + offset_scale=1.0, + individual=True, + ).mesh.set_material(material=title_material) + return {"Geometry": join_geometry(geometry=[*segments, placed_title, extruded_title])} + + def _finalize_groups(): import bpy groups = [] - for name in ("VG Pie Segment", "VG Pie Chart"): + for name in ("VG Pie Segment", "VG Pie Chart", "VG Extended Pie Segment", "VG Extended Pie Chart"): group = bpy.data.node_groups.get(name) if not group: continue diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 61f393c..a4f0604 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -37,7 +37,8 @@ from `cartesian.blend`. The completed pie chart translation is `docs/research/translations/shriinivas-piechart.md`. It covers `NodeGroup` and -`Pie Chart` from `piechart.blend`. +`Pie Chart`, plus the numbered `getPie.*` family and `Extended Pie Chart` from +`piechart.blend`. The completed field-value translation is `docs/research/translations/shriinivas-fieldvalue-digit-at.md`. It covers @@ -48,14 +49,13 @@ case with matching evaluated geometry. The completed parametric/polar translation is `docs/research/translations/shriinivas-paramnpolareq.md`. It covers scalar -equation helpers, `Archimedes Spiral`, `Epicycloid`, and a mirrored root spiral -from `paramnpolareq.blend`. +equation helpers, chooser groups, `getxy.001`, `Archimedes Spiral`, +`Epicycloid`, the main wrapper, and a mirrored root spiral from +`paramnpolareq.blend`. -The CurveToMeshUV utility sample has started at -`docs/research/translations/quellenform-curve-to-mesh-uv.md`. So far it covers -the small `Auto Smooth` helper from the quellenform file. The main -`Curve to Mesh UV` group is a 126-node utility quarry and should be staged into -subcontracts rather than translated as one heroic wall. +The completed CurveToMeshUV utility sample is +`docs/research/translations/quellenform-curve-to-mesh-uv.md`. It covers +`Auto Smooth`, `Curve to Mesh UV`, `_258246`, and `_Title`. `docs/research/procedural-doctrine.md` now stores the current spatial reasoning playbook for mapping geometric ideas to Geometry Script. Doctrine entries should @@ -82,11 +82,10 @@ The GameCult fork is intentionally pruned to `main` plus VibeGeometry-owned tooling branches. Upstream branch clutter should not be copied forward unless a future patch actually needs it. -The current next action is to continue the translation corpus with either the -main CurveToMeshUV utility staged into subcontracts or a scattering/instancing -sample. Keep `docs/research/procedural-doctrine.md` compact; put -sample-specific graph maps and verification details in -`docs/research/translations/`. +The current next action is to add a new source sample focused on scattering, +instancing, and attribute distribution. Keep +`docs/research/procedural-doctrine.md` compact; put sample-specific graph maps +and verification details in `docs/research/translations/`. ## Important Invariants diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 14f915d..f28c60c 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -24,3 +24,4 @@ {"ts": "2026-05-04T14:35:46+00:00", "type": "doctrine", "status": "accepted", "note": "Updated VibeGeometry priors: Python is the authoring and orchestration layer, Geometry Script is the inspectable node-graph emission surface, bpy handles Blender scene/render/evaluation machinery, and external Python tools handle inspection, converter drafts, verification, docs, and corpus evidence. Do not reason as if the Geometry Script DSL is the whole toolchain."} {"ts": "2026-05-04T14:54:04+00:00", "type": "implementation", "status": "ok", "note": "Completed and verified full VG Field Value translation, including Blender 5 capture-item helper and Geometry Script menu-socket default tolerance patch. Added and verified paramnpolareq translations for equation helpers, Archimedes spiral, epicycloid, and mirrored root spiral."} {"ts": "2026-05-04T14:59:36+00:00", "type": "implementation", "status": "ok", "note": "Started CurveToMeshUV utility sample by translating and verifying Auto Smooth; main Curve to Mesh UV remains a staged utility-quarry target rather than a one-pass translation."} +{"ts": "2026-05-04T15:57:11+00:00", "type": "implementation", "status": "ok", "note": "Finished remaining local sample graph families: extended pie clones/compositor, param/polar selector and wrapper, and full CurveToMeshUV utility/demo/title with mesh, UV-field, and caps-mask harness verification."} diff --git a/state/map.yaml b/state/map.yaml index a8d6b28..25a4efd 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -91,8 +91,8 @@ 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 inspected Shriinivas cartesian, pie chart, field-value full display, parametric/polar equation graphs, and the first CurveToMeshUV utility helper. The repo-local Geometry Script fork includes a Blender 5.1 nodes_to_script converter port plus nested-group and menu-socket fixes needed by these translations. - next_action: Continue the translation corpus with the main CurveToMeshUV utility staged into subcontracts, or pivot to a scattering/instancing sample; keep doctrine compact and put graph-specific autopsies under `docs/research/translations/`. + summary: VibeGeometry has an initial persistence scaffold plus verified Geometry Script translations for all currently inspected local sample graph families: Shriinivas cartesian, pie chart including extended clones, field-value full display, parametric/polar selectors and wrappers, plus CurveToMeshUV utility/demo/title graphs. The repo-local Geometry Script fork includes a Blender 5.1 nodes_to_script converter port plus nested-group and menu-socket fixes needed by these translations. + next_action: Add a new source sample focused on scattering/instancing and attribute distribution; keep doctrine compact and put graph-specific autopsies under `docs/research/translations/`. remotes: vibegeometry: https://github.com/GameCult/VibeGeometry geometry_script_fork: https://github.com/GameCult/geometry-script diff --git a/tools/verify_curve_to_mesh_uv_translations.py b/tools/verify_curve_to_mesh_uv_translations.py index 9dfcf8a..0d93290 100644 --- a/tools/verify_curve_to_mesh_uv_translations.py +++ b/tools/verify_curve_to_mesh_uv_translations.py @@ -14,6 +14,23 @@ import bpy ROOT = Path(__file__).resolve().parents[1] TRANSLATION = ROOT / "examples" / "geometry_script" / "quellenform_curve_to_mesh_uv.py" AUTO_SMOOTH_CASE = {"Angle": 0.75} +CURVE_TO_MESH_UV_CASE = { + "Fill Caps": True, + "• Lock Caps UV-Scaling": False, + "Hole Tolerant": False, + "• Smooth Angle": 3.1415927410125732, + "Free U-Space": False, + "• Lock U-Scaling": False, + "Free V-Space": False, + "• Lock V-Scaling": False, + "Sides UV Scale": (1.0, 1.0, 0.0), + "Sides UV Offset": (0.0, 0.0, 0.0), + "Sides UV Z-Rotation": 0.0, + "Caps UV Scale": (1.0, 1.0, 0.0), + "Caps UV Offset": (0.0, 0.0, 0.0), + "Caps UV Z-Rotation": 0.0, + "Store Attributes": False, +} def _load_translation() -> None: @@ -62,6 +79,76 @@ def _build_auto_smooth_wrapper(name: str, source_group: bpy.types.GeometryNodeTr return wrapper +def _normalized_key(name: str) -> str: + return name.lower().replace(" ", "").replace("•", "").replace("-", "") + + +def _set_inputs(group_node: bpy.types.GeometryNode, inputs: dict[str, object]): + normalized = {_normalized_key(key): value for key, value in inputs.items()} + for socket in group_node.inputs: + key = _normalized_key(socket.name) + if socket.name in inputs: + socket.default_value = inputs[socket.name] + elif key in normalized: + socket.default_value = normalized[key] + + +def _build_curve_to_mesh_uv_wrapper( + name: str, + source_group: bpy.types.GeometryNodeTree, + inputs: dict[str, object], + output_mode: str = "mesh", +): + wrapper = _new_geometry_group(name) + nodes = wrapper.nodes + links = wrapper.links + + curve = nodes.new("GeometryNodeCurvePrimitiveCircle") + curve.mode = "RADIUS" + _socket_by_name(curve.inputs, "Resolution").default_value = 24 + _socket_by_name(curve.inputs, "Radius").default_value = 1.2 + + profile = nodes.new("GeometryNodeCurvePrimitiveCircle") + profile.mode = "RADIUS" + _socket_by_name(profile.inputs, "Resolution").default_value = 8 + _socket_by_name(profile.inputs, "Radius").default_value = 0.2 + + group_node = nodes.new("GeometryNodeGroup") + group_node.node_tree = source_group + links.new(_socket_by_name(curve.outputs, "Curve"), _socket_by_name(group_node.inputs, "Curve")) + links.new(_socket_by_name(profile.outputs, "Curve"), _socket_by_name(group_node.inputs, "Profile Curve")) + _set_inputs(group_node, inputs) + + output_geometry = _socket_by_name(group_node.outputs, "Mesh") + if output_mode == "uv": + set_position = nodes.new("GeometryNodeSetPosition") + links.new(_socket_by_name(group_node.outputs, "Mesh"), _socket_by_name(set_position.inputs, "Geometry")) + links.new(_socket_by_name(group_node.outputs, "UV Map"), _socket_by_name(set_position.inputs, "Position")) + output_geometry = _socket_by_name(set_position.outputs, "Geometry") + elif output_mode == "caps": + delete = nodes.new("GeometryNodeDeleteGeometry") + delete.mode = "ALL" + delete.domain = "FACE" + links.new(_socket_by_name(group_node.outputs, "Mesh"), _socket_by_name(delete.inputs, "Geometry")) + links.new(_socket_by_name(group_node.outputs, "Caps Mask"), _socket_by_name(delete.inputs, "Selection")) + output_geometry = _socket_by_name(delete.outputs, "Geometry") + + group_output = nodes.new("NodeGroupOutput") + links.new(output_geometry, _socket_by_name(group_output.inputs, "Geometry")) + return wrapper + + +def _build_no_input_geometry_wrapper(name: str, source_group: bpy.types.GeometryNodeTree): + wrapper = _new_geometry_group(name) + nodes = wrapper.nodes + links = wrapper.links + group_node = nodes.new("GeometryNodeGroup") + group_node.node_tree = source_group + group_output = nodes.new("NodeGroupOutput") + links.new(_socket_by_name(group_node.outputs, "Geometry"), _socket_by_name(group_output.inputs, "Geometry")) + return wrapper + + def _evaluated_mesh_summary(group: bpy.types.GeometryNodeTree): mesh = bpy.data.meshes.new(group.name + " Input Mesh") obj = bpy.data.objects.new(group.name + " Object", mesh) @@ -94,7 +181,7 @@ def main() -> int: (math.dist(a, b) for a, b in zip(sorted(source["vertices"]), sorted(translated["vertices"]))), default=0.0, ) - result = { + auto_smooth_result = { "case": "auto_smooth_cube", "source_vertex_count": len(source["vertices"]), "translated_vertex_count": len(translated["vertices"]), @@ -102,14 +189,66 @@ def main() -> int: "source_smooth_faces": sum(source["polygon_smooth"]), "translated_smooth_faces": sum(translated["polygon_smooth"]), } - result["ok"] = ( - result["source_vertex_count"] == result["translated_vertex_count"] + auto_smooth_result["ok"] = ( + auto_smooth_result["source_vertex_count"] == auto_smooth_result["translated_vertex_count"] and max_delta <= 1e-6 and source["polygon_smooth"] == translated["polygon_smooth"] ) - payload = {"ok": result["ok"], "results": [result]} + results = [auto_smooth_result] + for mode in ("mesh", "uv", "caps"): + source_uv = _evaluated_mesh_summary( + _build_curve_to_mesh_uv_wrapper( + f"VG Verify Source Curve To Mesh UV {mode}", + bpy.data.node_groups["Curve to Mesh UV"], + CURVE_TO_MESH_UV_CASE, + output_mode=mode, + ) + ) + translated_uv = _evaluated_mesh_summary( + _build_curve_to_mesh_uv_wrapper( + f"VG Verify Translated Curve To Mesh UV {mode}", + bpy.data.node_groups["VG Curve To Mesh UV"], + CURVE_TO_MESH_UV_CASE, + output_mode=mode, + ) + ) + uv_delta = max( + (math.dist(a, b) for a, b in zip(sorted(source_uv["vertices"]), sorted(translated_uv["vertices"]))), + default=0.0, + ) + uv_result = { + "case": f"curve_to_mesh_uv_{mode}", + "source_vertex_count": len(source_uv["vertices"]), + "translated_vertex_count": len(translated_uv["vertices"]), + "max_sorted_vertex_delta": uv_delta, + } + uv_result["ok"] = uv_result["source_vertex_count"] == uv_result["translated_vertex_count"] and uv_delta <= 1e-6 + results.append(uv_result) + for case, source_name, translated_name in ( + ("curve_to_mesh_uv_demo", "_258246", "VG Curve To Mesh UV Demo"), + ("curve_to_mesh_uv_title", "_Title", "VG Curve To Mesh UV Title"), + ): + source_demo = _evaluated_mesh_summary(_build_no_input_geometry_wrapper(f"VG Verify Source {case}", bpy.data.node_groups[source_name])) + translated_demo = _evaluated_mesh_summary( + _build_no_input_geometry_wrapper(f"VG Verify Translated {case}", bpy.data.node_groups[translated_name]) + ) + demo_delta = max( + (math.dist(a, b) for a, b in zip(sorted(source_demo["vertices"]), sorted(translated_demo["vertices"]))), + default=0.0, + ) + demo_result = { + "case": case, + "source_vertex_count": len(source_demo["vertices"]), + "translated_vertex_count": len(translated_demo["vertices"]), + "max_sorted_vertex_delta": demo_delta, + } + demo_result["ok"] = ( + demo_result["source_vertex_count"] == demo_result["translated_vertex_count"] and demo_delta <= 1e-6 + ) + results.append(demo_result) + payload = {"ok": all(result["ok"] for result in results), "results": results} print("VG_CURVE_TO_MESH_UV_TRANSLATION_BEHAVIOR " + json.dumps(payload, sort_keys=True)) - return 0 if result["ok"] else 1 + return 0 if payload["ok"] else 1 if __name__ == "__main__": diff --git a/tools/verify_paramnpolareq_translations.py b/tools/verify_paramnpolareq_translations.py index 48c4e99..6ba6954 100644 --- a/tools/verify_paramnpolareq_translations.py +++ b/tools/verify_paramnpolareq_translations.py @@ -18,6 +18,17 @@ SCALAR_CASE = {"a": 0.8, "b": 0.35, "t": 1.25, "theta": 1.25} ARCHIMEDES_CASE = {"Resolution": 64, "No of Rounds": 2.5, "a": 0.25, "b": 0.15} EPICYCLOID_CASE = {"Resolution": 80, "maxT": 12.0, "a": 0.8, "b": 0.3} ROOT_SPIRAL_CASE = {"a": 0.2, "Round Count": 4.0, "Resolution": 96.0} +PARAM_CURVE_CASE = { + "Curve Type": 3, + "a": 0.8, + "b": 0.5, + "c": 1.0, + "z": 0.125, + "maxT": 12.0, + "Resolution": 64.0, + "showlabel": False, + "thickness": 0.01, +} def _load_translation() -> None: @@ -84,6 +95,41 @@ def _build_scalar_position_wrapper(name: str, source_group: bpy.types.GeometryNo return wrapper +def _build_xy_position_wrapper(name: str, source_group: bpy.types.GeometryNodeTree, inputs: dict[str, object]): + wrapper = _new_geometry_group(name) + nodes = wrapper.nodes + links = wrapper.links + group_node = nodes.new("GeometryNodeGroup") + group_node.node_tree = source_group + lower_inputs = {key.lower(): value for key, value in inputs.items()} + normalized_inputs = {_normalized_key(key): value for key, value in inputs.items()} + for socket in group_node.inputs: + if socket.name in inputs: + socket.default_value = inputs[socket.name] + elif socket.name.lower() in lower_inputs: + socket.default_value = lower_inputs[socket.name.lower()] + elif _normalized_key(socket.name) in normalized_inputs: + socket.default_value = normalized_inputs[_normalized_key(socket.name)] + + line = nodes.new("GeometryNodeMeshLine") + line.mode = "OFFSET" + line.count_mode = "TOTAL" + _socket_by_name(line.inputs, "Count").default_value = 1 + _socket_by_name(line.inputs, "Offset").default_value = (1.0, 0.0, 0.0) + + vector = nodes.new("ShaderNodeCombineXYZ") + links.new(_socket_by_name(group_node.outputs, "x"), _socket_by_name(vector.inputs, "X")) + links.new(_socket_by_name(group_node.outputs, "y"), _socket_by_name(vector.inputs, "Y")) + + set_position_node = nodes.new("GeometryNodeSetPosition") + links.new(_socket_by_name(line.outputs, "Mesh"), _socket_by_name(set_position_node.inputs, "Geometry")) + links.new(_socket_by_name(vector.outputs, "Vector"), _socket_by_name(set_position_node.inputs, "Position")) + + group_output = nodes.new("NodeGroupOutput") + links.new(_socket_by_name(set_position_node.outputs, "Geometry"), _socket_by_name(group_output.inputs, "Geometry")) + return wrapper + + def _build_geometry_wrapper(name: str, source_group: bpy.types.GeometryNodeTree, inputs: dict[str, object]): wrapper = _new_geometry_group(name) nodes = wrapper.nodes @@ -172,6 +218,28 @@ def main() -> int: results.append(_compare_vertices("archimedes_spiral", "Archimedes Spiral", "VG Archimedes Spiral", ARCHIMEDES_CASE)) results.append(_compare_vertices("epicycloid", "Epicycloid", "VG Epicycloid", EPICYCLOID_CASE)) results.append(_compare_vertices("mirrored_root_spiral", "Geometry Nodes Group.002", "VG Mirrored Root Spiral", ROOT_SPIRAL_CASE)) + for curve_type in range(5): + inputs = {"a": 0.8, "b": 0.35, "c": 1.1, "t": 1.25, "Curve Type": curve_type} + source_vertices = _evaluated_vertices( + _build_xy_position_wrapper(f"VG Verify Source Param XY {curve_type}", bpy.data.node_groups["getxy.001"], inputs) + ) + translated_vertices = _evaluated_vertices( + _build_xy_position_wrapper(f"VG Verify Translated Param XY {curve_type}", bpy.data.node_groups["VG Param XY"], inputs) + ) + max_delta = max( + (math.dist(a, b) for a, b in zip(sorted(source_vertices), sorted(translated_vertices))), + default=0.0, + ) + results.append( + { + "case": {"param_xy_curve_type": curve_type}, + "source_vertex": source_vertices[0] if source_vertices else None, + "translated_vertex": translated_vertices[0] if translated_vertices else None, + "max_sorted_vertex_delta": max_delta, + "ok": len(source_vertices) == len(translated_vertices) and max_delta <= 1e-6, + } + ) + results.append(_compare_vertices("param_curve_wrapper", "Geometry Nodes Group", "VG Param Curve", PARAM_CURVE_CASE)) ok = all(result["ok"] for result in results) print("VG_PARAMNPOLAREQ_TRANSLATION_BEHAVIOR " + json.dumps({"ok": ok, "results": results}, sort_keys=True)) diff --git a/tools/verify_piechart_translations.py b/tools/verify_piechart_translations.py index 270774f..c62130c 100644 --- a/tools/verify_piechart_translations.py +++ b/tools/verify_piechart_translations.py @@ -44,11 +44,14 @@ def _new_geometry_group(name: str) -> bpy.types.GeometryNodeTree: def _set_inputs(group_node: bpy.types.GeometryNode, values: dict[str, object]) -> None: lower_values = {name.lower(): value for name, value in values.items()} + normalized_values = {name.lower().replace(" ", ""): value for name, value in values.items()} for socket in group_node.inputs: if socket.name in values: socket.default_value = values[socket.name] elif socket.name.lower() in lower_values: socket.default_value = lower_values[socket.name.lower()] + elif socket.name.lower().replace(" ", "") in normalized_values: + socket.default_value = normalized_values[socket.name.lower().replace(" ", "")] def _build_segment_wrapper(name: str, group: bpy.types.GeometryNodeTree, inputs: dict[str, object]): @@ -78,6 +81,18 @@ def _build_chart_wrapper(name: str, group: bpy.types.GeometryNodeTree, inputs: d return wrapper +def _build_extended_segment_wrapper(name: str, group: bpy.types.GeometryNodeTree, inputs: dict[str, object]): + wrapper = _new_geometry_group(name) + nodes = wrapper.nodes + links = wrapper.links + group_node = nodes.new("GeometryNodeGroup") + group_node.node_tree = group + _set_inputs(group_node, inputs) + group_output = nodes.new("NodeGroupOutput") + links.new(_socket_by_name(group_node.outputs, "Pie"), _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) @@ -131,6 +146,10 @@ def main() -> int: mat1 = bpy.data.materials.get("Material 1") or bpy.data.materials.new("Material 1") mat2 = bpy.data.materials.get("Material 2") or bpy.data.materials.new("Material 2") mat3 = bpy.data.materials.get("Material 3") or bpy.data.materials.new("Material 3") + materials = { + f"Material {index}": bpy.data.materials.get(f"Material {index}") or bpy.data.materials.new(f"Material {index}") + for index in range(1, 11) + } segment_inputs = { "Start": 0.35, @@ -152,6 +171,67 @@ def main() -> int: "C Material": mat3, "Text Material": text_material, } + extended_segment_inputs = { + "Radius": 1.0, + "Pie Height": 0.1, + "Text Height": 0.005, + "Text Size": 0.08, + "Text Material": text_material, + "Text Offset": 0.7, + "Pie Material": mat1, + "Include Percentage": True, + "Value": 20.0, + "Total": 120.0, + "Start Angle": 0.25, + "Shift": 0.15, + "Text": "Lorem", + } + extended_chart_inputs = { + "Title": "Extended Pie Chart", + "Title Size": 0.2, + "Title Material": mat2, + "Title Offset": 0.18, + "Segment Count": 10, + "Radius": 1.0, + "Pie Height": 0.1, + "Text Height": 0.005, + "Text Size": 0.08, + "Text Material": text_material, + "Text Offset": 0.7, + "Include Percentage": True, + "Value 1": 20.0, + "Label 1": "Lorem", + "Shift 1": 0.2, + "Value 2": 30.0, + "Label 2": "Ipsum", + "Shift 2": 0.0, + "Value 3": 27.0, + "Label 3": "Dolor", + "Shift 3": 0.0, + "Value 4": 25.0, + "Label 4": "Sit", + "Shift 4": 0.0, + "Value 5": 55.0, + "Label 5": "Amet", + "Shift 5": 0.0, + "Value 6": 45.0, + "Label 6": "Consectetur", + "Shift 6": 0.0, + "Value 7": 25.0, + "Label 7": "Adipiscing", + "Shift 7": 0.0, + "Value 8": 35.0, + "Label 8": "Elit", + "Shift 8": 0.0, + "Value 9": 58.0, + "Label 9": "Sed", + "Shift 9": 0.0, + "Value 10": 32.0, + "Label 10": "Do", + "Shift 10": 0.0, + } + for index in range(1, 11): + extended_chart_inputs[f"Material {index}"] = materials[f"Material {index}"] cases = [ ( @@ -164,6 +244,24 @@ def main() -> int: _build_chart_wrapper("VG Verify Source Pie Chart", bpy.data.node_groups["Pie Chart"], chart_inputs), _build_chart_wrapper("VG Verify Translated Pie Chart", bpy.data.node_groups["VG Pie Chart"], chart_inputs), ), + ( + "extended_segment", + _build_extended_segment_wrapper("VG Verify Source Extended Segment", bpy.data.node_groups["getPie.012"], extended_segment_inputs), + _build_extended_segment_wrapper( + "VG Verify Translated Extended Segment", + bpy.data.node_groups["VG Extended Pie Segment"], + extended_segment_inputs, + ), + ), + ( + "extended_chart", + _build_chart_wrapper("VG Verify Source Extended Pie Chart", bpy.data.node_groups["Extended Pie Chart"], extended_chart_inputs), + _build_chart_wrapper( + "VG Verify Translated Extended Pie Chart", + bpy.data.node_groups["VG Extended Pie Chart"], + extended_chart_inputs, + ), + ), ] results = [_compare(case, _evaluated_vertices(source), _evaluated_vertices(translated)) for case, source, translated in cases] ok = all(result["ok"] for result in results)