[Bf-blender-cvs] [81b76f8dafd] temp-attribute-transfer-node: progress
Jacques Lucke
noreply at git.blender.org
Tue Apr 20 13:22:49 CEST 2021
Commit: 81b76f8dafdda741f372416bb002b51e22d4e03f
Author: Jacques Lucke
Date: Tue Apr 20 12:53:45 2021 +0200
Branches: temp-attribute-transfer-node
https://developer.blender.org/rB81b76f8dafdda741f372416bb002b51e22d4e03f
progress
===================================================================
M source/blender/blenkernel/BKE_geometry_set.hh
M source/blender/blenkernel/intern/attribute_access.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index bfb4afe085c..25d4f8bec8f 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -158,6 +158,9 @@ class GeometryComponent {
std::unique_ptr<blender::fn::GVArray> attribute_try_get_for_read(
const blender::StringRef attribute_name, const AttributeDomain domain) const;
+ std::unique_ptr<blender::fn::GVArray> attribute_try_get_for_read(
+ const blender::StringRef attribute_name, const CustomDataType data_type) const;
+
/* Get a virtual array to read the data of an attribute. If that is not possible, the returned
* virtual array will contain a default value. This never returns null. */
std::unique_ptr<blender::fn::GVArray> attribute_get_for_read(
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 70572e446b7..1fda0ada05b 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -786,6 +786,23 @@ std::unique_ptr<blender::bke::GVArray> GeometryComponent::attribute_try_get_for_
return std::move(attribute.varray);
}
+std::unique_ptr<blender::fn::GVArray> GeometryComponent::attribute_try_get_for_read(
+ const blender::StringRef attribute_name, const CustomDataType data_type) const
+{
+ blender::bke::ReadAttributeLookup attribute = this->attribute_try_get_for_read(attribute_name);
+ if (!attribute) {
+ return {};
+ }
+ const blender::fn::CPPType *type = blender::bke::custom_data_type_to_cpp_type(data_type);
+ BLI_assert(type != nullptr);
+ if (attribute.varray->type() == *type) {
+ return std::move(attribute.varray);
+ }
+ const blender::nodes::DataTypeConversions &conversions =
+ blender::nodes::get_implicit_type_conversions();
+ return conversions.try_convert(std::move(attribute.varray), *type);
+}
+
std::unique_ptr<blender::bke::GVArray> GeometryComponent::attribute_get_for_read(
const StringRef attribute_name,
const AttributeDomain domain,
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
index 5f695a54e3b..958040d6af8 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_transfer.cc
@@ -85,7 +85,8 @@ static CustomDataType get_result_data_type(const GeometrySet &geometry,
static void get_closest_pointcloud_point_indices(const PointCloud &pointcloud,
const VArray<float3> &positions,
- const MutableSpan<int> r_indices)
+ const MutableSpan<int> r_indices,
+ const MutableSpan<float> r_distances_sq)
{
BLI_assert(positions.size() == r_indices.size());
BLI_assert(pointcloud.totpoint > 0);
@@ -100,6 +101,7 @@ static void get_closest_pointcloud_point_indices(const PointCloud &pointcloud,
BLI_bvhtree_find_nearest(
tree_data.tree, position, &nearest, tree_data.nearest_callback, &tree_data);
r_indices[i] = nearest.index;
+ r_distances_sq[i] = nearest.dist_sq;
}
free_bvhtree_from_pointcloud(&tree_data);
@@ -107,7 +109,8 @@ static void get_closest_pointcloud_point_indices(const PointCloud &pointcloud,
static void get_closest_mesh_point_indices(const Mesh &mesh,
const VArray<float3> &positions,
- const MutableSpan<int> r_indices)
+ const MutableSpan<int> r_indices,
+ const MutableSpan<float> r_distances_sq)
{
BLI_assert(positions.size() == r_indices.size());
BLI_assert(mesh.totvert > 0);
@@ -122,6 +125,7 @@ static void get_closest_mesh_point_indices(const Mesh &mesh,
BLI_bvhtree_find_nearest(
tree_data.tree, position, &nearest, tree_data.nearest_callback, &tree_data);
r_indices[i] = nearest.index;
+ r_distances_sq[i] = nearest.dist_sq;
}
free_bvhtree_from_mesh(&tree_data);
@@ -130,7 +134,8 @@ static void get_closest_mesh_point_indices(const Mesh &mesh,
static void get_closest_mesh_surface_samples(const Mesh &mesh,
const VArray<float3> &positions,
const MutableSpan<int> r_looptri_indices,
- const MutableSpan<float3> r_positions)
+ const MutableSpan<float3> r_positions,
+ const MutableSpan<float> r_distances_sq)
{
BLI_assert(positions.size() == r_looptri_indices.size());
BLI_assert(positions.size() == r_positions.size());
@@ -146,6 +151,7 @@ static void get_closest_mesh_surface_samples(const Mesh &mesh,
tree_data.tree, position, &nearest, tree_data.nearest_callback, &tree_data);
r_looptri_indices[i] = nearest.index;
r_positions[i] = nearest.co;
+ r_distances_sq[i] = nearest.dist_sq;
}
free_bvhtree_from_mesh(&tree_data);
@@ -172,12 +178,10 @@ static void transfer_attribute(const GeometrySet &src_geometry,
if (pointcloud->totpoint == 0) {
return;
}
- ReadAttributeLookup src_attribute = src_component.attribute_try_get_for_read(src_name);
+ GVArrayPtr src_attribute = src_component.attribute_try_get_for_read(src_name, data_type);
if (!src_attribute) {
return;
}
- /* TODO: Possibly convert data type. */
- BLI_assert(src_attribute.varray->type() == type);
OutputAttribute dst_attribute = dst_component.attribute_try_get_for_output_only(
dst_name, result_domain, data_type);
@@ -189,13 +193,15 @@ static void transfer_attribute(const GeometrySet &src_geometry,
"position", result_domain, {0, 0, 0});
Array<int> nearest_point_indices(dst_positions.size());
- get_closest_pointcloud_point_indices(*pointcloud, dst_positions, nearest_point_indices);
+ Array<float> nearest_point_distances_sq(dst_positions.size());
+ get_closest_pointcloud_point_indices(
+ *pointcloud, dst_positions, nearest_point_indices, nearest_point_distances_sq);
BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
for (const int i : dst_positions.index_range()) {
const int point_index = nearest_point_indices[i];
- src_attribute.varray->get(point_index, buffer);
+ src_attribute->get(point_index, buffer);
dst_attribute->set_by_relocate(i, buffer);
}
More information about the Bf-blender-cvs
mailing list