Blender V5.3
node_texture_rotate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10
11#include "BLI_math_vector_c.hh"
12
13#include "node_texture_util.hh"
14
15namespace blender {
16
18 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
19 {SOCK_FLOAT, N_("Turns"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE},
20 {SOCK_VECTOR, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION},
21 {-1, ""},
22};
23
25 {SOCK_RGBA, N_("Color")},
26 {-1, ""},
27};
28
29static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
30{
31 float para[3];
32 float perp[3];
33 float cp[3];
34
35 float cos_a = cosf(a * float(2 * M_PI));
36 float sin_a = sinf(a * float(2 * M_PI));
37
38 /* `x' = xcosa + n(n.x)(1-cosa) + (x*n)sina`. */
39
40 mul_v3_v3fl(perp, co, cos_a);
41 mul_v3_v3fl(para, ax, dot_v3v3(co, ax) * (1 - cos_a));
42
43 cross_v3_v3v3(cp, ax, co);
44 mul_v3_fl(cp, sin_a);
45
46 new_co[0] = para[0] + perp[0] + cp[0];
47 new_co[1] = para[1] + perp[1] + cp[1];
48 new_co[2] = para[2] + perp[2] + cp[2];
49}
50
51static void colorfn(float *out, TexParams *p, bNode * /*node*/, bNodeStack **in, short thread)
52{
53 float new_co[3], a, ax[3];
54
55 a = tex_input_value(in[1], p, thread);
56 tex_input_vec(ax, in[2], p, thread);
57
58 rotate(new_co, a, ax, p->co);
59
60 {
61 TexParams np = *p;
62 np.co = new_co;
63 tex_input_rgba(out, in[0], &np, thread);
64 }
65}
66static void exec(void *data,
67 int /*thread*/,
68 bNode *node,
69 bNodeExecData *execdata,
70 bNodeStack **in,
72{
73 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
74}
75
77{
78 static bke::bNodeType ntype;
79
80 tex_node_type_base(&ntype, "TextureNodeRotate"_ustr, TEX_NODE_ROTATE);
81 ntype.ui_name = "Rotate";
82 ntype.enum_name_legacy = "ROTATE";
85 ntype.exec_fn = exec;
86
88}
89
90} // namespace blender
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:486
#define TEX_NODE_ROTATE
#define M_PI
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:6134
BMesh Iterators.
void register_node_type_tex_rotate()
void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread)
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
static void colorfn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
BMesh const char void * data
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
static bke::bNodeSocketTemplate inputs[]
void tex_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
static bke::bNodeSocketTemplate outputs[]
@ PROP_DIRECTION
Definition RNA_types.hh:319
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
#define sinf
#define cosf
Compact definition of a node socket.
Definition BKE_node.hh:102
Defines a node type.
Definition BKE_node.hh:265
NodeExecFunction exec_fn
Definition BKE_node.hh:371
const char * enum_name_legacy
Definition BKE_node.hh:274
#define N_(msgid)