Blender V5.3
versioning_common.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_function_ref.hh"
12#include "BLI_map.hh"
13#include "BLI_string_ref.hh"
14
15#include "BKE_fcurve.hh"
16
17#include "RNA_define.hh"
18
19#include "DNA_anim_types.h"
20#include "DNA_listBase.h"
21#include "DNA_node_types.h"
22
23namespace blender {
24
25struct ARegion;
26struct bNode;
27struct bNodeSocket;
28struct bNodeTree;
29struct ID;
30struct IDProperty;
31struct Main;
32struct ViewLayer;
33struct SceneRenderLayer;
34
49short do_versions_new_to_old_idcode_get(short id_code_new);
50
56ARegion *do_versions_add_region_if_not_found(ListBaseT<ARegion> *regionbase,
57 int region_type,
58 const char *allocname,
59 int link_after_region_type);
65ARegion *do_versions_ensure_region(ListBaseT<ARegion> *regionbase,
66 int region_type,
67 const char *allocname,
68 int link_after_region_type);
69
75ID *do_versions_rename_id(Main *bmain, short id_type, const char *name_src, const char *name_dst);
76
78
80 int node_type,
81 const char *old_name,
82 const char *new_name);
84 int node_type,
85 const char *old_name,
86 const char *new_name);
88 int node_type,
89 const char *old_name,
90 const char *new_name);
91
96
115bNode &version_node_add_empty(bNodeTree &ntree, const char *idname);
116
129 bke::bNodeType &ntype,
130 const char *idname,
131 const int16_t legacy_type,
132 const std::string &ui_name,
133 const std::string &ui_description,
134 const std::string &enum_name_legacy,
135 const short nclass,
136 const float width = 140.0f,
137 const float height = 100.0f,
138 const bool no_muting = false);
139
148 bNode &node,
149 eNodeSocketInOut in_out,
150 const char *idname,
151 const char *identifier);
153 bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b);
154
164
183 Main *bmain,
184 int node_tree_type, /* NTREE_....., e.g. NTREE_SHADER */
185 int node_type, /* SH_NODE_..., e.g. SH_NODE_BSDF_PRINCIPLED */
186 int socket_index_orig,
187 int socket_index_offset,
188 int total_number_of_sockets);
189
191 int node_tree_type,
192 const char *node_idname,
193 int socket_index_orig,
194 int socket_index_offset,
195 int total_number_of_sockets);
196
200void version_node_id(bNodeTree *ntree, int node_type, const char *new_name);
201
206
208
210 bNode *node,
211 int in_out,
212 int type,
213 int subtype,
214 const char *identifier,
215 const char *name);
216
218
224 const ListBaseT<bNodeSocket> &sockets,
225 const char *separator,
226 const std::optional<int> total = std::nullopt);
227
233ARegion *do_versions_add_region(int regiontype, const char *name);
234
236
238 bNode *node,
239 bNodeSocket *geometry_socket);
240
244
249
250float version_cycles_property_float(IDProperty *idprop, const char *name, float default_value);
251int version_cycles_property_int(IDProperty *idprop, const char *name, int default_value);
252void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value);
253bool version_cycles_property_boolean(IDProperty *idprop, const char *name, bool default_value);
254void version_cycles_property_boolean_set(IDProperty *idprop, const char *name, bool value);
255
257 bNode &old_node,
258 bNode &new_node,
261 bNodeTree *ntree,
262 FunctionRef<bool(bNode *)> check_node,
263 const char *socket_identifier,
264 FunctionRef<void(bNode *, bNodeSocket *)> update_input,
265 FunctionRef<void(bNode *, bNodeSocket *, bNode *, bNodeSocket *)> update_input_link);
266
268
275
276bool all_scenes_use(Main *bmain, const Span<const char *> engines);
277
283template<typename Function>
285 const PropertyType property_type,
286 const Function &function)
287{
288 /* Adjust key frames. */
289 if (fcurve->bezt) {
290 for (int i = 0; i < fcurve->totvert; i++) {
291 fcurve->bezt[i].vec[0][1] = function(fcurve->bezt[i].vec[0][1]);
292 fcurve->bezt[i].vec[1][1] = function(fcurve->bezt[i].vec[1][1]);
293 fcurve->bezt[i].vec[2][1] = function(fcurve->bezt[i].vec[2][1]);
294 }
295 }
296
297 /* Adjust baked key frames. */
298 if (fcurve->fpt) {
299 for (int i = 0; i < fcurve->totvert; i++) {
300 fcurve->fpt[i].vec[1] = function(fcurve->fpt[i].vec[1]);
301 }
302 }
303
304 /* Setup the flags based on the property type. */
306 switch (property_type) {
307 case PROP_FLOAT:
308 break;
309 case PROP_INT:
310 fcurve->flag |= FCURVE_INT_VALUES;
311 break;
312 default:
314 break;
315 }
316
317 /* Recalculate the automatic handles of the FCurve after adjustments. */
319}
320
321/* Gets the compositing node tree of the given scene. The deprecated node-tree member is returned
322 * for older versions before reusable node trees were introduced in bd61e69be5, while the new
323 * compositing_node_group is returned otherwise. */
324bNodeTree *version_get_scene_compositor_node_tree(Main *bmain, Scene *scene);
325
326/* Adds the given node group as a new scene compositor effect to the given scene. */
327void version_compositing_node_group_to_effect(Scene &scene, bNodeTree &node_group);
328
329} // namespace blender
These structs are the foundation for all linked lists in the library system.
Definition scene.h:133
BMesh Iterators.
bool version_node_ensure_storage_or_invalidate(bNode &node)
bool version_node_socket_is_used(bNodeSocket *sock)
void node_tree_relink_with_socket_id_map(bNodeTree &ntree, bNode &old_node, bNode &new_node, const Map< std::string, std::string > &map)
void version_node_socket_id_delim(bNodeSocket *socket)
StringRef legacy_socket_idname_to_socket_type(StringRef idname)
void sequencer_init_preview_region(ARegion *region)
float version_cycles_property_float(IDProperty *idprop, const char *name, float default_value)
void version_update_node_input(bNodeTree *ntree, FunctionRef< bool(bNode *)> check_node, const char *socket_identifier, FunctionRef< void(bNode *, bNodeSocket *)> update_input, FunctionRef< void(bNode *, bNodeSocket *, bNode *, bNodeSocket *)> update_input_link)
void version_cycles_property_boolean_set(IDProperty *idprop, const char *name, bool value)
ARegion * do_versions_add_region(int regiontype, const char *)
float * version_cycles_node_socket_float_value(bNodeSocket *socket)
float * version_cycles_node_socket_vector_value(bNodeSocket *socket)
IDProperty * version_cycles_properties_from_render_layer(SceneRenderLayer *render_layer)
bNode & version_node_add_empty(bNodeTree &ntree, const char *idname)
int version_cycles_property_int(IDProperty *idprop, const char *name, int default_value)
void version_socket_update_is_used(bNodeTree *ntree)
void version_node_output_socket_name(bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
void version_node_socket_identifier_set(bNodeSocket &socket, const StringRefNull identifier)
float * version_cycles_node_socket_rgba_value(bNodeSocket *socket)
ID * do_versions_rename_id(Main *bmain, const short id_type, const char *name_src, const char *name_dst)
void BKE_fcurve_handles_recalc(FCurve &fcu)
IDProperty * version_cycles_visibility_properties_from_ID(ID *id)
void version_system_idprops_nodes_generate(Main *bmain)
void version_node_id(bNodeTree *ntree, const int node_type, const char *new_name)
@ FCURVE_DISCRETE_VALUES
void version_cycles_property_int_set(IDProperty *idprop, const char *name, int value)
bool all_scenes_use(Main *bmain, const Span< const char * > engines)
void version_socket_identifier_suffixes_for_dynamic_types(const ListBaseT< bNodeSocket > &sockets, const char *separator, const std::optional< int > total)
bNode * version_eevee_output_node_get(bNodeTree *ntree, int16_t node_type)
void version_node_tree_clear_interface(bNodeTree &ntree)
ARegion * do_versions_ensure_region(ListBaseT< ARegion > *regionbase, int region_type, const char *, int link_after_region_type)
bool version_cycles_property_boolean(IDProperty *idprop, const char *name, bool default_value)
void version_compositing_node_group_to_effect(Scene &scene, bNodeTree &node_group)
void version_system_idprops_children_bones_generate(Main *bmain)
void version_node_input_socket_name(bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
static void adjust_fcurve_key_frame_values(FCurve *fcurve, const PropertyType property_type, const Function &function)
IDProperty * version_cycles_properties_from_ID(ID *id)
ARegion * do_versions_add_region_if_not_found(ListBaseT< ARegion > *regionbase, int region_type, const char *, int link_after_region_type)
void version_node_socket_index_animdata(Main *bmain, const int node_tree_type, const int node_type, const int socket_index_orig, const int socket_index_offset, const int total_number_of_sockets)
void add_realize_instances_before_socket(bNodeTree *ntree, bNode *node, bNodeSocket *geometry_socket)
IDProperty * version_cycles_properties_from_view_layer(ViewLayer *view_layer)
bNodeLink & version_node_add_link(bNodeTree &ntree, bNode &node_a, bNodeSocket &socket_a, bNode &node_b, bNodeSocket &socket_b)
short do_versions_new_to_old_idcode_get(const short id_code_new)
bNodeSocket * version_node_add_socket_if_not_exist(bNodeTree *ntree, bNode *node, int in_out, int type, int subtype, const char *identifier, const char *name)
bNodeTree * version_get_scene_compositor_node_tree(Main *bmain, Scene *scene)
bNode & version_node_add_unknown(bNodeTree &ntree, bke::bNodeType &ntype, const char *idname, const int16_t legacy_type, const std::string &ui_name, const std::string &ui_description, const std::string &enum_name_legacy, const short nclass, const float width, const float height, const bool no_muting)
void version_node_socket_name(bNodeTree *ntree, const int node_type, const char *old_name, const char *new_name)
signed short int16_t
Definition BKE_text.h:77
bNodeSocket & version_node_add_socket(bNodeTree &ntree, bNode &node, const eNodeSocketInOut in_out, const char *idname, const char *identifier)
void version_node_remove(bNodeTree &ntree, bNode &node)
void version_system_idprops_generate(Main *bmain)
eFCurve_Flags flag
unsigned int totvert
Defines a node type.
Definition BKE_node.hh:265