[Bf-blender-cvs] [7ccfe67c9b6] temp-geometry-nodes-instances-api-v2: WIP implementation, double vectors, sort of weird
Hans Goudey
noreply at git.blender.org
Thu Feb 4 06:57:00 CET 2021
Commit: 7ccfe67c9b6ac9a3280259d784b786c691fb8147
Author: Hans Goudey
Date: Wed Feb 3 17:51:16 2021 -0600
Branches: temp-geometry-nodes-instances-api-v2
https://developer.blender.org/rB7ccfe67c9b6ac9a3280259d784b786c691fb8147
WIP implementation, double vectors, sort of weird
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index bad38bce89b..0ea43202b4a 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -481,4 +481,8 @@ using ForeachGeometryCallbackConst = std::function<void(
const GeometryComponent &component, blender::Span<blender::float4x4> transforms)>;
void BKE_foreach_geometry_component_recursive(const GeometrySet &geometry_set,
- const ForeachGeometryCallbackConst &callback);
\ No newline at end of file
+ const ForeachGeometryCallbackConst &callback);
+
+using GeometrySetGroup = std::pair<GeometrySet, blender::Vector<blender::float4x4>>;
+blender::Vector<GeometrySetGroup> BKE_geometry_set_gather_instanced(
+ const GeometrySet &geometry_set);
\ No newline at end of file
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index df25a0beb38..e7f20d98d56 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -57,6 +57,10 @@ static void node_point_distribute_update(bNodeTree *UNUSED(ntree), bNode *node)
}
namespace blender::nodes {
+struct AttributeInfo {
+ CustomDataType data_type;
+ AttributeDomain domain;
+};
/**
* Use an arbitrary choice of axes for a usable rotation attribute directly out of this node.
@@ -127,48 +131,69 @@ static void sample_mesh_surface(const Mesh &mesh,
}
}
-BLI_NOINLINE static KDTree_3d *build_kdtree(Span<float3> positions)
+BLI_NOINLINE static KDTree_3d *build_kdtree(Span<Vector<float3>> all_positions)
{
+ for (Vector<float3> positions : all_positions) {
+ for (const float3 position : positions) {
+ }
+ }
KDTree_3d *kdtree = BLI_kdtree_3d_new(positions.size());
- for (const int i : positions.index_range()) {
- BLI_kdtree_3d_insert(kdtree, i, positions[i]);
+ int i = 0;
+ for (Vector<float3> positions : all_positions) {
+ for (const float3 position : positions) {
+ BLI_kdtree_3d_insert(kdtree, i, positions[i]);
+ i++;
+ }
}
BLI_kdtree_3d_balance(kdtree);
return kdtree;
}
BLI_NOINLINE static void update_elimination_mask_for_close_points(
- Span<float3> positions, const float minimum_distance, MutableSpan<bool> elimination_mask)
+ Span<Vector<float3>> positions_per_instance,
+ const float minimum_distance,
+ MutableSpan<bool> elimination_mask_per_instance)
{
if (minimum_distance <= 0.0f) {
return;
}
- KDTree_3d *kdtree = build_kdtree(positions);
-
- for (const int i : positions.index_range()) {
- if (elimination_mask[i]) {
+ for (const int i_set : get_groups.index_range()) {
+ const GeometrySetGroup &set_group = get_groups[i_set];
+ const GeometrySet &set = set_group.first;
+ if (!set.has_mesh()) {
continue;
}
-
- struct CallbackData {
- int index;
- MutableSpan<bool> elimination_mask;
- } callback_data = {i, elimination_mask};
-
- BLI_kdtree_3d_range_search_cb(
- kdtree,
- positions[i],
- minimum_distance,
- [](void *user_data, int index, const float *UNUSED(co), float UNUSED(dist_sq)) {
- CallbackData &callback_data = *static_cast<CallbackData *>(user_data);
- if (index != callback_data.index) {
- callback_data.elimination_mask[index] = true;
- }
- return true;
- },
- &callback_data);
+ const Mesh &mesh = *set.get_mesh_for_read();
+ for (const float4x4 &transform : set_group.second) {
+ }
}
+ KDTree_3d *kdtree = build_kdtree(positions);
+
+ for (const int i_instance :)
+ for (const int i : positions.index_range()) {
+ if (elimination_mask[i]) {
+ continue;
+ }
+
+ struct CallbackData {
+ int index;
+ MutableSpan<bool> elimination_mask;
+ } callback_data = {i, elimination_mask};
+
+ BLI_kdtree_3d_range_search_cb(
+ kdtree,
+ positions[i],
+ minimum_distance,
+ [](void *user_data, int index, const float *UNUSED(co), float UNUSED(dist_sq)) {
+ CallbackData &callback_data = *static_cast<CallbackData *>(user_data);
+ if (index != callback_data.index) {
+ callback_data.elimination_mask[index] = true;
+ }
+ return true;
+ },
+ &callback_data);
+ }
BLI_kdtree_3d_free(kdtree);
}
@@ -388,120 +413,146 @@ BLI_NOINLINE static void add_remaining_point_attributes(const MeshComponent &mes
*mesh_component.get_for_read(), component, bary_coords, looptri_indices);
}
-struct AttributeInfo {
- std::string name;
- Vector<CustomDataType> data_types;
- Vector<AttributeDomain> domains;
-};
-
-struct ScatterPointsOnMeshOp {
- /* Input data. */
- const GeometryNodePointDistributeMethod distribute_method;
- const std::string &density_attribute_name;
- const int seed;
- const float density;
-
- /* Output data. */
- Vector<float3> &positions;
- Vector<float3> &bary_coords;
- Vector<int> &looptri_indices;
- Set<AttributeInfo> &attributes;
-
- void operator()(const GeometryComponent &component, blender::Span<blender::float4x4> transforms)
- {
- if (component.type() != GeometryComponentType::Mesh) {
- return;
+Map<const std::string, AttributeInfo> gather_attribute_info(Span<GeometrySetGroup> geometry_sets)
+{
+ Map<const std::string, AttributeInfo> attribute_info;
+ for (const GeometrySetGroup &set_group : geometry_sets) {
+ const GeometrySet &set = set_group.first;
+ if (!set.has_mesh()) {
+ continue;
}
+ const MeshComponent &component = *set.get_component_for_read<MeshComponent>();
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- if (!mesh_component.has_mesh()) {
- return;
- }
- const Mesh &mesh = *mesh_component.get_for_read();
- for (const float4x4 &transform : transforms) {
- switch (distribute_method) {
- case GEO_NODE_POINT_DISTRIBUTE_RANDOM: {
- const FloatReadAttribute density_factors = mesh_component.attribute_get_for_read<float>(
- density_attribute_name, ATTR_DOMAIN_POINT, 1.0f);
- sample_mesh_surface(mesh,
- transform,
- density,
- &density_factors,
- seed,
- positions,
- bary_coords,
- looptri_indices);
- break;
- }
- case GEO_NODE_POINT_DISTRIBUTE_POISSON:
- sample_mesh_surface(
- mesh, transform, density, nullptr, seed, positions, bary_coords, looptri_indices);
- break;
+ for (const std::string &name : component.attribute_names()) {
+ if (ELEM(name, "position", "normal", "id")) {
+ continue;
+ }
+ 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});
+ /* TODO: Choose the domain based on priority. */
+ info.domain = domain;
+ }
+ else {
+ attribute_info.add(name, {data_type, domain});
}
}
}
-};
-
-struct PoissonEliminateFromDensityOp {
- /* Input data. */
- const std::string &density_attribute_name;
- const float density;
- Span<float3> bary_coords;
- Span<int> looptri_indices;
-
- /* Output data. */
- MutableSpan<bool> elimination_mask;
+}
- void operator()(const GeometryComponent &component, blender::Span<blender::float4x4> transforms)
- {
- if (component.type() != GeometryComponentType::Mesh) {
- return;
- }
- const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
- if (!mesh_component.has_mesh()) {
- return;
+PointCloud *random_create_points(Span<GeometrySetGroup> get_groups,
+ const GeoNodeExecParams ¶ms,
+ MutableSpan<Vector<float3>> r_bary_coords_set,
+ MutableSpan<Vector<int>> r_looptri_indices_set,
+ const StringRef density_attribute_name,
+ const float density,
+ const int seed)
+{
+ Vector<float3> positions;
+ for (const int i_set : get_groups.index_range()) {
+ const GeometrySetGroup &set_group = get_groups[i_set];
+ const GeometrySet &set = set_group.first;
+ if (!set.has_mesh()) {
+ continue;
}
- const Mesh &mesh = *mesh_component.get_for_read();
- for (const float4x4 &transform : transforms) {
- const FloatReadAttribute density_factors = mesh_component.attribute_get_for_read<float>(
- density_attribute_name, ATTR_DOMAIN_POINT, 1.0f);
- update_elimination_mask_based_on_density_factors(
- mesh, density_factors, bary_coords, looptri_indices, elimination_mask);
+ Vector<float3> &bary_coords = r_bary_coords_set[i_set];
+ Vector<int> &looptri_indices = r_looptri_indices_set[i_set];
+
+ const MeshComponent &component = *set.get_component_for_read<MeshComponent>();
+ const Mesh &mesh = *component.get_for_read();
+ const FloatReadAttribute density_factors = component.attribute_get_for_read<float>(
+ density_attribute_name, ATTR_DOMAIN_POINT, 1.0f);
+ for (const float4x4 &transform : set_group.second) {
+ sample_mesh_surface(mesh,
+ transform,
+ density,
+ &density_factors,
+ seed,
+ positions,
+ bary_coords,
+ looptri_indices);
}
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list