Blender V5.3
rna_scene_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BLI_kdopbvh.hh"
12#include "BLI_path_utils.hh"
13
14#include "RNA_define.hh"
15#include "RNA_enum_types.hh"
16
17#include "DNA_scene_types.h"
18
19#include "rna_internal.hh" /* own include */
20
21#ifdef RNA_RUNTIME
22
23# include "DNA_screen_types.h"
24
25# include "BLI_math_matrix_c.hh"
26# include "BLI_math_vector_c.hh"
27
28# include "BKE_editmesh.hh"
29# include "BKE_global.hh"
30# include "BKE_image.hh"
31# include "BKE_image_format.hh"
32# include "BKE_main.hh"
33# include "BKE_scene.hh"
34# include "BKE_screen.hh"
35
36# include "DEG_depsgraph_query.hh"
37
38# include "ED_mesh.hh"
39# include "ED_transform.hh"
41# include "ED_uvedit.hh"
42
43# include "MOV_write.hh"
44
45# include "SEQ_sequencer.hh"
46
47# include "WM_api.hh"
48# include "WM_types.hh"
49
50# ifdef WITH_PYTHON
51# include "BPY_extern.hh"
52# endif
53
54namespace blender {
55
56static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subframe)
57{
58 double cfra = double(frame) + double(subframe);
59
60 CLAMP(cfra, MINAFRAME, MAXFRAME);
61 BKE_scene_frame_set(scene, cfra);
62
63# ifdef WITH_PYTHON
65# endif
66
67 for (ViewLayer *view_layer = scene->view_layers.first(); view_layer != nullptr;
68 view_layer = view_layer->next)
69 {
70 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
72 }
73
74# ifdef WITH_PYTHON
76# endif
77
79 for (bScreen *screen = bmain->screens.first(); screen;
80 screen = static_cast<bScreen *>(screen->id.next))
81 {
82 BKE_screen_view3d_scene_sync(screen, scene);
83 }
84 }
85
86 /* don't do notifier when we're rendering, avoid some viewport crashes
87 * redrawing while the data is being modified for render */
88 if (!G.is_rendering) {
89 /* can't use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
90 * BKE_scene_graph_update_for_newframe which will lose any un-keyed changes #24690. */
91 // WM_main_add_notifier(NC_SCENE|ND_FRAME, scene);
92
93 /* instead just redraw the views */
95 }
96}
97
98static void rna_Scene_uvedit_aspect(Scene * /*scene*/, Object *ob, float aspect[2])
99{
100 if ((ob->type == OB_MESH) && (ob->mode == OB_MODE_EDIT)) {
101 Mesh *mesh = id_cast<Mesh *>(ob->data);
102 if (EDBM_uv_check(mesh)) {
103 ED_uvedit_get_aspect(ob, aspect, aspect + 1);
104 return;
105 }
106 }
107
108 aspect[0] = aspect[1] = 1.0f;
109}
110
111static void rna_SceneRender_get_frame_path(ID *id,
112 RenderData *rd,
113 Main *bmain,
114 ReportList *reports,
115 int frame,
116 bool preview,
117 const char *view,
118 char *filepath)
119{
120 Scene *scene = reinterpret_cast<Scene *>(id);
121 const char *suffix = BKE_scene_multiview_view_suffix_get(rd, view);
122
123 /* avoid nullptr pointer */
124 if (!suffix) {
125 suffix = "";
126 }
127
128 if (BKE_imtype_is_movie(rd->im_format.imtype)) {
130 MOV_filepath_from_settings(filepath, scene, project, rd, preview != 0, suffix, reports);
131 });
132 }
133 else {
134 bke::path_templates::VariableMap template_variables;
136 BKE_add_template_variables_general(template_variables, &scene->id, project);
137 });
138 BKE_add_template_variables_for_render_path(template_variables, *scene);
139
140 const char *relbase = BKE_main_blendfile_path(bmain);
141
143 filepath,
144 rd->pic,
145 relbase,
146 &template_variables,
147 (frame == INT_MIN) ? rd->cfra : frame,
148 &rd->im_format,
149 (rd->scemode & R_EXTENSION) != 0,
150 true,
151 suffix);
152
153 if (!errors.is_empty()) {
154 BKE_report_path_template_errors(reports, RPT_ERROR, rd->pic, errors);
155 }
156 }
157}
158
159static void rna_Scene_ray_cast(Scene * /*scene*/,
160 Depsgraph *depsgraph,
161 const float origin[3],
162 const float direction[3],
163 float ray_dist,
164 bool *r_success,
165 float r_location[3],
166 float r_normal[3],
167 int *r_index,
168 Object **r_ob,
169 float r_obmat[16])
170{
171 float direction_unit[3];
172 normalize_v3_v3(direction_unit, direction);
174
175 ed::transform::SnapObjectParams snap_object_params{};
176 snap_object_params.snap_target_select = SCE_SNAP_TARGET_ALL;
177 snap_object_params.ignore_editmode_filtering = true;
178
180 depsgraph,
181 nullptr,
182 &snap_object_params,
183 origin,
184 direction_unit,
185 &ray_dist,
186 r_location,
187 r_normal,
188 r_index,
189 (const Object **)(r_ob),
190 (float (*)[4])r_obmat);
191
193
194 if (r_ob != nullptr && *r_ob != nullptr) {
195 *r_ob = DEG_get_original(*r_ob);
196 }
197
198 if (ret) {
199 *r_success = true;
200 }
201 else {
202 *r_success = false;
203
204 unit_m4(reinterpret_cast<float (*)[4]>(r_obmat));
205 zero_v3(r_location);
206 zero_v3(r_normal);
207 }
208}
209
210static void rna_Scene_sequencer_editing_free(Scene *scene)
211{
212 seq::editing_free(scene, true);
213}
214
215} // namespace blender
216
217#else
218
219namespace blender {
220
222{
223 FunctionRNA *func;
224 PropertyRNA *parm;
225
226 func = RNA_def_function(srna, "frame_set", "rna_Scene_frame_set");
228 func, "Set scene frame updating all objects and view layers immediately");
229 parm = RNA_def_int(
230 func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set", MINAFRAME, MAXFRAME);
233 func, "subframe", 0.0, 0.0, 1.0, "", "Subframe time, between 0.0 and 1.0", 0.0, 1.0);
235
236 func = RNA_def_function(srna, "uvedit_aspect", "rna_Scene_uvedit_aspect");
237 RNA_def_function_ui_description(func, "Get uv aspect for current object");
238 parm = RNA_def_pointer(func, "object", "Object", "", "Object");
241 func, "result", 2, nullptr, 0.0f, FLT_MAX, "", "aspect", 0.0f, FLT_MAX);
243 RNA_def_function_output(func, parm);
244
245 /* Ray Cast */
246 func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
247 RNA_def_function_ui_description(func, "Cast a ray onto evaluated geometry in world-space");
248
249 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "The current dependency graph");
251 /* ray start and end */
252 parm = RNA_def_float_vector(func, "origin", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
254 parm = RNA_def_float_vector(func, "direction", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
256 RNA_def_float(func,
257 "distance",
259 0.0,
261 "",
262 "Maximum distance",
263 0.0,
265 /* return location and normal */
266 parm = RNA_def_boolean(func, "result", false, "", "");
267 RNA_def_function_output(func, parm);
268 parm = RNA_def_float_vector(func,
269 "location",
270 3,
271 nullptr,
272 -FLT_MAX,
273 FLT_MAX,
274 "Location",
275 "The hit location of this ray cast",
276 -1e4,
277 1e4);
279 RNA_def_function_output(func, parm);
280 parm = RNA_def_float_vector(func,
281 "normal",
282 3,
283 nullptr,
284 -FLT_MAX,
285 FLT_MAX,
286 "Normal",
287 "The face normal at the ray cast hit location",
288 -1e4,
289 1e4);
291 RNA_def_function_output(func, parm);
292 parm = RNA_def_int(
293 func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
294 RNA_def_function_output(func, parm);
295 parm = RNA_def_pointer(func,
296 "object",
297 "Object",
298 "",
299 "The original (un-evaluated) object that was hit. "
300 "Note that ``location``, ``normal``, and ``index`` "
301 "correspond to the evaluated object's mesh.");
302 RNA_def_function_output(func, parm);
303 parm = RNA_def_float_matrix(func, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
304 RNA_def_function_output(func, parm);
305
306 /* Sequencer. */
307 func = RNA_def_function(srna, "sequence_editor_create", "seq::editing_ensure");
308 RNA_def_function_ui_description(func, "Ensure sequence editor is valid in this scene");
309 parm = RNA_def_pointer(func, "sequence_editor", "SequenceEditor", "", "Sequence editor data");
311 RNA_def_function_return(func, parm);
312
313 func = RNA_def_function(srna, "sequence_editor_clear", "rna_Scene_sequencer_editing_free");
314 RNA_def_function_ui_description(func, "Clear sequence editor in this scene");
315}
316
318{
319 FunctionRNA *func;
320 PropertyRNA *parm;
321
322 func = RNA_def_function(srna, "frame_path", "rna_SceneRender_get_frame_path");
325 func, "Return the absolute path to the filename to be written for a given frame");
326 RNA_def_int(func,
327 "frame",
328 INT_MIN,
329 INT_MIN,
330 INT_MAX,
331 "",
332 "Frame number to use, if unset the current frame will be used",
333 MINAFRAME,
334 MAXFRAME);
335 RNA_def_boolean(func, "preview", false, "Preview", "Use preview range");
337 "view",
338 nullptr,
339 FILE_MAX,
340 "View",
341 "The name of the view to use to replace the \"%\" chars");
342 parm = RNA_def_string_file_path(func,
343 "filepath",
344 nullptr,
345 FILE_MAX,
346 "File Path",
347 "The resulting filepath from the scenes render settings");
349 parm, PROP_THICK_WRAP, ParameterFlag(0)); /* needed for string return value */
350 RNA_def_function_output(func, parm);
351}
352
353} // namespace blender
354
355#endif
#define BVH_RAYCAST_DIST_MAX
#define FILE_MAX
#define BPy_BEGIN_ALLOW_THREADS
Definition BPY_extern.hh:52
#define BPy_END_ALLOW_THREADS
Definition BPY_extern.hh:56
#define MINAFRAME
#define MAXFRAME
#define NC_WINDOW
Definition WM_types.hh:388
#define CLAMP(a, b, c)
#define FLT_MAX
#define INT_MAX
bool snap_object_project_ray_ex(SnapObjectContext *sctx, Depsgraph *depsgraph, const View3D *v3d, const SnapObjectParams *params, const float ray_start[3], const float ray_normal[3], float *ray_depth, float r_loc[3], float r_no[3], int *r_index, const Object **r_ob, float r_obmat[4][4])
void snap_object_context_destroy(SnapObjectContext *sctx)
SnapObjectContext * snap_object_context_create()
void editing_free(Scene *scene, const bool do_id_user)
Definition sequencer.cc:321
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2953
void MOV_filepath_from_settings(char filepath[1024], const Scene *scene, const bke::BlenderProject *project, const RenderData *rd, bool preview, const char *suffix, ReportList *reports)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
void ED_uvedit_get_aspect(Object *obedit, float *r_aspx, float *r_aspy)
void BKE_add_template_variables_general(bke::path_templates::VariableMap &variables, const ID *path_owner_id, const bke::BlenderProject *project)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
@ FUNC_USE_REPORTS
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:980
@ FUNC_USE_MAIN
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void BKE_report_path_template_errors(ReportList *reports, eReportType report_type, StringRef path, Span< bke::path_templates::Error > errors)
const char * BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3390
Vector< bke::path_templates::Error > BKE_image_path_from_imformat(char *filepath, const char *base, const char *relbase, const bke::path_templates::VariableMap *template_variables, int frame, const ImageFormatData *im_format, bool use_ext, bool use_frames, const char *suffix)
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
bool EDBM_uv_check(const Mesh *mesh)
void BKE_scene_frame_set(Scene *scene, float frame)
Definition scene.cc:2600
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void BKE_add_template_variables_for_render_path(bke::path_templates::VariableMap &variables, const Scene &scene)
Global G
Definition blender.cc:57
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_api_scene_render(StructRNA *srna)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void unit_m4(float m[4][4])
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
MINLINE void zero_v3(float r[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
bool BKE_imtype_is_movie(char imtype)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
T * DEG_get_original(T *id)
void BKE_screen_view3d_scene_sync(bScreen *screen, Scene *scene)
Definition screen.cc:1249
bool BKE_scene_camera_switch_update(Scene *scene)
Definition scene.cc:2480
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
void RNA_api_scene(StructRNA *srna)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, const int rows, const int columns, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
@ PARM_REQUIRED
Definition RNA_types.hh:631
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
const NodeType * type
Definition graph/node.h:179