Page MenuHome

Geometry Nodes: Proof of concept lazy conversion to and from BMesh
AbandonedPublic

Authored by Hans Goudey (HooglyBoogly) on Aug 9 2021, 7:56 PM.

Details

Summary

Often there will be multiple nodes using BMesh in a row. Currently we
convert from Mesh to BMesh and then BMesh to Mesh for every node.

This patch would allow only converting back to Mesh when necessary, i.e.
when using the attribute API or outputting the result from the modifier.
Theoretically the lazy conversion could be used over multiple modifiers
in the future.

The benefit of this approach is that the lazy conversion happens in both
directions, not just Mesh to BMesh, and that it's at the MeshComponent
level, which simplifies using it, because a node can simply use get_bmesh_for_write().
Another benefit is that it consolidates the boilerplate code from the conversions,
which is quite annoying to write.

I've noticed that the geometry nodes logger gets a list of attributes for every node
in GeometryValueLog which means that currently this patch will only have a benefit
when logging is turned off. I think we should turn off this attribute value logging
for nodes that won't show an attribute list (which should be much simpler in the future
when only a few nodes will have the attribute dropdown!)

Diff Detail

Repository
rB Blender
Branch
geometry-nodes-lazy-bmesh-conversion (branched from master)
Build Status
Buildable 16370
Build 16370: arc lint + arc unit

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Aug 9 2021, 7:56 PM
Hans Goudey (HooglyBoogly) created this revision.
  • Support BMesh in attribute_domain_size
source/blender/nodes/geometry/nodes/node_geo_material_assign.cc
88

I moved this here because the Ico sphere primitive now outputs a BMesh. Doesn't it make more sense here anyway? Or did we need that because of object material overrides? I forget already.

source/blender/blenkernel/intern/geometry_component_mesh.cc
102

Should this create an empty mesh if there is none?

255

Does this function still work correctly when there is only a bmesh?

Hans Goudey (HooglyBoogly) marked 2 inline comments as done.
  • Various cleanups, rename variables, add has_bmesh(), add comments
source/blender/blenkernel/intern/geometry_component_mesh.cc
102

No, I don't think so, because the component is allowed to return a null mesh currently, and often does. I don't really think we should change that.

I can see why the name doesn't really fit with that behavior though, since it's called "ensure". I renamed it to "ensure_mesh_from_bmesh" to be more clear.

255

Good catch, added a this->ensure_mesh_from_bmesh(); call to fix that.

Hans Goudey (HooglyBoogly) planned changes to this revision.Dec 15 2021, 5:25 AM

I'll need to update this to latest master now.

Hans Goudey (HooglyBoogly) abandoned this revision.EditedFeb 4 2022, 10:19 PM

Actually, I don't think we should be making it easier to use BMesh for procedural operations, but rather implementing them with Mesh. At least for now.