Blender V5.0
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
21struct SpaceNode;
22struct Object;
23
24namespace blender::nodes {
25
33 static int node_type;
34 static constexpr StringRefNull node_idname = "GeometryNodeBake";
35 static constexpr bool has_type = true;
36 static constexpr bool has_name = true;
38 static constexpr StringRefNull add_item = "NODE_OT_bake_node_item_add";
39 static constexpr StringRefNull remove_item = "NODE_OT_bake_node_item_remove";
40 static constexpr StringRefNull move_item = "NODE_OT_bake_node_item_move";
41 };
42 struct ui_idnames {
43 static constexpr StringRefNull list = "DATA_UL_bake_node_items";
44 };
45 struct rna_names {
46 static constexpr StringRefNull items = "bake_items";
47 static constexpr StringRefNull active_index = "active_index";
48 };
49
51 {
52 auto *storage = static_cast<NodeGeometryBake *>(node.storage);
53 return {&storage->items, &storage->items_num, &storage->active_index};
54 }
55
57 {
58 dst = src;
59 dst.name = BLI_strdup_null(dst.name);
60 }
61
63 {
64 MEM_SAFE_FREE(item->name);
65 }
66
67 static void blend_write_item(BlendWriter *writer, const ItemT &item);
68 static void blend_read_data_item(BlendDataReader *reader, ItemT &item);
69
74
75 static char **get_name(NodeGeometryBakeItem &item)
76 {
77 return &item.name;
78 }
79
80 static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
81 {
82 return SimulationItemsAccessor::supports_socket_type(socket_type, ntree_type);
83 }
84
87 const eNodeSocketDatatype socket_type,
88 const char *name)
89 {
90 auto *storage = static_cast<NodeGeometryBake *>(node.storage);
91 item.socket_type = socket_type;
92 item.identifier = storage->next_identifier++;
94 }
95
96 static std::string socket_identifier_for_item(const NodeGeometryBakeItem &item)
97 {
98 return "Item_" + std::to_string(item.identifier);
99 }
100};
101
103 const bNode *node;
109 std::optional<IndexRange> baked_range;
110 std::optional<IndexRange> frame_range;
113 std::optional<NodesModifierBakeTarget> bake_target;
115};
116
117[[nodiscard]] bool get_bake_draw_context(const bContext *C,
118 const bNode &node,
119 BakeDrawContext &r_ctx);
120
121std::string get_baked_string(const BakeDrawContext &ctx);
122
123std::optional<std::string> get_bake_state_string(const BakeDrawContext &ctx);
126 uiLayout *layout,
127 bool is_in_sidebar = false);
128
129} // namespace blender::nodes
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
Definition string.cc:46
eNodeSocketDatatype
#define MEM_SAFE_FREE(v)
#define C
Definition RandGen.cpp:29
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_common_bake_settings(bContext *C, BakeDrawContext &ctx, uiLayout *layout)
void draw_bake_button_row(const BakeDrawContext &ctx, uiLayout *layout, bool is_in_sidebar=false)
std::optional< std::string > get_bake_state_string(const BakeDrawContext &ctx)
std::string get_baked_string(const BakeDrawContext &ctx)
const char * name
void * storage
std::optional< NodesModifierBakeTarget > bake_target
std::optional< IndexRange > frame_range
const NodesModifierData * nmd
std::optional< IndexRange > baked_range
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)