2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spnode
|
2012-08-01 19:11:17 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
#include <numeric>
|
|
|
|
|
|
2023-06-09 12:56:55 +02:00
|
|
|
#include "AS_asset_representation.hh"
|
2023-03-16 15:40:31 +01:00
|
|
|
|
2012-11-04 11:57:49 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2021-03-15 14:57:00 +00:00
|
|
|
#include "DNA_collection_types.h"
|
2012-08-01 19:11:17 +00:00
|
|
|
#include "DNA_node_types.h"
|
2021-03-15 14:57:00 +00:00
|
|
|
#include "DNA_texture_types.h"
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2012-11-04 11:57:49 +00:00
|
|
|
#include "BLI_listbase.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_geom.h"
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-10-26 17:32:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
|
#include "BKE_image.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2012-08-01 19:11:17 +00:00
|
|
|
#include "BKE_main.h"
|
2023-05-15 15:14:22 +02:00
|
|
|
#include "BKE_node.hh"
|
2022-09-03 14:12:55 -05:00
|
|
|
#include "BKE_node_runtime.hh"
|
2021-12-21 15:18:56 +01:00
|
|
|
#include "BKE_node_tree_update.h"
|
2012-08-01 19:11:17 +00:00
|
|
|
#include "BKE_report.h"
|
2017-03-22 12:00:33 +03:00
|
|
|
#include "BKE_scene.h"
|
|
|
|
|
#include "BKE_texture.h"
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_build.hh"
|
2021-04-09 15:10:27 +01:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_asset.hh"
|
2023-09-11 08:20:26 -04:00
|
|
|
#include "ED_asset_menu_utils.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_node.hh" /* own include */
|
|
|
|
|
#include "ED_render.hh"
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.hh"
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
|
|
|
|
#include "RNA_define.hh"
|
|
|
|
|
#include "RNA_enum_types.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
|
|
|
|
#include "WM_types.hh"
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_view2d.hh"
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2021-11-12 12:12:27 -06:00
|
|
|
#include "node_intern.hh" /* own include */
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2022-03-15 17:29:54 +11:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Utilities
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
static void position_node_based_on_mouse(bNode &node, const float2 &location)
|
|
|
|
|
{
|
2023-03-17 04:19:05 +01:00
|
|
|
node.locx = location.x - NODE_DY * 1.5f / UI_SCALE_FAC;
|
|
|
|
|
node.locy = location.y + NODE_DY * 0.5f / UI_SCALE_FAC;
|
2022-08-01 16:32:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bNode *add_node(const bContext &C, const StringRef idname, const float2 &location)
|
2012-08-01 19:11:17 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(&C);
|
|
|
|
|
Main &bmain = *CTX_data_main(&C);
|
2022-12-20 17:14:34 -06:00
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(node_tree);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
const std::string idname_str = idname;
|
|
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
bNode *node = nodeAddNode(&C, &node_tree, idname_str.c_str());
|
2013-03-18 16:34:57 +00:00
|
|
|
BLI_assert(node && node->typeinfo);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
position_node_based_on_mouse(*node, location);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-03-20 19:13:56 +01:00
|
|
|
nodeSetSelected(node, true);
|
2022-12-20 17:14:34 -06:00
|
|
|
ED_node_set_active(&bmain, &snode, &node_tree, node, nullptr);
|
2022-08-01 16:32:43 -05:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
ED_node_tree_propagate_change(&C, &bmain, &node_tree);
|
2022-08-01 16:32:43 -05:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bNode *add_static_node(const bContext &C, int type, const float2 &location)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(&C);
|
|
|
|
|
Main &bmain = *CTX_data_main(&C);
|
2022-12-20 17:14:34 -06:00
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2022-08-01 16:32:43 -05:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(node_tree);
|
2022-08-01 16:32:43 -05:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
bNode *node = nodeAddStaticNode(&C, &node_tree, type);
|
2022-08-01 16:32:43 -05:00
|
|
|
BLI_assert(node && node->typeinfo);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
position_node_based_on_mouse(*node, location);
|
|
|
|
|
|
|
|
|
|
nodeSetSelected(node, true);
|
2022-12-20 17:14:34 -06:00
|
|
|
ED_node_set_active(&bmain, &snode, &node_tree, node, nullptr);
|
2022-08-01 16:32:43 -05:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
ED_node_tree_propagate_change(&C, &bmain, &node_tree);
|
2012-08-01 19:11:17 +00:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add Reroute Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2023-03-19 07:03:01 +01:00
|
|
|
std::optional<float2> link_path_intersection(const bNodeLink &link, const Span<float2> path)
|
2012-08-01 19:11:17 +00:00
|
|
|
{
|
2022-09-02 15:43:53 -05:00
|
|
|
std::array<float2, NODE_LINK_RESOL + 1> coords;
|
2023-03-19 07:03:01 +01:00
|
|
|
node_link_bezier_points_evaluated(link, coords);
|
2022-09-02 15:43:53 -05:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
for (const int i : path.index_range().drop_back(1)) {
|
|
|
|
|
for (const int j : IndexRange(NODE_LINK_RESOL)) {
|
|
|
|
|
float2 result;
|
|
|
|
|
if (isect_seg_seg_v2_point(path[i], path[i + 1], coords[j], coords[j + 1], result) > 0) {
|
|
|
|
|
return result;
|
2017-05-19 22:18:54 +10:00
|
|
|
}
|
|
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2022-09-02 15:43:53 -05:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
return std::nullopt;
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
struct RerouteCutsForSocket {
|
|
|
|
|
/* The output socket's owner node. */
|
|
|
|
|
bNode *from_node;
|
|
|
|
|
/* Intersected links connected to the socket and their path intersection locations. */
|
|
|
|
|
Map<bNodeLink *, float2> links;
|
2021-06-02 17:19:36 +02:00
|
|
|
};
|
2012-11-04 11:57:49 +00:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
static int add_reroute_exec(bContext *C, wmOperator *op)
|
2012-11-04 11:57:49 +00:00
|
|
|
{
|
2022-09-03 14:12:55 -05:00
|
|
|
const ARegion ®ion = *CTX_wm_region(C);
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &ntree = *snode.edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
Vector<float2> path;
|
|
|
|
|
RNA_BEGIN (op->ptr, itemptr, "path") {
|
|
|
|
|
float2 loc_region;
|
|
|
|
|
RNA_float_get_array(&itemptr, "loc", loc_region);
|
|
|
|
|
float2 loc_view;
|
|
|
|
|
UI_view2d_region_to_view(®ion.v2d, loc_region.x, loc_region.y, &loc_view.x, &loc_view.y);
|
|
|
|
|
path.append(loc_view);
|
|
|
|
|
if (path.size() >= 256) {
|
2012-11-04 11:57:49 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-11-04 11:57:49 +00:00
|
|
|
}
|
2022-09-03 14:12:55 -05:00
|
|
|
RNA_END;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
if (path.is_empty()) {
|
|
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2012-11-04 11:57:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(ntree);
|
|
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
ntree.ensure_topology_cache();
|
|
|
|
|
const Vector<bNode *> frame_nodes = ntree.nodes_by_type("NodeFrame");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
2012-11-04 11:57:49 +00:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
/* All link "cuts" that start at a particular output socket. Deduplicating new reroutes per
|
|
|
|
|
* output socket is useful because it allows reusing reroutes for connected intersections.
|
2022-09-06 16:25:20 +10:00
|
|
|
* Further deduplication using the second map means we only have one cut per link. */
|
2022-09-03 14:12:55 -05:00
|
|
|
Map<bNodeSocket *, RerouteCutsForSocket> cuts_per_socket;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) {
|
2023-03-19 07:03:01 +01:00
|
|
|
if (node_link_is_hidden_or_dimmed(region.v2d, *link)) {
|
2022-09-03 14:12:55 -05:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-03-19 07:03:01 +01:00
|
|
|
const std::optional<float2> cut = link_path_intersection(*link, path);
|
2023-01-06 09:26:48 -05:00
|
|
|
if (!cut) {
|
2022-09-03 14:12:55 -05:00
|
|
|
continue;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2022-09-03 14:12:55 -05:00
|
|
|
RerouteCutsForSocket &from_cuts = cuts_per_socket.lookup_or_add_default(link->fromsock);
|
|
|
|
|
from_cuts.from_node = link->fromnode;
|
2023-01-06 09:26:48 -05:00
|
|
|
from_cuts.links.add(link, *cut);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
for (const auto item : cuts_per_socket.items()) {
|
|
|
|
|
const Map<bNodeLink *, float2> &cuts = item.value.links;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
bNode *reroute = nodeAddStaticNode(C, &ntree, NODE_REROUTE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
nodeAddLink(&ntree,
|
|
|
|
|
item.value.from_node,
|
|
|
|
|
item.key,
|
|
|
|
|
reroute,
|
|
|
|
|
static_cast<bNodeSocket *>(reroute->inputs.first));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
/* Reconnect links from the original output socket to the new reroute. */
|
|
|
|
|
for (bNodeLink *link : cuts.keys()) {
|
|
|
|
|
link->fromnode = reroute;
|
|
|
|
|
link->fromsock = static_cast<bNodeSocket *>(reroute->outputs.first);
|
|
|
|
|
BKE_ntree_update_tag_link_changed(&ntree);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
/* Place the new reroute at the average location of all connected cuts. */
|
2022-10-06 07:32:04 +02:00
|
|
|
const float2 insert_point = std::accumulate(
|
|
|
|
|
cuts.values().begin(), cuts.values().end(), float2(0)) /
|
|
|
|
|
cuts.size();
|
2023-03-17 04:19:05 +01:00
|
|
|
reroute->locx = insert_point.x / UI_SCALE_FAC;
|
|
|
|
|
reroute->locy = insert_point.y / UI_SCALE_FAC;
|
2022-09-03 14:12:55 -05:00
|
|
|
|
|
|
|
|
/* Attach the reroute node to frame nodes behind it. */
|
|
|
|
|
for (const int i : frame_nodes.index_range()) {
|
|
|
|
|
bNode *frame_node = frame_nodes.last(i);
|
2022-11-18 12:46:20 +01:00
|
|
|
if (BLI_rctf_isect_pt_v(&frame_node->runtime->totr, insert_point)) {
|
2022-11-18 11:20:13 +01:00
|
|
|
nodeAttachNode(&ntree, reroute, frame_node);
|
2022-09-03 14:12:55 -05:00
|
|
|
break;
|
|
|
|
|
}
|
2012-11-04 11:57:49 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-03 14:12:55 -05:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), &ntree);
|
|
|
|
|
return OPERATOR_FINISHED;
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_add_reroute(wmOperatorType *ot)
|
|
|
|
|
{
|
2013-01-27 07:23:58 +00:00
|
|
|
ot->name = "Add Reroute";
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->idname = "NODE_OT_add_reroute";
|
2013-02-28 15:31:20 +00:00
|
|
|
ot->description = "Add a reroute node";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->invoke = WM_gesture_lines_invoke;
|
|
|
|
|
ot->modal = WM_gesture_lines_modal;
|
|
|
|
|
ot->exec = add_reroute_exec;
|
|
|
|
|
ot->cancel = WM_gesture_lines_cancel;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* flags */
|
2021-09-17 12:09:26 +10:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_DEPENDS_ON_CURSOR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-16 16:11:04 +11:00
|
|
|
/* properties */
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
|
2021-06-02 17:19:36 +02:00
|
|
|
RNA_def_property_flag(prop, (PropertyFlag)(PROP_HIDDEN | PROP_SKIP_SAVE));
|
2012-08-01 19:11:17 +00:00
|
|
|
/* internal */
|
2019-09-26 14:31:48 +02:00
|
|
|
RNA_def_int(ot->srna, "cursor", WM_CURSOR_CROSS, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add Node Group Operator
|
|
|
|
|
* \{ */
|
2021-02-15 19:35:24 +01:00
|
|
|
|
2022-11-01 16:09:49 +01:00
|
|
|
static bool node_group_add_poll(const bNodeTree &node_tree,
|
|
|
|
|
const bNodeTree &node_group,
|
|
|
|
|
ReportList &reports)
|
2021-02-15 19:35:24 +01:00
|
|
|
{
|
2022-11-01 16:09:49 +01:00
|
|
|
if (node_group.type != node_tree.type) {
|
|
|
|
|
return false;
|
2021-02-15 19:35:24 +01:00
|
|
|
}
|
2021-04-12 18:43:23 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
const char *disabled_hint = nullptr;
|
2022-11-01 16:09:49 +01:00
|
|
|
if (!nodeGroupPoll(&node_tree, &node_group, &disabled_hint)) {
|
2021-04-12 18:43:23 +02:00
|
|
|
if (disabled_hint) {
|
2022-11-01 16:09:49 +01:00
|
|
|
BKE_reportf(&reports,
|
2021-04-12 18:43:23 +02:00
|
|
|
RPT_ERROR,
|
|
|
|
|
"Can not add node group '%s' to '%s':\n %s",
|
2022-11-01 16:09:49 +01:00
|
|
|
node_group.id.name + 2,
|
|
|
|
|
node_tree.id.name + 2,
|
2021-04-12 18:43:23 +02:00
|
|
|
disabled_hint);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-11-01 16:09:49 +01:00
|
|
|
BKE_reportf(&reports,
|
2021-04-12 18:43:23 +02:00
|
|
|
RPT_ERROR,
|
|
|
|
|
"Can not add node group '%s' to '%s'",
|
2022-11-01 16:09:49 +01:00
|
|
|
node_group.id.name + 2,
|
|
|
|
|
node_tree.id.name + 2);
|
2021-04-12 18:43:23 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-01 16:09:49 +01:00
|
|
|
return false;
|
2021-02-15 19:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-01 16:09:49 +01:00
|
|
|
return true;
|
2021-02-15 19:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_add_group_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
|
|
2022-11-01 16:09:49 +01:00
|
|
|
bNodeTree *node_group = reinterpret_cast<bNodeTree *>(
|
|
|
|
|
WM_operator_properties_id_lookup_from_name_or_session_uuid(bmain, op->ptr, ID_NT));
|
2022-08-01 16:32:43 -05:00
|
|
|
if (!node_group) {
|
2021-02-15 19:35:24 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2022-11-01 16:09:49 +01:00
|
|
|
if (!node_group_add_poll(*ntree, *node_group, *op->reports)) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2021-02-15 19:35:24 +01:00
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
|
|
|
|
|
2022-05-23 14:43:12 +02:00
|
|
|
const char *node_idname = node_group_idname(C);
|
|
|
|
|
if (node_idname[0] == '\0') {
|
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not determine type of group node");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
bNode *group_node = add_node(*C, node_idname, snode->runtime->cursor);
|
2021-02-15 19:35:24 +01:00
|
|
|
if (!group_node) {
|
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not add node group");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2023-08-24 15:12:00 +02:00
|
|
|
if (!RNA_boolean_get(op->ptr, "show_datablock_in_node")) {
|
|
|
|
|
/* By default, don't show the data-block selector since it's not usually necessary for assets.
|
|
|
|
|
*/
|
|
|
|
|
group_node->flag &= ~NODE_OPTIONS;
|
|
|
|
|
}
|
2021-02-15 19:35:24 +01:00
|
|
|
|
|
|
|
|
group_node->id = &node_group->id;
|
|
|
|
|
id_us_plus(group_node->id);
|
2021-12-28 11:21:07 +01:00
|
|
|
BKE_ntree_update_tag_node_property(snode->edittree, group_node);
|
2021-02-15 19:35:24 +01:00
|
|
|
|
|
|
|
|
nodeSetActive(ntree, group_node);
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, nullptr);
|
2023-09-04 12:46:22 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_ADDED, nullptr);
|
2022-05-24 10:05:52 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2021-02-15 19:35:24 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 14:43:12 +02:00
|
|
|
static bool node_add_group_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
if (!ED_operator_node_editable(C)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
if (snode->edittree->type == NTREE_CUSTOM) {
|
2022-11-01 16:09:49 +01:00
|
|
|
CTX_wm_operator_poll_msg_set(
|
|
|
|
|
C, "Adding node groups isn't supported for custom (Python defined) node trees");
|
2022-05-23 14:43:12 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-15 19:35:24 +01:00
|
|
|
static int node_add_group_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
ARegion *region = CTX_wm_region(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
|
|
/* Convert mouse coordinates to v2d space. */
|
|
|
|
|
UI_view2d_region_to_view(®ion->v2d,
|
|
|
|
|
event->mval[0],
|
|
|
|
|
event->mval[1],
|
|
|
|
|
&snode->runtime->cursor[0],
|
|
|
|
|
&snode->runtime->cursor[1]);
|
|
|
|
|
|
2023-03-17 04:19:05 +01:00
|
|
|
snode->runtime->cursor[0] /= UI_SCALE_FAC;
|
|
|
|
|
snode->runtime->cursor[1] /= UI_SCALE_FAC;
|
2021-02-15 19:35:24 +01:00
|
|
|
|
|
|
|
|
return node_add_group_exec(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_add_group(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add Node Group";
|
|
|
|
|
ot->description = "Add an existing node group to the current node editor";
|
|
|
|
|
ot->idname = "NODE_OT_add_group";
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_add_group_exec;
|
|
|
|
|
ot->invoke = node_add_group_invoke;
|
2022-05-23 14:43:12 +02:00
|
|
|
ot->poll = node_add_group_poll;
|
2021-02-15 19:35:24 +01:00
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
|
|
|
|
|
2022-05-24 17:00:59 +02:00
|
|
|
WM_operator_properties_id_lookup(ot, true);
|
2023-08-24 15:12:00 +02:00
|
|
|
|
2023-08-25 09:39:26 +10:00
|
|
|
PropertyRNA *prop = RNA_def_boolean(
|
|
|
|
|
ot->srna, "show_datablock_in_node", true, "Show the datablock selector in the node", "");
|
2023-08-24 15:12:00 +02:00
|
|
|
RNA_def_property_flag(prop, (PropertyFlag)(PROP_SKIP_SAVE | PROP_HIDDEN));
|
2021-02-15 19:35:24 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-11-01 16:09:49 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add Node Group Asset Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2023-03-16 15:40:31 +01:00
|
|
|
static bool add_node_group_asset(const bContext &C,
|
2023-07-04 14:46:19 +02:00
|
|
|
const asset_system::AssetRepresentation &asset,
|
2023-03-16 15:40:31 +01:00
|
|
|
ReportList &reports)
|
2022-11-01 16:09:49 +01:00
|
|
|
{
|
|
|
|
|
Main &bmain = *CTX_data_main(&C);
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(&C);
|
|
|
|
|
bNodeTree &edit_tree = *snode.edittree;
|
|
|
|
|
|
|
|
|
|
bNodeTree *node_group = reinterpret_cast<bNodeTree *>(
|
2023-07-11 14:18:11 +02:00
|
|
|
asset::asset_local_id_ensure_imported(bmain, asset));
|
2022-11-01 16:09:49 +01:00
|
|
|
if (!node_group) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!node_group_add_poll(edit_tree, *node_group, reports)) {
|
|
|
|
|
/* Remove the node group if it was newly appended but can't be added to the tree. */
|
|
|
|
|
id_us_plus(&node_group->id);
|
|
|
|
|
BKE_id_free_us(&bmain, node_group);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(&C), CTX_data_main(&C));
|
|
|
|
|
|
|
|
|
|
bNode *group_node = add_node(
|
|
|
|
|
C, ntreeTypeFind(node_group->idname)->group_idname, snode.runtime->cursor);
|
|
|
|
|
if (!group_node) {
|
|
|
|
|
BKE_report(&reports, RPT_WARNING, "Could not add node group");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* By default, don't show the data-block selector since it's not usually necessary for assets. */
|
|
|
|
|
group_node->flag &= ~NODE_OPTIONS;
|
|
|
|
|
|
|
|
|
|
group_node->id = &node_group->id;
|
|
|
|
|
id_us_plus(group_node->id);
|
|
|
|
|
BKE_ntree_update_tag_node_property(&edit_tree, group_node);
|
|
|
|
|
|
|
|
|
|
nodeSetActive(&edit_tree, group_node);
|
|
|
|
|
ED_node_tree_propagate_change(&C, &bmain, nullptr);
|
2023-09-04 12:46:22 +02:00
|
|
|
WM_event_add_notifier(&C, NC_NODE | NA_ADDED, nullptr);
|
2022-11-01 16:09:49 +01:00
|
|
|
DEG_relations_tag_update(&bmain);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
ARegion ®ion = *CTX_wm_region(C);
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
|
2023-09-11 08:20:26 -04:00
|
|
|
const asset_system::AssetRepresentation *asset =
|
|
|
|
|
asset::operator_asset_reference_props_get_asset_from_all_library(*C, *op->ptr, op->reports);
|
2023-03-16 15:40:31 +01:00
|
|
|
if (!asset) {
|
2022-11-01 16:09:49 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert mouse coordinates to v2d space. */
|
|
|
|
|
UI_view2d_region_to_view(®ion.v2d,
|
|
|
|
|
event->mval[0],
|
|
|
|
|
event->mval[1],
|
|
|
|
|
&snode.runtime->cursor[0],
|
|
|
|
|
&snode.runtime->cursor[1]);
|
|
|
|
|
|
2023-03-17 04:19:05 +01:00
|
|
|
snode.runtime->cursor /= UI_SCALE_FAC;
|
2022-11-01 16:09:49 +01:00
|
|
|
|
2023-06-09 12:56:55 +02:00
|
|
|
if (!add_node_group_asset(*C, *asset, *op->reports)) {
|
2022-11-01 16:09:49 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wmOperatorType *ot = WM_operatortype_find("NODE_OT_translate_attach_remove_on_cancel", true);
|
|
|
|
|
BLI_assert(ot);
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
|
|
|
|
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, nullptr);
|
|
|
|
|
WM_operator_properties_free(&ptr);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 19:11:27 +02:00
|
|
|
static std::string node_add_group_asset_get_description(bContext *C,
|
2023-09-11 08:20:26 -04:00
|
|
|
wmOperatorType * /*ot*/,
|
|
|
|
|
PointerRNA *values)
|
2023-02-22 17:33:04 +01:00
|
|
|
{
|
2023-09-11 08:20:26 -04:00
|
|
|
const asset_system::AssetRepresentation *asset =
|
|
|
|
|
asset::operator_asset_reference_props_get_asset_from_all_library(*C, *values, nullptr);
|
2023-03-16 15:40:31 +01:00
|
|
|
if (!asset) {
|
2023-08-11 19:11:27 +02:00
|
|
|
return "";
|
2023-02-22 17:33:04 +01:00
|
|
|
}
|
2023-07-04 14:46:19 +02:00
|
|
|
const AssetMetaData &asset_data = asset->get_metadata();
|
2023-02-22 17:33:04 +01:00
|
|
|
if (!asset_data.description) {
|
2023-08-11 19:11:27 +02:00
|
|
|
return "";
|
2023-02-22 17:33:04 +01:00
|
|
|
}
|
2023-08-11 19:11:27 +02:00
|
|
|
return TIP_(asset_data.description);
|
2023-02-22 17:33:04 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-01 16:09:49 +01:00
|
|
|
void NODE_OT_add_group_asset(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
ot->name = "Add Node Group Asset";
|
|
|
|
|
ot->description = "Add a node group asset to the active node tree";
|
|
|
|
|
ot->idname = "NODE_OT_add_group_asset";
|
|
|
|
|
|
|
|
|
|
ot->invoke = node_add_group_asset_invoke;
|
|
|
|
|
ot->poll = node_add_group_poll;
|
2023-02-22 17:33:04 +01:00
|
|
|
ot->get_description = node_add_group_asset_get_description;
|
2022-11-01 16:09:49 +01:00
|
|
|
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
2023-09-11 08:20:26 -04:00
|
|
|
|
|
|
|
|
asset::operator_asset_reference_props_register(*ot->srna);
|
2022-11-01 16:09:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2021-03-15 14:57:00 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add Node Object Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
static int node_add_object_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
|
|
2022-05-24 16:47:48 +02:00
|
|
|
Object *object = reinterpret_cast<Object *>(
|
|
|
|
|
WM_operator_properties_id_lookup_from_name_or_session_uuid(bmain, op->ptr, ID_OB));
|
|
|
|
|
|
|
|
|
|
if (!object) {
|
2021-03-15 14:57:00 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
|
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
bNode *object_node = add_static_node(*C, GEO_NODE_OBJECT_INFO, snode->runtime->cursor);
|
2021-03-15 14:57:00 +00:00
|
|
|
if (!object_node) {
|
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not add node object");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bNodeSocket *sock = nodeFindSocket(object_node, SOCK_IN, "Object");
|
|
|
|
|
if (!sock) {
|
2022-11-01 16:09:49 +01:00
|
|
|
BLI_assert_unreachable();
|
2021-03-15 14:57:00 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocketValueObject *socket_data = (bNodeSocketValueObject *)sock->default_value;
|
2021-03-15 14:57:00 +00:00
|
|
|
socket_data->value = object;
|
|
|
|
|
id_us_plus(&object->id);
|
|
|
|
|
|
|
|
|
|
nodeSetActive(ntree, object_node);
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, ntree);
|
2021-04-09 15:10:27 +01:00
|
|
|
DEG_relations_tag_update(bmain);
|
2021-03-24 13:57:27 +00:00
|
|
|
|
2021-03-15 14:57:00 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_add_object_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
ARegion *region = CTX_wm_region(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
|
|
/* Convert mouse coordinates to v2d space. */
|
|
|
|
|
UI_view2d_region_to_view(®ion->v2d,
|
|
|
|
|
event->mval[0],
|
|
|
|
|
event->mval[1],
|
|
|
|
|
&snode->runtime->cursor[0],
|
|
|
|
|
&snode->runtime->cursor[1]);
|
|
|
|
|
|
2023-03-17 04:19:05 +01:00
|
|
|
snode->runtime->cursor[0] /= UI_SCALE_FAC;
|
|
|
|
|
snode->runtime->cursor[1] /= UI_SCALE_FAC;
|
2021-03-15 14:57:00 +00:00
|
|
|
|
|
|
|
|
return node_add_object_exec(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool node_add_object_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
const SpaceNode *snode = CTX_wm_space_node(C);
|
2023-08-14 13:12:33 +02:00
|
|
|
return ED_operator_node_editable(C) && ELEM(snode->nodetree->type, NTREE_GEOMETRY);
|
2021-03-15 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_add_object(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add Node Object";
|
|
|
|
|
ot->description = "Add an object info node to the current node editor";
|
|
|
|
|
ot->idname = "NODE_OT_add_object";
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_add_object_exec;
|
|
|
|
|
ot->invoke = node_add_object_invoke;
|
|
|
|
|
ot->poll = node_add_object_poll;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
|
|
|
|
|
2022-05-24 16:47:48 +02:00
|
|
|
WM_operator_properties_id_lookup(ot, true);
|
2021-03-15 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add Node Collection Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
static int node_add_collection_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
2022-08-01 16:32:43 -05:00
|
|
|
bNodeTree &ntree = *snode.edittree;
|
2021-03-15 14:57:00 +00:00
|
|
|
|
2022-05-24 16:47:48 +02:00
|
|
|
Collection *collection = reinterpret_cast<Collection *>(
|
|
|
|
|
WM_operator_properties_id_lookup_from_name_or_session_uuid(bmain, op->ptr, ID_GR));
|
|
|
|
|
|
|
|
|
|
if (!collection) {
|
2021-03-15 14:57:00 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
|
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
bNode *collection_node = add_static_node(*C, GEO_NODE_COLLECTION_INFO, snode.runtime->cursor);
|
2021-03-15 14:57:00 +00:00
|
|
|
if (!collection_node) {
|
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not add node collection");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bNodeSocket *sock = nodeFindSocket(collection_node, SOCK_IN, "Collection");
|
|
|
|
|
if (!sock) {
|
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not find node collection socket");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocketValueCollection *socket_data = (bNodeSocketValueCollection *)sock->default_value;
|
2021-03-15 14:57:00 +00:00
|
|
|
socket_data->value = collection;
|
|
|
|
|
id_us_plus(&collection->id);
|
|
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
nodeSetActive(&ntree, collection_node);
|
|
|
|
|
ED_node_tree_propagate_change(C, bmain, &ntree);
|
2021-06-14 11:35:36 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2021-03-15 14:57:00 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_add_collection_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
ARegion *region = CTX_wm_region(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
|
|
/* Convert mouse coordinates to v2d space. */
|
|
|
|
|
UI_view2d_region_to_view(®ion->v2d,
|
|
|
|
|
event->mval[0],
|
|
|
|
|
event->mval[1],
|
|
|
|
|
&snode->runtime->cursor[0],
|
|
|
|
|
&snode->runtime->cursor[1]);
|
|
|
|
|
|
2023-03-17 04:19:05 +01:00
|
|
|
snode->runtime->cursor[0] /= UI_SCALE_FAC;
|
|
|
|
|
snode->runtime->cursor[1] /= UI_SCALE_FAC;
|
2021-03-15 14:57:00 +00:00
|
|
|
|
|
|
|
|
return node_add_collection_exec(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool node_add_collection_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
const SpaceNode *snode = CTX_wm_space_node(C);
|
2023-08-14 13:12:33 +02:00
|
|
|
return ED_operator_node_editable(C) && ELEM(snode->nodetree->type, NTREE_GEOMETRY);
|
2021-03-15 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_add_collection(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add Node Collection";
|
2022-12-09 16:00:42 -06:00
|
|
|
ot->description = "Add a collection info node to the current node editor";
|
2021-03-15 14:57:00 +00:00
|
|
|
ot->idname = "NODE_OT_add_collection";
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_add_collection_exec;
|
|
|
|
|
ot->invoke = node_add_collection_invoke;
|
|
|
|
|
ot->poll = node_add_collection_poll;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
|
|
|
|
|
2022-05-24 16:47:48 +02:00
|
|
|
WM_operator_properties_id_lookup(ot, true);
|
2021-03-15 14:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add File Node Operator
|
|
|
|
|
* \{ */
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2021-01-24 20:57:57 +01:00
|
|
|
static bool node_add_file_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
const SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
return ED_operator_node_editable(C) &&
|
2021-10-25 13:02:43 +02:00
|
|
|
ELEM(snode->nodetree->type, NTREE_SHADER, NTREE_TEXTURE, NTREE_COMPOSIT, NTREE_GEOMETRY);
|
2021-01-24 20:57:57 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
static int node_add_file_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2018-06-11 15:40:37 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
2013-03-18 18:25:05 +00:00
|
|
|
int type = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
Image *ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM);
|
2014-11-23 22:48:48 +01:00
|
|
|
if (!ima) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
switch (snode.nodetree->type) {
|
2012-08-01 19:11:17 +00:00
|
|
|
case NTREE_SHADER:
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
type = SH_NODE_TEX_IMAGE;
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
|
|
|
|
case NTREE_TEXTURE:
|
2013-03-18 16:34:57 +00:00
|
|
|
type = TEX_NODE_IMAGE;
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
|
|
|
|
case NTREE_COMPOSIT:
|
2013-03-18 16:34:57 +00:00
|
|
|
type = CMP_NODE_IMAGE;
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
2021-10-25 13:02:43 +02:00
|
|
|
case NTREE_GEOMETRY:
|
|
|
|
|
type = GEO_NODE_IMAGE_TEXTURE;
|
|
|
|
|
break;
|
2012-08-01 19:11:17 +00:00
|
|
|
default:
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-18 15:51:31 +01:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
bNode *node = add_static_node(*C, type, snode.runtime->cursor);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (!node) {
|
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not add an image node");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-25 13:02:43 +02:00
|
|
|
if (type == GEO_NODE_IMAGE_TEXTURE) {
|
|
|
|
|
bNodeSocket *image_socket = (bNodeSocket *)node->inputs.first;
|
|
|
|
|
bNodeSocketValueImage *socket_value = (bNodeSocketValueImage *)image_socket->default_value;
|
|
|
|
|
socket_value->value = ima;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
node->id = (ID *)ima;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-12-23 10:47:27 +05:00
|
|
|
/* When adding new image file via drag-drop we need to load imbuf in order
|
2023-01-03 20:02:01 -05:00
|
|
|
* to get proper image source. */
|
2014-12-23 10:47:27 +05:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
|
2021-06-02 17:19:36 +02:00
|
|
|
BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_RELOAD);
|
2014-12-23 10:47:27 +05:00
|
|
|
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode.edittree);
|
2021-06-14 11:35:36 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2012-08-01 19:11:17 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2012-08-01 19:11:17 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Convert mouse coordinates to `v2d` space. */
|
2021-01-19 16:43:08 -06:00
|
|
|
UI_view2d_region_to_view(®ion->v2d,
|
|
|
|
|
event->mval[0],
|
|
|
|
|
event->mval[1],
|
|
|
|
|
&snode->runtime->cursor[0],
|
|
|
|
|
&snode->runtime->cursor[1]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-17 04:19:05 +01:00
|
|
|
snode->runtime->cursor[0] /= UI_SCALE_FAC;
|
|
|
|
|
snode->runtime->cursor[1] /= UI_SCALE_FAC;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-20 14:49:14 +02:00
|
|
|
if (WM_operator_properties_id_lookup_is_set(op->ptr) ||
|
|
|
|
|
RNA_struct_property_is_set(op->ptr, "filepath"))
|
|
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
return node_add_file_exec(C, op);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-07-03 17:20:08 +02:00
|
|
|
return WM_operator_filesel(C, op, event);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_add_file(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add File Node";
|
|
|
|
|
ot->description = "Add a file node to the current node editor";
|
|
|
|
|
ot->idname = "NODE_OT_add_file";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_add_file_exec;
|
|
|
|
|
ot->invoke = node_add_file_invoke;
|
2021-01-24 20:57:57 +01:00
|
|
|
ot->poll = node_add_file_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-02-07 22:56:20 +11:00
|
|
|
WM_operator_properties_filesel(ot,
|
|
|
|
|
FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE,
|
|
|
|
|
FILE_SPECIAL,
|
|
|
|
|
FILE_OPENFILE,
|
|
|
|
|
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
|
|
|
|
|
FILE_DEFAULTDISPLAY,
|
2020-11-02 23:55:59 +01:00
|
|
|
FILE_SORT_DEFAULT);
|
2022-05-24 17:00:59 +02:00
|
|
|
WM_operator_properties_id_lookup(ot, true);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add Mask Node Operator
|
|
|
|
|
* \{ */
|
2013-07-22 19:24:39 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool node_add_mask_poll(bContext *C)
|
2013-07-22 19:24:39 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
|
|
return ED_operator_node_editable(C) && snode->nodetree->type == NTREE_COMPOSIT;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 13:03:03 +00:00
|
|
|
static int node_add_mask_exec(bContext *C, wmOperator *op)
|
2013-07-22 19:24:39 +00:00
|
|
|
{
|
2018-05-31 16:04:04 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
2013-07-22 19:24:39 +00:00
|
|
|
|
2022-05-24 16:47:48 +02:00
|
|
|
ID *mask = WM_operator_properties_id_lookup_from_name_or_session_uuid(bmain, op->ptr, ID_MSK);
|
2013-07-22 19:24:39 +00:00
|
|
|
if (!mask) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 15:51:31 +01:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
2013-07-22 19:24:39 +00:00
|
|
|
|
2022-08-01 16:32:43 -05:00
|
|
|
bNode *node = add_static_node(*C, CMP_NODE_MASK, snode.runtime->cursor);
|
2013-07-22 19:24:39 +00:00
|
|
|
|
|
|
|
|
if (!node) {
|
2013-07-23 06:58:05 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not add a mask node");
|
2013-07-22 19:24:39 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node->id = mask;
|
|
|
|
|
id_us_plus(mask);
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode.edittree);
|
2021-06-14 11:35:36 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2013-07-22 19:24:39 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_add_mask(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add Mask Node";
|
|
|
|
|
ot->description = "Add a mask node to the current node editor";
|
|
|
|
|
ot->idname = "NODE_OT_add_mask";
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
2013-09-05 13:03:03 +00:00
|
|
|
ot->exec = node_add_mask_exec;
|
2013-07-22 19:24:39 +00:00
|
|
|
ot->poll = node_add_mask_poll;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
2016-03-28 10:07:06 +02:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
2013-07-22 19:24:39 +00:00
|
|
|
|
2022-05-24 16:47:48 +02:00
|
|
|
WM_operator_properties_id_lookup(ot, true);
|
2013-07-22 19:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
2023-08-29 15:51:18 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Add Material Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
static int node_add_material_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
|
|
|
|
|
|
Material *material = reinterpret_cast<Material *>(
|
|
|
|
|
WM_operator_properties_id_lookup_from_name_or_session_uuid(bmain, op->ptr, ID_MA));
|
|
|
|
|
|
|
|
|
|
if (!material) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
|
|
|
|
|
|
|
|
|
bNode *material_node = add_static_node(*C, GEO_NODE_INPUT_MATERIAL, snode->runtime->cursor);
|
|
|
|
|
if (!material_node) {
|
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not add material");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
material_node->id = &material->id;
|
|
|
|
|
id_us_plus(&material->id);
|
|
|
|
|
|
|
|
|
|
ED_node_tree_propagate_change(C, bmain, ntree);
|
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_add_material_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
ARegion *region = CTX_wm_region(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
|
|
/* Convert mouse coordinates to v2d space. */
|
|
|
|
|
UI_view2d_region_to_view(®ion->v2d,
|
|
|
|
|
event->mval[0],
|
|
|
|
|
event->mval[1],
|
|
|
|
|
&snode->runtime->cursor[0],
|
|
|
|
|
&snode->runtime->cursor[1]);
|
|
|
|
|
|
|
|
|
|
snode->runtime->cursor[0] /= UI_SCALE_FAC;
|
|
|
|
|
snode->runtime->cursor[1] /= UI_SCALE_FAC;
|
|
|
|
|
|
|
|
|
|
return node_add_material_exec(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool node_add_material_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
const SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
return ED_operator_node_editable(C) && ELEM(snode->nodetree->type, NTREE_GEOMETRY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_add_material(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add Material";
|
|
|
|
|
ot->description = "Add a material node to the current node editor";
|
|
|
|
|
ot->idname = "NODE_OT_add_material";
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_add_material_exec;
|
|
|
|
|
ot->invoke = node_add_material_invoke;
|
|
|
|
|
ot->poll = node_add_material_poll;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
|
|
|
|
|
|
|
|
|
WM_operator_properties_id_lookup(ot, true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 10:57:17 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
2021-02-18 14:06:12 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name New Node Tree Operator
|
|
|
|
|
* \{ */
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
|
static int new_node_tree_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2013-03-18 18:25:05 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2013-03-18 16:34:57 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2012-08-01 19:11:17 +00:00
|
|
|
bNodeTree *ntree;
|
2023-09-06 00:48:50 +02:00
|
|
|
PointerRNA ptr;
|
2012-08-01 19:11:17 +00:00
|
|
|
PropertyRNA *prop;
|
2013-03-18 16:34:57 +00:00
|
|
|
const char *idname;
|
2015-01-01 23:26:03 +11:00
|
|
|
char treename_buf[MAX_ID_NAME - 2];
|
|
|
|
|
const char *treename;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "type")) {
|
|
|
|
|
prop = RNA_struct_find_property(op->ptr, "type");
|
|
|
|
|
RNA_property_enum_identifier(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &idname);
|
|
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else if (snode) {
|
2013-03-18 16:34:57 +00:00
|
|
|
idname = snode->tree_idname;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-15 23:12:49 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-05 18:14:35 +01:00
|
|
|
if (!ntreeTypeFind(idname)) {
|
|
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Node tree type %s undefined", idname);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 14:33:53 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "name")) {
|
2015-01-01 23:26:03 +11:00
|
|
|
RNA_string_get(op->ptr, "name", treename_buf);
|
|
|
|
|
treename = treename_buf;
|
2013-03-26 14:33:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-05 18:14:35 +01:00
|
|
|
const bNodeTreeType *type = ntreeTypeFind(idname);
|
|
|
|
|
treename = type->ui_name;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-22 16:00:59 +02:00
|
|
|
ntree = ntreeAddTree(bmain, treename, idname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Hook into UI. */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (prop) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* #RNA_property_pointer_set increases the user count, fixed here as the editor is the initial
|
|
|
|
|
* user. */
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&ntree->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-06 00:48:50 +02:00
|
|
|
PointerRNA idptr = RNA_id_pointer_create(&ntree->id);
|
2021-06-02 17:19:36 +02:00
|
|
|
RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
|
2012-08-01 19:11:17 +00:00
|
|
|
RNA_property_update(C, &ptr, prop);
|
|
|
|
|
}
|
|
|
|
|
else if (snode) {
|
|
|
|
|
snode->nodetree = ntree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
ED_node_tree_update(C);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-05 13:44:02 -05:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_ADDED, nullptr);
|
2022-09-28 15:08:09 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static const EnumPropertyItem *new_node_tree_type_itemf(bContext * /*C*/,
|
|
|
|
|
PointerRNA * /*ptr*/,
|
|
|
|
|
PropertyRNA * /*prop*/,
|
2017-10-18 15:07:26 +11:00
|
|
|
bool *r_free)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
return rna_node_tree_type_itemf(nullptr, nullptr, r_free);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
void NODE_OT_new_node_tree(wmOperatorType *ot)
|
|
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
PropertyRNA *prop;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "New Node Tree";
|
|
|
|
|
ot->idname = "NODE_OT_new_node_tree";
|
|
|
|
|
ot->description = "Create a new node tree";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = new_node_tree_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-08-25 12:57:52 +10:00
|
|
|
prop = RNA_def_enum(ot->srna, "type", rna_enum_dummy_NULL_items, 0, "Tree Type", "");
|
2013-03-18 16:34:57 +00:00
|
|
|
RNA_def_enum_funcs(prop, new_node_tree_type_itemf);
|
2012-08-01 19:11:17 +00:00
|
|
|
RNA_def_string(ot->srna, "name", "NodeTree", MAX_ID_NAME - 2, "Name", "");
|
|
|
|
|
}
|
2021-02-18 14:06:12 +11:00
|
|
|
|
|
|
|
|
/** \} */
|
2022-01-20 10:36:56 -06:00
|
|
|
|
|
|
|
|
} // namespace blender::ed::space_node
|