diff options
author | Hans Goudey <h.goudey@me.com> | 2021-10-14 20:43:36 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-10-14 20:43:36 +0300 |
commit | 89c7c115cebb2ac0aaaeb98eb95decc7b5a129c8 (patch) | |
tree | 607efee3ecf0bd2d19f83b427a632590298d7f2f /source/blender/blenkernel/BKE_geometry_set.hh | |
parent | cddda706188a9ebb14ddbfbed5651f321ef31522 (diff) |
Geometry Nodes: Create empty components less often
Avoiding creating empty components can be a hassle for code that
interacts with a geometry set. One easy way to do that was calling
the functions that retrieved mutable access to geometry data directly,
like get_mesh_for_write. This commit makes it so that sort of direct
function does not create an empty component if there is no data.
Another way to create an empty component was calling the replace_*
methods with a null pointer. It's more convenient to have a nice API
that handles those cases without creating an empty component.
It's still convenient that the regular get_component_for_write adds
the component if it doesn't exist, because that's often a nice way to
add data to the geometry set.
Differential Revision: https://developer.blender.org/D12862
Diffstat (limited to 'source/blender/blenkernel/BKE_geometry_set.hh')
-rw-r--r-- | source/blender/blenkernel/BKE_geometry_set.hh | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index b36d15578a7..66466e3972e 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -357,6 +357,15 @@ struct GeometrySet { GeometryOwnershipType ownership = GeometryOwnershipType::Owned); void replace_curve(CurveEval *curve, GeometryOwnershipType ownership = GeometryOwnershipType::Owned); + + private: + /* Utility to retrieve a mutable component without creating it. */ + GeometryComponent *get_component_ptr(GeometryComponentType type); + template<typename Component> Component *get_component_ptr() + { + BLI_STATIC_ASSERT(is_geometry_component_v<Component>, ""); + return static_cast<Component *>(get_component_ptr(Component::static_type)); + } }; /** A geometry component that can store a mesh. */ |