diff options
author | Hans Goudey <h.goudey@me.com> | 2021-02-12 20:58:15 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-02-12 20:58:15 +0300 |
commit | a4baedea91196176cb07d15a4d8acfab52cf9f83 (patch) | |
tree | 5d0d7c06fdab146a1abc3495a882bd8ef3b68463 /source/blender/blenkernel/BKE_geometry_set.hh | |
parent | ff3df2ea568f6f55cdee74ce6ed5586c15af2062 (diff) |
Geometry Nodes: Make instances real on-demand
This commit makes the geometry output of the collection info usable.
The output is the geometry of a collection instance, but this commit
adds a utility to convert the instances to real geometry, used in the
background whenever it is needed, like copy on write.
The recursive nature of the "realize instances" code is essential,
because collection instances in the `InstancesComponent`, might have no
geometry sets of their own containing even more collection instances,
which might then contain object instances, etc.
Another consideration is that currently, every single instance contains
a reference to its data. This is inefficient since most of the time
there are many locations and only a few sets of unique data. So this
commit adds a `GeometryInstanceGroup` to support this future optimization.
The API for instances returns a vector of `GeometryInstanceGroup`.
This may be less efficient when there are many instances, but it makes
more complicated operations like point distribution that need to iterate
over input geometry multiple times much simpler.
Any code that needs to change data, like most of the attribute nodes,
can simply call `geometry_set_realize_instances(geometry_set)`,
which will move any geometry in the `InstancesComponent` to new "real"
geometry components.
Many nodes can support read-only access to instances in order to avoid
making them real, this will be addressed where needed in the near future.
Instances from the existing "dupli" system are not supported yet.
Differential Revision: https://developer.blender.org/D10327
Diffstat (limited to 'source/blender/blenkernel/BKE_geometry_set.hh')
-rw-r--r-- | source/blender/blenkernel/BKE_geometry_set.hh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh index 02b3c88183a..5b429a61b3f 100644 --- a/source/blender/blenkernel/BKE_geometry_set.hh +++ b/source/blender/blenkernel/BKE_geometry_set.hh @@ -467,3 +467,25 @@ class VolumeComponent : public GeometryComponent { static constexpr inline GeometryComponentType static_type = GeometryComponentType::Volume; }; + +/** + * Used to keep track of a group of instances using the same geometry data. + */ +struct GeometryInstanceGroup { + /** + * The geometry set instanced on each of the transforms. The components are not necessarily + * owned here. For example, they may be owned by the instanced object. This cannot be a + * reference because not all instanced data will necessarily have a #geometry_set_eval. + */ + GeometrySet geometry_set; + + /** + * As an optimization to avoid copying, the same geometry set can be associated with multiple + * instances. Each instance is stored as a transform matrix here. Again, these must be owned + * because they may be transformed from the original data. TODO: Validate that last statement. + */ + blender::Vector<blender::float4x4> transforms; +}; + +blender::Vector<GeometryInstanceGroup> BKE_geometry_set_gather_instances( + const GeometrySet &geometry_set); |