Blender V5.3
object.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9/* Allow using deprecated functionality for .blend file I/O. */
10#define DNA_DEPRECATED_ALLOW
11
12#include <cmath>
13#include <cstdio>
14#include <cstring>
15#include <optional>
16
17#include "CLG_log.h"
18
19#include "MEM_guardedalloc.h"
20
21#include "DNA_anim_types.h"
22#include "DNA_armature_types.h"
23#include "DNA_camera_types.h"
26#include "DNA_curve_types.h"
28#include "DNA_effect_types.h"
29#include "DNA_fluid_types.h"
33#include "DNA_key_types.h"
34#include "DNA_lattice_types.h"
35#include "DNA_light_types.h"
37#include "DNA_material_types.h"
38#include "DNA_mesh_types.h"
39#include "DNA_meta_types.h"
40#include "DNA_movieclip_types.h"
41#include "DNA_nla_types.h"
43#include "DNA_object_types.h"
45#include "DNA_rigidbody_types.h"
46#include "DNA_scene_types.h"
47#include "DNA_shader_fx_types.h"
48#include "DNA_view3d_types.h"
49
50#include "BLI_bounds.hh"
51#include "BLI_kdtree.hh"
52#include "BLI_linklist.hh"
53#include "BLI_listbase.hh"
54#include "BLI_math_matrix_c.hh"
57#include "BLI_path_utils.hh"
58#include "BLI_string.hh"
59#include "BLI_string_utf8.hh"
60#include "BLI_threads.hh"
61#include "BLI_utildefines.hh"
62
63#include "BLT_translation.hh"
64
65#include "BKE_action.hh"
66#include "BKE_anim_data.hh"
67#include "BKE_anim_path.h"
69#include "BKE_animsys.hh"
70#include "BKE_annotations.h"
71#include "BKE_armature.hh"
72#include "BKE_asset.hh"
73#include "BKE_bpath.hh"
74#include "BKE_camera.h"
75#include "BKE_collection.hh"
76#include "BKE_constraint.h"
77#include "BKE_crazyspace.hh"
78#include "BKE_curve.hh"
79#include "BKE_curves.hh"
80#include "BKE_deform.hh"
81#include "BKE_displist.h"
82#include "BKE_duplilist.hh"
83#include "BKE_editmesh.hh"
84#include "BKE_editmesh_cache.hh"
85#include "BKE_effect.h"
86#include "BKE_fcurve.hh"
87#include "BKE_geometry_set.hh"
89#include "BKE_global.hh"
90#include "BKE_grease_pencil.hh"
92#include "BKE_idprop.hh"
93#include "BKE_idtype.hh"
94#include "BKE_image.hh"
95#include "BKE_key.hh"
96#include "BKE_lattice.hh"
97#include "BKE_layer.hh"
98#include "BKE_lib_id.hh"
99#include "BKE_lib_query.hh"
100#include "BKE_lib_remap.hh"
101#include "BKE_library.hh"
102#include "BKE_light.h"
103#include "BKE_light_linking.h"
104#include "BKE_lightprobe.h"
105#include "BKE_linestyle.h"
106#include "BKE_main.hh"
107#include "BKE_material.hh"
108#include "BKE_mball.hh"
109#include "BKE_mesh.hh"
110#include "BKE_mesh_wrapper.hh"
111#include "BKE_modifier.hh"
112#include "BKE_multires.hh"
113#include "BKE_node.hh"
114#include "BKE_object.hh"
115#include "BKE_object_types.hh"
116#include "BKE_paint.hh"
117#include "BKE_particle.h"
118#include "BKE_pointcache.h"
119#include "BKE_pointcloud.hh"
120#include "BKE_pose_backup.h"
121#include "BKE_preview_image.hh"
122#include "BKE_report.hh"
123#include "BKE_rigidbody.h"
124#include "BKE_scene.hh"
125#include "BKE_shader_fx.hh"
126#include "BKE_softbody.h"
127#include "BKE_speaker.hh"
128#include "BKE_subdiv_ccg.hh"
129#include "BKE_vfont.hh"
130#include "BKE_volume.hh"
131
132#include "DEG_depsgraph.hh"
133#include "DEG_depsgraph_query.hh"
134
135#include "DRW_engine.hh"
136
137#include "BLO_read_write.hh"
138#include "BLO_readfile.hh"
139
140#include "SEQ_sequencer.hh"
141
142#include "ANIM_action_legacy.hh"
143#include "ANIM_animdata.hh"
144
146
147#include "RNA_prototypes.hh"
148
149#ifdef WITH_PYTHON
150# include "BPY_extern.hh"
151#endif
152
153namespace blender {
154
155static CLG_LogRef LOG = {"object"};
156
163#define VPARENT_THREADING_HACK
164
165#ifdef VPARENT_THREADING_HACK
167#endif
168
169/* The flag `contained_geometry_types` in the object runtime uses a bit for each geometry type.
170 * Statically check that there are enough bits to be used. */
173
174static void copy_object_pose(Object *obn, const Object *ob, const int flag);
175
176static void object_init_data(ID *id)
177{
178 Object *ob = id_cast<Object *>(id);
180
181 ob->type = OB_EMPTY;
182
183 ob->runtime = MEM_new<bke::ObjectRuntime>(__func__);
184
185 /* Animation Visualization defaults */
187}
188
189static void object_copy_data(Main *bmain,
190 std::optional<Library *> /*owner_library*/,
191 ID *id_dst,
192 const ID *id_src,
193 const int flag)
194{
195 Object *ob_dst = id_cast<Object *>(id_dst);
196 const Object *ob_src = id_cast<const Object *>(id_src);
197
198 ob_dst->runtime = MEM_new<bke::ObjectRuntime>(__func__, *ob_src->runtime);
200
201 /* We never handle user-count here for own data. */
202 const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
203
204 if (ob_src->totcol) {
205 ob_dst->mat = MEM_dupalloc(ob_src->mat);
206 ob_dst->matbits = MEM_dupalloc(ob_src->matbits);
207 ob_dst->totcol = ob_src->totcol;
208 }
209 else if (ob_dst->mat != nullptr || ob_dst->matbits != nullptr) {
210 /* This shall not be needed, but better be safe than sorry. */
212 0, "Object copy: non-nullptr material pointers with zero counter, should not happen.");
213 ob_dst->mat = nullptr;
214 ob_dst->matbits = nullptr;
215 }
216
217 if (ob_src->iuser) {
218 ob_dst->iuser = MEM_dupalloc(ob_src->iuser);
219 }
220
221 ob_dst->shader_fx.clear_no_delete();
222 for (ShaderFxData &fx : ob_src->shader_fx) {
224 STRNCPY(nfx->name, fx.name);
225 BKE_shaderfx_copydata_ex(&fx, nfx, flag_subdata);
226 BLI_addtail(&ob_dst->shader_fx, nfx);
227 }
228
229 if (ob_src->pose) {
230 copy_object_pose(ob_dst, ob_src, flag_subdata);
231 /* backwards compat... non-armatures can get poses in older files? */
232 if (ob_src->type == OB_ARMATURE) {
233 const bool do_pose_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
234 BKE_pose_rebuild(bmain, ob_dst, id_cast<bArmature *>(ob_dst->data), do_pose_id_user);
235 }
236 }
237
238 BKE_constraints_copy_ex(&ob_dst->constraints, &ob_src->constraints, flag_subdata, true);
239
240 ob_dst->mode = OB_MODE_OBJECT;
241 ob_dst->runtime->sculpt_session = nullptr;
242
243 if (ob_src->pd) {
244 ob_dst->pd = MEM_dupalloc(ob_src->pd);
245 }
246 BKE_rigidbody_object_copy(bmain, ob_dst, ob_src, flag_subdata);
247
248 ob_dst->modifiers.clear_no_delete();
249 ob_dst->greasepencil_modifiers.clear_no_delete();
250 /* NOTE: Also takes care of soft-body and particle systems copying. */
251 BKE_object_modifier_stack_copy(ob_dst, ob_src, true, flag_subdata);
253
254 ob_dst->pc_ids.clear_no_delete();
255
256 ob_dst->avs = ob_src->avs;
257 ob_dst->mpath = bke::motionpath::copy(ob_src->mpath);
258
259 if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
260 BKE_previewimg_id_copy(&ob_dst->id, &ob_src->id);
261 }
262 else {
263 ob_dst->preview = nullptr;
264 }
265
266 if (ob_src->lightgroup) {
267 ob_dst->lightgroup = MEM_dupalloc(ob_src->lightgroup);
268 }
269 BKE_light_linking_copy(ob_dst, ob_src, flag_subdata);
270
271 if ((flag & LIB_ID_COPY_SET_COPIED_ON_WRITE) != 0) {
272 if (ob_src->lightprobe_cache) {
273 /* Reference the original object data. */
274 ob_dst->lightprobe_cache = static_cast<LightProbeObjectCache *>(
275 MEM_dupalloc(ob_src->lightprobe_cache));
276 ob_dst->lightprobe_cache->shared = true;
277 }
278 }
279 else {
280 if (ob_src->lightprobe_cache) {
281 /* Duplicate the original object data. */
283 ob_dst->lightprobe_cache->shared = false;
284 }
285 }
286}
287
288static void object_free_data(ID *id)
289{
290 Object *ob = id_cast<Object *>(id);
291
292 /* BKE_<id>_free shall never touch to ID->us. Never ever. */
295
296 MEM_SAFE_DELETE(ob->mat);
297 MEM_SAFE_DELETE(ob->matbits);
298 MEM_SAFE_DELETE(ob->iuser);
299
300 if (ob->pose) {
301 BKE_pose_free_ex(ob->pose, false);
302 ob->pose = nullptr;
303 }
304 if (ob->mpath) {
306 ob->mpath = nullptr;
307 }
308
310
312 BKE_rigidbody_free_object(ob, nullptr);
314
315 sbFree(ob);
316
318
319 ob->pc_ids.free_no_destruct();
320
321 /* Free runtime curves data. */
322 if (ob->runtime->curve_cache) {
326 }
327 MEM_delete(ob->runtime->curve_cache);
328 ob->runtime->curve_cache = nullptr;
329 }
330
332
333 MEM_SAFE_DELETE(ob->lightgroup);
335
337
338 MEM_delete(ob->runtime);
339}
340
341static void library_foreach_modifiersForeachIDLink(void *user_data,
342 Object * /*object*/,
343 ID **id_pointer,
344 const LibraryForeachIDCallbackFlag cb_flag)
345{
346 LibraryForeachIDData *data = static_cast<LibraryForeachIDData *>(user_data);
348 data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
349}
350
352 void *user_data,
353 Object * /*object*/,
354 ID **id_pointer,
355 const LibraryForeachIDCallbackFlag cb_flag)
356{
357 LibraryForeachIDData *data = static_cast<LibraryForeachIDData *>(user_data);
359 data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
360}
361
362static void library_foreach_shaderfxForeachIDLink(void *user_data,
363 Object * /*object*/,
364 ID **id_pointer,
365 const LibraryForeachIDCallbackFlag cb_flag)
366{
367 LibraryForeachIDData *data = static_cast<LibraryForeachIDData *>(user_data);
369 data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
370}
371
373 ID **id_pointer,
374 bool is_reference,
375 void *user_data)
376{
377 LibraryForeachIDData *data = static_cast<LibraryForeachIDData *>(user_data);
378 const LibraryForeachIDCallbackFlag cb_flag = is_reference ? IDWALK_CB_USER : IDWALK_CB_NOP;
380 data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
381}
382
384 ID **id_pointer,
385 void *user_data,
386 const LibraryForeachIDCallbackFlag cb_flag)
387{
388 LibraryForeachIDData *data = static_cast<LibraryForeachIDData *>(user_data);
390 data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
391}
392
394{
395 Object *object = reinterpret_cast<Object *>(id);
397
398 /* object data special case */
399 if (object->type == OB_EMPTY) {
400 /* empty can have nullptr or Image */
402 }
403 else {
404 /* when set, this can't be nullptr */
405 if (object->data) {
407 }
408 }
409
413
414 for (int i = 0; i < object->totcol; i++) {
416 }
417
419
420 if (object->pd) {
423 }
424
425 if (object->pose) {
426 for (bPoseChannel &pchan : object->pose->chanbase) {
429 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
430 }));
432 data,
434 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
435 }));
436
439 data,
442 }
443 }
444
445 if (object->rigidbody_constraint) {
447 data, object->rigidbody_constraint->ob1, IDWALK_CB_NEVER_SELF);
449 data, object->rigidbody_constraint->ob2, IDWALK_CB_NEVER_SELF);
450 }
451
455 data,
459 data,
461 &object->constraints, library_foreach_constraintObjectLooper, flag, data));
464
465 for (ParticleSystem &psys : object->particlesystem) {
467 data,
469 }
470
471 if (object->soft) {
473
474 if (object->soft->effector_weights) {
476 data, object->soft->effector_weights->group, IDWALK_CB_USER);
477 }
478 }
479
480 if (object->light_linking) {
482 data, object->light_linking->receiver_collection, IDWALK_CB_USER);
484 data, object->light_linking->blocker_collection, IDWALK_CB_USER);
485 }
486
489 /* Note: This is technically _not_ needed currently, because readcode (see
490 * #object_blend_read_data) directly converts and removes these deprecated ObHook data.
491 * However, for sake of consistency, better have this ID pointer handled here nonetheless. */
492 for (ObHook &hook : object->hooks) {
493 /* No `ObHook` data should ever exist currently at a point where 'foreach_id' code is
494 * executed. */
497 }
498
500
503 /* Note that `proxy_from` is purposefully skipped here, as this should be considered as pure
504 * runtime data. */
505
507 if (paf && paf->group) {
509 }
510 }
511}
512
513static void object_foreach_path_pointcache(ListBaseT<PointCache> *ptcache_list,
514 BPathForeachPathData *bpath_data)
515{
516 for (PointCache *cache = ptcache_list->first(); cache != nullptr; cache = cache->next) {
517 if (cache->flag & PTCACHE_DISK_CACHE) {
518 BKE_bpath_foreach_path_fixed_process(bpath_data, cache->path, sizeof(cache->path));
519 }
520 }
521}
522
524{
525 /* Particle systems are stored on disk in a different way than the generic pointcache files.
526 * Or at least not in the path stored in cache->path. So that's why there's no call to
527 * object_foreach_path_pointcache() here. */
528
529 const Library *lib = ob->id.lib;
530 const char *blendfile_path = lib ? BKE_main_blendfile_path_from_library(*lib) :
531 BKE_main_blendfile_path(bpath_data->bmain);
532
533 for (ParticleSystem &psys : ob->particlesystem) {
534 bool all_caches_external = true;
535
536 if (psys.part->type == PART_HAIR && (psys.flag & PSYS_HAIR_DYNAMICS) == 0) {
537 /* Hair system without dynamics, this means it doesn't use its particle cache.
538 * NOTE: the PSYS_HAIR_DYNAMICS flag can be animated, so technically this is only correct for
539 * the current frame. */
540 continue;
541 }
542
543 for (PointCache &cache : psys.ptcaches) {
544 /* When the 'External' checkbox is checked, the regular pointcache path is used. */
545 if (cache.flag & PTCACHE_EXTERNAL) {
546 BKE_bpath_foreach_path_fixed_process(bpath_data, cache.path, sizeof(cache.path));
547 }
548 else {
549 all_caches_external = false;
550 }
551 }
552
553 if (all_caches_external) {
554 /* If all caches use the 'External' flag, the calls above have covered this particle system,
555 * and the code below can be skipped. */
556 continue;
557 }
558
559 PTCacheID pid;
560 BKE_ptcache_id_from_particles(&pid, ob, &psys);
561
562 /* Just report the directory that contains the pointcache files. */
563 char ptcache_path[FILE_MAX];
564 BKE_ptcache_path(&pid, ptcache_path);
565
566 /* The path can be modified by BKE_bpath_foreach_path_fixed_process(), for example when using
567 * "Save As..." to write the blend file to another directory. In that case blendfile-relative
568 * paths are updated, so that they still point to the same physical location on disk. This
569 * rewriting is not supported here, as the particle system cache is always in the same
570 * directory as the blend file itself.
571 *
572 * And because it's always in the same directory, it makes sense to convert the path to a
573 * blendfile-relative path. */
574 BLI_path_rel(ptcache_path, blendfile_path);
575 BKE_bpath_foreach_path_fixed_process(bpath_data, ptcache_path, sizeof(ptcache_path));
576 }
577}
578
579static void object_foreach_path(ID *id, BPathForeachPathData *bpath_data)
580{
581 Object *ob = reinterpret_cast<Object *>(id);
582
583 for (ModifierData &md : ob->modifiers) {
584 /* TODO: Move that to #ModifierTypeInfo. */
585 switch (md.type) {
587 FluidsimModifierData *fluidmd = reinterpret_cast<FluidsimModifierData *>(&md);
588 if (fluidmd->fss) {
590 bpath_data, fluidmd->fss->surfdataPath, sizeof(fluidmd->fss->surfdataPath));
591 }
592 break;
593 }
594 case eModifierType_Fluid: {
595 FluidModifierData *fmd = reinterpret_cast<FluidModifierData *>(&md);
596 if (fmd->type & MOD_FLUID_TYPE_DOMAIN && fmd->domain) {
598 bpath_data, fmd->domain->cache_directory, sizeof(fmd->domain->cache_directory));
599 }
600 break;
601 }
602 case eModifierType_Cloth: {
603 ClothModifierData *clmd = reinterpret_cast<ClothModifierData *>(&md);
604 object_foreach_path_pointcache(&clmd->ptcaches, bpath_data);
605 break;
606 }
607 case eModifierType_Ocean: {
608 OceanModifierData *omd = reinterpret_cast<OceanModifierData *>(&md);
609 BKE_bpath_foreach_path_fixed_process(bpath_data, omd->cachepath, sizeof(omd->cachepath));
610 break;
611 }
613 MeshCacheModifierData *mcmd = reinterpret_cast<MeshCacheModifierData *>(&md);
614 BKE_bpath_foreach_path_fixed_process(bpath_data, mcmd->filepath, sizeof(mcmd->filepath));
615 break;
616 }
617 case eModifierType_Nodes: {
618 auto &nmd = reinterpret_cast<NodesModifierData &>(md);
619 for (NodesModifierBake &bake : MutableSpan(nmd.bakes, nmd.bakes_num)) {
620 if (bake.packed && (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_PACKED) != 0) {
621 continue;
622 }
624 if (bake.directory && bake.directory[0]) {
625 BKE_bpath_foreach_path_allocated_process(bpath_data, &bake.directory);
626 }
627 }
628 else {
629 if (nmd.bake_directory && nmd.bake_directory[0]) {
630 BKE_bpath_foreach_path_allocated_process(bpath_data, &nmd.bake_directory);
631 }
632 }
633 }
634 break;
635 }
636 default:
637 break;
638 }
639 }
640
641 if (ob->soft != nullptr) {
643 }
644
645 object_foreach_path_particles(ob, bpath_data);
646}
647
648static void object_foreach_cache(ID *id,
649 IDTypeForeachCacheFunctionCallback function_callback,
650 void *user_data)
651{
652 Object *ob = reinterpret_cast<Object *>(id);
653 IDCacheKey key;
654 key.id_session_uid = id->session_uid;
655
656 constexpr size_t runtime_base_id = size_t(1) << 32u;
657 key.identifier = runtime_base_id + offsetof(bke::ObjectRuntime, sculpt_session);
658 function_callback(
659 id, &key, reinterpret_cast<void **>(&ob->runtime->sculpt_session), 0, user_data);
660
661 for (ModifierData &md : ob->modifiers) {
662 if (const ModifierTypeInfo *info = BKE_modifier_get_info(md.type)) {
663 if (info->foreach_cache) {
664 info->foreach_cache(ob, &md, [&](const IDCacheKey &cache_key, void **cache_p, uint flags) {
665 function_callback(id, &cache_key, cache_p, flags, user_data);
666 });
667 }
668 }
669 }
670}
671
674{
675 Object *ob = id_cast<Object *>(id);
676
677 fn.single(ob->color);
678
679 for (ShaderFxData &fx : ob->shader_fx) {
681 if (fxi && fxi->foreach_working_space_color) {
683 }
684 }
685
686 for (ModifierData &md : ob->modifiers) {
688 if (mti && mti->foreach_working_space_color) {
690 }
691 }
692}
693
694namespace forward_compat {
695
701{
702 for (ModifierData &md : ob.modifiers) {
703 if (md.type != eModifierType_Nodes) {
704 continue;
705 }
706 NodesModifierData &nmd = reinterpret_cast<NodesModifierData &>(md);
707 const IDProperty *system_props = nmd.modifier.system_properties;
708 if (!system_props) {
709 return;
710 }
711
712 IDProperty *legacy_props = bke::idprop::create_group("Nodes Modifier Settings").release();
713
714 const IDProperty *inputs = IDP_GetPropertyFromGroup(system_props, "inputs");
715 if (inputs && inputs->type == IDP_GROUP) {
716 for (const IDProperty &prop : inputs->data.group) {
717 if (prop.type != IDP_GROUP) {
718 continue;
719 }
720 const StringRefNull identifier = prop.name;
721 const IDProperty *type_prop = IDP_GetPropertyFromGroup(&prop, "type");
722 if (!type_prop) {
723 continue;
724 }
725 const int type = IDP_int_get(type_prop);
726 if (type == int(nodes::GeometryNodesInputType::Layer)) {
727 if (const IDProperty *name = IDP_GetPropertyFromGroup(&prop, "layer_name")) {
729 STRNCPY(legacy_prop->name, identifier.c_str());
730 IDP_AddToGroup(legacy_props, legacy_prop);
731 }
732 }
733 else {
734 if (const IDProperty *value = IDP_GetPropertyFromGroup(&prop, "value")) {
736 STRNCPY(legacy_prop->name, identifier.c_str());
737 IDP_AddToGroup(legacy_props, legacy_prop);
738 }
739
740 const bool use_attribute = type == int(nodes::GeometryNodesInputType::Attribute);
742 legacy_props,
743 bke::idprop::create(identifier + "_use_attribute", int(use_attribute)).release());
744
745 if (const IDProperty *name = IDP_GetPropertyFromGroup(&prop, "attribute_name")) {
746 IDProperty *legacy_attr_prop = IDP_CopyProperty_ex(name,
748 SNPRINTF(legacy_attr_prop->name, "%s_attribute_name", identifier.c_str());
749 IDP_AddToGroup(legacy_props, legacy_attr_prop);
750 }
751 }
752 }
753 }
754
755 const IDProperty *outputs = IDP_GetPropertyFromGroup(system_props, "outputs");
756 if (outputs && outputs->type == IDP_GROUP) {
757 for (const IDProperty &prop : outputs->data.group) {
758 if (prop.type != IDP_GROUP) {
759 continue;
760 }
761 const StringRefNull identifier = prop.name;
762 if (const IDProperty *name = IDP_GetPropertyFromGroup(&prop, "attribute_name")) {
764 SNPRINTF(legacy_prop->name, "%s_attribute_name", identifier.c_str());
765 IDP_AddToGroup(legacy_props, legacy_prop);
766 }
767 }
768 }
769
771 nmd.settings_legacy.properties = legacy_props;
772 }
773}
774
776{
777 for (ModifierData &md : ob.modifiers) {
778 if (md.type != eModifierType_Nodes) {
779 continue;
780 }
781 NodesModifierData &nmd = reinterpret_cast<NodesModifierData &>(md);
782 if (!nmd.settings_legacy.properties) {
783 continue;
784 }
786 nmd.settings_legacy.properties = nullptr;
787 }
788}
789
790} // namespace forward_compat
791
792static void object_blend_write(BlendWriter *writer, ID *id, const void *id_address)
793{
794 Object *ob = id_cast<Object *>(id);
795
796 const bool is_undo = writer->is_undo();
797
798 /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
799 ob->runtime = nullptr;
800
801 if (is_undo) {
802 /* For undo we stay in object mode during undo presses, so keep edit-mode disabled on save as
803 * well, can help reducing false detection of changed data-blocks. */
804 ob->mode &= ~OB_MODE_EDIT;
805 }
806
807 /* write LibData */
808 writer->write_id_struct(id_address, ob);
809 BKE_id_blend_write(writer, &ob->id);
810
811 if (!is_undo) {
813 }
814
815 /* direct data */
816 writer->write_pointer_array(ob->totcol, ob->mat);
817 writer->write_char_array(ob->totcol, ob->matbits);
818
819 if (ob->pose) {
821 BKE_pose_blend_write(writer, ob->pose);
822 }
825
826 writer->write_struct(ob->pd);
827 if (ob->soft) {
828 /* Set deprecated pointers to prevent crashes of older Blenders */
829 ob->soft->pointcache = ob->soft->shared->pointcache;
830 ob->soft->ptcaches = ob->soft->shared->ptcaches;
831 writer->write_struct(ob->soft);
832 writer->write_struct(ob->soft->shared);
834 writer->write_struct(ob->soft->effector_weights);
835 }
836
837 if (ob->rigidbody_object) {
838 /* TODO: if any extra data is added to handle duplis, will need separate function then */
839 writer->write_struct(ob->rigidbody_object);
840 }
841 if (ob->rigidbody_constraint) {
843 }
844
845 if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
846 writer->write_struct(ob->iuser);
847 }
848
850 BKE_modifier_blend_write(writer, &ob->id, &ob->modifiers);
852
853 writer->write_struct_list(&ob->pc_ids);
854
856
857 if (ob->lightgroup) {
858 writer->write_struct(ob->lightgroup);
859 }
860 if (ob->light_linking) {
861 writer->write_struct(ob->light_linking, [](BlendStructWriter<LightLinking> &struct_writer) {
862 struct_writer.shallow_data.runtime = {};
863 });
864 }
865
866 if (ob->lightprobe_cache) {
867 writer->write_struct(ob->lightprobe_cache);
868 BKE_lightprobe_cache_blend_write(writer, ob->lightprobe_cache);
869 }
870
871 if (!is_undo) {
873 }
874}
875
877{
878 Object *ob = id_cast<Object *>(id);
879
880 ob->runtime = MEM_new<bke::ObjectRuntime>(__func__);
881
882 PartEff *paf;
883
884 /* XXX This should not be needed - but seems like it can happen in some cases,
885 * so for now play safe. */
886 ob->proxy_from = nullptr;
887
888 const bool is_undo = BLO_read_data_is_undo(reader);
889 if (ob->id.tag & (ID_TAG_EXTERN | ID_TAG_INDIRECT)) {
890 /* Do not allow any non-object mode for linked data.
891 * See #34776, #42780, #81027 for more information. */
893 }
894 else if (is_undo) {
895 /* For undo we want to stay in object mode during undo presses, so keep some edit modes
896 * disabled.
897 * TODO: Check if we should not disable more edit modes here? */
899 }
900
901 BLO_read_struct(reader, bPose, &ob->pose);
902 BKE_pose_blend_read_data(reader, &ob->id, ob->pose);
903
904 BLO_read_struct(reader, bMotionPath, &ob->mpath);
905 if (ob->mpath) {
907 }
908
909 /* Only for versioning, vertex group names are now stored on object data. */
911 BLO_read_struct_list(reader, bFaceMap, &ob->fmaps);
912
914 /* Ignore failure to read, matbis will become null which is valid. */
915 (void)BLO_read_array(reader, &ob->matbits, ob->totcol);
916
917 /* do it here, below old data gets converted */
918 BKE_modifier_blend_read_data(reader, &ob->modifiers, ob);
920 BKE_shaderfx_blend_read_data(reader, &ob->shader_fx, ob);
921
922 BLO_read_struct_list(reader, PartEff, &ob->effect);
923 paf = ob->effect.first_as<PartEff>();
924 while (paf) {
925 if (paf->type == EFF_PARTICLE) {
926 paf->keys = nullptr;
927 }
928 if (paf->type == EFF_WAVE) {
929 WaveEff *wav = reinterpret_cast<WaveEff *>(paf);
930 PartEff *next = paf->next;
931 WaveModifierData *wmd = reinterpret_cast<WaveModifierData *>(
933
934 wmd->damp = wav->damp;
935 wmd->flag = WaveModifierFlag(wav->flag);
936 wmd->height = wav->height;
937 wmd->lifetime = wav->lifetime;
938 wmd->narrow = wav->narrow;
939 wmd->speed = wav->speed;
940 wmd->startx = wav->startx;
941 wmd->starty = wav->startx;
942 wmd->timeoffs = wav->timeoffs;
943 wmd->width = wav->width;
944
945 BLI_addtail(&ob->modifiers, wmd);
947
948 BLI_remlink(&ob->effect, paf);
949 MEM_delete(paf);
950
951 paf = next;
952 continue;
953 }
954 if (paf->type == EFF_BUILD) {
955 BuildEff *baf = reinterpret_cast<BuildEff *>(paf);
956 PartEff *next = paf->next;
957 BuildModifierData *bmd = reinterpret_cast<BuildModifierData *>(
959
960 bmd->start = baf->sfra;
961 bmd->length = baf->len;
962 bmd->randomize = 0;
963 bmd->seed = 1;
964
965 BLI_addtail(&ob->modifiers, bmd);
967
968 BLI_remlink(&ob->effect, paf);
969 MEM_delete(paf);
970
971 paf = next;
972 continue;
973 }
974 paf = paf->next;
975 }
976
977 BLO_read_struct(reader, PartDeflect, &ob->pd);
979 BLO_read_struct(reader, SoftBody, &ob->soft);
980 if (ob->soft) {
981 SoftBody *sb = ob->soft;
982
983 sb->bpoint = nullptr; /* init pointers so it gets rebuilt nicely */
984 sb->bspring = nullptr;
985 sb->scratch = nullptr;
986 /* although not used anymore */
987 /* still have to be loaded to be compatible with old files */
989 if (sb->keys) {
990 for (int a = 0; a < sb->totkey; a++) {
991 BLO_read_struct(reader, SBVertex, &sb->keys[a]);
992 }
993 }
994
996 if (!sb->effector_weights) {
998 }
999
1000 BLO_read_struct(reader, SoftBody_Shared, &sb->shared);
1001 if (sb->shared == nullptr) {
1002 /* Link deprecated caches if they exist, so we can use them for versioning.
1003 * We should only do this when `sb->shared == nullptr`, because those pointers
1004 * are always set (for compatibility with older Blenders). We mustn't link
1005 * the same point-cache twice. */
1006 BKE_ptcache_blend_read_data(reader, &sb->ptcaches, &sb->pointcache, false);
1007 }
1008 else {
1009 /* link caches */
1010 BKE_ptcache_blend_read_data(reader, &sb->shared->ptcaches, &sb->shared->pointcache, false);
1011 }
1012 }
1013 BLO_read_struct(reader, FluidsimSettings, &ob->fluidsimSettings); /* NT */
1014
1016 if (ob->rigidbody_object) {
1017 RigidBodyOb *rbo = ob->rigidbody_object;
1018 /* Allocate runtime-only struct */
1019 rbo->shared = MEM_new<RigidBodyOb_Shared>("RigidBodyObShared");
1020 }
1022 if (ob->rigidbody_constraint) {
1024 }
1025
1028
1029 BKE_constraint_blend_read_data(reader, &ob->id, &ob->constraints);
1030
1031 BLO_read_struct_list(reader, ObHook, &ob->hooks);
1032 while (ob->hooks.first()) {
1033 ObHook *hook = ob->hooks.first();
1034 HookModifierData *hmd = reinterpret_cast<HookModifierData *>(
1036
1037 BLO_read_array_and_validate_size(reader, &hook->indexar, &hook->totindex);
1038
1039 /* Do conversion here because if we have loaded
1040 * a hook we need to make sure it gets converted
1041 * and freed, regardless of version.
1042 */
1043 copy_v3_v3(hmd->cent, hook->cent);
1044 hmd->falloff = hook->falloff;
1045 hmd->force = hook->force;
1046 hmd->indexar = hook->indexar;
1047 hmd->object = hook->parent;
1048 memcpy(hmd->parentinv, hook->parentinv, sizeof(hmd->parentinv));
1049 hmd->indexar_num = hook->totindex;
1050
1051 BLI_addhead(&ob->modifiers, hmd);
1052 BLI_remlink(&ob->hooks, hook);
1053
1054 BKE_modifier_unique_name(&ob->modifiers, reinterpret_cast<ModifierData *>(hmd));
1056
1057 MEM_delete(hook);
1058 }
1059
1060 BLO_read_struct(reader, ImageUser, &ob->iuser);
1061 if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE && !ob->iuser) {
1063 }
1064
1065 BLO_read_struct_list(reader, LinkData, &ob->pc_ids);
1066
1067 /* in case this value changes in future, clamp else we get undefined behavior */
1069
1070 BLO_read_struct(reader, PreviewImage, &ob->preview);
1072
1075
1077 if (ob->lightprobe_cache) {
1079 }
1080
1082}
1083
1085{
1086 Object *ob = reinterpret_cast<Object *>(id);
1087
1088 Main *bmain = BLO_read_lib_get_main(reader);
1089 BlendFileReadReport *reports = BLO_read_lib_reports(reader);
1090
1091 if (ob->data == nullptr && ob->type != OB_EMPTY) {
1092 /* NOTE: This case is not expected to happen anymore, since in when a linked ID disappears, an
1093 * empty placeholder is created for it by readfile code. Only some serious corruption of data
1094 * should be able to trigger this code nowadays. */
1095
1096 ob->type = OB_EMPTY;
1097
1098 if (ob->pose) {
1099 /* This code is now executed after _all_ ID pointers have been lib-linked,so it's safe to do
1100 * a proper cleanup. Further more, since user count of IDs is not done in read-code anymore,
1101 * `BKE_pose_free_ex(ob->pose, false)` can be called (instead of
1102 * `BKE_pose_free_ex(ob->pose)`), avoiding any access to other IDs altogether. */
1103 BKE_pose_free_ex(ob->pose, false);
1104 ob->pose = nullptr;
1105 ob->mode &= ~OB_MODE_POSE;
1106 }
1107
1108 if (ob->id.lib) {
1109 BLO_reportf_wrap(reports,
1110 RPT_INFO,
1111 RPT_("Cannot find object data of %s lib %s"),
1112 ob->id.name + 2,
1113 ob->id.lib->filepath);
1114 }
1115 else {
1116 BLO_reportf_wrap(reports, RPT_INFO, RPT_("Object %s lost data"), ob->id.name + 2);
1117 }
1118 reports->count.missing_obdata++;
1119 }
1120
1121 if (ob->data && ELEM(ob->type, OB_FONT, OB_CURVES_LEGACY, OB_SURF)) {
1122 /* NOTE: This case may happen when linked curve data changes it's type,
1123 * since a #Curve may be used for Text/Surface/Curve.
1124 * Since the same ID type is used for all of these.
1125 * Within a file (no library linking) this should never happen.
1126 * see: #139133. */
1127
1129 /* Don't recalculate any internal curve data is this is low level logic
1130 * intended to avoid errors when switching between font/curve types. */
1131 BKE_curve_type_test(ob, false);
1132 }
1133
1134 /* When the object is local and the data is library its possible
1135 * the material list size gets out of sync. #22663. */
1136 if (ob->data && ob->id.lib != ob->data->lib) {
1137 BKE_object_materials_sync_length(bmain, ob, ob->data);
1138 }
1139
1140 /* Performs quite extensive rebuilding & validation of object-level Pose data from the Armature
1141 * obdata. */
1142 BKE_pose_blend_read_after_liblink(reader, ob, ob->pose);
1143
1145
1146 /* When loading undo steps, for objects in modes that use `sculpt_session`, recreate the mode
1147 * runtime data. For regular non-undo reading, this is currently handled by mode switching after
1148 * the initial file read. */
1150 /* The runtime may have been created in a non-matching mode and should be deleted here. */
1151 if (ob->runtime->sculpt_session != nullptr &&
1152 ob->runtime->sculpt_session->mode_type != ob->mode)
1153 {
1155 }
1156 if (ob->runtime->sculpt_session == nullptr) {
1158 }
1159 }
1160}
1161
1163{
1164 PartEff *paf;
1165
1166 paf = ob->effect.first_as<PartEff>();
1167 while (paf) {
1168 if (paf->type == EFF_PARTICLE) {
1169 return paf;
1170 }
1171 paf = paf->next;
1172 }
1173 return nullptr;
1174}
1175
1176static void object_lib_override_apply_post(ID *id_dst, ID *id_src)
1177{
1178 /* id_dst is the new local override copy of the linked reference data. id_src is the old override
1179 * data stored on disk, used as source data for override operations. */
1180 Object *object_dst = id_cast<Object *>(id_dst);
1181 Object *object_src = id_cast<Object *>(id_src);
1182
1183 ListBaseT<PTCacheID> pidlist_dst, pidlist_src;
1184 BKE_ptcache_ids_from_object(&pidlist_dst, object_dst, nullptr, 0);
1185 BKE_ptcache_ids_from_object(&pidlist_src, object_src, nullptr, 0);
1186
1187 /* Problem with point caches is that several status flags (like OUTDATED or BAKED) are read-only
1188 * at RNA level, and therefore not overridable per-se.
1189 *
1190 * This code is a workaround this to check all point-caches from both source and destination
1191 * objects in parallel, and transfer those flags when it makes sense.
1192 *
1193 * This allows to keep baked caches across lib-overrides applies.
1194 *
1195 * NOTE: This is fairly hackish and weak, but so is the point-cache system as its whole. A more
1196 * robust solution would be e.g. to have a specific RNA entry point to deal with such cases
1197 * (maybe a new flag to allow override code to set values of some read-only properties?).
1198 */
1199 PTCacheID *pid_src, *pid_dst;
1200 for (pid_dst = pidlist_dst.first(), pid_src = pidlist_src.first(); pid_dst != nullptr;
1201 pid_dst = pid_dst->next, pid_src = (pid_src != nullptr) ? pid_src->next : nullptr)
1202 {
1203 /* If pid's do not match, just tag info of caches in dst as dirty and continue. */
1204 if (pid_src == nullptr) {
1205 continue;
1206 }
1207 if (pid_dst->type != pid_src->type || pid_dst->file_type != pid_src->file_type ||
1208 pid_dst->default_step != pid_src->default_step || pid_dst->max_step != pid_src->max_step ||
1209 pid_dst->data_types != pid_src->data_types || pid_dst->info_types != pid_src->info_types)
1210 {
1211 for (PointCache &point_cache_src : *pid_src->ptcaches) {
1212 point_cache_src.flag |= PTCACHE_FLAG_INFO_DIRTY;
1213 }
1214 continue;
1215 }
1216
1217 PointCache *point_cache_dst, *point_cache_src;
1218 for (point_cache_dst = pid_dst->ptcaches->first(),
1219 point_cache_src = pid_src->ptcaches->first();
1220 point_cache_dst != nullptr;
1221 point_cache_dst = point_cache_dst->next,
1222 point_cache_src = (point_cache_src != nullptr) ? point_cache_src->next : nullptr)
1223 {
1224 /* Always force updating info about caches of applied lib-overrides. */
1225 point_cache_dst->flag |= PTCACHE_FLAG_INFO_DIRTY;
1226 if (point_cache_src == nullptr || !STREQ(point_cache_dst->name, point_cache_src->name)) {
1227 continue;
1228 }
1229 if ((point_cache_src->flag & PTCACHE_BAKED) != 0) {
1230 point_cache_dst->flag |= PTCACHE_BAKED;
1231 }
1232 if ((point_cache_src->flag & PTCACHE_OUTDATED) == 0) {
1233 point_cache_dst->flag &= ~PTCACHE_OUTDATED;
1234 }
1235 }
1236 }
1237 pidlist_dst.free_no_destruct();
1238 pidlist_src.free_no_destruct();
1239}
1240
1242{
1243 using namespace blender::bke;
1244 float3 dimensions;
1245 BKE_object_dimensions_get(ob, dimensions);
1246 if (is_zero_v3(dimensions)) {
1247 return nullptr;
1248 }
1249 return idprop::create("dimensions", Span(&dimensions.x, 3)).release();
1250}
1251
1252static void object_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_data)
1253{
1254 Object *ob = static_cast<Object *>(asset_ptr);
1255 BLI_assert(GS(ob->id.name) == ID_OB);
1256
1257 /* Update dimensions hint for the asset. */
1258 if (IDProperty *dimensions_prop = object_asset_dimensions_property(ob)) {
1259 BKE_asset_metadata_idprop_ensure(asset_data, dimensions_prop);
1260 }
1261}
1262
1264 /*pre_save_fn*/ object_asset_metadata_ensure,
1265 /*on_mark_asset_fn*/ object_asset_metadata_ensure,
1266 /*on_clear_asset_fn*/ nullptr,
1267};
1268
1270 .id_code = Object::id_type,
1271 .id_filter = FILTER_ID_OB,
1272 /* Could be more specific, but simpler to just always say 'yes' here. */
1273 .dependencies_id_types = FILTER_ID_ALL,
1274 .main_listbase_index = INDEX_ID_OB,
1275 .struct_size = sizeof(Object),
1276 .name = "Object",
1277 .name_plural = N_("objects"),
1278 .translation_context = BLT_I18NCONTEXT_ID_OBJECT,
1279 .flags = 0,
1280 .asset_type_info = &AssetType_OB,
1281
1282 .init_data = object_init_data,
1283 .copy_data = object_copy_data,
1284 .free_data = object_free_data,
1285 .make_local = nullptr,
1286 .foreach_id = object_foreach_id,
1287 .foreach_cache = object_foreach_cache,
1288 .foreach_path = object_foreach_path,
1289 .foreach_working_space_color = object_foreach_working_space_color,
1290 .foreach_asset_weak_reference = nullptr,
1291 .owner_pointer_get = nullptr,
1292
1293 .blend_write = object_blend_write,
1294 .blend_read_data = object_blend_read_data,
1295 .blend_read_after_liblink = object_blend_read_after_liblink,
1296
1297 .blend_read_undo_preserve = nullptr,
1298
1299 .lib_override_apply_post = object_lib_override_apply_post,
1300};
1301
1303{
1304 *workob = dna::shallow_zero_initialize();
1305
1306 workob->scale[0] = workob->scale[1] = workob->scale[2] = 1.0f;
1307 workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f;
1308 workob->rotmode = ROT_MODE_EUL;
1309}
1310
1312{
1313 while (ParticleSystem *psys = static_cast<ParticleSystem *>(BLI_pophead(&ob->particlesystem))) {
1314 psys_free(ob, psys);
1315 }
1316}
1317
1319{
1320 sbFree(ob);
1321}
1322
1324{
1325 if (ob->runtime->curve_cache) {
1329 MEM_delete(ob->runtime->curve_cache->anim_path_accum_length);
1330 }
1332 MEM_delete(ob->runtime->curve_cache);
1333 ob->runtime->curve_cache = nullptr;
1334 }
1335}
1336
1337void BKE_object_free_modifiers(Object *ob, const int flag)
1338{
1339 while (ModifierData *md = static_cast<ModifierData *>(BLI_pophead(&ob->modifiers))) {
1340 BKE_modifier_free_ex(md, flag);
1341 }
1342
1343 while (GpencilModifierData *gp_md = static_cast<GpencilModifierData *>(
1345 {
1347 }
1348 /* Particle modifiers were freed, so free the particle-systems as well. */
1350
1351 /* Same for soft-body */
1353
1354 /* modifiers may have stored data in the DM cache */
1356}
1357
1358void BKE_object_free_shaderfx(Object *ob, const int flag)
1359{
1360 while (ShaderFxData *fx = static_cast<ShaderFxData *>(BLI_pophead(&ob->shader_fx))) {
1361 BKE_shaderfx_free_ex(fx, flag);
1362 }
1363}
1364
1366{
1367 /* reset functionality */
1368 if (hmd->object) {
1370
1371 if (hmd->subtarget[0] && pchan) {
1372 float imat[4][4], mat[4][4];
1373
1374 /* Calculate the world-space matrix for the pose-channel target first,
1375 * then carry on as usual. */
1376 mul_m4_m4m4(mat, hmd->object->object_to_world().ptr(), pchan->pose_mat);
1377
1378 invert_m4_m4(imat, mat);
1379 mul_m4_m4m4(hmd->parentinv, imat, ob->object_to_world().ptr());
1380 }
1381 else {
1383 hmd->object->object_to_world().ptr());
1385 hmd->parentinv, hmd->object->world_to_object().ptr(), ob->object_to_world().ptr());
1386 }
1387 }
1388}
1389
1391{
1392 if (hmd->object == nullptr) {
1393 return;
1394 }
1395 /* reset functionality */
1397
1398 if (hmd->subtarget[0] && pchan) {
1399 float imat[4][4], mat[4][4];
1400
1401 /* Calculate the world-space matrix for the pose-channel target first,
1402 * then carry on as usual. */
1403 mul_m4_m4m4(mat, hmd->object->object_to_world().ptr(), pchan->pose_mat);
1404
1405 invert_m4_m4(imat, mat);
1406 mul_m4_m4m4(hmd->parentinv, imat, ob->object_to_world().ptr());
1407 }
1408 else {
1410 hmd->object->object_to_world().ptr());
1411 mul_m4_m4m4(hmd->parentinv, hmd->object->world_to_object().ptr(), ob->object_to_world().ptr());
1412 }
1413}
1414
1416{
1417 for (ModifierData &md_iter : ob->modifiers) {
1418 md_iter.flag &= ~eModifierFlag_Active;
1419 }
1420
1421 if (md != nullptr) {
1422 BLI_assert(BLI_findindex(&ob->modifiers, md) != -1);
1424 }
1425}
1426
1428{
1429 /* In debug mode, check for only one active modifier. */
1430#ifndef NDEBUG
1431 int active_count = 0;
1432 for (ModifierData &md : ob->modifiers) {
1433 if (md.flag & eModifierFlag_Active) {
1434 active_count++;
1435 }
1436 }
1437 BLI_assert(ELEM(active_count, 0, 1));
1438#endif
1439
1440 for (ModifierData &md : ob->modifiers) {
1441 if (md.flag & eModifierFlag_Active) {
1442 return &md;
1443 }
1444 }
1445
1446 return nullptr;
1447}
1448
1450{
1451 return ELEM(ob->type,
1452 OB_MESH,
1453 OB_CURVES,
1455 OB_SURF,
1456 OB_FONT,
1457 OB_LATTICE,
1459 OB_VOLUME,
1461 OB_EMPTY);
1462}
1463
1464bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
1465{
1466 const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(modifier_type));
1467
1468 /* Surface and lattice objects don't output geometry sets. */
1469 if (mti->modify_geometry_set != nullptr && ELEM(ob->type, OB_SURF, OB_LATTICE)) {
1470 return false;
1471 }
1472
1473 /* Empties only support geometry nodes modifiers. */
1474 if (ob->type == OB_EMPTY) {
1475 return modifier_type == eModifierType_Nodes;
1476 }
1477 if (ELEM(ob->type, OB_POINTCLOUD, OB_CURVES)) {
1479 }
1480 if (ob->type == OB_VOLUME) {
1481 return mti->modify_geometry_set != nullptr;
1482 }
1484 if (ob->type == OB_LATTICE && (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly) == 0) {
1485 return false;
1486 }
1487
1488 if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) ||
1489 (ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh))))
1490 {
1491 return false;
1492 }
1493
1494 return true;
1495 }
1497 return true;
1498 }
1499
1500 return false;
1501}
1502
1504{
1506}
1507
1518 const Scene *scene,
1519 Object *ob_dst,
1520 ParticleSystem *psys_src)
1521{
1522 ParticleSystem *psys_dst = nullptr;
1523
1524 /* Check if a particle system with the same particle settings
1525 * already exists on the destination object. */
1526 for (ParticleSystem &psys : ob_dst->particlesystem) {
1527 if (psys.part == psys_src->part) {
1528 psys_dst = &psys;
1529 break;
1530 }
1531 }
1532
1533 /* If it does not exist, copy the particle system to the destination object. */
1534 if (psys_dst == nullptr) {
1535 ModifierData *md = object_copy_particle_system(bmain, scene, ob_dst, psys_src);
1536 psys_dst = (reinterpret_cast<ParticleSystemModifierData *>(md))->psys;
1537 }
1538
1539 return psys_dst;
1540}
1541
1543 const Scene *scene,
1544 Object *ob_dst,
1545 const Object *ob_src,
1546 const ModifierData *md_src)
1547{
1548 const ModifierTypeInfo *mti = BKE_modifier_get_info(md_src->type);
1549 if (!object_modifier_type_copy_check(md_src->type)) {
1550 /* We never allow copying those modifiers here. */
1551 return nullptr;
1552 }
1553 if (!BKE_object_support_modifier_type_check(ob_dst, md_src->type)) {
1554 return nullptr;
1555 }
1556 if (mti->flags & eModifierTypeFlag_Single) {
1557 if (BKE_modifiers_findby_type(ob_dst, md_src->type) != nullptr) {
1558 return nullptr;
1559 }
1560 }
1561
1562 ParticleSystem *psys_src = nullptr;
1563 ParticleSystem *psys_dst = nullptr;
1564
1565 switch (md_src->type) {
1567 BKE_object_copy_softbody(ob_dst, ob_src, 0);
1568 break;
1569 case eModifierType_Skin:
1570 /* ensure skin-node customdata exists */
1571 BKE_mesh_ensure_skin_customdata(id_cast<Mesh *>(ob_dst->data));
1572 break;
1573 case eModifierType_Fluid: {
1574 const FluidModifierData *fmd = reinterpret_cast<const FluidModifierData *>(md_src);
1575 if (fmd->type == MOD_FLUID_TYPE_FLOW) {
1576 if (fmd->flow != nullptr && fmd->flow->psys != nullptr) {
1577 psys_src = fmd->flow->psys;
1578 psys_dst = object_copy_modifier_particle_system_ensure(bmain, scene, ob_dst, psys_src);
1579 }
1580 }
1581 break;
1582 }
1584 const DynamicPaintModifierData *dpmd = reinterpret_cast<const DynamicPaintModifierData *>(
1585 md_src);
1586 if (dpmd->brush != nullptr && dpmd->brush->psys != nullptr) {
1587 psys_src = dpmd->brush->psys;
1588 psys_dst = object_copy_modifier_particle_system_ensure(bmain, scene, ob_dst, psys_src);
1589 }
1590 break;
1591 }
1592 default:
1593 break;
1594 }
1595
1596 ModifierData *md_dst;
1597 if (md_src->type == eModifierType_ParticleSystem) {
1599 bmain,
1600 scene,
1601 ob_dst,
1602 (reinterpret_cast<const ParticleSystemModifierData *>(md_src))->psys);
1603 }
1604 else {
1605 md_dst = BKE_modifier_new(md_src->type);
1606
1607 STRNCPY_UTF8(md_dst->name, md_src->name);
1608
1609 if (md_src->type == eModifierType_Multires) {
1610 /* Has to be done after mod creation, but *before* we actually copy its settings! */
1612 reinterpret_cast<const MultiresModifierData *>(md_src),
1613 reinterpret_cast<MultiresModifierData *>(md_dst));
1614 }
1615
1616 BKE_modifier_copydata(md_src, md_dst);
1617
1618 switch (md_dst->type) {
1620 if (psys_dst != nullptr) {
1621 FluidModifierData *fmd_dst = reinterpret_cast<FluidModifierData *>(md_dst);
1622 BLI_assert(fmd_dst->type == MOD_FLUID_TYPE_FLOW && fmd_dst->flow != nullptr &&
1623 fmd_dst->flow->psys != nullptr);
1624 fmd_dst->flow->psys = psys_dst;
1625 }
1626 break;
1628 if (psys_dst != nullptr) {
1629 DynamicPaintModifierData *dpmd_dst = reinterpret_cast<DynamicPaintModifierData *>(
1630 md_dst);
1631 BLI_assert(dpmd_dst->brush != nullptr && dpmd_dst->brush->psys != nullptr);
1632 dpmd_dst->brush->psys = psys_dst;
1633 }
1634 break;
1635 default:
1636 break;
1637 }
1638
1640 BKE_modifier_unique_name(&ob_dst->modifiers, md_dst);
1641 BKE_modifiers_persistent_uid_init(*ob_dst, *md_dst);
1642 }
1643
1644 return md_dst;
1645}
1646
1648 const Object *ob_src,
1649 const bool do_copy_all,
1650 const int flag_subdata)
1651{
1652 if (!ob_dst->modifiers.is_empty() || !ob_dst->greasepencil_modifiers.is_empty()) {
1654 false,
1655 "Trying to copy a modifier stack into an object having a non-empty modifier stack.");
1656 return false;
1657 }
1658
1659 for (ModifierData &md_src : ob_src->modifiers) {
1660 if (!do_copy_all && !object_modifier_type_copy_check(md_src.type)) {
1661 continue;
1662 }
1663 if (!BKE_object_support_modifier_type_check(ob_dst, md_src.type)) {
1664 continue;
1665 }
1666
1667 ModifierData *md_dst = BKE_modifier_copy_ex(&md_src, flag_subdata);
1668 BLI_addtail(&ob_dst->modifiers, md_dst);
1669 }
1670
1671 /* This could be copied from anywhere, since no other modifier actually use this data. But for
1672 * consistency do it together with particle systems. */
1673 BKE_object_copy_softbody(ob_dst, ob_src, flag_subdata);
1674
1675 /* It is mandatory that this happens after copying modifiers, as it will update their `psys`
1676 * pointers accordingly. */
1677 BKE_object_copy_particlesystems(ob_dst, ob_src, flag_subdata);
1678
1679 return true;
1680}
1681
1682void BKE_object_link_modifiers(Object *ob_dst, const Object *ob_src)
1683{
1684 BKE_object_free_modifiers(ob_dst, 0);
1685
1686 BKE_object_modifier_stack_copy(ob_dst, ob_src, false, 0);
1687}
1688
1692static void copy_ccg_data(Mesh *mesh_dst, Mesh *mesh_src, const eCustomDataType layer_type)
1693{
1694 BLI_assert(mesh_dst->corners_num == mesh_src->corners_num);
1695 CustomData *data_dst = &mesh_dst->corner_data;
1696 CustomData *data_src = &mesh_src->corner_data;
1697 const int num_elements = mesh_src->corners_num;
1698 if (!CustomData_has_layer(data_src, layer_type)) {
1699 return;
1700 }
1701 const int layer_index = CustomData_get_layer_index(data_dst, layer_type);
1702 CustomData_free_layer(data_dst, layer_type, layer_index);
1703 BLI_assert(!CustomData_has_layer(data_dst, layer_type));
1704 CustomData_add_layer(data_dst, eCustomDataType(layer_type), CD_SET_DEFAULT, num_elements);
1705 BLI_assert(CustomData_has_layer(data_dst, layer_type));
1706 CustomData_copy_layer_type_data(data_src, data_dst, layer_type, 0, 0, num_elements);
1707}
1708
1710{
1711 /* Currently CCG is only created for Mesh objects. */
1712 if (object->type != OB_MESH) {
1713 return;
1714 }
1715 const bke::GeometrySet *geometry_set_eval = object->runtime->geometry_set_eval;
1716 if (geometry_set_eval == nullptr) {
1717 /* Object was never evaluated, so can not have CCG subdivision surface. */
1718 return;
1719 }
1720 /* Check for owns_direct_data() which may reference the original mesh from before modifier
1721 * evaluation. In that case the mesh can't be read, because it's a separately owned ID that most
1722 * likely comes from the object's copy-on-eval modifier input mesh which the depsgraph free
1723 * destroys in an undefined order. For non read-only ownership types, the GeometrySet will have a
1724 * user for the mesh, so it can be safely read here. */
1725 const auto *mesh_component = geometry_set_eval->get_component<bke::MeshComponent>();
1726 if (mesh_component == nullptr || !mesh_component->owns_direct_data()) {
1727 return;
1728 }
1729 const Mesh *mesh_eval = mesh_component->get();
1730 if (mesh_eval == nullptr) {
1731 return;
1732 }
1733 SubdivCCG *subdiv_ccg = mesh_eval->runtime->subdiv_ccg.get();
1734 if (subdiv_ccg == nullptr) {
1735 return;
1736 }
1737 /* Check whether there is anything to be reshaped. */
1738 if (!subdiv_ccg->dirty.coords && !subdiv_ccg->dirty.hidden) {
1739 return;
1740 }
1741 const int tot_level = mesh_eval->runtime->subdiv_ccg_tot_level;
1742 Object *object_orig = DEG_get_original(object);
1743 Mesh *mesh_orig = id_cast<Mesh *>(object_orig->data);
1744 multiresModifier_reshapeFromCCG(tot_level, mesh_orig, subdiv_ccg);
1745 /* NOTE: we need to reshape into an original mesh from main database,
1746 * allowing:
1747 *
1748 * - Update copies of that mesh at any moment.
1749 * - Save the file without doing extra reshape.
1750 * - All the users of the mesh have updated displacement.
1751 *
1752 * However, the tricky part here is that we only know about sculpted
1753 * state of a mesh on an object level, and object is being updated after
1754 * mesh data-block is updated. This forces us to:
1755 *
1756 * - Update mesh data-block from object evaluation, which is technically
1757 * forbidden, but there is no other place for this yet.
1758 * - Reshape to the original mesh from main database, and then copy updated
1759 * layer to copy of that mesh (since copy of the mesh has decoupled
1760 * custom data layers).
1761 *
1762 * All this is defeating all the designs we need to follow to allow safe
1763 * threaded evaluation, but this is as good as we can make it within the
1764 * current sculpt/evaluated mesh design. This is also how we've survived
1765 * with old #DerivedMesh based solutions. So, while this is all wrong and
1766 * needs reconsideration, doesn't seem to be a big stopper for real
1767 * production artists.
1768 */
1769 /* TODO(sergey): Solve this somehow, to be fully stable for threaded
1770 * evaluation environment.
1771 */
1772 /* NOTE: runtime.data_orig is what was before assigning mesh_eval,
1773 * it is orig as in what was in object_eval->data before evaluating
1774 * modifier stack.
1775 *
1776 * mesh_cow is a copy-on-written version of `object_orig->data`.
1777 */
1778 Mesh *mesh_cow = id_cast<Mesh *>(object->runtime->data_orig);
1779 copy_ccg_data(mesh_cow, mesh_orig, CD_MDISPS);
1780 copy_ccg_data(mesh_cow, mesh_orig, CD_GRID_PAINT_MASK);
1781 /* Everything is now up-to-date. */
1782 subdiv_ccg->dirty.coords = false;
1783 subdiv_ccg->dirty.hidden = false;
1784}
1785
1786void BKE_object_eval_assign_data(Object *object_eval, ID *data_eval, bool is_owned)
1787{
1788 BLI_assert(object_eval->id.tag & ID_TAG_COPIED_ON_EVAL);
1789 BLI_assert(object_eval->runtime->data_eval == nullptr);
1790 BLI_assert(data_eval->tag & ID_TAG_NO_MAIN);
1791
1792 /* Assigned evaluated data. */
1793 object_eval->runtime->data_eval = data_eval;
1794 object_eval->runtime->is_data_eval_owned = is_owned;
1795
1796 /* Overwrite data of evaluated object, if the data-block types match. */
1797 ID *data = object_eval->data;
1798 if (data->id_type() == data_eval->id_type()) {
1799 /* NOTE: we are not supposed to invoke evaluation for original objects,
1800 * but some areas are still being ported, so we play safe here. */
1801 if (object_eval->id.tag & ID_TAG_COPIED_ON_EVAL) {
1802 object_eval->data = data_eval;
1803 }
1804 }
1805
1806 /* Is set separately currently. */
1807 object_eval->runtime->geometry_set_eval = nullptr;
1808}
1809
1811{
1812 ob->runtime->bounds_eval.reset();
1813
1815
1816 if (ob->runtime->data_eval != nullptr) {
1817 if (ob->runtime->is_data_eval_owned) {
1818 ID *data_eval = ob->runtime->data_eval;
1819 if (data_eval->id_type() == ID_ME) {
1820 BKE_id_free(nullptr, id_cast<Mesh *>(data_eval));
1821 }
1822 else {
1823 BKE_libblock_free_data(data_eval, false);
1824 BKE_libblock_free_datablock(data_eval, 0);
1825 MEM_delete(data_eval);
1826 }
1827 }
1828 ob->runtime->data_eval = nullptr;
1829 }
1830
1831 /* Restore initial pointer for copy-on-evaluation data-blocks, object->data
1832 * might be pointing to an evaluated data-block data was just freed above. */
1833 if (ob->runtime->data_orig != nullptr) {
1834 ob->data = ob->runtime->data_orig;
1835 }
1836
1841
1843
1844 if (ob->runtime->geometry_set_eval != nullptr) {
1845 delete ob->runtime->geometry_set_eval;
1846 ob->runtime->geometry_set_eval = nullptr;
1848 }
1849}
1850
1852{
1853 short update_flag = 0;
1854
1855 /* Free particle system caches holding paths. */
1856 if (object->particlesystem.first()) {
1857 for (ParticleSystem &psys : object->particlesystem) {
1858 psys_free_path_cache(&psys, psys.edit);
1859 update_flag |= ID_RECALC_PSYS_REDO;
1860 }
1861 }
1862
1863 /* Free memory used by cached derived meshes in the particle system modifiers. */
1864 for (ModifierData &md : object->modifiers) {
1866 ParticleSystemModifierData *psmd = reinterpret_cast<ParticleSystemModifierData *>(&md);
1867 if (psmd->mesh_final) {
1868 BKE_id_free(nullptr, psmd->mesh_final);
1869 psmd->mesh_final = nullptr;
1870 if (psmd->mesh_original) {
1871 BKE_id_free(nullptr, psmd->mesh_original);
1872 psmd->mesh_original = nullptr;
1873 }
1875 update_flag |= ID_RECALC_GEOMETRY;
1876 }
1877 }
1878 }
1879
1880 /* NOTE: If object is coming from a duplicator, it might be a temporary
1881 * object created by dependency graph, which shares pointers with original
1882 * object. In this case we can not free anything.
1883 */
1884 if ((object->base_flag & BASE_FROM_DUPLI) == 0) {
1886 update_flag |= ID_RECALC_GEOMETRY;
1887 }
1888
1889 /* Tag object for update, so once memory critical operation is over and
1890 * scene update routines are back to its business the object will be
1891 * guaranteed to be in a known state.
1892 */
1893 if (update_flag != 0) {
1894 DEG_id_tag_update(&object->id, update_flag);
1895 }
1896}
1897
1899{
1900 if (ob->data == nullptr) {
1901 return false;
1902 }
1903
1904 switch (ob->type) {
1905 case OB_MESH:
1906 return (id_cast<Mesh *>(ob->data))->runtime->edit_mesh != nullptr;
1907 case OB_ARMATURE:
1908 return (id_cast<bArmature *>(ob->data))->edbo != nullptr;
1909 case OB_FONT:
1910 return (id_cast<Curve *>(ob->data))->editfont != nullptr;
1911 case OB_MBALL:
1912 return (id_cast<MetaBall *>(ob->data))->editelems != nullptr;
1913 case OB_LATTICE:
1914 return (id_cast<Lattice *>(ob->data))->editlatt != nullptr;
1915 case OB_SURF:
1916 case OB_CURVES_LEGACY:
1917 return (id_cast<Curve *>(ob->data))->editnurb != nullptr;
1918 case OB_CURVES:
1919 case OB_POINTCLOUD:
1920 case OB_GREASE_PENCIL:
1921 return ob->mode == OB_MODE_EDIT;
1922 default:
1923 return false;
1924 }
1925}
1926
1931
1932bool BKE_object_data_is_in_editmode(const Object *ob, const ID *id)
1933{
1934 const short type = id->id_type();
1936 switch (type) {
1937 case ID_ME:
1938 return (id_cast<const Mesh *>(id))->runtime->edit_mesh != nullptr;
1939 case ID_CU_LEGACY:
1940 return (((id_cast<const Curve *>(id))->editnurb != nullptr) ||
1941 ((id_cast<const Curve *>(id))->editfont != nullptr));
1942 case ID_MB:
1943 return (id_cast<const MetaBall *>(id))->editelems != nullptr;
1944 case ID_LT:
1945 return (id_cast<const Lattice *>(id))->editlatt != nullptr;
1946 case ID_AR:
1947 return (id_cast<const bArmature *>(id))->edbo != nullptr;
1948 case ID_CV:
1949 case ID_PT:
1950 case ID_GP:
1951 if (ob) {
1952 return BKE_object_is_in_editmode(ob);
1953 }
1954 return false;
1955 default:
1957 return false;
1958 }
1959}
1960
1962{
1963 const short type = id->id_type();
1964 switch (type) {
1965 case ID_ME: {
1966 if (BMEditMesh *em = (id_cast<Mesh *>(id))->runtime->edit_mesh.get()) {
1967 return &em->needs_flush_to_id;
1968 }
1969 break;
1970 }
1971 case ID_CU_LEGACY: {
1972 if ((id_cast<Curve *>(id))->ob_type == OB_FONT) {
1973 EditFont *ef = (id_cast<Curve *>(id))->editfont;
1974 if (ef != nullptr) {
1975 return &ef->needs_flush_to_id;
1976 }
1977 }
1978 else {
1979 EditNurb *editnurb = (id_cast<Curve *>(id))->editnurb;
1980 if (editnurb) {
1981 return &editnurb->needs_flush_to_id;
1982 }
1983 }
1984 break;
1985 }
1986 case ID_MB: {
1987 MetaBall *mb = id_cast<MetaBall *>(id);
1988 return &mb->needs_flush_to_id;
1989 }
1990 case ID_LT: {
1991 EditLatt *editlatt = (id_cast<Lattice *>(id))->editlatt;
1992 if (editlatt) {
1993 return &editlatt->needs_flush_to_id;
1994 }
1995 break;
1996 }
1997 case ID_AR: {
1998 bArmature *arm = id_cast<bArmature *>(id);
1999 return &arm->needs_flush_to_id;
2000 }
2001 case ID_GP:
2002 case ID_PT:
2003 case ID_CV:
2004 return nullptr;
2005 default:
2007 return nullptr;
2008 }
2009 return nullptr;
2010}
2011
2013{
2014 if (ob->type == OB_MESH) {
2015 Mesh *mesh = id_cast<Mesh *>(ob->data);
2016 return ((ob->mode & OB_MODE_WEIGHT_PAINT) && (mesh->runtime->edit_mesh == nullptr) &&
2018 }
2019
2020 return false;
2021}
2022
2023bool BKE_object_has_mode_data(const Object *ob, eObjectMode object_mode)
2024{
2025 if (object_mode & OB_MODE_EDIT) {
2026 if (BKE_object_is_in_editmode(ob)) {
2027 return true;
2028 }
2029 }
2030 else if (object_mode & OB_MODE_VERTEX_PAINT) {
2031 if (ob->runtime->sculpt_session &&
2033 {
2034 return true;
2035 }
2036 }
2037 else if (object_mode & OB_MODE_WEIGHT_PAINT) {
2038 if (ob->runtime->sculpt_session &&
2040 {
2041 return true;
2042 }
2043 }
2044 else if (object_mode & OB_MODE_SCULPT) {
2046 {
2047 return true;
2048 }
2049 }
2050 else if (object_mode & OB_MODE_POSE) {
2051 if (ob->pose != nullptr) {
2052 return true;
2053 }
2054 }
2055 return false;
2056}
2057
2059{
2060 return ((ob->mode == object_mode) || (ob->mode & object_mode) != 0);
2061}
2062
2063int BKE_object_visibility(const Object *ob, const int dag_eval_mode)
2064{
2066 return 0;
2067 }
2068
2069 /* Test which components the object has. */
2070 int visibility = OB_VISIBLE_SELF;
2071 if (ob->particlesystem.first()) {
2073 }
2074 else if (ob->transflag & OB_DUPLI) {
2075 visibility |= OB_VISIBLE_INSTANCES;
2076 }
2077
2079 visibility |= OB_VISIBLE_INSTANCES;
2080 }
2081
2082 /* Optional hiding of self if there are particles or instancers. */
2083 if (visibility & (OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES)) {
2084 switch (eEvaluationMode(dag_eval_mode)) {
2085 case DAG_EVAL_VIEWPORT:
2087 visibility &= ~OB_VISIBLE_SELF;
2088 }
2089 break;
2090 case DAG_EVAL_RENDER:
2092 visibility &= ~OB_VISIBLE_SELF;
2093 }
2094 break;
2095 }
2096 }
2097
2098 return visibility;
2099}
2100
2101bool BKE_object_exists_check(Main *bmain, const Object *obtest)
2102{
2103 if (obtest == nullptr) {
2104 return false;
2105 }
2106
2107 for (Object &ob : bmain->objects) {
2108 if (&ob == obtest) {
2109 return true;
2110 }
2111 }
2112
2113 return false;
2114}
2115
2116/* *************************************************** */
2117
2118static const char *get_obdata_defname(ObjectType type)
2119{
2120 switch (type) {
2121 case OB_MESH:
2122 return DATA_("Mesh");
2123 case OB_CURVES_LEGACY:
2124 return DATA_("Curve");
2125 case OB_SURF:
2126 return DATA_("Surf");
2127 case OB_FONT:
2128 return DATA_("Text");
2129 case OB_MBALL:
2130 return DATA_("Mball");
2131 case OB_CAMERA:
2132 return DATA_("Camera");
2133 case OB_LAMP:
2134 return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Light");
2135 case OB_LATTICE:
2136 return DATA_("Lattice");
2137 case OB_ARMATURE:
2138 return DATA_("Armature");
2139 case OB_SPEAKER:
2140 return DATA_("Speaker");
2141 case OB_CURVES:
2142 return DATA_("Curves");
2143 case OB_POINTCLOUD:
2144 return DATA_("PointCloud");
2145 case OB_VOLUME:
2146 return CTX_DATA_(BLT_I18NCONTEXT_ID_ID, "Volume");
2147 case OB_EMPTY:
2148 return CTX_DATA_(BLT_I18NCONTEXT_ID_ID, "Empty");
2149 case OB_LIGHTPROBE:
2150 return DATA_("LightProbe");
2151 case OB_GREASE_PENCIL:
2152 return DATA_("GreasePencil");
2153 default:
2154 CLOG_ERROR(&LOG, "Internal error, bad type: %d", type);
2155 return CTX_DATA_(BLT_I18NCONTEXT_ID_ID, "Empty");
2156 }
2157}
2158
2159static void object_init(Object *ob, const ObjectType ob_type)
2160{
2161 object_init_data(&ob->id);
2162
2163 ob->type = ob_type;
2164
2165 if (ob->type != OB_EMPTY) {
2166 zero_v2(ob->ima_ofs);
2167 }
2168
2169 if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
2170 ob->trackflag = OB_NEGZ;
2171 ob->upflag = OB_POSY;
2172 }
2173
2174 if (ob->type == OB_GREASE_PENCIL) {
2176 }
2177
2178 if (ob->type == OB_LAMP) {
2179 /* Lights are invisible to camera rays and are assumed to be a
2180 * shadow catcher by default. */
2182 }
2183}
2184
2185void *BKE_object_obdata_add_from_type(Main *bmain, ObjectType type, const char *name)
2186{
2187 if (name == nullptr) {
2188 name = get_obdata_defname(type);
2189 }
2190
2191 switch (type) {
2192 case OB_MESH:
2193 return BKE_mesh_add(bmain, name);
2194 case OB_CURVES_LEGACY:
2195 return BKE_curve_add(bmain, name, OB_CURVES_LEGACY);
2196 case OB_SURF:
2197 return BKE_curve_add(bmain, name, OB_SURF);
2198 case OB_FONT:
2199 return BKE_curve_add(bmain, name, OB_FONT);
2200 case OB_MBALL:
2201 return BKE_mball_add(bmain, name);
2202 case OB_CAMERA:
2203 return BKE_camera_add(bmain, name);
2204 case OB_LAMP:
2205 return BKE_light_add(bmain, name);
2206 case OB_LATTICE:
2207 return BKE_lattice_add(bmain, name);
2208 case OB_ARMATURE:
2209 return BKE_armature_add(bmain, name);
2210 case OB_SPEAKER:
2211 return BKE_speaker_add(bmain, name);
2212 case OB_LIGHTPROBE:
2213 return BKE_lightprobe_add(bmain, name);
2214 case OB_CURVES:
2215 return BKE_curves_add(bmain, name);
2216 case OB_POINTCLOUD:
2217 return BKE_pointcloud_add(bmain, name);
2218 case OB_VOLUME:
2219 return BKE_volume_add(bmain, name);
2220 case OB_GREASE_PENCIL:
2221 return BKE_grease_pencil_add(bmain, name);
2222 case OB_EMPTY:
2223 return nullptr;
2224 default:
2225 CLOG_ERROR(&LOG, "Internal error, bad type: %d", type);
2226 return nullptr;
2227 }
2228}
2229
2231{
2232 /* Keep in sync with #OB_DATA_SUPPORT_ID macro. */
2233 switch (id->id_type()) {
2234 case ID_ME:
2235 return OB_MESH;
2236 case ID_CU_LEGACY:
2237 return reinterpret_cast<const Curve *>(id)->ob_type;
2238 case ID_MB:
2239 return OB_MBALL;
2240 case ID_LA:
2241 return OB_LAMP;
2242 case ID_SPK:
2243 return OB_SPEAKER;
2244 case ID_CA:
2245 return OB_CAMERA;
2246 case ID_LT:
2247 return OB_LATTICE;
2248 case ID_AR:
2249 return OB_ARMATURE;
2250 case ID_LP:
2251 return OB_LIGHTPROBE;
2252 case ID_CV:
2253 return OB_CURVES;
2254 case ID_PT:
2255 return OB_POINTCLOUD;
2256 case ID_VO:
2257 return OB_VOLUME;
2258 case ID_GP:
2259 return OB_GREASE_PENCIL;
2260 default:
2261 return -1;
2262 }
2263}
2264
2265Object *BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name)
2266{
2267 if (!name) {
2268 name = get_obdata_defname(type);
2269 }
2270
2271 /* We cannot use #BKE_id_new here as we need some custom initialization code. */
2272 Object *ob = static_cast<Object *>(
2273 BKE_libblock_alloc(bmain, ID_OB, name, bmain ? 0 : LIB_ID_CREATE_NO_MAIN));
2274
2275 /* We increase object user count when linking to Collections. */
2276 id_us_min(&ob->id);
2277
2278 /* default object vars */
2279 object_init(ob, type);
2280
2281 return ob;
2282}
2283
2285 Main *bmain, const Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name)
2286{
2287 Object *ob = BKE_object_add_only_object(bmain, type, name);
2288 ob->data = static_cast<ID *>(BKE_object_obdata_add_from_type(bmain, type, name));
2289 BKE_view_layer_base_deselect_all(*bmain, scene, view_layer);
2290
2293 return ob;
2294}
2295
2297 Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name)
2298{
2299 Object *ob = object_add_common(bmain, scene, view_layer, type, name);
2300
2301 LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
2302 BKE_collection_viewlayer_object_add(bmain, view_layer, layer_collection->collection, ob);
2303
2304 /* NOTE: There is no way to be sure that #BKE_collection_viewlayer_object_add will actually
2305 * manage to find a valid collection in given `view_layer` to add the new object to. */
2306 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2307 Base *base = BKE_view_layer_base_find(view_layer, ob);
2308 if (base != nullptr) {
2310 }
2311
2312 return ob;
2313}
2314
2316 Scene *scene,
2317 ViewLayer *view_layer,
2318 ObjectType type,
2319 const char *name,
2320 Object *ob_src)
2321{
2322 Object *ob = object_add_common(bmain, scene, view_layer, type, name);
2323 BKE_collection_object_add_from(bmain, scene, ob_src, ob);
2324
2325 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2326 Base *base = BKE_view_layer_base_find(view_layer, ob);
2328
2329 return ob;
2330}
2331
2333 const Scene *scene,
2334 ViewLayer *view_layer,
2335 ObjectType type,
2336 const char *name,
2337 ID *data,
2338 bool do_id_user)
2339{
2340 /* same as object_add_common, except we don't create new ob->data */
2341 Object *ob = BKE_object_add_only_object(bmain, type, name);
2342 ob->data = data;
2343 if (do_id_user) {
2345 }
2346
2347 BKE_view_layer_base_deselect_all(*bmain, scene, view_layer);
2350
2351 LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
2352 BKE_collection_object_add(bmain, layer_collection->collection, ob);
2353
2354 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
2355 Base *base = BKE_view_layer_base_find(view_layer, ob);
2357
2358 return ob;
2359}
2360
2361void BKE_object_copy_softbody(Object *ob_dst, const Object *ob_src, const int flag)
2362{
2363 SoftBody *sb = ob_src->soft;
2364
2365 ob_dst->softflag = ob_src->softflag;
2366 if (sb == nullptr) {
2367 ob_dst->soft = nullptr;
2368 return;
2369 }
2370
2371 ob_dst->soft = sbCopy(sb, flag);
2372}
2373
2375{
2376 ParticleSystem *psysn = MEM_dupalloc(psys);
2377
2378 psys_copy_particles(psysn, psys);
2379
2380 if (psys->clmd) {
2381 psysn->clmd = reinterpret_cast<ClothModifierData *>(BKE_modifier_new(eModifierType_Cloth));
2382 BKE_modifier_copydata_ex(reinterpret_cast<ModifierData *>(psys->clmd),
2383 reinterpret_cast<ModifierData *>(psysn->clmd),
2384 flag);
2385 psys->hair_in_mesh = psys->hair_out_mesh = nullptr;
2386 }
2387
2388 BLI_duplicatelist(&psysn->targets, &psys->targets);
2389
2390 psysn->pathcache = nullptr;
2391 psysn->childcache = nullptr;
2392 psysn->edit = nullptr;
2393 psysn->pdd = nullptr;
2394 psysn->effectors = nullptr;
2395 psysn->tree = nullptr;
2396 psysn->bvhtree = nullptr;
2397 psysn->batch_cache = nullptr;
2398
2399 psysn->pathcachebufs.clear_no_delete();
2400 psysn->childcachebufs.clear_no_delete();
2401
2403 /* XXX Disabled, fails when evaluating depsgraph after copying ID with no main for preview
2404 * creation. */
2405 // BLI_assert((psys->flag & PSYS_SHARED_CACHES) == 0);
2406 psysn->flag |= PSYS_SHARED_CACHES;
2407 BLI_assert(psysn->pointcache != nullptr);
2408 }
2409 else {
2410 psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, flag);
2411 }
2412
2413 /* XXX(@ideasman42): from reading existing code this seems correct but intended usage of
2414 * point-cache should with cloth should be added in 'ParticleSystem'. */
2415 if (psysn->clmd) {
2416 psysn->clmd->point_cache = psysn->pointcache;
2417 }
2418
2419 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
2420 id_us_plus(id_cast<ID *>(psysn->part));
2421 }
2422
2423 return psysn;
2424}
2425
2426void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, const int flag)
2427{
2428 if (ob_dst->type != OB_MESH) {
2429 /* currently only mesh objects can have soft body */
2430 return;
2431 }
2432
2433 ob_dst->particlesystem.clear_no_delete();
2434 for (ParticleSystem &psys : ob_src->particlesystem) {
2435 ParticleSystem *npsys = BKE_object_copy_particlesystem(&psys, flag);
2436
2437 BLI_addtail(&ob_dst->particlesystem, npsys);
2438
2439 /* need to update particle modifiers too */
2440 for (ModifierData &md : ob_dst->modifiers) {
2442 ParticleSystemModifierData *psmd = reinterpret_cast<ParticleSystemModifierData *>(&md);
2443 if (psmd->psys == &psys) {
2444 psmd->psys = npsys;
2445 }
2446 }
2447 else if (md.type == eModifierType_DynamicPaint) {
2448 DynamicPaintModifierData *pmd = reinterpret_cast<DynamicPaintModifierData *>(&md);
2449 if (pmd->brush) {
2450 if (pmd->brush->psys == &psys) {
2451 pmd->brush->psys = npsys;
2452 }
2453 }
2454 }
2455 else if (md.type == eModifierType_Fluid) {
2456 FluidModifierData *fmd = reinterpret_cast<FluidModifierData *>(&md);
2457
2458 if (fmd->type == MOD_FLUID_TYPE_FLOW) {
2459 if (fmd->flow) {
2460 if (fmd->flow->psys == &psys) {
2461 fmd->flow->psys = npsys;
2462 }
2463 }
2464 }
2465 }
2466 }
2467 }
2468}
2469
2470static void copy_object_pose(Object *obn, const Object *ob, const int flag)
2471{
2472 /* NOTE: need to clear `obn->pose` pointer first,
2473 * so that #BKE_pose_copy_data works (otherwise there's a crash) */
2474 obn->pose = nullptr;
2475 BKE_pose_copy_data_ex(&obn->pose, ob->pose, flag, true); /* true = copy constraints */
2476
2477 for (bPoseChannel &chan : obn->pose->chanbase) {
2478
2479 /* XXX Remapping object pointing onto itself should be handled by generic
2480 * BKE_library_remap stuff, but...
2481 * the flush_constraint_targets callback am not sure about, so will delay that for now. */
2482 for (bConstraint &con : chan.constraints) {
2483 ListBaseT<bConstraintTarget> targets = {nullptr, nullptr};
2484
2485 if (BKE_constraint_targets_get(&con, &targets)) {
2486 for (bConstraintTarget &ct : targets) {
2487 if (ct.tar == ob) {
2488 ct.tar = obn;
2489 }
2490 }
2491
2492 BKE_constraint_targets_flush(&con, &targets, false);
2493 }
2494 }
2495 }
2496}
2497
2499{
2500 if ((ob) && (ob->type == OB_ARMATURE) && (ob->pose) && (ob->mode & OB_MODE_POSE)) {
2501 return true;
2502 }
2503
2504 return false;
2505}
2506
2508{
2509 if (ob == nullptr) {
2510 return nullptr;
2511 }
2512
2514 return ob;
2515 }
2516
2518
2519 /* Only use selected check when non-active. */
2521 return ob;
2522 }
2523
2524 return nullptr;
2525}
2526
2528{
2529 /* When not in weight paint mode. */
2530 if (ob) {
2531 switch (ob->type) {
2532 case OB_MESH: {
2533 if ((ob->mode & OB_MODE_WEIGHT_PAINT) == 0) {
2534 return nullptr;
2535 }
2536 break;
2537 }
2538 case OB_GREASE_PENCIL: {
2539 if ((ob->mode & OB_MODE_WEIGHT_GREASE_PENCIL) == 0) {
2540 return nullptr;
2541 }
2542 break;
2543 }
2544 default:
2545 break;
2546 }
2547 }
2549}
2550
2552 const Main &bmain, Object *ob, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
2553{
2554 Object *ob_armature = BKE_object_pose_armature_get(ob);
2555 if (ob_armature) {
2556 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
2557 Base *base = BKE_view_layer_base_find(view_layer, ob_armature);
2558 if (base) {
2559 if (BASE_VISIBLE(v3d, base)) {
2560 return ob_armature;
2561 }
2562 }
2563 }
2564 return nullptr;
2565}
2566
2568 const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d, bool unique)
2569{
2570 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
2571 Object *ob_active = BKE_view_layer_active_object_get(view_layer);
2572 Object *ob_pose = BKE_object_pose_armature_get(ob_active);
2573 if (ob_pose == ob_active) {
2574 ObjectsInModeParams ob_params{};
2575 ob_params.object_mode = OB_MODE_POSE;
2576 ob_params.no_dup_data = unique;
2577
2579 bmain, scene, view_layer, v3d, &ob_params);
2580 }
2581 if (ob_pose != nullptr) {
2582 return {ob_pose};
2583 }
2584
2585 return {};
2586}
2588 const Scene *scene,
2589 ViewLayer *view_layer,
2590 View3D *v3d)
2591{
2592 return BKE_object_pose_array_get_ex(bmain, scene, view_layer, v3d, true);
2593}
2595 const Scene *scene,
2596 ViewLayer *view_layer,
2597 View3D *v3d)
2598{
2599 return BKE_object_pose_array_get_ex(bmain, scene, view_layer, v3d, false);
2600}
2601
2603 const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d, bool unique)
2604{
2605 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
2606 Base *base_active = BKE_view_layer_active_base_get(view_layer);
2607 Object *ob_pose = base_active ? BKE_object_pose_armature_get(base_active->object) : nullptr;
2608 Base *base_pose = nullptr;
2609
2610 if (base_active) {
2611 if (ob_pose == base_active->object) {
2612 base_pose = base_active;
2613 }
2614 else {
2615 base_pose = BKE_view_layer_base_find(view_layer, ob_pose);
2616 }
2617 }
2618
2619 if (base_active && (base_pose == base_active)) {
2620 ObjectsInModeParams ob_params{};
2621 ob_params.object_mode = OB_MODE_POSE;
2622 ob_params.no_dup_data = unique;
2623
2625 bmain, scene, view_layer, v3d, &ob_params);
2626 }
2627 if (base_pose != nullptr) {
2628 return {base_pose};
2629 }
2630
2631 return {};
2632}
2634 const Scene *scene,
2635 ViewLayer *view_layer,
2636 View3D *v3d)
2637{
2638 return BKE_object_pose_base_array_get_ex(bmain, scene, view_layer, v3d, true);
2639}
2641 const Scene *scene,
2642 ViewLayer *view_layer,
2643 View3D *v3d)
2644{
2645 return BKE_object_pose_base_array_get_ex(bmain, scene, view_layer, v3d, false);
2646}
2647
2648void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
2649{
2650 copy_v3_v3(ob_tar->loc, ob_src->loc);
2651 copy_v3_v3(ob_tar->rot, ob_src->rot);
2652 copy_v4_v4(ob_tar->quat, ob_src->quat);
2653 copy_v3_v3(ob_tar->rotAxis, ob_src->rotAxis);
2654 ob_tar->rotAngle = ob_src->rotAngle;
2655 ob_tar->rotmode = ob_src->rotmode;
2656 copy_v3_v3(ob_tar->scale, ob_src->scale);
2657}
2658
2660 Object *ob,
2661 eDupli_ID_Flags dupflag,
2662 /*eLibIDDuplicateFlags*/ uint duplicate_options)
2663{
2664 const bool is_subprocess = (duplicate_options & LIB_ID_DUPLICATE_IS_SUBPROCESS) != 0;
2665 const bool is_root_id = (duplicate_options & LIB_ID_DUPLICATE_IS_ROOT_ID) != 0;
2666 int copy_flags = LIB_ID_COPY_DEFAULT;
2667
2668 if (!is_subprocess) {
2670 }
2671 else {
2672 /* In case copying object is a sub-process of collection (or scene) copying, do not try to
2673 * re-assign RB objects to existing RBW collections. */
2675 }
2676 if (is_root_id) {
2677 /* In case root duplicated ID is linked, assume we want to get a local copy of it and duplicate
2678 * all expected linked data. */
2679 if (ID_IS_LINKED(ob)) {
2680 dupflag |= USER_DUP_LINKED_ID;
2681 }
2682 duplicate_options &= ~LIB_ID_DUPLICATE_IS_ROOT_ID;
2683 }
2684
2685 Material ***matarar;
2686
2687 Object *obn = id_cast<Object *>(BKE_id_copy_for_duplicate(bmain, &ob->id, dupflag, copy_flags));
2688
2689 /* 0 == full linked. */
2690 if (dupflag == 0) {
2691 return obn;
2692 }
2693
2694 if (dupflag & USER_DUP_MAT) {
2695 for (int i = 0; i < obn->totcol; i++) {
2696 BKE_id_copy_for_duplicate(bmain, id_cast<ID *>(obn->mat[i]), dupflag, copy_flags);
2697 }
2698 }
2699 if (dupflag & USER_DUP_PSYS) {
2700 for (ParticleSystem &psys : obn->particlesystem) {
2701 BKE_id_copy_for_duplicate(bmain, id_cast<ID *>(psys.part), dupflag, copy_flags);
2702 }
2703 }
2704
2705 ID *id_old = obn->data;
2706 ID *id_new = nullptr;
2707 const bool need_to_duplicate_obdata = (id_old != nullptr) && (id_old->newid == nullptr);
2708
2709 switch (obn->type) {
2710 case OB_MESH:
2711 if (dupflag & USER_DUP_MESH) {
2712 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2713 }
2714 break;
2715 case OB_CURVES_LEGACY:
2716 if (dupflag & USER_DUP_CURVE) {
2717 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2718 }
2719 break;
2720 case OB_SURF:
2721 if (dupflag & USER_DUP_SURF) {
2722 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2723 }
2724 break;
2725 case OB_FONT:
2726 if (dupflag & USER_DUP_FONT) {
2727 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2728 }
2729 break;
2730 case OB_MBALL:
2731 if (dupflag & USER_DUP_MBALL) {
2732 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2733 }
2734 break;
2735 case OB_LAMP:
2736 if (dupflag & USER_DUP_LAMP) {
2737 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2738 }
2739 break;
2740 case OB_ARMATURE:
2741 if (dupflag & USER_DUP_ARM) {
2742 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2743 }
2744 break;
2745 case OB_LATTICE:
2746 if (dupflag & USER_DUP_LATTICE) {
2747 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2748 }
2749 break;
2750 case OB_CAMERA:
2751 if (dupflag & USER_DUP_CAMERA) {
2752 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2753 }
2754 break;
2755 case OB_LIGHTPROBE:
2756 if (dupflag & USER_DUP_LIGHTPROBE) {
2757 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2758 }
2759 break;
2760 case OB_SPEAKER:
2761 if (dupflag & USER_DUP_SPEAKER) {
2762 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2763 }
2764 break;
2765 case OB_GREASE_PENCIL:
2766 if (dupflag & USER_DUP_GPENCIL) {
2767 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2768 }
2769 break;
2770 case OB_CURVES:
2771 if (dupflag & USER_DUP_CURVES) {
2772 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2773 }
2774 break;
2775 case OB_POINTCLOUD:
2776 if (dupflag & USER_DUP_POINTCLOUD) {
2777 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2778 }
2779 break;
2780 case OB_VOLUME:
2781 if (dupflag & USER_DUP_VOLUME) {
2782 id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2783 }
2784 break;
2785 default:
2786 break;
2787 }
2788
2789 /* If obdata has been copied, we may also have to duplicate the materials assigned to it. */
2790 if (need_to_duplicate_obdata && !ELEM(id_new, nullptr, id_old)) {
2791 if (dupflag & USER_DUP_MAT) {
2792 matarar = BKE_object_material_array_p(obn);
2793 if (matarar) {
2794 for (int i = 0; i < obn->totcol; i++) {
2795 BKE_id_copy_for_duplicate(bmain, id_cast<ID *>((*matarar)[i]), dupflag, copy_flags);
2796 }
2797 }
2798 }
2799 }
2800
2801 if (!is_subprocess) {
2802 /* This code will follow into all ID links using an ID tagged with ID_TAG_NEW. */
2803 /* Unfortunate, but with some types (e.g. meshes), an object is considered in Edit mode if its
2804 * obdata contains edit mode runtime data. This can be the case of all newly duplicated
2805 * objects, as even though duplicate code move the object back in Object mode, they are still
2806 * using the original obdata ID, leading to them being falsely detected as being in Edit mode,
2807 * and therefore not remapping their obdata to the newly duplicated one.
2808 * See #139715. */
2811
2812#ifndef NDEBUG
2813 /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those flags. */
2814 ID *id_iter;
2815 FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2816 BLI_assert((id_iter->tag & ID_TAG_NEW) == 0);
2817 }
2819#endif
2820
2821 /* Cleanup. */
2823 }
2824
2825 if (obn->type == OB_ARMATURE) {
2827 if (obn->pose) {
2828 BKE_pose_tag_recalc(bmain, obn->pose);
2829 }
2830 // BKE_pose_rebuild(bmain, obn, obn->data, true);
2831 }
2832
2833 if (obn->data != nullptr) {
2835 }
2836
2837 return obn;
2838}
2839
2841{
2842 return (ob && ID_IS_LINKED(ob));
2843}
2844
2846{
2847 /* Linked objects with local obdata are forbidden! */
2848 BLI_assert(!ob || !ob->data || (ID_IS_LINKED(ob) ? ID_IS_LINKED(ob->data) : true));
2849 return (ob && ob->data && ID_IS_LINKED(ob->data));
2850}
2851
2852void BKE_object_obdata_size_init(Object *ob, const float size)
2853{
2854 /* apply radius as a scale to types that support it */
2855 switch (ob->type) {
2856 case OB_EMPTY: {
2857 ob->empty_drawsize *= size;
2858 break;
2859 }
2860 case OB_FONT: {
2861 Curve *cu = id_cast<Curve *>(ob->data);
2862 cu->fsize *= size;
2863 break;
2864 }
2865 case OB_CAMERA: {
2866 Camera *cam = id_cast<Camera *>(ob->data);
2867 cam->drawsize *= size;
2868 break;
2869 }
2870 case OB_LAMP: {
2871 Light *lamp = id_cast<Light *>(ob->data);
2872 lamp->radius *= size;
2873 lamp->area_size *= size;
2874 lamp->area_sizey *= size;
2875 lamp->area_sizez *= size;
2876 break;
2877 }
2878 /* Only lattice (not mesh, curve, mball...),
2879 * because its got data when newly added */
2880 case OB_LATTICE: {
2881 Lattice *lt = id_cast<Lattice *>(ob->data);
2882 float mat[4][4];
2883
2884 unit_m4(mat);
2885 scale_m4_fl(mat, size);
2886
2887 BKE_lattice_transform(lt, static_cast<float (*)[4]>(mat), false);
2888 break;
2889 }
2890 default:
2891 break;
2892 }
2893}
2894
2895/* -------------------------------------------------------------------- */
2898
2899void BKE_object_scale_to_mat3(const Object *ob, float mat[3][3])
2900{
2901 float3 vec;
2902 mul_v3_v3v3(vec, ob->scale, ob->dscale);
2903 size_to_mat3(mat, vec);
2904}
2905
2906void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot)
2907{
2908 float rmat[3][3], dmat[3][3];
2909
2910 /* 'dmat' is the delta-rotation matrix, which will get (pre)multiplied
2911 * with the rotation matrix to yield the appropriate rotation
2912 */
2913
2914 /* Rotations may either be quaternions, eulers (with various rotation orders), or axis-angle. */
2915 if (ob->rotmode > 0) {
2916 /* Euler rotations
2917 * (will cause gimbal lock, but this can be alleviated a bit with rotation orders). */
2918 eulO_to_mat3(rmat, ob->rot, ob->rotmode);
2919 eulO_to_mat3(dmat, ob->drot, ob->rotmode);
2920 }
2921 else if (ob->rotmode == ROT_MODE_AXISANGLE) {
2922 /* axis-angle - not really that great for 3D-changing orientations */
2923 axis_angle_to_mat3(rmat, ob->rotAxis, ob->rotAngle);
2924 axis_angle_to_mat3(dmat, ob->drotAxis, ob->drotAngle);
2925 }
2926 else {
2927 /* Quaternions are normalized before use to eliminate scaling issues. */
2928 float tquat[4];
2929
2930 normalize_qt_qt(tquat, ob->quat);
2931 quat_to_mat3(rmat, tquat);
2932
2933 normalize_qt_qt(tquat, ob->dquat);
2934 quat_to_mat3(dmat, tquat);
2935 }
2936
2937 /* combine these rotations */
2938 if (use_drot) {
2939 mul_m3_m3m3(mat, dmat, rmat);
2940 }
2941 else {
2942 copy_m3_m3(mat, rmat);
2943 }
2944}
2945
2946void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
2947{
2948 BLI_ASSERT_UNIT_M3(mat);
2949
2950 switch (ob->rotmode) {
2951 case ROT_MODE_QUAT: {
2952 float dquat[4];
2953 mat3_normalized_to_quat(ob->quat, mat);
2954 normalize_qt_qt(dquat, ob->dquat);
2955 invert_qt_normalized(dquat);
2956 mul_qt_qtqt(ob->quat, dquat, ob->quat);
2957 break;
2958 }
2959 case ROT_MODE_AXISANGLE: {
2960 float quat[4];
2961 float dquat[4];
2962
2963 /* Without `drot` we could apply 'mat' directly. */
2964 mat3_normalized_to_quat(quat, mat);
2965 axis_angle_to_quat(dquat, ob->drotAxis, ob->drotAngle);
2966 invert_qt_normalized(dquat);
2967 mul_qt_qtqt(quat, dquat, quat);
2968 quat_to_axis_angle(ob->rotAxis, &ob->rotAngle, quat);
2969 break;
2970 }
2971 default: /* euler */
2972 {
2973 float quat[4];
2974 float dquat[4];
2975
2976 /* Without `drot` we could apply 'mat' directly. */
2977 mat3_normalized_to_quat(quat, mat);
2978 eulO_to_quat(dquat, ob->drot, ob->rotmode);
2979 invert_qt_normalized(dquat);
2980 mul_qt_qtqt(quat, dquat, quat);
2981 /* End `drot` correction. */
2982
2983 if (use_compat) {
2984 quat_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, quat);
2985 }
2986 else {
2987 quat_to_eulO(ob->rot, ob->rotmode, quat);
2988 }
2989 break;
2990 }
2991 }
2992}
2993
2995{
2996 float4 quat;
2997 if (ob.rotmode > 0) {
2998 eulO_to_quat(quat, ob.rot, ob.rotmode);
2999 }
3000 else if (ob.rotmode == ROT_MODE_AXISANGLE) {
3001 axis_angle_to_quat(quat, ob.rotAxis, ob.rotAngle);
3002 }
3003 else {
3004 /* Normalized quaternion to stay consistent with `BKE_pchan_rot_to_mat3`. */
3005 normalize_qt_qt(quat, ob.quat);
3006 }
3007 return quat;
3008}
3009
3011{
3012 switch (ob.rotmode) {
3013 case ROT_MODE_QUAT:
3014 normalize_qt_qt(ob.quat, quat);
3015 break;
3016 case ROT_MODE_AXISANGLE:
3017 quat_to_axis_angle(ob.rotAxis, &ob.rotAngle, quat);
3018 break;
3019 default: /* euler */
3020 quat_to_eulO(ob.rot, ob.rotmode, quat);
3021 break;
3022 }
3023}
3024
3026{
3027
3028#define TFMCPY(_v) (obtfm->_v = ob->_v)
3029#define TFMCPY3D(_v) copy_v3_v3(obtfm->_v, ob->_v)
3030#define TFMCPY4D(_v) copy_v4_v4(obtfm->_v, ob->_v)
3031
3032 TFMCPY3D(loc);
3033 TFMCPY3D(dloc);
3034 TFMCPY3D(scale);
3035 TFMCPY3D(dscale);
3036 TFMCPY3D(rot);
3037 TFMCPY3D(drot);
3038 TFMCPY4D(quat);
3039 TFMCPY4D(dquat);
3040 TFMCPY3D(rotAxis);
3041 TFMCPY3D(drotAxis);
3042 TFMCPY(rotAngle);
3043 TFMCPY(drotAngle);
3044
3045#undef TFMCPY
3046#undef TFMCPY3D
3047#undef TFMCPY4D
3048}
3049
3051 const ObjectTfmProtectedChannels *obtfm,
3052 const short protectflag)
3053{
3054 uint i;
3055
3056 for (i = 0; i < 3; i++) {
3057 if (protectflag & (OB_LOCK_LOCX << i)) {
3058 ob->loc[i] = obtfm->loc[i];
3059 ob->dloc[i] = obtfm->dloc[i];
3060 }
3061
3062 if (protectflag & (OB_LOCK_SCALEX << i)) {
3063 ob->scale[i] = obtfm->scale[i];
3064 ob->dscale[i] = obtfm->dscale[i];
3065 }
3066
3067 if (protectflag & (OB_LOCK_ROTX << i)) {
3068 ob->rot[i] = obtfm->rot[i];
3069 ob->drot[i] = obtfm->drot[i];
3070
3071 ob->quat[i + 1] = obtfm->quat[i + 1];
3072 ob->dquat[i + 1] = obtfm->dquat[i + 1];
3073
3074 ob->rotAxis[i] = obtfm->rotAxis[i];
3075 ob->drotAxis[i] = obtfm->drotAxis[i];
3076 }
3077 }
3078
3079 if ((protectflag & OB_LOCK_ROT4D) && (protectflag & OB_LOCK_ROTW)) {
3080 ob->quat[0] = obtfm->quat[0];
3081 ob->dquat[0] = obtfm->dquat[0];
3082
3083 ob->rotAngle = obtfm->rotAngle;
3084 ob->drotAngle = obtfm->drotAngle;
3085 }
3086}
3087
3088void BKE_object_tfm_copy(Object *object_dst, const Object *object_src)
3089{
3090#define TFMCPY(_v) (object_dst->_v = object_src->_v)
3091#define TFMCPY3D(_v) copy_v3_v3(object_dst->_v, object_src->_v)
3092#define TFMCPY4D(_v) copy_v4_v4(object_dst->_v, object_src->_v)
3093
3094 TFMCPY3D(loc);
3095 TFMCPY3D(dloc);
3096 TFMCPY3D(scale);
3097 TFMCPY3D(dscale);
3098 TFMCPY3D(rot);
3099 TFMCPY3D(drot);
3100 TFMCPY4D(quat);
3101 TFMCPY4D(dquat);
3102 TFMCPY3D(rotAxis);
3103 TFMCPY3D(drotAxis);
3104 TFMCPY(rotAngle);
3105 TFMCPY(drotAngle);
3106
3107#undef TFMCPY
3108#undef TFMCPY3D
3109#undef TFMCPY4D
3110}
3111
3112void BKE_object_to_mat3(const Object *ob, float r_mat[3][3]) /* no parent */
3113{
3114 float smat[3][3];
3115 float rmat[3][3];
3116
3117 /* Scale. */
3118 BKE_object_scale_to_mat3(ob, smat);
3119
3120 /* Rotation. */
3121 BKE_object_rot_to_mat3(ob, rmat, true);
3122 mul_m3_m3m3(r_mat, rmat, smat);
3123}
3124
3125void BKE_object_to_mat4(const Object *ob, float r_mat[4][4])
3126{
3127 float tmat[3][3];
3128
3129 BKE_object_to_mat3(ob, tmat);
3130
3131 copy_m4_m3(r_mat, tmat);
3132
3133 add_v3_v3v3(r_mat[3], ob->loc, ob->dloc);
3134}
3135
3136void BKE_object_matrix_local_get(Object *ob, float r_mat[4][4])
3137{
3138 if (ob->parent) {
3139 float par_imat[4][4];
3140
3141 BKE_object_get_parent_matrix(ob, ob->parent, par_imat);
3142 invert_m4(par_imat);
3143 mul_m4_m4m4(r_mat, par_imat, ob->object_to_world().ptr());
3144 }
3145 else {
3146 copy_m4_m4(r_mat, ob->object_to_world().ptr());
3147 }
3148}
3149
3151{
3152 float delta_matrix[4][4];
3153 float scale_mat[3][3];
3154 float rotation_mat[3][3];
3155 size_to_mat3(scale_mat, obj.dscale);
3156 switch (obj.rotmode) {
3157 case ROT_MODE_AXISANGLE:
3158 axis_angle_to_mat3(rotation_mat, obj.drotAxis, obj.drotAngle);
3159 break;
3160 case ROT_MODE_QUAT: {
3161 float normalized_dquat[4];
3162 normalize_qt_qt(normalized_dquat, obj.dquat);
3163 quat_to_mat3(rotation_mat, normalized_dquat);
3164 break;
3165 }
3166 default:
3168 eulO_to_mat3(rotation_mat, obj.drot, obj.rotmode);
3169 break;
3170 }
3171
3172 float mat[3][3];
3173 mul_m3_m3m3(mat, rotation_mat, scale_mat);
3174 copy_m4_m3(delta_matrix, mat);
3175 copy_v3_v3(delta_matrix[3], obj.dloc);
3176 return float4x4(delta_matrix);
3177}
3178
3182static bool ob_parcurve(const Object *ob, Object *par, float r_mat[4][4])
3183{
3184 Curve *cu = id_cast<Curve *>(par->data);
3185 float vec[4], quat[4], radius, ctime;
3186
3187 /* NOTE: Curve cache is supposed to be evaluated here already, however there
3188 * are cases where we can not guarantee that. This includes, for example,
3189 * dependency cycles. We can't correct anything from here, since that would
3190 * cause threading conflicts.
3191 *
3192 * TODO(sergey): Some of the legit looking cases like #56619 need to be
3193 * looked into, and maybe curve cache (and other dependencies) are to be
3194 * evaluated prior to conversion. */
3195 if (par->runtime->curve_cache == nullptr) {
3196 return false;
3197 }
3198 if (par->runtime->curve_cache->anim_path_accum_length == nullptr) {
3199 return false;
3200 }
3201
3202 /* `ctime` is now a proper var setting of Curve which gets set by Animato like any other var
3203 * that's animated, but this will only work if it actually is animated.
3204 *
3205 * We divide the curve-time calculated in the previous step by the length of the path,
3206 * to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range. */
3207 if (cu->pathlen) {
3208 ctime = cu->ctime / cu->pathlen;
3209 }
3210 else {
3211 ctime = cu->ctime;
3212 }
3213
3214 if (cu->flag & CU_PATH_CLAMP) {
3215 CLAMP(ctime, 0.0f, 1.0f);
3216 }
3217
3218 unit_m4(r_mat);
3219
3220 /* vec: 4 items! */
3222 par, ctime, vec, nullptr, (cu->flag & CU_FOLLOW) ? quat : nullptr, &radius, nullptr))
3223 {
3224 if (cu->flag & CU_FOLLOW) {
3226 quat, std::clamp<short>(ob->trackflag, 0, 5), std::clamp<short>(ob->upflag, 0, 2));
3227 normalize_qt(quat);
3228 quat_to_mat4(r_mat, quat);
3229 }
3230 if (cu->flag & CU_PATH_RADIUS) {
3231 float tmat[4][4], rmat[4][4];
3232 scale_m4_fl(tmat, radius);
3233 mul_m4_m4m4(rmat, tmat, r_mat);
3234 copy_m4_m4(r_mat, rmat);
3235 }
3236 copy_v3_v3(r_mat[3], vec);
3237 }
3238
3239 return true;
3240}
3241
3242static void ob_parbone(const Object *ob, const Object *par, float r_mat[4][4])
3243{
3244 float3 vec;
3245
3246 if (par->type != OB_ARMATURE) {
3247 unit_m4(r_mat);
3248 return;
3249 }
3250
3251 /* Make sure the bone is still valid */
3252 const bPoseChannel *pchan = BKE_pose_channel_find_name(par->pose, ob->parsubstr);
3253 const Bone *pchan_bone = pchan ? pchan->bone_get(*par) : nullptr;
3254 if (!pchan || !pchan_bone) {
3255 CLOG_WARN(
3256 &LOG, "Parent Bone: '%s' for Object: '%s' doesn't exist", ob->parsubstr, ob->id.name + 2);
3257 unit_m4(r_mat);
3258 return;
3259 }
3260
3261 /* get bone transform */
3262 if (pchan_bone->flag & BONE_RELATIVE_PARENTING) {
3263 /* the new option uses the root - expected behavior, but differs from old... */
3264 /* XXX check on version patching? */
3265 copy_m4_m4(r_mat, pchan->chan_mat);
3266 }
3267 else {
3268 copy_m4_m4(r_mat, pchan->pose_mat);
3269 copy_v3_v3(vec, r_mat[1]);
3270 mul_v3_fl(vec, pchan_bone->length * ob->parent_bone_head_tail_factor);
3271 add_v3_v3(r_mat[3], vec);
3272 }
3273}
3274
3275static void give_parvert(const Object *par, int nr, float vec[3], const bool use_evaluated_indices)
3276{
3277 zero_v3(vec);
3278
3279 if (par->type == OB_MESH) {
3280 const BMesh *bm = BKE_editmesh_bmesh_get(par);
3281 const Mesh *mesh_eval = (bm) ? BKE_object_get_editmesh_eval_final(par) :
3283
3284 if (mesh_eval) {
3285 const Span<float3> positions = mesh_eval->vert_positions();
3286 int count = 0;
3287 int numVerts = mesh_eval->verts_num;
3288
3289 if (bm && mesh_eval->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH) {
3290 numVerts = bm->totvert;
3291 if (bm->elem_table_dirty & BM_VERT) {
3292#ifdef VPARENT_THREADING_HACK
3293 std::scoped_lock lock(vparent_lock);
3294 if (bm->elem_table_dirty & BM_VERT) {
3295 BM_mesh_elem_table_ensure(const_cast<BMesh *>(bm), BM_VERT);
3296 }
3297#else
3298 BLI_assert_msg(0, "Not safe for threading");
3299 BM_mesh_elem_table_ensure(const_cast<BMesh *>(bm), BM_VERT);
3300#endif
3301 }
3302 if (nr < numVerts) {
3303 if (mesh_eval && mesh_eval->runtime->edit_data &&
3304 !mesh_eval->runtime->edit_data->vert_positions.is_empty())
3305 {
3306 add_v3_v3(vec, mesh_eval->runtime->edit_data->vert_positions[nr]);
3307 }
3308 else {
3309 const BMVert *v = BM_vert_at_index(const_cast<BMesh *>(bm), nr);
3310 add_v3_v3(vec, v->co);
3311 }
3312 count++;
3313 }
3314 }
3315 else if (use_evaluated_indices && CustomData_has_layer(&mesh_eval->vert_data, CD_ORIGINDEX))
3316 {
3317 const int *index = static_cast<const int *>(
3319 /* Get the average of all verts with (original index == nr). */
3320 for (int i = 0; i < numVerts; i++) {
3321 if (index[i] == nr) {
3322 add_v3_v3(vec, positions[i]);
3323 count++;
3324 }
3325 }
3326 }
3327 else {
3328 if (nr < numVerts) {
3329 add_v3_v3(vec, positions[nr]);
3330 count++;
3331 }
3332 }
3333
3334 if (count == 0) {
3335 /* keep as 0, 0, 0 */
3336 }
3337 else if (count > 0) {
3338 mul_v3_fl(vec, 1.0f / count);
3339 }
3340 else {
3341 /* use first index if its out of range */
3342 if (mesh_eval->verts_num) {
3343 copy_v3_v3(vec, positions[0]);
3344 }
3345 }
3346 }
3347 else {
3348 CLOG_ERROR(&LOG,
3349 "Evaluated mesh is needed to solve parenting, "
3350 "object position can be wrong now");
3351 }
3352 }
3353 else if (ELEM(par->type, OB_CURVES_LEGACY, OB_SURF)) {
3354 ListBaseT<Nurb> *nurb;
3355
3356 /* It is possible that a cycle in the dependency graph was resolved in a way that caused this
3357 * object to be evaluated before its dependencies. In this case the curve cache may be null. */
3358 if (par->runtime->curve_cache && par->runtime->curve_cache->deformed_nurbs.first() != nullptr)
3359 {
3360 nurb = &par->runtime->curve_cache->deformed_nurbs;
3361 }
3362 else {
3363 Curve *cu = id_cast<Curve *>(par->data);
3364 nurb = BKE_curve_nurbs_get(cu);
3365 }
3366
3367 BKE_nurbList_index_get_co(nurb, nr, vec);
3368 }
3369 else if (par->type == OB_LATTICE) {
3370 Lattice *latt = id_cast<Lattice *>(par->data);
3371 DispList *dl = par->runtime->curve_cache ?
3373 nullptr;
3374 float (*co)[3] = dl ? reinterpret_cast<float (*)[3]>(dl->verts) : nullptr;
3375 int tot;
3376
3377 if (latt->editlatt) {
3378 latt = latt->editlatt->latt;
3379 }
3380
3381 tot = latt->pntsu * latt->pntsv * latt->pntsw;
3382
3383 /* ensure dl is correct size */
3384 BLI_assert(dl == nullptr || dl->nr == tot);
3385
3386 if (nr < tot) {
3387 if (co) {
3388 copy_v3_v3(vec, co[nr]);
3389 }
3390 else {
3391 copy_v3_v3(vec, latt->def[nr].vec);
3392 }
3393 }
3394 }
3395}
3396
3397static void ob_parvert3(const Object *ob, const Object *par, float r_mat[4][4])
3398{
3399 /* in local ob space */
3400 if (OB_TYPE_SUPPORT_PARVERT(par->type)) {
3401 float cmat[3][3], v1[3], v2[3], v3[3], q[4];
3402 const bool use_evaluated_indices = !(ob->transflag & OB_PARENT_USE_FINAL_INDICES);
3403
3404 give_parvert(par, ob->par1, v1, use_evaluated_indices);
3405 give_parvert(par, ob->par2, v2, use_evaluated_indices);
3406 give_parvert(par, ob->par3, v3, use_evaluated_indices);
3407
3408 tri_to_quat(q, v1, v2, v3);
3409 quat_to_mat3(cmat, q);
3410 copy_m4_m3(r_mat, cmat);
3411
3412 mid_v3_v3v3v3(r_mat[3], v1, v2, v3);
3413 }
3414 else {
3415 unit_m4(r_mat);
3416 }
3417}
3418
3419void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentmat[4][4])
3420{
3421 float tmat[4][4];
3422 float vec[3];
3423 const bool use_evaluated_indices = !(ob->transflag & OB_PARENT_USE_FINAL_INDICES);
3424 switch (ob->partype & PARTYPE) {
3425 case PAROBJECT: {
3426 bool ok = false;
3427 if (par->type == OB_CURVES_LEGACY) {
3428 if (((id_cast<Curve *>(par->data))->flag & CU_PATH) && ob_parcurve(ob, par, tmat)) {
3429 ok = true;
3430 }
3431 }
3432
3433 if (ok) {
3434 mul_m4_m4m4(r_parentmat, par->object_to_world().ptr(), tmat);
3435 }
3436 else {
3437 copy_m4_m4(r_parentmat, par->object_to_world().ptr());
3438 }
3439
3440 break;
3441 }
3442 case PARBONE:
3443 ob_parbone(ob, par, tmat);
3444 mul_m4_m4m4(r_parentmat, par->object_to_world().ptr(), tmat);
3445 break;
3446
3447 case PARVERT1:
3448 unit_m4(r_parentmat);
3449 give_parvert(par, ob->par1, vec, use_evaluated_indices);
3450 mul_v3_m4v3(r_parentmat[3], par->object_to_world().ptr(), vec);
3451 break;
3452 case PARVERT3:
3453 ob_parvert3(ob, par, tmat);
3454
3455 mul_m4_m4m4(r_parentmat, par->object_to_world().ptr(), tmat);
3456 break;
3457
3458 case PARSKEL:
3459 copy_m4_m4(r_parentmat, par->object_to_world().ptr());
3460 break;
3461 default:
3462 break;
3463 }
3464}
3465
3467
3468/* -------------------------------------------------------------------- */
3471
3476static void solve_parenting(const Object *ob,
3477 Object *par,
3478 const bool set_origin,
3479 float r_obmat[4][4],
3480 float r_originmat[3][3])
3481{
3482 float totmat[4][4];
3483 float tmat[4][4];
3484 float locmat[4][4];
3485
3486 BKE_object_to_mat4(ob, locmat);
3487
3488 BKE_object_get_parent_matrix(ob, par, totmat);
3489
3490 /* total */
3491 mul_m4_m4m4(tmat, totmat, ob->parentinv);
3492 mul_m4_m4m4(r_obmat, tmat, locmat);
3493
3494 if (r_originmat) {
3495 /* Usable `r_originmat`. */
3496 copy_m3_m4(r_originmat, tmat);
3497 }
3498
3499 /* origin, for help line */
3500 if (set_origin) {
3501 if ((ob->partype & PARTYPE) == PARSKEL) {
3502 copy_v3_v3(ob->runtime->parent_display_origin, par->object_to_world().location());
3503 }
3504 else {
3505 copy_v3_v3(ob->runtime->parent_display_origin, totmat[3]);
3506 }
3507 }
3508}
3509
3510static void object_where_is_calc_ex(Depsgraph *depsgraph,
3511 Scene *scene,
3512 Object *ob,
3513 float ctime,
3514 RigidBodyWorld *rbw,
3515 float r_originmat[3][3])
3516{
3517 if (ob->parent) {
3518 Object *par = ob->parent;
3519
3520 /* calculate parent matrix */
3521 solve_parenting(ob, par, true, ob->runtime->object_to_world.ptr(), r_originmat);
3522 }
3523 else {
3525 }
3526
3527 /* try to fall back to the scene rigid body world if none given */
3528 rbw = rbw ? rbw : scene->rigidbody_world;
3529 /* read values pushed into RBO from sim/cache... */
3530 BKE_rigidbody_sync_transforms(rbw, ob, ctime);
3531
3532 /* solve constraints */
3533 if (ob->constraints.first() && !(ob->transflag & OB_NO_CONSTRAINTS)) {
3534 bConstraintOb *cob;
3535 cob = BKE_constraints_make_evalob(depsgraph, scene, ob, nullptr, CONSTRAINT_OBTYPE_OBJECT);
3536 BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime);
3538 }
3539
3540 /* set negative scale flag in object */
3541 if (is_negative_m4(ob->object_to_world().ptr())) {
3542 ob->transflag |= OB_NEG_SCALE;
3543 }
3544 else {
3545 ob->transflag &= ~OB_NEG_SCALE;
3546 }
3547}
3548
3549void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
3550{
3551 /* Execute drivers and animation. */
3552 const bool flush_to_original = DEG_is_active(depsgraph);
3553 const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph,
3554 ctime);
3556 &ob->id, ob->adt, &anim_eval_context, ADT_RECALC_ALL, flush_to_original);
3557 object_where_is_calc_ex(depsgraph, scene, ob, ctime, nullptr, nullptr);
3558}
3559
3560void BKE_object_where_is_calc_mat4(const Object *ob, float r_obmat[4][4])
3561{
3562 if (ob->parent) {
3563 Object *par = ob->parent;
3564 solve_parenting(ob, par, false, r_obmat, nullptr);
3565 }
3566 else {
3567 BKE_object_to_mat4(ob, r_obmat);
3568 }
3569}
3570
3572 Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
3573{
3574 float ctime = DEG_get_ctime(depsgraph);
3575 object_where_is_calc_ex(depsgraph, scene, ob, ctime, rbw, r_originmat);
3576}
3577void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
3578{
3579 float ctime = DEG_get_ctime(depsgraph);
3580 object_where_is_calc_ex(depsgraph, scene, ob, ctime, nullptr, nullptr);
3581}
3582
3583float4x4 BKE_object_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob)
3584{
3585 bke::ObjectRuntime workob_runtime;
3586 Object workob;
3587 BKE_object_workob_clear(&workob);
3588 workob.runtime = &workob_runtime;
3589
3591 unit_m4(workob.parentinv);
3592 unit_m4(workob.constinv);
3593
3594 /* Since this is used while calculating parenting,
3595 * at this moment ob_eval->parent is still nullptr. */
3596 workob.parent = DEG_get_evaluated(depsgraph, ob->parent);
3597
3598 workob.trackflag = ob->trackflag;
3599 workob.upflag = ob->upflag;
3600
3601 workob.partype = ob->partype;
3602 workob.par1 = ob->par1;
3603 workob.par2 = ob->par2;
3604 workob.par3 = ob->par3;
3606
3607 /* The effects of constraints should NOT be included in the parent-inverse matrix. Constraints
3608 * are supposed to be applied after the object's local loc/rot/scale. If the (inverted) effect of
3609 * constraints would be included in the parent inverse matrix, these would be applied before the
3610 * object's local loc/rot/scale instead of after. For example, a "Copy Rotation" constraint would
3611 * rotate the object's local translation as well. See #82156. */
3612
3613 STRNCPY_UTF8(workob.parsubstr, ob->parsubstr);
3614
3615 BKE_object_where_is_calc(depsgraph, scene, &workob);
3616
3617 return workob.object_to_world();
3618}
3619
3621 const float mat[4][4],
3622 Object *parent,
3623 const float parentinv[4][4],
3624 const bool use_compat)
3625{
3626 /* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */
3627
3628 float rot[3][3];
3629
3630 if (parent != nullptr) {
3631 float rmat[4][4], diff_mat[4][4], imat[4][4], parent_mat[4][4];
3632
3633 BKE_object_get_parent_matrix(ob, parent, parent_mat);
3634
3635 mul_m4_m4m4(diff_mat, parent_mat, parentinv);
3636 invert_m4_m4(imat, diff_mat);
3637 mul_m4_m4m4(rmat, imat, mat); /* get the parent relative matrix */
3638
3639 /* same as below, use rmat rather than mat */
3640 mat4_to_loc_rot_size(ob->loc, rot, ob->scale, rmat);
3641 }
3642 else {
3643 mat4_to_loc_rot_size(ob->loc, rot, ob->scale, mat);
3644 }
3645
3646 BKE_object_mat3_to_rot(ob, rot, use_compat);
3647
3648 sub_v3_v3(ob->loc, ob->dloc);
3649
3650 if (ob->dscale[0] != 0.0f) {
3651 ob->scale[0] /= ob->dscale[0];
3652 }
3653 if (ob->dscale[1] != 0.0f) {
3654 ob->scale[1] /= ob->dscale[1];
3655 }
3656 if (ob->dscale[2] != 0.0f) {
3657 ob->scale[2] /= ob->dscale[2];
3658 }
3659
3660 /* BKE_object_mat3_to_rot handles delta rotations */
3661}
3662
3664 const float mat[4][4],
3665 const bool use_compat,
3666 const bool use_parent)
3667{
3668 BKE_object_apply_mat4_ex(ob, mat, use_parent ? ob->parent : nullptr, ob->parentinv, use_compat);
3669}
3670
3672{
3673 /*
3674 * Use parent's world transform as the child's origin.
3675 *
3676 * Let:
3677 * `local = identity`
3678 * `world = orthonormalized(parent)`
3679 *
3680 * Then:
3681 * `world = parent @ parentinv @ local`
3682 * `inv(parent) @ world = parentinv`
3683 * `parentinv = inv(parent) @ world`
3684 *
3685 * NOTE: If `ob->object_to_world().ptr()` has shear, then this `parentinv` is insufficient
3686 * because `parent @ parentinv => shearless result`
3687 *
3688 * Thus, local will have shear which cannot be decomposed into TRS:
3689 * `local = inv(parent @ parentinv) @ world`
3690 *
3691 * This is currently not supported for consistency in the handling of shear during the other
3692 * parenting ops: Parent (Keep Transform), Clear [Parent] and Keep Transform.
3693 */
3694 float par_locrot[4][4], par_imat[4][4];
3695 BKE_object_get_parent_matrix(ob, ob->parent, par_locrot);
3696 invert_m4_m4(par_imat, par_locrot);
3697
3698 orthogonalize_m4_stable(par_locrot, 0, true);
3699
3700 mul_m4_m4m4(ob->parentinv, par_imat, par_locrot);
3701
3702 /* Now, preserve `world` given the new `parentinv`.
3703 *
3704 * `world = parent @ parentinv @ local`
3705 * `inv(parent) @ world = parentinv @ local`
3706 * `inv(parentinv) @ inv(parent) @ world = local`
3707 *
3708 * `local = inv(parentinv) @ inv(parent) @ world`
3709 */
3710 float ob_local[4][4];
3711 copy_m4_m4(ob_local, ob->parentinv);
3712 invert_m4(ob_local);
3713 mul_m4_m4_post(ob_local, par_imat);
3714 mul_m4_m4_post(ob_local, ob->object_to_world().ptr());
3715
3716 /* Send use_compat=False so the rotation is predictable. */
3717 BKE_object_apply_mat4(ob, ob_local, false, false);
3718}
3719
3721
3722/* -------------------------------------------------------------------- */
3725
3726std::optional<Bounds<float3>> BKE_object_boundbox_get(const Object *ob)
3727{
3728 switch (ob->type) {
3729 case OB_MESH:
3730 return id_cast<const Mesh *>(ob->data)->bounds_min_max();
3731 case OB_CURVES_LEGACY:
3732 case OB_SURF:
3733 case OB_FONT:
3734 return BKE_curve_minmax(id_cast<const Curve *>(ob->data), true);
3735 case OB_MBALL:
3737 case OB_LATTICE:
3738 return BKE_lattice_minmax(id_cast<const Lattice *>(ob->data));
3739 case OB_ARMATURE:
3740 return BKE_armature_min_max(ob);
3741 case OB_CURVES:
3742 return id_cast<const Curves *>(ob->data)->geometry.wrap().bounds_min_max();
3743 case OB_POINTCLOUD:
3744 return id_cast<const PointCloud *>(ob->data)->bounds_min_max();
3745 case OB_VOLUME:
3746 return BKE_volume_min_max(id_cast<const Volume *>(ob->data));
3747 case OB_GREASE_PENCIL:
3748 return id_cast<const GreasePencil *>(ob->data)->bounds_min_max_eval();
3749 case OB_LIGHTPROBE:
3750 /* Set to enable additional functionality (e.g. the Scale Cage tool in object mode). */
3751 return blender::Bounds(float3(-1.0f), float3(1.0f));
3752 default:
3753 break;
3754 }
3755 return std::nullopt;
3756}
3757
3758std::optional<Bounds<float3>> BKE_object_boundbox_eval_cached_get(const Object *ob)
3759{
3760 if (ob->runtime->bounds_eval) {
3761 return ob->runtime->bounds_eval;
3762 }
3763 return BKE_object_boundbox_get(ob);
3764}
3765
3766std::optional<Bounds<float3>> BKE_object_evaluated_geometry_bounds(const Object *ob)
3767{
3769 const bool use_radius = ob->type != OB_CURVES_LEGACY;
3770 const bool use_subdiv = true;
3771 return geometry->compute_boundbox_without_instances(use_radius, use_subdiv);
3772 }
3773 if (const CurveCache *curve_cache = ob->runtime->curve_cache) {
3774 float3 min(std::numeric_limits<float>::max());
3775 float3 max(std::numeric_limits<float>::lowest());
3776 BKE_displist_minmax(&curve_cache->disp, min, max);
3777 return Bounds<float3>{min, max};
3778 }
3779 return std::nullopt;
3780}
3781
3783
3784/* -------------------------------------------------------------------- */
3789
3790static float3 boundbox_to_dimensions(const Object *ob, const std::optional<Bounds<float3>> bounds)
3791{
3792 if (!bounds) {
3793 return float3(0);
3794 }
3795 const float3 scale = math::to_scale(ob->object_to_world());
3796 return scale * (bounds->max - bounds->min);
3797}
3798
3799void BKE_object_dimensions_get(const Object *ob, float r_vec[3])
3800{
3802}
3803
3808
3810 const float value[3],
3811 int axis_mask,
3812 const float ob_scale_orig[3],
3813 const float ob_obmat_orig[4][4])
3814{
3815 if (const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_eval_cached_get(ob)) {
3816 float3 len = bounds->max - bounds->min;
3817
3818 for (int i = 0; i < 3; i++) {
3819 if (((1 << i) & axis_mask) == 0) {
3820
3821 if (ob_scale_orig != nullptr) {
3822 const float scale_delta = len_v3(ob_obmat_orig[i]) / ob_scale_orig[i];
3823 if (isfinite(scale_delta)) {
3824 len[i] *= scale_delta;
3825 }
3826 }
3827
3828 const float scale = copysignf(value[i] / len[i], ob->scale[i]);
3829 if (isfinite(scale)) {
3830 ob->scale[i] = scale;
3831 }
3832 }
3833 }
3834 }
3835}
3836
3837void BKE_object_dimensions_set(Object *ob, const float value[3], int axis_mask)
3838{
3839 BKE_object_dimensions_set_ex(ob, value, axis_mask, nullptr, nullptr);
3840}
3841
3842void BKE_object_minmax(Object *ob, float3 &r_min, float3 &r_max)
3843{
3844 const float4x4 &object_to_world = ob->object_to_world();
3845 if (const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(ob)) {
3846 math::min_max(math::transform_point(object_to_world, bounds->min), r_min, r_max);
3847 math::min_max(math::transform_point(object_to_world, bounds->max), r_min, r_max);
3848 return;
3849 }
3850
3851 float3 size = ob->scale;
3852 if (ob->type == OB_EMPTY) {
3853 size *= ob->empty_drawsize;
3854 }
3855
3856 math::min_max(object_to_world.location() + size, r_min, r_max);
3857 math::min_max(object_to_world.location() - size, r_min, r_max);
3858}
3859
3860void BKE_object_empty_draw_type_set(Object *ob, const int value)
3861{
3863
3864 if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
3865 if (!ob->iuser) {
3866 ob->iuser = MEM_new<ImageUser>("image user");
3867 ob->iuser->flag |= IMA_ANIM_ALWAYS;
3868 ob->iuser->frames = 100;
3869 ob->iuser->sfra = 1;
3870 }
3871 }
3872 else {
3873 MEM_SAFE_DELETE(ob->iuser);
3874 }
3875}
3876
3878{
3879 const char visibility_flag = ob->empty_image_visibility_flag;
3880 if (rv3d->is_persp) {
3881 return (visibility_flag & OB_EMPTY_IMAGE_HIDE_PERSPECTIVE) == 0;
3882 }
3883
3884 return (visibility_flag & OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC) == 0;
3885}
3886
3888{
3889 /* Caller is expected to check this. */
3891
3892 const char visibility_flag = ob->empty_image_visibility_flag;
3893
3894 if ((visibility_flag & (OB_EMPTY_IMAGE_HIDE_BACK | OB_EMPTY_IMAGE_HIDE_FRONT)) != 0) {
3895 float eps, dot;
3896 if (rv3d->is_persp) {
3897 /* NOTE: we could normalize the 'view_dir' then use 'eps'
3898 * however the issue with empty objects being visible when viewed from the side
3899 * is only noticeable in orthographic views. */
3900 float3 view_dir;
3901 sub_v3_v3v3(view_dir, rv3d->viewinv[3], ob->object_to_world().location());
3902 dot = dot_v3v3(ob->object_to_world().ptr()[2], view_dir);
3903 eps = 0.0f;
3904 }
3905 else {
3906 dot = dot_v3v3(ob->object_to_world().ptr()[2], rv3d->viewinv[2]);
3907 eps = 1e-5f;
3908 }
3909 if (visibility_flag & OB_EMPTY_IMAGE_HIDE_BACK) {
3910 if (dot < eps) {
3911 return false;
3912 }
3913 }
3914 if (visibility_flag & OB_EMPTY_IMAGE_HIDE_FRONT) {
3915 if (dot > -eps) {
3916 return false;
3917 }
3918 }
3919 }
3920
3921 if (visibility_flag & OB_EMPTY_IMAGE_HIDE_NON_AXIS_ALIGNED) {
3922 float3 proj, ob_z_axis;
3923 normalize_v3_v3(ob_z_axis, ob->object_to_world().ptr()[2]);
3924 project_plane_v3_v3v3(proj, ob_z_axis, rv3d->viewinv[2]);
3925 const float proj_length_sq = len_squared_v3(proj);
3926 if (proj_length_sq > 1e-5f) {
3927 return false;
3928 }
3929 }
3930
3931 return true;
3932}
3933
3934bool BKE_object_minmax_empty_drawtype(const Object *ob, float r_min[3], float r_max[3])
3935{
3936 BLI_assert(ob->type == OB_EMPTY);
3937 float3 min(0), max(0);
3938
3939 bool ok = false;
3940 const float radius = ob->empty_drawsize;
3941
3942 switch (ob->empty_drawtype) {
3943 case OB_ARROWS: {
3944 max = float3(radius);
3945 ok = true;
3946 break;
3947 }
3948 case OB_PLAINAXES:
3949 case OB_CUBE:
3950 case OB_EMPTY_SPHERE: {
3951 min = float3(-radius);
3952 max = float3(radius);
3953 ok = true;
3954 break;
3955 }
3956 case OB_CIRCLE: {
3957 max[0] = max[2] = radius;
3958 min[0] = min[2] = -radius;
3959 ok = true;
3960 break;
3961 }
3962 case OB_SINGLE_ARROW: {
3963 max[2] = radius;
3964 ok = true;
3965 break;
3966 }
3967 case OB_EMPTY_CONE: {
3968 min = float3(-radius, 0.0f, -radius);
3969 max = float3(radius, radius * 2.0f, radius);
3970 ok = true;
3971 break;
3972 }
3973 case OB_EMPTY_IMAGE: {
3974 const float *ofs = ob->ima_ofs;
3975 /* NOTE: this is the best approximation that can be calculated without loading the image.
3976 */
3977 min[0] = ofs[0] * radius;
3978 min[1] = ofs[1] * radius;
3979 max[0] = radius + (ofs[0] * radius);
3980 max[1] = radius + (ofs[1] * radius);
3981 /* Since the image aspect can shrink the bounds towards the object origin,
3982 * adjust the min/max to account for that. */
3983 for (int i = 0; i < 2; i++) {
3984 CLAMP_MAX(min[i], 0.0f);
3985 CLAMP_MIN(max[i], 0.0f);
3986 }
3987 ok = true;
3988 break;
3989 }
3990 }
3991
3992 if (ok) {
3993 copy_v3_v3(r_min, min);
3994 copy_v3_v3(r_max, max);
3995 }
3996 return ok;
3997}
3998
4000 Depsgraph *depsgraph, Object *ob, float3 &r_min, float3 &r_max, const bool use_hidden)
4001{
4002 bool ok = false;
4003 if ((ob->transflag & OB_DUPLI) == 0 && ob->runtime->geometry_set_eval == nullptr) {
4004 return ok;
4005 }
4006
4007 DupliList duplilist;
4008 object_duplilist(depsgraph, ob, nullptr, duplilist);
4009 for (DupliObject &dob : duplilist) {
4010 if (((use_hidden == false) && (dob.no_draw != 0)) || dob.ob_data == nullptr) {
4011 /* pass */
4012 }
4013 else {
4014 Object temp_ob = dna::shallow_copy(*dob.ob);
4015 bke::ObjectRuntime runtime = *dob.ob->runtime;
4016 temp_ob.runtime = &runtime;
4017
4018 /* Do not modify the original bounding-box. */
4019 temp_ob.runtime->bounds_eval.reset();
4020 BKE_object_replace_data_on_shallow_copy(&temp_ob, dob.ob_data);
4021 if (const std::optional<Bounds<float3>> bounds = BKE_object_boundbox_get(&temp_ob)) {
4022 const Bounds tranformed_bounds = bounds::transform_bounds(float4x4(dob.mat), *bounds);
4023 r_min = math::min(tranformed_bounds.min, r_min);
4024 r_max = math::max(tranformed_bounds.max, r_max);
4025 ok = true;
4026 }
4027 }
4028 }
4029
4030 return ok;
4031}
4032
4034 const float obmat[4][4],
4035 void (*func_cb)(const float[3], void *),
4036 void *user_data)
4037{
4038 /* TODO: volume object support. */
4039 const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob);
4040 float3 co;
4041
4042 if (mesh_eval != nullptr) {
4043 const Span<float3> positions = BKE_mesh_wrapper_vert_coords(mesh_eval);
4044 for (const int i : positions.index_range()) {
4045 mul_v3_m4v3(co, obmat, positions[i]);
4046 func_cb(co, user_data);
4047 }
4048 }
4049 else if (ob->type == OB_GREASE_PENCIL) {
4050 using namespace blender::bke::greasepencil;
4051 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob->data);
4052 for (const Layer *layer : grease_pencil.layers()) {
4053 if (!layer->is_visible()) {
4054 continue;
4055 }
4056 const float4x4 layer_to_world = layer->to_world_space(*ob);
4057 if (const Drawing *drawing = grease_pencil.get_drawing_at(*layer,
4058 grease_pencil.runtime->eval_frame))
4059 {
4060 const bke::CurvesGeometry &curves = drawing->strokes();
4061 const Span<float3> positions = curves.evaluated_positions();
4062 threading::parallel_for(positions.index_range(), 4096, [&](const IndexRange range) {
4063 for (const int i : range) {
4064 func_cb(math::transform_point(layer_to_world, positions[i]), user_data);
4065 }
4066 });
4067 }
4068 }
4069 }
4070 else if (ob->runtime->curve_cache && ob->runtime->curve_cache->disp.first()) {
4071 for (DispList &dl : ob->runtime->curve_cache->disp) {
4072 const float *v3 = dl.verts;
4073 int totvert = dl.nr;
4074 int i;
4075
4076 for (i = 0; i < totvert; i++, v3 += 3) {
4077 mul_v3_m4v3(co, obmat, v3);
4078 func_cb(co, user_data);
4079 }
4080 }
4081 }
4082 else if (ob->type == OB_POINTCLOUD) {
4083 PointCloud &pointcloud = *id_cast<PointCloud *>(ob->data);
4084 const Span<float3> positions = pointcloud.positions();
4085 threading::parallel_for(positions.index_range(), 4096, [&](const IndexRange range) {
4086 for (const int i : range) {
4087 func_cb(math::transform_point(float4x4(obmat), positions[i]), user_data);
4088 }
4089 });
4090 }
4091 else if (ob->type == OB_CURVES) {
4092 Curves &curves_id = *id_cast<Curves *>(ob->data);
4093 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
4094 const Span<float3> positions = curves.evaluated_positions();
4095 threading::parallel_for(positions.index_range(), 4096, [&](const IndexRange range) {
4096 for (const int i : range) {
4097 func_cb(math::transform_point(float4x4(obmat), positions[i]), user_data);
4098 }
4099 });
4100 }
4101}
4102
4103void BKE_scene_foreach_display_point(Depsgraph *depsgraph,
4104 void (*func_cb)(const float[3], void *),
4105 void *user_data)
4106{
4107 DEGObjectIterSettings deg_iter_settings{};
4108 deg_iter_settings.depsgraph = depsgraph;
4111 DEG_OBJECT_ITER_BEGIN (&deg_iter_settings, ob) {
4112 if ((ob->base_flag & BASE_SELECTED) != 0) {
4113 BKE_object_foreach_display_point(ob, ob->object_to_world().ptr(), func_cb, user_data);
4114 }
4115 }
4117}
4118
4120
4121/* -------------------------------------------------------------------- */
4124
4129 float loc[3], dloc[3];
4130 float scale[3], dscale[3];
4131 float rot[3], drot[3];
4132 float quat[4], dquat[4];
4133 float rotAxis[3], drotAxis[3];
4135 float obmat[4][4];
4136 float parentinv[4][4];
4137 float constinv[4][4];
4138 float imat[4][4];
4139};
4140
4142{
4143 ObTfmBack *obtfm = MEM_new_uninitialized<ObTfmBack>("ObTfmBack");
4144 copy_v3_v3(obtfm->loc, ob->loc);
4145 copy_v3_v3(obtfm->dloc, ob->dloc);
4146 copy_v3_v3(obtfm->scale, ob->scale);
4147 copy_v3_v3(obtfm->dscale, ob->dscale);
4148 copy_v3_v3(obtfm->rot, ob->rot);
4149 copy_v3_v3(obtfm->drot, ob->drot);
4150 copy_qt_qt(obtfm->quat, ob->quat);
4151 copy_qt_qt(obtfm->dquat, ob->dquat);
4152 copy_v3_v3(obtfm->rotAxis, ob->rotAxis);
4153 copy_v3_v3(obtfm->drotAxis, ob->drotAxis);
4154 obtfm->rotAngle = ob->rotAngle;
4155 obtfm->drotAngle = ob->drotAngle;
4156 copy_m4_m4(obtfm->obmat, ob->object_to_world().ptr());
4157 copy_m4_m4(obtfm->parentinv, ob->parentinv);
4158 copy_m4_m4(obtfm->constinv, ob->constinv);
4159 copy_m4_m4(obtfm->imat, ob->world_to_object().ptr());
4160
4161 return static_cast<void *>(obtfm);
4162}
4163
4164void BKE_object_tfm_restore(Object *ob, void *obtfm_pt)
4165{
4166 ObTfmBack *obtfm = static_cast<ObTfmBack *>(obtfm_pt);
4167 copy_v3_v3(ob->loc, obtfm->loc);
4168 copy_v3_v3(ob->dloc, obtfm->dloc);
4169 copy_v3_v3(ob->scale, obtfm->scale);
4170 copy_v3_v3(ob->dscale, obtfm->dscale);
4171 copy_v3_v3(ob->rot, obtfm->rot);
4172 copy_v3_v3(ob->drot, obtfm->drot);
4173 copy_qt_qt(ob->quat, obtfm->quat);
4174 copy_qt_qt(ob->dquat, obtfm->dquat);
4175 copy_v3_v3(ob->rotAxis, obtfm->rotAxis);
4176 copy_v3_v3(ob->drotAxis, obtfm->drotAxis);
4177 ob->rotAngle = obtfm->rotAngle;
4178 ob->drotAngle = obtfm->drotAngle;
4179 copy_m4_m4(ob->runtime->object_to_world.ptr(), obtfm->obmat);
4180 copy_m4_m4(ob->parentinv, obtfm->parentinv);
4181 copy_m4_m4(ob->constinv, obtfm->constinv);
4182 copy_m4_m4(ob->runtime->world_to_object.ptr(), obtfm->imat);
4183}
4184
4185void BKE_object_tfm_free(void *obtfm_pt)
4186{
4187 ObTfmBack *obtfm = static_cast<ObTfmBack *>(obtfm_pt);
4188 MEM_delete(obtfm);
4189}
4190
4192
4193/* -------------------------------------------------------------------- */
4196
4197void BKE_object_protected_location_set(Object *ob, const float location[3])
4198{
4199 if ((ob->protectflag & OB_LOCK_LOCX) == 0) {
4200 ob->loc[0] = location[0];
4201 }
4202 if ((ob->protectflag & OB_LOCK_LOCY) == 0) {
4203 ob->loc[1] = location[1];
4204 }
4205 if ((ob->protectflag & OB_LOCK_LOCZ) == 0) {
4206 ob->loc[2] = location[2];
4207 }
4208}
4209
4211{
4212 if ((ob->protectflag & OB_LOCK_SCALEX) == 0) {
4213 ob->scale[0] = scale[0];
4214 }
4215 if ((ob->protectflag & OB_LOCK_SCALEY) == 0) {
4216 ob->scale[1] = scale[1];
4217 }
4218 if ((ob->protectflag & OB_LOCK_SCALEZ) == 0) {
4219 ob->scale[2] = scale[2];
4220 }
4221}
4222
4224{
4225 if ((ob->protectflag & OB_LOCK_ROTW) == 0) {
4226 ob->quat[0] = quat[0];
4227 }
4228 if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
4229 ob->quat[1] = quat[1];
4230 }
4231 if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
4232 ob->quat[2] = quat[2];
4233 }
4234 if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
4235 ob->quat[3] = quat[3];
4236 }
4237}
4238
4240{
4241 if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
4242 ob->rot[0] = euler[0];
4243 }
4244 if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
4245 ob->rot[1] = euler[1];
4246 }
4247 if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
4248 ob->rot[2] = euler[2];
4249 }
4250}
4251
4253 const float axis[3],
4254 const float angle)
4255{
4256 if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
4257 ob->rotAxis[0] = axis[0];
4258 }
4259 if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
4260 ob->rotAxis[1] = axis[1];
4261 }
4262 if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
4263 ob->rotAxis[2] = axis[2];
4264 }
4265 if ((ob->protectflag & OB_LOCK_ROTW) == 0) {
4266 ob->rotAngle = angle;
4267 }
4268}
4269
4271
4272/* -------------------------------------------------------------------- */
4275
4276void BKE_object_handle_update_ex(Depsgraph *depsgraph,
4277 Scene *scene,
4278 Object *ob,
4279 RigidBodyWorld *rbw)
4280{
4281 const ID *object_data = ob->data;
4282 const bool recalc_object = (ob->id.recalc & ID_RECALC_ALL) != 0;
4283 const bool recalc_data = (object_data != nullptr) ?
4284 ((object_data->recalc & ID_RECALC_ALL) != 0) :
4285 false;
4286 if (!recalc_object && !recalc_data) {
4287 return;
4288 }
4289 /* Speed optimization for animation lookups. */
4290 if (ob->pose != nullptr) {
4294 }
4295 }
4296 if (recalc_data) {
4297 if (ob->type == OB_ARMATURE) {
4298 /* this happens for reading old files and to match library armatures
4299 * with poses we do it ahead of BKE_object_where_is_calc to ensure animation
4300 * is evaluated on the rebuilt pose, otherwise we get incorrect poses
4301 * on file load */
4302 if (ob->pose == nullptr || (ob->pose->flag & POSE_RECALC)) {
4303 /* No need to pass `bmain` here, we assume we do not need to rebuild DEG from here. */
4304 BKE_pose_rebuild(nullptr, ob, id_cast<bArmature *>(ob->data), true);
4305 }
4306 }
4307 }
4308 /* XXX new animsys warning: depsgraph tag ID_RECALC_GEOMETRY should not skip drivers,
4309 * which is only in BKE_object_where_is_calc now */
4310 /* XXX: should this case be ID_RECALC_TRANSFORM instead? */
4311 if (recalc_object || recalc_data) {
4312 if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
4313 printf("recalcob %s\n", ob->id.name + 2);
4314 }
4315 BKE_object_where_is_calc_ex(depsgraph, scene, rbw, ob, nullptr);
4316 }
4317
4318 if (recalc_data) {
4319 BKE_object_handle_data_update(depsgraph, scene, ob);
4320 }
4321}
4322
4323void BKE_object_handle_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
4324{
4325 BKE_object_handle_update_ex(depsgraph, scene, ob, nullptr);
4326}
4327
4329{
4330 eObjectMode allowed_modes = OB_MODE_ALL_SCULPT;
4331 if (USER_EXPERIMENTAL_TEST(&U, use_3d_texture_paint)) {
4332 allowed_modes |= OB_MODE_TEXTURE_PAINT;
4333 }
4334 return mode & allowed_modes;
4335}
4336
4338{
4340 ob->runtime->sculpt_session = MEM_new<SculptSession>(__func__);
4342}
4343
4345 char **r_texspace_flag,
4346 float **r_texspace_location,
4347 float **r_texspace_size)
4348{
4349 if (ob->data == nullptr) {
4350 return false;
4351 }
4352
4353 switch (ob->data->id_type()) {
4354 case ID_ME: {
4356 id_cast<Mesh *>(ob->data), r_texspace_flag, r_texspace_location, r_texspace_size);
4357 break;
4358 }
4359 case ID_CU_LEGACY: {
4360 Curve *cu = id_cast<Curve *>(ob->data);
4362 if (r_texspace_flag) {
4363 *r_texspace_flag = &cu->texspace_flag;
4364 }
4365 if (r_texspace_location) {
4366 *r_texspace_location = cu->texspace_location;
4367 }
4368 if (r_texspace_size) {
4369 *r_texspace_size = cu->texspace_size;
4370 }
4371 break;
4372 }
4373 case ID_MB: {
4374 MetaBall *mb = id_cast<MetaBall *>(ob->data);
4375 if (r_texspace_flag) {
4376 *r_texspace_flag = &mb->texspace_flag;
4377 }
4378 if (r_texspace_location) {
4379 *r_texspace_location = mb->texspace_location;
4380 }
4381 if (r_texspace_size) {
4382 *r_texspace_size = mb->texspace_size;
4383 }
4384 break;
4385 }
4386 default:
4387 return false;
4388 }
4389 return true;
4390}
4391
4393{
4394 /* First attempt to retrieve the evaluated mesh from the evaluated geometry set. Most
4395 * object types either store it there or add a reference to it if it's owned elsewhere. */
4396 bke::GeometrySet *geometry_set_eval = object->runtime->geometry_set_eval;
4397 if (geometry_set_eval) {
4398 /* Some areas expect to be able to modify the evaluated mesh in limited ways. Theoretically
4399 * this should be avoided, or at least protected with a lock, so a const mesh could be
4400 * returned from this function. We use a const_cast instead of #get_mesh_for_write, because
4401 * that might result in a copy of the mesh when it is shared. */
4402 Mesh *mesh = const_cast<Mesh *>(geometry_set_eval->get_mesh());
4403 if (mesh) {
4404 return mesh;
4405 }
4406 }
4407
4408 /* Some object types do not yet add the evaluated mesh to an evaluated geometry set, if they do
4409 * not support evaluating to multiple data types. Eventually this should be removed, when all
4410 * object types use #geometry_set_eval. */
4411 ID *data_eval = object->runtime->data_eval;
4412 if (data_eval && data_eval->id_type() == ID_ME) {
4413 return reinterpret_cast<Mesh *>(data_eval);
4414 }
4415
4416 return nullptr;
4417}
4418
4420{
4421 if (!DEG_object_geometry_is_evaluated(*object)) {
4422 return nullptr;
4423 }
4425}
4426
4428{
4430 if (!mesh) {
4431 return nullptr;
4432 }
4434}
4435
4437{
4438 if (!DEG_object_geometry_is_evaluated(*object_eval)) {
4439 return nullptr;
4440 }
4441 return BKE_object_get_evaluated_mesh_unchecked(object_eval);
4442}
4443
4445{
4446 BLI_assert(object->type == OB_MESH);
4447 if (const ID *data_orig = object->runtime->data_orig) {
4449 BLI_assert(object->id.orig_id != nullptr);
4450 BLI_assert(data_orig->orig_id == ((const Object *)object->id.orig_id)->data);
4451 BLI_assert((data_orig->tag & ID_TAG_COPIED_ON_EVAL) != 0);
4452 if (data_orig->id_type() != ID_ME) {
4453 return nullptr;
4454 }
4455 return reinterpret_cast<const Mesh *>(data_orig);
4456 }
4457 BLI_assert((object->id.tag & ID_TAG_COPIED_ON_EVAL) == 0);
4458 return id_cast<const Mesh *>(object->data);
4459}
4460
4462{
4463 Mesh *result = nullptr;
4464 if (object->id.orig_id == nullptr) {
4465 BLI_assert((object->id.tag & ID_TAG_COPIED_ON_EVAL) == 0);
4466 result = id_cast<Mesh *>(object->data);
4467 }
4468 else {
4469 BLI_assert((object->id.tag & ID_TAG_COPIED_ON_EVAL) != 0);
4470 result = id_cast<Mesh *>((id_cast<Object *>(object->id.orig_id))->data);
4471 }
4472 BLI_assert(result != nullptr);
4473 BLI_assert((result->id.tag & (ID_TAG_COPIED_ON_EVAL)) == 0);
4474 return result;
4475}
4476
4478{
4479 BLI_assert(!DEG_is_original(object));
4480 BLI_assert(object->type == OB_MESH);
4481
4482 const Mesh *mesh = id_cast<const Mesh *>(object->data);
4483 if (mesh->runtime->edit_mesh == nullptr) {
4484 /* Happens when requesting material of evaluated 3d font object: the evaluated object get
4485 * converted to mesh, and it does not have edit mesh. */
4486 return nullptr;
4487 }
4488
4489 return reinterpret_cast<const Mesh *>(object->runtime->data_eval);
4490}
4491
4493{
4494 using namespace blender::bke;
4496 BLI_assert(object->type == OB_MESH);
4497
4498 const GeometrySet *geometry_set = object->runtime->geometry_set_eval;
4499 if (!geometry_set) {
4500 return nullptr;
4501 }
4502 const auto *component = geometry_set->get_component<GeometryComponentEditData>();
4503 if (!component) {
4504 return nullptr;
4505 }
4506 const MeshEditHints *edit_hints = component->mesh_edit_hints_.get();
4507 if (!edit_hints) {
4508 return nullptr;
4509 }
4510 BLI_assert(!edit_hints->mesh_cage ||
4512 const auto *mesh_component = static_cast<const MeshComponent *>(edit_hints->mesh_cage.get());
4513 if (!mesh_component) {
4514 return nullptr;
4515 }
4516 return mesh_component->get();
4517}
4518
4520{
4521 using namespace blender::bke;
4523 BLI_assert(object->type == OB_MESH);
4524 const GeometrySet *geometry_set = object->runtime->geometry_set_eval;
4525 if (!geometry_set) {
4526 return nullptr;
4527 }
4528 const auto *component = geometry_set->get_component<GeometryComponentEditData>();
4529 if (!component) {
4530 return nullptr;
4531 }
4532 const MeshEditHints *edit_hints = component->mesh_edit_hints_.get();
4533 if (!edit_hints) {
4534 return nullptr;
4535 }
4536 BLI_assert(!edit_hints->mesh_deform ||
4538 const auto *mesh_component = static_cast<const MeshComponent *>(edit_hints->mesh_deform.get());
4539 if (!mesh_component) {
4540 return nullptr;
4541 }
4542 return mesh_component->get();
4543}
4544
4546{
4547 ID *data = object->data;
4548 if (data == nullptr || data->id_type() != ID_LT) {
4549 return nullptr;
4550 }
4551
4552 Lattice *lt = id_cast<Lattice *>(data);
4553 if (lt->editlatt) {
4554 return lt->editlatt->latt;
4555 }
4556
4557 return lt;
4558}
4559
4561{
4562 ID *data_eval = object->runtime->data_eval;
4563
4564 if (data_eval == nullptr || data_eval->id_type() != ID_LT) {
4565 return nullptr;
4566 }
4567
4568 Lattice *lt_eval = id_cast<Lattice *>(data_eval);
4569 if (lt_eval->editlatt) {
4570 return lt_eval->editlatt->latt;
4571 }
4572
4573 return lt_eval;
4574}
4575
4577
4578/* -------------------------------------------------------------------- */
4581
4582static int pc_cmp(const void *a, const void *b)
4583{
4584 const LinkData *ad = static_cast<const LinkData *>(a), *bd = static_cast<const LinkData *>(b);
4585 if (POINTER_AS_INT(ad->data) > POINTER_AS_INT(bd->data)) {
4586 return 1;
4587 }
4588
4589 return 0;
4590}
4591
4593{
4594 /* TODO: Review the usages of this function, currently with copy-on-eval it will be called for
4595 * orig object and then again for evaluated copies of it, think this is bad since there is no
4596 * guarantee that we get the same stack index in both cases? Order is important since this index
4597 * is used for filenames on disk. */
4598
4599 LinkData *link = nullptr;
4600 int i = 0;
4601
4603
4604 for (link = ob->pc_ids.first(), i = 0; link; link = link->next, i++) {
4605 int index = POINTER_AS_INT(link->data);
4606
4607 if (i < index) {
4608 break;
4609 }
4610 }
4611
4612 link = MEM_new_zeroed<LinkData>("PCLink");
4613 link->data = POINTER_FROM_INT(i);
4614 BLI_addtail(&ob->pc_ids, link);
4615
4616 return i;
4617}
4618
4619static int pc_findindex(ListBaseT<LinkData> *listbase, int index)
4620{
4621 int number = 0;
4622
4623 if (listbase == nullptr) {
4624 return -1;
4625 }
4626
4627 LinkData *link = listbase->first();
4628 while (link) {
4629 if (POINTER_AS_INT(link->data) == index) {
4630 return number;
4631 }
4632
4633 number++;
4634 link = link->next;
4635 }
4636
4637 return -1;
4638}
4639
4641{
4642 int list_index = pc_findindex(&ob->pc_ids, index);
4643 LinkData *link = static_cast<LinkData *>(BLI_findlink(&ob->pc_ids, list_index));
4644 BLI_freelinkN(&ob->pc_ids, link);
4645}
4646
4648
4649/* -------------------------------------------------------------------- */
4652
4654static KeyBlock *insert_meshkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
4655{
4656 Mesh *mesh = id_cast<Mesh *>(ob->data);
4657 Key *key = mesh->key;
4658 KeyBlock *kb;
4659 int newkey = 0;
4660
4661 if (key == nullptr) {
4662 key = mesh->key = BKE_key_add(bmain, id_cast<ID *>(mesh));
4663 key->type = KEY_RELATIVE;
4664 newkey = 1;
4665 }
4666
4667 if (newkey || from_mix == false) {
4668 /* create from mesh */
4669 kb = BKE_keyblock_add_ctime(key, name, false);
4671 }
4672 else {
4673 /* copy from current values */
4674 int totelem;
4675 float *data = BKE_key_evaluate_object(ob, &totelem);
4676
4677 /* create new block with prepared data */
4678 kb = BKE_keyblock_add_ctime(key, name, false);
4679 kb->data = data;
4680 kb->totelem = totelem;
4681 }
4682
4683 return kb;
4684}
4685
4686static KeyBlock *insert_lattkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
4687{
4688 Lattice *lt = id_cast<Lattice *>(ob->data);
4689 Key *key = lt->key;
4690 KeyBlock *kb;
4691 int newkey = 0;
4692
4693 if (key == nullptr) {
4694 key = lt->key = BKE_key_add(bmain, id_cast<ID *>(lt));
4695 key->type = KEY_RELATIVE;
4696 newkey = 1;
4697 }
4698
4699 if (newkey || from_mix == false) {
4700 kb = BKE_keyblock_add_ctime(key, name, false);
4701 if (!newkey) {
4702 KeyBlock *basekb = key->block.first();
4703 kb->data = MEM_dupalloc_void(basekb->data);
4704 kb->totelem = basekb->totelem;
4705 }
4706 else {
4708 }
4709 }
4710 else {
4711 /* copy from current values */
4712 int totelem;
4713 float *data = BKE_key_evaluate_object(ob, &totelem);
4714
4715 /* create new block with prepared data */
4716 kb = BKE_keyblock_add_ctime(key, name, false);
4717 kb->totelem = totelem;
4718 kb->data = data;
4719 }
4720
4721 return kb;
4722}
4723
4724static KeyBlock *insert_curvekey(Main *bmain, Object *ob, const char *name, const bool from_mix)
4725{
4726 Curve *cu = id_cast<Curve *>(ob->data);
4727 Key *key = cu->key;
4728 KeyBlock *kb;
4729 ListBaseT<Nurb> *lb = BKE_curve_nurbs_get(cu);
4730 int newkey = 0;
4731
4732 if (key == nullptr) {
4733 key = cu->key = BKE_key_add(bmain, id_cast<ID *>(cu));
4734 key->type = KEY_RELATIVE;
4735 newkey = 1;
4736 }
4737
4738 if (newkey || from_mix == false) {
4739 /* create from curve */
4740 kb = BKE_keyblock_add_ctime(key, name, false);
4741 if (!newkey) {
4742 KeyBlock *basekb = key->block.first();
4743 kb->data = MEM_dupalloc_void(basekb->data);
4744 kb->totelem = basekb->totelem;
4745 }
4746 else {
4748 }
4749 }
4750 else {
4751 /* copy from current values */
4752 int totelem;
4753 float *data = BKE_key_evaluate_object(ob, &totelem);
4754
4755 /* create new block with prepared data */
4756 kb = BKE_keyblock_add_ctime(key, name, false);
4757 kb->totelem = totelem;
4758 kb->data = data;
4759 }
4760
4761 return kb;
4762}
4763
4765
4766/* -------------------------------------------------------------------- */
4769
4771 Object *ob,
4772 const char *name,
4773 const bool from_mix)
4774{
4775 KeyBlock *key = nullptr;
4776
4777 switch (ob->type) {
4778 case OB_MESH:
4779 key = insert_meshkey(bmain, ob, name, from_mix);
4780 break;
4781 case OB_CURVES_LEGACY:
4782 case OB_SURF:
4783 key = insert_curvekey(bmain, ob, name, from_mix);
4784 break;
4785 case OB_LATTICE:
4786 key = insert_lattkey(bmain, ob, name, from_mix);
4787 break;
4788 default:
4789 break;
4790 }
4791
4792 /* Set the first active when none is set when called from RNA. */
4793 if (key != nullptr) {
4794 if (ob->shapenr <= 0) {
4795 ob->shapenr = 1;
4796 }
4797 }
4798
4799 return key;
4800}
4801
4803{
4804 Key **key_p, *key;
4805
4806 key_p = BKE_key_from_object_p(ob);
4807 if (ELEM(nullptr, key_p, *key_p)) {
4808 return false;
4809 }
4810
4811 key = *key_p;
4812 *key_p = nullptr;
4813
4814 BKE_id_free_us(bmain, key);
4815
4816 return true;
4817}
4818
4820{
4821 Key *key = BKE_key_from_object(ob);
4822 short kb_index;
4823
4824 if (key == nullptr) {
4825 return false;
4826 }
4827
4828 BKE_animdata_drivers_remove_for_rna_struct(key->id, *RNA_ShapeKey, kb);
4829
4830 kb_index = BLI_findindex(&key->block, kb);
4831 BLI_assert(kb_index != -1);
4832
4833 for (KeyBlock &rkb : key->block) {
4834 if (rkb.relative == kb_index) {
4835 /* remap to the 'Basis' */
4836 rkb.relative = 0;
4837 }
4838 else if (rkb.relative >= kb_index) {
4839 /* Fix positional shift of the keys when kb is deleted from the list */
4840 rkb.relative -= 1;
4841 }
4842 }
4843
4844 BLI_remlink(&key->block, kb);
4845 key->totkey--;
4846 if (key->refkey == kb) {
4847 key->refkey = key->block.first();
4848
4849 if (key->refkey) {
4850 /* apply new basis key on original data */
4851 switch (ob->type) {
4852 case OB_MESH: {
4853 Mesh *mesh = id_cast<Mesh *>(ob->data);
4854 BKE_keyblock_convert_to_mesh(key->refkey, mesh->vert_positions_for_write());
4855 break;
4856 }
4857 case OB_CURVES_LEGACY:
4858 case OB_SURF:
4860 id_cast<Curve *>(ob->data),
4861 BKE_curve_nurbs_get(id_cast<Curve *>(ob->data)));
4862 break;
4863 case OB_LATTICE:
4864 BKE_keyblock_convert_to_lattice(key->refkey, id_cast<Lattice *>(ob->data));
4865 break;
4866 default:
4867 break;
4868 }
4869 }
4870 }
4871
4872 if (kb->data) {
4873 MEM_delete_void(kb->data);
4874 }
4875 MEM_delete(kb);
4876
4877 /* Unset active when all are freed. */
4878 if (key->block.is_empty()) {
4879 ob->shapenr = 0;
4880 }
4881 else if (ob->shapenr > 1) {
4882 ob->shapenr--;
4883 }
4884
4885 if (key->totkey == 0) {
4886 BKE_object_shapekey_free(bmain, ob);
4887 }
4888
4889 return true;
4890}
4891
4893
4894/* -------------------------------------------------------------------- */
4897
4898bool BKE_object_parent_loop_check(const Object *par, const Object *ob)
4899{
4900 /* test if 'ob' is a parent somewhere in par's parents */
4901 if (par == nullptr) {
4902 return false;
4903 }
4904 if (ob == par) {
4905 return true;
4906 }
4907 return BKE_object_parent_loop_check(par->parent, ob);
4908}
4909
4910bool BKE_object_flag_test_recursive(const Object *ob, short flag)
4911{
4912 if (ob->flag & flag) {
4913 return true;
4914 }
4915 if (ob->parent) {
4916 return BKE_object_flag_test_recursive(ob->parent, flag);
4917 }
4918
4919 return false;
4920}
4921
4922bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
4923{
4924 for (ob_child = ob_child->parent; ob_child; ob_child = ob_child->parent) {
4925 if (ob_child == ob_parent) {
4926 return true;
4927 }
4928 }
4929 return false;
4930}
4931
4933{
4934 /* Always test on original object since evaluated object may no longer
4935 * have shape keys or modifiers that were used to evaluate it. */
4936 ob = DEG_get_original(ob);
4937
4938 int flag = 0;
4939
4940 if (BKE_key_from_object(ob)) {
4942 }
4943 else {
4944 ModifierData *md;
4945 VirtualModifierData virtual_modifier_data;
4946 /* cloth */
4947 for (md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
4948 md && (flag != (eModifierMode_Render | eModifierMode_Realtime));
4949 md = md->next)
4950 {
4951 if ((flag & eModifierMode_Render) == 0 &&
4953 {
4954 flag |= eModifierMode_Render;
4955 }
4956
4957 if ((flag & eModifierMode_Realtime) == 0 &&
4959 {
4960 flag |= eModifierMode_Realtime;
4961 }
4962 }
4963 }
4964
4965 return flag;
4966}
4967
4968bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
4969{
4970 /* If object has any sort of animation data assume it is moving. */
4972 return true;
4973 }
4974 if (!object->constraints.is_empty()) {
4975 return true;
4976 }
4977 if (recurse_parent && object->parent != nullptr) {
4978 return BKE_object_moves_in_time(object->parent, true);
4979 }
4980 return false;
4981}
4982
4983static bool object_moves_in_time(const Object *object)
4984{
4985 return BKE_object_moves_in_time(object, true);
4986}
4987
4988static bool object_deforms_in_time(Object *object)
4989{
4990 if (BKE_key_from_object(object) != nullptr) {
4991 return true;
4992 }
4993 if (!object->modifiers.is_empty()) {
4994 return true;
4995 }
4996 return object_moves_in_time(object);
4997}
4998
5000{
5001 /* TODO(sergey): Consider generalizing this a bit so all modifier logic
5002 * is concentrated in MOD_{modifier}.c file,
5003 */
5004 if (md->type == eModifierType_Array) {
5005 ArrayModifierData *amd = reinterpret_cast<ArrayModifierData *>(md);
5006 /* TODO(sergey): Check if curve is deformed. */
5007 return (amd->start_cap != nullptr && object_moves_in_time(amd->start_cap)) ||
5008 (amd->end_cap != nullptr && object_moves_in_time(amd->end_cap)) ||
5009 (amd->curve_ob != nullptr && object_moves_in_time(amd->curve_ob)) ||
5010 (amd->offset_ob != nullptr && object_moves_in_time(amd->offset_ob));
5011 }
5012 if (md->type == eModifierType_Mirror) {
5013 MirrorModifierData *mmd = reinterpret_cast<MirrorModifierData *>(md);
5014 return mmd->mirror_ob != nullptr &&
5016 }
5017 if (md->type == eModifierType_Screw) {
5018 ScrewModifierData *smd = reinterpret_cast<ScrewModifierData *>(md);
5019 return smd->ob_axis != nullptr && object_moves_in_time(smd->ob_axis);
5020 }
5022 /* NOTE: Not ideal because it's unknown whether topology changes or not.
5023 * This will be detected later, so by assuming it's only deformation
5024 * going on here we allow baking deform-only mesh to Alembic and have
5025 * proper motion blur after that.
5026 */
5027 return true;
5028 }
5029 if (md->type == eModifierType_Nodes) {
5030 /* Not ideal for performance to always assume this is animated,
5031 * but hard to detect in general. The better long term solution is likely
5032 * to replace BKE_object_is_deform_modified by a test if the object was
5033 * modified by the depsgraph when changing frames. */
5034 return true;
5035 }
5036 return false;
5037}
5038
5040{
5041 /* TODO(sergey): This is a bit code duplication with depsgraph, but
5042 * would be nicer to solve this as a part of new dependency graph
5043 * work, so we avoid conflicts and so.
5044 */
5045 if (ob->adt != nullptr) {
5046 AnimData *adt = ob->adt;
5047 if (adt->action != nullptr) {
5049 if (strstr(fcu->rna_path().c_str(), "modifiers[")) {
5050 return true;
5051 }
5052 }
5053 }
5054 for (FCurve &fcu : adt->drivers) {
5055 if (strstr(fcu.rna_path().c_str(), "modifiers[")) {
5056 return true;
5057 }
5058 }
5059 }
5060 return false;
5061}
5062
5064{
5065 /* Always test on original object since evaluated object may no longer
5066 * have shape keys or modifiers that were used to evaluate it. */
5067 ob = DEG_get_original(ob);
5068
5069 ModifierData *md;
5070 VirtualModifierData virtual_modifier_data;
5071 int flag = 0;
5072 const bool is_modifier_animated = modifiers_has_animation_check(ob);
5073
5074 if (BKE_key_from_object(ob)) {
5076 }
5077
5078 if (ob->type == OB_CURVES_LEGACY) {
5079 Curve *cu = id_cast<Curve *>(ob->data);
5080 if (cu->taperobj != nullptr && object_deforms_in_time(cu->taperobj)) {
5082 }
5083 }
5084
5085 /* cloth */
5086 for (md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data);
5087 md && (flag != (eModifierMode_Render | eModifierMode_Realtime));
5088 md = md->next)
5089 {
5091 bool can_deform = mti->type == ModifierTypeType::OnlyDeform || is_modifier_animated;
5092
5093 if (!can_deform) {
5094 can_deform = constructive_modifier_is_deform_modified(ob, md);
5095 }
5096
5097 if (can_deform) {
5098 if (!(flag & eModifierMode_Render) &&
5100 {
5101 flag |= eModifierMode_Render;
5102 }
5103
5104 if (!(flag & eModifierMode_Realtime) &&
5106 {
5107 flag |= eModifierMode_Realtime;
5108 }
5109 }
5110 }
5111
5112 return flag;
5113}
5114
5115void BKE_object_get_mirror_axes(const Object *ob, bool r_axis[3])
5116{
5117 r_axis[0] = r_axis[1] = r_axis[2] = false;
5118
5119 for (ModifierData &md : ob->modifiers) {
5121 const MirrorModifierData *mmd = reinterpret_cast<MirrorModifierData *>(&md);
5122 if (mmd->mirror_ob) {
5123 /* Mirror objects may have an arbitrary transform, so the mirrored
5124 * geometry isn't guaranteed to be continuous with the original. */
5125 continue;
5126 }
5127 if (mmd->flag & MOD_MIR_NO_MERGE) {
5128 continue;
5129 }
5130 if (mmd->flag & MOD_MIR_AXIS_X) {
5131 r_axis[0] = true;
5132 }
5133 if (mmd->flag & MOD_MIR_AXIS_Y) {
5134 r_axis[1] = true;
5135 }
5136 if (mmd->flag & MOD_MIR_AXIS_Z) {
5137 r_axis[2] = true;
5138 }
5139 }
5140 }
5141}
5142
5144{
5145 int num_scenes = 0;
5146 for (Scene &scene : bmain->scenes) {
5148 num_scenes++;
5149 }
5150 }
5151 return num_scenes;
5152}
5153
5154MovieClip *BKE_object_movieclip_get(Scene *scene, const Object *ob, bool use_default)
5155{
5156 MovieClip *clip = use_default ? scene->clip : nullptr;
5157 bConstraint *con = ob->constraints.first(), *scon = nullptr;
5158
5159 while (con) {
5160 if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) {
5161 if (scon == nullptr || (scon->flag & CONSTRAINT_OFF)) {
5162 scon = con;
5163 }
5164 }
5165
5166 con = con->next;
5167 }
5168
5169 if (scon) {
5170 bCameraSolverConstraint *solver = static_cast<bCameraSolverConstraint *>(scon->data);
5171 if ((solver->flag & CAMERASOLVER_ACTIVECLIP) == 0) {
5172 clip = solver->clip;
5173 }
5174 else {
5175 clip = scene->clip;
5176 }
5177 }
5178
5179 return clip;
5180}
5181
5183{
5184 return ELEM(ob->type,
5185 OB_MESH,
5187 OB_SURF,
5188 OB_FONT,
5189 OB_MBALL,
5190 OB_CURVES,
5192 OB_VOLUME,
5194}
5195
5197
5198/* -------------------------------------------------------------------- */
5201
5203{
5204 *object->runtime = {};
5205}
5206
5207void BKE_object_runtime_reset_on_copy(Object *object, const int /*flag*/)
5208{
5209 bke::ObjectRuntime *runtime = object->runtime;
5210 runtime->data_eval = nullptr;
5211 runtime->curve_cache = nullptr;
5212 runtime->object_as_temp_mesh = nullptr;
5213 runtime->pose_backup = nullptr;
5214 runtime->object_as_temp_curve = nullptr;
5215 runtime->geometry_set_eval = nullptr;
5216 runtime->contained_geometry_types = 0;
5217 runtime->sculpt_session = nullptr;
5218
5219 runtime->crazyspace_deform_imats = {};
5220 runtime->crazyspace_deform_cos = {};
5221}
5222
5224{
5226 BKE_sculptsession_free(object);
5227
5229}
5230
5232
5233/* -------------------------------------------------------------------- */
5236
5241{
5242 Object *ob_arm = nullptr;
5243
5244 if (ob->parent && ob->partype == PARSKEL && ob->parent->type == OB_ARMATURE) {
5245 ob_arm = ob->parent;
5246 }
5247 else {
5248 for (ModifierData &mod : ob->modifiers) {
5249 if (mod.type == eModifierType_Armature) {
5250 ob_arm = (reinterpret_cast<ArmatureModifierData *>(&mod))->object;
5251 }
5252 }
5253 }
5254
5255 return ob_arm;
5256}
5257
5258static bool obrel_list_test(Object *ob)
5259{
5260 return ob && !(ob->id.tag & ID_TAG_DOIT);
5261}
5262
5263static void obrel_list_add(LinkNode **links, Object *ob)
5264{
5265 BLI_linklist_prepend(links, ob);
5266 ob->id.tag |= ID_TAG_DOIT;
5267}
5268
5270 const Scene *scene,
5271 ViewLayer *view_layer,
5272 eObjectSet objectSet,
5273 eObRelationTypes includeFilter)
5274{
5275 LinkNode *links = nullptr;
5276
5277 /* Remove markers from all objects */
5278 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
5279 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
5280 base.object->id.tag &= ~ID_TAG_DOIT;
5281 }
5282
5283 /* iterate over all selected and visible objects */
5284 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
5285 if (objectSet == OB_SET_ALL) {
5286 /* As we get all anyway, just add it. */
5287 Object *ob = base.object;
5288 obrel_list_add(&links, ob);
5289 }
5290 else {
5291 if ((objectSet == OB_SET_SELECTED && BASE_SELECTED_EDITABLE(((View3D *)nullptr), &base)) ||
5292 (objectSet == OB_SET_VISIBLE && BASE_EDITABLE(((View3D *)nullptr), &base)))
5293 {
5294 Object *ob = base.object;
5295
5296 if (obrel_list_test(ob)) {
5297 obrel_list_add(&links, ob);
5298 }
5299
5300 /* parent relationship */
5301 if (includeFilter & (OB_REL_PARENT | OB_REL_PARENT_RECURSIVE)) {
5302 Object *parent = ob->parent;
5303 if (obrel_list_test(parent)) {
5304
5305 obrel_list_add(&links, parent);
5306
5307 /* recursive parent relationship */
5308 if (includeFilter & OB_REL_PARENT_RECURSIVE) {
5309 parent = parent->parent;
5310 while (obrel_list_test(parent)) {
5311
5312 obrel_list_add(&links, parent);
5313 parent = parent->parent;
5314 }
5315 }
5316 }
5317 }
5318
5319 /* child relationship */
5320 if (includeFilter & (OB_REL_CHILDREN | OB_REL_CHILDREN_RECURSIVE)) {
5321 for (Base &local_base : *BKE_view_layer_object_bases_get(view_layer)) {
5322 if (BASE_EDITABLE(((View3D *)nullptr), &local_base)) {
5323
5324 Object *child = local_base.object;
5325 if (obrel_list_test(child)) {
5326 if ((includeFilter & OB_REL_CHILDREN_RECURSIVE &&
5327 BKE_object_is_child_recursive(ob, child)) ||
5328 (includeFilter & OB_REL_CHILDREN && child->parent && child->parent == ob))
5329 {
5330 obrel_list_add(&links, child);
5331 }
5332 }
5333 }
5334 }
5335 }
5336
5337 /* include related armatures */
5338 if (includeFilter & OB_REL_MOD_ARMATURE) {
5339 Object *arm = obrel_armature_find(ob);
5340 if (obrel_list_test(arm)) {
5341 obrel_list_add(&links, arm);
5342 }
5343 }
5344 }
5345 }
5346 }
5347
5348 return links;
5349}
5350
5352{
5353 LinkNode *collection_linknode = nullptr;
5354 Collection *collection = nullptr;
5355 while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
5356 BLI_linklist_prepend(&collection_linknode, collection);
5357 }
5358
5359 return collection_linknode;
5360}
5361
5362void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *ob)
5363{
5364 Collection *collection = nullptr;
5365 while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
5366 BKE_collection_object_remove(bmain, collection, ob, false);
5368 }
5369}
5370
5372
5373/* -------------------------------------------------------------------- */
5376
5378{
5379 KDTree<float3> *tree = nullptr;
5380 uint tot = 0;
5381
5382 switch (ob->type) {
5383 case OB_MESH: {
5384 Mesh *mesh = id_cast<Mesh *>(ob->data);
5385 uint i;
5386
5387 const Mesh *mesh_eval = BKE_object_get_mesh_deform_eval(ob) ?
5390 const int *index;
5391
5392 if (mesh_eval && (index = static_cast<const int *>(
5394 {
5395 const Span<float3> positions = mesh->vert_positions();
5396
5397 /* Tree over-allocates in case where some verts have #ORIGINDEX_NONE. */
5398 tot = 0;
5399 tree = kdtree_new<float3>(positions.size());
5400
5401 /* We don't how many verts from the DM we can use. */
5402 for (i = 0; i < positions.size(); i++) {
5403 if (index[i] != ORIGINDEX_NONE) {
5404 float co[3];
5405 mul_v3_m4v3(co, ob->object_to_world().ptr(), positions[i]);
5406 kdtree_insert<float3>(tree, index[i], co);
5407 tot++;
5408 }
5409 }
5410 }
5411 else {
5412 const Span<float3> positions = mesh->vert_positions();
5413
5414 tot = positions.size();
5415 tree = kdtree_new<float3>(tot);
5416
5417 for (i = 0; i < tot; i++) {
5418 float co[3];
5419 mul_v3_m4v3(co, ob->object_to_world().ptr(), positions[i]);
5420 kdtree_insert<float3>(tree, i, co);
5421 }
5422 }
5423
5425 break;
5426 }
5427 case OB_CURVES_LEGACY:
5428 case OB_SURF: {
5429 /* TODO: take deformation into account */
5430 Curve *cu = id_cast<Curve *>(ob->data);
5431 uint i, a;
5432
5433 Nurb *nu;
5434
5436 tree = kdtree_new<float3>(tot);
5437 i = 0;
5438
5439 nu = cu->nurb.first();
5440 while (nu) {
5441 if (nu->bezt) {
5442 BezTriple *bezt;
5443
5444 bezt = nu->bezt;
5445 a = nu->pntsu;
5446 while (a--) {
5447 float co[3];
5448 mul_v3_m4v3(co, ob->object_to_world().ptr(), bezt->vec[1]);
5449 kdtree_insert<float3>(tree, i++, co);
5450 bezt++;
5451 }
5452 }
5453 else {
5454 BPoint *bp;
5455
5456 bp = nu->bp;
5457 a = nu->pntsu * nu->pntsv;
5458 while (a--) {
5459 float co[3];
5460 mul_v3_m4v3(co, ob->object_to_world().ptr(), bp->vec);
5461 kdtree_insert<float3>(tree, i++, co);
5462 bp++;
5463 }
5464 }
5465 nu = nu->next;
5466 }
5467
5469 break;
5470 }
5471 case OB_LATTICE: {
5472 /* TODO: take deformation into account */
5473 Lattice *lt = id_cast<Lattice *>(ob->data);
5474 BPoint *bp;
5475 uint i;
5476
5477 tot = lt->pntsu * lt->pntsv * lt->pntsw;
5478 tree = kdtree_new<float3>(tot);
5479 i = 0;
5480
5481 for (bp = lt->def; i < tot; bp++) {
5482 float co[3];
5483 mul_v3_m4v3(co, ob->object_to_world().ptr(), bp->vec);
5484 kdtree_insert<float3>(tree, i++, co);
5485 }
5486
5488 break;
5489 }
5490 default:
5491 break;
5492 }
5493
5494 *r_tot = tot;
5495 return tree;
5496}
5497
5499
5500/* -------------------------------------------------------------------- */
5503
5507static void object_cacheIgnoreClear(Object *ob, const bool state)
5508{
5509 ListBaseT<PTCacheID> pidlist;
5510 BKE_ptcache_ids_from_object(&pidlist, ob, nullptr, 0);
5511
5512 for (PTCacheID &pid : pidlist) {
5513 if (pid.cache) {
5514 if (state) {
5515 pid.cache->flag |= PTCACHE_IGNORE_CLEAR;
5516 }
5517 else {
5518 pid.cache->flag &= ~PTCACHE_IGNORE_CLEAR;
5519 }
5520 }
5521 }
5522
5523 pidlist.free_no_destruct();
5524}
5525
5532
5542 Object *ob,
5543 const bool update_mesh,
5544 const int parent_recursion_limit)
5545{
5546 /* NOTE: this function must not modify the object
5547 * since this is used for setting up depsgraph relationships.
5548 *
5549 * Although the #ObjectModifierUpdateContext::update_or_tag_fn callback may change the object
5550 * as this is needed to implement #BKE_object_modifier_update_subframe. */
5551
5552 /* NOTE(@ideasman42): `parent_recursion_limit` is used to prevent this function attempting to
5553 * scan object hierarchies infinitely, needed since constraint targets are also included.
5554 * A more elegant alternative may be to track which objects have been handled.
5555 * Since #BKE_object_modifier_update_subframe is documented not to be used
5556 * for new code (if possible), leave as-is. */
5557
5559
5561 DynamicPaintModifierData *pmd = reinterpret_cast<DynamicPaintModifierData *>(md);
5562
5563 /* if other is dynamic paint canvas, don't update */
5564 if (pmd && pmd->canvas) {
5565 return true;
5566 }
5567 }
5568 else if (ctx.modifier_type == eModifierType_Fluid) {
5569 FluidModifierData *fmd = reinterpret_cast<FluidModifierData *>(md);
5570
5571 if (fmd && (fmd->type & MOD_FLUID_TYPE_DOMAIN) != 0) {
5572 return true;
5573 }
5574 }
5575
5576 /* if object has parents, update them too */
5577 if (parent_recursion_limit) {
5578 const int recursion = parent_recursion_limit - 1;
5579 bool no_update = false;
5580 if (ob->parent) {
5581 no_update |= object_modifier_recurse_for_update_subframe(ctx, ob->parent, false, recursion);
5582 }
5583
5584 /* Skip sub-frame if object is parented to vertex of a dynamic paint canvas. */
5585 if (no_update && ELEM(ob->partype, PARVERT1, PARVERT3)) {
5586 return false;
5587 }
5588
5589 /* also update constraint targets */
5590 for (bConstraint &con : ob->constraints) {
5591 ListBaseT<bConstraintTarget> targets = {nullptr, nullptr};
5592
5593 if (BKE_constraint_targets_get(&con, &targets)) {
5594 for (bConstraintTarget &ct : targets) {
5595 if (ct.tar) {
5596 object_modifier_recurse_for_update_subframe(ctx, ct.tar, false, recursion);
5597 }
5598 }
5599 /* free temp targets */
5600 BKE_constraint_targets_flush(&con, &targets, false);
5601 }
5602 }
5603 }
5604
5605 ctx.update_or_tag_fn(ob, update_mesh);
5606
5607 return false;
5608}
5609
5611 Object *ob,
5612 const bool update_mesh,
5613 const int parent_recursion_limit,
5614 const /*ModifierType*/ int modifier_type,
5615 FunctionRef<void(Object *object, bool update_mesh)> update_or_tag_fn)
5616{
5618 ModifierType(modifier_type),
5619 update_or_tag_fn,
5620 };
5621 object_modifier_recurse_for_update_subframe(ctx, ob, update_mesh, parent_recursion_limit);
5622}
5623
5624void BKE_object_modifier_update_subframe(Depsgraph *depsgraph,
5625 Scene *scene,
5626 Object *ob,
5627 const bool update_mesh,
5628 const int parent_recursion_limit,
5629 const float frame,
5630 const /*ModifierType*/ int modifier_type)
5631{
5632 const bool flush_to_original = DEG_is_active(depsgraph);
5633
5634 auto update_or_tag_fn = [depsgraph, scene, frame, flush_to_original](Object *ob,
5635 const bool update_mesh) {
5636 /* NOTE: changes here may require updates to #DEG_add_collision_relations
5637 * so the depsgraph is handling updates correctly. */
5638
5639 /* was originally ID_RECALC_ALL - TODO: which flags are really needed??? */
5640 /* TODO(sergey): What about animation? */
5641 const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph,
5642 frame);
5643
5644 ob->id.recalc |= ID_RECALC_ALL;
5645 if (update_mesh) {
5647 &ob->id, ob->adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
5648 /* Ignore cache clear during sub-frame updates to not mess up cache validity. */
5649 object_cacheIgnoreClear(ob, true);
5650 BKE_object_handle_update(depsgraph, scene, ob);
5651 object_cacheIgnoreClear(ob, false);
5652 }
5653 else {
5654 BKE_object_where_is_calc_time(depsgraph, scene, ob, frame);
5655 }
5656
5657 /* for curve following objects, parented curve has to be updated too */
5658 if (ob->type == OB_CURVES_LEGACY) {
5659 Curve *cu = id_cast<Curve *>(ob->data);
5661 &cu->id, cu->adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
5662 }
5663 /* and armatures... */
5664 if (ob->type == OB_ARMATURE) {
5665 bArmature *arm = id_cast<bArmature *>(ob->data);
5667 &arm->id, arm->adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
5668 BKE_pose_where_is(depsgraph, scene, ob);
5669 }
5670 };
5671
5673 ob, update_mesh, parent_recursion_limit, modifier_type, update_or_tag_fn);
5674}
5675
5677{
5678 Object *ob = bmain->objects.first();
5679 int select_id = 1;
5680 while (ob) {
5681 ob->runtime->select_id = select_id++;
5682 ob = static_cast<Object *>(ob->id.next);
5683 }
5684}
5685
5687
5688/* -------------------------------------------------------------------- */
5691
5692Mesh *BKE_object_to_mesh(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
5693{
5695
5696 Mesh *mesh = BKE_mesh_new_from_object(depsgraph, object, preserve_all_data_layers, false, true);
5697 object->runtime->object_as_temp_mesh = mesh;
5698 return mesh;
5699}
5700
5702{
5703 if (object->runtime->object_as_temp_mesh == nullptr) {
5704 return;
5705 }
5706 BKE_id_free(nullptr, object->runtime->object_as_temp_mesh);
5707 object->runtime->object_as_temp_mesh = nullptr;
5708}
5709
5710Curve *BKE_object_to_curve(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
5711{
5713
5714 Curve *curve = BKE_curve_new_from_object(object, depsgraph, apply_modifiers);
5715 object->runtime->object_as_temp_curve = curve;
5716 return curve;
5717}
5718
5720{
5721 if (object->runtime->object_as_temp_curve == nullptr) {
5722 return;
5723 }
5724 BKE_id_free(nullptr, object->runtime->object_as_temp_curve);
5725 object->runtime->object_as_temp_curve = nullptr;
5726}
5727
5732
5734{
5735 ModifierData *md = ob->modifiers.last();
5736
5737 while (md) {
5738 if (md->type == eModifierType_Subsurf) {
5739 break;
5740 }
5741
5742 md = md->prev;
5743 }
5744
5745 return reinterpret_cast<SubsurfModifierData *>(md);
5746}
5747
5749{
5750 ob->type = ObjectType(BKE_object_obdata_to_type(new_data));
5751 ob->data = new_data;
5752 ob->runtime->geometry_set_eval = nullptr;
5754 ob->runtime->data_eval = new_data;
5755 ob->runtime->bounds_eval.reset();
5756 ob->id.py_instance = nullptr;
5757}
5758
5760
5761const float4x4 &Object::object_to_world() const
5762{
5763 BLI_assert(!this->runtime->is_draw_dupli_reference_tmp_object);
5764 return this->runtime->object_to_world;
5765}
5766const float4x4 &Object::world_to_object() const
5767{
5768 BLI_assert(!this->runtime->is_draw_dupli_reference_tmp_object);
5769 return this->runtime->world_to_object;
5770}
5771
5772} // namespace blender
Functions for backward compatibility with the legacy Action API.
Functions to work with AnimData.
Blender kernel action and pose functionality.
Camera data-block and utility functions.
Low-level operations for curves.
#define ORIGINDEX_NONE
support for deformation groups and hooks.
display list (or rather multi purpose list) stuff.
#define GEO_COMPONENT_TYPE_ENUM_SIZE
Low-level operations for grease pencil.
#define IDP_int_get(prop)
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
General operations, lookup, etc. for blender lights.
General operations for probes.
Blender kernel freestyle line style functionality.
#define FOREACH_MAIN_ID_END
Definition BKE_main.hh:735
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition BKE_main.hh:729
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
General operations for point clouds.
API for Blender-side Rigid Body stuff.
General operations for speakers.
Volume data-block.
A KD-tree for nearest neighbor search.
#define BLI_ASSERT_UNIT_M3(m)
#define FILE_MAX
#define SNPRINTF(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
external readfile function prototypes.
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_ID
#define BLT_I18NCONTEXT_ID_LIGHT
#define BLT_I18NCONTEXT_ID_OBJECT
#define CTX_DATA_(context, msgid)
#define DATA_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
#define FILTER_ID_OB
Definition DNA_ID.h:1216
#define FILTER_ID_ALL
Definition DNA_ID.h:1241
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
Object groups, one object can be in many groups at once.
#define ME_EDIT_PAINT_SEL_MODE(_me)
#define OB_MODE_ALL_MODE_DATA
#define OB_MODE_ALL_SCULPT
Object is a sort of wrapper for general info.
#define OB_TYPE_SUPPORT_PARVERT(_type)
#define OB_DATA_SUPPORT_EDITMODE(_type)
#define OB_TYPE_SUPPORT_VGROUP(_type)
Types and defines for representing Rigid Body entities.
#define BASE_SELECTED_EDITABLE(v3d, base)
#define BASE_EDITABLE(v3d, base)
#define BASE_VISIBLE(v3d, base)
#define USER_EXPERIMENTAL_TEST(userdef, member)
Read Blender memory allocation and freeing.
volatile int lock
#define CLAMP(a, b, c)
#define CLAMP_MAX(a, c)
#define BLI_assert_unreachable()
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
#define BLI_assert(a)
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
btScalar max
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
constexpr Span()=default
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr MutableSpan()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr const char * c_str() const
#define copysignf(x, y)
#define offsetof(t, d)
#define rot(x, k)
#define layer
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
MatBase< 4, 4 > float4x4
float3x3 scale(float3x3 mat, float2 scale)
const int state
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
Span< FCurve * > fcurves_for_assigned_action(AnimData *adt)
Definition animdata.cc:349
void settings_init(struct bAnimVizSettings *avs)
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
void blend_read_data(struct BlendDataReader *reader, struct bMotionPath *mpath)
struct bMotionPath * copy(const struct bMotionPath *mpath_src)
void free(struct bMotionPath *mpath)
void blend_write(struct BlendWriter *writer, struct bMotionPath *mpath)
bool object_has_geometry_set_instances(const Object &object)
Bounds< VecBase< T, 3 > > transform_bounds(const MatBase< T, D, D > &matrix, const Bounds< VecBase< T, 3 > > &bounds)
internal::ShallowZeroInitializeTag shallow_zero_initialize()
Definition DNA_defs.h:159
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
static void create_legacy_geometry_nodes_properties(Object &ob)
Definition object.cc:700
static void free_legacy_geometry_nodes_properties(Object &ob)
Definition object.cc:775
T min(const T &a, const T &b)
void min_max(const T &value, T &min, T &max)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
T max(const T &a, const T &b)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit)
Definition particle.cc:938
int BKE_object_insert_ptcache(Object *ob)
Definition object.cc:4592
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
Definition object.cc:3549
UserDef U
Definition blender.cc:58
const Mesh * BKE_object_get_pre_modified_mesh(const Object *object)
Definition object.cc:4444
Vector< Base * > BKE_object_pose_base_array_get(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2640
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_constraints_copy_ex(ListBaseT< bConstraint > *dst, const ListBaseT< bConstraint > *src, int flag, bool do_extern)
static void object_copy_data(Main *bmain, std::optional< Library * >, ID *id_dst, const ID *id_src, const int flag)
Definition object.cc:189
void BKE_modifier_copydata(const ModifierData *md, ModifierData *target)
void kdtree_balance(KDTree< CoordT > *tree)
static void object_foreach_path_pointcache(ListBaseT< PointCache > *ptcache_list, BPathForeachPathData *bpath_data)
Definition object.cc:513
void BKE_modifier_copydata_ex(const ModifierData *md, ModifierData *target, int flag)
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name) ATTR_NONNULL(1
Definition object.cc:2296
const Mesh * BKE_object_get_editmesh_eval_cage(const Object *object)
Definition object.cc:4492
void BKE_sculptsession_free(Object *ob)
SubsurfModifierData * BKE_object_get_last_subsurf_modifier(const Object *ob)
Definition object.cc:5733
void BKE_object_sculpt_data_create(Object *ob)
Definition object.cc:4337
bool BKE_object_is_in_editmode_vgroup(const Object *ob)
Definition object.cc:1927
bArmature * BKE_armature_add(Main *bmain, const char *name)
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1398
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
void BKE_previewimg_id_free(ID *id)
void BKE_object_rot_to_mat3(const Object *ob, float r_mat[3][3], bool use_drot)
Definition object.cc:2906
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_object_tfm_copy(Object *object_dst, const Object *object_src)
Definition object.cc:3088
struct Curves * BKE_curves_add(struct Main *bmain, const char *name)
void BKE_object_runtime_reset(Object *object)
Definition object.cc:5202
void BKE_pose_tag_recalc(Main *bmain, bPose *pose) ATTR_NONNULL(1
void BKE_object_empty_draw_type_set(Object *ob, int value)
Definition object.cc:3860
@ ADT_RECALC_ANIM
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void BKE_view_layer_base_select_and_set_active(ViewLayer *view_layer, Base *selbase)
Key ** BKE_key_from_object_p(Object *ob)
Definition key.cc:1302
void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
void BKE_asset_metadata_idprop_ensure(AssetMetaData *asset_data, IDProperty *prop)
Definition asset.cc:172
int BKE_ptcache_path(PTCacheID *pid, char *dirname)
bool BKE_object_empty_image_frame_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d)
Definition object.cc:3877
void BKE_object_tfm_protected_backup(const Object *ob, ObjectTfmProtectedChannels *obtfm)
Definition object.cc:3025
@ NODES_MODIFIER_BAKE_CUSTOM_PATH
void BKE_mesh_texspace_get_reference(Mesh *mesh, char **r_texspace_flag, float **r_texspace_location, float **r_texspace_size)
static void obrel_list_add(LinkNode **links, Object *ob)
Definition object.cc:5263
void BKE_shaderfx_foreach_ID_link(Object *ob, ShaderFxIDWalkFunc walk, void *user_data)
Definition shader_fx.cc:239
Mesh * BKE_object_get_evaluated_mesh_no_subsurf_unchecked(const Object *object)
Definition object.cc:4392
@ POSE_CONSTRAINTS_NEED_UPDATE_FLAGS
void BKE_light_linking_copy(struct Object *object_dst, const struct Object *object_src, const int copy_flags)
void BKE_object_apply_parent_inverse(Object *ob)
Definition object.cc:3671
std::optional< Bounds< float3 > > BKE_volume_min_max(const Volume *volume)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static IDProperty * object_asset_dimensions_property(Object *ob)
Definition object.cc:1241
void BKE_previewimg_blend_read(BlendDataReader *reader, PreviewImage *prv)
void BKE_id_free_us(Main *bmain, void *idv) ATTR_NONNULL()
bool BKE_bpath_foreach_path_allocated_process(BPathForeachPathData *bpath_data, char **path)
Definition bpath.cc:266
void BKE_constraint_targets_flush(struct bConstraint *con, ListBaseT< bConstraintTarget > *targets, bool no_copy)
void BKE_libblock_relink_to_newid(Main *bmain, ID *id, int remap_flag) ATTR_NONNULL()
Definition lib_remap.cc:932
ShaderFxData * BKE_shaderfx_new(ShaderFxType type)
Definition shader_fx.cc:56
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
void copy_m3_m4(float m1[3][3], const float m2[4][4])
@ eParticleSystemFlag_file_loaded
void BKE_modifier_blend_read_data(BlendDataReader *reader, ListBaseT< ModifierData > *lb, Object *ob)
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:324
Material *** BKE_object_material_array_p(Object *ob)
void BLO_read_pointer_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size)
void BKE_constraints_solve(struct Depsgraph *depsgraph, ListBaseT< bConstraint > *conlist, struct bConstraintOb *cob, float ctime)
void id_us_plus(ID *id)
Definition lib_id.cc:433
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void BKE_object_free_softbody(Object *ob)
Definition object.cc:1318
LayerCollection * BKE_layer_collection_get_active(ViewLayer *view_layer)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3])
void BKE_object_runtime_free_data(Object *object)
Definition object.cc:5223
void BKE_pose_free_ex(bPose *pose, bool do_id_user)
bool BKE_object_empty_image_data_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d)
Definition object.cc:3887
void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentmat[4][4])
Definition object.cc:3419
bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
Definition object.cc:4968
void BKE_displist_free(ListBaseT< DispList > *lb)
Definition displist.cc:68
bool BKE_collection_viewlayer_object_add(Main *bmain, const ViewLayer *view_layer, Collection *collection, Object *ob)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:834
ListBaseT< Nurb > * BKE_curve_nurbs_get(Curve *cu)
Definition curve.cc:4992
@ BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT
void BKE_curve_type_test(Object *ob, bool dimension_update)
Definition curve.cc:476
void copy_m4_m3(float m1[4][4], const float m2[3][3])
bool BKE_where_on_path(const struct Object *ob, float ctime, float r_vec[4], float r_dir[3], float r_quat[4], float *r_radius, float *r_weight)
void BKE_object_update_select_id(Main *bmain)
Definition object.cc:5676
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
void BKE_shaderfx_blend_write(BlendWriter *writer, ListBaseT< ShaderFxData > *fxbase)
Definition shader_fx.cc:258
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
struct bConstraintOb * BKE_constraints_make_evalob(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, void *subdata, short datatype)
void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, MutableSpan< float3 > vert_positions)
Definition key.cc:1697
Volume * BKE_volume_add(Main *bmain, const char *name)
Object * BKE_object_add_for_data(Main *bmain, const Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name, ID *data, bool do_id_user) ATTR_RETURNS_NONNULL
Definition object.cc:2332
@ IDWALK_DO_DEPRECATED_POINTERS
void BKE_shaderfx_blend_read_data(BlendDataReader *reader, ListBaseT< ShaderFxData > *lb, Object *ob)
Definition shader_fx.cc:274
void BKE_object_free_particlesystems(Object *ob)
Definition object.cc:1311
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
void BKE_previewimg_blend_write(BlendWriter *writer, const PreviewImage *prv)
static void object_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition object.cc:792
static void object_lib_override_apply_post(ID *id_dst, ID *id_src)
Definition object.cc:1176
int BKE_object_is_modified(Scene *scene, Object *ob)
Definition object.cc:4932
static Object * obrel_armature_find(Object *ob)
Definition object.cc:5240
void BKE_nurbList_free(ListBaseT< Nurb > *lb)
Definition curve.cc:619
void BKE_object_eval_assign_data(Object *object, ID *data, bool is_owned)
Definition object.cc:1786
void BKE_lattice_transform(Lattice *lt, const float mat[4][4], bool do_keys)
Definition lattice.cc:645
float tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3])
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:818
Vector< Base * > BKE_view_layer_array_from_bases_in_mode_params(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d, const ObjectsInModeParams *params)
float normalize_qt(float q[4])
std::optional< Bounds< float3 > > BKE_lattice_minmax(const Lattice *lt)
Definition lattice.cc:625
void * BKE_object_obdata_add_from_type(Main *bmain, ObjectType type, const char *name) ATTR_NONNULL(1)
Definition object.cc:2185
PartEff * BKE_object_do_version_give_parteff_245(Object *ob)
Definition object.cc:1162
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve *cu, ListBaseT< Nurb > *nurb)
Definition key.cc:1658
@ eModifierType_ParticleSystem
@ eModifierType_MeshSequenceCache
@ eModifierType_DynamicPaint
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, FunctionRef< void(IDProperty *id_property)> callback)
void(*)(ID *id, const IDCacheKey *cache_key, void **cache_p, uint flags, void *user_data) IDTypeForeachCacheFunctionCallback
Vector< Base * > BKE_object_pose_base_array_get_ex(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d, bool unique)
Definition object.cc:2602
Object * BKE_modifiers_is_deformed_by_armature(Object *ob)
void void void BKE_modifiers_foreach_ID_link(Object *ob, IDWalkFunc walk, void *user_data)
IDTypeInfo IDType_ID_OB
Definition object.cc:1269
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
Definition object.cc:4477
void BKE_light_linking_delete(struct Object *object, const int delete_flags)
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void BKE_object_modifier_update_subframe_only_callback(Object *ob, bool update_mesh, int parent_recursion_limit, int modifier_type, FunctionRef< void(Object *object, bool update_mesh)> update_or_tag_fn)
Definition object.cc:5610
ID * BKE_id_copy_for_duplicate(Main *bmain, ID *id, eDupli_ID_Flags duplicate_flags, int copy_flags)
Definition lib_id.cc:861
struct ModifierData * object_copy_particle_system(struct Main *bmain, const struct Scene *scene, struct Object *ob, const struct ParticleSystem *psys_orig)
Lattice * BKE_object_get_evaluated_lattice(const Object *object)
Definition object.cc:4560
static KeyBlock * insert_curvekey(Main *bmain, Object *ob, const char *name, const bool from_mix)
Definition object.cc:4724
Curve * BKE_curve_add(Main *bmain, const char *name, ObjectType type)
Definition curve.cc:429
void BKE_modifier_blend_write(BlendWriter *writer, const ID *id_owner, ListBaseT< ModifierData > *modbase)
bool is_negative_m4(const float mat[4][4])
void BKE_pose_channels_hash_ensure(bPose *pose) ATTR_NONNULL(1)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
DispList * BKE_displist_find(ListBaseT< DispList > *lb, int type)
Definition displist.cc:75
bool invert_m4(float mat[4][4])
void BKE_particlesystem_id_loop(struct ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
void BKE_particle_partdeflect_blend_read_data(struct BlendDataReader *reader, struct PartDeflect *pd)
Definition particle.cc:315
void BKE_object_material_active_index_sanitize(Object *ob)
@ ID_REMAP_SKIP_USER_CLEAR
@ ID_REMAP_FORCE_OBDATA_IN_EDITMODE
void BKE_object_free_modifiers(Object *ob, int flag)
Definition object.cc:1337
int CustomData_get_layer_index(const CustomData *data, eCustomDataType type)
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
ATTR_WARN_UNUSED_RESULT const BMVert * v
bool BKE_animdata_id_is_animated(const ID *id)
Definition anim_data.cc:224
static Object * object_add_common(Main *bmain, const Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name)
Definition object.cc:2284
static void give_parvert(const Object *par, int nr, float vec[3], const bool use_evaluated_indices)
Definition object.cc:3275
void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob)
MatBase< float, 4, 4 > float4x4
std::optional< Bounds< float3 > > BKE_armature_min_max(const Object *ob)
Lattice * BKE_object_get_lattice(const Object *object)
Definition object.cc:4545
static bool ob_parcurve(const Object *ob, Object *par, float r_mat[4][4])
Definition object.cc:3182
LibraryForeachIDFlag BKE_lib_query_foreachid_process_flags_get(const LibraryForeachIDData *data)
Definition lib_query.cc:133
MovieClip * BKE_object_movieclip_get(Scene *scene, const Object *ob, bool use_default)
Definition object.cc:5154
static void object_foreach_cache(ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data)
Definition object.cc:648
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2890
void MEM_delete_void(void *vmemh)
static void object_foreach_working_space_color(ID *id, const IDTypeForeachColorFunctionCallback &fn)
Definition object.cc:672
void BKE_curve_texspace_ensure(Curve *cu)
Definition curve.cc:524
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
void BKE_object_delete_ptcache(Object *ob, int index)
Definition object.cc:4640
bool BKE_object_supports_modifiers(const Object *ob)
Definition object.cc:1449
GreasePencil * BKE_grease_pencil_add(Main *bmain, const char *name)
void BKE_object_protected_location_set(Object *ob, const float location[3])
Definition object.cc:4197
@ LIB_ID_CREATE_NO_USER_REFCOUNT
@ LIB_ID_COPY_NO_PREVIEW
@ LIB_ID_COPY_RIGID_BODY_NO_COLLECTION_HANDLING
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
@ LIB_ID_COPY_DEFAULT
@ LIB_ID_CREATE_NO_MAIN
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition object.cc:3663
MINLINE void mul_v3_fl(float r[3], float f)
void quat_to_compatible_eulO(float eul[3], const float oldrot[3], short order, const float quat[4])
void BKE_object_free_caches(Object *object)
Definition object.cc:1851
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
Definition anim_sys.cc:602
void void BLI_linklist_prepend(LinkNode **listp, void *ptr) ATTR_NONNULL(1)
void BKE_object_copy_softbody(Object *ob_dst, const Object *ob_src, int flag)
Definition object.cc:2361
ModifierData * BKE_object_active_modifier(const Object *ob)
Definition object.cc:1427
void BKE_lightprobe_cache_blend_read(struct BlendDataReader *reader, struct LightProbeObjectCache *cache)
static int pc_cmp(const void *a, const void *b)
Definition object.cc:4582
void BKE_particle_system_blend_write(struct BlendWriter *writer, ListBaseT< ParticleSystem > *particles)
Definition particle.cc:5593
@ G_DEBUG_DEPSGRAPH_EVAL
bool DEG_is_original(const T *id)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
void BKE_libblock_free_data(ID *id, bool do_id_user) ATTR_NONNULL()
static int pc_findindex(ListBaseT< LinkData > *listbase, int index)
Definition object.cc:4619
bool BKE_object_parent_loop_check(const Object *parent, const Object *ob)
Definition object.cc:4898
void BKE_object_obdata_size_init(Object *ob, float size)
Definition object.cc:2852
Global G
Definition blender.cc:57
MINLINE void sub_v3_v3(float r[3], const float a[3])
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
VecBase< float, 4 > float4
void BKE_ptcache_blend_read_data(struct BlendDataReader *reader, ListBaseT< PointCache > *ptcaches, struct PointCache **ocache, int force_disk)
void BKE_lib_query_foreachid_process(LibraryForeachIDData *data, ID **id_pp, LibraryForeachIDCallbackFlag cb_flag)
Definition lib_query.cc:82
void BKE_modifier_unique_name(ListBaseT< ModifierData > *modifiers, ModifierData *md)
@ LIB_ID_DUPLICATE_IS_SUBPROCESS
@ LIB_ID_DUPLICATE_IS_ROOT_ID
Collection * BKE_collection_object_find(Main *bmain, Scene *scene, Collection *collection, Object *ob)
void eulO_to_mat3(float M[3][3], const float e[3], short order)
ModifierData * BKE_modifier_copy_ex(const ModifierData *md, int flag)
void BKE_shaderfx_copydata_ex(ShaderFxData *fx, ShaderFxData *target, int flag)
Definition shader_fx.cc:189
KDTree< CoordT > * kdtree_new(uint nodes_len_capacity)
Definition BLI_kdtree.hh:65
void BKE_object_foreach_display_point(Object *ob, const float obmat[4][4], void(*func_cb)(const float[3], void *), void *user_data)
Definition object.cc:4033
void quat_to_mat3(float m[3][3], const float q[4])
SoftBody * sbCopy(struct SoftBody *sb, int flag)
Definition softbody.cc:3145
Object * BKE_object_pose_armature_get_with_wpaint_check(Object *ob)
Definition object.cc:2527
static bool object_modifier_recurse_for_update_subframe(const ObjectModifierUpdateContext &ctx, Object *ob, const bool update_mesh, const int parent_recursion_limit)
Definition object.cc:5541
static void object_foreach_path(ID *id, BPathForeachPathData *bpath_data)
Definition object.cc:579
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
bool BLO_read_data_is_undo(BlendDataReader *reader)
Definition readfile.cc:6819
Vector< Object * > BKE_object_pose_array_get_unique(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2587
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
float4 BKE_object_rot_to_quat(const Object &ob)
Definition object.cc:2994
void BKE_object_minmax(Object *ob, float3 &r_min, float3 &r_max)
Definition object.cc:3842
void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
static const char * get_obdata_defname(ObjectType type)
Definition object.cc:2118
void * MEM_dupalloc_void(const void *vmemh) ATTR_WARN_UNUSED_RESULT
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
void BKE_object_dimensions_set_ex(Object *ob, const float value[3], int axis_mask, const float ob_scale_orig[3], const float ob_obmat_orig[4][4])
Definition object.cc:3809
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_rigidbody_object_copy(struct Main *bmain, struct Object *ob_dst, const struct Object *ob_src, int flag)
void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *object)
Definition object.cc:5362
void BKE_object_protected_rotation_axisangle_set(Object *ob, const float axis[3], float angle)
Definition object.cc:4252
static void object_blend_read_data(BlendDataReader *reader, ID *id)
Definition object.cc:876
LinkNode * BKE_object_relational_superset(const Main &bmain, const Scene *scene, ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter)
Definition object.cc:5269
static void object_where_is_calc_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime, RigidBodyWorld *rbw, float r_originmat[3][3])
Definition object.cc:3510
void BKE_object_free_derived_caches(Object *ob)
Definition object.cc:1810
void BKE_pose_copy_data_ex(bPose **dst, const bPose *src, int flag, bool copy_constraints)
void BKE_object_scale_to_mat3(const Object *ob, float r_mat[3][3])
Definition object.cc:2899
bool BKE_nurbList_index_get_co(ListBaseT< Nurb > *nurb, int index, float r_co[3])
Definition curve.cc:533
Key * BKE_key_add(Main *bmain, ID *id)
Definition key.cc:228
Curve * BKE_object_to_curve(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
Definition object.cc:5710
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void copy_qt_qt(float q[4], const float a[4])
void BKE_object_to_mat4(const Object *ob, float r_mat[4][4])
Definition object.cc:3125
void DEG_id_tag_update(ID *id, unsigned int flags)
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_WEIGHT_GREASE_PENCIL
BMesh const char void * data
void BKE_object_materials_sync_length(Main *bmain, Object *ob, ID *id)
Curve * BKE_curve_new_from_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
Definition object.cc:1464
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
static Mutex vparent_lock
Definition object.cc:166
struct Camera * BKE_camera_add(struct Main *bmain, const char *name)
void BKE_modifiers_add_at_end_if_possible(Object *ob, ModifierData *new_md)
int BKE_object_is_deform_modified(Scene *scene, Object *ob)
Definition object.cc:5063
void object_duplilist(Depsgraph *depsgraph, Object *ob, Set< const Object * > *include_objects, DupliList &r_duplilist)
Vector< Object * > BKE_view_layer_array_from_objects_in_mode_params(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d, const ObjectsInModeParams *params)
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
Definition object.cc:2063
static void ob_parbone(const Object *ob, const Object *par, float r_mat[4][4])
Definition object.cc:3242
ModifierData * BKE_modifier_new(int type)
static KeyBlock * insert_lattkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
Definition object.cc:4686
void * BKE_object_tfm_backup(Object *ob)
Definition object.cc:4141
bool BKE_object_has_mode_data(const Object *ob, eObjectMode object_mode)
Definition object.cc:2023
Object * BKE_object_duplicate(Main *bmain, Object *ob, eDupli_ID_Flags dupflag, uint duplicate_options)
Definition object.cc:2659
void BKE_particle_system_blend_read_after_liblink(struct BlendLibReader *reader, struct Object *ob, struct ID *id, ListBaseT< ParticleSystem > *particles)
Definition particle.cc:5728
void BKE_grease_pencil_modifier_blend_read_data(struct BlendDataReader *reader, ListBaseT< GpencilModifierData > *lb, struct Object *ob)
void BKE_object_matrix_local_get(Object *ob, float r_mat[4][4])
Definition object.cc:3136
void psys_free(struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:1009
static void object_free_data(ID *id)
Definition object.cc:288
float4x4 BKE_object_delta_matrix_get(const Object &obj)
Definition object.cc:3150
void quat_to_eulO(float e[3], short order, const float q[4])
void BKE_lightprobe_cache_blend_write(struct BlendWriter *writer, struct LightProbeObjectCache *cache)
PointCloud * BKE_pointcloud_add(Main *bmain, const char *name)
void kdtree_insert(KDTree< CoordT > *tree, int index, const CoordT &co)
Definition BLI_kdtree.hh:96
static void library_foreach_gpencil_modifiersForeachIDLink(void *user_data, Object *, ID **id_pointer, const LibraryForeachIDCallbackFlag cb_flag)
Definition object.cc:351
void BKE_object_runtime_reset_on_copy(Object *object, int flag)
Definition object.cc:5207
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
BlendFileReadReport * BLO_read_lib_reports(BlendLibReader *reader)
Definition readfile.cc:6858
bool BKE_object_data_is_in_editmode(const Object *ob, const ID *id)
Definition object.cc:1932
bool BKE_object_shapekey_free(Main *bmain, Object *ob)
Definition object.cc:4802
void BKE_object_where_is_calc_mat4(const Object *ob, float r_obmat[4][4])
Definition object.cc:3560
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
void BKE_object_dimensions_get(const Object *ob, float r_vec[3])
Definition object.cc:3799
static void library_foreach_particlesystemsObjectLooper(ParticleSystem *, ID **id_pointer, void *user_data, const LibraryForeachIDCallbackFlag cb_flag)
Definition object.cc:383
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
void BKE_object_workob_clear(Object *workob)
Definition object.cc:1302
void void BKE_pose_blend_write(BlendWriter *writer, bPose *pose) ATTR_NONNULL(1
struct LightProbe * BKE_lightprobe_add(struct Main *bmain, const char *name)
void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
void invert_qt_normalized(float q[4])
KDTree< float3 > * BKE_object_as_kdtree(Object *ob, int *r_tot)
Definition object.cc:5377
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_displist_minmax(const ListBaseT< DispList > *dispbase, float min[3], float max[3])
Definition displist.cc:1741
VectorList< DupliObject > DupliList
Vector< Base * > BKE_object_pose_base_array_get_unique(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2633
void BKE_scene_foreach_display_point(Depsgraph *depsgraph, void(*func_cb)(const float[3], void *), void *user_data)
Definition object.cc:4103
static void object_blend_read_after_liblink(BlendLibReader *reader, ID *id)
Definition object.cc:1084
@ DAG_EVAL_VIEWPORT
void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
int BKE_constraint_targets_get(struct bConstraint *con, ListBaseT< bConstraintTarget > *r_targets)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
bool BKE_object_use_sculptsession(eObjectMode mode)
Definition object.cc:4328
void BKE_object_check_uids_unique_and_report(const Object *object)
Definition object.cc:5728
Vector< Object * > BKE_object_pose_array_get_ex(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d, bool unique)
Definition object.cc:2567
void unit_m4(float m[4][4])
void BKE_object_protected_scale_set(Object *ob, const float scale[3])
Definition object.cc:4210
bool CustomData_free_layer(CustomData *data, eCustomDataType type, int index)
static bool constructive_modifier_is_deform_modified(Object *ob, ModifierData *md)
Definition object.cc:4999
void BKE_pose_update_constraint_flags(Object &pose_ob)
void BKE_lightprobe_cache_free(struct Object *object)
static bool object_modifier_type_copy_check(ModifierType md_type)
Definition object.cc:1503
void BKE_ptcache_ids_from_object(ListBaseT< PTCacheID > *lb, struct Object *ob, struct Scene *scene, int duplis)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void BKE_rigidbody_free_object(struct Object *ob, struct RigidBodyWorld *rbw)
Definition rigidbody.cc:166
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void BKE_shaderfx_free_ex(ShaderFxData *fx, int flag)
Definition shader_fx.cc:93
void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition readfile.cc:237
void BKE_object_modifier_update_subframe(Depsgraph *depsgraph, Scene *scene, Object *ob, bool update_mesh, int parent_recursion_limit, float frame, int modifier_type)
Definition object.cc:5624
void multiresModifier_sync_levels_ex(Object *ob_dst, const MultiresModifierData *mmd_src, MultiresModifierData *mmd_dst)
Definition multires.cc:620
void BKE_object_protected_rotation_quaternion_set(Object *ob, const float quat[4])
Definition object.cc:4223
KeyBlock * BKE_object_shapekey_insert(Main *bmain, Object *ob, const char *name, bool from_mix)
Definition object.cc:4770
MINLINE void zero_v3(float r[3])
void quat_apply_track(float quat[4], short axis, short upflag)
void BKE_id_free(Main *bmain, void *idv)
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
Mesh * BKE_object_get_evaluated_mesh_unchecked(const Object *object)
Definition object.cc:4427
void BKE_constraint_blend_read_data(struct BlendDataReader *reader, struct ID *id_owner, ListBaseT< bConstraint > *lb)
void BKE_object_quat_to_rot(Object &ob, const float4 &quat)
Definition object.cc:3010
void BKE_object_free_curve_cache(Object *ob)
Definition object.cc:1323
@ eModifierTypeFlag_AcceptsGreasePencil
@ eModifierTypeFlag_AcceptsCVs
@ eModifierTypeFlag_AcceptsMesh
@ eModifierTypeFlag_Single
@ eModifierTypeFlag_AcceptsVertexCosOnly
int BKE_object_obdata_to_type(const ID *id) ATTR_NONNULL(1)
Definition object.cc:2230
void BKE_mesh_ensure_skin_customdata(Mesh *mesh)
bool BLO_read_array(BlendDataReader *reader, T **ptr_p, const SizeT array_size, const int elems=1)
static void library_foreach_constraintObjectLooper(bConstraint *, ID **id_pointer, bool is_reference, void *user_data)
Definition object.cc:372
void BKE_object_protected_rotation_euler_set(Object *ob, const float euler[3])
Definition object.cc:4239
char * BKE_object_data_editmode_flush_ptr_get(ID *id)
Definition object.cc:1961
static void object_foreach_id(ID *id, LibraryForeachIDData *data)
Definition object.cc:393
void BKE_object_tfm_restore(Object *ob, void *obtfm_pt)
Definition object.cc:4164
void BKE_grease_pencil_modifier_free_ex(struct GpencilModifierData *md, int flag)
void void BLI_listbase_sort(ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
Definition listbase.cc:319
@ OB_PARENT_USE_FINAL_INDICES
void BKE_view_layer_base_deselect_all(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
static float3 boundbox_to_dimensions(const Object *ob, const std::optional< Bounds< float3 > > bounds)
Definition object.cc:3790
void project_plane_v3_v3v3(float out[3], const float p[3], const float v_plane[3])
void BKE_partdeflect_free(struct PartDeflect *pd)
Definition effect.cc:126
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
Definition object.cc:2648
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
Main * BLO_read_lib_get_main(BlendLibReader *reader)
Definition readfile.cc:6853
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
bool BKE_object_minmax_empty_drawtype(const Object *ob, float r_min[3], float r_max[3])
Definition object.cc:3934
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:2097
void BKE_animsys_evaluate_animdata(ID *id, AnimData *adt, const AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, bool flush_to_original)
Definition anim_sys.cc:3716
static KeyBlock * insert_meshkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
Definition object.cc:4654
static void object_foreach_path_particles(Object *ob, BPathForeachPathData *bpath_data)
Definition object.cc:523
void BKE_modifier_free_ex(ModifierData *md, int flag)
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys)
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
Definition BKE_bpath.hh:49
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
int BKE_object_scenes_users_get(Main *bmain, Object *ob)
Definition object.cc:5143
static void object_cacheIgnoreClear(Object *ob, const bool state)
Definition object.cc:5507
MINLINE void add_v3_v3(float r[3], const float a[3])
void BKE_previewimg_id_copy(ID *new_id, const ID *old_id)
void BKE_keyblock_convert_from_lattice(const Lattice *lt, KeyBlock *kb)
Definition key.cc:1493
std::optional< Bounds< float3 > > BKE_object_evaluated_geometry_bounds(const Object *ob)
Definition object.cc:3766
void BKE_object_free_shaderfx(Object *ob, int flag)
Definition object.cc:1358
static void ob_parvert3(const Object *ob, const Object *par, float r_mat[4][4])
Definition object.cc:3397
bool BKE_object_shapekey_remove(Main *bmain, Object *ob, KeyBlock *kb)
Definition object.cc:4819
static void object_update_from_subsurf_ccg(Object *object)
Definition object.cc:1709
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_object_mat3_to_rot(Object *ob, float r_mat[3][3], bool use_compat)
Definition object.cc:2946
void BKE_object_handle_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition object.cc:4323
T * DEG_get_original(T *id)
Light * BKE_light_add(Main *bmain, const char *name) ATTR_WARN_UNUSED_RESULT
bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us)
float4x4 BKE_object_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition object.cc:3583
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
bool BKE_bpath_foreach_path_fixed_process(BPathForeachPathData *bpath_data, char *path, size_t path_maxncpy)
Definition bpath.cc:130
void BKE_pose_backup_clear(struct Object *ob)
@ OB_REL_CHILDREN
@ OB_REL_PARENT_RECURSIVE
@ OB_REL_CHILDREN_RECURSIVE
@ OB_REL_MOD_ARMATURE
@ OB_REL_PARENT
void BKE_object_replace_data_on_shallow_copy(Object *ob, ID *new_data)
Definition object.cc:5748
ModifierData * BKE_object_copy_modifier(Main *bmain, const Scene *scene, Object *ob_dst, const Object *ob_src, const ModifierData *md)
Definition object.cc:1542
Mesh * BKE_object_to_mesh(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
Definition object.cc:5692
ATTR_WARN_UNUSED_RESULT const BMVert * v2
bool BKE_object_flag_test_recursive(const Object *ob, short flag)
Definition object.cc:4910
void void void void BKE_pose_blend_read_after_liblink(BlendLibReader *reader, Object *ob, bPose *pose) ATTR_NONNULL(1
bool BKE_object_obdata_texspace_get(Object *ob, char **r_texspace_flag, float **r_texspace_location, float **r_texspace_size)
Definition object.cc:4344
@ INDEX_ID_OB
Definition DNA_ID.h:1341
void void void BKE_pose_blend_read_data(BlendDataReader *reader, ID *id_owner, bPose *pose) ATTR_NONNULL(1
void BKE_constraints_clear_evalob(struct bConstraintOb *cob)
static AssetTypeInfo AssetType_OB
Definition object.cc:1263
static bool object_moves_in_time(const Object *object)
Definition object.cc:4983
void BKE_object_to_mat3(const Object *ob, float r_mat[3][3])
Definition object.cc:3112
void BKE_object_where_is_calc_ex(Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
Definition object.cc:3571
bool multiresModifier_reshapeFromCCG(int tot_level, Mesh *coarse_mesh, SubdivCCG *subdiv_ccg)
MetaBall * BKE_mball_add(Main *bmain, const char *name)
Definition mball.cc:173
void eulO_to_quat(float q[4], const float e[3], short order)
static void solve_parenting(const Object *ob, Object *par, const bool set_origin, float r_obmat[4][4], float r_originmat[3][3])
Definition object.cc:3476
void mul_m4_m4_post(float R[4][4], const float B[4][4])
std::mutex Mutex
Definition BLI_mutex.hh:51
LinkNode * BKE_object_groups(Main *bmain, Scene *scene, Object *ob)
Definition object.cc:5351
float * BKE_key_evaluate_object(Object *ob, int *r_totelem)
Definition key.cc:1137
@ ID_RECALC_ALL
Definition DNA_ID.h:1190
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_PSYS_REDO
Definition DNA_ID.h:1081
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_EDITORS
Definition DNA_ID.h:1111
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
ID_Type GS(const char *name)
Definition DNA_ID.h:410
bool BKE_object_is_in_wpaint_select_vert(const Object *ob)
Definition object.cc:2012
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
std::optional< Bounds< float3 > > BKE_object_boundbox_eval_cached_get(const Object *ob)
Definition object.cc:3758
Object * BKE_object_pose_armature_get_visible(const Main &bmain, Object *ob, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2551
bool BKE_object_minmax_dupli(Depsgraph *depsgraph, Object *ob, float3 &r_min, float3 &r_max, bool use_hidden)
Definition object.cc:3999
@ OB_EMPTY_IMAGE_HIDE_FRONT
@ OB_EMPTY_IMAGE_HIDE_BACK
@ OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC
@ OB_EMPTY_IMAGE_HIDE_PERSPECTIVE
@ OB_EMPTY_IMAGE_HIDE_NON_AXIS_ALIGNED
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
@ ID_TAG_NO_MAIN
Definition DNA_ID.h:981
@ ID_TAG_INDIRECT
Definition DNA_ID.h:851
@ ID_TAG_COPIED_ON_EVAL
Definition DNA_ID.h:1000
@ ID_TAG_EXTERN
Definition DNA_ID.h:845
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
@ ID_TAG_NEW
Definition DNA_ID.h:922
Object * BKE_object_add_from(Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name, Object *ob_src) ATTR_NONNULL(1
Definition object.cc:2315
void sbFree(struct Object *ob)
Definition softbody.cc:3120
Span< float3 > BKE_mesh_wrapper_vert_coords(const Mesh *mesh)
bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
Definition object.cc:4922
static void object_init(Object *ob, const ObjectType ob_type)
Definition object.cc:2159
void psys_copy_particles(struct ParticleSystem *psys_dst, struct ParticleSystem *psys_src)
Definition particle.cc:1087
bool BKE_object_supports_material_slots(Object *ob)
Definition object.cc:5182
struct PointCache * BKE_ptcache_copy_list(ListBaseT< PointCache > *ptcaches_new, const ListBaseT< PointCache > *ptcaches_old, int flag)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
struct Speaker * BKE_speaker_add(struct Main *bmain, const char *name)
Definition speaker.cc:82
static CLG_LogRef LOG
Definition logging.cpp:12
static void library_foreach_shaderfxForeachIDLink(void *user_data, Object *, ID **id_pointer, const LibraryForeachIDCallbackFlag cb_flag)
Definition object.cc:362
void BKE_object_get_mirror_axes(const Object *ob, bool r_axis[3])
Definition object.cc:5115
bool BLO_read_lib_is_undo(BlendLibReader *reader)
Definition readfile.cc:6848
void size_to_mat3(float R[3][3], const float size[3])
void BKE_particle_system_blend_read_data(struct BlendDataReader *reader, ListBaseT< ParticleSystem > *particles)
Definition particle.cc:5637
void BKE_ptcache_blend_write(struct BlendWriter *writer, ListBaseT< PointCache > *ptcaches)
void CustomData_copy_layer_type_data(const CustomData *source, CustomData *destination, eCustomDataType type, int source_index, int destination_index, int count)
Mesh * BKE_mesh_new_from_object(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers, bool preserve_origindex, bool ensure_subdivision)
std::optional< Bounds< float3 > > BKE_object_boundbox_get(const Object *ob)
Definition object.cc:3726
MINLINE void copy_v4_v4(float r[4], const float a[4])
void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime)
static void copy_ccg_data(Mesh *mesh_dst, Mesh *mesh_src, const eCustomDataType layer_type)
Definition object.cc:1692
Mesh * BKE_object_get_original_mesh(const Object *object)
Definition object.cc:4461
void BKE_crazyspace_api_eval_clear(Object *object)
void BKE_constraints_free_ex(ListBaseT< bConstraint > *list, bool do_id_user)
void BKE_libblock_free_datablock(ID *id, int flag) ATTR_NONNULL()
bool BKE_collection_has_object_recursive(Collection *collection, Object *ob)
ParticleSystem * BKE_object_copy_particlesystem(ParticleSystem *psys, int flag)
Definition object.cc:2374
void BKE_grease_pencil_modifiers_foreach_ID_link(struct Object *ob, GreasePencilIDWalkFunc walk, void *user_data)
KeyBlock * BKE_keyblock_add_ctime(Key *key, const char *name, bool do_force)
Definition key.cc:1380
bool BKE_object_modifier_stack_copy(Object *ob_dst, const Object *ob_src, bool do_copy_all, int flag_subdata)
Definition object.cc:1647
static void object_init_data(ID *id)
Definition object.cc:176
void BKE_constraints_id_loop(ListBaseT< bConstraint > *list, ConstraintIDFunc func, const int flag, void *userdata)
bool BKE_animdata_drivers_remove_for_rna_struct(ID &owner_id, struct StructRNA &type, void *data)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition object.cc:3577
std::optional< Bounds< float3 > > BKE_curve_minmax(const Curve *cu, bool use_radius)
Definition curve.cc:5131
void BKE_object_dimensions_set(Object *ob, const float value[3], int axis_mask)
Definition object.cc:3837
LibraryForeachIDCallbackFlag
@ IDWALK_CB_OVERRIDE_LIBRARY_HIERARCHY_DEFAULT
@ IDWALK_CB_NEVER_NULL
@ IDWALK_CB_NEVER_SELF
VecBase< float, 3 > float3
@ ME_WRAPPER_TYPE_BMESH
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
Definition object.cc:2265
void scale_m4_fl(float R[4][4], float scale)
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1311
static bool obrel_list_test(Object *ob)
Definition object.cc:5258
Mesh * BKE_mesh_add(Main *bmain, const char *name)
void BKE_object_modifier_set_active(Object *ob, ModifierData *md)
Definition object.cc:1415
bool BKE_modifiers_persistent_uids_are_valid(const Object &object)
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:968
bool BKE_object_is_libdata(const Object *ob)
Definition object.cc:2840
void BKE_keyblock_convert_to_lattice(const KeyBlock *kb, Lattice *lt)
Definition key.cc:1517
static ParticleSystem * object_copy_modifier_particle_system_ensure(Main *bmain, const Scene *scene, Object *ob_dst, ParticleSystem *psys_src)
Definition object.cc:1517
MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
void BKE_object_modifier_gpencil_hook_reset(Object *ob, HookGpencilModifierData *hmd)
Definition object.cc:1390
static bool object_deforms_in_time(Object *object)
Definition object.cc:4988
bool BKE_object_exists_check(Main *bmain, const Object *obtest)
Definition object.cc:2101
void BKE_object_link_modifiers(Object *ob_dst, const Object *ob_src)
Definition object.cc:1682
@ OB_SET_VISIBLE
@ OB_SET_SELECTED
void BKE_object_dimensions_eval_cached_get(const Object *ob, float r_vec[3])
Definition object.cc:3804
static void object_asset_metadata_ensure(void *asset_ptr, AssetMetaData *asset_data)
Definition object.cc:1252
void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd)
Definition object.cc:1365
void BKE_object_tfm_free(void *obtfm_pt)
Definition object.cc:4185
bool DEG_object_geometry_is_evaluated(const Object &object)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
void BKE_keyblock_convert_from_mesh(const Mesh *mesh, const Key *key, KeyBlock *kb)
Definition key.cc:1681
bool BKE_object_is_mode_compat(const Object *ob, eObjectMode object_mode)
Definition object.cc:2058
void BKE_constraint_blend_write(struct BlendWriter *writer, ListBaseT< bConstraint > *conlist)
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
Definition effect.cc:63
void BKE_object_to_curve_clear(Object *object)
Definition object.cc:5719
Vector< Object * > BKE_object_pose_array_get(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2594
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
LightProbeObjectCache * BKE_lightprobe_cache_copy(LightProbeObjectCache *src_cache)
Mesh * BKE_object_get_evaluated_mesh_no_subsurf(const Object *object_eval)
Definition object.cc:4419
void id_us_min(ID *id)
Definition lib_id.cc:441
static bool modifiers_has_animation_check(const Object *ob)
Definition object.cc:5039
Mesh * BKE_mesh_wrapper_ensure_subdivision(Mesh *mesh)
float DEG_get_ctime(const Depsgraph *graph)
Lattice * BKE_lattice_add(Main *bmain, const char *name)
Definition lattice.cc:392
void BKE_pose_check_uids_unique_and_report(const bPose *pose)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
MINLINE void zero_v2(float r[2])
void orthogonalize_m4_stable(float R[4][4], int axis, bool normalize)
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
void * BKE_libblock_alloc(Main *bmain, short type, const char *name, int flag) ATTR_WARN_UNUSED_RESULT
Definition lib_id.cc:1545
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
@ OB_VISIBLE_PARTICLES
@ OB_VISIBLE_SELF
@ OB_VISIBLE_INSTANCES
@ IDP_TYPE_FILTER_ID
void BKE_object_tfm_protected_restore(Object *ob, const ObjectTfmProtectedChannels *obtfm, short protectflag)
Definition object.cc:3050
const char * BKE_main_blendfile_path_from_library(const Library &library)
Definition main.cc:1068
void BKE_keyblock_convert_from_curve(const Curve *cu, KeyBlock *kb, const ListBaseT< Nurb > *nurb)
Definition key.cc:1615
int BKE_nurbList_verts_count_without_handles(const ListBaseT< Nurb > *nurb)
Definition curve.cc:575
const Mesh * BKE_object_get_mesh_deform_eval(const Object *object)
Definition object.cc:4519
void BKE_rigidbody_free_constraint(struct Object *ob)
Definition rigidbody.cc:217
void BKE_object_apply_mat4_ex(Object *ob, const float mat[4][4], Object *parent, const float parentinv[4][4], bool use_compat)
Definition object.cc:3620
bool BKE_object_obdata_is_libdata(const Object *ob)
Definition object.cc:2845
void BKE_curve_bevelList_free(ListBaseT< BevList > *bev)
Definition curve.cc:2544
void quat_to_mat4(float m[4][4], const float q[4])
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Definition object.cc:4436
static void library_foreach_modifiersForeachIDLink(void *user_data, Object *, ID **id_pointer, const LibraryForeachIDCallbackFlag cb_flag)
Definition object.cc:341
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
void BKE_object_handle_update_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, RigidBodyWorld *rbw)
Definition object.cc:4276
void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, int flag)
Definition object.cc:2426
void BKE_object_to_mesh_clear(Object *object)
Definition object.cc:5701
static void copy_object_pose(Object *obn, const Object *ob, const int flag)
Definition object.cc:2470
const ShaderFxTypeInfo * BKE_shaderfx_get_info(ShaderFxType type)
Definition shader_fx.cc:134
float normalize_qt_qt(float r[4], const float q[4])
bool BKE_object_pose_context_check(const Object *ob)
Definition object.cc:2498
#define TFMCPY4D(_v)
#define TFMCPY3D(_v)
#define TFMCPY(_v)
const btScalar eps
Definition poly34.cpp:11
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
ListBaseT< FCurve > drivers
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
struct Object * object
struct blender::BlendFileReadReport::@140003175311343306107257242277261221002217304000 count
void write_pointer_array(int64_t num, const void *data)
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
void write_char_array(int64_t num, const char *data)
void write_struct_list(const ListBaseT< T > *list, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
bool is_undo() const
struct PointCache * point_cache
struct ListBaseT< PointCache > ptcaches
ListBaseT< Nurb > deformed_nurbs
Definition BKE_curve.hh:46
ListBaseT< BevList > bev
Definition BKE_curve.hh:45
const float * anim_path_accum_length
Definition BKE_curve.hh:53
ListBaseT< DispList > disp
Definition BKE_curve.hh:44
ListBaseT< Nurb > nurb
float texspace_location[3]
struct AnimData * adt
struct Object * taperobj
struct Key * key
struct DynamicPaintBrushSettings * brush
struct DynamicPaintCanvasSettings * canvas
struct Lattice * latt
struct ParticleSystem * psys
struct FluidFlowSettings * flow
struct FluidDomainSettings * domain
struct FluidsimSettings * fss
unsigned int id_session_uid
Definition BKE_idtype.hh:78
ListBaseT< struct IDProperty > group
Definition DNA_ID.h:133
eIDPropertyType type
Definition DNA_ID.h:145
IDPropertyData data
Definition DNA_ID.h:157
char name[258]
Definition DNA_ID.h:433
bke::id::ID_Runtime * runtime
Definition DNA_ID.h:541
struct ID * newid
Definition DNA_ID.h:419
struct Library * lib
Definition DNA_ID.h:421
void * next
Definition DNA_ID.h:418
unsigned int recalc
Definition DNA_ID.h:446
void * py_instance
Definition DNA_ID.h:519
eImageUser_Flag flag
KeyBlock * refkey
ListBaseT< KeyBlock > block
ShapekeyContainerType type
struct EditLatt * editlatt
struct BPoint * def
struct Collection * collection
char filepath[1024]
Definition DNA_ID.h:562
struct LinkData * next
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
const c_style_mat & ptr() const
bke::MeshRuntime * runtime
CustomData corner_data
CustomData vert_data
struct ModifierData * next
struct ModifierData * prev
struct IDProperty * system_properties
void(*) modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
void(*) foreach_working_space_color(ModifierData *md, const IDTypeForeachColorFunctionCallback &fn)
struct NodesModifierSettings settings_legacy
BezTriple * bezt
struct Nurb * next
struct Object * parent
float parentinv[4][4]
float parentinv[4][4]
Definition object.cc:4136
float obmat[4][4]
Definition object.cc:4135
float drotAxis[3]
Definition object.cc:4133
float imat[4][4]
Definition object.cc:4138
float constinv[4][4]
Definition object.cc:4137
FunctionRef< void(Object *object, bool update_mesh)> update_or_tag_fn
Definition object.cc:5530
struct PartDeflect * pd
struct Object * parent
ListBaseT< ModifierData > modifiers
ListBaseT< struct ObHook > hooks
float parentinv[4][4]
eObject_DrawExtraFlag dtx
struct PreviewImage * preview
ListBaseT< ShaderFxData > shader_fx
ListBaseT< bFaceMap > fmaps
bke::ObjectRuntime * runtime
struct LightProbeObjectCache * lightprobe_cache
LightLinking * light_linking
ListBaseT< GpencilModifierData > greasepencil_modifiers
ListBaseT< struct ParticleSystem > particlesystem
eObject_VisibilityFlag visibility_flag
bAnimVizSettings avs
float parent_bone_head_tail_factor
eObject_Partype partype
ListBaseT< Effect > effect
ListBaseT< bConstraint > constraints
ListBaseT< bDeformGroup > defbase
bMotionPath * mpath
eObject_Axis upflag
struct AnimData * adt
ListBaseT< LinkData > pc_ids
eObject_EmptyImageVisibilityFlag empty_image_visibility_flag
eObject_Axis trackflag
eObject_EmptyDrawType empty_drawtype
struct RigidBodyOb * rigidbody_object
eObject_TransFlag transflag
eObject_ProtectFlag protectflag
DNA_DEPRECATED struct Object * proxy_from
struct bPose * pose
eObject_DuplicatorVisibilityFlag duplicator_visibility_flag
struct LightgroupMembership * lightgroup
struct Material ** mat
struct RigidBodyCon * rigidbody_constraint
struct SoftBody * soft
unsigned int max_step
unsigned int default_step
struct PTCacheID * next
unsigned int file_type
ListBaseT< PointCache > * ptcaches
unsigned int info_types
unsigned int data_types
struct Collection * group
struct PartEff * next
ListBaseT< LinkData > pathcachebufs
struct ParticleDrawData * pdd
ListBaseT< LinkData > childcachebufs
draw::ParticleBatchCache * batch_cache
struct ClothModifierData * clmd
struct PTCacheEdit * edit
ListBaseT< ParticleTarget > targets
struct ListBaseT< struct EffectorCache > * effectors
ListBaseT< PointCache > ptcaches
struct ParticleCacheKey ** childcache
struct ParticleCacheKey ** pathcache
eParticleSystem_Flag flag
struct PointCache * pointcache
struct PointCache * next
struct RigidBodyOb_Shared * shared
struct Collection * master_collection
struct MovieClip * clip
struct RigidBodyWorld * rigidbody_world
void(*) foreach_working_space_color(ShaderFxData *fx, const IDTypeForeachColorFunctionCallback &func)
ListBaseT< PointCache > ptcaches
struct EffectorWeights * effector_weights
struct SoftBody_Shared * shared
struct SBScratch * scratch
DNA_DEPRECATED struct PointCache * pointcache
struct BodyPoint * bpoint
ListBaseT< PointCache > ptcaches
struct BodySpring * bspring
struct blender::SubdivCCG::@356361271106267377043074237104234372210112141040 dirty
struct AnimData * adt
struct bConstraint * next
ListBaseT< struct bConstraint > constraints
ListBaseT< bPoseChannel > chanbase
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
const Mesh * get_mesh() const
GeometryComponentPtr mesh_deform
GeometryComponentPtr mesh_cage
std::unique_ptr< EditMeshData > edit_data
std::unique_ptr< SubdivCCG > subdiv_ccg
eMeshWrapperType wrapper_type
Array< float3x3, 0 > crazyspace_deform_imats
std::optional< Bounds< float3 > > bounds_eval
Array< float3, 0 > crazyspace_deform_cos
#define N_(msgid)