Blender V5.3
cycles/blender/util.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "BKE_colorband.hh"
8#include "BKE_colortools.hh"
9#include "BKE_main.hh"
10#include "DNA_fluid_types.h"
11#include "DNA_text_types.h"
12#include "RE_engine.h"
13#include "RNA_access.hh"
14
15#include "scene/mesh.h"
16#include "scene/scene.h"
17
18#include "util/algorithm.h"
19#include "util/array.h"
20#include "util/path.h"
21#include "util/set.h"
22#include "util/transform.h"
23#include "util/types.h"
24
25#include "BLI_listbase.hh"
26
27#include "DNA_mesh_types.h"
28#include "DNA_modifier_types.h"
29#include "DNA_object_types.h"
30#include "DNA_view3d_types.h"
31
32#include "BKE_global.hh"
33#include "BKE_image.hh"
34#include "BKE_lib_id.hh"
35#include "BKE_mesh.h"
36#include "BKE_mesh_types.hh"
37#include "BKE_mesh_wrapper.hh"
38#include "BKE_object.hh"
39
41
42/* To make GS macro work. */
44
45static inline blender::ID *object_get_data(const blender::Object &b_ob,
46 const bool use_adaptive_subdivision)
47{
48 if (!use_adaptive_subdivision && b_ob.type == blender::OB_MESH) {
49 return &BKE_mesh_wrapper_ensure_subdivision(blender::id_cast<blender::Mesh *>(b_ob.data))->id;
50 }
51
52 return reinterpret_cast<blender::ID *>(b_ob.data);
53}
54
56 /* Object directly provided by the depsgraph iterator. This object is only valid during one
57 * iteration and must not be accessed afterwards. Transforms and visibility should be checked on
58 * this object. */
60
61 /* This object remains alive even after the object iterator is done. It corresponds to one
62 * original object. It is the object that owns the object data below. */
64
65 /* The object-data referenced by the iter object. This is still valid after the depsgraph
66 * iterator is done. It might have a different type compared to object_get_data(real_object). */
68
69 /* Object will use adaptive subdivision. */
71
72 /* True when the current geometry is the data of the referenced object. False when it is a
73 * geometry instance that does not have a 1-to-1 relationship with an object. */
78};
79
80static inline blender::Mesh *object_copy_mesh_data(const BObjectInfo &b_ob_info)
81{
82 blender::Mesh *mesh = BKE_mesh_new_from_object(
83 nullptr, b_ob_info.real_object, false, false, !b_ob_info.use_adaptive_subdivision);
84 return mesh;
85}
86
87int blender_attribute_name_split_type(ustring name, string *r_real_name);
88
89static inline blender::Mesh *object_to_mesh(BObjectInfo &b_ob_info)
90{
91 blender::Mesh *mesh = (b_ob_info.object_data->id_type() == blender::ID_ME) ?
92 blender::id_cast<blender::Mesh *>(b_ob_info.object_data) :
93 nullptr;
94
95 if (b_ob_info.is_real_object_data()) {
96 if (mesh) {
97 if (mesh->runtime->edit_mesh) {
98 /* Flush edit-mesh to mesh, including all data layers. */
99 mesh = object_copy_mesh_data(b_ob_info);
100 }
101 }
102 else {
103 mesh = object_copy_mesh_data(b_ob_info);
104 }
105 }
106 else {
107 /* TODO: what to do about non-mesh geometry instances? */
108 }
109
110 if (mesh) {
111 if (b_ob_info.use_adaptive_subdivision) {
112 mesh->corner_tris();
113 }
114 }
115
116 return mesh;
117}
118
119static inline void free_object_to_mesh(BObjectInfo &b_ob_info, blender::Mesh &mesh)
120{
121 if (!b_ob_info.is_real_object_data()) {
122 return;
123 }
124 /* Free mesh if we didn't just use the existing one. */
125 blender::Object *object = b_ob_info.real_object;
126 if (object_get_data(*object, b_ob_info.use_adaptive_subdivision) != &mesh.id) {
127 BKE_id_free(nullptr, &mesh.id);
128 }
129}
130
131static inline void colorramp_to_array(const blender::ColorBand &ramp,
132 array<packed_float3> &ramp_color,
133 array<float> &ramp_alpha,
134 const int size)
135{
136 const int full_size = size + 1;
137 ramp_color.resize(full_size);
138 ramp_alpha.resize(full_size);
139
140 for (int i = 0; i < full_size; i++) {
141 float color[4];
142
143 BKE_colorband_evaluate(&ramp, float(i) / float(size), color);
144 ramp_color[i] = make_float3(color[0], color[1], color[2]);
145 ramp_alpha[i] = color[3];
146 }
147}
148
149static inline void curvemap_minmax_curve(const blender::CurveMap &curve,
150 float *min_x,
151 float *max_x)
152{
153 const blender::Span<blender::CurveMapPoint> points(curve.curve, curve.totpoint);
154 *min_x = min(*min_x, points.first().x);
155 *max_x = max(*max_x, points.last().x);
156}
157
158static inline void curvemapping_minmax(const blender::CurveMapping &cumap,
159 const int num_curves,
160 float *min_x,
161 float *max_x)
162{
163 // const int num_curves = cumap.curves.length(); /* Gives linking error so far. */
164 *min_x = FLT_MAX;
165 *max_x = -FLT_MAX;
166 for (int i = 0; i < num_curves; ++i) {
167 const blender::CurveMap &map(cumap.cm[i]);
168 curvemap_minmax_curve(map, min_x, max_x);
169 }
170}
171
172static inline void curvemapping_to_array(const blender::CurveMapping &cumap,
173 array<float> &data,
174 const int size)
175{
176 BKE_curvemapping_changed_all(&const_cast<blender::CurveMapping &>(cumap));
177 const blender::CurveMap &curve = cumap.cm[0];
178 const int full_size = size + 1;
179 data.resize(full_size);
180 if (!curve.table) {
181 BKE_curvemapping_init(&const_cast<blender::CurveMapping &>(cumap));
182 }
183 for (int i = 0; i < full_size; i++) {
184 const float t = float(i) / float(size);
185 data[i] = BKE_curvemap_evaluateF(&cumap, &curve, t);
186 }
187}
188
190 array<float> &data,
191 const int size)
192{
193 float min = 0.0f;
194 float max = 1.0f;
195
196 curvemapping_minmax(cumap, 1, &min, &max);
197
198 const float range = max - min;
199
200 BKE_curvemapping_changed_all(&const_cast<blender::CurveMapping &>(cumap));
201
202 const blender::CurveMap &map = cumap.cm[0];
203
204 const int full_size = size + 1;
205 data.resize(full_size);
206 if (!map.table) {
207 BKE_curvemapping_init(&const_cast<blender::CurveMapping &>(cumap));
208 }
209 for (int i = 0; i < full_size; i++) {
210 const float t = min + float(i) / float(size) * range;
211 data[i] = BKE_curvemap_evaluateF(&cumap, &map, t);
212 }
213}
214
217 const int size,
218 bool rgb_curve)
219{
220 float min_x = 0.0f;
221 float max_x = 1.0f;
222
223 /* TODO(sergey): There is no easy way to automatically guess what is
224 * the range to be used here for the case when mapping is applied on
225 * top of another mapping (i.e. R curve applied on top of common
226 * one).
227 *
228 * Using largest possible range form all curves works correct for the
229 * cases like vector curves and should be good enough heuristic for
230 * the color curves as well.
231 *
232 * There might be some better estimations here tho.
233 */
234 const int num_curves = rgb_curve ? 4 : 3;
235 curvemapping_minmax(cumap, num_curves, &min_x, &max_x);
236
237 const float range_x = max_x - min_x;
238
239 BKE_curvemapping_changed_all(&const_cast<blender::CurveMapping &>(cumap));
240
241 const blender::CurveMap &mapR = cumap.cm[0];
242 const blender::CurveMap &mapG = cumap.cm[1];
243 const blender::CurveMap &mapB = cumap.cm[2];
244 if (!mapR.table || !mapG.table || !mapB.table) {
245 BKE_curvemapping_init(&const_cast<blender::CurveMapping &>(cumap));
246 }
247
248 const int full_size = size + 1;
249 data.resize(full_size);
250
251 if (rgb_curve) {
252 const blender::CurveMap &mapI = cumap.cm[3];
253 if (!mapR.table || !mapG.table || !mapB.table || !mapI.table) {
254 BKE_curvemapping_init(&const_cast<blender::CurveMapping &>(cumap));
255 }
256
257 for (int i = 0; i < full_size; i++) {
258 const float t = min_x + float(i) / float(size) * range_x;
259 data[i] = make_float3(
260 BKE_curvemap_evaluateF(&cumap, &mapR, BKE_curvemap_evaluateF(&cumap, &mapI, t)),
261 BKE_curvemap_evaluateF(&cumap, &mapG, BKE_curvemap_evaluateF(&cumap, &mapI, t)),
262 BKE_curvemap_evaluateF(&cumap, &mapB, BKE_curvemap_evaluateF(&cumap, &mapI, t)));
263 }
264 }
265 else {
266 if (!mapR.table || !mapG.table || !mapB.table) {
267 BKE_curvemapping_init(&const_cast<blender::CurveMapping &>(cumap));
268 }
269
270 for (int i = 0; i < full_size; i++) {
271 const float t = min_x + float(i) / float(size) * range_x;
272 data[i] = make_float3(BKE_curvemap_evaluateF(&cumap, &mapR, t),
273 BKE_curvemap_evaluateF(&cumap, &mapG, t),
274 BKE_curvemap_evaluateF(&cumap, &mapB, t));
275 }
276 }
277}
278
280 blender::Scene &scene,
281 bool preview)
282{
283 if (!self.is_real_object_data()) {
284 /* Comes from geometry nodes, can't use heuristic to guess if it's animated. */
285 return true;
286 }
287
288 /* Use heuristic to quickly check if object is potentially animated. */
289 const int settings = preview ? blender::eModifierMode_Realtime : blender::eModifierMode_Render;
290 return (blender::BKE_object_is_deform_modified(&scene, self.real_object) & settings) != 0;
291}
292
293static inline int render_resolution_x(const blender::RenderData &b_render)
294{
295 return b_render.xsch * b_render.size / 100;
296}
297
298static inline int render_resolution_y(const blender::RenderData &b_render)
299{
300 return b_render.ysch * b_render.size / 100;
301}
302
303static inline string image_user_file_path(blender::Main &data,
304 blender::ImageUser &iuser,
305 blender::Image &ima,
306 const int cfra)
307{
308 char filepath[1024];
309 BKE_image_user_frame_calc(&ima, &iuser, cfra);
310 BKE_image_user_file_path_ex(&data, &iuser, &ima, filepath, false, true);
311
312 return string(filepath);
313}
314
316 blender::Image &ima,
317 const int cfra)
318{
319 BKE_image_user_frame_calc(&ima, &iuser, cfra);
320 return iuser.framenr;
321}
322
324{
325 const blender::eImageSource image_source = blender::eImageSource(ima.source);
326 if (image_source == blender::IMA_SRC_TILED) {
327 /* If any tile is marked as generated, then treat the entire Image as built-in. */
328 for (blender::ImageTile &tile : ima.tiles) {
329 if (tile.gen_flag & blender::IMA_GEN_TILE) {
330 return true;
331 }
332 }
333 }
334
335 return BKE_image_has_packedfile(&ima) || image_source == blender::IMA_SRC_GENERATED ||
336 image_source == blender::IMA_SRC_MOVIE || BKE_image_is_dirty(&ima) ||
337 ((engine.flag & blender::RE_ENGINE_PREVIEW) != 0 &&
338 image_source != blender::IMA_SRC_SEQUENCE);
339}
340
341static inline void render_add_metadata(blender::RenderResult &b_rr, string name, string value)
342{
343 BKE_render_result_stamp_data(&b_rr, name.c_str(), value.c_str());
344}
345
346/* Utilities */
347
348static inline Transform get_transform(const blender::float4x4 &matrix)
349{
350 /* Convert from Blender column major to Cycles row major, assume it's an affine transform that
351 * does not need the last row. */
352 const float *ptr = matrix.base_ptr();
353 return make_transform(ptr[0],
354 ptr[4],
355 ptr[8],
356 ptr[12],
357
358 ptr[1],
359 ptr[5],
360 ptr[9],
361 ptr[13],
362
363 ptr[2],
364 ptr[6],
365 ptr[10],
366 ptr[14]);
367}
368
369static inline float2 get_float2(blender::PointerRNA &ptr, const char *name)
370{
371 float2 f;
372 RNA_float_get_array(&ptr, name, &f.x);
373 return f;
374}
375
376static inline void set_float2(blender::PointerRNA &ptr, const char *name, const float2 value)
377{
378 RNA_float_set_array(&ptr, name, &value.x);
379}
380
381static inline float3 get_float3(blender::PointerRNA &ptr, const char *name)
382{
383 float3 f;
384 RNA_float_get_array(&ptr, name, &f.x);
385 return f;
386}
387
388static inline void set_float3(blender::PointerRNA &ptr, const char *name, const float3 value)
389{
390 RNA_float_set_array(&ptr, name, &value.x);
391}
392
393static inline float4 get_float4(blender::PointerRNA &ptr, const char *name)
394{
395 float4 f;
396 RNA_float_get_array(&ptr, name, &f.x);
397 return f;
398}
399
400static inline void set_float4(blender::PointerRNA &ptr, const char *name, const float4 value)
401{
402 RNA_float_set_array(&ptr, name, &value.x);
403}
404
405static inline bool get_boolean(blender::PointerRNA &ptr, const char *name)
406{
407 return RNA_boolean_get(&ptr, name) ? true : false;
408}
409
410static inline void set_boolean(blender::PointerRNA &ptr, const char *name, bool value)
411{
412 RNA_boolean_set(&ptr, name, (int)value);
413}
414
415static inline float get_float(blender::PointerRNA &ptr, const char *name)
416{
417 return RNA_float_get(&ptr, name);
418}
419
420static inline void set_float(blender::PointerRNA &ptr, const char *name, const float value)
421{
422 RNA_float_set(&ptr, name, value);
423}
424
425static inline int get_int(blender::PointerRNA &ptr, const char *name)
426{
427 return RNA_int_get(&ptr, name);
428}
429
430static inline void set_int(blender::PointerRNA &ptr, const char *name, const int value)
431{
432 RNA_int_set(&ptr, name, value);
433}
434
435/* Get a RNA enum value with sanity check: if the RNA value is above num_values
436 * the function will return a fallback default value.
437 *
438 * NOTE: This function assumes that RNA enum values are a continuous sequence
439 * from 0 to num_values-1. Be careful to use it with enums where some values are
440 * deprecated!
441 */
442static inline int get_enum(blender::PointerRNA &ptr,
443 const char *name,
444 int num_values = -1,
445 int default_value = -1)
446{
447 int value = RNA_enum_get(&ptr, name);
448 if (num_values != -1 && value >= num_values) {
449 assert(default_value != -1);
450 value = default_value;
451 }
452 return value;
453}
454
455static inline string get_enum_identifier(blender::PointerRNA &ptr, const char *name)
456{
457 blender::PropertyRNA *prop = RNA_struct_find_property(&ptr, name);
458 const char *identifier = "";
459 const int value = RNA_property_enum_get(&ptr, prop);
460
461 RNA_property_enum_identifier(nullptr, &ptr, prop, value, &identifier);
462
463 return string(identifier);
464}
465
466static inline void set_enum(blender::PointerRNA &ptr, const char *name, const int value)
467{
468 RNA_enum_set(&ptr, name, value);
469}
470
471static inline void set_enum(blender::PointerRNA &ptr, const char *name, const string &identifier)
472{
473 RNA_enum_set_identifier(nullptr, &ptr, name, identifier.c_str());
474}
475
476static inline string get_string(blender::PointerRNA &ptr, const char *name)
477{
478 return RNA_string_get(&ptr, name);
479}
480
481static inline void set_string(blender::PointerRNA &ptr, const char *name, const string &value)
482{
483 RNA_string_set(&ptr, name, value.c_str());
484}
485
486/* Relative Paths */
487
488static inline string blender_absolute_path(blender::Main &b_data,
489 blender::ID *b_id,
490 const string &path)
491{
492 if (path.size() >= 2 && path[0] == '/' && path[1] == '/') {
493 string dirname;
494
495 if (b_id && b_id->lib) {
496 dirname = blender_absolute_path(b_data, &b_id->lib->id, b_id->lib->filepath);
497 }
498 else {
499 dirname = b_data.filepath;
500 }
501
502 return path_join(path_dirname(dirname), path.substr(2));
503 }
504
505 return path;
506}
507
508static inline string get_text_datablock_content(const blender::ID *id)
509{
510 if (id == nullptr) {
511 return "";
512 }
513 if (id->id_type() != blender::ID_TXT) {
514 return "";
515 }
516 const auto &text = *blender::id_cast<const blender::Text *>(id);
517
518 string content;
519 for (blender::TextLine &line : text.lines) {
520 content += line.line ? line.line : "";
521 content += "\n";
522 }
523
524 return content;
525}
526
527/* Texture Space */
528
529static inline void mesh_texture_space(const blender::Mesh &b_mesh, float3 &loc, float3 &size)
530{
531 float texspace_location[3];
532 float texspace_size[3];
533 BKE_mesh_texspace_get(const_cast<blender::Mesh *>(&b_mesh), texspace_location, texspace_size);
534
535 loc = make_float3(texspace_location[0], texspace_location[1], texspace_location[2]);
536 size = make_float3(texspace_size[0], texspace_size[1], texspace_size[2]);
537
538 if (size.x != 0.0f) {
539 size.x = 0.5f / size.x;
540 }
541 if (size.y != 0.0f) {
542 size.y = 0.5f / size.y;
543 }
544 if (size.z != 0.0f) {
545 size.z = 0.5f / size.z;
546 }
547
548 loc = loc * size - make_float3(0.5f, 0.5f, 0.5f);
549}
550
551/* Object motion steps, returns 0 if no motion blur needed. */
552static inline uint object_motion_steps(blender::Object &b_parent,
553 blender::Object &b_ob,
554 const int max_steps = INT_MAX)
555{
556 /* Get motion enabled and steps from object itself. */
557 blender::PointerRNA object_rna_ptr = RNA_id_pointer_create(&b_ob.id);
558 blender::PointerRNA cobject = RNA_pointer_get(&object_rna_ptr, "cycles");
559 bool use_motion = get_boolean(cobject, "use_motion_blur");
560 if (!use_motion) {
561 return 0;
562 }
563
564 int steps = max(1, get_int(cobject, "motion_steps"));
565
566 /* Also check parent object, so motion blur and steps can be
567 * controlled by dupli-group duplicator for linked groups. */
568 if (&b_parent != &b_ob) {
569 blender::PointerRNA parent_rna_ptr = RNA_id_pointer_create(&b_parent.id);
570 blender::PointerRNA parent_cobject = RNA_pointer_get(&parent_rna_ptr, "cycles");
571 use_motion &= get_boolean(parent_cobject, "use_motion_blur");
572
573 if (!use_motion) {
574 return 0;
575 }
576
577 steps = max(steps, get_int(parent_cobject, "motion_steps"));
578 }
579
580 /* Use uneven number of steps so we get one keyframe at the current frame,
581 * and use 2^(steps - 1) so objects with more/fewer steps still have samples
582 * at the same times, to avoid sampling at many different times. */
583 return min((2 << (steps - 1)) + 1, max_steps);
584}
585
586/* object uses deformation motion blur */
587static inline bool object_use_deform_motion(blender::Object &b_parent, blender::Object &b_ob)
588{
589 blender::PointerRNA b_ob_rna_ptr = RNA_id_pointer_create(&b_ob.id);
590 blender::PointerRNA cobject = RNA_pointer_get(&b_ob_rna_ptr, "cycles");
591 bool use_deform_motion = get_boolean(cobject, "use_deform_motion");
592 /* If motion blur is enabled for the object we also check
593 * whether it's enabled for the parent object as well.
594 *
595 * This way we can control motion blur from the dupli-group
596 * duplicator much easier. */
597 if (use_deform_motion && &b_parent != &b_ob) {
598 blender::PointerRNA b_parent_rna_ptr = RNA_id_pointer_create(&b_parent.id);
599 blender::PointerRNA parent_cobject = RNA_pointer_get(&b_parent_rna_ptr, "cycles");
600 use_deform_motion &= get_boolean(parent_cobject, "use_deform_motion");
601 }
602 return use_deform_motion;
603}
604
606{
607 for (blender::ModifierData &b_mod : b_ob.modifiers) {
608 if (b_mod.type == blender::eModifierType_Fluid) {
609 auto *b_mmd = reinterpret_cast<blender::FluidModifierData *>(&b_mod);
610
611 if (b_mmd->type == blender::MOD_FLUID_TYPE_DOMAIN &&
612 b_mmd->domain->type == blender::FLUID_DOMAIN_TYPE_GAS)
613 {
614 return b_mmd->domain;
615 }
616 }
617 }
618
619 return nullptr;
620}
621
623 const bool preview)
624{
625 blender::ModifierData *md = b_ob.modifiers.last();
626 if (!md) {
627 return nullptr;
628 }
630 return nullptr;
631 }
632 const blender::ModifierMode enabled_mode = preview ? blender::eModifierMode_Realtime :
634 if ((md->mode & enabled_mode) == 0) {
635 return nullptr;
636 }
637 blender::SubsurfModifierData *subsurf = reinterpret_cast<blender::SubsurfModifierData *>(md);
639 return nullptr;
640 }
641 return subsurf;
642}
643
645 const bool preview,
646 const bool use_adaptive_subdivision)
647{
648 if (!use_adaptive_subdivision) {
650 }
651
653
654 if (subsurf) {
657 }
659 }
660
662}
663
665 Mesh &mesh,
666 const bool preview,
667 const bool use_adaptive_subdivision)
668{
669 if (!use_adaptive_subdivision) {
670 mesh.set_subdivision_type(Mesh::SUBDIVISION_NONE);
671 return;
672 }
673
675
676 if (!subsurf) {
677 mesh.set_subdivision_type(Mesh::SUBDIVISION_NONE);
678 return;
679 }
680
682 mesh.set_subdivision_type(Mesh::SUBDIVISION_LINEAR);
683 return;
684 }
685
686 mesh.set_subdivision_type(Mesh::SUBDIVISION_CATMULL_CLARK);
687
688 switch (subsurf->boundary_smooth) {
690 mesh.set_subdivision_boundary_interpolation(Mesh::SUBDIVISION_BOUNDARY_EDGE_AND_CORNER);
691 break;
693 mesh.set_subdivision_boundary_interpolation(Mesh::SUBDIVISION_BOUNDARY_EDGE_ONLY);
694 break;
695 }
696
697 switch (subsurf->uv_smooth) {
699 mesh.set_subdivision_fvar_interpolation(Mesh::SUBDIVISION_FVAR_LINEAR_ALL);
700 break;
702 mesh.set_subdivision_fvar_interpolation(Mesh::SUBDIVISION_FVAR_LINEAR_CORNERS_ONLY);
703 break;
705 mesh.set_subdivision_fvar_interpolation(Mesh::SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS1);
706 break;
708 mesh.set_subdivision_fvar_interpolation(Mesh::SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS2);
709 break;
711 mesh.set_subdivision_fvar_interpolation(Mesh::SUBDIVISION_FVAR_LINEAR_BOUNDARIES);
712 break;
714 mesh.set_subdivision_fvar_interpolation(Mesh::SUBDIVISION_FVAR_LINEAR_NONE);
715 break;
716 }
717}
718
747
748/* Check whether some of "built-in" motion-related attributes are needed to be exported (includes
749 * things like velocity from cache modifier, fluid simulation).
750 *
751 * NOTE: This code is run prior to object motion blur initialization. so can not access properties
752 * set by `sync_object_motion_init()`. */
753static inline bool object_need_motion_attribute(BObjectInfo &b_ob_info, Scene *scene)
754{
755 const Scene::MotionType need_motion = scene->need_motion();
756 if (need_motion == Scene::MOTION_NONE) {
757 /* Simple case: neither motion pass nor motion blur is needed, no need in the motion related
758 * attributes. */
759 return false;
760 }
761
762 if (need_motion == Scene::MOTION_BLUR) {
763 /* A bit tricky and implicit case:
764 * - Motion blur is enabled in the scene, which implies specific number of time steps for
765 * objects.
766 * - If the object has motion blur disabled on it, it will have 0 time steps.
767 * - Motion attribute expects non-zero time steps.
768 *
769 * Avoid adding motion attributes if the motion blur will enforce 0 motion steps. */
770 blender::PointerRNA b_ob_rna_ptr = RNA_id_pointer_create(&b_ob_info.real_object->id);
771 blender::PointerRNA cobject = RNA_pointer_get(&b_ob_rna_ptr, "cycles");
772 const bool use_motion = get_boolean(cobject, "use_motion_blur");
773 if (!use_motion) {
774 return false;
775 }
776 }
777
778 /* Motion pass which implies 3 motion steps, or motion blur which is not disabled on object
779 * level. */
780 return true;
781}
782
788
789class EdgeMap {
790 public:
791 EdgeMap() = default;
792
793 void clear()
794 {
795 edges_.clear();
796 }
797
798 void insert(int v0, int v1)
799 {
800 get_sorted_verts(v0, v1);
801 edges_.insert(std::pair<int, int>(v0, v1));
802 }
803
804 bool exists(int v0, int v1)
805 {
806 get_sorted_verts(v0, v1);
807 return edges_.contains(std::pair<int, int>(v0, v1));
808 }
809
810 protected:
811 void get_sorted_verts(int &v0, int &v1)
812 {
813 if (v0 > v1) {
814 swap(v0, v1);
815 }
816 }
817
818 set<std::pair<int, int>> edges_;
819};
820
General operations, lookup, etc. for blender objects.
const char * dirname(char *path)
Object is a sort of wrapper for general info.
int blender_attribute_name_split_type(ustring name, string *r_real_name)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
btScalar max
set< std::pair< int, int > > edges_
EdgeMap()=default
void insert(int v0, int v1)
bool exists(int v0, int v1)
void get_sorted_verts(int &v0, int &v1)
@ SUBDIVISION_FVAR_LINEAR_NONE
Definition scene/mesh.h:126
@ SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS2
Definition scene/mesh.h:129
@ SUBDIVISION_FVAR_LINEAR_CORNERS_ONLY
Definition scene/mesh.h:127
@ SUBDIVISION_FVAR_LINEAR_ALL
Definition scene/mesh.h:131
@ SUBDIVISION_FVAR_LINEAR_BOUNDARIES
Definition scene/mesh.h:130
@ SUBDIVISION_FVAR_LINEAR_CORNERS_PLUS1
Definition scene/mesh.h:128
SubdivisionType
Definition scene/mesh.h:113
@ SUBDIVISION_NONE
Definition scene/mesh.h:114
@ SUBDIVISION_LINEAR
Definition scene/mesh.h:115
@ SUBDIVISION_CATMULL_CLARK
Definition scene/mesh.h:116
@ SUBDIVISION_BOUNDARY_EDGE_ONLY
Definition scene/mesh.h:121
@ SUBDIVISION_BOUNDARY_EDGE_AND_CORNER
Definition scene/mesh.h:122
Definition scene.h:133
MotionType need_motion() const
Definition scene.cpp:429
MotionType
Definition scene.h:207
@ MOTION_NONE
Definition scene.h:207
@ MOTION_BLUR
Definition scene.h:207
T * resize(const size_t newsize)
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
static void curvemapping_color_to_array(const blender::CurveMapping &cumap, array< packed_float3 > &data, const int size, bool rgb_curve)
static void set_float2(blender::PointerRNA &ptr, const char *name, const float2 value)
static string get_text_datablock_content(const blender::ID *id)
static blender::SubsurfModifierData * object_subdivision_modifier(blender::Object &b_ob, const bool preview)
static Transform get_transform(const blender::float4x4 &matrix)
static uint object_motion_steps(blender::Object &b_parent, blender::Object &b_ob, const int max_steps=INT_MAX)
static blender::ID * object_get_data(const blender::Object &b_ob, const bool use_adaptive_subdivision)
static void mesh_texture_space(const blender::Mesh &b_mesh, float3 &loc, float3 &size)
static void set_string(blender::PointerRNA &ptr, const char *name, const string &value)
static bool image_is_builtin(blender::Image &ima, blender::RenderEngine &engine)
static void set_enum(blender::PointerRNA &ptr, const char *name, const int value)
static bool region_view3d_navigating_or_transforming(const blender::RegionView3D *b_rv3d)
static PathRayVisibility object_ray_visibility(blender::Object &b_ob)
static void curvemap_minmax_curve(const blender::CurveMap &curve, float *min_x, float *max_x)
static blender::FluidDomainSettings * object_fluid_gas_domain_find(blender::Object &b_ob)
blender::ID_Type ID_Type
static float3 get_float3(blender::PointerRNA &ptr, const char *name)
static string get_string(blender::PointerRNA &ptr, const char *name)
static int render_resolution_y(const blender::RenderData &b_render)
static bool object_need_motion_attribute(BObjectInfo &b_ob_info, Scene *scene)
static void object_subdivision_to_mesh(blender::Object &b_ob, Mesh &mesh, const bool preview, const bool use_adaptive_subdivision)
static float4 get_float4(blender::PointerRNA &ptr, const char *name)
static void curvemapping_float_to_array(const blender::CurveMapping &cumap, array< float > &data, const int size)
static void curvemapping_to_array(const blender::CurveMapping &cumap, array< float > &data, const int size)
static Mesh::SubdivisionType object_subdivision_type(blender::Object &b_ob, const bool preview, const bool use_adaptive_subdivision)
static string blender_absolute_path(blender::Main &b_data, blender::ID *b_id, const string &path)
static float get_float(blender::PointerRNA &ptr, const char *name)
static blender::Mesh * object_to_mesh(BObjectInfo &b_ob_info)
static string get_enum_identifier(blender::PointerRNA &ptr, const char *name)
static void set_boolean(blender::PointerRNA &ptr, const char *name, bool value)
static bool object_use_deform_motion(blender::Object &b_parent, blender::Object &b_ob)
static blender::Mesh * object_copy_mesh_data(const BObjectInfo &b_ob_info)
static bool get_boolean(blender::PointerRNA &ptr, const char *name)
static void curvemapping_minmax(const blender::CurveMapping &cumap, const int num_curves, float *min_x, float *max_x)
static void colorramp_to_array(const blender::ColorBand &ramp, array< packed_float3 > &ramp_color, array< float > &ramp_alpha, const int size)
static int image_user_frame_number(blender::ImageUser &iuser, blender::Image &ima, const int cfra)
static string image_user_file_path(blender::Main &data, blender::ImageUser &iuser, blender::Image &ima, const int cfra)
static void render_add_metadata(blender::RenderResult &b_rr, string name, string value)
static int get_int(blender::PointerRNA &ptr, const char *name)
static bool BKE_object_is_deform_modified(BObjectInfo &self, blender::Scene &scene, bool preview)
static float2 get_float2(blender::PointerRNA &ptr, const char *name)
static void set_float3(blender::PointerRNA &ptr, const char *name, const float3 value)
static int get_enum(blender::PointerRNA &ptr, const char *name, int num_values=-1, int default_value=-1)
static void free_object_to_mesh(BObjectInfo &b_ob_info, blender::Mesh &mesh)
static void set_float(blender::PointerRNA &ptr, const char *name, const float value)
static void set_float4(blender::PointerRNA &ptr, const char *name, const float4 value)
static int render_resolution_x(const blender::RenderData &b_render)
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define assert(assertion)
#define FLT_MAX
#define INT_MAX
void set_int(int val, int &outval)
const ccl_global KernelWorkTile * tile
uint32_t PathRayVisibility
@ PATH_RAY_VISIBILITY_VOLUME_SCATTER
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_TRANSMIT
@ PATH_RAY_VISIBILITY_SHADOW
@ PATH_RAY_VISIBILITY_RAYCAST
@ PATH_RAY_VISIBILITY_DIFFUSE
@ PATH_RAY_VISIBILITY_NONE
@ PATH_RAY_VISIBILITY_GLOSSY
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_AND_JUNCTIONS
@ SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_JUNCTIONS_AND_CONCAVE
MatBase< float, 4, 4 > float4x4
Global G
Definition blender.cc:57
@ eSubsurfModifierFlag_UseAdaptiveSubdivision
int BKE_object_is_deform_modified(Scene *scene, Object *ob)
Definition object.cc:5063
@ SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS
@ SUBSURF_BOUNDARY_SMOOTH_ALL
@ G_TRANSFORM_OBJ
@ G_TRANSFORM_EDIT
@ RE_ENGINE_PREVIEW
Definition RE_engine.h:64
@ FLUID_DOMAIN_TYPE_GAS
string path_dirname(const string &path)
Definition path.cpp:422
string path_join(const string &dir, const string &file)
Definition path.cpp:436
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define swap(a, b)
Definition sort.cc:61
#define min(a, b)
Definition sort.cc:38
blender::Object * iter_object
bool is_real_object_data() const
blender::ID * object_data
blender::Object * real_object
CurveMapPoint * curve
CurveMapPoint * table
struct Library * lib
Definition DNA_ID.h:421
char filepath[1024]
Definition DNA_ID.h:562
char filepath[1024]
Definition BKE_main.hh:267
const T * base_ptr() const
bke::MeshRuntime * runtime
ListBaseT< ModifierData > modifiers
eObject_VisibilityFlag visibility_flag
eRegionView3D_Flag rflag
eSubsurfBoundarySmooth boundary_smooth
std::shared_ptr< BMEditMesh > edit_mesh
float x
float x
Definition sky_math.h:136
float x
Definition sky_math.h:225
ccl_device_inline Transform make_transform(const float a, const float b, const float c, const float d, const float e, const float f, const float g, const float h, const float i, const float j, const float k, const float l)
Definition transform.h:185