forked from blender/blender
davidhaver-WIP-realize-depth #2
@ -31,7 +31,7 @@ struct RealizeInstancesOptions {
|
|||||||
/**
|
/**
|
||||||
* Allow the user to choice which instances to realize and to what depth.
|
* Allow the user to choice which instances to realize and to what depth.
|
||||||
*/
|
*/
|
||||||
struct SpecificInstancesChoice {
|
struct VariedDepthOption {
|
||||||
/**
|
/**
|
||||||
* Selection of top-level instances to realize.
|
* Selection of top-level instances to realize.
|
||||||
*/
|
*/
|
||||||
@ -71,10 +71,10 @@ bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
|||||||
* output will contain an `id` attribute as well. The output id is generated by mixing/hashing ids
|
* output will contain an `id` attribute as well. The output id is generated by mixing/hashing ids
|
||||||
* of instances and of the instanced geometry data.
|
* of instances and of the instanced geometry data.
|
||||||
*
|
*
|
||||||
* Will realize only the instaces chosen by chosen_instaces to there chosen depth.
|
* Will realize only the instances chosen by varied_depth_option to there chosen depth.
|
||||||
*/
|
*/
|
||||||
bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instaces);
|
const VariedDepthOption &varied_depth_option);
|
||||||
|
|
||||||
} // namespace blender::geometry
|
} // namespace blender::geometry
|
||||||
|
@ -827,7 +827,7 @@ void static gather_attributes_for_propagation(
|
|||||||
attribute_foreach(re_geometry_set,
|
attribute_foreach(re_geometry_set,
|
||||||
component_types,
|
component_types,
|
||||||
0,
|
0,
|
||||||
SpecificInstancesChoice::MAX_DEPTH,
|
VariedDepthOption::MAX_DEPTH,
|
||||||
instance_depth,
|
instance_depth,
|
||||||
selection,
|
selection,
|
||||||
[&](const AttributeIDRef &attribute_id,
|
[&](const AttributeIDRef &attribute_id,
|
||||||
@ -878,7 +878,7 @@ void static gather_attributes_for_propagation(
|
|||||||
static OrderedAttributes gather_generic_instance_attributes_to_propagate(
|
static OrderedAttributes gather_generic_instance_attributes_to_propagate(
|
||||||
const bke::GeometrySet &in_geometry_set,
|
const bke::GeometrySet &in_geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances)
|
const VariedDepthOption &varied_depth_option)
|
||||||
{
|
{
|
||||||
Vector<bke::GeometryComponent::Type> src_component_types;
|
Vector<bke::GeometryComponent::Type> src_component_types;
|
||||||
src_component_types.append(bke::GeometryComponent::Type::Instance);
|
src_component_types.append(bke::GeometryComponent::Type::Instance);
|
||||||
@ -887,8 +887,8 @@ static OrderedAttributes gather_generic_instance_attributes_to_propagate(
|
|||||||
gather_attributes_for_propagation(in_geometry_set,
|
gather_attributes_for_propagation(in_geometry_set,
|
||||||
src_component_types,
|
src_component_types,
|
||||||
bke::GeometryComponent::Type::Instance,
|
bke::GeometryComponent::Type::Instance,
|
||||||
chosen_instances.depths,
|
varied_depth_option.depths,
|
||||||
chosen_instances.selection,
|
varied_depth_option.selection,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
attributes_to_propagate.remove("position");
|
attributes_to_propagate.remove("position");
|
||||||
@ -1008,7 +1008,7 @@ static void execute_instances_tasks(
|
|||||||
static OrderedAttributes gather_generic_pointcloud_attributes_to_propagate(
|
static OrderedAttributes gather_generic_pointcloud_attributes_to_propagate(
|
||||||
const bke::GeometrySet &in_geometry_set,
|
const bke::GeometrySet &in_geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances,
|
const VariedDepthOption &varied_depth_option,
|
||||||
bool &r_create_radii,
|
bool &r_create_radii,
|
||||||
bool &r_create_id)
|
bool &r_create_id)
|
||||||
{
|
{
|
||||||
@ -1022,8 +1022,8 @@ static OrderedAttributes gather_generic_pointcloud_attributes_to_propagate(
|
|||||||
gather_attributes_for_propagation(in_geometry_set,
|
gather_attributes_for_propagation(in_geometry_set,
|
||||||
src_component_types,
|
src_component_types,
|
||||||
bke::GeometryComponent::Type::PointCloud,
|
bke::GeometryComponent::Type::PointCloud,
|
||||||
chosen_instances.depths,
|
varied_depth_option.depths,
|
||||||
chosen_instances.selection,
|
varied_depth_option.selection,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
|
|
||||||
@ -1055,12 +1055,12 @@ static void gather_pointclouds_to_realize(const bke::GeometrySet &geometry_set,
|
|||||||
|
|
||||||
static AllPointCloudsInfo preprocess_pointclouds(const bke::GeometrySet &geometry_set,
|
static AllPointCloudsInfo preprocess_pointclouds(const bke::GeometrySet &geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances)
|
const VariedDepthOption &varied_depth_option)
|
||||||
{
|
{
|
||||||
AllPointCloudsInfo info;
|
AllPointCloudsInfo info;
|
||||||
info.attributes = gather_generic_pointcloud_attributes_to_propagate(geometry_set,
|
info.attributes = gather_generic_pointcloud_attributes_to_propagate(geometry_set,
|
||||||
options,
|
options,
|
||||||
chosen_instances,
|
varied_depth_option,
|
||||||
info.create_radius_attribute,
|
info.create_radius_attribute,
|
||||||
info.create_id_attribute);
|
info.create_id_attribute);
|
||||||
|
|
||||||
@ -1217,7 +1217,7 @@ static void execute_realize_pointcloud_tasks(bool keep_original_ids,
|
|||||||
static OrderedAttributes gather_generic_mesh_attributes_to_propagate(
|
static OrderedAttributes gather_generic_mesh_attributes_to_propagate(
|
||||||
const bke::GeometrySet &in_geometry_set,
|
const bke::GeometrySet &in_geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances,
|
const VariedDepthOption &varied_depth_option,
|
||||||
bool &r_create_id,
|
bool &r_create_id,
|
||||||
bool &r_create_material_index)
|
bool &r_create_material_index)
|
||||||
{
|
{
|
||||||
@ -1231,8 +1231,8 @@ static OrderedAttributes gather_generic_mesh_attributes_to_propagate(
|
|||||||
gather_attributes_for_propagation(in_geometry_set,
|
gather_attributes_for_propagation(in_geometry_set,
|
||||||
src_component_types,
|
src_component_types,
|
||||||
bke::GeometryComponent::Type::Mesh,
|
bke::GeometryComponent::Type::Mesh,
|
||||||
chosen_instances.depths,
|
varied_depth_option.depths,
|
||||||
chosen_instances.selection,
|
varied_depth_option.selection,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
attributes_to_propagate.remove("position");
|
attributes_to_propagate.remove("position");
|
||||||
@ -1266,13 +1266,13 @@ static void gather_meshes_to_realize(const bke::GeometrySet &geometry_set,
|
|||||||
|
|
||||||
static AllMeshesInfo preprocess_meshes(const bke::GeometrySet &geometry_set,
|
static AllMeshesInfo preprocess_meshes(const bke::GeometrySet &geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances)
|
const VariedDepthOption &varied_depth_option)
|
||||||
{
|
{
|
||||||
AllMeshesInfo info;
|
AllMeshesInfo info;
|
||||||
info.attributes = gather_generic_mesh_attributes_to_propagate(
|
info.attributes = gather_generic_mesh_attributes_to_propagate(
|
||||||
geometry_set,
|
geometry_set,
|
||||||
options,
|
options,
|
||||||
chosen_instances,
|
varied_depth_option,
|
||||||
info.create_id_attribute,
|
info.create_id_attribute,
|
||||||
info.create_material_index_attribute);
|
info.create_material_index_attribute);
|
||||||
|
|
||||||
@ -1588,7 +1588,7 @@ static void execute_realize_mesh_tasks(bool keep_original_ids,
|
|||||||
static OrderedAttributes gather_generic_curve_attributes_to_propagate(
|
static OrderedAttributes gather_generic_curve_attributes_to_propagate(
|
||||||
const bke::GeometrySet &in_geometry_set,
|
const bke::GeometrySet &in_geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances,
|
const VariedDepthOption &varied_depth_option,
|
||||||
bool &r_create_id)
|
bool &r_create_id)
|
||||||
{
|
{
|
||||||
Vector<bke::GeometryComponent::Type> src_component_types;
|
Vector<bke::GeometryComponent::Type> src_component_types;
|
||||||
@ -1601,8 +1601,8 @@ static OrderedAttributes gather_generic_curve_attributes_to_propagate(
|
|||||||
gather_attributes_for_propagation(in_geometry_set,
|
gather_attributes_for_propagation(in_geometry_set,
|
||||||
src_component_types,
|
src_component_types,
|
||||||
bke::GeometryComponent::Type::Curve,
|
bke::GeometryComponent::Type::Curve,
|
||||||
chosen_instances.depths,
|
varied_depth_option.depths,
|
||||||
chosen_instances.selection,
|
varied_depth_option.selection,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
attributes_to_propagate.remove("position");
|
attributes_to_propagate.remove("position");
|
||||||
@ -1638,11 +1638,11 @@ static void gather_curves_to_realize(const bke::GeometrySet &geometry_set,
|
|||||||
|
|
||||||
static AllCurvesInfo preprocess_curves(const bke::GeometrySet &geometry_set,
|
static AllCurvesInfo preprocess_curves(const bke::GeometrySet &geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances)
|
const VariedDepthOption &varied_depth_option)
|
||||||
{
|
{
|
||||||
AllCurvesInfo info;
|
AllCurvesInfo info;
|
||||||
info.attributes = gather_generic_curve_attributes_to_propagate(
|
info.attributes = gather_generic_curve_attributes_to_propagate(
|
||||||
geometry_set, options, chosen_instances, info.create_id_attribute);
|
geometry_set, options, varied_depth_option, info.create_id_attribute);
|
||||||
|
|
||||||
gather_curves_to_realize(geometry_set, info.order);
|
gather_curves_to_realize(geometry_set, info.order);
|
||||||
info.realize_info.reinitialize(info.order.size());
|
info.realize_info.reinitialize(info.order.size());
|
||||||
@ -1969,8 +1969,8 @@ bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
|||||||
return geometry_set;
|
return geometry_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpecificInstancesChoice all_instances;
|
VariedDepthOption all_instances;
|
||||||
all_instances.depths = VArray<int>::ForSingle(SpecificInstancesChoice::MAX_DEPTH,
|
all_instances.depths = VArray<int>::ForSingle(VariedDepthOption::MAX_DEPTH,
|
||||||
geometry_set.get_instances()->instances_num());
|
geometry_set.get_instances()->instances_num());
|
||||||
IndexMaskMemory memory;
|
IndexMaskMemory memory;
|
||||||
all_instances.selection = IndexMask::from_bools(
|
all_instances.selection = IndexMask::from_bools(
|
||||||
@ -1980,7 +1980,7 @@ bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
|||||||
|
|
||||||
bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
||||||
const RealizeInstancesOptions &options,
|
const RealizeInstancesOptions &options,
|
||||||
const SpecificInstancesChoice &chosen_instances)
|
const VariedDepthOption &varied_depth_option)
|
||||||
{
|
{
|
||||||
/* The algorithm works in three steps:
|
/* The algorithm works in three steps:
|
||||||
* 1. Preprocess each unique geometry that is instanced (e.g. each `Mesh`).
|
* 1. Preprocess each unique geometry that is instanced (e.g. each `Mesh`).
|
||||||
@ -1995,18 +1995,18 @@ bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
|||||||
|
|
||||||
bke::GeometrySet not_to_realize_set;
|
bke::GeometrySet not_to_realize_set;
|
||||||
propagate_instances_to_keep(
|
propagate_instances_to_keep(
|
||||||
geometry_set, chosen_instances.selection, not_to_realize_set, options.propagation_info);
|
geometry_set, varied_depth_option.selection, not_to_realize_set, options.propagation_info);
|
||||||
|
|
||||||
if (options.keep_original_ids) {
|
if (options.keep_original_ids) {
|
||||||
remove_id_attribute_from_instances(geometry_set);
|
remove_id_attribute_from_instances(geometry_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
AllPointCloudsInfo all_pointclouds_info = preprocess_pointclouds(
|
AllPointCloudsInfo all_pointclouds_info = preprocess_pointclouds(
|
||||||
geometry_set, options, chosen_instances);
|
geometry_set, options, varied_depth_option);
|
||||||
AllMeshesInfo all_meshes_info = preprocess_meshes(geometry_set, options, chosen_instances);
|
AllMeshesInfo all_meshes_info = preprocess_meshes(geometry_set, options, varied_depth_option);
|
||||||
AllCurvesInfo all_curves_info = preprocess_curves(geometry_set, options, chosen_instances);
|
AllCurvesInfo all_curves_info = preprocess_curves(geometry_set, options, varied_depth_option);
|
||||||
OrderedAttributes all_instance_attributes = gather_generic_instance_attributes_to_propagate(
|
OrderedAttributes all_instance_attributes = gather_generic_instance_attributes_to_propagate(
|
||||||
geometry_set, options, chosen_instances);
|
geometry_set, options, varied_depth_option);
|
||||||
|
|
||||||
const bool create_id_attribute = all_pointclouds_info.create_id_attribute ||
|
const bool create_id_attribute = all_pointclouds_info.create_id_attribute ||
|
||||||
all_meshes_info.create_id_attribute ||
|
all_meshes_info.create_id_attribute ||
|
||||||
@ -2017,8 +2017,8 @@ bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
|||||||
all_curves_info,
|
all_curves_info,
|
||||||
all_instance_attributes,
|
all_instance_attributes,
|
||||||
create_id_attribute,
|
create_id_attribute,
|
||||||
chosen_instances.selection,
|
varied_depth_option.selection,
|
||||||
chosen_instances.depths,
|
varied_depth_option.depths,
|
||||||
temporary_arrays};
|
temporary_arrays};
|
||||||
|
|
||||||
if (not_to_realize_set.has_instances()) {
|
if (not_to_realize_set.has_instances()) {
|
||||||
@ -2033,7 +2033,7 @@ bke::GeometrySet realize_instances(bke::GeometrySet geometry_set,
|
|||||||
|
|
||||||
gather_realize_tasks_recursive(gather_info,
|
gather_realize_tasks_recursive(gather_info,
|
||||||
0,
|
0,
|
||||||
SpecificInstancesChoice::MAX_DEPTH,
|
VariedDepthOption::MAX_DEPTH,
|
||||||
geometry_set,
|
geometry_set,
|
||||||
transform,
|
transform,
|
||||||
attribute_fallbacks);
|
attribute_fallbacks);
|
||||||
|
@ -65,15 +65,15 @@ static void node_geo_exec(GeoNodeExecParams params)
|
|||||||
evaluator.set_selection(selection_field_overrided);
|
evaluator.set_selection(selection_field_overrided);
|
||||||
evaluator.evaluate();
|
evaluator.evaluate();
|
||||||
|
|
||||||
geometry::SpecificInstancesChoice chosen_instances;
|
geometry::VariedDepthOption varied_depth_option;
|
||||||
chosen_instances.depths = evaluator.get_evaluated<int>(evaluated_depth_index);
|
varied_depth_option.depths = evaluator.get_evaluated<int>(evaluated_depth_index);
|
||||||
chosen_instances.selection = evaluator.get_evaluated_selection_as_mask();
|
varied_depth_option.selection = evaluator.get_evaluated_selection_as_mask();
|
||||||
|
|
||||||
geometry::RealizeInstancesOptions options;
|
geometry::RealizeInstancesOptions options;
|
||||||
options.keep_original_ids = false;
|
options.keep_original_ids = false;
|
||||||
options.realize_instance_attributes = true;
|
options.realize_instance_attributes = true;
|
||||||
options.propagation_info = params.get_output_propagation_info("Geometry");
|
options.propagation_info = params.get_output_propagation_info("Geometry");
|
||||||
geometry_set = geometry::realize_instances(geometry_set, options, chosen_instances);
|
geometry_set = geometry::realize_instances(geometry_set, options, varied_depth_option);
|
||||||
params.set_output("Geometry", std::move(geometry_set));
|
params.set_output("Geometry", std::move(geometry_set));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user