Blender  V3.3
rna_scene_api.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2009 Blender Foundation. All rights reserved. */
3 
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 #include "BLI_kdopbvh.h"
12 #include "BLI_path_util.h"
13 #include "BLI_utildefines.h"
14 
15 #include "RNA_define.h"
16 #include "RNA_enum_types.h"
17 
18 #include "DNA_anim_types.h"
19 #include "DNA_object_types.h"
20 #include "DNA_scene_types.h"
21 
22 #include "rna_internal.h" /* own include */
23 
24 #ifdef WITH_ALEMBIC
25 # include "ABC_alembic.h"
26 #endif
27 
28 #ifdef RNA_RUNTIME
29 
30 # include "BKE_editmesh.h"
31 # include "BKE_global.h"
32 # include "BKE_image.h"
33 # include "BKE_scene.h"
34 # include "BKE_writeavi.h"
35 
36 # include "DEG_depsgraph_query.h"
37 
38 # include "ED_transform.h"
40 # include "ED_uvedit.h"
41 
42 # ifdef WITH_PYTHON
43 # include "BPY_extern.h"
44 # endif
45 
46 static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subframe)
47 {
48  double cfra = (double)frame + (double)subframe;
49 
50  CLAMP(cfra, MINAFRAME, MAXFRAME);
52 
53 # ifdef WITH_PYTHON
55 # endif
56 
57  for (ViewLayer *view_layer = scene->view_layers.first; view_layer != NULL;
58  view_layer = view_layer->next) {
59  Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
61  }
62 
63 # ifdef WITH_PYTHON
65 # endif
66 
68  for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
70  }
71  }
72 
73  /* don't do notifier when we're rendering, avoid some viewport crashes
74  * redrawing while the data is being modified for render */
75  if (!G.is_rendering) {
76  /* can't use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
77  * BKE_scene_graph_update_for_newframe which will lose any un-keyed changes T24690. */
78  // WM_main_add_notifier(NC_SCENE|ND_FRAME, scene);
79 
80  /* instead just redraw the views */
82  }
83 }
84 
85 static void rna_Scene_uvedit_aspect(Scene *UNUSED(scene), Object *ob, float aspect[2])
86 {
87  if ((ob->type == OB_MESH) && (ob->mode == OB_MODE_EDIT)) {
88  BMEditMesh *em;
89  em = BKE_editmesh_from_object(ob);
90  if (EDBM_uv_check(em)) {
91  ED_uvedit_get_aspect(ob, aspect, aspect + 1);
92  return;
93  }
94  }
95 
96  aspect[0] = aspect[1] = 1.0f;
97 }
98 
99 static void rna_SceneRender_get_frame_path(
100  RenderData *rd, Main *bmain, int frame, bool preview, const char *view, char *name)
101 {
102  const char *suffix = BKE_scene_multiview_view_suffix_get(rd, view);
103 
104  /* avoid NULL pointer */
105  if (!suffix) {
106  suffix = "";
107  }
108 
110  BKE_movie_filepath_get(name, rd, preview != 0, suffix);
111  }
112  else {
114  rd->pic,
116  (frame == INT_MIN) ? rd->cfra : frame,
117  &rd->im_format,
118  (rd->scemode & R_EXTENSION) != 0,
119  true,
120  suffix);
121  }
122 }
123 
124 static void rna_Scene_ray_cast(Scene *scene,
126  float origin[3],
127  float direction[3],
128  float ray_dist,
129  bool *r_success,
130  float r_location[3],
131  float r_normal[3],
132  int *r_index,
133  Object **r_ob,
134  float r_obmat[16])
135 {
136  normalize_v3(direction);
138 
140  depsgraph,
141  NULL,
142  &(const struct SnapObjectParams){
143  .snap_target_select = SCE_SNAP_TARGET_ALL,
144  },
145  origin,
146  direction,
147  &ray_dist,
148  r_location,
149  r_normal,
150  r_index,
151  r_ob,
152  (float(*)[4])r_obmat);
153 
155 
156  if (r_ob != NULL && *r_ob != NULL) {
157  *r_ob = DEG_get_original_object(*r_ob);
158  }
159 
160  if (ret) {
161  *r_success = true;
162  }
163  else {
164  *r_success = false;
165 
166  unit_m4((float(*)[4])r_obmat);
167  zero_v3(r_location);
168  zero_v3(r_normal);
169  }
170 }
171 
172 static void rna_Scene_sequencer_editing_free(Scene *scene)
173 {
174  SEQ_editing_free(scene, true);
175 }
176 
177 # ifdef WITH_ALEMBIC
178 
179 static void rna_Scene_alembic_export(Scene *scene,
180  bContext *C,
181  const char *filepath,
182  int frame_start,
183  int frame_end,
184  int xform_samples,
185  int geom_samples,
186  float shutter_open,
187  float shutter_close,
188  bool selected_only,
189  bool uvs,
190  bool normals,
191  bool vcolors,
192  bool apply_subdiv,
193  bool flatten_hierarchy,
194  bool visible_objects_only,
195  bool face_sets,
196  bool use_subdiv_schema,
197  bool export_hair,
198  bool export_particles,
199  bool packuv,
200  float scale,
201  bool triangulate,
202  int quad_method,
203  int ngon_method)
204 {
205 /* We have to enable allow_threads, because we may change scene frame number
206  * during export. */
207 # ifdef WITH_PYTHON
209 # endif
210 
211  const struct AlembicExportParams params = {
212  .frame_start = frame_start,
213  .frame_end = frame_end,
214 
215  .frame_samples_xform = xform_samples,
216  .frame_samples_shape = geom_samples,
217 
218  .shutter_open = shutter_open,
219  .shutter_close = shutter_close,
220 
221  .selected_only = selected_only,
222  .uvs = uvs,
223  .normals = normals,
224  .vcolors = vcolors,
225  .apply_subdiv = apply_subdiv,
226  .flatten_hierarchy = flatten_hierarchy,
227  .visible_objects_only = visible_objects_only,
228  .face_sets = face_sets,
229  .use_subdiv_schema = use_subdiv_schema,
230  .export_hair = export_hair,
231  .export_particles = export_particles,
232  .packuv = packuv,
233  .triangulate = triangulate,
234  .quad_method = quad_method,
235  .ngon_method = ngon_method,
236 
237  .global_scale = scale,
238  };
239 
240  ABC_export(scene, C, filepath, &params, true);
241 
242 # ifdef WITH_PYTHON
244 # endif
245 }
246 
247 # endif
248 
249 #else
250 
252 {
253  FunctionRNA *func;
254  PropertyRNA *parm;
255 
256  func = RNA_def_function(srna, "frame_set", "rna_Scene_frame_set");
257  RNA_def_function_ui_description(func, "Set scene frame updating all objects immediately");
258  parm = RNA_def_int(
259  func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set", MINAFRAME, MAXFRAME);
262  func, "subframe", 0.0, 0.0, 1.0, "", "Subframe time, between 0.0 and 1.0", 0.0, 1.0);
264 
265  func = RNA_def_function(srna, "uvedit_aspect", "rna_Scene_uvedit_aspect");
266  RNA_def_function_ui_description(func, "Get uv aspect for current object");
267  parm = RNA_def_pointer(func, "object", "Object", "", "Object");
269  parm = RNA_def_float_vector(func, "result", 2, NULL, 0.0f, FLT_MAX, "", "aspect", 0.0f, FLT_MAX);
271  RNA_def_function_output(func, parm);
272 
273  /* Ray Cast */
274  func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
275  RNA_def_function_ui_description(func, "Cast a ray onto in object space");
276 
277  parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "The current dependency graph");
279  /* ray start and end */
280  parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
282  parm = RNA_def_float_vector(func, "direction", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
284  RNA_def_float(func,
285  "distance",
287  0.0,
289  "",
290  "Maximum distance",
291  0.0,
293  /* return location and normal */
294  parm = RNA_def_boolean(func, "result", 0, "", "");
295  RNA_def_function_output(func, parm);
296  parm = RNA_def_float_vector(func,
297  "location",
298  3,
299  NULL,
300  -FLT_MAX,
301  FLT_MAX,
302  "Location",
303  "The hit location of this ray cast",
304  -1e4,
305  1e4);
307  RNA_def_function_output(func, parm);
308  parm = RNA_def_float_vector(func,
309  "normal",
310  3,
311  NULL,
312  -FLT_MAX,
313  FLT_MAX,
314  "Normal",
315  "The face normal at the ray cast hit location",
316  -1e4,
317  1e4);
319  RNA_def_function_output(func, parm);
320  parm = RNA_def_int(
321  func, "index", 0, 0, 0, "", "The face index, -1 when original data isn't available", 0, 0);
322  RNA_def_function_output(func, parm);
323  parm = RNA_def_pointer(func, "object", "Object", "", "Ray cast object");
324  RNA_def_function_output(func, parm);
325  parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
326  RNA_def_function_output(func, parm);
327 
328  /* Sequencer. */
329  func = RNA_def_function(srna, "sequence_editor_create", "SEQ_editing_ensure");
330  RNA_def_function_ui_description(func, "Ensure sequence editor is valid in this scene");
331  parm = RNA_def_pointer(
332  func, "sequence_editor", "SequenceEditor", "", "New sequence editor data or NULL");
333  RNA_def_function_return(func, parm);
334 
335  func = RNA_def_function(srna, "sequence_editor_clear", "rna_Scene_sequencer_editing_free");
336  RNA_def_function_ui_description(func, "Clear sequence editor in this scene");
337 
338 # ifdef WITH_ALEMBIC
339  /* XXX Deprecated, will be removed in 2.8 in favor of calling the export operator. */
340  func = RNA_def_function(srna, "alembic_export", "rna_Scene_alembic_export");
342  func, "Export to Alembic file (deprecated, use the Alembic export operator)");
343 
344  parm = RNA_def_string(
345  func, "filepath", NULL, FILE_MAX, "File Path", "File path to write Alembic file");
347  RNA_def_property_subtype(parm, PROP_FILEPATH); /* allow non utf8 */
348 
349  RNA_def_int(func, "frame_start", 1, INT_MIN, INT_MAX, "Start", "Start Frame", INT_MIN, INT_MAX);
350  RNA_def_int(func, "frame_end", 1, INT_MIN, INT_MAX, "End", "End Frame", INT_MIN, INT_MAX);
351  RNA_def_int(
352  func, "xform_samples", 1, 1, 128, "Xform samples", "Transform samples per frame", 1, 128);
353  RNA_def_int(
354  func, "geom_samples", 1, 1, 128, "Geom samples", "Geometry samples per frame", 1, 128);
355  RNA_def_float(func, "shutter_open", 0.0f, -1.0f, 1.0f, "Shutter open", "", -1.0f, 1.0f);
356  RNA_def_float(func, "shutter_close", 1.0f, -1.0f, 1.0f, "Shutter close", "", -1.0f, 1.0f);
357  RNA_def_boolean(func, "selected_only", 0, "Selected only", "Export only selected objects");
358  RNA_def_boolean(func, "uvs", 1, "UVs", "Export UVs");
359  RNA_def_boolean(func, "normals", 1, "Normals", "Export normals");
360  RNA_def_boolean(func, "vcolors", 0, "Color Attributes", "Export color attributes");
362  func, "apply_subdiv", 1, "Subsurfs as meshes", "Export subdivision surfaces as meshes");
363  RNA_def_boolean(func, "flatten", 0, "Flatten hierarchy", "Flatten hierarchy");
364  RNA_def_boolean(func,
365  "visible_objects_only",
366  0,
367  "Visible layers only",
368  "Export only objects in visible layers");
369  RNA_def_boolean(func, "face_sets", 0, "Facesets", "Export face sets");
370  RNA_def_boolean(func,
371  "subdiv_schema",
372  0,
373  "Use Alembic subdivision Schema",
374  "Use Alembic subdivision Schema");
376  func, "export_hair", 1, "Export Hair", "Exports hair particle systems as animated curves");
378  func, "export_particles", 1, "Export Particles", "Exports non-hair particle systems");
380  func, "packuv", 0, "Export with packed UV islands", "Export with packed UV islands");
382  func,
383  "scale",
384  1.0f,
385  0.0001f,
386  1000.0f,
387  "Scale",
388  "Value by which to enlarge or shrink the objects with respect to the world's origin",
389  0.0001f,
390  1000.0f);
392  func, "triangulate", 0, "Triangulate", "Export polygons (quads and n-gons) as triangles");
393  RNA_def_enum(func,
394  "quad_method",
396  0,
397  "Quad Method",
398  "Method for splitting the quads into triangles");
399  RNA_def_enum(func,
400  "ngon_method",
402  0,
403  "N-gon Method",
404  "Method for splitting the n-gons into triangles");
405 
407 # endif
408 }
409 
411 {
412  FunctionRNA *func;
413  PropertyRNA *parm;
414 
415  func = RNA_def_function(srna, "frame_path", "rna_SceneRender_get_frame_path");
418  func, "Return the absolute path to the filename to be written for a given frame");
419  RNA_def_int(func,
420  "frame",
421  INT_MIN,
422  INT_MIN,
423  INT_MAX,
424  "",
425  "Frame number to use, if unset the current frame will be used",
426  MINAFRAME,
427  MAXFRAME);
428  RNA_def_boolean(func, "preview", 0, "Preview", "Use preview range");
430  "view",
431  NULL,
432  FILE_MAX,
433  "View",
434  "The name of the view to use to replace the \"%\" chars");
435  parm = RNA_def_string_file_path(func,
436  "filepath",
437  NULL,
438  FILE_MAX,
439  "File Path",
440  "The resulting filepath from the scenes render settings");
441  RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
442  RNA_def_function_output(func, parm);
443 }
444 
445 #endif
bool ABC_export(struct Scene *scene, struct bContext *C, const char *filepath, const struct AlembicExportParams *params, bool as_background_job)
typedef float(TangentPoint)[2]
BMEditMesh * BKE_editmesh_from_object(struct Object *ob)
Return the BMEditMesh for a given object.
Definition: editmesh.c:58
void BKE_image_path_from_imformat(char *string, const char *base, const char *relbase, int frame, const struct 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 struct Main *bmain) ATTR_NONNULL()
bool BKE_scene_camera_switch_update(struct Scene *scene)
Definition: scene.cc:2295
void BKE_scene_graph_update_for_newframe(struct Depsgraph *depsgraph)
Definition: scene.cc:2728
struct Depsgraph * BKE_scene_ensure_depsgraph(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer)
Definition: scene.cc:3456
void BKE_scene_frame_set(struct Scene *scene, float frame)
Definition: scene.cc:2420
const char * BKE_scene_multiview_view_suffix_get(const struct RenderData *rd, const char *viewname)
void BKE_screen_view3d_scene_sync(struct bScreen *screen, struct Scene *scene)
Definition: screen.c:994
void BKE_movie_filepath_get(char *string, const struct RenderData *rd, bool preview, const char *suffix)
#define BVH_RAYCAST_DIST_MAX
Definition: BLI_kdopbvh.h:89
void unit_m4(float m[4][4])
Definition: rct.c:1090
MINLINE float normalize_v3(float r[3])
MINLINE void zero_v3(float r[3])
#define FILE_MAX
#define UNUSED(x)
#define BPy_BEGIN_ALLOW_THREADS
Definition: BPY_extern.h:54
#define BPy_END_ALLOW_THREADS
Definition: BPY_extern.h:58
typedef double(DMatrix)[4][4]
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
struct Object * DEG_get_original_object(struct Object *object)
@ OB_MODE_EDIT
Object is a sort of wrapper for general info.
@ OB_MESH
#define R_EXTENSION
@ SCE_SNAP_TARGET_ALL
#define MINAFRAME
#define MAXFRAME
bool EDBM_uv_check(struct BMEditMesh *em)
SnapObjectContext * ED_transform_snap_object_context_create(struct Scene *scene, int flag)
void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx)
bool ED_transform_snap_object_project_ray_ex(struct SnapObjectContext *sctx, struct Depsgraph *depsgraph, const View3D *v3d, const struct 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, struct Object **r_ob, float r_obmat[4][4])
void ED_uvedit_get_aspect(struct Object *obedit, float *r_aspx, float *r_aspy)
static AppView * view
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
@ PARM_REQUIRED
Definition: RNA_types.h:352
@ FUNC_USE_MAIN
Definition: RNA_types.h:661
@ FUNC_USE_CONTEXT
Definition: RNA_types.h:662
@ PROP_THICK_WRAP
Definition: RNA_types.h:285
@ PROP_NEVER_NULL
Definition: RNA_types.h:239
@ PROP_FILEPATH
Definition: RNA_types.h:129
#define C
Definition: RandGen.cpp:25
#define NC_WINDOW
Definition: WM_types.h:325
Scene scene
const Depsgraph * depsgraph
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define G(x, y, z)
static const pxr::TfToken preview("preview", pxr::TfToken::Immortal)
MutableSpan< float3 > normals
return ret
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3836
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4170
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4312
PropertyRNA * RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int rows, int columns, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3954
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3711
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4273
void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
Definition: rna_define.c:4337
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3862
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4347
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4342
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3687
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
Definition: rna_define.c:1534
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3783
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1518
const EnumPropertyItem rna_enum_modifier_triangulate_ngon_method_items[]
Definition: rna_modifier.c:333
const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[]
Definition: rna_modifier.c:304
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.c:263
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
ListBase screens
Definition: BKE_main.h:183
struct ImageFormatData im_format
char pic[1024]
ListBase view_layers
void WM_main_add_notifier(unsigned int type, void *reference)