Fix T97375: changing node tree from Python is very slow

The issue was that the `NodeTreeRef` acceleration data structure was
rebuild much more often than necessary. That happened because the
Map Range node accidentally tagged the node tree for change even
though it did not actually change.

Differential Revision: https://developer.blender.org/D14842
This commit is contained in:
Jacques Lucke 2022-05-04 15:02:19 +02:00
parent d86d7c935e
commit 54b293237e
Notes: blender-bot 2023-02-13 22:20:49 +01:00
Referenced by issue #97375, Regression: Creating material node links in python is VERY slow in v3.1
1 changed files with 17 additions and 9 deletions

View File

@ -66,24 +66,32 @@ static void node_shader_update_map_range(bNodeTree *ntree, bNode *node)
const CustomDataType data_type = static_cast<CustomDataType>(storage.data_type);
const int type = (data_type == CD_PROP_FLOAT) ? SOCK_FLOAT : SOCK_VECTOR;
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
nodeSetSocketAvailability(ntree, socket, socket->type == type);
}
Array<bool> new_input_availability(BLI_listbase_count(&node->inputs));
Array<bool> new_output_availability(BLI_listbase_count(&node->outputs));
LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
nodeSetSocketAvailability(ntree, socket, socket->type == type);
int index;
LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->inputs, index) {
new_input_availability[index] = socket->type == type;
}
LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->outputs, index) {
new_output_availability[index] = socket->type == type;
}
if (storage.interpolation_type != NODE_MAP_RANGE_STEPPED) {
if (type == SOCK_FLOAT) {
bNodeSocket *sockSteps = (bNodeSocket *)BLI_findlink(&node->inputs, 5);
nodeSetSocketAvailability(ntree, sockSteps, false);
new_input_availability[5] = false;
}
else {
bNodeSocket *sockSteps = (bNodeSocket *)BLI_findlink(&node->inputs, 11);
nodeSetSocketAvailability(ntree, sockSteps, false);
new_input_availability[11] = false;
}
}
LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->inputs, index) {
nodeSetSocketAvailability(ntree, socket, new_input_availability[index]);
}
LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &node->outputs, index) {
nodeSetSocketAvailability(ntree, socket, new_output_availability[index]);
}
}
static void node_shader_init_map_range(bNodeTree *UNUSED(ntree), bNode *node)