Blender V4.5
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 WITH_ALEMBIC
22#endif
23
24#ifdef RNA_RUNTIME
25
26# include "BKE_editmesh.hh"
27# include "BKE_global.hh"
28# include "BKE_image.hh"
29# include "BKE_scene.hh"
30
31# include "DEG_depsgraph_query.hh"
32
33# include "ED_transform.hh"
35# include "ED_uvedit.hh"
36
37# include "MOV_write.hh"
38
39# ifdef WITH_PYTHON
40# include "BPY_extern.hh"
41# endif
42
43static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subframe)
44{
45 double cfra = double(frame) + double(subframe);
46
47 CLAMP(cfra, MINAFRAME, MAXFRAME);
48 BKE_scene_frame_set(scene, cfra);
49
50# ifdef WITH_PYTHON
52# endif
53
54 for (ViewLayer *view_layer = static_cast<ViewLayer *>(scene->view_layers.first);
55 view_layer != nullptr;
56 view_layer = view_layer->next)
57 {
58 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
60 }
61
62# ifdef WITH_PYTHON
64# endif
65
67 for (bScreen *screen = static_cast<bScreen *>(bmain->screens.first); screen;
68 screen = static_cast<bScreen *>(screen->id.next))
69 {
70 BKE_screen_view3d_scene_sync(screen, scene);
71 }
72 }
73
74 /* don't do notifier when we're rendering, avoid some viewport crashes
75 * redrawing while the data is being modified for render */
76 if (!G.is_rendering) {
77 /* can't use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
78 * BKE_scene_graph_update_for_newframe which will lose any un-keyed changes #24690. */
79 // WM_main_add_notifier(NC_SCENE|ND_FRAME, scene);
80
81 /* instead just redraw the views */
83 }
84}
85
86static void rna_Scene_uvedit_aspect(Scene * /*scene*/, Object *ob, float aspect[2])
87{
88 if ((ob->type == OB_MESH) && (ob->mode == OB_MODE_EDIT)) {
89 BMEditMesh *em;
91 if (EDBM_uv_check(em)) {
92 ED_uvedit_get_aspect(ob, aspect, aspect + 1);
93 return;
94 }
95 }
96
97 aspect[0] = aspect[1] = 1.0f;
98}
99
100static void rna_SceneRender_get_frame_path(RenderData *rd,
101 Main *bmain,
103 int frame,
104 bool preview,
105 const char *view,
106 char *filepath)
107{
108
109 const char *suffix = BKE_scene_multiview_view_suffix_get(rd, view);
110
111 /* avoid nullptr pointer */
112 if (!suffix) {
113 suffix = "";
114 }
115
117 MOV_filepath_from_settings(filepath, rd, preview != 0, suffix, reports);
118 }
119 else {
120 const char *relbase = BKE_main_blendfile_path(bmain);
121 const blender::bke::path_templates::VariableMap template_variables =
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()) {
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# ifdef WITH_ALEMBIC
198
199static void rna_Scene_alembic_export(Scene *scene,
200 bContext *C,
201 const char *filepath,
202 int frame_start,
203 int frame_end,
204 int xform_samples,
205 int geom_samples,
206 float shutter_open,
207 float shutter_close,
208 bool selected_only,
209 bool uvs,
210 bool normals,
211 bool vcolors,
212 bool apply_subdiv,
213 bool flatten_hierarchy,
214 bool visible_objects_only,
215 bool face_sets,
216 bool use_subdiv_schema,
217 bool export_hair,
218 bool export_particles,
219 bool packuv,
220 float scale,
221 bool triangulate,
222 int quad_method,
223 int ngon_method)
224{
225/* We have to enable allow_threads, because we may change scene frame number
226 * during export. */
227# ifdef WITH_PYTHON
229# endif
230
232 params.frame_start = frame_start;
233 params.frame_end = frame_end;
234
235 params.frame_samples_xform = xform_samples;
236 params.frame_samples_shape = geom_samples;
237
238 params.shutter_open = shutter_open;
239 params.shutter_close = shutter_close;
240
241 params.selected_only = selected_only;
242 params.uvs = uvs;
243 params.normals = normals;
244 params.vcolors = vcolors;
245 params.apply_subdiv = apply_subdiv;
246 params.flatten_hierarchy = flatten_hierarchy;
247 params.visible_objects_only = visible_objects_only;
248 params.face_sets = face_sets;
249 params.use_subdiv_schema = use_subdiv_schema;
250 params.export_hair = export_hair;
251 params.export_particles = export_particles;
252 params.packuv = packuv;
253 params.triangulate = triangulate;
254 params.quad_method = quad_method;
255 params.ngon_method = ngon_method;
256
257 params.global_scale = scale;
258
259 ABC_export(scene, C, filepath, &params, true);
260
261# ifdef WITH_PYTHON
263# endif
264}
265
266# endif
267
268#else
269
271{
272 FunctionRNA *func;
273 PropertyRNA *parm;
274
275 func = RNA_def_function(srna, "frame_set", "rna_Scene_frame_set");
277 func, "Set scene frame updating all objects and view layers immediately");
278 parm = RNA_def_int(
279 func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set", MINAFRAME, MAXFRAME);
282 func, "subframe", 0.0, 0.0, 1.0, "", "Subframe time, between 0.0 and 1.0", 0.0, 1.0);
284
285 func = RNA_def_function(srna, "uvedit_aspect", "rna_Scene_uvedit_aspect");
286 RNA_def_function_ui_description(func, "Get uv aspect for current object");
287 parm = RNA_def_pointer(func, "object", "Object", "", "Object");
290 func, "result", 2, nullptr, 0.0f, FLT_MAX, "", "aspect", 0.0f, FLT_MAX);
292 RNA_def_function_output(func, parm);
293
294 /* Ray Cast */
295 func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
296 RNA_def_function_ui_description(func, "Cast a ray onto evaluated geometry in world-space");
297
298 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "The current dependency graph");
300 /* ray start and end */
301 parm = RNA_def_float_vector(func, "origin", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
303 parm = RNA_def_float_vector(func, "direction", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
305 RNA_def_float(func,
306 "distance",
308 0.0,
310 "",
311 "Maximum distance",
312 0.0,
314 /* return location and normal */
315 parm = RNA_def_boolean(func, "result", false, "", "");
316 RNA_def_function_output(func, parm);
317 parm = RNA_def_float_vector(func,
318 "location",
319 3,
320 nullptr,
321 -FLT_MAX,
322 FLT_MAX,
323 "Location",
324 "The hit location of this ray cast",
325 -1e4,
326 1e4);
328 RNA_def_function_output(func, parm);
329 parm = RNA_def_float_vector(func,
330 "normal",
331 3,
332 nullptr,
333 -FLT_MAX,
334 FLT_MAX,
335 "Normal",
336 "The face normal at the ray cast hit location",
337 -1e4,
338 1e4);
340 RNA_def_function_output(func, parm);
341 parm = RNA_def_int(
342 func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
343 RNA_def_function_output(func, parm);
344 parm = RNA_def_pointer(func, "object", "Object", "", "Ray cast object");
345 RNA_def_function_output(func, parm);
346 parm = RNA_def_float_matrix(func, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
347 RNA_def_function_output(func, parm);
348
349 /* Sequencer. */
350 func = RNA_def_function(srna, "sequence_editor_create", "blender::seq::editing_ensure");
351 RNA_def_function_ui_description(func, "Ensure sequence editor is valid in this scene");
352 parm = RNA_def_pointer(
353 func, "sequence_editor", "SequenceEditor", "", "New sequence editor data or nullptr");
354 RNA_def_function_return(func, parm);
355
356 func = RNA_def_function(srna, "sequence_editor_clear", "rna_Scene_sequencer_editing_free");
357 RNA_def_function_ui_description(func, "Clear sequence editor in this scene");
358
359# ifdef WITH_ALEMBIC
360 /* XXX Deprecated, will be removed in 2.8 in favor of calling the export operator. */
361 func = RNA_def_function(srna, "alembic_export", "rna_Scene_alembic_export");
363 func, "Export to Alembic file (deprecated, use the Alembic export operator)");
364
365 parm = RNA_def_string(
366 func, "filepath", nullptr, FILE_MAX, "File Path", "File path to write Alembic file");
368 RNA_def_property_subtype(parm, PROP_FILEPATH); /* Allow non UTF8. */
369
370 RNA_def_int(func, "frame_start", 1, INT_MIN, INT_MAX, "Start", "Start Frame", INT_MIN, INT_MAX);
371 RNA_def_int(func, "frame_end", 1, INT_MIN, INT_MAX, "End", "End Frame", INT_MIN, INT_MAX);
373 func, "xform_samples", 1, 1, 128, "Xform samples", "Transform samples per frame", 1, 128);
375 func, "geom_samples", 1, 1, 128, "Geom samples", "Geometry samples per frame", 1, 128);
376 RNA_def_float(func, "shutter_open", 0.0f, -1.0f, 1.0f, "Shutter open", "", -1.0f, 1.0f);
377 RNA_def_float(func, "shutter_close", 1.0f, -1.0f, 1.0f, "Shutter close", "", -1.0f, 1.0f);
378 RNA_def_boolean(func, "selected_only", false, "Selected only", "Export only selected objects");
379 RNA_def_boolean(func, "uvs", true, "UVs", "Export UVs");
380 RNA_def_boolean(func, "normals", true, "Normals", "Export normals");
381 RNA_def_boolean(func, "vcolors", false, "Color Attributes", "Export color attributes");
383 func, "apply_subdiv", true, "Subsurfs as meshes", "Export subdivision surfaces as meshes");
384 RNA_def_boolean(func, "flatten", false, "Flatten hierarchy", "Flatten hierarchy");
385 RNA_def_boolean(func,
386 "visible_objects_only",
387 false,
388 "Visible layers only",
389 "Export only objects in visible layers");
390 RNA_def_boolean(func, "face_sets", false, "Facesets", "Export face sets");
391 RNA_def_boolean(func,
392 "subdiv_schema",
393 false,
394 "Use Alembic subdivision Schema",
395 "Use Alembic subdivision Schema");
396 RNA_def_boolean(func,
397 "export_hair",
398 true,
399 "Export Hair",
400 "Exports hair particle systems as animated curves");
402 func, "export_particles", true, "Export Particles", "Exports non-hair particle systems");
404 func, "packuv", false, "Export with packed UV islands", "Export with packed UV islands");
406 func,
407 "scale",
408 1.0f,
409 0.0001f,
410 1000.0f,
411 "Scale",
412 "Value by which to enlarge or shrink the objects with respect to the world's origin",
413 0.0001f,
414 1000.0f);
415 RNA_def_boolean(func,
416 "triangulate",
417 false,
418 "Triangulate",
419 "Export polygons (quads and n-gons) as triangles");
420 RNA_def_enum(func,
421 "quad_method",
423 0,
424 "Quad Method",
425 "Method for splitting the quads into triangles");
426 RNA_def_enum(func,
427 "ngon_method",
429 0,
430 "N-gon Method",
431 "Method for splitting the n-gons into triangles");
432
434# endif
435}
436
438{
439 FunctionRNA *func;
440 PropertyRNA *parm;
441
442 func = RNA_def_function(srna, "frame_path", "rna_SceneRender_get_frame_path");
445 func, "Return the absolute path to the filename to be written for a given frame");
446 RNA_def_int(func,
447 "frame",
448 INT_MIN,
449 INT_MIN,
450 INT_MAX,
451 "",
452 "Frame number to use, if unset the current frame will be used",
453 MINAFRAME,
454 MAXFRAME);
455 RNA_def_boolean(func, "preview", false, "Preview", "Use preview range");
457 "view",
458 nullptr,
459 FILE_MAX,
460 "View",
461 "The name of the view to use to replace the \"%\" chars");
462 parm = RNA_def_string_file_path(func,
463 "filepath",
464 nullptr,
465 FILE_MAX,
466 "File Path",
467 "The resulting filepath from the scenes render settings");
469 parm, PROP_THICK_WRAP, ParameterFlag(0)); /* needed for string return value */
470 RNA_def_function_output(func, parm);
471}
472
473#endif
bool ABC_export(struct Scene *scene, struct bContext *C, const char *filepath, const struct AlembicExportParams *params, bool as_background_job)
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:872
void BKE_report_path_template_errors(ReportList *reports, eReportType report_type, blender::StringRef path, blender::Span< blender::bke::path_templates::Error > errors)
blender::bke::path_templates::VariableMap BKE_build_template_variables_for_render_path(const RenderData *render_data)
void BKE_scene_frame_set(Scene *scene, float frame)
Definition scene.cc:2386
const char * BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3149
bool BKE_scene_camera_switch_update(Scene *scene)
Definition scene.cc:2267
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3427
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2697
void BKE_screen_view3d_scene_sync(bScreen *screen, Scene *scene)
Definition screen.cc:998
#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:51
#define BPy_END_ALLOW_THREADS
Definition BPY_extern.hh:55
T * DEG_get_original(T *id)
@ OB_MODE_EDIT
@ OB_MESH
#define MINAFRAME
@ R_EXTENSION
@ SCE_SNAP_TARGET_ALL
#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:510
@ PARM_REQUIRED
Definition RNA_types.hh:511
@ FUNC_USE_REPORTS
Definition RNA_types.hh:805
@ FUNC_USE_MAIN
Definition RNA_types.hh:803
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:804
PropertyFlag
Definition RNA_types.hh:286
@ PROP_THICK_WRAP
Definition RNA_types.hh:397
@ PROP_NEVER_NULL
Definition RNA_types.hh:351
@ PROP_FILEPATH
Definition RNA_types.hh:224
#define C
Definition RandGen.cpp:29
#define NC_WINDOW
Definition WM_types.hh:372
ReportList * reports
Definition WM_types.hh:1025
BPy_StructRNA * depsgraph
bool is_empty() const
static float normals[][3]
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define G(x, y, z)
void MOV_filepath_from_settings(char filepath[1024], 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)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
void editing_free(Scene *scene, const bool do_id_user)
Definition sequencer.cc:293
return ret
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
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)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
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)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
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)
const EnumPropertyItem rna_enum_modifier_triangulate_ngon_method_items[]
const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[]
void RNA_api_scene(StructRNA *srna)
void RNA_api_scene_render(StructRNA *srna)
#define FLT_MAX
Definition stdcycles.h:14
void * first
ListBase screens
Definition BKE_main.hh:261
struct ImageFormatData im_format
char pic[1024]
ListBase view_layers
struct ViewLayer * next
void WM_main_add_notifier(uint type, void *reference)