Blender V4.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
9#include <cmath>
10
11#include "BLI_math_vector.h"
12
13#include "node_texture_util.hh"
14
16 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
17 {SOCK_FLOAT, N_("Turns"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE},
18 {SOCK_VECTOR, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION},
19 {-1, ""},
20};
21
23 {SOCK_RGBA, N_("Color")},
24 {-1, ""},
25};
26
27static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
28{
29 float para[3];
30 float perp[3];
31 float cp[3];
32
33 float cos_a = cosf(a * float(2 * M_PI));
34 float sin_a = sinf(a * float(2 * M_PI));
35
36 /* `x' = xcosa + n(n.x)(1-cosa) + (x*n)sina`. */
37
38 mul_v3_v3fl(perp, co, cos_a);
39 mul_v3_v3fl(para, ax, dot_v3v3(co, ax) * (1 - cos_a));
40
41 cross_v3_v3v3(cp, ax, co);
42 mul_v3_fl(cp, sin_a);
43
44 new_co[0] = para[0] + perp[0] + cp[0];
45 new_co[1] = para[1] + perp[1] + cp[1];
46 new_co[2] = para[2] + perp[2] + cp[2];
47}
48
49static void colorfn(float *out, TexParams *p, bNode * /*node*/, bNodeStack **in, short thread)
50{
51 float new_co[3], new_dxt[3], new_dyt[3], a, ax[3];
52
53 a = tex_input_value(in[1], p, thread);
54 tex_input_vec(ax, in[2], p, thread);
55
56 rotate(new_co, a, ax, p->co);
57 if (p->osatex) {
58 rotate(new_dxt, a, ax, p->dxt);
59 rotate(new_dyt, a, ax, p->dyt);
60 }
61
62 {
63 TexParams np = *p;
64 np.co = new_co;
65 np.dxt = new_dxt;
66 np.dyt = new_dyt;
67 tex_input_rgba(out, in[0], &np, thread);
68 }
69}
70static void exec(void *data,
71 int /*thread*/,
72 bNode *node,
73 bNodeExecData *execdata,
74 bNodeStack **in,
75 bNodeStack **out)
76{
77 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
78}
79
81{
82 static blender::bke::bNodeType ntype;
83
84 tex_node_type_base(&ntype, TEX_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT);
85 blender::bke::node_type_socket_templates(&ntype, inputs, outputs);
86 ntype.exec_fn = exec;
87
89}
#define NODE_CLASS_DISTORT
Definition BKE_node.hh:412
#define M_PI
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
@ PROP_DIRECTION
Definition RNA_types.hh:165
@ PROP_NONE
Definition RNA_types.hh:136
#define sinf(x)
#define cosf(x)
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:4570
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
void register_node_type_tex_rotate()
static void colorfn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void tex_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
const float * co
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
#define N_(msgid)