Files
test2/source/blender/nodes/texture/nodes/node_texture_image.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
2.7 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2006 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup texnodes
2011-02-27 20:13:22 +00:00
*/
#include "BKE_image.hh"
#include "BLI_math_vector.h"
#include "BLI_threads.h"
2024-01-18 22:50:23 +02:00
#include "IMB_imbuf.hh"
#include "node_texture_util.hh"
#include "node_util.hh"
static blender::bke::bNodeSocketTemplate outputs[] = {
Nodes: Support storing socket link limits in bNodeSocketType Currently the link limit of sockets is stored in bNodeSocket->limit. This allows for a lot of flexibility, but is also very redundant. In every case I've had to deal with so far, it would have "more correct" to set the link limit per socket type and not per socket. I did not enforce this constraint yet, because the link limit is exposed in the Python API, which I did not want to break here. In the future it might even make sense to only support only three kinds of link limits: a) no links, b) at most one link, c) an arbitrary number links links. The other link limits usually don't work well with tools (e.g. which link should be removed when a new one is connected?) and is not used in practice. However, that is for another day. Eventually, I would like to get rid of bNodeSocket->limit completely and replace it either with fixed link limits or a callback in bNodeSocketType. This patch consists of three parts: **1. Support defining link limit in socket type** This introduces a new `nodeSocketLinkLimit` function that serves as an indirection to hide where the link limit of a socket is defined. **2. Define link limits for builtin sockets on socket type** Data sockets: one input, many outputs Virtual sockets: one input, one output Undefined sockets: many inputs, many outputs (to avoid that links are removed when the type of the socket is not known) **3. Remove `bNodeSocketTemplate->limit`** This wasn't used anymore after the second commit. Removing it simplifies socket definitions in hundreds of places and removes a lot of redundancy. Differential Revision: https://developer.blender.org/D7038 Reviewers: brecht
2020-03-06 12:20:05 +01:00
{SOCK_RGBA, N_("Image")},
{-1, ""},
};
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack ** /*in*/, short /*thread*/)
{
float x = p->co[0];
float y = p->co[1];
2013-05-27 07:57:17 +00:00
Image *ima = (Image *)node->id;
ImageUser *iuser = (ImageUser *)node->storage;
2013-05-27 07:57:17 +00:00
if (ima) {
2022-11-19 11:51:42 +01:00
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, nullptr);
2013-05-27 07:57:17 +00:00
if (ibuf) {
float xsize, ysize;
float xoff, yoff;
int px, py;
const float *result;
xsize = ibuf->x / 2;
ysize = ibuf->y / 2;
xoff = yoff = -1;
px = int((x - xoff) * xsize);
py = int((y - yoff) * ysize);
2019-04-22 13:31:31 +10:00
if ((!xsize) || (!ysize)) {
return;
2019-04-22 13:31:31 +10:00
}
if (!ibuf->float_buffer.data) {
BLI_thread_lock(LOCK_IMAGE);
if (!ibuf->float_buffer.data) {
IMB_float_from_byte(ibuf);
2019-04-22 13:31:31 +10:00
}
BLI_thread_unlock(LOCK_IMAGE);
}
2019-04-22 13:31:31 +10:00
while (px < 0) {
2013-05-27 07:57:17 +00:00
px += ibuf->x;
2019-04-22 13:31:31 +10:00
}
while (py < 0) {
2013-05-27 07:57:17 +00:00
py += ibuf->y;
2019-04-22 13:31:31 +10:00
}
while (px >= ibuf->x) {
2013-05-27 07:57:17 +00:00
px -= ibuf->x;
2019-04-22 13:31:31 +10:00
}
while (py >= ibuf->y) {
2013-05-27 07:57:17 +00:00
py -= ibuf->y;
2019-04-22 13:31:31 +10:00
}
result = ibuf->float_buffer.data + py * ibuf->x * 4 + px * 4;
copy_v4_v4(out, result);
2022-11-19 11:51:42 +01:00
BKE_image_release_ibuf(ima, ibuf, nullptr);
}
}
}
Merge of the PyNodes branch (aka "custom nodes") into trunk. PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
2013-03-18 16:34:57 +00:00
static void exec(void *data,
int /*thread*/,
Merge of the PyNodes branch (aka "custom nodes") into trunk. PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
2013-03-18 16:34:57 +00:00
bNode *node,
bNodeExecData *execdata,
bNodeStack **in,
bNodeStack **out)
{
tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
}
static void init(bNodeTree * /*ntree*/, bNode *node)
{
ImageUser *iuser = MEM_callocN<ImageUser>("node image user");
2013-05-27 07:57:17 +00:00
node->storage = iuser;
iuser->sfra = 1;
iuser->flag |= IMA_ANIM_ALWAYS;
}
void register_node_type_tex_image()
{
static blender::bke::bNodeType ntype;
tex_node_type_base(&ntype, "TextureNodeImage", TEX_NODE_IMAGE);
ntype.ui_name = "Image";
ntype.enum_name_legacy = "IMAGE";
ntype.nclass = NODE_CLASS_INPUT;
blender::bke::node_type_socket_templates(&ntype, nullptr, outputs);
ntype.initfunc = init;
blender::bke::node_type_storage(
ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
ntype.exec_fn = exec;
ntype.labelfunc = node_image_label;
ntype.flag |= NODE_PREVIEW;
blender::bke::node_register_type(ntype);
}