Page MenuHome

Geometry Nodes: Curve and mesh topology access nodes
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Sep 21 2022, 5:23 AM.
Tokens
"Like" token, awarded by duarteframos."Cup of Joe" token, awarded by Bit."Mountain of Wealth" token, awarded by Moder."Love" token, awarded by silex."Love" token, awarded by cmermoud."Love" token, awarded by dreamak.

Details

Summary

This patch contains an initial set of nodes to access basic
mesh topology information, as explored in T100020.

The nodes allow five direct topology mappings for meshes:

  • Corner -> Face Which face the corner is part of, and its index in the face
  • Vertex -> Edge Choose an edge attached to the vertex
  • Vertex -> Corner Choose a corner attached to the vertex
  • Corner -> Edge The next and previous edge at each face corner
  • Corner -> Vertex The vertex associated with a corner
  • Corner -> Corner Offset a corner index within a face

And two new topology mappings for curves:

  • Curve -> Points Choose a point within a curve
  • Point -> Curve Find which curve a point is part of

The idea is that some of the 16 possible mesh mappings are more
important, and that this is a useful set of nodes to start exploring this area.

For mappings with an arbitrary number of connections, we generally
have to sort them and use an index to choose a single element, because
geometry nodes does not support list fields. There are performance benefits
to doing it this way too.

Currently which of the "start" elements is used is determined by the field
context, so the "Field at Index" and "Interpolate Domain" nodes will be quite
important. Also, currently the "Sort Index" inputs are clamped to the number
of connections.

Todo after initial commit:

  • Rename "Control Point Neighbors" node to be consistent with the naming here
  • Version away the "Vertex Neighbors" node which is fully redundant now
  • Implement a special case for when no weights are used for performance
  • Experiment with de-duplicating some of the sorting logic between the nodes
  • Improve performance and memory use of topology mappings
  • Look into caching some of the mappings on meshes

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Sep 21 2022, 5:23 AM
Hans Goudey (HooglyBoogly) created this revision.
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
  • Add index inputs
  • Various fixes and cleanups

Set Sort Index to anything higher than 3 -> Crash

Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
  • Fix typo and logic in "Corners of Vertex" node
  • Add "Vertex of Corner" node

Thanks for testing @Miro Horváth (dreamak), that node should be fixed now.

Hans Goudey (HooglyBoogly) retitled this revision from Geometry Nodes: Mesh topology access nodes (WIP) to Geometry Nodes: Mesh topology access nodes.Sep 23 2022, 10:30 PM

The fact that the Total output is contained in nodes means that for variable size data, you will have to duplicate nodes in order to have a quantity in the first place.
Also, if the mesh cannot be entered, then this data will be relevant only for itself. I think until it is somehow decided, but still I don’t remember.

Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
  • Add the two curve inputs from the design task
  • Move the curve topology inputs to a separate submenu
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
  • Rename "Corner Neighbors" to "Offset Corner in Face"
release/scripts/startup/bl_ui/node_add_menu_geometry.py
248

typo In

source/blender/blenkernel/BKE_mesh_mapping.h
341 ↗(On Diff #56226)

This sounds like a variable name, not like a function name.

source/blender/blenkernel/intern/mesh_mapping.cc
573 ↗(On Diff #56226)

I do wonder whether it would be better to use a two pass algorithm that first counts the number of edges per vert. That can be optimized separately though :)

source/blender/functions/FN_field.hh
491 ↗(On Diff #56226)

This name is very misleading imo. Sounds like it makes sure that values in the field will be <= 0.

source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
33

Looks like a copy-paste error (CornersOfFaceInput)

source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc
92

Wouldn't mind a short comment here for what that is doing.

93

Guess the optimization here would be to just skip all of that when the weights are a single value?

97

passing negative indices into the node has wrong behavior. May want to use mod_i.

Hans Goudey (HooglyBoogly) marked 7 inline comments as done.Sep 28 2022, 5:50 PM
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/blenkernel/BKE_mesh_mapping.h
341 ↗(On Diff #56226)

To me the namespace in front makes it clear, but I added build_ in front.

source/blender/blenkernel/intern/mesh_mapping.cc
573 ↗(On Diff #56226)

Yes, definitely. But I want to refactor this more to avoid using an array of vectors. Now that it's in a central place I feel better doing that.

source/blender/functions/FN_field.hh
491 ↗(On Diff #56226)

Good point. I renamed it to clamp_above_zero.

source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_face.cc
93

Yeah, I figured I would work on that separately though

Hans Goudey (HooglyBoogly) marked 3 inline comments as done.
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)
  • Use mod_i
  • Add comment for sorting
  • Add "build_" to mesh topology functions
  • Fix copy and paste mistake in points of curve node
  • Fix alphabetical sorting
  • Fix typo in node id name
Hans Goudey (HooglyBoogly) retitled this revision from Geometry Nodes: Mesh topology access nodes to Geometry Nodes: Curve and mesh topology access nodes.

Merge master

Fix input and output retrieval in curve of point node

source/blender/nodes/geometry/nodes/node_geo_curve_topology_curve_of_point.cc
94

unnecessary newline

95

That doesn't look like it has been tested (the name is wrong). Same below.

source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
156

Any reason why you have this intermediate variable here but not below? I'd be fine with skipping the intermediate value in both cases. Debugging these intermediate values is rarely useful.

source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
32

Don't do that, because attributes() may return none.

Hans Goudey (HooglyBoogly) marked 4 inline comments as done.
  • Fix potential use of optional attribute accessor
  • Remove intermediate values when building fields
  • Cleanup: Whitespace
source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
156

No, I'm mostly doing that to make the formatting/line wrapping look better. I'll remove this one though (and maybe a couple others)

source/blender/nodes/geometry/nodes/node_geo_field_at_index.cc
32

This is all copied, but I'll fix it here.

  • Remove "clamp_above_zero"
  • Fix potential use after move

Code generally seems fine. Didn't test it all myself yet. I expect you to test the output of every socket (also when the context is some unsupported geometry type like a volume).

  • Offsets and sort indices should have repeating behavior (so that e.g. -1 refers to the last element).
This revision is now accepted and ready to land.Sep 28 2022, 6:50 PM