Blender V5.0
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 "BKE_editmesh.hh"
24# include "BKE_global.hh"
25# include "BKE_image.hh"
26# include "BKE_scene.hh"
27
28# include "DEG_depsgraph_query.hh"
29
30# include "ED_transform.hh"
32# include "ED_uvedit.hh"
33
34# include "MOV_write.hh"
35
36# ifdef WITH_PYTHON
37# include "BPY_extern.hh"
38# endif
39
40static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subframe)
41{
42 double cfra = double(frame) + double(subframe);
43
44 CLAMP(cfra, MINAFRAME, MAXFRAME);
45 BKE_scene_frame_set(scene, cfra);
46
47# ifdef WITH_PYTHON
49# endif
50
51 for (ViewLayer *view_layer = static_cast<ViewLayer *>(scene->view_layers.first);
52 view_layer != nullptr;
53 view_layer = view_layer->next)
54 {
55 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
57 }
58
59# ifdef WITH_PYTHON
61# endif
62
64 for (bScreen *screen = static_cast<bScreen *>(bmain->screens.first); screen;
65 screen = static_cast<bScreen *>(screen->id.next))
66 {
67 BKE_screen_view3d_scene_sync(screen, scene);
68 }
69 }
70
71 /* don't do notifier when we're rendering, avoid some viewport crashes
72 * redrawing while the data is being modified for render */
73 if (!G.is_rendering) {
74 /* can't use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
75 * BKE_scene_graph_update_for_newframe which will lose any un-keyed changes #24690. */
76 // WM_main_add_notifier(NC_SCENE|ND_FRAME, scene);
77
78 /* instead just redraw the views */
80 }
81}
82
83static void rna_Scene_uvedit_aspect(Scene * /*scene*/, Object *ob, float aspect[2])
84{
85 if ((ob->type == OB_MESH) && (ob->mode == OB_MODE_EDIT)) {
86 BMEditMesh *em;
88 if (EDBM_uv_check(em)) {
89 ED_uvedit_get_aspect(ob, aspect, aspect + 1);
90 return;
91 }
92 }
93
94 aspect[0] = aspect[1] = 1.0f;
95}
96
97static void rna_SceneRender_get_frame_path(ID *id,
98 RenderData *rd,
99 Main *bmain,
100 ReportList *reports,
101 int frame,
102 bool preview,
103 const char *view,
104 char *filepath)
105{
106 Scene *scene = reinterpret_cast<Scene *>(id);
107 const char *suffix = BKE_scene_multiview_view_suffix_get(rd, view);
108
109 /* avoid nullptr pointer */
110 if (!suffix) {
111 suffix = "";
112 }
113
115 MOV_filepath_from_settings(filepath, scene, rd, preview != 0, suffix, reports);
116 }
117 else {
119 BKE_add_template_variables_general(template_variables, &scene->id);
120 BKE_add_template_variables_for_render_path(template_variables, *scene);
121
122 const char *relbase = BKE_main_blendfile_path(bmain);
123
126 rd->pic,
127 relbase,
128 &template_variables,
129 (frame == INT_MIN) ? rd->cfra : frame,
130 &rd->im_format,
131 (rd->scemode & R_EXTENSION) != 0,
132 true,
133 suffix);
134
135 if (!errors.is_empty()) {
136 BKE_report_path_template_errors(reports, RPT_ERROR, rd->pic, errors);
137 }
138 }
139}
140
141static void rna_Scene_ray_cast(Scene *scene,
142 Depsgraph *depsgraph,
143 const float origin[3],
144 const float direction[3],
145 float ray_dist,
146 bool *r_success,
147 float r_location[3],
148 float r_normal[3],
149 int *r_index,
150 Object **r_ob,
151 float r_obmat[16])
152{
153 float direction_unit[3];
154 normalize_v3_v3(direction_unit, direction);
157
158 blender::ed::transform::SnapObjectParams snap_object_params{};
159 snap_object_params.snap_target_select = SCE_SNAP_TARGET_ALL;
160
162 depsgraph,
163 nullptr,
164 &snap_object_params,
165 origin,
166 direction_unit,
167 &ray_dist,
168 r_location,
169 r_normal,
170 r_index,
171 (const Object **)(r_ob),
172 (float (*)[4])r_obmat);
173
175
176 if (r_ob != nullptr && *r_ob != nullptr) {
177 *r_ob = DEG_get_original(*r_ob);
178 }
179
180 if (ret) {
181 *r_success = true;
182 }
183 else {
184 *r_success = false;
185
186 unit_m4((float (*)[4])r_obmat);
187 zero_v3(r_location);
188 zero_v3(r_normal);
189 }
190}
191
192static void rna_Scene_sequencer_editing_free(Scene *scene)
193{
194 blender::seq::editing_free(scene, true);
195}
196
197#else
198
200{
201 FunctionRNA *func;
202 PropertyRNA *parm;
203
204 func = RNA_def_function(srna, "frame_set", "rna_Scene_frame_set");
206 func, "Set scene frame updating all objects and view layers immediately");
207 parm = RNA_def_int(
208 func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set", MINAFRAME, MAXFRAME);
211 func, "subframe", 0.0, 0.0, 1.0, "", "Subframe time, between 0.0 and 1.0", 0.0, 1.0);
213
214 func = RNA_def_function(srna, "uvedit_aspect", "rna_Scene_uvedit_aspect");
215 RNA_def_function_ui_description(func, "Get uv aspect for current object");
216 parm = RNA_def_pointer(func, "object", "Object", "", "Object");
219 func, "result", 2, nullptr, 0.0f, FLT_MAX, "", "aspect", 0.0f, FLT_MAX);
221 RNA_def_function_output(func, parm);
222
223 /* Ray Cast */
224 func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
225 RNA_def_function_ui_description(func, "Cast a ray onto evaluated geometry in world-space");
226
227 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "The current dependency graph");
229 /* ray start and end */
230 parm = RNA_def_float_vector(func, "origin", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
232 parm = RNA_def_float_vector(func, "direction", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
234 RNA_def_float(func,
235 "distance",
237 0.0,
239 "",
240 "Maximum distance",
241 0.0,
243 /* return location and normal */
244 parm = RNA_def_boolean(func, "result", false, "", "");
245 RNA_def_function_output(func, parm);
246 parm = RNA_def_float_vector(func,
247 "location",
248 3,
249 nullptr,
250 -FLT_MAX,
251 FLT_MAX,
252 "Location",
253 "The hit location of this ray cast",
254 -1e4,
255 1e4);
257 RNA_def_function_output(func, parm);
258 parm = RNA_def_float_vector(func,
259 "normal",
260 3,
261 nullptr,
262 -FLT_MAX,
263 FLT_MAX,
264 "Normal",
265 "The face normal at the ray cast hit location",
266 -1e4,
267 1e4);
269 RNA_def_function_output(func, parm);
270 parm = RNA_def_int(
271 func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
272 RNA_def_function_output(func, parm);
273 parm = RNA_def_pointer(func, "object", "Object", "", "Ray cast object");
274 RNA_def_function_output(func, parm);
275 parm = RNA_def_float_matrix(func, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
276 RNA_def_function_output(func, parm);
277
278 /* Sequencer. */
279 func = RNA_def_function(srna, "sequence_editor_create", "blender::seq::editing_ensure");
280 RNA_def_function_ui_description(func, "Ensure sequence editor is valid in this scene");
281 parm = RNA_def_pointer(
282 func, "sequence_editor", "SequenceEditor", "", "New sequence editor data or nullptr");
283 RNA_def_function_return(func, parm);
284
285 func = RNA_def_function(srna, "sequence_editor_clear", "rna_Scene_sequencer_editing_free");
286 RNA_def_function_ui_description(func, "Clear sequence editor in this scene");
287}
288
290{
291 FunctionRNA *func;
292 PropertyRNA *parm;
293
294 func = RNA_def_function(srna, "frame_path", "rna_SceneRender_get_frame_path");
297 func, "Return the absolute path to the filename to be written for a given frame");
298 RNA_def_int(func,
299 "frame",
300 INT_MIN,
301 INT_MIN,
302 INT_MAX,
303 "",
304 "Frame number to use, if unset the current frame will be used",
305 MINAFRAME,
306 MAXFRAME);
307 RNA_def_boolean(func, "preview", false, "Preview", "Use preview range");
309 "view",
310 nullptr,
311 FILE_MAX,
312 "View",
313 "The name of the view to use to replace the \"%\" chars");
314 parm = RNA_def_string_file_path(func,
315 "filepath",
316 nullptr,
317 FILE_MAX,
318 "File Path",
319 "The resulting filepath from the scenes render settings");
321 parm, PROP_THICK_WRAP, ParameterFlag(0)); /* needed for string return value */
322 RNA_def_function_output(func, parm);
323}
324
325#endif
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:61
blender::Vector< blender::bke::path_templates::Error > BKE_image_path_from_imformat(char *filepath, const char *base, const char *relbase, const blender::bke::path_templates::VariableMap *template_variables, int frame, const ImageFormatData *im_format, bool use_ext, bool use_frames, const char *suffix)
bool BKE_imtype_is_movie(char imtype)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:887
void BKE_report_path_template_errors(ReportList *reports, eReportType report_type, blender::StringRef path, blender::Span< blender::bke::path_templates::Error > errors)
void BKE_add_template_variables_for_render_path(blender::bke::path_templates::VariableMap &variables, const Scene &scene)
void BKE_add_template_variables_general(blender::bke::path_templates::VariableMap &variables, const ID *path_owner_id)
@ RPT_ERROR
Definition BKE_report.hh:39
void BKE_scene_frame_set(Scene *scene, float frame)
Definition scene.cc:2389
const char * BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3137
bool BKE_scene_camera_switch_update(Scene *scene)
Definition scene.cc:2265
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3416
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2700
void BKE_screen_view3d_scene_sync(bScreen *screen, Scene *scene)
Definition screen.cc:1004
#define BVH_RAYCAST_DIST_MAX
void unit_m4(float m[4][4])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void zero_v3(float r[3])
#define FILE_MAX
#define CLAMP(a, b, c)
#define BPy_BEGIN_ALLOW_THREADS
Definition BPY_extern.hh:52
#define BPy_END_ALLOW_THREADS
Definition BPY_extern.hh:56
T * DEG_get_original(T *id)
@ OB_MODE_EDIT
@ OB_MESH
#define MINAFRAME
@ SCE_SNAP_TARGET_ALL
@ R_EXTENSION
#define MAXFRAME
bool EDBM_uv_check(BMEditMesh *em)
void ED_uvedit_get_aspect(Object *obedit, float *r_aspx, float *r_aspy)
static AppView * view
ParameterFlag
Definition RNA_types.hh:544
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ FUNC_USE_REPORTS
Definition RNA_types.hh:914
@ FUNC_USE_MAIN
Definition RNA_types.hh:912
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:889
PropertyFlag
Definition RNA_types.hh:300
@ PROP_THICK_WRAP
Definition RNA_types.hh:423
@ PROP_NEVER_NULL
Definition RNA_types.hh:377
#define NC_WINDOW
Definition WM_types.hh:375
BPy_StructRNA * depsgraph
bool is_empty() const
#define G(x, y, z)
void MOV_filepath_from_settings(char filepath[1024], const Scene *scene, const RenderData *rd, bool preview, const char *suffix, ReportList *reports)
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(Scene *scene, int flag)
void editing_free(Scene *scene, const bool do_id_user)
Definition sequencer.cc:305
return ret
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
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)
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)
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)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_function_flag(FunctionRNA *func, int flag)
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)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
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)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_api_scene(StructRNA *srna)
void RNA_api_scene_render(StructRNA *srna)
#define FLT_MAX
Definition stdcycles.h:14
Definition DNA_ID.h:414
void * first
ListBase screens
Definition BKE_main.hh:292
struct ImageFormatData im_format
char pic[1024]
ListBase view_layers
struct ViewLayer * next
void WM_main_add_notifier(uint type, void *reference)