Blender V5.0
node_texture_output.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "BLI_string.h"
12
13#include "node_texture_util.hh"
14#include "node_util.hh"
15
16/* **************** COMPOSITE ******************** */
18 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
19 {-1, ""},
20};
21
22/* applies to render pipeline */
23static void exec(void *data,
24 int /*thread*/,
25 bNode *node,
26 bNodeExecData * /*execdata*/,
27 bNodeStack **in,
28 bNodeStack ** /*out*/)
29{
30 TexCallData *cdata = (TexCallData *)data;
31 TexResult *target = cdata->target;
32
33 if (cdata->do_preview) {
36
37 tex_input_rgba(target->trgba, in[0], &params, cdata->thread);
38 }
39 else {
40 /* 0 means don't care, so just use first */
41 if (cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) {
44
45 tex_input_rgba(target->trgba, in[0], &params, cdata->thread);
46
47 target->tin = (target->trgba[0] + target->trgba[1] + target->trgba[2]) / 3.0f;
48 target->talpha = true;
49 }
50 }
51}
52
53static void unique_name(bNode *node)
54{
55 TexNodeOutput *tno = (TexNodeOutput *)node->storage;
56 char new_name[sizeof(tno->name)];
57 int new_len = 0;
58 int suffix;
59 bNode *i;
60 const char *name = tno->name;
61
62 new_name[0] = '\0';
63 i = node;
64 while (i->prev) {
65 i = i->prev;
66 }
67 for (; i; i = i->next) {
68 if (i == node || i->type_legacy != TEX_NODE_OUTPUT ||
69 !STREQ(name, ((TexNodeOutput *)(i->storage))->name))
70 {
71 continue;
72 }
73
74 if (new_name[0] == '\0') {
75 int len = strlen(name);
76 if (len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) {
77 new_len = len;
78 }
79 else {
80 suffix = 0;
81 new_len = len + 4;
82 new_len = std::min<ulong>(new_len, sizeof(tno->name) - 1);
83 }
84
85 STRNCPY(new_name, name);
86 name = new_name;
87 }
88 int name_ofs = new_len - 4;
89 BLI_snprintf(new_name + name_ofs, sizeof(new_name) - name_ofs, ".%03d", ++suffix);
90 }
91
92 if (new_name[0] != '\0') {
93 STRNCPY(tno->name, new_name);
94 }
95}
96
97static void assign_index(bNode *node)
98{
99 bNode *tnode;
100 int index = 1;
101
102 tnode = node;
103 while (tnode->prev) {
104 tnode = tnode->prev;
105 }
106
107check_index:
108 for (; tnode; tnode = tnode->next) {
109 if (tnode->type_legacy == TEX_NODE_OUTPUT && tnode != node) {
110 if (tnode->custom1 == index) {
111 index++;
112 goto check_index;
113 }
114 }
115 }
116
117 node->custom1 = index;
118}
119
120static void init(bNodeTree * /*ntree*/, bNode *node)
121{
122 TexNodeOutput *tno = MEM_callocN<TexNodeOutput>("TEX_output");
123 node->storage = tno;
124
125 STRNCPY(tno->name, "Default");
126 unique_name(node);
127 assign_index(node);
128}
129
130static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
131{
132 node_copy_standard_storage(dest_ntree, dest_node, src_node);
133 unique_name(dest_node);
134 assign_index(dest_node);
135}
136
138{
139 static blender::bke::bNodeType ntype;
140
141 tex_node_type_base(&ntype, "TextureNodeOutput", TEX_NODE_OUTPUT);
142 ntype.ui_name = "Output";
143 ntype.enum_name_legacy = "OUTPUT";
147 ntype.initfunc = init;
149 ntype.exec_fn = exec;
150
151 ntype.flag |= NODE_PREVIEW;
152 ntype.no_muting = true;
153
155}
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:448
#define TEX_NODE_OUTPUT
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define STREQ(a, b)
@ NODE_PREVIEW
@ SOCK_RGBA
BMesh const char void * data
void init()
#define in
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:5352
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5414
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static blender::bke::bNodeSocketTemplate inputs[]
static void init(bNodeTree *, bNode *node)
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
static void unique_name(bNode *node)
static void exec(void *data, int, bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack **)
void register_node_type_tex_output()
static void assign_index(bNode *node)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void params_from_cdata(TexParams *out, TexCallData *in)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
const char * name
TexResult * target
float tin
Definition RE_texture.h:59
float trgba[4]
Definition RE_texture.h:60
int16_t custom1
int16_t type_legacy
struct bNode * prev
struct bNode * next
void * storage
Compact definition of a node socket.
Definition BKE_node.hh:99
Defines a node type.
Definition BKE_node.hh:238
NodeExecFunction exec_fn
Definition BKE_node.hh:340
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
const char * enum_name_legacy
Definition BKE_node.hh:247
i
Definition text_draw.cc:230
uint len
#define N_(msgid)