[Bf-blender-cvs] [8f2b60ddbfe] master: Cleanup: Variable names, formatting, reduce indentation

Hans Goudey noreply at git.blender.org
Sat Aug 14 04:47:13 CEST 2021


Commit: 8f2b60ddbfea800ac155d9419e8d237c791fcda9
Author: Hans Goudey
Date:   Fri Aug 13 21:46:59 2021 -0500
Branches: master
https://developer.blender.org/rB8f2b60ddbfea800ac155d9419e8d237c791fcda9

Cleanup: Variable names, formatting, reduce indentation

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_raycast.cc

===================================================================

diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
index 0c1d8645411..88e3bf17d43 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
@@ -63,20 +63,20 @@ static void geo_node_raycast_init(bNodeTree *UNUSED(tree), bNode *node)
   node->storage = data;
 }
 
+namespace blender::nodes {
+
 static void geo_node_raycast_update(bNodeTree *UNUSED(ntree), bNode *node)
 {
   NodeGeometryRaycast *node_storage = (NodeGeometryRaycast *)node->storage;
-  blender::nodes::update_attribute_input_socket_availabilities(
+  update_attribute_input_socket_availabilities(
       *node,
       "Ray Direction",
       (GeometryNodeAttributeInputMode)node_storage->input_type_ray_direction);
-  blender::nodes::update_attribute_input_socket_availabilities(
+  update_attribute_input_socket_availabilities(
       *node, "Ray Length", (GeometryNodeAttributeInputMode)node_storage->input_type_ray_length);
 }
 
-namespace blender::nodes {
-
-static void raycast_to_mesh(const Mesh *mesh,
+static void raycast_to_mesh(const Mesh &mesh,
                             const VArray<float3> &ray_origins,
                             const VArray<float3> &ray_directions,
                             const VArray<float> &ray_lengths,
@@ -95,62 +95,64 @@ static void raycast_to_mesh(const Mesh *mesh,
   BLI_assert(ray_origins.size() == r_hit_distances.size() || r_hit_distances.is_empty());
 
   BVHTreeFromMesh tree_data;
-  BKE_bvhtree_from_mesh_get(&tree_data, mesh, BVHTREE_FROM_LOOPTRI, 4);
-
-  if (tree_data.tree != nullptr) {
-    for (const int i : ray_origins.index_range()) {
-      const float ray_length = ray_lengths[i];
-      const float3 ray_origin = ray_origins[i];
-      const float3 ray_direction = ray_directions[i].normalized();
-
-      BVHTreeRayHit hit;
-      hit.index = -1;
-      hit.dist = ray_length;
-      if (BLI_bvhtree_ray_cast(tree_data.tree,
-                               ray_origin,
-                               ray_direction,
-                               0.0f,
-                               &hit,
-                               tree_data.raycast_callback,
-                               &tree_data) != -1) {
-        if (!r_hit.is_empty()) {
-          r_hit[i] = hit.index >= 0;
-        }
-        if (!r_hit_indices.is_empty()) {
-          /* Index should always be a valid looptri index, use 0 when hit failed. */
-          r_hit_indices[i] = max_ii(hit.index, 0);
-        }
-        if (!r_hit_positions.is_empty()) {
-          r_hit_positions[i] = hit.co;
-        }
-        if (!r_hit_normals.is_empty()) {
-          r_hit_normals[i] = hit.no;
-        }
-        if (!r_hit_distances.is_empty()) {
-          r_hit_distances[i] = hit.dist;
-        }
+  BKE_bvhtree_from_mesh_get(&tree_data, &mesh, BVHTREE_FROM_LOOPTRI, 4);
+  if (tree_data.tree == nullptr) {
+    free_bvhtree_from_mesh(&tree_data);
+    return;
+  }
+
+  for (const int i : ray_origins.index_range()) {
+    const float ray_length = ray_lengths[i];
+    const float3 ray_origin = ray_origins[i];
+    const float3 ray_direction = ray_directions[i].normalized();
+
+    BVHTreeRayHit hit;
+    hit.index = -1;
+    hit.dist = ray_length;
+    if (BLI_bvhtree_ray_cast(tree_data.tree,
+                             ray_origin,
+                             ray_direction,
+                             0.0f,
+                             &hit,
+                             tree_data.raycast_callback,
+                             &tree_data) != -1) {
+      if (!r_hit.is_empty()) {
+        r_hit[i] = hit.index >= 0;
+      }
+      if (!r_hit_indices.is_empty()) {
+        /* Index should always be a valid looptri index, use 0 when hit failed. */
+        r_hit_indices[i] = max_ii(hit.index, 0);
+      }
+      if (!r_hit_positions.is_empty()) {
+        r_hit_positions[i] = hit.co;
       }
-      else {
-        if (!r_hit.is_empty()) {
-          r_hit[i] = false;
-        }
-        if (!r_hit_indices.is_empty()) {
-          r_hit_indices[i] = 0;
-        }
-        if (!r_hit_positions.is_empty()) {
-          r_hit_positions[i] = float3(0.0f, 0.0f, 0.0f);
-        }
-        if (!r_hit_normals.is_empty()) {
-          r_hit_normals[i] = float3(0.0f, 0.0f, 0.0f);
-        }
-        if (!r_hit_distances.is_empty()) {
-          r_hit_distances[i] = ray_length;
-        }
+      if (!r_hit_normals.is_empty()) {
+        r_hit_normals[i] = hit.no;
+      }
+      if (!r_hit_distances.is_empty()) {
+        r_hit_distances[i] = hit.dist;
+      }
+    }
+    else {
+      if (!r_hit.is_empty()) {
+        r_hit[i] = false;
+      }
+      if (!r_hit_indices.is_empty()) {
+        r_hit_indices[i] = 0;
+      }
+      if (!r_hit_positions.is_empty()) {
+        r_hit_positions[i] = float3(0.0f, 0.0f, 0.0f);
+      }
+      if (!r_hit_normals.is_empty()) {
+        r_hit_normals[i] = float3(0.0f, 0.0f, 0.0f);
+      }
+      if (!r_hit_distances.is_empty()) {
+        r_hit_distances[i] = ray_length;
       }
     }
-
-    free_bvhtree_from_mesh(&tree_data);
   }
+
+  free_bvhtree_from_mesh(&tree_data);
 }
 
 static bke::mesh_surface_sample::eAttributeMapMode get_map_mode(
@@ -166,7 +168,7 @@ static bke::mesh_surface_sample::eAttributeMapMode get_map_mode(
 }
 
 static void raycast_from_points(const GeoNodeExecParams &params,
-                                const GeometrySet &src_geometry,
+                                const GeometrySet &target_geometry,
                                 GeometryComponent &dst_component,
                                 const StringRef hit_name,
                                 const StringRef hit_position_name,
@@ -177,7 +179,8 @@ static void raycast_from_points(const GeoNodeExecParams &params,
 {
   BLI_assert(hit_attribute_names.size() == hit_attribute_output_names.size());
 
-  const MeshComponent *src_mesh_component = src_geometry.get_component_for_read<MeshComponent>();
+  const MeshComponent *src_mesh_component =
+      target_geometry.get_component_for_read<MeshComponent>();
   if (src_mesh_component == nullptr) {
     return;
   }
@@ -211,8 +214,7 @@ static void raycast_from_points(const GeoNodeExecParams &params,
       dst_component.attribute_try_get_for_output_only<float>(hit_distance_name, result_domain);
 
   /* Positions and looptri indices are always needed for interpolation,
-   * so create temporary arrays if no output attribute is given.
-   */
+   * so create temporary arrays if no output attribute is given. */
   Array<int> hit_indices;
   Array<float3> hit_positions_internal;
   if (!hit_attribute_names.is_empty()) {
@@ -232,7 +234,7 @@ static void raycast_from_points(const GeoNodeExecParams &params,
                                                hit_distance_attribute.as_span() :
                                                MutableSpan<float>();
 
-  raycast_to_mesh(src_mesh,
+  raycast_to_mesh(*src_mesh,
                   ray_origins,
                   ray_directions,
                   ray_lengths,
@@ -268,34 +270,32 @@ static void raycast_from_points(const GeoNodeExecParams &params,
 static void geo_node_raycast_exec(GeoNodeExecParams params)
 {
   GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
-  GeometrySet cast_geometry_set = params.extract_input<GeometrySet>("Target Geometry");
+  GeometrySet target_geometry_set = params.extract_input<GeometrySet>("Target Geometry");
 
   const std::string hit_name = params.extract_input<std::string>("Is Hit");
   const std::string hit_position_name = params.extract_input<std::string>("Hit Position");
   const std::string hit_normal_name = params.extract_input<std::string>("Hit Normal");
   const std::string hit_distance_name = params.extract_input<std::string>("Hit Distance");
 
-  const Array<std::string> hit_attribute_names = {
-      params.extract_input<std::string>("Target Attribute")};
-  const Array<std::string> hit_attribute_output_names = {
-      params.extract_input<std::string>("Hit Attribute")};
+  const Array<std::string> hit_names = {params.extract_input<std::string>("Target Attribute")};
+  const Array<std::string> hit_output_names = {params.extract_input<std::string>("Hit Attribute")};
 
   geometry_set = bke::geometry_set_realize_instances(geometry_set);
-  cast_geometry_set = bke::geometry_set_realize_instances(cast_geometry_set);
+  target_geometry_set = bke::geometry_set_realize_instances(target_geometry_set);
 
-  static const Array<GeometryComponentType> SupportedTypes = {
+  static const Array<GeometryComponentType> types = {
       GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD, GEO_COMPONENT_TYPE_CURVE};
-  for (GeometryComponentType geo_type : SupportedTypes) {
-    if (geometry_set.has(geo_type)) {
+  for (const GeometryComponentType type : types) {
+    if (geometry_set.has(type)) {
       raycast_from_points(params,
-                          cast_geometry_set,
-                          geometry_set.get_component_for_write(geo_type),
+                          target_geometry_set,
+                          geometry_set.get_component_for_write(type),
                           hit_name,
                           hit_position_name,
                           hit_normal_name,
                           hit_distance_name,
-                          hit_attribute_names,
-                          hit_attribute_output_names);
+                          hit_names,
+                          hit_output_names);
     }
   }
 
@@ -312,7 +312,7 @@ void register_node_type_geo_raycast()
   node_type_socket_templates(&ntype, geo_node_raycast_in, geo_node_raycast_out);
   node_type_size_preset(&ntype, NODE_SIZE_LARGE);
   node_type_init(&ntype, geo_node_raycast_init);
-  node_type_update(&ntype, geo_node_raycast_update);
+  node_type_update(&ntype, blender::nodes::geo_node_raycast_update);
   node_type_storage(
       &ntype, "NodeGeometryRaycast", node_free_standard_storage, node_copy_standard_storage);
   ntype.geometry_node_execute = blender::nodes::geo_node_raycast_exec;



More information about the Bf-blender-cvs mailing list