[Bf-blender-cvs] [a83abdd155e] temp-geometry-nodes-instances-api-v2: Remove callback instances API to focus on other approach
Hans Goudey
noreply at git.blender.org
Sun Feb 7 05:54:16 CET 2021
Commit: a83abdd155ebcd8e9a918c406bab4938faff48a1
Author: Hans Goudey
Date: Sat Feb 6 22:54:06 2021 -0600
Branches: temp-geometry-nodes-instances-api-v2
https://developer.blender.org/rBa83abdd155ebcd8e9a918c406bab4938faff48a1
Remove callback instances API to focus on other approach
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/intern/geometry_set.cc
M source/blender/nodes/geometry/node_geometry_util.cc
M source/blender/nodes/geometry/node_geometry_util.hh
M source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
M source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
M source/blender/nodes/geometry/nodes/node_geo_point_separate.cc
M source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index ffc632d55f9..e8e91cebd73 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -477,16 +477,10 @@ class VolumeComponent : public GeometryComponent {
static constexpr inline GeometryComponentType static_type = GeometryComponentType::Volume;
};
-using ForeachGeometryCallbackConst = std::function<void(
- const GeometryComponent &component, blender::Span<blender::float4x4> transforms)>;
-
-void BKE_geometry_set_foreach_component_recursive(const GeometrySet &geometry_set,
- const ForeachGeometryCallbackConst &callback);
-
/**
* Used to keep track of a group of instances using the same geometry data.
*
- * \note In the future, this can be used to store "geometry set instances".
+ * \note In the future, this can be used to store direct instances of geometry sets.
*/
struct GeometryInstanceGroup {
/**
@@ -504,5 +498,5 @@ struct GeometryInstanceGroup {
blender::Vector<blender::float4x4> transforms;
};
-blender::Vector<GeometryInstanceGroup> BKE_geometry_set_gather_instanced(
+blender::Vector<GeometryInstanceGroup> BKE_geometry_set_gather_instances(
const GeometrySet &geometry_set);
\ No newline at end of file
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 2423740b32b..9ebf8067983 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -607,91 +607,6 @@ static GeometrySet object_get_geometry_set_for_read(const Object &object)
/** \} */
-/* -------------------------------------------------------------------- */
-/** \name Geometry Set Instances Callback
- * \{ */
-
-static void foreach_geometry_component_recursive(const GeometrySet &geometry_set,
- const ForeachGeometryCallbackConst &callback,
- const float4x4 &transform);
-
-static void foreach_collection_geometry_set_recursive(const Collection &collection,
- const ForeachGeometryCallbackConst &callback,
- const float4x4 &transform)
-{
- LISTBASE_FOREACH (const CollectionObject *, collection_object, &collection.gobject) {
- BLI_assert(collection_object->ob != nullptr);
- const Object &object = *collection_object->ob;
- GeometrySet instance_geometry_set = object_get_geometry_set_for_read(object);
-
- /* TODO: This seems to work-- validate this. */
- const float4x4 instance_transform = transform * object.obmat;
- foreach_geometry_component_recursive(instance_geometry_set, callback, instance_transform);
- }
- LISTBASE_FOREACH (const CollectionChild *, collection_child, &collection.children) {
- BLI_assert(collection_child->collection != nullptr);
- const Collection &collection = *collection_child->collection;
- foreach_collection_geometry_set_recursive(collection, callback, transform);
- }
-}
-
-static void foreach_geometry_component_recursive(const GeometrySet &geometry_set,
- const ForeachGeometryCallbackConst &callback,
- const float4x4 &transform)
-{
- if (geometry_set.has_mesh()) {
- callback(*geometry_set.get_component_for_read<MeshComponent>(), {transform});
- }
- if (geometry_set.has_pointcloud()) {
- callback(*geometry_set.get_component_for_read<PointCloudComponent>(), {transform});
- }
- if (geometry_set.has_volume()) {
- callback(*geometry_set.get_component_for_read<VolumeComponent>(), {transform});
- }
-
- if (geometry_set.has_instances()) {
- const InstancesComponent &instances_component =
- *geometry_set.get_component_for_read<InstancesComponent>();
-
- Span<float4x4> transforms = instances_component.transforms();
- Span<InstancedData> instances = instances_component.instanced_data();
- for (const int i : instances.index_range()) {
- const InstancedData &data = instances[i];
- const float4x4 &transform = transforms[i];
-
- if (data.type == INSTANCE_DATA_TYPE_OBJECT) {
- BLI_assert(data.data.object != nullptr);
- const Object &object = *data.data.object;
- GeometrySet instance_geometry_set = object_get_geometry_set_for_read(object);
- foreach_geometry_component_recursive(instance_geometry_set, callback, transform);
- }
- else if (data.type == INSTANCE_DATA_TYPE_COLLECTION) {
- BLI_assert(data.data.collection != nullptr);
- const Collection &collection = *data.data.collection;
- foreach_collection_geometry_set_recursive(collection, callback, transform);
- }
- }
- }
-}
-
-/**
- * Execute a callback for every component of a geometry set. This approach is used to avoid
- * allocating a temporary vector the store the flattened instances before operation.
- *
- * \note For convenience (to avoid duplication in the caller),
- * this also executes the callback for the argument geometry set.
- */
-void BKE_geometry_set_foreach_component_recursive(const GeometrySet &geometry_set,
- const ForeachGeometryCallbackConst &callback)
-{
- float4x4 unit_transform;
- unit_m4(unit_transform.values);
-
- foreach_geometry_component_recursive(geometry_set, callback, unit_transform);
-}
-
-/** \} */
-
/* -------------------------------------------------------------------- */
/** \name Geometry Set Gather Recursive Instances
* \{ */
@@ -753,14 +668,14 @@ static void collect_geometry_set_recursive(const GeometrySet &geometry_set,
}
/**
- * Return a vector of geometry sets, including a flattened array of instances. This approach
- * (as opposed to #BKE_geometry_set_foreach_component_recursive) can be used where multiple
- * iterations over the input data are needed, or where it simplifies code enough.
+ * Return flattened vector of the geometry component's recursive instances. I.e. all collection
+ * instances and object instances will be expanded into the instances of their geometry components.
+ * Even the instances in those geometry components' will be included.
*
* \note For convenience (to avoid duplication in the caller),
* the returned vector also contains the argument geometry set.
*/
-Vector<GeometryInstanceGroup> BKE_geometry_set_gather_instanced(const GeometrySet &geometry_set)
+Vector<GeometryInstanceGroup> BKE_geometry_set_gather_instances(const GeometrySet &geometry_set)
{
Vector<GeometryInstanceGroup> result_vector;
diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc
index 5b144441a91..4619857efc4 100644
--- a/source/blender/nodes/geometry/node_geometry_util.cc
+++ b/source/blender/nodes/geometry/node_geometry_util.cc
@@ -27,30 +27,40 @@
namespace blender::nodes {
template<typename Component>
-Map<std::string, AttributeInfo> gather_attribute_info(Span<GeometryInstanceGroup> geometry_sets)
+void gather_attribute_info(Map<std::string, AttributeInfo> &attributes,
+ Span<GeometryInstanceGroup> set_groups,
+ Set<std::string> ignored_attributes)
{
- Map<std::string, AttributeInfo> attribute_info;
- for (const GeometryInstanceGroup &set_group : geometry_sets) {
+ for (const GeometryInstanceGroup &set_group : set_groups) {
const GeometrySet &set = set_group.geometry_set;
- if (set.has<Component>()) {
- const Component &component = *set.get_component_for_read<Component>();
- for (const std::string &name : component.attribute_names()) {
- ReadAttributePtr attribute = component.attribute_try_get_for_read(name);
- BLI_assert(attribute);
- const CustomDataType data_type = attribute->custom_data_type();
- const AttributeDomain domain = attribute->domain();
- if (attribute_info.contains(name)) {
- AttributeInfo &info = attribute_info.lookup(name);
- info.data_type = attribute_data_type_highest_complexity({info.data_type, data_type});
- info.domain = domain; /* TODO: Use domain priority. */
- }
- else {
- attribute_info.add(name, {data_type});
- }
+ if (!set.has<Component>()) {
+ continue;
+ }
+ const Component &component = *set.get_component_for_read<Component>();
+
+ for (const std::string name : component.attribute_names()) {
+ if (ignored_attributes.contains(name)) {
+ continue;
}
+ const ReadAttributePtr read_attribute = component.attribute_try_get_for_read(name);
+ if (!read_attribute) {
+ continue;
+ }
+ const AttributeDomain domain = read_attribute->domain();
+ const CustomDataType data_type = read_attribute->custom_data_type();
+
+ auto add_info = [&, data_type, domain](AttributeInfo *info) {
+ info->domain = domain;
+ info->data_type = data_type;
+ };
+ auto modify_info = [&, data_type, domain](AttributeInfo *info) {
+ info->domain = domain; /* TODO: Use highest priority domain. */
+ info->data_type = attribute_data_type_highest_complexity({info->data_type, data_type});
+ };
+
+ attributes.add_or_modify(name, add_info, modify_info);
}
}
- return attribute_info;
}
static Mesh *join_mesh_topology_and_builtin_attributes(Span<GeometryInstanceGroup> set_groups)
@@ -200,8 +210,8 @@ static void join_components_mesh(Span<GeometryInstanceGroup> set_groups, Geometr
dst_component.replace(new_mesh);
/* The position attribute is handled above already. */
- Map<std::string, AttributeInfo> attributes = gather_attribute_info<MeshComponent>(set_groups);
- attributes.remove("position");
+ Map<std::string, AttributeInfo> attributes;
+ gather_attribute_info<MeshComponent>(attributes, set_groups, {"position"});
join_attributes<MeshComponent>(
set_groups, attributes, static_cast<GeometryComponent &>(dst_component));
}
@@ -220,9 +230,8 @@ static void j
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list