Blender V4.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
9#include <cstdio>
10#include <cstdlib>
11
12#include "BLI_kdopbvh.h"
13#include "BLI_math_matrix.h"
14#include "BLI_math_vector.h"
15#include "BLI_path_utils.hh"
16#include "BLI_utildefines.h"
17
18#include "RNA_define.hh"
19#include "RNA_enum_types.hh"
20
21#include "DNA_anim_types.h"
22#include "DNA_object_types.h"
23#include "DNA_scene_types.h"
24
25#include "rna_internal.hh" /* own include */
26
27#ifdef WITH_ALEMBIC
28# include "ABC_alembic.h"
29#endif
30
31#ifdef RNA_RUNTIME
32
33# include "BKE_editmesh.hh"
34# include "BKE_global.hh"
35# include "BKE_image.hh"
36# include "BKE_scene.hh"
37# include "BKE_writemovie.hh"
38
39# include "DEG_depsgraph_query.hh"
40
41# include "ED_transform.hh"
43# include "ED_uvedit.hh"
44
45# ifdef WITH_PYTHON
46# include "BPY_extern.hh"
47# endif
48
49static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subframe)
50{
51 double cfra = double(frame) + double(subframe);
52
53 CLAMP(cfra, MINAFRAME, MAXFRAME);
54 BKE_scene_frame_set(scene, cfra);
55
56# ifdef WITH_PYTHON
58# endif
59
60 for (ViewLayer *view_layer = static_cast<ViewLayer *>(scene->view_layers.first);
61 view_layer != nullptr;
62 view_layer = view_layer->next)
63 {
64 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
66 }
67
68# ifdef WITH_PYTHON
70# endif
71
73 for (bScreen *screen = static_cast<bScreen *>(bmain->screens.first); screen;
74 screen = static_cast<bScreen *>(screen->id.next))
75 {
76 BKE_screen_view3d_scene_sync(screen, scene);
77 }
78 }
79
80 /* don't do notifier when we're rendering, avoid some viewport crashes
81 * redrawing while the data is being modified for render */
82 if (!G.is_rendering) {
83 /* can't use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
84 * BKE_scene_graph_update_for_newframe which will lose any un-keyed changes #24690. */
85 // WM_main_add_notifier(NC_SCENE|ND_FRAME, scene);
86
87 /* instead just redraw the views */
89 }
90}
91
92static void rna_Scene_uvedit_aspect(Scene * /*scene*/, Object *ob, float aspect[2])
93{
94 if ((ob->type == OB_MESH) && (ob->mode == OB_MODE_EDIT)) {
95 BMEditMesh *em;
97 if (EDBM_uv_check(em)) {
98 ED_uvedit_get_aspect(ob, aspect, aspect + 1);
99 return;
100 }
101 }
102
103 aspect[0] = aspect[1] = 1.0f;
104}
105
106static void rna_SceneRender_get_frame_path(
107 RenderData *rd, Main *bmain, int frame, bool preview, const char *view, char *filepath)
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 BKE_movie_filepath_get(filepath, rd, preview != 0, suffix);
118 }
119 else {
121 rd->pic,
123 (frame == INT_MIN) ? rd->cfra : frame,
124 &rd->im_format,
125 (rd->scemode & R_EXTENSION) != 0,
126 true,
127 suffix);
128 }
129}
130
131static void rna_Scene_ray_cast(Scene *scene,
132 Depsgraph *depsgraph,
133 const float origin[3],
134 const float direction[3],
135 float ray_dist,
136 bool *r_success,
137 float r_location[3],
138 float r_normal[3],
139 int *r_index,
140 Object **r_ob,
141 float r_obmat[16])
142{
143 float direction_unit[3];
144 normalize_v3_v3(direction_unit, direction);
146
147 SnapObjectParams snap_object_params{};
148 snap_object_params.snap_target_select = SCE_SNAP_TARGET_ALL;
149
151 depsgraph,
152 nullptr,
153 &snap_object_params,
154 origin,
155 direction_unit,
156 &ray_dist,
157 r_location,
158 r_normal,
159 r_index,
160 (const Object **)(r_ob),
161 (float(*)[4])r_obmat);
162
164
165 if (r_ob != nullptr && *r_ob != nullptr) {
166 *r_ob = DEG_get_original_object(*r_ob);
167 }
168
169 if (ret) {
170 *r_success = true;
171 }
172 else {
173 *r_success = false;
174
175 unit_m4((float(*)[4])r_obmat);
176 zero_v3(r_location);
177 zero_v3(r_normal);
178 }
179}
180
181static void rna_Scene_sequencer_editing_free(Scene *scene)
182{
183 SEQ_editing_free(scene, true);
184}
185
186# ifdef WITH_ALEMBIC
187
188static void rna_Scene_alembic_export(Scene *scene,
189 bContext *C,
190 const char *filepath,
191 int frame_start,
192 int frame_end,
193 int xform_samples,
194 int geom_samples,
195 float shutter_open,
196 float shutter_close,
197 bool selected_only,
198 bool uvs,
199 bool normals,
200 bool vcolors,
201 bool apply_subdiv,
202 bool flatten_hierarchy,
203 bool visible_objects_only,
204 bool face_sets,
205 bool use_subdiv_schema,
206 bool export_hair,
207 bool export_particles,
208 bool packuv,
209 float scale,
210 bool triangulate,
211 int quad_method,
212 int ngon_method)
213{
214/* We have to enable allow_threads, because we may change scene frame number
215 * during export. */
216# ifdef WITH_PYTHON
218# endif
219
221 params.frame_start = frame_start;
222 params.frame_end = frame_end;
223
224 params.frame_samples_xform = xform_samples;
225 params.frame_samples_shape = geom_samples;
226
227 params.shutter_open = shutter_open;
228 params.shutter_close = shutter_close;
229
230 params.selected_only = selected_only;
231 params.uvs = uvs;
232 params.normals = normals;
233 params.vcolors = vcolors;
234 params.apply_subdiv = apply_subdiv;
235 params.flatten_hierarchy = flatten_hierarchy;
236 params.visible_objects_only = visible_objects_only;
237 params.face_sets = face_sets;
238 params.use_subdiv_schema = use_subdiv_schema;
239 params.export_hair = export_hair;
240 params.export_particles = export_particles;
241 params.packuv = packuv;
242 params.triangulate = triangulate;
243 params.quad_method = quad_method;
244 params.ngon_method = ngon_method;
245
246 params.global_scale = scale;
247
248 ABC_export(scene, C, filepath, &params, true);
249
250# ifdef WITH_PYTHON
252# endif
253}
254
255# endif
256
257#else
258
260{
261 FunctionRNA *func;
262 PropertyRNA *parm;
263
264 func = RNA_def_function(srna, "frame_set", "rna_Scene_frame_set");
265 RNA_def_function_ui_description(func, "Set scene frame updating all objects immediately");
266 parm = RNA_def_int(
267 func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set", MINAFRAME, MAXFRAME);
270 func, "subframe", 0.0, 0.0, 1.0, "", "Subframe time, between 0.0 and 1.0", 0.0, 1.0);
272
273 func = RNA_def_function(srna, "uvedit_aspect", "rna_Scene_uvedit_aspect");
274 RNA_def_function_ui_description(func, "Get uv aspect for current object");
275 parm = RNA_def_pointer(func, "object", "Object", "", "Object");
278 func, "result", 2, nullptr, 0.0f, FLT_MAX, "", "aspect", 0.0f, FLT_MAX);
280 RNA_def_function_output(func, parm);
281
282 /* Ray Cast */
283 func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
284 RNA_def_function_ui_description(func, "Cast a ray onto in object space");
285
286 parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "The current dependency graph");
288 /* ray start and end */
289 parm = RNA_def_float_vector(func, "origin", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
291 parm = RNA_def_float_vector(func, "direction", 3, nullptr, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
293 RNA_def_float(func,
294 "distance",
296 0.0,
298 "",
299 "Maximum distance",
300 0.0,
302 /* return location and normal */
303 parm = RNA_def_boolean(func, "result", false, "", "");
304 RNA_def_function_output(func, parm);
305 parm = RNA_def_float_vector(func,
306 "location",
307 3,
308 nullptr,
309 -FLT_MAX,
310 FLT_MAX,
311 "Location",
312 "The hit location of this ray cast",
313 -1e4,
314 1e4);
316 RNA_def_function_output(func, parm);
317 parm = RNA_def_float_vector(func,
318 "normal",
319 3,
320 nullptr,
321 -FLT_MAX,
322 FLT_MAX,
323 "Normal",
324 "The face normal at the ray cast hit location",
325 -1e4,
326 1e4);
328 RNA_def_function_output(func, parm);
329 parm = RNA_def_int(
330 func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
331 RNA_def_function_output(func, parm);
332 parm = RNA_def_pointer(func, "object", "Object", "", "Ray cast object");
333 RNA_def_function_output(func, parm);
334 parm = RNA_def_float_matrix(func, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
335 RNA_def_function_output(func, parm);
336
337 /* Sequencer. */
338 func = RNA_def_function(srna, "sequence_editor_create", "SEQ_editing_ensure");
339 RNA_def_function_ui_description(func, "Ensure sequence editor is valid in this scene");
340 parm = RNA_def_pointer(
341 func, "sequence_editor", "SequenceEditor", "", "New sequence editor data or nullptr");
342 RNA_def_function_return(func, parm);
343
344 func = RNA_def_function(srna, "sequence_editor_clear", "rna_Scene_sequencer_editing_free");
345 RNA_def_function_ui_description(func, "Clear sequence editor in this scene");
346
347# ifdef WITH_ALEMBIC
348 /* XXX Deprecated, will be removed in 2.8 in favor of calling the export operator. */
349 func = RNA_def_function(srna, "alembic_export", "rna_Scene_alembic_export");
351 func, "Export to Alembic file (deprecated, use the Alembic export operator)");
352
353 parm = RNA_def_string(
354 func, "filepath", nullptr, FILE_MAX, "File Path", "File path to write Alembic file");
356 RNA_def_property_subtype(parm, PROP_FILEPATH); /* allow non utf8 */
357
358 RNA_def_int(func, "frame_start", 1, INT_MIN, INT_MAX, "Start", "Start Frame", INT_MIN, INT_MAX);
359 RNA_def_int(func, "frame_end", 1, INT_MIN, INT_MAX, "End", "End Frame", INT_MIN, INT_MAX);
361 func, "xform_samples", 1, 1, 128, "Xform samples", "Transform samples per frame", 1, 128);
363 func, "geom_samples", 1, 1, 128, "Geom samples", "Geometry samples per frame", 1, 128);
364 RNA_def_float(func, "shutter_open", 0.0f, -1.0f, 1.0f, "Shutter open", "", -1.0f, 1.0f);
365 RNA_def_float(func, "shutter_close", 1.0f, -1.0f, 1.0f, "Shutter close", "", -1.0f, 1.0f);
366 RNA_def_boolean(func, "selected_only", false, "Selected only", "Export only selected objects");
367 RNA_def_boolean(func, "uvs", true, "UVs", "Export UVs");
368 RNA_def_boolean(func, "normals", true, "Normals", "Export normals");
369 RNA_def_boolean(func, "vcolors", false, "Color Attributes", "Export color attributes");
371 func, "apply_subdiv", true, "Subsurfs as meshes", "Export subdivision surfaces as meshes");
372 RNA_def_boolean(func, "flatten", false, "Flatten hierarchy", "Flatten hierarchy");
373 RNA_def_boolean(func,
374 "visible_objects_only",
375 false,
376 "Visible layers only",
377 "Export only objects in visible layers");
378 RNA_def_boolean(func, "face_sets", false, "Facesets", "Export face sets");
379 RNA_def_boolean(func,
380 "subdiv_schema",
381 false,
382 "Use Alembic subdivision Schema",
383 "Use Alembic subdivision Schema");
384 RNA_def_boolean(func,
385 "export_hair",
386 true,
387 "Export Hair",
388 "Exports hair particle systems as animated curves");
390 func, "export_particles", true, "Export Particles", "Exports non-hair particle systems");
392 func, "packuv", false, "Export with packed UV islands", "Export with packed UV islands");
394 func,
395 "scale",
396 1.0f,
397 0.0001f,
398 1000.0f,
399 "Scale",
400 "Value by which to enlarge or shrink the objects with respect to the world's origin",
401 0.0001f,
402 1000.0f);
403 RNA_def_boolean(func,
404 "triangulate",
405 false,
406 "Triangulate",
407 "Export polygons (quads and n-gons) as triangles");
408 RNA_def_enum(func,
409 "quad_method",
411 0,
412 "Quad Method",
413 "Method for splitting the quads into triangles");
414 RNA_def_enum(func,
415 "ngon_method",
417 0,
418 "N-gon Method",
419 "Method for splitting the n-gons into triangles");
420
422# endif
423}
424
426{
427 FunctionRNA *func;
428 PropertyRNA *parm;
429
430 func = RNA_def_function(srna, "frame_path", "rna_SceneRender_get_frame_path");
433 func, "Return the absolute path to the filename to be written for a given frame");
434 RNA_def_int(func,
435 "frame",
436 INT_MIN,
437 INT_MIN,
438 INT_MAX,
439 "",
440 "Frame number to use, if unset the current frame will be used",
441 MINAFRAME,
442 MAXFRAME);
443 RNA_def_boolean(func, "preview", false, "Preview", "Use preview range");
445 "view",
446 nullptr,
447 FILE_MAX,
448 "View",
449 "The name of the view to use to replace the \"%\" chars");
450 parm = RNA_def_string_file_path(func,
451 "filepath",
452 nullptr,
453 FILE_MAX,
454 "File Path",
455 "The resulting filepath from the scenes render settings");
457 parm, PROP_THICK_WRAP, ParameterFlag(0)); /* needed for string return value */
458 RNA_def_function_output(func, parm);
459}
460
461#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:63
void BKE_image_path_from_imformat(char *filepath, const char *base, const char *relbase, 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:832
void BKE_scene_frame_set(Scene *scene, float frame)
Definition scene.cc:2336
const char * BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
Definition scene.cc:3125
bool BKE_scene_camera_switch_update(Scene *scene)
Definition scene.cc:2213
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3377
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2647
void BKE_screen_view3d_scene_sync(bScreen *screen, Scene *scene)
Definition screen.cc:963
void BKE_movie_filepath_get(char filepath[1024], const RenderData *rd, bool preview, const char *suffix)
Definition writemovie.cc:93
#define BVH_RAYCAST_DIST_MAX
Definition BLI_kdopbvh.h:92
void unit_m4(float m[4][4])
Definition rct.c:1127
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:50
#define BPy_END_ALLOW_THREADS
Definition BPY_extern.hh:54
typedef double(DMatrix)[4][4]
Object * DEG_get_original_object(Object *object)
@ OB_MODE_EDIT
Object is a sort of wrapper for general info.
@ OB_MESH
@ R_EXTENSION
#define MINAFRAME
@ SCE_SNAP_TARGET_ALL
#define MAXFRAME
bool EDBM_uv_check(BMEditMesh *em)
bool ED_transform_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])
SnapObjectContext * ED_transform_snap_object_context_create(Scene *scene, int flag)
void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx)
void ED_uvedit_get_aspect(Object *obedit, float *r_aspx, float *r_aspy)
ParameterFlag
Definition RNA_types.hh:396
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_MAIN
Definition RNA_types.hh:678
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:679
PropertyFlag
Definition RNA_types.hh:201
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_FILEPATH
Definition RNA_types.hh:139
#define NC_WINDOW
Definition WM_types.hh:342
const Depsgraph * depsgraph
static float normals[][3]
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define G(x, y, z)
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)
void SEQ_editing_free(Scene *scene, const bool do_id_user)
Definition sequencer.cc:284
#define FLT_MAX
Definition stdcycles.h:14
void * first
ListBase screens
Definition BKE_main.hh:225
struct ImageFormatData im_format
char pic[1024]
void WM_main_add_notifier(uint type, void *reference)