Cleanup: Remove redundant node type lookup function
Using the topology map gives a constant time lookup, since it has a map of nodes per type. The collada code used the old function, but had been ifdef'd for four years, so it's removed here.
This commit is contained in:
@@ -39,7 +39,6 @@ bNodeTree *ntreeCopyTree(Main *bmain, const bNodeTree *ntree);
|
||||
|
||||
void ntreeFreeLocalNode(bNodeTree *ntree, bNode *node);
|
||||
|
||||
bNode *ntreeFindType(bNodeTree *ntree, int type);
|
||||
|
||||
void ntreeUpdateAllNew(Main *main);
|
||||
|
||||
|
||||
@@ -3736,22 +3736,8 @@ void ntreeRemoveSocketInterface(bNodeTree *ntree, bNodeSocket *sock)
|
||||
BKE_ntree_update_tag_interface(ntree);
|
||||
}
|
||||
|
||||
/* ************ find stuff *************** */
|
||||
|
||||
namespace blender::bke {
|
||||
|
||||
bNode *ntreeFindType(bNodeTree *ntree, const int type)
|
||||
{
|
||||
if (ntree) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
||||
if (node->type == type) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool ntree_contains_tree_exec(const bNodeTree *tree_to_search_in,
|
||||
const bNodeTree *tree_to_search_for,
|
||||
Set<const bNodeTree *> &already_passed)
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
#include "BKE_mesh_mapping.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
#include "BKE_node.hh"
|
||||
#include "BKE_node_runtime.hh"
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_report.h"
|
||||
#include "BKE_scene.h"
|
||||
@@ -6636,8 +6637,9 @@ static void default_paint_slot_color_get(int layer_type, Material *ma, float col
|
||||
case LAYER_ROUGHNESS:
|
||||
case LAYER_METALLIC: {
|
||||
bNodeTree *ntree = nullptr;
|
||||
bNode *in_node = ma ? blender::bke::ntreeFindType(ma->nodetree, SH_NODE_BSDF_PRINCIPLED) :
|
||||
nullptr;
|
||||
ma->nodetree->ensure_topology_cache();
|
||||
const blender::Span<bNode *> nodes = ma->nodetree->nodes_by_type("ShaderNodeBsdfPrincipled");
|
||||
bNode *in_node = nodes.is_empty() ? nullptr : nodes.first();
|
||||
if (!in_node) {
|
||||
/* An existing material or Principled BSDF node could not be found.
|
||||
* Copy default color values from a default Principled BSDF instead. */
|
||||
@@ -6741,7 +6743,9 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
|
||||
nodeSetActive(ntree, new_node);
|
||||
|
||||
/* Connect to first available principled BSDF node. */
|
||||
bNode *in_node = blender::bke::ntreeFindType(ntree, SH_NODE_BSDF_PRINCIPLED);
|
||||
ntree->ensure_topology_cache();
|
||||
const blender::Span<bNode *> bsdf_nodes = ntree->nodes_by_type("ShaderNodeBsdfPrincipled");
|
||||
bNode *in_node = bsdf_nodes.is_empty() ? nullptr : bsdf_nodes.first();
|
||||
bNode *out_node = new_node;
|
||||
|
||||
if (in_node != nullptr) {
|
||||
@@ -6777,7 +6781,9 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
|
||||
}
|
||||
else if (type == LAYER_DISPLACEMENT) {
|
||||
/* Connect to the displacement output socket */
|
||||
in_node = blender::bke::ntreeFindType(ntree, SH_NODE_OUTPUT_MATERIAL);
|
||||
const blender::Span<bNode *> output_nodes = ntree->nodes_by_type(
|
||||
"ShaderNodeOutputMaterial");
|
||||
in_node = output_nodes.is_empty() ? nullptr : output_nodes.first();
|
||||
|
||||
if (in_node != nullptr) {
|
||||
in_sock = nodeFindSocket(in_node, SOCK_IN, layer_type_items[type].name);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "BKE_node.hh"
|
||||
|
||||
#include "BKE_node_runtime.hh"
|
||||
#include "BKE_node_tree_update.h"
|
||||
|
||||
MaterialNode::MaterialNode(bContext *C, Material *ma, KeyImageMap &key_image_map)
|
||||
@@ -249,22 +250,24 @@ void MaterialNode::set_diffuse(COLLADAFW::ColorOrTexture &cot)
|
||||
|
||||
Image *MaterialNode::get_diffuse_image()
|
||||
{
|
||||
bNode *shader = blender::bke::ntreeFindType(ntree, SH_NODE_BSDF_PRINCIPLED);
|
||||
if (shader == nullptr) {
|
||||
ntree->ensure_topology_cache();
|
||||
const blender::Span<const bNode *> nodes = ntree->nodes_by_type("ShaderNodeBsdfPrincipled");
|
||||
if (nodes.is_empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
const bNode *shader = nodes.first();
|
||||
|
||||
bNodeSocket *in_socket = nodeFindSocket(shader, SOCK_IN, "Base Color");
|
||||
const bNodeSocket *in_socket = nodeFindSocket(shader, SOCK_IN, "Base Color");
|
||||
if (in_socket == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bNodeLink *link = in_socket->link;
|
||||
const bNodeLink *link = in_socket->link;
|
||||
if (link == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bNode *texture = link->fromnode;
|
||||
const bNode *texture = link->fromnode;
|
||||
if (texture == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1140,66 +1140,6 @@ static bNode *bc_add_node(bContext *C, bNodeTree *ntree, int node_type, int locx
|
||||
return bc_add_node(C, ntree, node_type, locx, locy, "");
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* experimental, probably not used */
|
||||
static bNodeSocket *bc_group_add_input_socket(bNodeTree *ntree,
|
||||
bNode *to_node,
|
||||
int to_index,
|
||||
std::string label)
|
||||
{
|
||||
bNodeSocket *to_socket = (bNodeSocket *)BLI_findlink(&to_node->inputs, to_index);
|
||||
|
||||
# if 0
|
||||
bNodeSocket *socket = ntreeAddSocketInterfaceFromSocket(ntree, to_node, to_socket);
|
||||
return socket;
|
||||
# endif
|
||||
|
||||
bNodeSocket *gsock = ntreeAddSocketInterfaceFromSocket(ntree, to_node, to_socket);
|
||||
bNode *inputGroup = ntreeFindType(ntree, NODE_GROUP_INPUT);
|
||||
node_group_input_verify(ntree, inputGroup, (ID *)ntree);
|
||||
bNodeSocket *newsock = node_group_input_find_socket(inputGroup, gsock->identifier);
|
||||
nodeAddLink(ntree, inputGroup, newsock, to_node, to_socket);
|
||||
strcpy(newsock->name, label.c_str());
|
||||
return newsock;
|
||||
}
|
||||
|
||||
static bNodeSocket *bc_group_add_output_socket(bNodeTree *ntree,
|
||||
bNode *from_node,
|
||||
int from_index,
|
||||
std::string label)
|
||||
{
|
||||
bNodeSocket *from_socket = (bNodeSocket *)BLI_findlink(&from_node->outputs, from_index);
|
||||
|
||||
# if 0
|
||||
bNodeSocket *socket = ntreeAddSocketInterfaceFromSocket(ntree, to_node, to_socket);
|
||||
return socket;
|
||||
# endif
|
||||
|
||||
bNodeSocket *gsock = ntreeAddSocketInterfaceFromSocket(ntree, from_node, from_socket);
|
||||
bNode *outputGroup = ntreeFindType(ntree, NODE_GROUP_OUTPUT);
|
||||
node_group_output_verify(ntree, outputGroup, (ID *)ntree);
|
||||
bNodeSocket *newsock = node_group_output_find_socket(outputGroup, gsock->identifier);
|
||||
nodeAddLink(ntree, from_node, from_socket, outputGroup, newsock);
|
||||
strcpy(newsock->name, label.c_str());
|
||||
return newsock;
|
||||
}
|
||||
|
||||
void bc_make_group(bContext *C, bNodeTree *ntree, std::map<std::string, bNode *> nmap)
|
||||
{
|
||||
bNode *gnode = node_group_make_from_selected(C, ntree, "ShaderNodeGroup", "ShaderNodeTree");
|
||||
bNodeTree *gtree = (bNodeTree *)gnode->id;
|
||||
|
||||
bc_group_add_input_socket(gtree, nmap["main"], 0, "Diffuse");
|
||||
bc_group_add_input_socket(gtree, nmap["emission"], 0, "Emission");
|
||||
bc_group_add_input_socket(gtree, nmap["mix"], 0, "Transparency");
|
||||
bc_group_add_input_socket(gtree, nmap["emission"], 1, "Emission");
|
||||
bc_group_add_input_socket(gtree, nmap["main"], 4, "Metallic");
|
||||
bc_group_add_input_socket(gtree, nmap["main"], 5, "Specular");
|
||||
|
||||
bc_group_add_output_socket(gtree, nmap["mix"], 0, "Shader");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void bc_node_add_link(
|
||||
bNodeTree *ntree, bNode *from_node, int from_index, bNode *to_node, int to_index)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user