Geometry Nodes: Add selection and depth options to realize instances #104832

Closed
Angus Stanton wants to merge 15 commits from ab_stanton/blender:add-selection-realize-instances into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 11 additions and 11 deletions
Showing only changes of commit 2a9df9b46d - Show all commits

View File

@ -32,7 +32,7 @@ struct RealizeInstancesOptions {
* of instances and of the instanced geometry data.
*/
GeometrySet realize_instances(GeometrySet geometry_set,
const IndexMask &selection,
IndexMask selection,
const RealizeInstancesOptions &options);
} // namespace blender::geometry

View File

@ -237,7 +237,7 @@ struct GatherTasksInfo {
bool create_id_attribute_on_any_component = false;
/** Selection for instances to realize. */
const IndexMask &selection;
IndexMask selection;
/**
* Under some circumstances, temporary arrays need to be allocated during the gather operation.
* For example, when an instance attribute has to be realized as a different data type. This
@ -1450,17 +1450,16 @@ static void remove_id_attribute_from_instances(GeometrySet &geometry_set)
/** Propagate instances from the old geometry set to the new geometry set if they are not realized.
*/
static void propagate_instances_to_keep(const GeometrySet &geometry_set,
const IndexMask &selection,
IndexMask selection,
GeometrySet &new_geometry_set)
{
const auto *instances_component = geometry_set.get_component_for_read<InstancesComponent>();
const auto *instances = instances_component->get_for_read();
const auto *instances = geometry_set.get_instances_for_read();
Vector<int64_t> inverse_selection_indices;
const IndexMask inverse_selection = selection.invert(IndexRange(instances->instances_num()),
inverse_selection_indices);
// check not all instances are being realized
/* Check not all instances are being realized. */
if (inverse_selection.is_empty()) {
return;
}
@ -1472,7 +1471,7 @@ static void propagate_instances_to_keep(const GeometrySet &geometry_set,
}
GeometrySet realize_instances(GeometrySet geometry_set,
const IndexMask &selection,
IndexMask selection,
const RealizeInstancesOptions &options)
{
/* The algorithm works in three steps:

View File

@ -2,6 +2,8 @@
#include "node_geometry_util.hh"
#include "BKE_instances.hh"
#include "GEO_realize_instances.hh"
#include "UI_interface.h"
@ -40,13 +42,12 @@ static void node_geo_exec(GeoNodeExecParams params)
return;
}
const auto *instances_component = geometry_set.get_component_for_read<InstancesComponent>();
Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
bke::GeometryFieldContext field_context{*instances_component, ATTR_DOMAIN_INSTANCE};
const int domain_size = instances_component->attribute_domain_size(ATTR_DOMAIN_INSTANCE);
const bke::Instances &instances = *geometry_set.get_instances_for_read();
const bke::InstancesFieldContext field_context{instances};
fn::FieldEvaluator evaluator{field_context, domain_size};
fn::FieldEvaluator evaluator{field_context, instances.instances_num()};
evaluator.set_selection(selection_field);
ab_stanton marked this conversation as resolved
Review

The whitespace here doesn't really help IMO. I'd suggest putting all of these in one block:

  const bke::InstancesFieldContext field_context{instances};
  fn::FieldEvaluator evaluator{field_context, instances.instances_num()};
  evaluator.set_selection(params.extract_input<Field<bool>>("Selection"));
  evaluator.add(params.extract_input<Field<int>>("Depth"));
  evaluator.evaluate();
  const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
  const VArray<int> depths = evaluator.get_evaluated<int>(0);

This is subjective, but generally blank lines are only helpful when used a bit more sparingly, to separate the code into meaningful sections. Just like paragraphs of prose I guess.

The whitespace here doesn't really help IMO. I'd suggest putting all of these in one block: ``` const bke::InstancesFieldContext field_context{instances}; fn::FieldEvaluator evaluator{field_context, instances.instances_num()}; evaluator.set_selection(params.extract_input<Field<bool>>("Selection")); evaluator.add(params.extract_input<Field<int>>("Depth")); evaluator.evaluate(); const IndexMask selection = evaluator.get_evaluated_selection_as_mask(); const VArray<int> depths = evaluator.get_evaluated<int>(0); ``` This is subjective, but generally blank lines are only helpful when used a bit more sparingly, to separate the code into meaningful sections. Just like paragraphs of prose I guess.
evaluator.evaluate();