Blender V4.3
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
9#include "BLI_string.h"
10
11#include "node_texture_util.hh"
12#include "node_util.hh"
13
14/* **************** COMPOSITE ******************** */
16 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
17 {-1, ""},
18};
19
20/* applies to render pipeline */
21static void exec(void *data,
22 int /*thread*/,
23 bNode *node,
24 bNodeExecData * /*execdata*/,
25 bNodeStack **in,
26 bNodeStack ** /*out*/)
27{
28 TexCallData *cdata = (TexCallData *)data;
29 TexResult *target = cdata->target;
30
31 if (cdata->do_preview) {
34
35 tex_input_rgba(target->trgba, in[0], &params, cdata->thread);
36 }
37 else {
38 /* 0 means don't care, so just use first */
39 if (cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) {
42
43 tex_input_rgba(target->trgba, in[0], &params, cdata->thread);
44
45 target->tin = (target->trgba[0] + target->trgba[1] + target->trgba[2]) / 3.0f;
46 target->talpha = true;
47 }
48 }
49}
50
51static void unique_name(bNode *node)
52{
53 TexNodeOutput *tno = (TexNodeOutput *)node->storage;
54 char new_name[sizeof(tno->name)];
55 int new_len = 0;
56 int suffix;
57 bNode *i;
58 const char *name = tno->name;
59
60 new_name[0] = '\0';
61 i = node;
62 while (i->prev) {
63 i = i->prev;
64 }
65 for (; i; i = i->next) {
66 if (i == node || i->type != TEX_NODE_OUTPUT ||
67 !STREQ(name, ((TexNodeOutput *)(i->storage))->name))
68 {
69 continue;
70 }
71
72 if (new_name[0] == '\0') {
73 int len = strlen(name);
74 if (len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) {
75 new_len = len;
76 }
77 else {
78 suffix = 0;
79 new_len = len + 4;
80 if (new_len > (sizeof(tno->name) - 1)) {
81 new_len = (sizeof(tno->name) - 1);
82 }
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 == 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_cnew<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, TEX_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT);
142 blender::bke::node_type_socket_templates(&ntype, inputs, nullptr);
144 ntype.initfunc = init;
146 ntype.exec_fn = exec;
147
148 ntype.flag |= NODE_PREVIEW;
149 ntype.no_muting = true;
150
152}
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:405
#define STRNCPY(dst, src)
Definition BLI_string.h:593
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
void init()
OperationNode * node
int len
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:4570
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void params_from_cdata(TexParams *out, TexCallData *in)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
TexResult * target
int16_t custom1
struct bNode * prev
struct bNode * next
void * storage
int16_t type
Compact definition of a node socket.
Definition BKE_node.hh:103
Defines a node type.
Definition BKE_node.hh:218
NodeExecFunction exec_fn
Definition BKE_node.hh:316
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
#define N_(msgid)