Blender V5.3
NOD_geo_bake.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <optional>
8
10#include "DNA_node_types.h"
11
12#include "NOD_geo_simulation.hh"
13#include "NOD_socket_items.hh"
14
15#include "RNA_access.hh"
16
17#include "BLI_index_range.hh"
18
19namespace blender {
20
23struct SpaceNode;
24struct Object;
25
26namespace nodes {
27
35 static int node_type;
36 static constexpr StringRefNull node_idname = "GeometryNodeBake";
37 static constexpr bool has_type = true;
38 static constexpr bool has_name = true;
40 static constexpr StringRefNull add_item = "NODE_OT_bake_node_item_add";
41 static constexpr StringRefNull remove_item = "NODE_OT_bake_node_item_remove";
42 static constexpr StringRefNull move_item = "NODE_OT_bake_node_item_move";
43 };
44 struct ui_idnames {
45 static constexpr StringRefNull list = "DATA_UL_bake_node_items";
46 };
47 struct rna_names {
48 static constexpr StringRefNull items = "bake_items";
49 static constexpr StringRefNull active_index = "active_index";
50 };
51
53 {
54 auto *storage = static_cast<NodeGeometryBake *>(node.storage);
55 return {&storage->items, &storage->items_num, &storage->active_index};
56 }
57
59 {
60 dst = src;
61 dst.name = BLI_strdup_null(dst.name);
62 }
63
65 {
66 MEM_SAFE_DELETE(item->name);
67 }
68
69 static void blend_write_item(BlendWriter *writer, const ItemT &item);
70 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
71
73 {
74 return item.socket_type;
75 }
76
77 static char **get_name(NodeGeometryBakeItem &item)
78 {
79 return &item.name;
80 }
81
82 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
83 {
84 return SimulationItemsAccessor::supports_socket_type(socket_type, ntree_type);
85 }
86
89 const eNodeSocketDatatype socket_type,
90 const char *name)
91 {
92 auto *storage = static_cast<NodeGeometryBake *>(node.storage);
93 item.socket_type = socket_type;
94 item.identifier = storage->next_identifier++;
96 }
97
98 static std::string socket_identifier_for_item(const NodeGeometryBakeItem &item)
99 {
100 return "Item_" + std::to_string(item.identifier);
101 }
102};
103
105 const bNode *node;
111 std::optional<IndexRange> baked_range;
112 std::optional<IndexRange> frame_range;
115 std::optional<NodesModifierBakeTarget> bake_target;
117};
118
119[[nodiscard]] bool get_bake_draw_context(const bContext *C,
120 const bNode &node,
121 BakeDrawContext &r_ctx);
122
123std::string get_baked_string(const BakeDrawContext &ctx);
124
125std::optional<std::string> get_bake_state_string(const BakeDrawContext &ctx);
128 ui::Layout &layout,
129 bool is_in_sidebar = false);
130
131} // namespace nodes
132} // namespace blender
#define C
Definition RandGen.cpp:29
#define storage(slot, qualifiers)
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
bool get_bake_draw_context(const bContext *C, const bNode &node, BakeDrawContext &r_ctx)
void draw_bake_button_row(const BakeDrawContext &ctx, ui::Layout &layout, bool is_in_sidebar=false)
void draw_common_bake_settings(bContext *C, BakeDrawContext &ctx, ui::Layout &layout)
std::optional< std::string > get_bake_state_string(const BakeDrawContext &ctx)
std::string get_baked_string(const BakeDrawContext &ctx)
BMesh Iterators.
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
eNodeSocketDatatype socket_type
std::optional< NodesModifierBakeTarget > bake_target
std::optional< IndexRange > frame_range
const NodesModifierData * nmd
std::optional< IndexRange > baked_range
const NodesModifierBake * bake
static constexpr StringRefNull active_index
static constexpr StringRefNull items
static constexpr StringRefNull list
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static eNodeSocketDatatype get_socket_type(const NodeGeometryBakeItem &item)
static void copy_item(const NodeGeometryBakeItem &src, NodeGeometryBakeItem &dst)
static constexpr bool has_name
static std::string socket_identifier_for_item(const NodeGeometryBakeItem &item)
static socket_items::SocketItemsRef< NodeGeometryBakeItem > get_items_from_node(bNode &node)
static constexpr StringRefNull node_idname
static char ** get_name(NodeGeometryBakeItem &item)
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static void destruct_item(NodeGeometryBakeItem *item)
static constexpr bool has_type
static void init_with_socket_type_and_name(bNode &node, NodeGeometryBakeItem &item, const eNodeSocketDatatype socket_type, const char *name)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int)