From 8ed7ed02554d9e595c2bdfa7a5bb3e9fda43e202 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 14 Jan 2021 15:16:06 +0100 Subject: Geometry Nodes: extract function for adding attributes in distribute node This shouldn't have any functional changes. --- .../geometry/nodes/node_geo_point_distribute.cc | 65 +++++++++++----------- 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'source/blender/nodes') 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 1370f45877d..46b29a08feb 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc @@ -217,12 +217,12 @@ BLI_NOINLINE static void eliminate_points_based_on_mask(Span elimination_m } } -BLI_NOINLINE static void compute_remaining_point_data(const Mesh &mesh, - Span bary_coords, - Span looptri_indices, - MutableSpan r_normals, - MutableSpan r_ids, - MutableSpan r_rotations) +BLI_NOINLINE static void compute_special_attributes(const Mesh &mesh, + Span bary_coords, + Span looptri_indices, + MutableSpan r_normals, + MutableSpan r_ids, + MutableSpan r_rotations) { Span looptris = get_mesh_looptris(mesh); for (const int i : bary_coords.index_range()) { @@ -243,6 +243,30 @@ BLI_NOINLINE static void compute_remaining_point_data(const Mesh &mesh, } } +BLI_NOINLINE static void add_remaining_point_attributes(const Mesh &mesh, + GeometryComponent &component, + Span bary_coords, + Span looptri_indices) +{ + WriteAttributePtr id_attribute = component.attribute_try_ensure_for_write( + "id", ATTR_DOMAIN_POINT, CD_PROP_INT32); + WriteAttributePtr normal_attribute = component.attribute_try_ensure_for_write( + "normal", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3); + WriteAttributePtr rotation_attribute = component.attribute_try_ensure_for_write( + "rotation", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3); + + compute_special_attributes(mesh, + bary_coords, + looptri_indices, + normal_attribute->get_span_for_write_only(), + id_attribute->get_span_for_write_only(), + rotation_attribute->get_span_for_write_only()); + + id_attribute->apply_span(); + normal_attribute->apply_span(); + rotation_attribute->apply_span(); +} + static void sample_mesh_surface_with_minimum_distance(const Mesh &mesh, const float max_density, const float minimum_distance, @@ -315,11 +339,6 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params) break; } const int tot_points = positions.size(); - Array normals(tot_points); - Array stable_ids(tot_points); - Array rotations(tot_points); - compute_remaining_point_data( - *mesh_in, bary_coords, looptri_indices, normals, stable_ids, rotations); PointCloud *pointcloud = BKE_pointcloud_new_nomain(tot_points); memcpy(pointcloud->co, positions.data(), sizeof(float3) * tot_points); @@ -332,29 +351,7 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params) geometry_set_out.get_component_for_write(); point_component.replace(pointcloud); - { - Int32WriteAttribute stable_id_attribute = point_component.attribute_try_ensure_for_write( - "id", ATTR_DOMAIN_POINT, CD_PROP_INT32); - MutableSpan stable_ids_span = stable_id_attribute.get_span(); - stable_ids_span.copy_from(stable_ids); - stable_id_attribute.apply_span(); - } - - { - Float3WriteAttribute normals_attribute = point_component.attribute_try_ensure_for_write( - "normal", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3); - MutableSpan normals_span = normals_attribute.get_span(); - normals_span.copy_from(normals); - normals_attribute.apply_span(); - } - - { - Float3WriteAttribute rotations_attribute = point_component.attribute_try_ensure_for_write( - "rotation", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3); - MutableSpan rotations_span = rotations_attribute.get_span(); - rotations_span.copy_from(rotations); - rotations_attribute.apply_span(); - } + add_remaining_point_attributes(*mesh_in, point_component, bary_coords, looptri_indices); params.set_output("Geometry", std::move(geometry_set_out)); } -- cgit v1.2.3