Geometry Nodes: replace more maps with array
This is the same as 8b6777edc2 but for node groups instead
of built-in nodes.
This commit is contained in:
@@ -718,16 +718,21 @@ class LazyFunctionForGroupNode : public LazyFunction {
|
||||
* For every output bsocket there is a corresponding boolean input that indicates whether the
|
||||
* output is used.
|
||||
*/
|
||||
Map<int, int> lf_input_for_output_bsocket_usage_;
|
||||
const Span<int> lf_input_for_output_bsocket_usage_;
|
||||
/**
|
||||
* For every geometry output that can propagate attributes from an input, there is an attribute
|
||||
* set input. It indicates which attributes should be propagated to the output.
|
||||
*/
|
||||
Map<int, int> lf_input_for_attribute_propagation_to_output_;
|
||||
const Span<int> lf_input_for_attribute_propagation_to_output_;
|
||||
|
||||
LazyFunctionForGroupNode(const bNode &group_node,
|
||||
const GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
|
||||
: group_node_(group_node)
|
||||
const GeometryNodesLazyFunctionGraphInfo &lf_graph_info,
|
||||
MutableSpan<int> r_lf_input_for_output_bsocket_usage,
|
||||
MutableSpan<int> r_lf_input_for_attribute_propagation_to_output)
|
||||
: group_node_(group_node),
|
||||
lf_input_for_output_bsocket_usage_(r_lf_input_for_output_bsocket_usage),
|
||||
lf_input_for_attribute_propagation_to_output_(
|
||||
r_lf_input_for_attribute_propagation_to_output)
|
||||
{
|
||||
debug_name_ = group_node.name;
|
||||
allow_missing_requested_inputs_ = true;
|
||||
@@ -744,9 +749,8 @@ class LazyFunctionForGroupNode : public LazyFunction {
|
||||
|
||||
/* Add a boolean input for every output bsocket that indicates whether that socket is used. */
|
||||
for (const int i : group_node.output_sockets().index_range()) {
|
||||
lf_input_for_output_bsocket_usage_.add_new(
|
||||
i,
|
||||
graph_inputs.append_and_get_index(lf_graph_info.mapping.group_output_used_sockets[i]));
|
||||
r_lf_input_for_output_bsocket_usage[group_node.output_socket(i).index_in_all_outputs()] =
|
||||
graph_inputs.append_and_get_index(lf_graph_info.mapping.group_output_used_sockets[i]);
|
||||
inputs_.append_as("Output is Used", CPPType::get<bool>(), lf::ValueUsage::Maybe);
|
||||
}
|
||||
graph_inputs.extend(lf_graph_info.mapping.group_output_used_sockets);
|
||||
@@ -758,7 +762,8 @@ class LazyFunctionForGroupNode : public LazyFunction {
|
||||
const int lf_index = inputs_.append_and_get_index_as(
|
||||
"Attribute Set", CPPType::get<bke::AnonymousAttributeSet>(), lf::ValueUsage::Maybe);
|
||||
graph_inputs.append(lf_socket);
|
||||
lf_input_for_attribute_propagation_to_output_.add(output_index, lf_index);
|
||||
r_lf_input_for_attribute_propagation_to_output[group_node_.output_socket(output_index)
|
||||
.index_in_all_outputs()] = lf_index;
|
||||
}
|
||||
|
||||
Vector<const lf::InputSocket *> graph_outputs;
|
||||
@@ -842,20 +847,19 @@ class LazyFunctionForGroupNode : public LazyFunction {
|
||||
if (i < group_node_.input_sockets().size()) {
|
||||
return group_node_.input_socket(i).name;
|
||||
}
|
||||
for (const auto [bsocket_index, lf_socket_index] :
|
||||
lf_input_for_output_bsocket_usage_.items()) {
|
||||
if (i == lf_socket_index) {
|
||||
std::stringstream ss;
|
||||
ss << "'" << group_node_.output_socket(bsocket_index).name << "' output is used";
|
||||
return ss.str();
|
||||
for (const bNodeSocket *bsocket : group_node_.output_sockets()) {
|
||||
{
|
||||
const int lf_index = lf_input_for_output_bsocket_usage_[bsocket->index_in_all_outputs()];
|
||||
if (i == lf_index) {
|
||||
return StringRef("Use Output '") + bsocket->identifier + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto [bsocket_index, lf_index] :
|
||||
lf_input_for_attribute_propagation_to_output_.items()) {
|
||||
if (i == lf_index) {
|
||||
std::stringstream ss;
|
||||
ss << "Propagate to '" << group_node_.output_socket(bsocket_index).name << "'";
|
||||
return ss.str();
|
||||
{
|
||||
const int lf_index =
|
||||
lf_input_for_attribute_propagation_to_output_[bsocket->index_in_all_outputs()];
|
||||
if (i == lf_index) {
|
||||
return StringRef("Propagate to '") + bsocket->identifier + "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
return inputs_[i].debug_name;
|
||||
@@ -1467,7 +1471,11 @@ struct GeometryNodesLazyFunctionGraphBuilder {
|
||||
return;
|
||||
}
|
||||
|
||||
auto lazy_function = std::make_unique<LazyFunctionForGroupNode>(bnode, *group_lf_graph_info);
|
||||
auto lazy_function = std::make_unique<LazyFunctionForGroupNode>(
|
||||
bnode,
|
||||
*group_lf_graph_info,
|
||||
mapping_->lf_input_index_for_output_bsocket_usage,
|
||||
mapping_->lf_input_index_for_attribute_propagation_to_output);
|
||||
lf::FunctionNode &lf_node = lf_graph_->add_function(*lazy_function);
|
||||
|
||||
for (const int i : bnode.input_sockets().index_range()) {
|
||||
@@ -1487,15 +1495,25 @@ struct GeometryNodesLazyFunctionGraphBuilder {
|
||||
lf_graph_info_->num_inline_nodes_approximate +=
|
||||
group_lf_graph_info->num_inline_nodes_approximate;
|
||||
static const bool static_false = false;
|
||||
for (const int i : lazy_function->lf_input_for_output_bsocket_usage_.values()) {
|
||||
lf_node.input(i).set_default_value(&static_false);
|
||||
socket_usage_inputs_.add(&lf_node.input(i));
|
||||
}
|
||||
/* Keep track of attribute set inputs that need to be populated later. */
|
||||
for (const auto [output_index, lf_input_index] :
|
||||
lazy_function->lf_input_for_attribute_propagation_to_output_.items()) {
|
||||
attribute_set_propagation_map_.add(&bnode.output_socket(output_index),
|
||||
&lf_node.input(lf_input_index));
|
||||
for (const bNodeSocket *bsocket : bnode.output_sockets()) {
|
||||
{
|
||||
const int lf_input_index =
|
||||
mapping_->lf_input_index_for_output_bsocket_usage[bsocket->index_in_all_outputs()];
|
||||
if (lf_input_index != -1) {
|
||||
lf::InputSocket &lf_input = lf_node.input(lf_input_index);
|
||||
lf_input.set_default_value(&static_false);
|
||||
socket_usage_inputs_.add(&lf_input);
|
||||
}
|
||||
}
|
||||
{
|
||||
/* Keep track of attribute set inputs that need to be populated later. */
|
||||
const int lf_input_index = mapping_->lf_input_index_for_attribute_propagation_to_output
|
||||
[bsocket->index_in_all_outputs()];
|
||||
if (lf_input_index != -1) {
|
||||
lf::InputSocket &lf_input = lf_node.input(lf_input_index);
|
||||
attribute_set_propagation_map_.add(bsocket, &lf_input);
|
||||
}
|
||||
}
|
||||
}
|
||||
lf_graph_info_->functions.append(std::move(lazy_function));
|
||||
}
|
||||
@@ -2160,8 +2178,10 @@ struct GeometryNodesLazyFunctionGraphBuilder {
|
||||
}
|
||||
|
||||
for (const bNodeSocket *output_bsocket : bnode.output_sockets()) {
|
||||
const int output_index = output_bsocket->index();
|
||||
const int lf_input_index = fn.lf_input_for_output_bsocket_usage_.lookup(output_index);
|
||||
const int lf_input_index =
|
||||
mapping_
|
||||
->lf_input_index_for_output_bsocket_usage[output_bsocket->index_in_all_outputs()];
|
||||
BLI_assert(lf_input_index >= 0);
|
||||
lf::InputSocket &lf_socket = lf_group_node.input(lf_input_index);
|
||||
if (lf::OutputSocket *lf_output_is_used =
|
||||
socket_is_used_map_[output_bsocket->index_in_tree()]) {
|
||||
|
||||
Reference in New Issue
Block a user