Blender  V3.3
object.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 /* Allow using deprecated functionality for .blend file I/O. */
9 #define DNA_DEPRECATED_ALLOW
10 
11 #include <cmath>
12 #include <cstdio>
13 #include <cstring>
14 
15 #include "CLG_log.h"
16 
17 #include "MEM_guardedalloc.h"
18 
19 #include "DNA_anim_types.h"
20 #include "DNA_armature_types.h"
21 #include "DNA_camera_types.h"
22 #include "DNA_collection_types.h"
23 #include "DNA_constraint_types.h"
24 #include "DNA_defaults.h"
25 #include "DNA_dynamicpaint_types.h"
26 #include "DNA_effect_types.h"
27 #include "DNA_fluid_types.h"
29 #include "DNA_gpencil_types.h"
30 #include "DNA_key_types.h"
31 #include "DNA_lattice_types.h"
32 #include "DNA_light_types.h"
33 #include "DNA_lightprobe_types.h"
34 #include "DNA_material_types.h"
35 #include "DNA_mesh_types.h"
36 #include "DNA_meshdata_types.h"
37 #include "DNA_meta_types.h"
38 #include "DNA_movieclip_types.h"
39 #include "DNA_nla_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_pointcloud_types.h"
43 #include "DNA_rigidbody_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_sequence_types.h"
47 #include "DNA_shader_fx_types.h"
48 #include "DNA_space_types.h"
49 #include "DNA_view3d_types.h"
50 #include "DNA_world_types.h"
51 
52 #include "BLI_blenlib.h"
53 #include "BLI_kdtree.h"
54 #include "BLI_linklist.h"
55 #include "BLI_listbase.h"
56 #include "BLI_math.h"
57 #include "BLI_math_vec_types.hh"
58 #include "BLI_threads.h"
59 #include "BLI_utildefines.h"
60 
61 #include "BLT_translation.h"
62 
63 #include "BKE_DerivedMesh.h"
64 #include "BKE_action.h"
65 #include "BKE_anim_data.h"
66 #include "BKE_anim_path.h"
67 #include "BKE_anim_visualization.h"
68 #include "BKE_animsys.h"
69 #include "BKE_armature.h"
70 #include "BKE_asset.h"
71 #include "BKE_bpath.h"
72 #include "BKE_camera.h"
73 #include "BKE_collection.h"
74 #include "BKE_constraint.h"
75 #include "BKE_crazyspace.h"
76 #include "BKE_curve.h"
77 #include "BKE_curves.hh"
78 #include "BKE_deform.h"
79 #include "BKE_displist.h"
80 #include "BKE_duplilist.h"
81 #include "BKE_editmesh.h"
82 #include "BKE_editmesh_cache.h"
83 #include "BKE_effect.h"
84 #include "BKE_fcurve.h"
85 #include "BKE_fcurve_driver.h"
86 #include "BKE_geometry_set.h"
87 #include "BKE_geometry_set.hh"
88 #include "BKE_global.h"
89 #include "BKE_gpencil.h"
90 #include "BKE_gpencil_geom.h"
91 #include "BKE_gpencil_modifier.h"
92 #include "BKE_icons.h"
93 #include "BKE_idprop.h"
94 #include "BKE_idtype.h"
95 #include "BKE_image.h"
96 #include "BKE_key.h"
97 #include "BKE_lattice.h"
98 #include "BKE_layer.h"
99 #include "BKE_lib_id.h"
100 #include "BKE_lib_query.h"
101 #include "BKE_lib_remap.h"
102 #include "BKE_light.h"
103 #include "BKE_lightprobe.h"
104 #include "BKE_linestyle.h"
105 #include "BKE_main.h"
106 #include "BKE_material.h"
107 #include "BKE_mball.h"
108 #include "BKE_mesh.h"
109 #include "BKE_mesh_wrapper.h"
110 #include "BKE_modifier.h"
111 #include "BKE_multires.h"
112 #include "BKE_node.h"
113 #include "BKE_object.h"
114 #include "BKE_object_facemap.h"
115 #include "BKE_paint.h"
116 #include "BKE_particle.h"
117 #include "BKE_pbvh.h"
118 #include "BKE_pointcache.h"
119 #include "BKE_pointcloud.h"
120 #include "BKE_rigidbody.h"
121 #include "BKE_scene.h"
122 #include "BKE_shader_fx.h"
123 #include "BKE_softbody.h"
124 #include "BKE_speaker.h"
125 #include "BKE_subdiv_ccg.h"
126 #include "BKE_subsurf.h"
127 #include "BKE_vfont.h"
128 #include "BKE_volume.h"
129 
130 #include "DEG_depsgraph.h"
131 #include "DEG_depsgraph_query.h"
132 
133 #include "DRW_engine.h"
134 
135 #include "BLO_read_write.h"
136 #include "BLO_readfile.h"
137 
138 #include "SEQ_sequencer.h"
139 
140 #ifdef WITH_PYTHON
141 # include "BPY_extern.h"
142 #endif
143 
144 #include "CCGSubSurf.h"
145 #include "atomic_ops.h"
146 
147 using blender::float3;
148 
149 static CLG_LogRef LOG = {"bke.object"};
150 
157 #define VPARENT_THREADING_HACK
158 
159 #ifdef VPARENT_THREADING_HACK
161 #endif
162 
163 static void copy_object_pose(Object *obn, const Object *ob, const int flag);
164 
165 static void object_init_data(ID *id)
166 {
167  Object *ob = (Object *)id;
169 
171 
172  ob->type = OB_EMPTY;
173 
174  ob->trackflag = OB_POSY;
175  ob->upflag = OB_POSZ;
176 
177  /* Animation Visualization defaults */
179 }
180 
181 static void object_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
182 {
183  Object *ob_dst = (Object *)id_dst;
184  const Object *ob_src = (const Object *)id_src;
185 
186  /* Do not copy runtime data. */
187  BKE_object_runtime_reset_on_copy(ob_dst, flag);
188 
189  /* We never handle usercount here for own data. */
190  const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
191 
192  if (ob_src->totcol) {
193  ob_dst->mat = (Material **)MEM_dupallocN(ob_src->mat);
194  ob_dst->matbits = (char *)MEM_dupallocN(ob_src->matbits);
195  ob_dst->totcol = ob_src->totcol;
196  }
197  else if (ob_dst->mat != nullptr || ob_dst->matbits != nullptr) {
198  /* This shall not be needed, but better be safe than sorry. */
200  0, "Object copy: non-nullptr material pointers with zero counter, should not happen.");
201  ob_dst->mat = nullptr;
202  ob_dst->matbits = nullptr;
203  }
204 
205  if (ob_src->iuser) {
206  ob_dst->iuser = (ImageUser *)MEM_dupallocN(ob_src->iuser);
207  }
208 
209  if (ob_src->runtime.bb) {
210  ob_dst->runtime.bb = (BoundBox *)MEM_dupallocN(ob_src->runtime.bb);
211  }
212 
213  BLI_listbase_clear(&ob_dst->shader_fx);
214  LISTBASE_FOREACH (ShaderFxData *, fx, &ob_src->shader_fx) {
215  ShaderFxData *nfx = BKE_shaderfx_new(fx->type);
216  BLI_strncpy(nfx->name, fx->name, sizeof(nfx->name));
217  BKE_shaderfx_copydata_ex(fx, nfx, flag_subdata);
218  BLI_addtail(&ob_dst->shader_fx, nfx);
219  }
220 
221  if (ob_src->pose) {
222  copy_object_pose(ob_dst, ob_src, flag_subdata);
223  /* backwards compat... non-armatures can get poses in older files? */
224  if (ob_src->type == OB_ARMATURE) {
225  const bool do_pose_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
226  BKE_pose_rebuild(bmain, ob_dst, (bArmature *)ob_dst->data, do_pose_id_user);
227  }
228  }
229 
230  BKE_object_facemap_copy_list(&ob_dst->fmaps, &ob_src->fmaps);
231  BKE_constraints_copy_ex(&ob_dst->constraints, &ob_src->constraints, flag_subdata, true);
232 
233  ob_dst->mode = ob_dst->type != OB_GPENCIL ? OB_MODE_OBJECT : ob_dst->mode;
234  ob_dst->sculpt = nullptr;
235 
236  if (ob_src->pd) {
237  ob_dst->pd = (PartDeflect *)MEM_dupallocN(ob_src->pd);
238  if (ob_dst->pd->rng) {
239  ob_dst->pd->rng = (RNG *)MEM_dupallocN(ob_src->pd->rng);
240  }
241  }
242  BKE_rigidbody_object_copy(bmain, ob_dst, ob_src, flag_subdata);
243 
244  BLI_listbase_clear(&ob_dst->modifiers);
246  /* NOTE: Also takes care of softbody and particle systems copying. */
247  BKE_object_modifier_stack_copy(ob_dst, ob_src, true, flag_subdata);
248 
249  BLI_listbase_clear((ListBase *)&ob_dst->drawdata);
250  BLI_listbase_clear(&ob_dst->pc_ids);
251 
252  ob_dst->avs = ob_src->avs;
253  ob_dst->mpath = animviz_copy_motionpath(ob_src->mpath);
254 
255  /* Do not copy object's preview
256  * (mostly due to the fact renderers create temp copy of objects). */
257  if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO: temp hack. */
258  BKE_previewimg_id_copy(&ob_dst->id, &ob_src->id);
259  }
260  else {
261  ob_dst->preview = nullptr;
262  }
263 
264  if (ob_src->lightgroup) {
266  }
267 }
268 
269 static void object_free_data(ID *id)
270 {
271  Object *ob = (Object *)id;
272 
273  DRW_drawdata_free((ID *)ob);
274 
275  /* BKE_<id>_free shall never touch to ID->us. Never ever. */
278 
279  MEM_SAFE_FREE(ob->mat);
280  MEM_SAFE_FREE(ob->matbits);
281  MEM_SAFE_FREE(ob->iuser);
282  MEM_SAFE_FREE(ob->runtime.bb);
283 
284  BLI_freelistN(&ob->fmaps);
285  if (ob->pose) {
286  BKE_pose_free_ex(ob->pose, false);
287  ob->pose = nullptr;
288  }
289  if (ob->mpath) {
291  ob->mpath = nullptr;
292  }
293 
295 
297  BKE_rigidbody_free_object(ob, nullptr);
299 
300  sbFree(ob);
301 
303 
304  BLI_freelistN(&ob->pc_ids);
305 
306  /* Free runtime curves data. */
307  if (ob->runtime.curve_cache) {
311  }
313  ob->runtime.curve_cache = nullptr;
314  }
315 
317 
319 }
320 
322  Object *UNUSED(object),
323  ID **id_pointer,
324  int cb_flag)
325 {
328  data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
329 }
330 
332  Object *UNUSED(object),
333  ID **id_pointer,
334  int cb_flag)
335 {
338  data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
339 }
340 
342  Object *UNUSED(object),
343  ID **id_pointer,
344  int cb_flag)
345 {
348  data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
349 }
350 
352  ID **id_pointer,
353  bool is_reference,
354  void *user_data)
355 {
357  const int cb_flag = is_reference ? IDWALK_CB_USER : IDWALK_CB_NOP;
359  data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
360 }
361 
363  ID **id_pointer,
364  void *user_data,
365  int cb_flag)
366 {
369  data, BKE_lib_query_foreachid_process(data, id_pointer, cb_flag));
370 }
371 
373 {
374  Object *object = (Object *)id;
375 
376  /* object data special case */
377  if (object->type == OB_EMPTY) {
378  /* empty can have nullptr or Image */
380  }
381  else {
382  /* when set, this can't be nullptr */
383  if (object->data) {
385  }
386  }
387 
390 
392 
393  for (int i = 0; i < object->totcol; i++) {
395  }
396 
397  /* Note that ob->gpd is deprecated, so no need to handle it here. */
399 
400  if (object->pd) {
403  }
404  /* Note that ob->effect is deprecated, so no need to handle it here. */
405 
406  if (object->pose) {
407  LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
409  data,
410  IDP_foreach_property(pchan->prop,
413  data));
414 
417  data,
419  &pchan->constraints, library_foreach_constraintObjectLooper, data));
420  }
421  }
422 
423  if (object->rigidbody_constraint) {
428  }
429 
433  data,
437  data,
441 
442  LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
445  }
446 
447  if (object->soft) {
449 
450  if (object->soft->effector_weights) {
453  }
454  }
455 }
456 
457 static void object_foreach_path_pointcache(ListBase *ptcache_list,
458  BPathForeachPathData *bpath_data)
459 {
460  for (PointCache *cache = (PointCache *)ptcache_list->first; cache != nullptr;
461  cache = cache->next) {
462  if (cache->flag & PTCACHE_DISK_CACHE) {
463  BKE_bpath_foreach_path_fixed_process(bpath_data, cache->path);
464  }
465  }
466 }
467 
468 static void object_foreach_path(ID *id, BPathForeachPathData *bpath_data)
469 {
470  Object *ob = reinterpret_cast<Object *>(id);
471 
472  LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
473  /* TODO: Move that to #ModifierTypeInfo. */
474  switch (md->type) {
475  case eModifierType_Fluidsim: {
476  FluidsimModifierData *fluidmd = reinterpret_cast<FluidsimModifierData *>(md);
477  if (fluidmd->fss) {
479  }
480  break;
481  }
482  case eModifierType_Fluid: {
483  FluidModifierData *fmd = reinterpret_cast<FluidModifierData *>(md);
484  if (fmd->type & MOD_FLUID_TYPE_DOMAIN && fmd->domain) {
486  }
487  break;
488  }
489  case eModifierType_Cloth: {
490  ClothModifierData *clmd = reinterpret_cast<ClothModifierData *>(md);
491  object_foreach_path_pointcache(&clmd->ptcaches, bpath_data);
492  break;
493  }
494  case eModifierType_Ocean: {
495  OceanModifierData *omd = reinterpret_cast<OceanModifierData *>(md);
497  break;
498  }
500  MeshCacheModifierData *mcmd = reinterpret_cast<MeshCacheModifierData *>(md);
502  break;
503  }
504  default:
505  break;
506  }
507  }
508 
509  if (ob->soft != nullptr) {
511  }
512 
514  object_foreach_path_pointcache(&psys->ptcaches, bpath_data);
515  }
516 }
517 
518 static void write_fmaps(BlendWriter *writer, ListBase *fbase)
519 {
520  LISTBASE_FOREACH (bFaceMap *, fmap, fbase) {
521  BLO_write_struct(writer, bFaceMap, fmap);
522  }
523 }
524 
525 static void object_blend_write(BlendWriter *writer, ID *id, const void *id_address)
526 {
527  Object *ob = (Object *)id;
528 
529  const bool is_undo = BLO_write_is_undo(writer);
530 
531  /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
533 
534  if (is_undo) {
535  /* For undo we stay in object mode during undo presses, so keep edit-mode disabled on save as
536  * well, can help reducing false detection of changed data-blocks. */
537  ob->mode &= ~OB_MODE_EDIT;
538  }
539 
540  /* write LibData */
541  BLO_write_id_struct(writer, Object, id_address, &ob->id);
542  BKE_id_blend_write(writer, &ob->id);
543 
544  if (ob->adt) {
545  BKE_animdata_blend_write(writer, ob->adt);
546  }
547 
548  /* direct data */
549  BLO_write_pointer_array(writer, ob->totcol, ob->mat);
550  BLO_write_raw(writer, sizeof(char) * ob->totcol, ob->matbits);
551 
552  bArmature *arm = nullptr;
553  if (ob->type == OB_ARMATURE) {
554  arm = (bArmature *)ob->data;
555  }
556 
557  BKE_pose_blend_write(writer, ob->pose, arm);
558  write_fmaps(writer, &ob->fmaps);
561 
562  BLO_write_struct(writer, PartDeflect, ob->pd);
563  if (ob->soft) {
564  /* Set deprecated pointers to prevent crashes of older Blenders */
565  ob->soft->pointcache = ob->soft->shared->pointcache;
566  ob->soft->ptcaches = ob->soft->shared->ptcaches;
567  BLO_write_struct(writer, SoftBody, ob->soft);
569  BKE_ptcache_blend_write(writer, &(ob->soft->shared->ptcaches));
571  }
572 
573  if (ob->rigidbody_object) {
574  /* TODO: if any extra data is added to handle duplis, will need separate function then */
576  }
577  if (ob->rigidbody_constraint) {
579  }
580 
581  if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
582  BLO_write_struct(writer, ImageUser, ob->iuser);
583  }
584 
586  BKE_modifier_blend_write(writer, &ob->id, &ob->modifiers);
588  BKE_shaderfx_blend_write(writer, &ob->shader_fx);
589 
590  BLO_write_struct_list(writer, LinkData, &ob->pc_ids);
591 
592  BKE_previewimg_blend_write(writer, ob->preview);
593 
594  if (ob->lightgroup) {
596  }
597 }
598 
599 /* XXX deprecated - old animation system */
600 static void direct_link_nlastrips(BlendDataReader *reader, ListBase *strips)
601 {
602  BLO_read_list(reader, strips);
603 
604  LISTBASE_FOREACH (bActionStrip *, strip, strips) {
605  BLO_read_list(reader, &strip->modifiers);
606  }
607 }
608 
609 static void object_blend_read_data(BlendDataReader *reader, ID *id)
610 {
611  Object *ob = (Object *)id;
612 
613  PartEff *paf;
614 
615  /* XXX This should not be needed - but seems like it can happen in some cases,
616  * so for now play safe. */
617  ob->proxy_from = nullptr;
618 
619  const bool is_undo = BLO_read_data_is_undo(reader);
620  if (ob->id.tag & (LIB_TAG_EXTERN | LIB_TAG_INDIRECT)) {
621  /* Do not allow any non-object mode for linked data.
622  * See T34776, T42780, T81027 for more information. */
623  ob->mode &= ~OB_MODE_ALL_MODE_DATA;
624  }
625  else if (is_undo) {
626  /* For undo we want to stay in object mode during undo presses, so keep some edit modes
627  * disabled.
628  * TODO: Check if we should not disable more edit modes here? */
630  }
631 
632  BLO_read_data_address(reader, &ob->adt);
633  BKE_animdata_blend_read_data(reader, ob->adt);
634 
635  BLO_read_data_address(reader, &ob->pose);
636  BKE_pose_blend_read_data(reader, ob->pose);
637 
638  BLO_read_data_address(reader, &ob->mpath);
639  if (ob->mpath) {
641  }
642 
643  /* Only for versioning, vertex group names are now stored on object data. */
644  BLO_read_list(reader, &ob->defbase);
645 
646  BLO_read_list(reader, &ob->fmaps);
647  /* XXX deprecated - old animation system <<< */
648  direct_link_nlastrips(reader, &ob->nlastrips);
649  BLO_read_list(reader, &ob->constraintChannels);
650  /* >>> XXX deprecated - old animation system */
651 
652  BLO_read_pointer_array(reader, (void **)&ob->mat);
653  BLO_read_data_address(reader, &ob->matbits);
654 
655  /* do it here, below old data gets converted */
656  BKE_modifier_blend_read_data(reader, &ob->modifiers, ob);
659 
660  BLO_read_list(reader, &ob->effect);
661  paf = (PartEff *)ob->effect.first;
662  while (paf) {
663  if (paf->type == EFF_PARTICLE) {
664  paf->keys = nullptr;
665  }
666  if (paf->type == EFF_WAVE) {
667  WaveEff *wav = (WaveEff *)paf;
668  PartEff *next = paf->next;
670 
671  wmd->damp = wav->damp;
672  wmd->flag = wav->flag;
673  wmd->height = wav->height;
674  wmd->lifetime = wav->lifetime;
675  wmd->narrow = wav->narrow;
676  wmd->speed = wav->speed;
677  wmd->startx = wav->startx;
678  wmd->starty = wav->startx;
679  wmd->timeoffs = wav->timeoffs;
680  wmd->width = wav->width;
681 
682  BLI_addtail(&ob->modifiers, wmd);
683 
684  BLI_remlink(&ob->effect, paf);
685  MEM_freeN(paf);
686 
687  paf = next;
688  continue;
689  }
690  if (paf->type == EFF_BUILD) {
691  BuildEff *baf = (BuildEff *)paf;
692  PartEff *next = paf->next;
694 
695  bmd->start = baf->sfra;
696  bmd->length = baf->len;
697  bmd->randomize = 0;
698  bmd->seed = 1;
699 
700  BLI_addtail(&ob->modifiers, bmd);
701 
702  BLI_remlink(&ob->effect, paf);
703  MEM_freeN(paf);
704 
705  paf = next;
706  continue;
707  }
708  paf = paf->next;
709  }
710 
711  BLO_read_data_address(reader, &ob->pd);
713  BLO_read_data_address(reader, &ob->soft);
714  if (ob->soft) {
715  SoftBody *sb = ob->soft;
716 
717  sb->bpoint = nullptr; /* init pointers so it gets rebuilt nicely */
718  sb->bspring = nullptr;
719  sb->scratch = nullptr;
720  /* although not used anymore */
721  /* still have to be loaded to be compatible with old files */
722  BLO_read_pointer_array(reader, (void **)&sb->keys);
723  if (sb->keys) {
724  for (int a = 0; a < sb->totkey; a++) {
725  BLO_read_data_address(reader, &sb->keys[a]);
726  }
727  }
728 
730  if (!sb->effector_weights) {
732  }
733 
734  BLO_read_data_address(reader, &sb->shared);
735  if (sb->shared == nullptr) {
736  /* Link deprecated caches if they exist, so we can use them for versioning.
737  * We should only do this when sb->shared == nullptr, because those pointers
738  * are always set (for compatibility with older Blenders). We mustn't link
739  * the same pointcache twice. */
740  BKE_ptcache_blend_read_data(reader, &sb->ptcaches, &sb->pointcache, false);
741  }
742  else {
743  /* link caches */
744  BKE_ptcache_blend_read_data(reader, &sb->shared->ptcaches, &sb->shared->pointcache, false);
745  }
746  }
747  BLO_read_data_address(reader, &ob->fluidsimSettings); /* NT */
748 
750  if (ob->rigidbody_object) {
751  RigidBodyOb *rbo = ob->rigidbody_object;
752  /* Allocate runtime-only struct */
753  rbo->shared = (RigidBodyOb_Shared *)MEM_callocN(sizeof(*rbo->shared), "RigidBodyObShared");
754  }
756  if (ob->rigidbody_constraint) {
758  }
759 
760  BLO_read_list(reader, &ob->particlesystem);
762 
764 
765  BLO_read_list(reader, &ob->hooks);
766  while (ob->hooks.first) {
767  ObHook *hook = (ObHook *)ob->hooks.first;
769 
770  BLO_read_int32_array(reader, hook->totindex, &hook->indexar);
771 
772  /* Do conversion here because if we have loaded
773  * a hook we need to make sure it gets converted
774  * and freed, regardless of version.
775  */
776  copy_v3_v3(hmd->cent, hook->cent);
777  hmd->falloff = hook->falloff;
778  hmd->force = hook->force;
779  hmd->indexar = hook->indexar;
780  hmd->object = hook->parent;
781  memcpy(hmd->parentinv, hook->parentinv, sizeof(hmd->parentinv));
782  hmd->indexar_num = hook->totindex;
783 
784  BLI_addhead(&ob->modifiers, hmd);
785  BLI_remlink(&ob->hooks, hook);
786 
788 
789  MEM_freeN(hook);
790  }
791 
792  BLO_read_data_address(reader, &ob->iuser);
793  if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE && !ob->iuser) {
795  }
796 
798  BLO_read_list(reader, &ob->pc_ids);
799 
800  /* in case this value changes in future, clamp else we get undefined behavior */
802 
803  if (ob->sculpt) {
804  ob->sculpt = nullptr;
805  /* Only create data on undo, otherwise rely on editor mode switching. */
806  if (BLO_read_data_is_undo(reader) && (ob->mode & OB_MODE_ALL_SCULPT)) {
808  }
809  }
810 
811  BLO_read_data_address(reader, &ob->preview);
812  BKE_previewimg_blend_read(reader, ob->preview);
813 
814  BLO_read_data_address(reader, &ob->lightgroup);
815 }
816 
817 /* XXX deprecated - old animation system */
818 static void lib_link_nlastrips(BlendLibReader *reader, ID *id, ListBase *striplist)
819 {
820  LISTBASE_FOREACH (bActionStrip *, strip, striplist) {
821  BLO_read_id_address(reader, id->lib, &strip->object);
822  BLO_read_id_address(reader, id->lib, &strip->act);
823  BLO_read_id_address(reader, id->lib, &strip->ipo);
824  LISTBASE_FOREACH (bActionModifier *, amod, &strip->modifiers) {
825  BLO_read_id_address(reader, id->lib, &amod->ob);
826  }
827  }
828 }
829 
830 /* XXX deprecated - old animation system */
831 static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBase *chanbase)
832 {
833  LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) {
834  BLO_read_id_address(reader, id->lib, &chan->ipo);
835  }
836 }
837 
838 static void object_blend_read_lib(BlendLibReader *reader, ID *id)
839 {
840  Object *ob = (Object *)id;
841 
842  Main *bmain = BLO_read_lib_get_main(reader);
843  BlendFileReadReport *reports = BLO_read_lib_reports(reader);
844 
845  /* XXX deprecated - old animation system <<< */
846  BLO_read_id_address(reader, ob->id.lib, &ob->ipo);
847  BLO_read_id_address(reader, ob->id.lib, &ob->action);
848  /* >>> XXX deprecated - old animation system */
849 
850  BLO_read_id_address(reader, ob->id.lib, &ob->parent);
851  BLO_read_id_address(reader, ob->id.lib, &ob->track);
852  BLO_read_id_address(reader, ob->id.lib, &ob->poselib);
853 
854  /* 2.8x drops support for non-empty dupli instances. */
855  if (ob->type == OB_EMPTY) {
856  BLO_read_id_address(reader, ob->id.lib, &ob->instance_collection);
857  }
858  else {
859  if (ob->instance_collection != nullptr) {
860  ID *new_id = BLO_read_get_new_id_address(reader, ob->id.lib, &ob->instance_collection->id);
861  BLO_reportf_wrap(reports,
862  RPT_INFO,
863  TIP_("Non-Empty object '%s' cannot duplicate collection '%s' "
864  "anymore in Blender 2.80, removed instancing"),
865  ob->id.name + 2,
866  new_id->name + 2);
867  }
868  ob->instance_collection = nullptr;
870  }
871 
872  BLO_read_id_address(reader, ob->id.lib, &ob->proxy);
873  if (ob->proxy) {
874  /* paranoia check, actually a proxy_from pointer should never be written... */
875  if (!ID_IS_LINKED(ob->proxy)) {
876  ob->proxy->proxy_from = nullptr;
877  ob->proxy = nullptr;
878 
879  if (ob->id.lib) {
880  BLO_reportf_wrap(reports,
881  RPT_INFO,
882  TIP_("Proxy lost from object %s lib %s\n"),
883  ob->id.name + 2,
884  ob->id.lib->filepath);
885  }
886  else {
888  reports, RPT_INFO, TIP_("Proxy lost from object %s lib <NONE>\n"), ob->id.name + 2);
889  }
890  reports->count.missing_obproxies++;
891  }
892  else {
893  /* this triggers object_update to always use a copy */
894  ob->proxy->proxy_from = ob;
895  }
896  }
897  BLO_read_id_address(reader, ob->id.lib, &ob->proxy_group);
898 
899  void *poin = ob->data;
900  BLO_read_id_address(reader, ob->id.lib, &ob->data);
901 
902  if (ob->data == nullptr && poin != nullptr) {
903  ob->type = OB_EMPTY;
904 
905  if (ob->pose) {
906  /* we can't call #BKE_pose_free() here because of library linking
907  * freeing will recurse down into every pose constraints ID pointers
908  * which are not always valid, so for now free directly and suffer
909  * some leaked memory rather than crashing immediately
910  * while bad this _is_ an exceptional case - campbell */
911 #if 0
912  BKE_pose_free(ob->pose);
913 #else
914  MEM_freeN(ob->pose);
915 #endif
916  ob->pose = nullptr;
917  ob->mode &= ~OB_MODE_POSE;
918  }
919 
920  if (ob->id.lib) {
921  BLO_reportf_wrap(reports,
922  RPT_INFO,
923  TIP_("Can't find object data of %s lib %s\n"),
924  ob->id.name + 2,
925  ob->id.lib->filepath);
926  }
927  else {
928  BLO_reportf_wrap(reports, RPT_INFO, TIP_("Object %s lost data\n"), ob->id.name + 2);
929  }
930  reports->count.missing_obdata++;
931  }
932  for (int a = 0; a < ob->totcol; a++) {
933  BLO_read_id_address(reader, ob->id.lib, &ob->mat[a]);
934  }
935 
936  /* When the object is local and the data is library its possible
937  * the material list size gets out of sync. T22663. */
938  if (ob->data && ob->id.lib != ((ID *)ob->data)->lib) {
939  BKE_object_materials_test(bmain, ob, (ID *)ob->data);
940  }
941 
942  BLO_read_id_address(reader, ob->id.lib, &ob->gpd);
943 
944  /* if id.us==0 a new base will be created later on */
945 
946  /* WARNING! Also check expand_object(), should reflect the stuff below. */
947  BKE_pose_blend_read_lib(reader, ob, ob->pose);
948  BKE_constraint_blend_read_lib(reader, &ob->id, &ob->constraints);
949 
950  /* XXX deprecated - old animation system <<< */
951  lib_link_constraint_channels(reader, &ob->id, &ob->constraintChannels);
952  lib_link_nlastrips(reader, &ob->id, &ob->nlastrips);
953  /* >>> XXX deprecated - old animation system */
954 
955  LISTBASE_FOREACH (PartEff *, paf, &ob->effect) {
956  if (paf->type == EFF_PARTICLE) {
957  BLO_read_id_address(reader, ob->id.lib, &paf->group);
958  }
959  }
960 
961  {
964 
965  if (fluidmd && fluidmd->fss) {
966  /* XXX: deprecated - old animation system. */
967  BLO_read_id_address(reader, ob->id.lib, &fluidmd->fss->ipo);
968  }
969  }
970 
971  {
974 
975  if (fmd && (fmd->type == MOD_FLUID_TYPE_DOMAIN) && fmd->domain) {
976  /* Flag for refreshing the simulation after loading */
978  }
979  else if (fmd && (fmd->type == MOD_FLUID_TYPE_FLOW) && fmd->flow) {
981  }
982  else if (fmd && (fmd->type == MOD_FLUID_TYPE_EFFEC) && fmd->effector) {
984  }
985  }
986 
987  /* texture field */
988  if (ob->pd) {
989  BKE_particle_partdeflect_blend_read_lib(reader, &ob->id, ob->pd);
990  }
991 
992  if (ob->soft) {
993  BLO_read_id_address(reader, ob->id.lib, &ob->soft->collision_group);
994 
995  BLO_read_id_address(reader, ob->id.lib, &ob->soft->effector_weights->group);
996  }
997 
998  BKE_particle_system_blend_read_lib(reader, ob, &ob->id, &ob->particlesystem);
999  BKE_modifier_blend_read_lib(reader, ob);
1001  BKE_shaderfx_blend_read_lib(reader, ob);
1002 
1003  if (ob->rigidbody_constraint) {
1004  BLO_read_id_address(reader, ob->id.lib, &ob->rigidbody_constraint->ob1);
1005  BLO_read_id_address(reader, ob->id.lib, &ob->rigidbody_constraint->ob2);
1006  }
1007 }
1008 
1009 /* XXX deprecated - old animation system */
1010 static void expand_constraint_channels(BlendExpander *expander, ListBase *chanbase)
1011 {
1012  LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) {
1013  BLO_expand(expander, chan->ipo);
1014  }
1015 }
1016 
1017 static void expand_object_expandModifiers(void *userData,
1018  Object *UNUSED(ob),
1019  ID **idpoin,
1020  int UNUSED(cb_flag))
1021 {
1022  BlendExpander *expander = (BlendExpander *)userData;
1023  BLO_expand(expander, *idpoin);
1024 }
1025 
1027 {
1028  PartEff *paf;
1029 
1030  paf = (PartEff *)ob->effect.first;
1031  while (paf) {
1032  if (paf->type == EFF_PARTICLE) {
1033  return paf;
1034  }
1035  paf = paf->next;
1036  }
1037  return nullptr;
1038 }
1039 
1040 static void object_blend_read_expand(BlendExpander *expander, ID *id)
1041 {
1042  Object *ob = (Object *)id;
1043 
1044  BLO_expand(expander, ob->data);
1045 
1046  BLO_expand(expander, ob->parent);
1047 
1048  /* expand_object_expandModifier() */
1049  if (ob->modifiers.first) {
1051  }
1052 
1053  /* expand_object_expandModifier() */
1054  if (ob->greasepencil_modifiers.first) {
1056  }
1057 
1058  /* expand_object_expandShaderFx() */
1059  if (ob->shader_fx.first) {
1061  }
1062 
1063  BKE_pose_blend_read_expand(expander, ob->pose);
1064  BLO_expand(expander, ob->poselib);
1066 
1067  BLO_expand(expander, ob->gpd);
1068 
1069  /* XXX deprecated - old animation system (for version patching only) */
1070  BLO_expand(expander, ob->ipo);
1071  BLO_expand(expander, ob->action);
1072 
1073  expand_constraint_channels(expander, &ob->constraintChannels);
1074 
1075  LISTBASE_FOREACH (bActionStrip *, strip, &ob->nlastrips) {
1076  BLO_expand(expander, strip->object);
1077  BLO_expand(expander, strip->act);
1078  BLO_expand(expander, strip->ipo);
1079  }
1080  /* XXX deprecated - old animation system (for version patching only) */
1081 
1082  for (int a = 0; a < ob->totcol; a++) {
1083  BLO_expand(expander, ob->mat[a]);
1084  }
1085 
1087  if (paf && paf->group) {
1088  BLO_expand(expander, paf->group);
1089  }
1090 
1091  if (ob->instance_collection) {
1092  BLO_expand(expander, ob->instance_collection);
1093  }
1094 
1095  if (ob->proxy) {
1096  BLO_expand(expander, ob->proxy);
1097  }
1098  if (ob->proxy_group) {
1099  BLO_expand(expander, ob->proxy_group);
1100  }
1101 
1103  BLO_expand(expander, psys->part);
1104  }
1105 
1106  if (ob->pd) {
1107  BLO_expand(expander, ob->pd->tex);
1108  BLO_expand(expander, ob->pd->f_source);
1109  }
1110 
1111  if (ob->soft) {
1112  BLO_expand(expander, ob->soft->collision_group);
1113 
1114  if (ob->soft->effector_weights) {
1115  BLO_expand(expander, ob->soft->effector_weights->group);
1116  }
1117  }
1118 
1119  if (ob->rigidbody_constraint) {
1120  BLO_expand(expander, ob->rigidbody_constraint->ob1);
1121  BLO_expand(expander, ob->rigidbody_constraint->ob2);
1122  }
1123 }
1124 
1125 static void object_lib_override_apply_post(ID *id_dst, ID *id_src)
1126 {
1127  /* id_dst is the new local override copy of the linked reference data. id_src is the old override
1128  * data stored on disk, used as source data for override operations. */
1129  Object *object_dst = (Object *)id_dst;
1130  Object *object_src = (Object *)id_src;
1131 
1132  ListBase pidlist_dst, pidlist_src;
1133  BKE_ptcache_ids_from_object(&pidlist_dst, object_dst, nullptr, 0);
1134  BKE_ptcache_ids_from_object(&pidlist_src, object_src, nullptr, 0);
1135 
1136  /* Problem with point caches is that several status flags (like OUTDATED or BAKED) are read-only
1137  * at RNA level, and therefore not overridable per-se.
1138  *
1139  * This code is a workaround this to check all point-caches from both source and destination
1140  * objects in parallel, and transfer those flags when it makes sense.
1141  *
1142  * This allows to keep baked caches across liboverrides applies.
1143  *
1144  * NOTE: This is fairly hackish and weak, but so is the point-cache system as its whole. A more
1145  * robust solution would be e.g. to have a specific RNA entry point to deal with such cases
1146  * (maybe a new flag to allow override code to set values of some read-only properties?).
1147  */
1148  PTCacheID *pid_src, *pid_dst;
1149  for (pid_dst = (PTCacheID *)pidlist_dst.first, pid_src = (PTCacheID *)pidlist_src.first;
1150  pid_dst != nullptr;
1151  pid_dst = pid_dst->next, pid_src = (pid_src != nullptr) ? pid_src->next : nullptr) {
1152  /* If pid's do not match, just tag info of caches in dst as dirty and continue. */
1153  if (pid_src == nullptr) {
1154  continue;
1155  }
1156  if (pid_dst->type != pid_src->type || pid_dst->file_type != pid_src->file_type ||
1157  pid_dst->default_step != pid_src->default_step || pid_dst->max_step != pid_src->max_step ||
1158  pid_dst->data_types != pid_src->data_types || pid_dst->info_types != pid_src->info_types) {
1159  LISTBASE_FOREACH (PointCache *, point_cache_src, pid_src->ptcaches) {
1160  point_cache_src->flag |= PTCACHE_FLAG_INFO_DIRTY;
1161  }
1162  continue;
1163  }
1164 
1165  PointCache *point_cache_dst, *point_cache_src;
1166  for (point_cache_dst = (PointCache *)pid_dst->ptcaches->first,
1167  point_cache_src = (PointCache *)pid_src->ptcaches->first;
1168  point_cache_dst != nullptr;
1169  point_cache_dst = point_cache_dst->next,
1170  point_cache_src = (point_cache_src != nullptr) ? point_cache_src->next : nullptr) {
1171  /* Always force updating info about caches of applied liboverrides. */
1172  point_cache_dst->flag |= PTCACHE_FLAG_INFO_DIRTY;
1173  if (point_cache_src == nullptr || !STREQ(point_cache_dst->name, point_cache_src->name)) {
1174  continue;
1175  }
1176  if ((point_cache_src->flag & PTCACHE_BAKED) != 0) {
1177  point_cache_dst->flag |= PTCACHE_BAKED;
1178  }
1179  if ((point_cache_src->flag & PTCACHE_OUTDATED) == 0) {
1180  point_cache_dst->flag &= ~PTCACHE_OUTDATED;
1181  }
1182  }
1183  }
1184  BLI_freelistN(&pidlist_dst);
1185  BLI_freelistN(&pidlist_src);
1186 }
1187 
1189 {
1190  float3 dimensions;
1191  BKE_object_dimensions_get(ob, dimensions);
1192  if (is_zero_v3(dimensions)) {
1193  return nullptr;
1194  }
1195 
1196  IDPropertyTemplate idprop{};
1197  idprop.array.len = ARRAY_SIZE(dimensions);
1198  idprop.array.type = IDP_FLOAT;
1199 
1200  IDProperty *property = IDP_New(IDP_ARRAY, &idprop, "dimensions");
1201  memcpy(IDP_Array(property), dimensions, sizeof(dimensions));
1202 
1203  return property;
1204 }
1205 
1206 static void object_asset_pre_save(void *asset_ptr, struct AssetMetaData *asset_data)
1207 {
1208  Object *ob = (Object *)asset_ptr;
1209  BLI_assert(GS(ob->id.name) == ID_OB);
1210 
1211  /* Update dimensions hint for the asset. */
1212  IDProperty *dimensions_prop = object_asset_dimensions_property(ob);
1213  if (dimensions_prop) {
1214  BKE_asset_metadata_idprop_ensure(asset_data, dimensions_prop);
1215  }
1216 }
1217 
1219  /* pre_save_fn */ object_asset_pre_save,
1220 };
1221 
1223  /* id_code */ ID_OB,
1224  /* id_filter */ FILTER_ID_OB,
1225  /* main_listbase_index */ INDEX_ID_OB,
1226  /* struct_size */ sizeof(Object),
1227  /* name */ "Object",
1228  /* name_plural */ "objects",
1229  /* translation_context */ BLT_I18NCONTEXT_ID_OBJECT,
1230  /* flags */ 0,
1231  /* asset_type_info */ &AssetType_OB,
1232 
1233  /* init_data */ object_init_data,
1234  /* copy_data */ object_copy_data,
1235  /* free_data */ object_free_data,
1236  /* make_local */ nullptr,
1237  /* foreach_id */ object_foreach_id,
1238  /* foreach_cache */ nullptr,
1239  /* foreach_path */ object_foreach_path,
1240  /* owner_get */ nullptr,
1241 
1242  /* blend_write */ object_blend_write,
1243  /* blend_read_data */ object_blend_read_data,
1244  /* blend_read_lib */ object_blend_read_lib,
1245  /* blend_read_expand */ object_blend_read_expand,
1246 
1247  /* blend_read_undo_preserve */ nullptr,
1248 
1249  /* lib_override_apply_post */ object_lib_override_apply_post,
1250 };
1251 
1253 {
1254  *workob = blender::dna::shallow_zero_initialize();
1255 
1256  workob->scale[0] = workob->scale[1] = workob->scale[2] = 1.0f;
1257  workob->dscale[0] = workob->dscale[1] = workob->dscale[2] = 1.0f;
1258  workob->rotmode = ROT_MODE_EUL;
1259 }
1260 
1262 {
1263  ParticleSystem *psys;
1264 
1265  while ((psys = (ParticleSystem *)BLI_pophead(&ob->particlesystem))) {
1266  psys_free(ob, psys);
1267  }
1268 }
1269 
1271 {
1272  sbFree(ob);
1273 }
1274 
1276 {
1277  if (ob->runtime.curve_cache) {
1282  }
1285  ob->runtime.curve_cache = nullptr;
1286  }
1287 }
1288 
1289 void BKE_object_free_modifiers(Object *ob, const int flag)
1290 {
1291  ModifierData *md;
1292  GpencilModifierData *gp_md;
1293 
1294  while ((md = (ModifierData *)BLI_pophead(&ob->modifiers))) {
1295  BKE_modifier_free_ex(md, flag);
1296  }
1297 
1298  while ((gp_md = (GpencilModifierData *)BLI_pophead(&ob->greasepencil_modifiers))) {
1299  BKE_gpencil_modifier_free_ex(gp_md, flag);
1300  }
1301  /* particle modifiers were freed, so free the particlesystems as well */
1303 
1304  /* same for softbody */
1306 
1307  /* modifiers may have stored data in the DM cache */
1309 }
1310 
1311 void BKE_object_free_shaderfx(Object *ob, const int flag)
1312 {
1313  ShaderFxData *fx;
1314 
1315  while ((fx = (ShaderFxData *)BLI_pophead(&ob->shader_fx))) {
1316  BKE_shaderfx_free_ex(fx, flag);
1317  }
1318 }
1319 
1321 {
1322  /* reset functionality */
1323  if (hmd->object) {
1325 
1326  if (hmd->subtarget[0] && pchan) {
1327  float imat[4][4], mat[4][4];
1328 
1329  /* Calculate the world-space matrix for the pose-channel target first,
1330  * then carry on as usual. */
1331  mul_m4_m4m4(mat, hmd->object->obmat, pchan->pose_mat);
1332 
1333  invert_m4_m4(imat, mat);
1334  mul_m4_m4m4(hmd->parentinv, imat, ob->obmat);
1335  }
1336  else {
1337  invert_m4_m4(hmd->object->imat, hmd->object->obmat);
1338  mul_m4_m4m4(hmd->parentinv, hmd->object->imat, ob->obmat);
1339  }
1340  }
1341 }
1342 
1344 {
1345  if (hmd->object == nullptr) {
1346  return;
1347  }
1348  /* reset functionality */
1350 
1351  if (hmd->subtarget[0] && pchan) {
1352  float imat[4][4], mat[4][4];
1353 
1354  /* Calculate the world-space matrix for the pose-channel target first,
1355  * then carry on as usual. */
1356  mul_m4_m4m4(mat, hmd->object->obmat, pchan->pose_mat);
1357 
1358  invert_m4_m4(imat, mat);
1359  mul_m4_m4m4(hmd->parentinv, imat, ob->obmat);
1360  }
1361  else {
1362  invert_m4_m4(hmd->object->imat, hmd->object->obmat);
1363  mul_m4_m4m4(hmd->parentinv, hmd->object->imat, ob->obmat);
1364  }
1365 }
1366 
1368 {
1369  LISTBASE_FOREACH (ModifierData *, md_iter, &ob->modifiers) {
1370  md_iter->flag &= ~eModifierFlag_Active;
1371  }
1372 
1373  if (md != nullptr) {
1374  BLI_assert(BLI_findindex(&ob->modifiers, md) != -1);
1375  md->flag |= eModifierFlag_Active;
1376  }
1377 }
1378 
1380 {
1381  /* In debug mode, check for only one active modifier. */
1382 #ifndef NDEBUG
1383  int active_count = 0;
1384  LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
1385  if (md->flag & eModifierFlag_Active) {
1386  active_count++;
1387  }
1388  }
1389  BLI_assert(ELEM(active_count, 0, 1));
1390 #endif
1391 
1392  LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
1393  if (md->flag & eModifierFlag_Active) {
1394  return md;
1395  }
1396  }
1397 
1398  return nullptr;
1399 }
1400 
1402 {
1403  return (ELEM(ob->type,
1404  OB_MESH,
1405  OB_CURVES,
1407  OB_SURF,
1408  OB_FONT,
1409  OB_LATTICE,
1410  OB_POINTCLOUD,
1411  OB_VOLUME));
1412 }
1413 
1414 bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
1415 {
1416  const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)modifier_type);
1417 
1418  /* Surface and lattice objects don't output geometry sets. */
1419  if (mti->modifyGeometrySet != nullptr && ELEM(ob->type, OB_SURF, OB_LATTICE)) {
1420  return false;
1421  }
1422 
1423  /* Only geometry objects should be able to get modifiers T25291. */
1424  if (ELEM(ob->type, OB_POINTCLOUD, OB_VOLUME, OB_CURVES)) {
1425  return (mti->modifyGeometrySet != nullptr);
1426  }
1428  if (ob->type == OB_LATTICE && (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly) == 0) {
1429  return false;
1430  }
1431 
1432  if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) ||
1433  (ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) {
1434  return false;
1435  }
1436 
1437  return true;
1438  }
1439 
1440  return false;
1441 }
1442 
1444 {
1445  return !ELEM(md_type, eModifierType_Hook, eModifierType_Collision);
1446 }
1447 
1458  Scene *scene,
1459  Object *ob_dst,
1460  ParticleSystem *psys_src)
1461 {
1462  ParticleSystem *psys_dst = nullptr;
1463 
1464  /* Check if a particle system with the same particle settings
1465  * already exists on the destination object. */
1466  LISTBASE_FOREACH (ParticleSystem *, psys, &ob_dst->particlesystem) {
1467  if (psys->part == psys_src->part) {
1468  psys_dst = psys;
1469  break;
1470  }
1471  }
1472 
1473  /* If it does not exist, copy the particle system to the destination object. */
1474  if (psys_dst == nullptr) {
1475  ModifierData *md = object_copy_particle_system(bmain, scene, ob_dst, psys_src);
1476  psys_dst = ((ParticleSystemModifierData *)md)->psys;
1477  }
1478 
1479  return psys_dst;
1480 }
1481 
1483  Main *bmain, Scene *scene, Object *ob_dst, const Object *ob_src, ModifierData *md_src)
1484 {
1485  BLI_assert(ob_dst->type != OB_GPENCIL);
1486 
1489  /* We never allow copying those modifiers here. */
1490  return false;
1491  }
1492  if (!BKE_object_support_modifier_type_check(ob_dst, md_src->type)) {
1493  return false;
1494  }
1495  if (mti->flags & eModifierTypeFlag_Single) {
1496  if (BKE_modifiers_findby_type(ob_dst, (ModifierType)md_src->type) != nullptr) {
1497  return false;
1498  }
1499  }
1500 
1501  ParticleSystem *psys_src = nullptr;
1502  ParticleSystem *psys_dst = nullptr;
1503 
1504  switch (md_src->type) {
1506  BKE_object_copy_softbody(ob_dst, ob_src, 0);
1507  break;
1508  case eModifierType_Skin:
1509  /* ensure skin-node customdata exists */
1511  break;
1512  case eModifierType_Fluid: {
1513  FluidModifierData *fmd = (FluidModifierData *)md_src;
1514  if (fmd->type == MOD_FLUID_TYPE_FLOW) {
1515  if (fmd->flow != nullptr && fmd->flow->psys != nullptr) {
1516  psys_src = fmd->flow->psys;
1517  psys_dst = object_copy_modifier_particle_system_ensure(bmain, scene, ob_dst, psys_src);
1518  }
1519  }
1520  break;
1521  }
1524  if (dpmd->brush != nullptr && dpmd->brush->psys != nullptr) {
1525  psys_src = dpmd->brush->psys;
1526  psys_dst = object_copy_modifier_particle_system_ensure(bmain, scene, ob_dst, psys_src);
1527  }
1528  break;
1529  }
1530  default:
1531  break;
1532  }
1533 
1534  ModifierData *md_dst;
1535  if (md_src->type == eModifierType_ParticleSystem) {
1536  md_dst = object_copy_particle_system(
1537  bmain, scene, ob_dst, ((ParticleSystemModifierData *)md_src)->psys);
1538  }
1539  else {
1540  md_dst = BKE_modifier_new(md_src->type);
1541 
1542  BLI_strncpy(md_dst->name, md_src->name, sizeof(md_dst->name));
1543 
1544  if (md_src->type == eModifierType_Multires) {
1545  /* Has to be done after mod creation, but *before* we actually copy its settings! */
1547  ob_dst, (MultiresModifierData *)md_src, (MultiresModifierData *)md_dst);
1548  }
1549 
1550  BKE_modifier_copydata(md_src, md_dst);
1551 
1552  switch (md_dst->type) {
1553  case eModifierType_Fluid:
1554  if (psys_dst != nullptr) {
1555  FluidModifierData *fmd_dst = (FluidModifierData *)md_dst;
1556  BLI_assert(fmd_dst->type == MOD_FLUID_TYPE_FLOW && fmd_dst->flow != nullptr &&
1557  fmd_dst->flow->psys != nullptr);
1558  fmd_dst->flow->psys = psys_dst;
1559  }
1560  break;
1562  if (psys_dst != nullptr) {
1563  DynamicPaintModifierData *dpmd_dst = (DynamicPaintModifierData *)md_dst;
1564  BLI_assert(dpmd_dst->brush != nullptr && dpmd_dst->brush->psys != nullptr);
1565  dpmd_dst->brush->psys = psys_dst;
1566  }
1567  break;
1568  default:
1569  break;
1570  }
1571 
1572  BLI_addtail(&ob_dst->modifiers, md_dst);
1573  BKE_modifier_unique_name(&ob_dst->modifiers, md_dst);
1574  }
1575 
1576  BKE_object_modifier_set_active(ob_dst, md_dst);
1577 
1578  return true;
1579 }
1580 
1582 {
1583  BLI_assert(ob_dst->type == OB_GPENCIL);
1584 
1585  GpencilModifierData *gmd_dst = BKE_gpencil_modifier_new(gmd_src->type);
1586  BLI_strncpy(gmd_dst->name, gmd_src->name, sizeof(gmd_dst->name));
1587 
1589  (GpencilModifierType)gmd_src->type);
1590  mti->copyData(gmd_src, gmd_dst);
1591 
1592  BLI_addtail(&ob_dst->greasepencil_modifiers, gmd_dst);
1594 
1595  return true;
1596 }
1597 
1599  const Object *ob_src,
1600  const bool do_copy_all,
1601  const int flag_subdata)
1602 {
1603  if ((ob_dst->type == OB_GPENCIL) != (ob_src->type == OB_GPENCIL)) {
1604  BLI_assert_msg(0,
1605  "Trying to copy a modifier stack between a GPencil object and another type.");
1606  return false;
1607  }
1608 
1609  if (!BLI_listbase_is_empty(&ob_dst->modifiers) ||
1611  BLI_assert(
1612  !"Trying to copy a modifier stack into an object having a non-empty modifier stack.");
1613  return false;
1614  }
1615 
1616  LISTBASE_FOREACH (ModifierData *, md_src, &ob_src->modifiers) {
1617  if (!do_copy_all && !object_modifier_type_copy_check((ModifierType)md_src->type)) {
1618  continue;
1619  }
1620  if (!BKE_object_support_modifier_type_check(ob_dst, md_src->type)) {
1621  continue;
1622  }
1623 
1624  ModifierData *md_dst = BKE_modifier_copy_ex(md_src, flag_subdata);
1625  BLI_addtail(&ob_dst->modifiers, md_dst);
1626  }
1627 
1629  GpencilModifierData *gmd_dst = BKE_gpencil_modifier_new(gmd_src->type);
1630  BLI_strncpy(gmd_dst->name, gmd_src->name, sizeof(gmd_dst->name));
1631  BKE_gpencil_modifier_copydata_ex(gmd_src, gmd_dst, flag_subdata);
1632  BLI_addtail(&ob_dst->greasepencil_modifiers, gmd_dst);
1633  }
1634 
1635  /* This could be copied from anywhere, since no other modifier actually use this data. But for
1636  * consistency do it together with particle systems. */
1637  BKE_object_copy_softbody(ob_dst, ob_src, flag_subdata);
1638 
1639  /* It is mandatory that this happens after copying modifiers, as it will update their `psys`
1640  * pointers accordingly. */
1641  BKE_object_copy_particlesystems(ob_dst, ob_src, flag_subdata);
1642 
1643  return true;
1644 }
1645 
1646 void BKE_object_link_modifiers(Object *ob_dst, const Object *ob_src)
1647 {
1648  BKE_object_free_modifiers(ob_dst, 0);
1649 
1650  BKE_object_modifier_stack_copy(ob_dst, ob_src, false, 0);
1651 }
1652 
1656 static void copy_ccg_data(Mesh *mesh_destination, Mesh *mesh_source, int layer_type)
1657 {
1658  BLI_assert(mesh_destination->totloop == mesh_source->totloop);
1659  CustomData *data_destination = &mesh_destination->ldata;
1660  CustomData *data_source = &mesh_source->ldata;
1661  const int num_elements = mesh_source->totloop;
1662  if (!CustomData_has_layer(data_source, layer_type)) {
1663  return;
1664  }
1665  const int layer_index = CustomData_get_layer_index(data_destination, layer_type);
1666  CustomData_free_layer(data_destination, layer_type, num_elements, layer_index);
1667  BLI_assert(!CustomData_has_layer(data_destination, layer_type));
1668  CustomData_add_layer(data_destination, layer_type, CD_CALLOC, nullptr, num_elements);
1669  BLI_assert(CustomData_has_layer(data_destination, layer_type));
1670  CustomData_copy_layer_type_data(data_source, data_destination, layer_type, 0, 0, num_elements);
1671 }
1672 
1674 {
1675  /* Currently CCG is only created for Mesh objects. */
1676  if (object->type != OB_MESH) {
1677  return;
1678  }
1679  /* If object does not own evaluated mesh we can not access it since it might be freed already
1680  * (happens on dependency graph free where order of CoW-ed IDs free is undefined).
1681  *
1682  * Good news is: such mesh does not have modifiers applied, so no need to worry about CCG. */
1683  if (!object->runtime.is_data_eval_owned) {
1684  return;
1685  }
1686  /* Object was never evaluated, so can not have CCG subdivision surface. If it were evaluated, do
1687  * not try to compute OpenSubDiv on the CPU as it is not needed here. */
1688  Mesh *mesh_eval = BKE_object_get_evaluated_mesh_no_subsurf(object);
1689  if (mesh_eval == nullptr) {
1690  return;
1691  }
1692  SubdivCCG *subdiv_ccg = mesh_eval->runtime.subdiv_ccg;
1693  if (subdiv_ccg == nullptr) {
1694  return;
1695  }
1696  /* Check whether there is anything to be reshaped. */
1697  if (!subdiv_ccg->dirty.coords && !subdiv_ccg->dirty.hidden) {
1698  return;
1699  }
1700  const int tot_level = mesh_eval->runtime.subdiv_ccg_tot_level;
1701  Object *object_orig = DEG_get_original_object(object);
1702  Mesh *mesh_orig = (Mesh *)object_orig->data;
1703  multiresModifier_reshapeFromCCG(tot_level, mesh_orig, subdiv_ccg);
1704  /* NOTE: we need to reshape into an original mesh from main database,
1705  * allowing:
1706  *
1707  * - Update copies of that mesh at any moment.
1708  * - Save the file without doing extra reshape.
1709  * - All the users of the mesh have updated displacement.
1710  *
1711  * However, the tricky part here is that we only know about sculpted
1712  * state of a mesh on an object level, and object is being updated after
1713  * mesh data-block is updated. This forces us to:
1714  *
1715  * - Update mesh data-block from object evaluation, which is technically
1716  * forbidden, but there is no other place for this yet.
1717  * - Reshape to the original mesh from main database, and then copy updated
1718  * layer to copy of that mesh (since copy of the mesh has decoupled
1719  * custom data layers).
1720  *
1721  * All this is defeating all the designs we need to follow to allow safe
1722  * threaded evaluation, but this is as good as we can make it within the
1723  * current sculpt/evaluated mesh design. This is also how we've survived
1724  * with old #DerivedMesh based solutions. So, while this is all wrong and
1725  * needs reconsideration, doesn't seem to be a big stopper for real
1726  * production artists.
1727  */
1728  /* TODO(sergey): Solve this somehow, to be fully stable for threaded
1729  * evaluation environment.
1730  */
1731  /* NOTE: runtime.data_orig is what was before assigning mesh_eval,
1732  * it is orig as in what was in object_eval->data before evaluating
1733  * modifier stack.
1734  *
1735  * mesh_cow is a copy-on-written version of `object_orig->data`.
1736  */
1737  Mesh *mesh_cow = (Mesh *)object->runtime.data_orig;
1738  copy_ccg_data(mesh_cow, mesh_orig, CD_MDISPS);
1739  copy_ccg_data(mesh_cow, mesh_orig, CD_GRID_PAINT_MASK);
1740  /* Everything is now up-to-date. */
1741  subdiv_ccg->dirty.coords = false;
1742  subdiv_ccg->dirty.hidden = false;
1743 }
1744 
1745 void BKE_object_eval_assign_data(Object *object_eval, ID *data_eval, bool is_owned)
1746 {
1747  BLI_assert(object_eval->id.tag & LIB_TAG_COPIED_ON_WRITE);
1748  BLI_assert(object_eval->runtime.data_eval == nullptr);
1749  BLI_assert(data_eval->tag & LIB_TAG_NO_MAIN);
1750 
1751  if (is_owned) {
1752  /* Set flag for debugging. */
1754  }
1755 
1756  /* Assigned evaluated data. */
1757  object_eval->runtime.data_eval = data_eval;
1758  object_eval->runtime.is_data_eval_owned = is_owned;
1759 
1760  /* Overwrite data of evaluated object, if the data-block types match. */
1761  ID *data = (ID *)object_eval->data;
1762  if (GS(data->name) == GS(data_eval->name)) {
1763  /* NOTE: we are not supposed to invoke evaluation for original objects,
1764  * but some areas are still being ported, so we play safe here. */
1765  if (object_eval->id.tag & LIB_TAG_COPIED_ON_WRITE) {
1766  object_eval->data = data_eval;
1767  }
1768  }
1769 
1770  /* Is set separately currently. */
1771  object_eval->runtime.geometry_set_eval = nullptr;
1772 }
1773 
1775 {
1776  MEM_SAFE_FREE(ob->runtime.bb);
1777 
1779 
1780  if (ob->runtime.editmesh_eval_cage &&
1781  ob->runtime.editmesh_eval_cage != reinterpret_cast<Mesh *>(ob->runtime.data_eval)) {
1783  }
1784  ob->runtime.editmesh_eval_cage = nullptr;
1785 
1786  if (ob->runtime.data_eval != nullptr) {
1787  if (ob->runtime.is_data_eval_owned) {
1788  ID *data_eval = ob->runtime.data_eval;
1789  if (GS(data_eval->name) == ID_ME) {
1790  BKE_mesh_eval_delete((Mesh *)data_eval);
1791  }
1792  else {
1793  BKE_libblock_free_data(data_eval, false);
1794  BKE_libblock_free_datablock(data_eval, 0);
1795  MEM_freeN(data_eval);
1796  }
1797  }
1798  ob->runtime.data_eval = nullptr;
1799  }
1800  if (ob->runtime.mesh_deform_eval != nullptr) {
1801  Mesh *mesh_deform_eval = ob->runtime.mesh_deform_eval;
1802  BKE_mesh_eval_delete(mesh_deform_eval);
1803  ob->runtime.mesh_deform_eval = nullptr;
1804  }
1805 
1806  /* Restore initial pointer for copy-on-write data-blocks, object->data
1807  * might be pointing to an evaluated data-block data was just freed above. */
1808  if (ob->runtime.data_orig != nullptr) {
1809  ob->data = ob->runtime.data_orig;
1810  }
1811 
1815 
1817 
1818  /* Clear grease pencil data. */
1819  if (ob->runtime.gpd_eval != nullptr) {
1821  ob->runtime.gpd_eval = nullptr;
1822  }
1823 
1824  if (ob->runtime.geometry_set_eval != nullptr) {
1826  ob->runtime.geometry_set_eval = nullptr;
1827  }
1828 
1830 }
1831 
1833 {
1834  short update_flag = 0;
1835 
1836  /* Free particle system caches holding paths. */
1837  if (object->particlesystem.first) {
1838  LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
1839  psys_free_path_cache(psys, psys->edit);
1840  update_flag |= ID_RECALC_PSYS_REDO;
1841  }
1842  }
1843 
1844  /* Free memory used by cached derived meshes in the particle system modifiers. */
1845  LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
1846  if (md->type == eModifierType_ParticleSystem) {
1848  if (psmd->mesh_final) {
1849  BKE_id_free(nullptr, psmd->mesh_final);
1850  psmd->mesh_final = nullptr;
1851  if (psmd->mesh_original) {
1852  BKE_id_free(nullptr, psmd->mesh_original);
1853  psmd->mesh_original = nullptr;
1854  }
1856  update_flag |= ID_RECALC_GEOMETRY;
1857  }
1858  }
1859  }
1860 
1861  /* NOTE: If object is coming from a duplicator, it might be a temporary
1862  * object created by dependency graph, which shares pointers with original
1863  * object. In this case we can not free anything.
1864  */
1865  if ((object->base_flag & BASE_FROM_DUPLI) == 0) {
1867  update_flag |= ID_RECALC_GEOMETRY;
1868  }
1869 
1870  /* Tag object for update, so once memory critical operation is over and
1871  * scene update routines are back to its business the object will be
1872  * guaranteed to be in a known state.
1873  */
1874  if (update_flag != 0) {
1875  DEG_id_tag_update(&object->id, update_flag);
1876  }
1877 }
1878 
1880 {
1881  if (ob->data == nullptr) {
1882  return false;
1883  }
1884 
1885  switch (ob->type) {
1886  case OB_MESH:
1887  return ((Mesh *)ob->data)->edit_mesh != nullptr;
1888  case OB_ARMATURE:
1889  return ((bArmature *)ob->data)->edbo != nullptr;
1890  case OB_FONT:
1891  return ((Curve *)ob->data)->editfont != nullptr;
1892  case OB_MBALL:
1893  return ((MetaBall *)ob->data)->editelems != nullptr;
1894  case OB_LATTICE:
1895  return ((Lattice *)ob->data)->editlatt != nullptr;
1896  case OB_SURF:
1897  case OB_CURVES_LEGACY:
1898  return ((Curve *)ob->data)->editnurb != nullptr;
1899  case OB_GPENCIL:
1900  /* Grease Pencil object has no edit mode data. */
1901  return GPENCIL_EDIT_MODE((bGPdata *)ob->data);
1902  case OB_CURVES:
1903  return ob->mode == OB_MODE_EDIT;
1904  default:
1905  return false;
1906  }
1907 }
1908 
1910 {
1912 }
1913 
1914 bool BKE_object_data_is_in_editmode(const Object *ob, const ID *id)
1915 {
1916  const short type = GS(id->name);
1918  switch (type) {
1919  case ID_ME:
1920  return ((const Mesh *)id)->edit_mesh != nullptr;
1921  case ID_CU_LEGACY:
1922  return ((((const Curve *)id)->editnurb != nullptr) ||
1923  (((const Curve *)id)->editfont != nullptr));
1924  case ID_MB:
1925  return ((const MetaBall *)id)->editelems != nullptr;
1926  case ID_LT:
1927  return ((const Lattice *)id)->editlatt != nullptr;
1928  case ID_AR:
1929  return ((const bArmature *)id)->edbo != nullptr;
1930  case ID_CV:
1931  if (ob) {
1932  return BKE_object_is_in_editmode(ob);
1933  }
1934  return false;
1935  default:
1937  return false;
1938  }
1939 }
1940 
1942 {
1943  const short type = GS(id->name);
1944  switch (type) {
1945  case ID_ME: {
1946  BMEditMesh *em = ((Mesh *)id)->edit_mesh;
1947  if (em != nullptr) {
1948  return &em->needs_flush_to_id;
1949  }
1950  break;
1951  }
1952  case ID_CU_LEGACY: {
1953  if (((Curve *)id)->vfont != nullptr) {
1954  EditFont *ef = ((Curve *)id)->editfont;
1955  if (ef != nullptr) {
1956  return &ef->needs_flush_to_id;
1957  }
1958  }
1959  else {
1960  EditNurb *editnurb = ((Curve *)id)->editnurb;
1961  if (editnurb) {
1962  return &editnurb->needs_flush_to_id;
1963  }
1964  }
1965  break;
1966  }
1967  case ID_MB: {
1968  MetaBall *mb = (MetaBall *)id;
1969  return &mb->needs_flush_to_id;
1970  }
1971  case ID_LT: {
1972  EditLatt *editlatt = ((Lattice *)id)->editlatt;
1973  if (editlatt) {
1974  return &editlatt->needs_flush_to_id;
1975  }
1976  break;
1977  }
1978  case ID_AR: {
1979  bArmature *arm = (bArmature *)id;
1980  return &arm->needs_flush_to_id;
1981  }
1982  case ID_CV: {
1983  /* Curves have no edit mode data. */
1984  return nullptr;
1985  }
1986  default:
1988  return nullptr;
1989  }
1990  return nullptr;
1991 }
1992 
1994 {
1995  if (ob->type == OB_MESH) {
1996  Mesh *me = (Mesh *)ob->data;
1997  return ((ob->mode & OB_MODE_WEIGHT_PAINT) && (me->edit_mesh == nullptr) &&
1999  }
2000 
2001  return false;
2002 }
2003 
2004 bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode)
2005 {
2006  if (object_mode & OB_MODE_EDIT) {
2007  if (BKE_object_is_in_editmode(ob)) {
2008  return true;
2009  }
2010  }
2011  else if (object_mode & OB_MODE_VERTEX_PAINT) {
2012  if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) {
2013  return true;
2014  }
2015  }
2016  else if (object_mode & OB_MODE_WEIGHT_PAINT) {
2017  if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) {
2018  return true;
2019  }
2020  }
2021  else if (object_mode & OB_MODE_SCULPT) {
2022  if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) {
2023  return true;
2024  }
2025  }
2026  else if (object_mode & OB_MODE_POSE) {
2027  if (ob->pose != nullptr) {
2028  return true;
2029  }
2030  }
2031  return false;
2032 }
2033 
2034 bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode)
2035 {
2036  return ((ob->mode == object_mode) || (ob->mode & object_mode) != 0);
2037 }
2038 
2039 int BKE_object_visibility(const Object *ob, const int dag_eval_mode)
2040 {
2041  if ((ob->base_flag & BASE_VISIBLE_DEPSGRAPH) == 0) {
2042  return 0;
2043  }
2044 
2045  /* Test which components the object has. */
2046  int visibility = OB_VISIBLE_SELF;
2047  if (ob->particlesystem.first) {
2049  }
2050  else if (ob->transflag & OB_DUPLI) {
2051  visibility |= OB_VISIBLE_INSTANCES;
2052  }
2053 
2055  visibility |= OB_VISIBLE_INSTANCES;
2056  }
2057 
2058  /* Optional hiding of self if there are particles or instancers. */
2059  if (visibility & (OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES)) {
2060  switch ((eEvaluationMode)dag_eval_mode) {
2061  case DAG_EVAL_VIEWPORT:
2063  visibility &= ~OB_VISIBLE_SELF;
2064  }
2065  break;
2066  case DAG_EVAL_RENDER:
2068  visibility &= ~OB_VISIBLE_SELF;
2069  }
2070  break;
2071  }
2072  }
2073 
2074  return visibility;
2075 }
2076 
2077 bool BKE_object_exists_check(Main *bmain, const Object *obtest)
2078 {
2079  if (obtest == nullptr) {
2080  return false;
2081  }
2082 
2083  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
2084  if (ob == obtest) {
2085  return true;
2086  }
2087  }
2088 
2089  return false;
2090 }
2091 
2092 /* *************************************************** */
2093 
2094 static const char *get_obdata_defname(int type)
2095 {
2096  switch (type) {
2097  case OB_MESH:
2098  return DATA_("Mesh");
2099  case OB_CURVES_LEGACY:
2100  return DATA_("Curve");
2101  case OB_SURF:
2102  return DATA_("Surf");
2103  case OB_FONT:
2104  return DATA_("Text");
2105  case OB_MBALL:
2106  return DATA_("Mball");
2107  case OB_CAMERA:
2108  return DATA_("Camera");
2109  case OB_LAMP:
2110  return CTX_DATA_(BLT_I18NCONTEXT_ID_LIGHT, "Light");
2111  case OB_LATTICE:
2112  return DATA_("Lattice");
2113  case OB_ARMATURE:
2114  return DATA_("Armature");
2115  case OB_SPEAKER:
2116  return DATA_("Speaker");
2117  case OB_CURVES:
2118  return DATA_("Curves");
2119  case OB_POINTCLOUD:
2120  return DATA_("PointCloud");
2121  case OB_VOLUME:
2122  return DATA_("Volume");
2123  case OB_EMPTY:
2124  return DATA_("Empty");
2125  case OB_GPENCIL:
2126  return DATA_("GPencil");
2127  case OB_LIGHTPROBE:
2128  return DATA_("LightProbe");
2129  default:
2130  CLOG_ERROR(&LOG, "Internal error, bad type: %d", type);
2131  return DATA_("Empty");
2132  }
2133 }
2134 
2135 static void object_init(Object *ob, const short ob_type)
2136 {
2137  object_init_data(&ob->id);
2138 
2139  ob->type = ob_type;
2140 
2141  if (ob->type != OB_EMPTY) {
2142  zero_v2(ob->ima_ofs);
2143  }
2144 
2145  if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
2146  ob->trackflag = OB_NEGZ;
2147  ob->upflag = OB_POSY;
2148  }
2149 
2150  if (ob->type == OB_GPENCIL) {
2151  ob->dtx |= OB_USE_GPENCIL_LIGHTS;
2152  }
2153 
2154  if (ob->type == OB_LAMP) {
2155  /* Lights are invisible to camera rays and are assumed to be a
2156  * shadow catcher by default. */
2158  }
2159 }
2160 
2161 void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
2162 {
2163  if (name == nullptr) {
2164  name = get_obdata_defname(type);
2165  }
2166 
2167  switch (type) {
2168  case OB_MESH:
2169  return BKE_mesh_add(bmain, name);
2170  case OB_CURVES_LEGACY:
2171  return BKE_curve_add(bmain, name, OB_CURVES_LEGACY);
2172  case OB_SURF:
2173  return BKE_curve_add(bmain, name, OB_SURF);
2174  case OB_FONT:
2175  return BKE_curve_add(bmain, name, OB_FONT);
2176  case OB_MBALL:
2177  return BKE_mball_add(bmain, name);
2178  case OB_CAMERA:
2179  return BKE_camera_add(bmain, name);
2180  case OB_LAMP:
2181  return BKE_light_add(bmain, name);
2182  case OB_LATTICE:
2183  return BKE_lattice_add(bmain, name);
2184  case OB_ARMATURE:
2185  return BKE_armature_add(bmain, name);
2186  case OB_SPEAKER:
2187  return BKE_speaker_add(bmain, name);
2188  case OB_LIGHTPROBE:
2189  return BKE_lightprobe_add(bmain, name);
2190  case OB_GPENCIL:
2191  return BKE_gpencil_data_addnew(bmain, name);
2192  case OB_CURVES:
2193  return BKE_curves_add(bmain, name);
2194  case OB_POINTCLOUD:
2195  return BKE_pointcloud_add_default(bmain, name);
2196  case OB_VOLUME:
2197  return BKE_volume_add(bmain, name);
2198  case OB_EMPTY:
2199  return nullptr;
2200  default:
2201  CLOG_ERROR(&LOG, "Internal error, bad type: %d", type);
2202  return nullptr;
2203  }
2204 }
2205 
2207 {
2208  /* Keep in sync with #OB_DATA_SUPPORT_ID macro. */
2209  switch (GS(id->name)) {
2210  case ID_ME:
2211  return OB_MESH;
2212  case ID_CU_LEGACY:
2213  return BKE_curve_type_get((const Curve *)id);
2214  case ID_MB:
2215  return OB_MBALL;
2216  case ID_LA:
2217  return OB_LAMP;
2218  case ID_SPK:
2219  return OB_SPEAKER;
2220  case ID_CA:
2221  return OB_CAMERA;
2222  case ID_LT:
2223  return OB_LATTICE;
2224  case ID_GD:
2225  return OB_GPENCIL;
2226  case ID_AR:
2227  return OB_ARMATURE;
2228  case ID_LP:
2229  return OB_LIGHTPROBE;
2230  case ID_CV:
2231  return OB_CURVES;
2232  case ID_PT:
2233  return OB_POINTCLOUD;
2234  case ID_VO:
2235  return OB_VOLUME;
2236  default:
2237  return -1;
2238  }
2239 }
2240 
2241 Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
2242 {
2243  if (!name) {
2244  name = get_obdata_defname(type);
2245  }
2246 
2247  /* We cannot use #BKE_id_new here as we need some custom initialization code. */
2248  Object *ob = (Object *)BKE_libblock_alloc(bmain, ID_OB, name, bmain ? 0 : LIB_ID_CREATE_NO_MAIN);
2249 
2250  /* We increase object user count when linking to Collections. */
2251  id_us_min(&ob->id);
2252 
2253  /* default object vars */
2254  object_init(ob, type);
2255 
2256  return ob;
2257 }
2258 
2259 static Object *object_add_common(Main *bmain, ViewLayer *view_layer, int type, const char *name)
2260 {
2261  Object *ob = BKE_object_add_only_object(bmain, type, name);
2262  ob->data = BKE_object_obdata_add_from_type(bmain, type, name);
2264 
2267  return ob;
2268 }
2269 
2270 Object *BKE_object_add(Main *bmain, ViewLayer *view_layer, int type, const char *name)
2271 {
2272  Object *ob = object_add_common(bmain, view_layer, type, name);
2273 
2274  LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
2275  BKE_collection_viewlayer_object_add(bmain, view_layer, layer_collection->collection, ob);
2276 
2277  /* NOTE: There is no way to be sure that #BKE_collection_viewlayer_object_add will actually
2278  * manage to find a valid collection in given `view_layer` to add the new object to. */
2279  Base *base = BKE_view_layer_base_find(view_layer, ob);
2280  if (base != nullptr) {
2282  }
2283 
2284  return ob;
2285 }
2286 
2288  Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name, Object *ob_src)
2289 {
2290  Object *ob = object_add_common(bmain, view_layer, type, name);
2291  BKE_collection_object_add_from(bmain, scene, ob_src, ob);
2292 
2293  Base *base = BKE_view_layer_base_find(view_layer, ob);
2295 
2296  return ob;
2297 }
2298 
2300  Main *bmain, ViewLayer *view_layer, int type, const char *name, ID *data, bool do_id_user)
2301 {
2302  /* same as object_add_common, except we don't create new ob->data */
2303  Object *ob = BKE_object_add_only_object(bmain, type, name);
2304  ob->data = (void *)data;
2305  if (do_id_user) {
2306  id_us_plus(data);
2307  }
2308 
2312 
2313  LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
2314  BKE_collection_object_add(bmain, layer_collection->collection, ob);
2315 
2316  Base *base = BKE_view_layer_base_find(view_layer, ob);
2318 
2319  return ob;
2320 }
2321 
2322 void BKE_object_copy_softbody(Object *ob_dst, const Object *ob_src, const int flag)
2323 {
2324  SoftBody *sb = ob_src->soft;
2325  const bool is_orig = (flag & LIB_ID_COPY_SET_COPIED_ON_WRITE) == 0;
2326 
2327  ob_dst->softflag = ob_src->softflag;
2328  if (sb == nullptr) {
2329  ob_dst->soft = nullptr;
2330  return;
2331  }
2332 
2333  SoftBody *sbn = (SoftBody *)MEM_dupallocN(sb);
2334 
2335  if ((flag & LIB_ID_COPY_CACHES) == 0) {
2336  sbn->totspring = sbn->totpoint = 0;
2337  sbn->bpoint = nullptr;
2338  sbn->bspring = nullptr;
2339  }
2340  else {
2341  sbn->totspring = sb->totspring;
2342  sbn->totpoint = sb->totpoint;
2343 
2344  if (sbn->bpoint) {
2345  int i;
2346 
2347  sbn->bpoint = (BodyPoint *)MEM_dupallocN(sbn->bpoint);
2348 
2349  for (i = 0; i < sbn->totpoint; i++) {
2350  if (sbn->bpoint[i].springs) {
2351  sbn->bpoint[i].springs = (int *)MEM_dupallocN(sbn->bpoint[i].springs);
2352  }
2353  }
2354  }
2355 
2356  if (sb->bspring) {
2357  sbn->bspring = (struct BodySpring *)MEM_dupallocN(sb->bspring);
2358  }
2359  }
2360 
2361  sbn->keys = nullptr;
2362  sbn->totkey = sbn->totpointkey = 0;
2363 
2364  sbn->scratch = nullptr;
2365 
2366  if (is_orig) {
2367  sbn->shared = (SoftBody_Shared *)MEM_dupallocN(sb->shared);
2369  &sbn->shared->ptcaches, &sb->shared->ptcaches, flag);
2370  }
2371 
2372  if (sb->effector_weights) {
2374  }
2375 
2376  ob_dst->soft = sbn;
2377 }
2378 
2380 {
2381  ParticleSystem *psysn = (ParticleSystem *)MEM_dupallocN(psys);
2382 
2383  psys_copy_particles(psysn, psys);
2384 
2385  if (psys->clmd) {
2388  psys->hair_in_mesh = psys->hair_out_mesh = nullptr;
2389  }
2390 
2391  BLI_duplicatelist(&psysn->targets, &psys->targets);
2392 
2393  psysn->pathcache = nullptr;
2394  psysn->childcache = nullptr;
2395  psysn->edit = nullptr;
2396  psysn->pdd = nullptr;
2397  psysn->effectors = nullptr;
2398  psysn->tree = nullptr;
2399  psysn->bvhtree = nullptr;
2400  psysn->batch_cache = nullptr;
2401 
2404 
2406  /* XXX Disabled, fails when evaluating depsgraph after copying ID with no main for preview
2407  * creation. */
2408  // BLI_assert((psys->flag & PSYS_SHARED_CACHES) == 0);
2409  psysn->flag |= PSYS_SHARED_CACHES;
2410  BLI_assert(psysn->pointcache != nullptr);
2411  }
2412  else {
2413  psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, flag);
2414  }
2415 
2416  /* XXX(@campbellbarton): from reading existing code this seems correct but intended usage of
2417  * point-cache should /w cloth should be added in 'ParticleSystem'. */
2418  if (psysn->clmd) {
2419  psysn->clmd->point_cache = psysn->pointcache;
2420  }
2421 
2422  if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
2423  id_us_plus((ID *)psysn->part);
2424  }
2425 
2426  return psysn;
2427 }
2428 
2429 void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, const int flag)
2430 {
2431  if (ob_dst->type != OB_MESH) {
2432  /* currently only mesh objects can have soft body */
2433  return;
2434  }
2435 
2437  LISTBASE_FOREACH (ParticleSystem *, psys, &ob_src->particlesystem) {
2439 
2440  BLI_addtail(&ob_dst->particlesystem, npsys);
2441 
2442  /* need to update particle modifiers too */
2443  LISTBASE_FOREACH (ModifierData *, md, &ob_dst->modifiers) {
2444  if (md->type == eModifierType_ParticleSystem) {
2446  if (psmd->psys == psys) {
2447  psmd->psys = npsys;
2448  }
2449  }
2450  else if (md->type == eModifierType_DynamicPaint) {
2452  if (pmd->brush) {
2453  if (pmd->brush->psys == psys) {
2454  pmd->brush->psys = npsys;
2455  }
2456  }
2457  }
2458  else if (md->type == eModifierType_Fluid) {
2459  FluidModifierData *fmd = (FluidModifierData *)md;
2460 
2461  if (fmd->type == MOD_FLUID_TYPE_FLOW) {
2462  if (fmd->flow) {
2463  if (fmd->flow->psys == psys) {
2464  fmd->flow->psys = npsys;
2465  }
2466  }
2467  }
2468  }
2469  }
2470  }
2471 }
2472 
2473 static void copy_object_pose(Object *obn, const Object *ob, const int flag)
2474 {
2475  /* NOTE: need to clear obn->pose pointer first,
2476  * so that BKE_pose_copy_data works (otherwise there's a crash) */
2477  obn->pose = nullptr;
2478  BKE_pose_copy_data_ex(&obn->pose, ob->pose, flag, true); /* true = copy constraints */
2479 
2480  LISTBASE_FOREACH (bPoseChannel *, chan, &obn->pose->chanbase) {
2481  chan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE);
2482 
2483  /* XXX Remapping object pointing onto itself should be handled by generic
2484  * BKE_library_remap stuff, but...
2485  * the flush_constraint_targets callback am not sure about, so will delay that for now. */
2486  LISTBASE_FOREACH (bConstraint *, con, &chan->constraints) {
2487  ListBase targets = {nullptr, nullptr};
2488 
2489  if (BKE_constraint_targets_get(con, &targets)) {
2490  LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) {
2491  if (ct->tar == ob) {
2492  ct->tar = obn;
2493  }
2494  }
2495 
2496  BKE_constraint_targets_flush(con, &targets, false);
2497  }
2498  }
2499  }
2500 }
2501 
2503 {
2504  if ((ob) && (ob->type == OB_ARMATURE) && (ob->pose) && (ob->mode & OB_MODE_POSE)) {
2505  return true;
2506  }
2507 
2508  return false;
2509 }
2510 
2512 {
2513  if (ob == nullptr) {
2514  return nullptr;
2515  }
2516 
2518  return ob;
2519  }
2520 
2522 
2523  /* Only use selected check when non-active. */
2525  return ob;
2526  }
2527 
2528  return nullptr;
2529 }
2530 
2532 {
2533  /* When not in weight paint mode. */
2534  if (ob) {
2535  switch (ob->type) {
2536  case OB_MESH: {
2537  if ((ob->mode & OB_MODE_WEIGHT_PAINT) == 0) {
2538  return nullptr;
2539  }
2540  break;
2541  }
2542  case OB_GPENCIL: {
2543  if ((ob->mode & OB_MODE_WEIGHT_GPENCIL) == 0) {
2544  return nullptr;
2545  }
2546  break;
2547  }
2548  }
2549  }
2550  return BKE_object_pose_armature_get(ob);
2551 }
2552 
2554 {
2555  Object *ob_armature = BKE_object_pose_armature_get(ob);
2556  if (ob_armature) {
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  View3D *v3d,
2569  uint *r_objects_len,
2570  bool unique)
2571 {
2572  Object *ob_active = OBACT(view_layer);
2573  Object *ob_pose = BKE_object_pose_armature_get(ob_active);
2574  Object **objects = nullptr;
2575  if (ob_pose == ob_active) {
2576  ObjectsInModeParams ob_params{};
2577  ob_params.object_mode = OB_MODE_POSE;
2578  ob_params.no_dup_data = unique;
2579 
2581  view_layer, v3d, r_objects_len, &ob_params);
2582  }
2583  else if (ob_pose != nullptr) {
2584  *r_objects_len = 1;
2585  objects = (Object **)MEM_mallocN(sizeof(*objects), __func__);
2586  objects[0] = ob_pose;
2587  }
2588  else {
2589  *r_objects_len = 0;
2590  objects = (Object **)MEM_mallocN(0, __func__);
2591  }
2592  return objects;
2593 }
2594 Object **BKE_object_pose_array_get_unique(ViewLayer *view_layer, View3D *v3d, uint *r_objects_len)
2595 {
2596  return BKE_object_pose_array_get_ex(view_layer, v3d, r_objects_len, true);
2597 }
2598 Object **BKE_object_pose_array_get(ViewLayer *view_layer, View3D *v3d, uint *r_objects_len)
2599 {
2600  return BKE_object_pose_array_get_ex(view_layer, v3d, r_objects_len, false);
2601 }
2602 
2604  View3D *v3d,
2605  uint *r_bases_len,
2606  bool unique)
2607 {
2608  Base *base_active = BASACT(view_layer);
2609  Object *ob_pose = base_active ? BKE_object_pose_armature_get(base_active->object) : nullptr;
2610  Base *base_pose = nullptr;
2611  Base **bases = nullptr;
2612 
2613  if (base_active) {
2614  if (ob_pose == base_active->object) {
2615  base_pose = base_active;
2616  }
2617  else {
2618  base_pose = BKE_view_layer_base_find(view_layer, ob_pose);
2619  }
2620  }
2621 
2622  if (base_active && (base_pose == base_active)) {
2623  ObjectsInModeParams ob_params{};
2624  ob_params.object_mode = OB_MODE_POSE;
2625  ob_params.no_dup_data = unique;
2626 
2628  view_layer, v3d, r_bases_len, &ob_params);
2629  }
2630  else if (base_pose != nullptr) {
2631  *r_bases_len = 1;
2632  bases = (Base **)MEM_mallocN(sizeof(*bases), __func__);
2633  bases[0] = base_pose;
2634  }
2635  else {
2636  *r_bases_len = 0;
2637  bases = (Base **)MEM_mallocN(0, __func__);
2638  }
2639  return bases;
2640 }
2642 {
2643  return BKE_object_pose_base_array_get_ex(view_layer, v3d, r_bases_len, true);
2644 }
2645 Base **BKE_object_pose_base_array_get(ViewLayer *view_layer, View3D *v3d, uint *r_bases_len)
2646 {
2647  return BKE_object_pose_base_array_get_ex(view_layer, v3d, r_bases_len, false);
2648 }
2649 
2650 void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
2651 {
2652  copy_v3_v3(ob_tar->loc, ob_src->loc);
2653  copy_v3_v3(ob_tar->rot, ob_src->rot);
2654  copy_v4_v4(ob_tar->quat, ob_src->quat);
2655  copy_v3_v3(ob_tar->rotAxis, ob_src->rotAxis);
2656  ob_tar->rotAngle = ob_src->rotAngle;
2657  ob_tar->rotmode = ob_src->rotmode;
2658  copy_v3_v3(ob_tar->scale, ob_src->scale);
2659 }
2660 
2661 Object *BKE_object_duplicate(Main *bmain, Object *ob, uint dupflag, uint duplicate_options)
2662 {
2663  const bool is_subprocess = (duplicate_options & LIB_ID_DUPLICATE_IS_SUBPROCESS) != 0;
2664  const bool is_root_id = (duplicate_options & LIB_ID_DUPLICATE_IS_ROOT_ID) != 0;
2665  int copy_flags = LIB_ID_COPY_DEFAULT;
2666 
2667  if (!is_subprocess) {
2669  }
2670  else {
2671  /* In case copying object is a sub-process of collection (or scene) copying, do not try to
2672  * re-assign RB objects to existing RBW collections. */
2674  }
2675  if (is_root_id) {
2676  /* In case root duplicated ID is linked, assume we want to get a local copy of it and duplicate
2677  * all expected linked data. */
2678  if (ID_IS_LINKED(ob)) {
2679  dupflag |= USER_DUP_LINKED_ID;
2680  }
2681  duplicate_options &= ~LIB_ID_DUPLICATE_IS_ROOT_ID;
2682  }
2683 
2684  Material ***matarar;
2685 
2686  Object *obn = (Object *)BKE_id_copy_for_duplicate(bmain, &ob->id, dupflag, copy_flags);
2687 
2688  /* 0 == full linked. */
2689  if (dupflag == 0) {
2690  return obn;
2691  }
2692 
2693  if (dupflag & USER_DUP_MAT) {
2694  for (int i = 0; i < obn->totcol; i++) {
2695  BKE_id_copy_for_duplicate(bmain, (ID *)obn->mat[i], dupflag, copy_flags);
2696  }
2697  }
2698  if (dupflag & USER_DUP_PSYS) {
2700  BKE_id_copy_for_duplicate(bmain, (ID *)psys->part, dupflag, copy_flags);
2701  }
2702  }
2703 
2704  ID *id_old = (ID *)obn->data;
2705  ID *id_new = nullptr;
2706  const bool need_to_duplicate_obdata = (id_old != nullptr) && (id_old->newid == nullptr);
2707 
2708  switch (obn->type) {
2709  case OB_MESH:
2710  if (dupflag & USER_DUP_MESH) {
2711  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2712  }
2713  break;
2714  case OB_CURVES_LEGACY:
2715  if (dupflag & USER_DUP_CURVE) {
2716  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2717  }
2718  break;
2719  case OB_SURF:
2720  if (dupflag & USER_DUP_SURF) {
2721  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2722  }
2723  break;
2724  case OB_FONT:
2725  if (dupflag & USER_DUP_FONT) {
2726  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2727  }
2728  break;
2729  case OB_MBALL:
2730  if (dupflag & USER_DUP_MBALL) {
2731  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2732  }
2733  break;
2734  case OB_LAMP:
2735  if (dupflag & USER_DUP_LAMP) {
2736  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2737  }
2738  break;
2739  case OB_ARMATURE:
2740  if (dupflag & USER_DUP_ARM) {
2741  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2742  }
2743  break;
2744  case OB_LATTICE:
2745  if (dupflag & USER_DUP_LATTICE) {
2746  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2747  }
2748  break;
2749  case OB_CAMERA:
2750  if (dupflag & USER_DUP_CAMERA) {
2751  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2752  }
2753  break;
2754  case OB_LIGHTPROBE:
2755  if (dupflag & USER_DUP_LIGHTPROBE) {
2756  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2757  }
2758  break;
2759  case OB_SPEAKER:
2760  if (dupflag & USER_DUP_SPEAKER) {
2761  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2762  }
2763  break;
2764  case OB_GPENCIL:
2765  if (dupflag & USER_DUP_GPENCIL) {
2766  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2767  }
2768  break;
2769  case OB_CURVES:
2770  if (dupflag & USER_DUP_CURVES) {
2771  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2772  }
2773  break;
2774  case OB_POINTCLOUD:
2775  if (dupflag & USER_DUP_POINTCLOUD) {
2776  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2777  }
2778  break;
2779  case OB_VOLUME:
2780  if (dupflag & USER_DUP_VOLUME) {
2781  id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
2782  }
2783  break;
2784  }
2785 
2786  /* If obdata has been copied, we may also have to duplicate the materials assigned to it. */
2787  if (need_to_duplicate_obdata && !ELEM(id_new, nullptr, id_old)) {
2788  if (dupflag & USER_DUP_MAT) {
2789  matarar = BKE_object_material_array_p(obn);
2790  if (matarar) {
2791  for (int i = 0; i < obn->totcol; i++) {
2792  BKE_id_copy_for_duplicate(bmain, (ID *)(*matarar)[i], dupflag, copy_flags);
2793  }
2794  }
2795  }
2796  }
2797 
2798  if (!is_subprocess) {
2799  /* This code will follow into all ID links using an ID tagged with LIB_TAG_NEW. */
2800  BKE_libblock_relink_to_newid(bmain, &obn->id, 0);
2801 
2802 #ifndef NDEBUG
2803  /* Call to `BKE_libblock_relink_to_newid` above is supposed to have cleared all those flags. */
2804  ID *id_iter;
2805  FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
2806  BLI_assert((id_iter->tag & LIB_TAG_NEW) == 0);
2807  }
2809 #endif
2810 
2811  /* Cleanup. */
2813  }
2814 
2815  if (obn->type == OB_ARMATURE) {
2817  if (obn->pose) {
2818  BKE_pose_tag_recalc(bmain, obn->pose);
2819  }
2820  // BKE_pose_rebuild(bmain, obn, obn->data, true);
2821  }
2822 
2823  if (obn->data != nullptr) {
2824  DEG_id_tag_update_ex(bmain, (ID *)obn->data, ID_RECALC_EDITORS);
2825  }
2826 
2827  return obn;
2828 }
2829 
2831 {
2832  return (ob && ID_IS_LINKED(ob));
2833 }
2834 
2836 {
2837  /* Linked objects with local obdata are forbidden! */
2838  BLI_assert(!ob || !ob->data || (ID_IS_LINKED(ob) ? ID_IS_LINKED(ob->data) : true));
2839  return (ob && ob->data && ID_IS_LINKED(ob->data));
2840 }
2841 
2842 void BKE_object_obdata_size_init(struct Object *ob, const float size)
2843 {
2844  /* apply radius as a scale to types that support it */
2845  switch (ob->type) {
2846  case OB_EMPTY: {
2847  ob->empty_drawsize *= size;
2848  break;
2849  }
2850  case OB_FONT: {
2851  Curve *cu = (Curve *)ob->data;
2852  cu->fsize *= size;
2853  break;
2854  }
2855  case OB_CAMERA: {
2856  Camera *cam = (Camera *)ob->data;
2857  cam->drawsize *= size;
2858  break;
2859  }
2860  case OB_LAMP: {
2861  Light *lamp = (Light *)ob->data;
2862  lamp->dist *= size;
2863  lamp->area_size *= size;
2864  lamp->area_sizey *= size;
2865  lamp->area_sizez *= size;
2866  break;
2867  }
2868  /* Only lattice (not mesh, curve, mball...),
2869  * because its got data when newly added */
2870  case OB_LATTICE: {
2871  Lattice *lt = (Lattice *)ob->data;
2872  float mat[4][4];
2873 
2874  unit_m4(mat);
2875  scale_m4_fl(mat, size);
2876 
2877  BKE_lattice_transform(lt, (float(*)[4])mat, false);
2878  break;
2879  }
2880  }
2881 }
2882 
2883 /* -------------------------------------------------------------------- */
2887 void BKE_object_scale_to_mat3(Object *ob, float mat[3][3])
2888 {
2889  float3 vec;
2890  mul_v3_v3v3(vec, ob->scale, ob->dscale);
2891  size_to_mat3(mat, vec);
2892 }
2893 
2894 void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot)
2895 {
2896  float rmat[3][3], dmat[3][3];
2897 
2898  /* 'dmat' is the delta-rotation matrix, which will get (pre)multiplied
2899  * with the rotation matrix to yield the appropriate rotation
2900  */
2901 
2902  /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */
2903  if (ob->rotmode > 0) {
2904  /* Euler rotations
2905  * (will cause gimbal lock, but this can be alleviated a bit with rotation orders). */
2906  eulO_to_mat3(rmat, ob->rot, ob->rotmode);
2907  eulO_to_mat3(dmat, ob->drot, ob->rotmode);
2908  }
2909  else if (ob->rotmode == ROT_MODE_AXISANGLE) {
2910  /* axis-angle - not really that great for 3D-changing orientations */
2911  axis_angle_to_mat3(rmat, ob->rotAxis, ob->rotAngle);
2912  axis_angle_to_mat3(dmat, ob->drotAxis, ob->drotAngle);
2913  }
2914  else {
2915  /* quats are normalized before use to eliminate scaling issues */
2916  float tquat[4];
2917 
2918  normalize_qt_qt(tquat, ob->quat);
2919  quat_to_mat3(rmat, tquat);
2920 
2921  normalize_qt_qt(tquat, ob->dquat);
2922  quat_to_mat3(dmat, tquat);
2923  }
2924 
2925  /* combine these rotations */
2926  if (use_drot) {
2927  mul_m3_m3m3(mat, dmat, rmat);
2928  }
2929  else {
2930  copy_m3_m3(mat, rmat);
2931  }
2932 }
2933 
2934 void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
2935 {
2936  BLI_ASSERT_UNIT_M3(mat);
2937 
2938  switch (ob->rotmode) {
2939  case ROT_MODE_QUAT: {
2940  float dquat[4];
2941  mat3_normalized_to_quat(ob->quat, mat);
2942  normalize_qt_qt(dquat, ob->dquat);
2943  invert_qt_normalized(dquat);
2944  mul_qt_qtqt(ob->quat, dquat, ob->quat);
2945  break;
2946  }
2947  case ROT_MODE_AXISANGLE: {
2948  float quat[4];
2949  float dquat[4];
2950 
2951  /* without drot we could apply 'mat' directly */
2952  mat3_normalized_to_quat(quat, mat);
2953  axis_angle_to_quat(dquat, ob->drotAxis, ob->drotAngle);
2954  invert_qt_normalized(dquat);
2955  mul_qt_qtqt(quat, dquat, quat);
2956  quat_to_axis_angle(ob->rotAxis, &ob->rotAngle, quat);
2957  break;
2958  }
2959  default: /* euler */
2960  {
2961  float quat[4];
2962  float dquat[4];
2963 
2964  /* without drot we could apply 'mat' directly */
2965  mat3_normalized_to_quat(quat, mat);
2966  eulO_to_quat(dquat, ob->drot, ob->rotmode);
2967  invert_qt_normalized(dquat);
2968  mul_qt_qtqt(quat, dquat, quat);
2969  /* end drot correction */
2970 
2971  if (use_compat) {
2972  quat_to_compatible_eulO(ob->rot, ob->rot, ob->rotmode, quat);
2973  }
2974  else {
2975  quat_to_eulO(ob->rot, ob->rotmode, quat);
2976  }
2977  break;
2978  }
2979  }
2980 }
2981 
2983 {
2984 
2985 #define TFMCPY(_v) (obtfm->_v = ob->_v)
2986 #define TFMCPY3D(_v) copy_v3_v3(obtfm->_v, ob->_v)
2987 #define TFMCPY4D(_v) copy_v4_v4(obtfm->_v, ob->_v)
2988 
2989  TFMCPY3D(loc);
2990  TFMCPY3D(dloc);
2991  TFMCPY3D(scale);
2992  TFMCPY3D(dscale);
2993  TFMCPY3D(rot);
2994  TFMCPY3D(drot);
2995  TFMCPY4D(quat);
2996  TFMCPY4D(dquat);
2997  TFMCPY3D(rotAxis);
2998  TFMCPY3D(drotAxis);
2999  TFMCPY(rotAngle);
3000  TFMCPY(drotAngle);
3001 
3002 #undef TFMCPY
3003 #undef TFMCPY3D
3004 #undef TFMCPY4D
3005 }
3006 
3008  const ObjectTfmProtectedChannels *obtfm,
3009  const short protectflag)
3010 {
3011  unsigned int i;
3012 
3013  for (i = 0; i < 3; i++) {
3014  if (protectflag & (OB_LOCK_LOCX << i)) {
3015  ob->loc[i] = obtfm->loc[i];
3016  ob->dloc[i] = obtfm->dloc[i];
3017  }
3018 
3019  if (protectflag & (OB_LOCK_SCALEX << i)) {
3020  ob->scale[i] = obtfm->scale[i];
3021  ob->dscale[i] = obtfm->dscale[i];
3022  }
3023 
3024  if (protectflag & (OB_LOCK_ROTX << i)) {
3025  ob->rot[i] = obtfm->rot[i];
3026  ob->drot[i] = obtfm->drot[i];
3027 
3028  ob->quat[i + 1] = obtfm->quat[i + 1];
3029  ob->dquat[i + 1] = obtfm->dquat[i + 1];
3030 
3031  ob->rotAxis[i] = obtfm->rotAxis[i];
3032  ob->drotAxis[i] = obtfm->drotAxis[i];
3033  }
3034  }
3035 
3036  if ((protectflag & OB_LOCK_ROT4D) && (protectflag & OB_LOCK_ROTW)) {
3037  ob->quat[0] = obtfm->quat[0];
3038  ob->dquat[0] = obtfm->dquat[0];
3039 
3040  ob->rotAngle = obtfm->rotAngle;
3041  ob->drotAngle = obtfm->drotAngle;
3042  }
3043 }
3044 
3045 void BKE_object_tfm_copy(Object *object_dst, const Object *object_src)
3046 {
3047 #define TFMCPY(_v) (object_dst->_v = object_src->_v)
3048 #define TFMCPY3D(_v) copy_v3_v3(object_dst->_v, object_src->_v)
3049 #define TFMCPY4D(_v) copy_v4_v4(object_dst->_v, object_src->_v)
3050 
3051  TFMCPY3D(loc);
3052  TFMCPY3D(dloc);
3053  TFMCPY3D(scale);
3054  TFMCPY3D(dscale);
3055  TFMCPY3D(rot);
3056  TFMCPY3D(drot);
3057  TFMCPY4D(quat);
3058  TFMCPY4D(dquat);
3059  TFMCPY3D(rotAxis);
3060  TFMCPY3D(drotAxis);
3061  TFMCPY(rotAngle);
3062  TFMCPY(drotAngle);
3063 
3064 #undef TFMCPY
3065 #undef TFMCPY3D
3066 #undef TFMCPY4D
3067 }
3068 
3069 void BKE_object_to_mat3(Object *ob, float r_mat[3][3]) /* no parent */
3070 {
3071  float smat[3][3];
3072  float rmat[3][3];
3073 
3074  /* Scale. */
3075  BKE_object_scale_to_mat3(ob, smat);
3076 
3077  /* Rotation. */
3078  BKE_object_rot_to_mat3(ob, rmat, true);
3079  mul_m3_m3m3(r_mat, rmat, smat);
3080 }
3081 
3082 void BKE_object_to_mat4(Object *ob, float r_mat[4][4])
3083 {
3084  float tmat[3][3];
3085 
3086  BKE_object_to_mat3(ob, tmat);
3087 
3088  copy_m4_m3(r_mat, tmat);
3089 
3090  add_v3_v3v3(r_mat[3], ob->loc, ob->dloc);
3091 }
3092 
3093 void BKE_object_matrix_local_get(struct Object *ob, float r_mat[4][4])
3094 {
3095  if (ob->parent) {
3096  float par_imat[4][4];
3097 
3098  BKE_object_get_parent_matrix(ob, ob->parent, par_imat);
3099  invert_m4(par_imat);
3100  mul_m4_m4m4(r_mat, par_imat, ob->obmat);
3101  }
3102  else {
3103  copy_m4_m4(r_mat, ob->obmat);
3104  }
3105 }
3106 
3110 static bool ob_parcurve(Object *ob, Object *par, float r_mat[4][4])
3111 {
3112  Curve *cu = (Curve *)par->data;
3113  float vec[4], quat[4], radius, ctime;
3114 
3115  /* NOTE: Curve cache is supposed to be evaluated here already, however there
3116  * are cases where we can not guarantee that. This includes, for example,
3117  * dependency cycles. We can't correct anything from here, since that would
3118  * cause threading conflicts.
3119  *
3120  * TODO(sergey): Some of the legit looking cases like T56619 need to be
3121  * looked into, and maybe curve cache (and other dependencies) are to be
3122  * evaluated prior to conversion. */
3123  if (par->runtime.curve_cache == nullptr) {
3124  return false;
3125  }
3126  if (par->runtime.curve_cache->anim_path_accum_length == nullptr) {
3127  return false;
3128  }
3129 
3130  /* ctime is now a proper var setting of Curve which gets set by Animato like any other var
3131  * that's animated, but this will only work if it actually is animated.
3132  *
3133  * We divide the curve-time calculated in the previous step by the length of the path,
3134  * to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range.
3135  */
3136  if (cu->pathlen) {
3137  ctime = cu->ctime / cu->pathlen;
3138  }
3139  else {
3140  ctime = cu->ctime;
3141  }
3142 
3143  if (cu->flag & CU_PATH_CLAMP) {
3144  CLAMP(ctime, 0.0f, 1.0f);
3145  }
3146 
3147  unit_m4(r_mat);
3148 
3149  /* vec: 4 items! */
3150  if (BKE_where_on_path(
3151  par, ctime, vec, nullptr, (cu->flag & CU_FOLLOW) ? quat : nullptr, &radius, nullptr)) {
3152  if (cu->flag & CU_FOLLOW) {
3153  quat_apply_track(quat, ob->trackflag, ob->upflag);
3154  normalize_qt(quat);
3155  quat_to_mat4(r_mat, quat);
3156  }
3157  if (cu->flag & CU_PATH_RADIUS) {
3158  float tmat[4][4], rmat[4][4];
3159  scale_m4_fl(tmat, radius);
3160  mul_m4_m4m4(rmat, tmat, r_mat);
3161  copy_m4_m4(r_mat, rmat);
3162  }
3163  copy_v3_v3(r_mat[3], vec);
3164  }
3165 
3166  return true;
3167 }
3168 
3169 static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
3170 {
3171  float3 vec;
3172 
3173  if (par->type != OB_ARMATURE) {
3174  unit_m4(r_mat);
3175  return;
3176  }
3177 
3178  /* Make sure the bone is still valid */
3180  if (!pchan || !pchan->bone) {
3181  CLOG_WARN(
3182  &LOG, "Parent Bone: '%s' for Object: '%s' doesn't exist", ob->parsubstr, ob->id.name + 2);
3183  unit_m4(r_mat);
3184  return;
3185  }
3186 
3187  /* get bone transform */
3188  if (pchan->bone->flag & BONE_RELATIVE_PARENTING) {
3189  /* the new option uses the root - expected behavior, but differs from old... */
3190  /* XXX check on version patching? */
3191  copy_m4_m4(r_mat, pchan->chan_mat);
3192  }
3193  else {
3194  copy_m4_m4(r_mat, pchan->pose_mat);
3195 
3196  /* but for backwards compatibility, the child has to move to the tail */
3197  copy_v3_v3(vec, r_mat[1]);
3198  mul_v3_fl(vec, pchan->bone->length);
3199  add_v3_v3(r_mat[3], vec);
3200  }
3201 }
3202 
3203 static void give_parvert(Object *par, int nr, float vec[3])
3204 {
3205  zero_v3(vec);
3206 
3207  if (par->type == OB_MESH) {
3208  Mesh *me = (Mesh *)par->data;
3209  BMEditMesh *em = me->edit_mesh;
3210  Mesh *me_eval = (em) ? BKE_object_get_editmesh_eval_final(par) :
3212 
3213  if (me_eval) {
3214  int count = 0;
3215  int numVerts = me_eval->totvert;
3216 
3217  if (em && me_eval->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH) {
3218  numVerts = em->bm->totvert;
3219  if (em->bm->elem_table_dirty & BM_VERT) {
3220 #ifdef VPARENT_THREADING_HACK
3222  if (em->bm->elem_table_dirty & BM_VERT) {
3224  }
3226 #else
3227  BLI_assert_msg(0, "Not safe for threading");
3229 #endif
3230  }
3231  if (nr < numVerts) {
3232  if (me_eval && me_eval->runtime.edit_data && me_eval->runtime.edit_data->vertexCos) {
3233  add_v3_v3(vec, me_eval->runtime.edit_data->vertexCos[nr]);
3234  }
3235  else {
3236  const BMVert *v = BM_vert_at_index(em->bm, nr);
3237  add_v3_v3(vec, v->co);
3238  }
3239  count++;
3240  }
3241  }
3242  else if (CustomData_has_layer(&me_eval->vdata, CD_ORIGINDEX)) {
3243  const int *index = (const int *)CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
3244  /* Get the average of all verts with (original index == nr). */
3245  for (int i = 0; i < numVerts; i++) {
3246  if (index[i] == nr) {
3247  add_v3_v3(vec, me_eval->mvert[i].co);
3248  count++;
3249  }
3250  }
3251  }
3252  else {
3253  if (nr < numVerts) {
3254  add_v3_v3(vec, me_eval->mvert[nr].co);
3255  count++;
3256  }
3257  }
3258 
3259  if (count == 0) {
3260  /* keep as 0, 0, 0 */
3261  }
3262  else if (count > 0) {
3263  mul_v3_fl(vec, 1.0f / count);
3264  }
3265  else {
3266  /* use first index if its out of range */
3267  if (me_eval->totvert) {
3268  copy_v3_v3(vec, me_eval->mvert[0].co);
3269  }
3270  }
3271  }
3272  else {
3273  CLOG_ERROR(&LOG,
3274  "Evaluated mesh is needed to solve parenting, "
3275  "object position can be wrong now");
3276  }
3277  }
3278  else if (ELEM(par->type, OB_CURVES_LEGACY, OB_SURF)) {
3279  ListBase *nurb;
3280 
3281  /* It is possible that a cycle in the dependency graph was resolved in a way that caused this
3282  * object to be evaluated before its dependencies. In this case the curve cache may be null. */
3283  if (par->runtime.curve_cache && par->runtime.curve_cache->deformed_nurbs.first != nullptr) {
3284  nurb = &par->runtime.curve_cache->deformed_nurbs;
3285  }
3286  else {
3287  Curve *cu = (Curve *)par->data;
3288  nurb = BKE_curve_nurbs_get(cu);
3289  }
3290 
3291  BKE_nurbList_index_get_co(nurb, nr, vec);
3292  }
3293  else if (par->type == OB_LATTICE) {
3294  Lattice *latt = (Lattice *)par->data;
3295  DispList *dl = par->runtime.curve_cache ?
3297  nullptr;
3298  float(*co)[3] = dl ? (float(*)[3])dl->verts : nullptr;
3299  int tot;
3300 
3301  if (latt->editlatt) {
3302  latt = latt->editlatt->latt;
3303  }
3304 
3305  tot = latt->pntsu * latt->pntsv * latt->pntsw;
3306 
3307  /* ensure dl is correct size */
3308  BLI_assert(dl == nullptr || dl->nr == tot);
3309 
3310  if (nr < tot) {
3311  if (co) {
3312  copy_v3_v3(vec, co[nr]);
3313  }
3314  else {
3315  copy_v3_v3(vec, latt->def[nr].vec);
3316  }
3317  }
3318  }
3319 }
3320 
3321 static void ob_parvert3(Object *ob, Object *par, float r_mat[4][4])
3322 {
3323  /* in local ob space */
3324  if (OB_TYPE_SUPPORT_PARVERT(par->type)) {
3325  float cmat[3][3], v1[3], v2[3], v3[3], q[4];
3326 
3327  give_parvert(par, ob->par1, v1);
3328  give_parvert(par, ob->par2, v2);
3329  give_parvert(par, ob->par3, v3);
3330 
3331  tri_to_quat(q, v1, v2, v3);
3332  quat_to_mat3(cmat, q);
3333  copy_m4_m3(r_mat, cmat);
3334 
3335  mid_v3_v3v3v3(r_mat[3], v1, v2, v3);
3336  }
3337  else {
3338  unit_m4(r_mat);
3339  }
3340 }
3341 
3342 void BKE_object_get_parent_matrix(Object *ob, Object *par, float r_parentmat[4][4])
3343 {
3344  float tmat[4][4];
3345  float vec[3];
3346 
3347  switch (ob->partype & PARTYPE) {
3348  case PAROBJECT: {
3349  bool ok = false;
3350  if (par->type == OB_CURVES_LEGACY) {
3351  if ((((Curve *)par->data)->flag & CU_PATH) && (ob_parcurve(ob, par, tmat))) {
3352  ok = true;
3353  }
3354  }
3355 
3356  if (ok) {
3357  mul_m4_m4m4(r_parentmat, par->obmat, tmat);
3358  }
3359  else {
3360  copy_m4_m4(r_parentmat, par->obmat);
3361  }
3362 
3363  break;
3364  }
3365  case PARBONE:
3366  ob_parbone(ob, par, tmat);
3367  mul_m4_m4m4(r_parentmat, par->obmat, tmat);
3368  break;
3369 
3370  case PARVERT1:
3371  unit_m4(r_parentmat);
3372  give_parvert(par, ob->par1, vec);
3373  mul_v3_m4v3(r_parentmat[3], par->obmat, vec);
3374  break;
3375  case PARVERT3:
3376  ob_parvert3(ob, par, tmat);
3377 
3378  mul_m4_m4m4(r_parentmat, par->obmat, tmat);
3379  break;
3380 
3381  case PARSKEL:
3382  copy_m4_m4(r_parentmat, par->obmat);
3383  break;
3384  }
3385 }
3386 
3389 /* -------------------------------------------------------------------- */
3397 static void solve_parenting(
3398  Object *ob, Object *par, const bool set_origin, float r_obmat[4][4], float r_originmat[3][3])
3399 {
3400  float totmat[4][4];
3401  float tmat[4][4];
3402  float locmat[4][4];
3403 
3404  BKE_object_to_mat4(ob, locmat);
3405 
3406  BKE_object_get_parent_matrix(ob, par, totmat);
3407 
3408  /* total */
3409  mul_m4_m4m4(tmat, totmat, ob->parentinv);
3410  mul_m4_m4m4(r_obmat, tmat, locmat);
3411 
3412  if (r_originmat) {
3413  /* usable originmat */
3414  copy_m3_m4(r_originmat, tmat);
3415  }
3416 
3417  /* origin, for help line */
3418  if (set_origin) {
3419  if ((ob->partype & PARTYPE) == PARSKEL) {
3421  }
3422  else {
3423  copy_v3_v3(ob->runtime.parent_display_origin, totmat[3]);
3424  }
3425  }
3426 }
3427 
3429  Scene *scene,
3430  Object *ob,
3431  float ctime,
3432  RigidBodyWorld *rbw,
3433  float r_originmat[3][3])
3434 {
3435  if (ob->parent) {
3436  Object *par = ob->parent;
3437 
3438  /* calculate parent matrix */
3439  solve_parenting(ob, par, true, ob->obmat, r_originmat);
3440  }
3441  else {
3442  BKE_object_to_mat4(ob, ob->obmat);
3443  }
3444 
3445  /* try to fall back to the scene rigid body world if none given */
3446  rbw = rbw ? rbw : scene->rigidbody_world;
3447  /* read values pushed into RBO from sim/cache... */
3448  BKE_rigidbody_sync_transforms(rbw, ob, ctime);
3449 
3450  /* solve constraints */
3451  if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
3452  bConstraintOb *cob;
3454  BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime);
3456  }
3457 
3458  /* set negative scale flag in object */
3459  if (is_negative_m4(ob->obmat)) {
3460  ob->transflag |= OB_NEG_SCALE;
3461  }
3462  else {
3463  ob->transflag &= ~OB_NEG_SCALE;
3464  }
3465 }
3466 
3468 {
3469  /* Execute drivers and animation. */
3470  const bool flush_to_original = DEG_is_active(depsgraph);
3472  ctime);
3474  &ob->id, ob->adt, &anim_eval_context, ADT_RECALC_ALL, flush_to_original);
3475  object_where_is_calc_ex(depsgraph, scene, ob, ctime, nullptr, nullptr);
3476 }
3477 
3478 void BKE_object_where_is_calc_mat4(Object *ob, float r_obmat[4][4])
3479 {
3480  if (ob->parent) {
3481  Object *par = ob->parent;
3482  solve_parenting(ob, par, false, r_obmat, nullptr);
3483  }
3484  else {
3485  BKE_object_to_mat4(ob, r_obmat);
3486  }
3487 }
3488 
3490  Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
3491 {
3492  float ctime = DEG_get_ctime(depsgraph);
3493  object_where_is_calc_ex(depsgraph, scene, ob, ctime, rbw, r_originmat);
3494 }
3496 {
3497  float ctime = DEG_get_ctime(depsgraph);
3498  object_where_is_calc_ex(depsgraph, scene, ob, ctime, nullptr, nullptr);
3499 }
3500 
3502 {
3503  BKE_object_workob_clear(workob);
3504 
3505  unit_m4(workob->obmat);
3506  unit_m4(workob->parentinv);
3507  unit_m4(workob->constinv);
3508 
3509  /* Since this is used while calculating parenting,
3510  * at this moment ob_eval->parent is still nullptr. */
3512 
3513  workob->trackflag = ob->trackflag;
3514  workob->upflag = ob->upflag;
3515 
3516  workob->partype = ob->partype;
3517  workob->par1 = ob->par1;
3518  workob->par2 = ob->par2;
3519  workob->par3 = ob->par3;
3520 
3521  /* The effects of constraints should NOT be included in the parent-inverse matrix. Constraints
3522  * are supposed to be applied after the object's local loc/rot/scale. If the (inverted) effect of
3523  * constraints would be included in the parent inverse matrix, these would be applied before the
3524  * object's local loc/rot/scale instead of after. For example, a "Copy Rotation" constraint would
3525  * rotate the object's local translation as well. See T82156. */
3526 
3527  BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr));
3528 
3530 }
3531 
3533  const float mat[4][4],
3534  Object *parent,
3535  const float parentinv[4][4],
3536  const bool use_compat)
3537 {
3538  /* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */
3539 
3540  float rot[3][3];
3541 
3542  if (parent != nullptr) {
3543  float rmat[4][4], diff_mat[4][4], imat[4][4], parent_mat[4][4];
3544 
3545  BKE_object_get_parent_matrix(ob, parent, parent_mat);
3546 
3547  mul_m4_m4m4(diff_mat, parent_mat, parentinv);
3548  invert_m4_m4(imat, diff_mat);
3549  mul_m4_m4m4(rmat, imat, mat); /* get the parent relative matrix */
3550 
3551  /* same as below, use rmat rather than mat */
3552  mat4_to_loc_rot_size(ob->loc, rot, ob->scale, rmat);
3553  }
3554  else {
3555  mat4_to_loc_rot_size(ob->loc, rot, ob->scale, mat);
3556  }
3557 
3558  BKE_object_mat3_to_rot(ob, rot, use_compat);
3559 
3560  sub_v3_v3(ob->loc, ob->dloc);
3561 
3562  if (ob->dscale[0] != 0.0f) {
3563  ob->scale[0] /= ob->dscale[0];
3564  }
3565  if (ob->dscale[1] != 0.0f) {
3566  ob->scale[1] /= ob->dscale[1];
3567  }
3568  if (ob->dscale[2] != 0.0f) {
3569  ob->scale[2] /= ob->dscale[2];
3570  }
3571 
3572  /* BKE_object_mat3_to_rot handles delta rotations */
3573 }
3574 
3576  const float mat[4][4],
3577  const bool use_compat,
3578  const bool use_parent)
3579 {
3580  BKE_object_apply_mat4_ex(ob, mat, use_parent ? ob->parent : nullptr, ob->parentinv, use_compat);
3581 }
3582 
3584 {
3585  /*
3586  * Use parent's world transform as the child's origin.
3587  *
3588  * Let:
3589  * `local = identity`
3590  * `world = orthonormalized(parent)`
3591  *
3592  * Then:
3593  * `world = parent @ parentinv @ local`
3594  * `inv(parent) @ world = parentinv`
3595  * `parentinv = inv(parent) @ world`
3596  *
3597  * NOTE: If `ob->obmat` has shear, then this `parentinv` is insufficient because
3598  * `parent @ parentinv => shearless result`
3599  *
3600  * Thus, local will have shear which cannot be decomposed into TRS:
3601  * `local = inv(parent @ parentinv) @ world`
3602  *
3603  * This is currently not supported for consistency in the handling of shear during the other
3604  * parenting ops: Parent (Keep Transform), Clear [Parent] and Keep Transform.
3605  */
3606  float par_locrot[4][4], par_imat[4][4];
3607  BKE_object_get_parent_matrix(ob, ob->parent, par_locrot);
3608  invert_m4_m4(par_imat, par_locrot);
3609 
3610  orthogonalize_m4_stable(par_locrot, 0, true);
3611 
3612  mul_m4_m4m4(ob->parentinv, par_imat, par_locrot);
3613 
3614  /* Now, preserve `world` given the new `parentinv`.
3615  *
3616  * `world = parent @ parentinv @ local`
3617  * `inv(parent) @ world = parentinv @ local`
3618  * `inv(parentinv) @ inv(parent) @ world = local`
3619  *
3620  * `local = inv(parentinv) @ inv(parent) @ world`
3621  */
3622  float ob_local[4][4];
3623  copy_m4_m4(ob_local, ob->parentinv);
3624  invert_m4(ob_local);
3625  mul_m4_m4_post(ob_local, par_imat);
3626  mul_m4_m4_post(ob_local, ob->obmat);
3627 
3628  /* Send use_compat=False so the rotation is predictable. */
3629  BKE_object_apply_mat4(ob, ob_local, false, false);
3630 }
3631 
3634 /* -------------------------------------------------------------------- */
3639 {
3640  BoundBox *bb = MEM_cnew<BoundBox>(__func__);
3642  return bb;
3643 }
3644 
3645 void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
3646 {
3647  bb->vec[0][0] = bb->vec[1][0] = bb->vec[2][0] = bb->vec[3][0] = min[0];
3648  bb->vec[4][0] = bb->vec[5][0] = bb->vec[6][0] = bb->vec[7][0] = max[0];
3649 
3650  bb->vec[0][1] = bb->vec[1][1] = bb->vec[4][1] = bb->vec[5][1] = min[1];
3651  bb->vec[2][1] = bb->vec[3][1] = bb->vec[6][1] = bb->vec[7][1] = max[1];
3652 
3653  bb->vec[0][2] = bb->vec[3][2] = bb->vec[4][2] = bb->vec[7][2] = min[2];
3654  bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = max[2];
3655 }
3656 
3657 void BKE_boundbox_calc_center_aabb(const BoundBox *bb, float r_cent[3])
3658 {
3659  r_cent[0] = 0.5f * (bb->vec[0][0] + bb->vec[4][0]);
3660  r_cent[1] = 0.5f * (bb->vec[0][1] + bb->vec[2][1]);
3661  r_cent[2] = 0.5f * (bb->vec[0][2] + bb->vec[1][2]);
3662 }
3663 
3664 void BKE_boundbox_calc_size_aabb(const BoundBox *bb, float r_size[3])
3665 {
3666  r_size[0] = 0.5f * fabsf(bb->vec[0][0] - bb->vec[4][0]);
3667  r_size[1] = 0.5f * fabsf(bb->vec[0][1] - bb->vec[2][1]);
3668  r_size[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]);
3669 }
3670 
3672  const float obmat[4][4],
3673  float r_min[3],
3674  float r_max[3])
3675 {
3676  int i;
3677  for (i = 0; i < 8; i++) {
3678  float vec[3];
3679  mul_v3_m4v3(vec, obmat, bb->vec[i]);
3680  minmax_v3v3_v3(r_min, r_max, vec);
3681  }
3682 }
3683 
3685 {
3686  BoundBox *bb = nullptr;
3687 
3688  switch (ob->type) {
3689  case OB_MESH:
3690  bb = BKE_mesh_boundbox_get(ob);
3691  break;
3692  case OB_CURVES_LEGACY:
3693  case OB_SURF:
3694  case OB_FONT:
3695  bb = BKE_curve_boundbox_get(ob);
3696  break;
3697  case OB_MBALL:
3698  bb = BKE_mball_boundbox_get(ob);
3699  break;
3700  case OB_LATTICE:
3701  bb = BKE_lattice_boundbox_get(ob);
3702  break;
3703  case OB_ARMATURE:
3704  bb = BKE_armature_boundbox_get(ob);
3705  break;
3706  case OB_GPENCIL:
3707  bb = BKE_gpencil_boundbox_get(ob);
3708  break;
3709  case OB_CURVES:
3710  bb = BKE_curves_boundbox_get(ob);
3711  break;
3712  case OB_POINTCLOUD:
3713  bb = BKE_pointcloud_boundbox_get(ob);
3714  break;
3715  case OB_VOLUME:
3716  bb = BKE_volume_boundbox_get(ob);
3717  break;
3718  default:
3719  break;
3720  }
3721  return bb;
3722 }
3723 
3725 {
3726  float3 min(FLT_MAX);
3727  float3 max(-FLT_MAX);
3728 
3729  if (!BKE_mesh_wrapper_minmax(me_eval, min, max)) {
3730  min = float3(0);
3731  max = float3(0);
3732  }
3733 
3734  if (ob->runtime.bb == nullptr) {
3735  ob->runtime.bb = MEM_cnew<BoundBox>("DM-BoundBox");
3736  }
3737 
3739 
3740  ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
3741 }
3742 
3744 {
3745  float3 min(FLT_MAX);
3746  float3 max(-FLT_MAX);
3747 
3748  if (ob->runtime.geometry_set_eval) {
3750  min = float3(0);
3751  max = float3(0);
3752  }
3753  }
3754  else if (const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob)) {
3755  if (!BKE_mesh_wrapper_minmax(mesh_eval, min, max)) {
3756  min = float3(0);
3757  max = float3(0);
3758  }
3759  }
3760  else if (ob->runtime.curve_cache) {
3762  }
3763  else {
3764  return false;
3765  }
3766 
3767  if (ob->runtime.bb == nullptr) {
3768  ob->runtime.bb = MEM_cnew<BoundBox>(__func__);
3769  }
3770 
3772 
3773  ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
3774 
3775  return true;
3776 }
3777 
3780 /* -------------------------------------------------------------------- */
3786 void BKE_object_dimensions_get(Object *ob, float r_vec[3])
3787 {
3788  const BoundBox *bb = BKE_object_boundbox_get(ob);
3789  if (bb) {
3790  float3 scale;
3791  mat4_to_size(scale, ob->obmat);
3792 
3793  r_vec[0] = fabsf(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
3794  r_vec[1] = fabsf(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
3795  r_vec[2] = fabsf(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
3796  }
3797  else {
3798  zero_v3(r_vec);
3799  }
3800 }
3801 
3803  const float value[3],
3804  int axis_mask,
3805  const float ob_scale_orig[3],
3806  const float ob_obmat_orig[4][4])
3807 {
3808  const BoundBox *bb = BKE_object_boundbox_get(ob);
3809  if (bb) {
3810  float3 len;
3811  len.x = bb->vec[4][0] - bb->vec[0][0];
3812  len.y = bb->vec[2][1] - bb->vec[0][1];
3813  len.z = bb->vec[1][2] - bb->vec[0][2];
3814 
3815  for (int i = 0; i < 3; i++) {
3816  if (((1 << i) & axis_mask) == 0) {
3817 
3818  if (ob_scale_orig != nullptr) {
3819  const float scale_delta = len_v3(ob_obmat_orig[i]) / ob_scale_orig[i];
3820  if (isfinite(scale_delta)) {
3821  len[i] *= scale_delta;
3822  }
3823  }
3824 
3825  const float scale = copysignf(value[i] / len[i], ob->scale[i]);
3826  if (isfinite(scale)) {
3827  ob->scale[i] = scale;
3828  }
3829  }
3830  }
3831  }
3832 }
3833 
3834 void BKE_object_dimensions_set(Object *ob, const float value[3], int axis_mask)
3835 {
3836  BKE_object_dimensions_set_ex(ob, value, axis_mask, nullptr, nullptr);
3837 }
3838 
3839 void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
3840 {
3841  bool changed = false;
3842 
3843  switch (ob->type) {
3844  case OB_CURVES_LEGACY:
3845  case OB_FONT:
3846  case OB_SURF: {
3847  const BoundBox bb = *BKE_curve_boundbox_get(ob);
3848  BKE_boundbox_minmax(&bb, ob->obmat, r_min, r_max);
3849  changed = true;
3850  break;
3851  }
3852  case OB_MESH: {
3853  const BoundBox bb = *BKE_mesh_boundbox_get(ob);
3854  BKE_boundbox_minmax(&bb, ob->obmat, r_min, r_max);
3855  changed = true;
3856  break;
3857  }
3858  case OB_GPENCIL: {
3859  const BoundBox bb = *BKE_gpencil_boundbox_get(ob);
3860  BKE_boundbox_minmax(&bb, ob->obmat, r_min, r_max);
3861  changed = true;
3862  break;
3863  }
3864  case OB_LATTICE: {
3865  Lattice *lt = (Lattice *)ob->data;
3866  BPoint *bp = lt->def;
3867  int u, v, w;
3868 
3869  for (w = 0; w < lt->pntsw; w++) {
3870  for (v = 0; v < lt->pntsv; v++) {
3871  for (u = 0; u < lt->pntsu; u++, bp++) {
3872  float3 vec;
3873  mul_v3_m4v3(vec, ob->obmat, bp->vec);
3874  minmax_v3v3_v3(r_min, r_max, vec);
3875  }
3876  }
3877  }
3878  changed = true;
3879  break;
3880  }
3881  case OB_ARMATURE: {
3882  changed = BKE_pose_minmax(ob, r_min, r_max, use_hidden, false);
3883  break;
3884  }
3885  case OB_MBALL: {
3886  float ob_min[3], ob_max[3];
3887 
3888  changed = BKE_mball_minmax_ex((const MetaBall *)ob->data, ob_min, ob_max, ob->obmat, 0);
3889  if (changed) {
3890  minmax_v3v3_v3(r_min, r_max, ob_min);
3891  minmax_v3v3_v3(r_min, r_max, ob_max);
3892  }
3893  break;
3894  }
3895  case OB_CURVES: {
3896  const BoundBox bb = *BKE_curves_boundbox_get(ob);
3897  BKE_boundbox_minmax(&bb, ob->obmat, r_min, r_max);
3898  changed = true;
3899  break;
3900  }
3901 
3902  case OB_POINTCLOUD: {
3903  const BoundBox bb = *BKE_pointcloud_boundbox_get(ob);
3904  BKE_boundbox_minmax(&bb, ob->obmat, r_min, r_max);
3905  changed = true;
3906  break;
3907  }
3908  case OB_VOLUME: {
3909  const BoundBox bb = *BKE_volume_boundbox_get(ob);
3910  BKE_boundbox_minmax(&bb, ob->obmat, r_min, r_max);
3911  changed = true;
3912  break;
3913  }
3914  }
3915 
3916  if (changed == false) {
3917  float3 size = ob->scale;
3918 
3919  copy_v3_v3(size, ob->scale);
3920  if (ob->type == OB_EMPTY) {
3921  size *= ob->empty_drawsize;
3922  }
3923 
3924  minmax_v3v3_v3(r_min, r_max, ob->obmat[3]);
3925 
3926  float3 vec;
3927  copy_v3_v3(vec, ob->obmat[3]);
3928  add_v3_v3(vec, size);
3929  minmax_v3v3_v3(r_min, r_max, vec);
3930 
3931  copy_v3_v3(vec, ob->obmat[3]);
3932  sub_v3_v3(vec, size);
3933  minmax_v3v3_v3(r_min, r_max, vec);
3934  }
3935 }
3936 
3937 void BKE_object_empty_draw_type_set(Object *ob, const int value)
3938 {
3939  ob->empty_drawtype = value;
3940 
3941  if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
3942  if (!ob->iuser) {
3943  ob->iuser = MEM_cnew<ImageUser>("image user");
3944  ob->iuser->flag |= IMA_ANIM_ALWAYS;
3945  ob->iuser->frames = 100;
3946  ob->iuser->sfra = 1;
3947  }
3948  }
3949  else {
3950  MEM_SAFE_FREE(ob->iuser);
3951  }
3952 }
3953 
3955 {
3956  const char visibility_flag = ob->empty_image_visibility_flag;
3957  if (rv3d->is_persp) {
3958  return (visibility_flag & OB_EMPTY_IMAGE_HIDE_PERSPECTIVE) == 0;
3959  }
3960 
3961  return (visibility_flag & OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC) == 0;
3962 }
3963 
3965 {
3966  /* Caller is expected to check this. */
3968 
3969  const char visibility_flag = ob->empty_image_visibility_flag;
3970 
3971  if ((visibility_flag & (OB_EMPTY_IMAGE_HIDE_BACK | OB_EMPTY_IMAGE_HIDE_FRONT)) != 0) {
3972  float eps, dot;
3973  if (rv3d->is_persp) {
3974  /* NOTE: we could normalize the 'view_dir' then use 'eps'
3975  * however the issue with empty objects being visible when viewed from the side
3976  * is only noticeable in orthographic views. */
3977  float3 view_dir;
3978  sub_v3_v3v3(view_dir, rv3d->viewinv[3], ob->obmat[3]);
3979  dot = dot_v3v3(ob->obmat[2], view_dir);
3980  eps = 0.0f;
3981  }
3982  else {
3983  dot = dot_v3v3(ob->obmat[2], rv3d->viewinv[2]);
3984  eps = 1e-5f;
3985  }
3986  if (visibility_flag & OB_EMPTY_IMAGE_HIDE_BACK) {
3987  if (dot < eps) {
3988  return false;
3989  }
3990  }
3991  if (visibility_flag & OB_EMPTY_IMAGE_HIDE_FRONT) {
3992  if (dot > -eps) {
3993  return false;
3994  }
3995  }
3996  }
3997 
3998  if (visibility_flag & OB_EMPTY_IMAGE_HIDE_NON_AXIS_ALIGNED) {
3999  float3 proj, ob_z_axis;
4000  normalize_v3_v3(ob_z_axis, ob->obmat[2]);
4001  project_plane_v3_v3v3(proj, ob_z_axis, rv3d->viewinv[2]);
4002  const float proj_length_sq = len_squared_v3(proj);
4003  if (proj_length_sq > 1e-5f) {
4004  return false;
4005  }
4006  }
4007 
4008  return true;
4009 }
4010 
4011 bool BKE_object_minmax_empty_drawtype(const struct Object *ob, float r_min[3], float r_max[3])
4012 {
4013  BLI_assert(ob->type == OB_EMPTY);
4014  float3 min(0), max(0);
4015 
4016  bool ok = false;
4017  const float radius = ob->empty_drawsize;
4018 
4019  switch (ob->empty_drawtype) {
4020  case OB_ARROWS: {
4021  max = float3(radius);
4022  ok = true;
4023  break;
4024  }
4025  case OB_PLAINAXES:
4026  case OB_CUBE:
4027  case OB_EMPTY_SPHERE: {
4028  min = float3(-radius);
4029  max = float3(radius);
4030  ok = true;
4031  break;
4032  }
4033  case OB_CIRCLE: {
4034  max[0] = max[2] = radius;
4035  min[0] = min[2] = -radius;
4036  ok = true;
4037  break;
4038  }
4039  case OB_SINGLE_ARROW: {
4040  max[2] = radius;
4041  ok = true;
4042  break;
4043  }
4044  case OB_EMPTY_CONE: {
4045  min = float3(-radius, 0.0f, -radius);
4046  max = float3(radius, radius * 2.0f, radius);
4047  ok = true;
4048  break;
4049  }
4050  case OB_EMPTY_IMAGE: {
4051  const float *ofs = ob->ima_ofs;
4052  /* NOTE: this is the best approximation that can be calculated without loading the image. */
4053  min[0] = ofs[0] * radius;
4054  min[1] = ofs[1] * radius;
4055  max[0] = radius + (ofs[0] * radius);
4056  max[1] = radius + (ofs[1] * radius);
4057  /* Since the image aspect can shrink the bounds towards the object origin,
4058  * adjust the min/max to account for that. */
4059  for (int i = 0; i < 2; i++) {
4060  CLAMP_MAX(min[i], 0.0f);
4061  CLAMP_MIN(max[i], 0.0f);
4062  }
4063  ok = true;
4064  break;
4065  }
4066  }
4067 
4068  if (ok) {
4069  copy_v3_v3(r_min, min);
4070  copy_v3_v3(r_max, max);
4071  }
4072  return ok;
4073 }
4074 
4076  Scene *scene,
4077  Object *ob,
4078  float r_min[3],
4079  float r_max[3],
4080  const bool use_hidden)
4081 {
4082  bool ok = false;
4083  if ((ob->transflag & OB_DUPLI) == 0 && ob->runtime.geometry_set_eval == nullptr) {
4084  return ok;
4085  }
4086 
4088  LISTBASE_FOREACH (DupliObject *, dob, lb) {
4089  if (((use_hidden == false) && (dob->no_draw != 0)) || dob->ob_data == nullptr) {
4090  /* pass */
4091  }
4092  else {
4093  Object temp_ob = blender::dna::shallow_copy(*dob->ob);
4094  /* Do not modify the original boundbox. */
4095  temp_ob.runtime.bb = nullptr;
4096  BKE_object_replace_data_on_shallow_copy(&temp_ob, dob->ob_data);
4097  const BoundBox *bb = BKE_object_boundbox_get(&temp_ob);
4098 
4099  if (bb) {
4100  int i;
4101  for (i = 0; i < 8; i++) {
4102  float3 vec;
4103  mul_v3_m4v3(vec, dob->mat, bb->vec[i]);
4104  minmax_v3v3_v3(r_min, r_max, vec);
4105  }
4106 
4107  ok = true;
4108  }
4109 
4110  MEM_SAFE_FREE(temp_ob.runtime.bb);
4111  }
4112  }
4113  free_object_duplilist(lb); /* does restore */
4114 
4115  return ok;
4116 }
4117 
4119  const float (*obmat)[4];
4120 
4121  void (*point_func_cb)(const float co[3], void *user_data);
4122  void *user_data;
4123 };
4124 
4126  bGPDframe *UNUSED(frame),
4127  bGPDstroke *stroke,
4128  void *thunk)
4129 {
4131  {
4132  bGPDspoint *pt;
4133  int i;
4134  for (i = 0, pt = stroke->points; i < stroke->totpoints; i++, pt++) {
4135  float3 co;
4136  mul_v3_m4v3(co, iter_data->obmat, &pt->x);
4137  iter_data->point_func_cb(co, iter_data->user_data);
4138  }
4139  }
4140 }
4141 
4143  const float obmat[4][4],
4144  void (*func_cb)(const float[3], void *),
4145  void *user_data)
4146 {
4147  /* TODO: pointcloud and curves object support */
4148  const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob);
4149  float3 co;
4150 
4151  if (mesh_eval != nullptr) {
4152  const MVert *mv = mesh_eval->mvert;
4153  const int totvert = mesh_eval->totvert;
4154  for (int i = 0; i < totvert; i++, mv++) {
4155  mul_v3_m4v3(co, obmat, mv->co);
4156  func_cb(co, user_data);
4157  }
4158  }
4159  else if (ob->type == OB_GPENCIL) {
4160  GPencilStrokePointIterData iter_data{};
4161  iter_data.obmat = obmat;
4162  iter_data.point_func_cb = func_cb;
4163  iter_data.user_data = user_data;
4164 
4166  (bGPdata *)ob->data, nullptr, foreach_display_point_gpencil_stroke_fn, &iter_data);
4167  }
4168  else if (ob->runtime.curve_cache && ob->runtime.curve_cache->disp.first) {
4170  const float *v3 = dl->verts;
4171  int totvert = dl->nr;
4172  int i;
4173 
4174  for (i = 0; i < totvert; i++, v3 += 3) {
4175  mul_v3_m4v3(co, obmat, v3);
4176  func_cb(co, user_data);
4177  }
4178  }
4179  }
4180 }
4181 
4183  void (*func_cb)(const float[3], void *),
4184  void *user_data)
4185 {
4187  ob,
4190  if ((ob->base_flag & BASE_SELECTED) != 0) {
4192  }
4193  }
4195 }
4196 
4199 /* -------------------------------------------------------------------- */
4206 struct ObTfmBack {
4207  float loc[3], dloc[3];
4208  float scale[3], dscale[3];
4209  float rot[3], drot[3];
4210  float quat[4], dquat[4];
4211  float rotAxis[3], drotAxis[3];
4213  float obmat[4][4];
4214  float parentinv[4][4];
4215  float constinv[4][4];
4216  float imat[4][4];
4217 };
4218 
4220 {
4221  ObTfmBack *obtfm = (ObTfmBack *)MEM_mallocN(sizeof(ObTfmBack), "ObTfmBack");
4222  copy_v3_v3(obtfm->loc, ob->loc);
4223  copy_v3_v3(obtfm->dloc, ob->dloc);
4224  copy_v3_v3(obtfm->scale, ob->scale);
4225  copy_v3_v3(obtfm->dscale, ob->dscale);
4226  copy_v3_v3(obtfm->rot, ob->rot);
4227  copy_v3_v3(obtfm->drot, ob->drot);
4228  copy_qt_qt(obtfm->quat, ob->quat);
4229  copy_qt_qt(obtfm->dquat, ob->dquat);
4230  copy_v3_v3(obtfm->rotAxis, ob->rotAxis);
4231  copy_v3_v3(obtfm->drotAxis, ob->drotAxis);
4232  obtfm->rotAngle = ob->rotAngle;
4233  obtfm->drotAngle = ob->drotAngle;
4234  copy_m4_m4(obtfm->obmat, ob->obmat);
4235  copy_m4_m4(obtfm->parentinv, ob->parentinv);
4236  copy_m4_m4(obtfm->constinv, ob->constinv);
4237  copy_m4_m4(obtfm->imat, ob->imat);
4238 
4239  return (void *)obtfm;
4240 }
4241 
4242 void BKE_object_tfm_restore(Object *ob, void *obtfm_pt)
4243 {
4244  ObTfmBack *obtfm = (ObTfmBack *)obtfm_pt;
4245  copy_v3_v3(ob->loc, obtfm->loc);
4246  copy_v3_v3(ob->dloc, obtfm->dloc);
4247  copy_v3_v3(ob->scale, obtfm->scale);
4248  copy_v3_v3(ob->dscale, obtfm->dscale);
4249  copy_v3_v3(ob->rot, obtfm->rot);
4250  copy_v3_v3(ob->drot, obtfm->drot);
4251  copy_qt_qt(ob->quat, obtfm->quat);
4252  copy_qt_qt(ob->dquat, obtfm->dquat);
4253  copy_v3_v3(ob->rotAxis, obtfm->rotAxis);
4254  copy_v3_v3(ob->drotAxis, obtfm->drotAxis);
4255  ob->rotAngle = obtfm->rotAngle;
4256  ob->drotAngle = obtfm->drotAngle;
4257  copy_m4_m4(ob->obmat, obtfm->obmat);
4258  copy_m4_m4(ob->parentinv, obtfm->parentinv);
4259  copy_m4_m4(ob->constinv, obtfm->constinv);
4260  copy_m4_m4(ob->imat, obtfm->imat);
4261 }
4262 
4265 /* -------------------------------------------------------------------- */
4270  Scene *scene,
4271  Object *ob,
4272  RigidBodyWorld *rbw)
4273 {
4274  const ID *object_data = (ID *)ob->data;
4275  const bool recalc_object = (ob->id.recalc & ID_RECALC_ALL) != 0;
4276  const bool recalc_data = (object_data != nullptr) ?
4277  ((object_data->recalc & ID_RECALC_ALL) != 0) :
4278  false;
4279  if (!recalc_object && !recalc_data) {
4280  return;
4281  }
4282  /* Speed optimization for animation lookups. */
4283  if (ob->pose != nullptr) {
4287  }
4288  }
4289  if (recalc_data) {
4290  if (ob->type == OB_ARMATURE) {
4291  /* this happens for reading old files and to match library armatures
4292  * with poses we do it ahead of BKE_object_where_is_calc to ensure animation
4293  * is evaluated on the rebuilt pose, otherwise we get incorrect poses
4294  * on file load */
4295  if (ob->pose == nullptr || (ob->pose->flag & POSE_RECALC)) {
4296  /* No need to pass bmain here, we assume we do not need to rebuild DEG from here... */
4297  BKE_pose_rebuild(nullptr, ob, (bArmature *)ob->data, true);
4298  }
4299  }
4300  }
4301  /* XXX new animsys warning: depsgraph tag ID_RECALC_GEOMETRY should not skip drivers,
4302  * which is only in BKE_object_where_is_calc now */
4303  /* XXX: should this case be ID_RECALC_TRANSFORM instead? */
4304  if (recalc_object || recalc_data) {
4305  if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
4306  printf("recalcob %s\n", ob->id.name + 2);
4307  }
4308  BKE_object_where_is_calc_ex(depsgraph, scene, rbw, ob, nullptr);
4309  }
4310 
4311  if (recalc_data) {
4313  }
4314 }
4315 
4317 {
4319 }
4320 
4322 {
4323  BLI_assert((ob->sculpt == nullptr) && (ob->mode & OB_MODE_ALL_SCULPT));
4324  ob->sculpt = MEM_cnew<SculptSession>(__func__);
4325  ob->sculpt->mode_type = (eObjectMode)ob->mode;
4326 }
4327 
4328 bool BKE_object_obdata_texspace_get(Object *ob, char **r_texflag, float **r_loc, float **r_size)
4329 {
4330 
4331  if (ob->data == nullptr) {
4332  return false;
4333  }
4334 
4335  switch (GS(((ID *)ob->data)->name)) {
4336  case ID_ME: {
4337  BKE_mesh_texspace_get_reference((Mesh *)ob->data, r_texflag, r_loc, r_size);
4338  break;
4339  }
4340  case ID_CU_LEGACY: {
4341  Curve *cu = (Curve *)ob->data;
4343  if (r_texflag) {
4344  *r_texflag = &cu->texflag;
4345  }
4346  if (r_loc) {
4347  *r_loc = cu->loc;
4348  }
4349  if (r_size) {
4350  *r_size = cu->size;
4351  }
4352  break;
4353  }
4354  case ID_MB: {
4355  MetaBall *mb = (MetaBall *)ob->data;
4356  if (r_texflag) {
4357  *r_texflag = &mb->texflag;
4358  }
4359  if (r_loc) {
4360  *r_loc = mb->loc;
4361  }
4362  if (r_size) {
4363  *r_size = mb->size;
4364  }
4365  break;
4366  }
4367  default:
4368  return false;
4369  }
4370  return true;
4371 }
4372 
4374 {
4375  /* First attempt to retrieve the evaluated mesh from the evaluated geometry set. Most
4376  * object types either store it there or add a reference to it if it's owned elsewhere. */
4377  GeometrySet *geometry_set_eval = object->runtime.geometry_set_eval;
4378  if (geometry_set_eval) {
4379  /* Some areas expect to be able to modify the evaluated mesh in limited ways. Theoretically
4380  * this should be avoided, or at least protected with a lock, so a const mesh could be returned
4381  * from this function. We use a const_cast instead of #get_mesh_for_write, because that might
4382  * result in a copy of the mesh when it is shared. */
4383  Mesh *mesh = const_cast<Mesh *>(geometry_set_eval->get_mesh_for_read());
4384  if (mesh) {
4385  return mesh;
4386  }
4387  }
4388 
4389  /* Some object types do not yet add the evaluated mesh to an evaluated geometry set, if they do
4390  * not support evaluating to multiple data types. Eventually this should be removed, when all
4391  * object types use #geometry_set_eval. */
4392  ID *data_eval = object->runtime.data_eval;
4393  if (data_eval && GS(data_eval->name) == ID_ME) {
4394  return reinterpret_cast<Mesh *>(data_eval);
4395  }
4396 
4397  return nullptr;
4398 }
4399 
4401 {
4403  if (!mesh) {
4404  return nullptr;
4405  }
4406 
4407  if (object->data && GS(((const ID *)object->data)->name) == ID_ME) {
4409  }
4410 
4411  return mesh;
4412 }
4413 
4415 {
4416  if (object->type == OB_MESH && object->runtime.data_orig != nullptr) {
4418  BLI_assert(object->id.orig_id != nullptr);
4419  BLI_assert(object->runtime.data_orig->orig_id == ((Object *)object->id.orig_id)->data);
4420  Mesh *result = (Mesh *)object->runtime.data_orig;
4421  BLI_assert((result->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0);
4423  return result;
4424  }
4425  BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0);
4426  return (Mesh *)object->data;
4427 }
4428 
4430 {
4431  Mesh *result = nullptr;
4432  if (object->id.orig_id == nullptr) {
4433  BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0);
4434  result = (Mesh *)object->data;
4435  }
4436  else {
4437  BLI_assert((object->id.tag & LIB_TAG_COPIED_ON_WRITE) != 0);
4438  result = (Mesh *)((Object *)object->id.orig_id)->data;
4439  }
4440  BLI_assert(result != nullptr);
4442  0);
4443  return result;
4444 }
4445 
4447 {
4448  BLI_assert(!DEG_is_original_id(&object->id));
4449  BLI_assert(object->type == OB_MESH);
4450 
4451  const Mesh *mesh = static_cast<const Mesh *>(object->data);
4452  if (mesh->edit_mesh == nullptr) {
4453  /* Happens when requesting material of evaluated 3d font object: the evaluated object get
4454  * converted to mesh, and it does not have edit mesh. */
4455  return nullptr;
4456  }
4457 
4458  return reinterpret_cast<Mesh *>(object->runtime.data_eval);
4459 }
4460 
4462 {
4463  BLI_assert(!DEG_is_original_id(&object->id));
4464  BLI_assert(object->type == OB_MESH);
4465 
4466  const Mesh *mesh = static_cast<const Mesh *>(object->data);
4467  BLI_assert(mesh->edit_mesh != nullptr);
4469 
4470  return object->runtime.editmesh_eval_cage;
4471 }
4472 
4474 {
4475  ID *data = (ID *)object->data;
4476  if (data == nullptr || GS(data->name) != ID_LT) {
4477  return nullptr;
4478  }
4479 
4480  Lattice *lt = (Lattice *)data;
4481  if (lt->editlatt) {
4482  return lt->editlatt->latt;
4483  }
4484 
4485  return lt;
4486 }
4487 
4489 {
4490  ID *data_eval = object->runtime.data_eval;
4491 
4492  if (data_eval == nullptr || GS(data_eval->name) != ID_LT) {
4493  return nullptr;
4494  }
4495 
4496  Lattice *lt_eval = (Lattice *)data_eval;
4497  if (lt_eval->editlatt) {
4498  return lt_eval->editlatt->latt;
4499  }
4500 
4501  return lt_eval;
4502 }
4503 
4506 /* -------------------------------------------------------------------- */
4510 static int pc_cmp(const void *a, const void *b)
4511 {
4512  const LinkData *ad = (const LinkData *)a, *bd = (const LinkData *)b;
4513  if (POINTER_AS_INT(ad->data) > POINTER_AS_INT(bd->data)) {
4514  return 1;
4515  }
4516 
4517  return 0;
4518 }
4519 
4520 /* TODO: Review the usages of this function, currently with COW it will be called for orig object
4521  * and then again for COW copies of it, think this is bad since there is no guarantee that we get
4522  * the same stack index in both cases? Order is important since this index is used for filenames on
4523  * disk. */
4525 {
4526  LinkData *link = nullptr;
4527  int i = 0;
4528 
4530 
4531  for (link = (LinkData *)ob->pc_ids.first, i = 0; link; link = link->next, i++) {
4532  int index = POINTER_AS_INT(link->data);
4533 
4534  if (i < index) {
4535  break;
4536  }
4537  }
4538 
4539  link = MEM_cnew<LinkData>("PCLink");
4540  link->data = POINTER_FROM_INT(i);
4541  BLI_addtail(&ob->pc_ids, link);
4542 
4543  return i;
4544 }
4545 
4546 static int pc_findindex(ListBase *listbase, int index)
4547 {
4548  int number = 0;
4549 
4550  if (listbase == nullptr) {
4551  return -1;
4552  }
4553 
4554  LinkData *link = (LinkData *)listbase->first;
4555  while (link) {
4556  if (POINTER_AS_INT(link->data) == index) {
4557  return number;
4558  }
4559 
4560  number++;
4561  link = link->next;
4562  }
4563 
4564  return -1;
4565 }
4566 
4567 void BKE_object_delete_ptcache(Object *ob, int index)
4568 {
4569  int list_index = pc_findindex(&ob->pc_ids, index);
4570  LinkData *link = (LinkData *)BLI_findlink(&ob->pc_ids, list_index);
4571  BLI_freelinkN(&ob->pc_ids, link);
4572 }
4573 
4576 /* -------------------------------------------------------------------- */
4581 static KeyBlock *insert_meshkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
4582 {
4583  Mesh *me = (Mesh *)ob->data;
4584  Key *key = me->key;
4585  KeyBlock *kb;
4586  int newkey = 0;
4587 
4588  if (key == nullptr) {
4589  key = me->key = BKE_key_add(bmain, (ID *)me);
4590  key->type = KEY_RELATIVE;
4591  newkey = 1;
4592  }
4593 
4594  if (newkey || from_mix == false) {
4595  /* create from mesh */
4596  kb = BKE_keyblock_add_ctime(key, name, false);
4597  BKE_keyblock_convert_from_mesh(me, key, kb);
4598  }
4599  else {
4600  /* copy from current values */
4601  int totelem;
4602  float *data = BKE_key_evaluate_object(ob, &totelem);
4603 
4604  /* create new block with prepared data */
4605  kb = BKE_keyblock_add_ctime(key, name, false);
4606  kb->data = data;
4607  kb->totelem = totelem;
4608  }
4609 
4610  return kb;
4611 }
4613 static KeyBlock *insert_lattkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
4614 {
4615  Lattice *lt = (Lattice *)ob->data;
4616  Key *key = lt->key;
4617  KeyBlock *kb;
4618  int newkey = 0;
4619 
4620  if (key == nullptr) {
4621  key = lt->key = BKE_key_add(bmain, (ID *)lt);
4622  key->type = KEY_RELATIVE;
4623  newkey = 1;
4624  }
4625 
4626  if (newkey || from_mix == false) {
4627  kb = BKE_keyblock_add_ctime(key, name, false);
4628  if (!newkey) {
4629  KeyBlock *basekb = (KeyBlock *)key->block.first;
4630  kb->data = MEM_dupallocN(basekb->data);
4631  kb->totelem = basekb->totelem;
4632  }
4633  else {
4635  }
4636  }
4637  else {
4638  /* copy from current values */
4639  int totelem;
4640  float *data = BKE_key_evaluate_object(ob, &totelem);
4641 
4642  /* create new block with prepared data */
4643  kb = BKE_keyblock_add_ctime(key, name, false);
4644  kb->totelem = totelem;
4645  kb->data = data;
4646  }
4647 
4648  return kb;
4649 }
4651 static KeyBlock *insert_curvekey(Main *bmain, Object *ob, const char *name, const bool from_mix)
4652 {
4653  Curve *cu = (Curve *)ob->data;
4654  Key *key = cu->key;
4655  KeyBlock *kb;
4656  ListBase *lb = BKE_curve_nurbs_get(cu);
4657  int newkey = 0;
4658 
4659  if (key == nullptr) {
4660  key = cu->key = BKE_key_add(bmain, (ID *)cu);
4661  key->type = KEY_RELATIVE;
4662  newkey = 1;
4663  }
4664 
4665  if (newkey || from_mix == false) {
4666  /* create from curve */
4667  kb = BKE_keyblock_add_ctime(key, name, false);
4668  if (!newkey) {
4669  KeyBlock *basekb = (KeyBlock *)key->block.first;
4670  kb->data = MEM_dupallocN(basekb->data);
4671  kb->totelem = basekb->totelem;
4672  }
4673  else {
4674  BKE_keyblock_convert_from_curve(cu, kb, lb);
4675  }
4676  }
4677  else {
4678  /* copy from current values */
4679  int totelem;
4680  float *data = BKE_key_evaluate_object(ob, &totelem);
4681 
4682  /* create new block with prepared data */
4683  kb = BKE_keyblock_add_ctime(key, name, false);
4684  kb->totelem = totelem;
4685  kb->data = data;
4686  }
4687 
4688  return kb;
4689 }
4690 
4693 /* -------------------------------------------------------------------- */
4698  Object *ob,
4699  const char *name,
4700  const bool from_mix)
4701 {
4702  KeyBlock *key = nullptr;
4703 
4704  switch (ob->type) {
4705  case OB_MESH:
4706  key = insert_meshkey(bmain, ob, name, from_mix);
4707  break;
4708  case OB_CURVES_LEGACY:
4709  case OB_SURF:
4710  key = insert_curvekey(bmain, ob, name, from_mix);
4711  break;
4712  case OB_LATTICE:
4713  key = insert_lattkey(bmain, ob, name, from_mix);
4714  break;
4715  default:
4716  break;
4717  }
4718 
4719  /* Set the first active when none is set when called from RNA. */
4720  if (key != nullptr) {
4721  if (ob->shapenr <= 0) {
4722  ob->shapenr = 1;
4723  }
4724  }
4725 
4726  return key;
4727 }
4728 
4730 {
4731  Key **key_p, *key;
4732 
4733  key_p = BKE_key_from_object_p(ob);
4734  if (ELEM(nullptr, key_p, *key_p)) {
4735  return false;
4736  }
4737 
4738  key = *key_p;
4739  *key_p = nullptr;
4740 
4741  BKE_id_free_us(bmain, key);
4742 
4743  return true;
4744 }
4745 
4747 {
4748  Key *key = BKE_key_from_object(ob);
4749  short kb_index;
4750 
4751  if (key == nullptr) {
4752  return false;
4753  }
4754 
4755  kb_index = BLI_findindex(&key->block, kb);
4756  BLI_assert(kb_index != -1);
4757 
4758  LISTBASE_FOREACH (KeyBlock *, rkb, &key->block) {
4759  if (rkb->relative == kb_index) {
4760  /* remap to the 'Basis' */
4761  rkb->relative = 0;
4762  }
4763  else if (rkb->relative >= kb_index) {
4764  /* Fix positional shift of the keys when kb is deleted from the list */
4765  rkb->relative -= 1;
4766  }
4767  }
4768 
4769  BLI_remlink(&key->block, kb);
4770  key->totkey--;
4771  if (key->refkey == kb) {
4772  key->refkey = (KeyBlock *)key->block.first;
4773 
4774  if (key->refkey) {
4775  /* apply new basis key on original data */
4776  switch (ob->type) {
4777  case OB_MESH: {
4778  Mesh *mesh = (Mesh *)ob->data;
4780  break;
4781  }
4782  case OB_CURVES_LEGACY:
4783  case OB_SURF:
4785  key->refkey, (Curve *)ob->data, BKE_curve_nurbs_get((Curve *)ob->data));
4786  break;
4787  case OB_LATTICE:
4789  break;
4790  }
4791  }
4792  }
4793 
4794  if (kb->data) {
4795  MEM_freeN(kb->data);
4796  }
4797  MEM_freeN(kb);
4798 
4799  /* Unset active when all are freed. */
4800  if (BLI_listbase_is_empty(&key->block)) {
4801  ob->shapenr = 0;
4802  }
4803  else if (ob->shapenr > 1) {
4804  ob->shapenr--;
4805  }
4806 
4807  if (key->totkey == 0) {
4808  BKE_object_shapekey_free(bmain, ob);
4809  }
4810 
4811  return true;
4812 }
4813 
4816 /* -------------------------------------------------------------------- */
4820 bool BKE_object_parent_loop_check(const Object *par, const Object *ob)
4821 {
4822  /* test if 'ob' is a parent somewhere in par's parents */
4823  if (par == nullptr) {
4824  return false;
4825  }
4826  if (ob == par) {
4827  return true;
4828  }
4829  return BKE_object_parent_loop_check(par->parent, ob);
4830 }
4831 
4832 bool BKE_object_flag_test_recursive(const Object *ob, short flag)
4833 {
4834  if (ob->flag & flag) {
4835  return true;
4836  }
4837  if (ob->parent) {
4838  return BKE_object_flag_test_recursive(ob->parent, flag);
4839  }
4840 
4841  return false;
4842 }
4843 
4844 bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
4845 {
4846  for (ob_child = ob_child->parent; ob_child; ob_child = ob_child->parent) {
4847  if (ob_child == ob_parent) {
4848  return true;
4849  }
4850  }
4851  return false;
4852 }
4853 
4855 {
4856  /* Always test on original object since evaluated object may no longer
4857  * have shape keys or modifiers that were used to evaluate it. */
4858  ob = DEG_get_original_object(ob);
4859 
4860  int flag = 0;
4861 
4862  if (BKE_key_from_object(ob)) {
4864  }
4865  else {
4866  ModifierData *md;
4867  VirtualModifierData virtualModifierData;
4868  /* cloth */
4869  for (md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
4870  md && (flag != (eModifierMode_Render | eModifierMode_Realtime));
4871  md = md->next) {
4872  if ((flag & eModifierMode_Render) == 0 &&
4874  flag |= eModifierMode_Render;
4875  }
4876 
4877  if ((flag & eModifierMode_Realtime) == 0 &&
4879  flag |= eModifierMode_Realtime;
4880  }
4881  }
4882  }
4883 
4884  return flag;
4885 }
4886 
4887 bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
4888 {
4889  /* If object has any sort of animation data assume it is moving. */
4890  if (BKE_animdata_id_is_animated(&object->id)) {
4891  return true;
4892  }
4893  if (!BLI_listbase_is_empty(&object->constraints)) {
4894  return true;
4895  }
4896  if (recurse_parent && object->parent != nullptr) {
4897  return BKE_object_moves_in_time(object->parent, true);
4898  }
4899  return false;
4900 }
4901 
4902 static bool object_moves_in_time(const Object *object)
4903 {
4904  return BKE_object_moves_in_time(object, true);
4905 }
4906 
4907 static bool object_deforms_in_time(Object *object)
4908 {
4909  if (BKE_key_from_object(object) != nullptr) {
4910  return true;
4911  }
4912  if (!BLI_listbase_is_empty(&object->modifiers)) {
4913  return true;
4914  }
4915  return object_moves_in_time(object);
4916 }
4917 
4919 {
4920  /* TODO(sergey): Consider generalizing this a bit so all modifier logic
4921  * is concentrated in MOD_{modifier}.c file,
4922  */
4923  if (md->type == eModifierType_Array) {
4924  ArrayModifierData *amd = (ArrayModifierData *)md;
4925  /* TODO(sergey): Check if curve is deformed. */
4926  return (amd->start_cap != nullptr && object_moves_in_time(amd->start_cap)) ||
4927  (amd->end_cap != nullptr && object_moves_in_time(amd->end_cap)) ||
4928  (amd->curve_ob != nullptr && object_moves_in_time(amd->curve_ob)) ||
4929  (amd->offset_ob != nullptr && object_moves_in_time(amd->offset_ob));
4930  }
4931  if (md->type == eModifierType_Mirror) {
4933  return mmd->mirror_ob != nullptr &&
4935  }
4936  if (md->type == eModifierType_Screw) {
4937  ScrewModifierData *smd = (ScrewModifierData *)md;
4938  return smd->ob_axis != nullptr && object_moves_in_time(smd->ob_axis);
4939  }
4941  /* NOTE: Not ideal because it's unknown whether topology changes or not.
4942  * This will be detected later, so by assuming it's only deformation
4943  * going on here we allow baking deform-only mesh to Alembic and have
4944  * proper motion blur after that.
4945  */
4946  return true;
4947  }
4948  if (md->type == eModifierType_Nodes) {
4949  /* Not ideal for performance to always assume this is animated,
4950  * but hard to detect in general. The better long term solution is likely
4951  * to replace BKE_object_is_deform_modified by a test if the object was
4952  * modified by the depsgraph when changing frames. */
4953  return true;
4954  }
4955  return false;
4956 }
4957 
4959 {
4960  /* TODO(sergey): This is a bit code duplication with depsgraph, but
4961  * would be nicer to solve this as a part of new dependency graph
4962  * work, so we avoid conflicts and so.
4963  */
4964  if (ob->adt != nullptr) {
4965  AnimData *adt = ob->adt;
4966  if (adt->action != nullptr) {
4967  LISTBASE_FOREACH (FCurve *, fcu, &adt->action->curves) {
4968  if (fcu->rna_path && strstr(fcu->rna_path, "modifiers[")) {
4969  return true;
4970  }
4971  }
4972  }
4973  LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
4974  if (fcu->rna_path && strstr(fcu->rna_path, "modifiers[")) {
4975  return true;
4976  }
4977  }
4978  }
4979  return false;
4980 }
4981 
4983 {
4984  /* Always test on original object since evaluated object may no longer
4985  * have shape keys or modifiers that were used to evaluate it. */
4986  ob = DEG_get_original_object(ob);
4987 
4988  ModifierData *md;
4989  VirtualModifierData virtualModifierData;
4990  int flag = 0;
4991  const bool is_modifier_animated = modifiers_has_animation_check(ob);
4992 
4993  if (BKE_key_from_object(ob)) {
4995  }
4996 
4997  if (ob->type == OB_CURVES_LEGACY) {
4998  Curve *cu = (Curve *)ob->data;
4999  if (cu->taperobj != nullptr && object_deforms_in_time(cu->taperobj)) {
5001  }
5002  }
5003 
5004  /* cloth */
5005  for (md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
5006  md && (flag != (eModifierMode_Render | eModifierMode_Realtime));
5007  md = md->next) {
5008  const ModifierTypeInfo *mti = BKE_modifier_get_info((const ModifierType)md->type);
5009  bool can_deform = mti->type == eModifierTypeType_OnlyDeform || is_modifier_animated;
5010 
5011  if (!can_deform) {
5012  can_deform = constructive_modifier_is_deform_modified(ob, md);
5013  }
5014 
5015  if (can_deform) {
5016  if (!(flag & eModifierMode_Render) &&
5018  flag |= eModifierMode_Render;
5019  }
5020 
5021  if (!(flag & eModifierMode_Realtime) &&
5023  flag |= eModifierMode_Realtime;
5024  }
5025  }
5026  }
5027 
5028  return flag;
5029 }
5030 
5032 {
5033  int num_scenes = 0;
5034  LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
5036  num_scenes++;
5037  }
5038  }
5039  return num_scenes;
5040 }
5041 
5043 {
5044  MovieClip *clip = use_default ? scene->clip : nullptr;
5045  bConstraint *con = (bConstraint *)ob->constraints.first, *scon = nullptr;
5046 
5047  while (con) {
5048  if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) {
5049  if (scon == nullptr || (scon->flag & CONSTRAINT_OFF)) {
5050  scon = con;
5051  }
5052  }
5053 
5054  con = con->next;
5055  }
5056 
5057  if (scon) {
5058  bCameraSolverConstraint *solver = (bCameraSolverConstraint *)scon->data;
5059  if ((solver->flag & CAMERASOLVER_ACTIVECLIP) == 0) {
5060  clip = solver->clip;
5061  }
5062  else {
5063  clip = scene->clip;
5064  }
5065  }
5066 
5067  return clip;
5068 }
5069 
5071 {
5072  return ELEM(ob->type,
5073  OB_MESH,
5075  OB_SURF,
5076  OB_FONT,
5077  OB_MBALL,
5078  OB_CURVES,
5079  OB_POINTCLOUD,
5080  OB_VOLUME,
5081  OB_GPENCIL);
5082 }
5083 
5086 /* -------------------------------------------------------------------- */
5091 {
5092  memset(&object->runtime, 0, sizeof(object->runtime));
5093 }
5094 
5095 void BKE_object_runtime_reset_on_copy(Object *object, const int UNUSED(flag))
5096 {
5097  Object_Runtime *runtime = &object->runtime;
5098  runtime->data_eval = nullptr;
5099  runtime->gpd_eval = nullptr;
5100  runtime->mesh_deform_eval = nullptr;
5101  runtime->curve_cache = nullptr;
5102  runtime->object_as_temp_mesh = nullptr;
5103  runtime->object_as_temp_curve = nullptr;
5104  runtime->geometry_set_eval = nullptr;
5105 
5106  runtime->crazyspace_deform_imats = nullptr;
5107  runtime->crazyspace_deform_cos = nullptr;
5108 }
5109 
5111 {
5112  /* Currently this is all that's needed. */
5114 
5115  BKE_object_runtime_reset(object);
5116 }
5117 
5120 /* -------------------------------------------------------------------- */
5128 {
5129  Object *ob_arm = nullptr;
5130 
5131  if (ob->parent && ob->partype == PARSKEL && ob->parent->type == OB_ARMATURE) {
5132  ob_arm = ob->parent;
5133  }
5134  else {
5135  ModifierData *mod;
5136  for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) {
5137  if (mod->type == eModifierType_Armature) {
5138  ob_arm = ((ArmatureModifierData *)mod)->object;
5139  }
5140  }
5141  }
5142 
5143  return ob_arm;
5144 }
5145 
5146 static bool obrel_list_test(Object *ob)
5147 {
5148  return ob && !(ob->id.tag & LIB_TAG_DOIT);
5149 }
5150 
5151 static void obrel_list_add(LinkNode **links, Object *ob)
5152 {
5153  BLI_linklist_prepend(links, ob);
5154  ob->id.tag |= LIB_TAG_DOIT;
5155 }
5156 
5158  eObjectSet objectSet,
5159  eObRelationTypes includeFilter)
5160 {
5161  LinkNode *links = nullptr;
5162 
5163  /* Remove markers from all objects */
5164  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
5165  base->object->id.tag &= ~LIB_TAG_DOIT;
5166  }
5167 
5168  /* iterate over all selected and visible objects */
5169  LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
5170  if (objectSet == OB_SET_ALL) {
5171  /* as we get all anyways just add it */
5172  Object *ob = base->object;
5173  obrel_list_add(&links, ob);
5174  }
5175  else {
5176  if ((objectSet == OB_SET_SELECTED && BASE_SELECTED_EDITABLE(((View3D *)nullptr), base)) ||
5177  (objectSet == OB_SET_VISIBLE && BASE_EDITABLE(((View3D *)nullptr), base))) {
5178  Object *ob = base->object;
5179 
5180  if (obrel_list_test(ob)) {
5181  obrel_list_add(&links, ob);
5182  }
5183 
5184  /* parent relationship */
5185  if (includeFilter & (OB_REL_PARENT | OB_REL_PARENT_RECURSIVE)) {
5186  Object *parent = ob->parent;
5187  if (obrel_list_test(parent)) {
5188 
5189  obrel_list_add(&links, parent);
5190 
5191  /* recursive parent relationship */
5192  if (includeFilter & OB_REL_PARENT_RECURSIVE) {
5193  parent = parent->parent;
5194  while (obrel_list_test(parent)) {
5195 
5196  obrel_list_add(&links, parent);
5197  parent = parent->parent;
5198  }
5199  }
5200  }
5201  }
5202 
5203  /* child relationship */
5204  if (includeFilter & (OB_REL_CHILDREN | OB_REL_CHILDREN_RECURSIVE)) {
5205  LISTBASE_FOREACH (Base *, local_base, &view_layer->object_bases) {
5206  if (BASE_EDITABLE(((View3D *)nullptr), local_base)) {
5207 
5208  Object *child = local_base->object;
5209  if (obrel_list_test(child)) {
5210  if ((includeFilter & OB_REL_CHILDREN_RECURSIVE &&
5211  BKE_object_is_child_recursive(ob, child)) ||
5212  (includeFilter & OB_REL_CHILDREN && child->parent && child->parent == ob)) {
5213  obrel_list_add(&links, child);
5214  }
5215  }
5216  }
5217  }
5218  }
5219 
5220  /* include related armatures */
5221  if (includeFilter & OB_REL_MOD_ARMATURE) {
5222  Object *arm = obrel_armature_find(ob);
5223  if (obrel_list_test(arm)) {
5224  obrel_list_add(&links, arm);
5225  }
5226  }
5227  }
5228  }
5229  }
5230 
5231  return links;
5232 }
5233 
5235 {
5236  LinkNode *collection_linknode = nullptr;
5237  Collection *collection = nullptr;
5238  while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
5239  BLI_linklist_prepend(&collection_linknode, collection);
5240  }
5241 
5242  return collection_linknode;
5243 }
5244 
5246 {
5247  Collection *collection = nullptr;
5248  while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) {
5249  BKE_collection_object_remove(bmain, collection, ob, false);
5251  }
5252 }
5253 
5256 /* -------------------------------------------------------------------- */
5260 KDTree_3d *BKE_object_as_kdtree(Object *ob, int *r_tot)
5261 {
5262  KDTree_3d *tree = nullptr;
5263  unsigned int tot = 0;
5264 
5265  switch (ob->type) {
5266  case OB_MESH: {
5267  Mesh *me = (Mesh *)ob->data;
5268  unsigned int i;
5269 
5270  Mesh *me_eval = ob->runtime.mesh_deform_eval ? ob->runtime.mesh_deform_eval :
5272  const int *index;
5273 
5274  if (me_eval && (index = (const int *)CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX))) {
5275  MVert *mvert = me_eval->mvert;
5276  uint totvert = me_eval->totvert;
5277 
5278  /* Tree over-allocates in case where some verts have #ORIGINDEX_NONE. */
5279  tot = 0;
5280  tree = BLI_kdtree_3d_new(totvert);
5281 
5282  /* We don't how many verts from the DM we can use. */
5283  for (i = 0; i < totvert; i++) {
5284  if (index[i] != ORIGINDEX_NONE) {
5285  float co[3];
5286  mul_v3_m4v3(co, ob->obmat, mvert[i].co);
5287  BLI_kdtree_3d_insert(tree, index[i], co);
5288  tot++;
5289  }
5290  }
5291  }
5292  else {
5293  MVert *mvert = me->mvert;
5294 
5295  tot = me->totvert;
5296  tree = BLI_kdtree_3d_new(tot);
5297 
5298  for (i = 0; i < tot; i++) {
5299  float co[3];
5300  mul_v3_m4v3(co, ob->obmat, mvert[i].co);
5301  BLI_kdtree_3d_insert(tree, i, co);
5302  }
5303  }
5304 
5305  BLI_kdtree_3d_balance(tree);
5306  break;
5307  }
5308  case OB_CURVES_LEGACY:
5309  case OB_SURF: {
5310  /* TODO: take deformation into account */
5311  Curve *cu = (Curve *)ob->data;
5312  unsigned int i, a;
5313 
5314  Nurb *nu;
5315 
5317  tree = BLI_kdtree_3d_new(tot);
5318  i = 0;
5319 
5320  nu = (Nurb *)cu->nurb.first;
5321  while (nu) {
5322  if (nu->bezt) {
5323  BezTriple *bezt;
5324 
5325  bezt = nu->bezt;
5326  a = nu->pntsu;
5327  while (a--) {
5328  float co[3];
5329  mul_v3_m4v3(co, ob->obmat, bezt->vec[1]);
5330  BLI_kdtree_3d_insert(tree, i++, co);
5331  bezt++;
5332  }
5333  }
5334  else {
5335  BPoint *bp;
5336 
5337  bp = nu->bp;
5338  a = nu->pntsu * nu->pntsv;
5339  while (a--) {
5340  float co[3];
5341  mul_v3_m4v3(co, ob->obmat, bp->vec);
5342  BLI_kdtree_3d_insert(tree, i++, co);
5343  bp++;
5344  }
5345  }
5346  nu = nu->next;
5347  }
5348 
5349  BLI_kdtree_3d_balance(tree);
5350  break;
5351  }
5352  case OB_LATTICE: {
5353  /* TODO: take deformation into account */
5354  Lattice *lt = (Lattice *)ob->data;
5355  BPoint *bp;
5356  unsigned int i;
5357 
5358  tot = lt->pntsu * lt->pntsv * lt->pntsw;
5359  tree = BLI_kdtree_3d_new(tot);
5360  i = 0;
5361 
5362  for (bp = lt->def; i < tot; bp++) {
5363  float co[3];
5364  mul_v3_m4v3(co, ob->obmat, bp->vec);
5365  BLI_kdtree_3d_insert(tree, i++, co);
5366  }
5367 
5368  BLI_kdtree_3d_balance(tree);
5369  break;
5370  }
5371  }
5372 
5373  *r_tot = tot;
5374  return tree;
5375 }
5376 
5379 /* -------------------------------------------------------------------- */
5386 static void object_cacheIgnoreClear(Object *ob, int state)
5387 {
5388  ListBase pidlist;
5389  BKE_ptcache_ids_from_object(&pidlist, ob, nullptr, 0);
5390 
5391  LISTBASE_FOREACH (PTCacheID *, pid, &pidlist) {
5392  if (pid->cache) {
5393  if (state) {
5394  pid->cache->flag |= PTCACHE_IGNORE_CLEAR;
5395  }
5396  else {
5397  pid->cache->flag &= ~PTCACHE_IGNORE_CLEAR;
5398  }
5399  }
5400  }
5401 
5402  BLI_freelistN(&pidlist);
5403 }
5404 
5406  Scene *scene,
5407  Object *ob,
5408  bool update_mesh,
5409  int parent_recursion,
5410  float frame,
5411  int type)
5412 {
5413  const bool flush_to_original = DEG_is_active(depsgraph);
5415 
5418 
5419  /* if other is dynamic paint canvas, don't update */
5420  if (pmd && pmd->canvas) {
5421  return true;
5422  }
5423  }
5424  else if (type == eModifierType_Fluid) {
5425  FluidModifierData *fmd = (FluidModifierData *)md;
5426 
5427  if (fmd && (fmd->type & MOD_FLUID_TYPE_DOMAIN) != 0) {
5428  return true;
5429  }
5430  }
5431 
5432  /* if object has parents, update them too */
5433  if (parent_recursion) {
5434  int recursion = parent_recursion - 1;
5435  bool no_update = false;
5436  if (ob->parent) {
5438  depsgraph, scene, ob->parent, false, recursion, frame, type);
5439  }
5440  if (ob->track) {
5442  depsgraph, scene, ob->track, false, recursion, frame, type);
5443  }
5444 
5445  /* skip subframe if object is parented
5446  * to vertex of a dynamic paint canvas */
5447  if (no_update && (ELEM(ob->partype, PARVERT1, PARVERT3))) {
5448  return false;
5449  }
5450 
5451  /* also update constraint targets */
5452  LISTBASE_FOREACH (bConstraint *, con, &ob->constraints) {
5453  ListBase targets = {nullptr, nullptr};
5454 
5455  if (BKE_constraint_targets_get(con, &targets)) {
5456  LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) {
5457  if (ct->tar) {
5459  depsgraph, scene, ct->tar, false, recursion, frame, type);
5460  }
5461  }
5462  /* free temp targets */
5463  BKE_constraint_targets_flush(con, &targets, false);
5464  }
5465  }
5466  }
5467 
5468  /* was originally ID_RECALC_ALL - TODO: which flags are really needed??? */
5469  /* TODO(sergey): What about animation? */
5471  frame);
5472 
5473  ob->id.recalc |= ID_RECALC_ALL;
5474  if (update_mesh) {
5476  &ob->id, ob->adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
5477  /* ignore cache clear during subframe updates
5478  * to not mess up cache validity */
5479  object_cacheIgnoreClear(ob, 1);
5481  object_cacheIgnoreClear(ob, 0);
5482  }
5483  else {
5485  }
5486 
5487  /* for curve following objects, parented curve has to be updated too */
5488  if (ob->type == OB_CURVES_LEGACY) {
5489  Curve *cu = (Curve *)ob->data;
5491  &cu->id, cu->adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
5492  }
5493  /* and armatures... */
5494  if (ob->type == OB_ARMATURE) {
5495  bArmature *arm = (bArmature *)ob->data;
5497  &arm->id, arm->adt, &anim_eval_context, ADT_RECALC_ANIM, flush_to_original);
5499  }
5500 
5501  return false;
5502 }
5503 
5505 {
5506  Object *ob = (Object *)bmain->objects.first;
5507  int select_id = 1;
5508  while (ob) {
5509  ob->runtime.select_id = select_id++;
5510  ob = (Object *)ob->id.next;
5511  }
5512 }
5513 
5516 /* -------------------------------------------------------------------- */
5520 Mesh *BKE_object_to_mesh(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
5521 {
5522  BKE_object_to_mesh_clear(object);
5523 
5524  Mesh *mesh = BKE_mesh_new_from_object(depsgraph, object, preserve_all_data_layers, false);
5525  object->runtime.object_as_temp_mesh = mesh;
5526  return mesh;
5527 }
5528 
5530 {
5531  if (object->runtime.object_as_temp_mesh == nullptr) {
5532  return;
5533  }
5534  BKE_id_free(nullptr, object->runtime.object_as_temp_mesh);
5535  object->runtime.object_as_temp_mesh = nullptr;
5536 }
5537 
5538 Curve *BKE_object_to_curve(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
5539 {
5540  BKE_object_to_curve_clear(object);
5541 
5542  Curve *curve = BKE_curve_new_from_object(object, depsgraph, apply_modifiers);
5543  object->runtime.object_as_temp_curve = curve;
5544  return curve;
5545 }
5546 
5548 {
5549  if (object->runtime.object_as_temp_curve == nullptr) {
5550  return;
5551  }
5552  BKE_id_free(nullptr, object->runtime.object_as_temp_curve);
5553  object->runtime.object_as_temp_curve = nullptr;
5554 }
5555 
5557 {
5560 }
5561 
5563  struct Object *ob,
5564  struct ID **idpoin,
5565  int cb_flag)
5566 {
5567  BlendLibReader *reader = (BlendLibReader *)userData;
5568 
5569  BLO_read_id_address(reader, ob->id.lib, idpoin);
5570  if (*idpoin != nullptr && (cb_flag & IDWALK_CB_USER) != 0) {
5571  id_us_plus_no_lib(*idpoin);
5572  }
5573 }
5574 
5576 {
5577  ModifierData *md = (ModifierData *)(ob->modifiers.last);
5578 
5579  while (md) {
5580  if (md->type == eModifierType_Subsurf) {
5581  break;
5582  }
5583 
5584  md = md->prev;
5585  }
5586 
5587  return (SubsurfModifierData *)(md);
5588 }
5589 
5591 {
5592  ob->type = BKE_object_obdata_to_type(new_data);
5593  ob->data = (void *)new_data;
5594  ob->runtime.geometry_set_eval = nullptr;
5595  ob->runtime.data_eval = new_data;
5596  if (ob->runtime.bb != nullptr) {
5597  ob->runtime.bb->flag |= BOUNDBOX_DIRTY;
5598  }
5599  ob->id.py_instance = nullptr;
5600 }
5601 
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
void BKE_pose_tag_recalc(struct Main *bmain, struct bPose *pose)
Definition: action.c:1719
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
void BKE_pose_check_uuids_unique_and_report(const struct bPose *pose)
void BKE_pose_blend_read_expand(struct BlendExpander *expander, struct bPose *pose)
Definition: action.c:1975
void BKE_pose_free_ex(struct bPose *pose, bool do_id_user)
Definition: action.c:1129
void BKE_pose_free(struct bPose *pose)
Definition: action.c:1138
void BKE_pose_blend_write(struct BlendWriter *writer, struct bPose *pose, struct bArmature *arm)
Definition: action.c:1832
void BKE_pose_blend_read_data(struct BlendDataReader *reader, struct bPose *pose)
Definition: action.c:1884
void BKE_pose_channels_hash_ensure(struct bPose *pose)
Definition: action.c:925
void BKE_pose_copy_data_ex(struct bPose **dst, const struct bPose *src, int flag, bool copy_constraints)
void BKE_pose_update_constraint_flags(struct bPose *pose)
Definition: action.c:1192
void BKE_pose_blend_read_lib(struct BlendLibReader *reader, struct Object *ob, struct bPose *pose)
Definition: action.c:1932
bool BKE_animdata_id_is_animated(const struct ID *id)
Definition: anim_data.c:238
void BKE_animdata_blend_read_data(struct BlendDataReader *reader, struct AnimData *adt)
Definition: anim_data.c:1443
void BKE_animdata_blend_write(struct BlendWriter *writer, struct AnimData *adt)
Definition: anim_data.c:1421
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 animviz_free_motionpath(struct bMotionPath *mpath)
struct bMotionPath * animviz_copy_motionpath(const struct bMotionPath *mpath_src)
void animviz_motionpath_blend_write(struct BlendWriter *writer, struct bMotionPath *mpath)
void animviz_motionpath_blend_read_data(struct BlendDataReader *reader, struct bMotionPath *mpath)
void animviz_settings_init(struct bAnimVizSettings *avs)
AnimationEvalContext BKE_animsys_eval_context_construct(struct Depsgraph *depsgraph, float eval_time)
Definition: anim_sys.c:761
@ ADT_RECALC_ANIM
Definition: BKE_animsys.h:290
@ ADT_RECALC_ALL
Definition: BKE_animsys.h:291
void BKE_animsys_evaluate_animdata(struct ID *id, struct AnimData *adt, const struct AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, bool flush_to_original)
bool BKE_pose_minmax(struct Object *ob, float r_min[3], float r_max[3], bool use_hidden, bool use_select)
Definition: armature.c:2711
struct BoundBox * BKE_armature_boundbox_get(struct Object *ob)
Definition: armature.c:2657
struct bArmature * BKE_armature_add(struct Main *bmain, const char *name)
Definition: armature.c:334
void BKE_pose_where_is(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
Definition: armature.c:2538
void BKE_pose_rebuild(struct Main *bmain, struct Object *ob, struct bArmature *arm, bool do_id_user)
Definition: armature.c:2362
void BKE_asset_metadata_idprop_ensure(struct AssetMetaData *asset_data, struct IDProperty *prop)
Definition: asset.cc:125
bool BKE_bpath_foreach_path_fixed_process(struct BPathForeachPathData *bpath_data, char *path)
Definition: bpath.c:121
Camera data-block and utility functions.
void * BKE_camera_add(struct Main *bmain, const char *name)
Definition: camera.c:203
struct Collection * BKE_collection_object_find(struct Main *bmain, struct Scene *scene, struct Collection *collection, struct Object *ob)
Definition: collection.c:950
void BKE_collection_object_add_from(struct Main *bmain, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst)
Definition: collection.c:1148
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
Definition: collection.c:1125
bool BKE_collection_viewlayer_object_add(struct Main *bmain, const struct ViewLayer *view_layer, struct Collection *collection, struct Object *ob)
bool BKE_collection_has_object_recursive(struct Collection *collection, struct Object *ob)
Definition: collection.c:921
bool BKE_collection_object_remove(struct Main *bmain, struct Collection *collection, struct Object *object, bool free_us)
Definition: collection.c:1170
void BKE_constraints_id_loop(struct ListBase *list, ConstraintIDFunc func, void *userdata)
Definition: constraint.c:5877
void BKE_constraints_free_ex(struct ListBase *list, bool do_id_user)
Definition: constraint.c:5576
void BKE_constraints_solve(struct Depsgraph *depsgraph, struct ListBase *conlist, struct bConstraintOb *cob, float ctime)
Definition: constraint.c:6352
void BKE_constraint_targets_flush(struct bConstraint *con, struct ListBase *targets, bool no_copy)
Definition: constraint.c:6186
void BKE_constraint_blend_write(struct BlendWriter *writer, struct ListBase *conlist)
Definition: constraint.c:6437
void BKE_constraint_blend_read_expand(struct BlendExpander *expander, struct ListBase *lb)
Definition: constraint.c:6596
void BKE_constraint_blend_read_data(struct BlendDataReader *reader, struct ListBase *lb)
Definition: constraint.c:6489
int BKE_constraint_targets_get(struct bConstraint *con, struct ListBase *r_targets)
Definition: constraint.c:6157
struct bConstraintOb * BKE_constraints_make_evalob(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, void *subdata, short datatype)
Definition: constraint.c:119
void BKE_constraint_blend_read_lib(struct BlendLibReader *reader, struct ID *id, struct ListBase *conlist)
Definition: constraint.c:6559
void BKE_constraints_copy_ex(struct ListBase *dst, const struct ListBase *src, int flag, bool do_extern)
void BKE_constraints_clear_evalob(struct bConstraintOb *cob)
Definition: constraint.c:196
void BKE_crazyspace_api_eval_clear(struct Object *object)
Definition: crazyspace.cc:585
void BKE_curve_bevelList_free(struct ListBase *bev)
Definition: curve.cc:2551
void BKE_curve_texspace_ensure(struct Curve *cu)
Definition: curve.cc:555
struct Curve * BKE_curve_add(struct Main *bmain, const char *name, int type)
Definition: curve.cc:414
bool BKE_nurbList_index_get_co(struct ListBase *editnurb, int index, float r_co[3])
Definition: curve.cc:562
struct BoundBox * BKE_curve_boundbox_get(struct Object *ob)
Definition: curve.cc:494
short BKE_curve_type_get(const struct Curve *cu)
int BKE_nurbList_verts_count_without_handles(const struct ListBase *nurb)
void BKE_nurbList_free(struct ListBase *lb)
Definition: curve.cc:649
struct Curve * BKE_curve_new_from_object(struct Object *object, struct Depsgraph *depsgraph, bool apply_modifiers)
Definition: curve_convert.c:56
ListBase * BKE_curve_nurbs_get(struct Curve *cu)
Definition: curve.cc:4976
void * BKE_curves_add(struct Main *bmain, const char *name)
Definition: curves.cc:231
struct BoundBox * BKE_curves_boundbox_get(struct Object *ob)
Definition: curves.cc:238
Low-level operations for curves.
void CustomData_copy_layer_type_data(const struct CustomData *source, struct CustomData *destination, int type, int source_index, int destination_index, int count)
bool CustomData_free_layer(struct CustomData *data, int type, int totelem, int index)
Definition: customdata.cc:2831
@ CD_CALLOC
bool CustomData_has_layer(const struct CustomData *data, int type)
#define ORIGINDEX_NONE
int CustomData_get_layer_index(const struct CustomData *data, int type)
void * CustomData_get_layer(const struct CustomData *data, int type)
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
Definition: customdata.cc:2776
support for deformation groups and hooks.
display list (or rather multi purpose list) stuff.
void BKE_displist_free(struct ListBase *lb)
Definition: displist.cc:69
@ DL_VERTS
Definition: BKE_displist.h:31
DispList * BKE_displist_find(struct ListBase *lb, int type)
Definition: displist.cc:78
void BKE_displist_minmax(const struct ListBase *dispbase, float min[3], float max[3])
struct ListBase * object_duplilist(struct Depsgraph *depsgraph, struct Scene *sce, struct Object *ob)
void free_object_duplilist(struct ListBase *lb)
void BKE_partdeflect_free(struct PartDeflect *pd)
Definition: effect.c:122
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
Definition: effect.c:58
void BKE_geometry_set_free(struct GeometrySet *geometry_set)
bool BKE_object_has_geometry_set_instances(const struct Object *ob)
@ G_DEBUG_DEPSGRAPH_EVAL
Definition: BKE_global.h:183
void BKE_gpencil_eval_delete(struct bGPdata *gpd_eval)
Definition: gpencil.c:498
void BKE_gpencil_visible_stroke_iter(struct bGPdata *gpd, gpIterCb layer_cb, gpIterCb stroke_cb, void *thunk)
Definition: gpencil.c:2389
struct bGPdata * BKE_gpencil_data_addnew(struct Main *bmain, const char name[])
Definition: gpencil.c:705
struct BoundBox * BKE_gpencil_boundbox_get(struct Object *ob)
void void BKE_gpencil_modifiers_foreach_ID_link(struct Object *ob, GreasePencilIDWalkFunc walk, void *userData)
bool BKE_gpencil_modifier_unique_name(struct ListBase *modifiers, struct GpencilModifierData *gmd)
void BKE_gpencil_modifier_copydata_ex(struct GpencilModifierData *md, struct GpencilModifierData *target, int flag)
void BKE_gpencil_modifier_blend_read_lib(struct BlendLibReader *reader, struct Object *ob)
void BKE_gpencil_modifier_blend_read_data(struct BlendDataReader *reader, struct ListBase *lb)
void BKE_gpencil_modifier_blend_write(struct BlendWriter *writer, struct ListBase *modbase)
void BKE_gpencil_modifier_free_ex(struct GpencilModifierData *md, int flag)
const GpencilModifierTypeInfo * BKE_gpencil_modifier_get_info(GpencilModifierType type)
struct GpencilModifierData * BKE_gpencil_modifier_new(int type)
void BKE_previewimg_free(struct PreviewImage **prv)
Definition: icons.cc:283
void BKE_previewimg_id_copy(struct ID *new_id, const struct ID *old_id)
void BKE_previewimg_blend_read(struct BlendDataReader *reader, struct PreviewImage *prv)
Definition: icons.cc:615
void BKE_previewimg_blend_write(struct BlendWriter *writer, const struct PreviewImage *prv)
void IDP_foreach_property(struct IDProperty *id_property_root, int type_filter, IDPForeachPropertyCallback callback, void *user_data)
Definition: idprop.c:1117
struct IDProperty * IDP_New(char type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: idprop.c:887
#define IDP_Array(prop)
Definition: BKE_idprop.h:245
void BKE_keyblock_convert_to_curve(struct KeyBlock *kb, struct Curve *cu, struct ListBase *nurb)
void BKE_keyblock_convert_from_curve(const struct Curve *cu, struct KeyBlock *kb, const struct ListBase *nurb)
float * BKE_key_evaluate_object(struct Object *ob, int *r_totelem)
Definition: key.c:1632
void BKE_keyblock_convert_from_mesh(const struct Mesh *me, const struct Key *key, struct KeyBlock *kb)
struct Key ** BKE_key_from_object_p(struct Object *ob)
Definition: key.c:1794
void BKE_keyblock_convert_to_lattice(const struct KeyBlock *kb, struct Lattice *lt)
void BKE_keyblock_convert_to_mesh(const struct KeyBlock *kb, struct MVert *mvert, int totvert)
struct Key * BKE_key_from_object(struct Object *ob)
Definition: key.c:1803
struct KeyBlock * BKE_keyblock_add_ctime(struct Key *key, const char *name, bool do_force)
Definition: key.c:1862
struct Key * BKE_key_add(struct Main *bmain, struct ID *id)
Definition: key.c:252
void BKE_keyblock_convert_from_lattice(const struct Lattice *lt, struct KeyBlock *kb)
void BKE_lattice_transform(struct Lattice *lt, const float mat[4][4], bool do_keys)
Definition: lattice.c:706
struct BoundBox * BKE_lattice_boundbox_get(struct Object *ob)
Definition: lattice.c:652
struct Lattice * BKE_lattice_add(struct Main *bmain, const char *name)
Definition: lattice.c:392
struct LayerCollection * BKE_layer_collection_get_active(struct ViewLayer *view_layer)
Definition: layer.c:636
void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer)
Definition: layer.c:388
struct Base * BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob)
Definition: layer.c:379
struct Base ** BKE_view_layer_array_from_bases_in_mode_params(struct ViewLayer *view_layer, const struct View3D *v3d, uint *r_len, const struct ObjectsInModeParams *params)
void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, struct Base *selbase)
Definition: layer.c:397
struct Object ** BKE_view_layer_array_from_objects_in_mode_params(struct ViewLayer *view_layer, const struct View3D *v3d, uint *len, const struct ObjectsInModeParams *params)
@ LIB_ID_COPY_NO_PREVIEW
Definition: BKE_lib_id.h:150
@ LIB_ID_COPY_CACHES
Definition: BKE_lib_id.h:152
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
Definition: BKE_lib_id.h:143
@ LIB_ID_CREATE_NO_USER_REFCOUNT
Definition: BKE_lib_id.h:126
@ LIB_ID_CREATE_NO_MAIN
Definition: BKE_lib_id.h:122
@ LIB_ID_COPY_DEFAULT
Definition: BKE_lib_id.h:181
@ LIB_ID_COPY_RIGID_BODY_NO_COLLECTION_HANDLING
Definition: BKE_lib_id.h:177
void BKE_main_id_newptr_and_tag_clear(struct Main *bmain)
Definition: lib_id.c:1465
void BKE_libblock_free_data(struct ID *id, bool do_id_user) ATTR_NONNULL()
Definition: lib_id_delete.c:44
void id_us_min(struct ID *id)
Definition: lib_id.c:313
void * BKE_libblock_alloc(struct Main *bmain, short type, const char *name, int flag) ATTR_WARN_UNUSED_RESULT
Definition: lib_id.c:1050
void BKE_id_free(struct Main *bmain, void *idv)
void BKE_libblock_free_datablock(struct ID *id, int flag) ATTR_NONNULL()
void id_us_plus(struct ID *id)
Definition: lib_id.c:305
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2008
void id_us_plus_no_lib(struct ID *id)
Definition: lib_id.c:289
struct ID * BKE_id_copy_for_duplicate(struct Main *bmain, struct ID *id, uint duplicate_flags, int copy_flags)
@ LIB_ID_DUPLICATE_IS_ROOT_ID
Definition: BKE_lib_id.h:228
@ LIB_ID_DUPLICATE_IS_SUBPROCESS
Definition: BKE_lib_id.h:225
void BKE_id_free_us(struct Main *bmain, void *idv) ATTR_NONNULL()
void BKE_lib_query_foreachid_process(struct LibraryForeachIDData *data, struct ID **id_pp, int cb_flag)
Definition: lib_query.c:68
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(_data, _id_super, _cb_flag)
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(_data, _func_call)
void BKE_lib_query_idpropertiesForeachIDLink_callback(struct IDProperty *id_prop, void *user_data)
Definition: lib_query.c:136
@ IDWALK_CB_NEVER_SELF
Definition: BKE_lib_query.h:35
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:73
@ IDWALK_CB_NEVER_NULL
Definition: BKE_lib_query.h:34
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:33
#define BKE_LIB_FOREACHID_PROCESS_ID(_data, _id, _cb_flag)
void BKE_libblock_relink_to_newid(struct Main *bmain, struct ID *id, int remap_flag) ATTR_NONNULL()
Definition: lib_remap.c:894
General operations, lookup, etc. for blender lights.
struct Light * BKE_light_add(struct Main *bmain, const char *name) ATTR_WARN_UNUSED_RESULT
Definition: light.c:203
General operations for probes.
void * BKE_lightprobe_add(struct Main *bmain, const char *name)
Definition: lightprobe.c:124
Blender kernel freestyle line style functionality.
#define FOREACH_MAIN_ID_END
Definition: BKE_main.h:367
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition: BKE_main.h:361
General operations, lookup, etc. for materials.
struct Material *** BKE_object_material_array_p(struct Object *ob)
Definition: material.c:311
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id)
Definition: material.c:864
struct MetaBall * BKE_mball_add(struct Main *bmain, const char *name)
Definition: mball.c:200
bool BKE_mball_minmax_ex(const struct MetaBall *mb, float min[3], float max[3], const float obmat[4][4], short flag)
struct BoundBox * BKE_mball_boundbox_get(struct Object *ob)
Definition: mball.c:298
struct BoundBox * BKE_mesh_boundbox_get(struct Object *ob)
Definition: mesh.cc:1207
void BKE_mesh_texspace_get_reference(struct Mesh *me, char **r_texflag, float **r_loc, float **r_size)
Definition: mesh.cc:1287
void BKE_mesh_ensure_skin_customdata(struct Mesh *me)
Definition: mesh.cc:786
struct Mesh * BKE_mesh_add(struct Main *bmain, const char *name)
Definition: mesh.cc:963
void BKE_mesh_eval_delete(struct Mesh *mesh_eval)
Definition: mesh.cc:1117
struct Mesh * BKE_mesh_new_from_object(struct Depsgraph *depsgraph, struct Object *object, bool preserve_all_data_layers, bool preserve_origindex)
bool BKE_mesh_wrapper_minmax(const struct Mesh *me, float min[3], float max[3])
struct Mesh * BKE_mesh_wrapper_ensure_subdivision(struct Mesh *me)
void BKE_modifier_copydata_ex(const struct ModifierData *md, struct ModifierData *target, int flag)
void BKE_modifier_check_uuids_unique_and_report(const struct Object *object)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
struct Object * BKE_modifiers_is_deformed_by_armature(struct Object *ob)
void BKE_modifier_blend_read_lib(struct BlendLibReader *reader, struct Object *ob)
bool BKE_modifier_is_enabled(const struct Scene *scene, struct ModifierData *md, int required_mode)
@ eModifierTypeFlag_Single
Definition: BKE_modifier.h:93
@ eModifierTypeFlag_AcceptsCVs
Definition: BKE_modifier.h:67
@ eModifierTypeFlag_AcceptsVertexCosOnly
Definition: BKE_modifier.h:100
@ eModifierTypeFlag_AcceptsMesh
Definition: BKE_modifier.h:66
struct ModifierData * BKE_modifiers_get_virtual_modifierlist(const struct Object *ob, struct VirtualModifierData *data)
void BKE_modifier_free_ex(struct ModifierData *md, int flag)
void BKE_modifier_copydata(const struct ModifierData *md, struct ModifierData *target)
void BKE_modifier_blend_write(struct BlendWriter *writer, const struct ID *id_owner, struct ListBase *modbase)
struct ModifierData * BKE_modifiers_findby_type(const struct Object *ob, ModifierType type)
struct ModifierData * BKE_modifier_new(int type)
@ eModifierTypeType_OnlyDeform
Definition: BKE_modifier.h:44
void BKE_modifiers_foreach_ID_link(struct Object *ob, IDWalkFunc walk, void *userData)
void BKE_modifier_blend_read_data(struct BlendDataReader *reader, struct ListBase *lb, struct Object *ob)
struct ModifierData * BKE_modifier_copy_ex(const struct ModifierData *md, int flag)
bool BKE_modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md)
bool multiresModifier_reshapeFromCCG(int tot_level, struct Mesh *coarse_mesh, struct SubdivCCG *subdiv_ccg)
void multiresModifier_sync_levels_ex(struct Object *ob_dst, struct MultiresModifierData *mmd_src, struct MultiresModifierData *mmd_dst)
Definition: multires.c:1330
General operations, lookup, etc. for blender objects.
eObRelationTypes
Definition: BKE_object.h:603
@ OB_REL_MOD_ARMATURE
Definition: BKE_object.h:609
@ OB_REL_PARENT
Definition: BKE_object.h:605
@ OB_REL_CHILDREN_RECURSIVE
Definition: BKE_object.h:608
@ OB_REL_PARENT_RECURSIVE
Definition: BKE_object.h:606
@ OB_REL_CHILDREN
Definition: BKE_object.h:607
void BKE_object_handle_data_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
@ OB_VISIBLE_INSTANCES
Definition: BKE_object.h:152
@ OB_VISIBLE_SELF
Definition: BKE_object.h:150
@ OB_VISIBLE_PARTICLES
Definition: BKE_object.h:151
eObjectSet
Definition: BKE_object.h:613
@ OB_SET_SELECTED
Definition: BKE_object.h:614
@ OB_SET_VISIBLE
Definition: BKE_object.h:615
@ OB_SET_ALL
Definition: BKE_object.h:616
Functions for dealing with object face-maps.
void BKE_object_facemap_copy_list(struct ListBase *outbase, const struct ListBase *inbase)
void BKE_sculptsession_free(struct Object *ob)
Definition: paint.c:1469
void BKE_particle_system_blend_read_lib(struct BlendLibReader *reader, struct Object *ob, struct ID *id, struct ListBase *particles)
Definition: particle.c:5419
void BKE_particle_system_blend_read_data(struct BlendDataReader *reader, struct ListBase *particles)
Definition: particle.c:5331
void BKE_particle_partdeflect_blend_read_lib(struct BlendLibReader *reader, struct ID *id, struct PartDeflect *pd)
Definition: particle.c:359
void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit)
Definition: particle.c:997
void BKE_particle_partdeflect_blend_read_data(struct BlendDataReader *reader, struct PartDeflect *pd)
void BKE_particle_system_blend_write(struct BlendWriter *writer, struct ListBase *particles)
Definition: particle.c:5287
void psys_free(struct Object *ob, struct ParticleSystem *psys)
Definition: particle.c:1068
void BKE_particlesystem_id_loop(struct ParticleSystem *psys, ParticleSystemIDFunc func, void *userdata)
void psys_copy_particles(struct ParticleSystem *psys_dst, struct ParticleSystem *psys_src)
Definition: particle.c:1147
struct ModifierData * object_copy_particle_system(struct Main *bmain, struct Scene *scene, struct Object *ob, const struct ParticleSystem *psys_orig)
A BVH for high poly meshes.
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob, struct Scene *scene, int duplis)
Definition: pointcache.c:1250
struct PointCache * BKE_ptcache_copy_list(struct ListBase *ptcaches_new, const struct ListBase *ptcaches_old, int flag)
void BKE_ptcache_blend_read_data(struct BlendDataReader *reader, struct ListBase *ptcaches, struct PointCache **ocache, int force_disk)
Definition: pointcache.c:3896
void BKE_ptcache_blend_write(struct BlendWriter *writer, struct ListBase *ptcaches)
Definition: pointcache.c:3820
General operations for point clouds.
struct BoundBox * BKE_pointcloud_boundbox_get(struct Object *ob)
Definition: pointcloud.cc:295
void * BKE_pointcloud_add_default(struct Main *bmain, const char *name)
Definition: pointcloud.cc:226
API for Blender-side Rigid Body stuff.
void BKE_rigidbody_free_constraint(struct Object *ob)
Definition: rigidbody.c:193
void BKE_rigidbody_free_object(struct Object *ob, struct RigidBodyWorld *rbw)
Definition: rigidbody.c:146
void BKE_rigidbody_object_copy(struct Main *bmain, struct Object *ob_dst, const struct Object *ob_src, int flag)
void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime)
Definition: rigidbody.c:2345
void BKE_shaderfx_foreach_ID_link(struct Object *ob, ShaderFxIDWalkFunc walk, void *userData)
Definition: shader_fx.c:246
void BKE_shaderfx_free_ex(struct ShaderFxData *fx, int flag)
Definition: shader_fx.c:97
void BKE_shaderfx_blend_write(struct BlendWriter *writer, struct ListBase *fxbase)
Definition: shader_fx.c:264
void BKE_shaderfx_blend_read_lib(struct BlendLibReader *reader, struct Object *ob)
Definition: shader_fx.c:294
struct ShaderFxData * BKE_shaderfx_new(int type)
Definition: shader_fx.c:62
void BKE_shaderfx_copydata_ex(struct ShaderFxData *fx, struct ShaderFxData *target, int flag)
Definition: shader_fx.c:196
void BKE_shaderfx_blend_read_data(struct BlendDataReader *reader, struct ListBase *lb)
Definition: shader_fx.c:280
void sbFree(struct Object *ob)
Definition: softbody.c:3148
General operations for speakers.
void * BKE_speaker_add(struct Main *bmain, const char *name)
Definition: speaker.c:109
Volume data-block.
struct BoundBox * BKE_volume_boundbox_get(struct Object *ob)
Definition: volume.cc:1007
void * BKE_volume_add(struct Main *bmain, const char *name)
Definition: volume.cc:690
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
A KD-tree for nearest neighbor search.
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:221
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:60
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:239
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:273
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void void BLI_listbase_sort(struct ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:100
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define BLI_ASSERT_UNIT_M3(m)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void size_to_mat3(float R[3][3], const float size[3])
Definition: math_matrix.c:2098
bool invert_m4(float R[4][4])
Definition: math_matrix.c:1206
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:71
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:87
void unit_m4(float m[4][4])
Definition: rct.c:1090
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:102
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
Definition: math_matrix.c:2224
void orthogonalize_m4_stable(float R[4][4], int axis, bool normalize)
Definition: math_matrix.c:1678
void scale_m4_fl(float R[4][4], float scale)
Definition: math_matrix.c:2297
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
bool is_negative_m4(const float mat[4][4])
Definition: math_matrix.c:2509
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2138
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:388
void mul_m4_m4_post(float R[4][4], const float B[4][4])
Definition: math_matrix.c:380
void eulO_to_mat3(float mat[3][3], const float eul[3], short order)
float tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3])
void invert_qt_normalized(float q[4])
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
float normalize_qt(float q[4])
float normalize_qt_qt(float r[4], const float q[4])
void quat_to_compatible_eulO(float eul[3], const float old[3], short order, const float quat[4])
void quat_to_eulO(float eul[3], short order, const float quat[4])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
Definition: math_rotation.c:46
void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
void eulO_to_quat(float quat[4], const float eul[3], short order)
void quat_apply_track(float quat[4], short axis, short upflag)
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:33
void quat_to_mat3(float mat[3][3], const float q[4])
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
void quat_to_mat4(float mat[4][4], const float q[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
Definition: math_vector.c:867
MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE bool is_zero_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void project_plane_v3_v3v3(float out[3], const float p[3], const float v_plane[3])
Definition: math_vector.c:638
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void zero_v2(float r[2])
MINLINE void zero_v3(float r[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3])
Definition: math_vector.c:256
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
unsigned int uint
Definition: BLI_sys_types.h:67
#define BLI_MUTEX_INITIALIZER
Definition: BLI_threads.h:83
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:373
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:378
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:82
#define CLAMP_MAX(a, c)
#define ARRAY_SIZE(arr)
#define POINTER_FROM_INT(i)
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
#define POINTER_AS_INT(i)
#define ELEM(...)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
#define BLO_read_data_address(reader, ptr_p)
struct Main * BLO_read_lib_get_main(BlendLibReader *reader)
Definition: readfile.c:5313
ID * BLO_read_get_new_id_address(BlendLibReader *reader, struct Library *lib, struct ID *id)
Definition: readfile.c:5138
struct BlendFileReadReport * BLO_read_lib_reports(BlendLibReader *reader)
Definition: readfile.c:5318
bool BLO_read_data_is_undo(BlendDataReader *reader)
Definition: readfile.c:5288
void BLO_read_int32_array(BlendDataReader *reader, int array_size, int32_t **ptr_p)
Definition: readfile.c:5177
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_list(BlendDataReader *reader, struct ListBase *list)
Definition: readfile.c:5172
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_expand(expander, id)
#define BLO_write_struct_list(writer, struct_name, list_ptr)
void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr)
Definition: writefile.c:1489
void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p)
Definition: readfile.c:5245
void BLO_reportf_wrap(struct BlendFileReadReport *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1608
void BLO_write_pointer_array(BlendWriter *writer, uint num, const void *data_ptr)
Definition: writefile.c:1591
external readfile function prototypes.
#define TIP_(msgid)
#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:190
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:189
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
bool DEG_is_active(const struct Depsgraph *depsgraph)
Definition: depsgraph.cc:312
eEvaluationMode
Definition: DEG_depsgraph.h:44
@ DAG_EVAL_RENDER
Definition: DEG_depsgraph.h:46
@ DAG_EVAL_VIEWPORT
Definition: DEG_depsgraph.h:45
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_id_tag_update(struct ID *id, int flag)
float DEG_get_ctime(const Depsgraph *graph)
#define DEG_OBJECT_ITER_END
struct Object * DEG_get_original_object(struct Object *object)
bool DEG_is_original_id(const struct ID *id)
#define DEG_OBJECT_ITER_BEGIN(graph_, instance_, flag_)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_DUPLI
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
@ IDP_TYPE_FILTER_ID
Definition: DNA_ID.h:155
#define FILTER_ID_OB
Definition: DNA_ID.h:916
@ IDP_FLOAT
Definition: DNA_ID.h:138
@ IDP_ARRAY
Definition: DNA_ID.h:140
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
@ ID_RECALC_PSYS_REDO
Definition: DNA_ID.h:798
@ ID_RECALC_EDITORS
Definition: DNA_ID.h:828
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:794
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
@ ID_RECALC_ALL
Definition: DNA_ID.h:891
@ INDEX_ID_OB
Definition: DNA_ID.h:1039
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
@ LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT
Definition: DNA_ID.h:730
@ LIB_TAG_INDIRECT
Definition: DNA_ID.h:677
@ LIB_TAG_NEW
Definition: DNA_ID.h:704
@ LIB_TAG_COPIED_ON_WRITE
Definition: DNA_ID.h:720
@ LIB_TAG_DOIT
Definition: DNA_ID.h:707
@ LIB_TAG_EXTERN
Definition: DNA_ID.h:674
@ LIB_TAG_NO_MAIN
Definition: DNA_ID.h:744
@ ID_CA
Definition: DNA_ID_enums.h:56
@ ID_AR
Definition: DNA_ID_enums.h:66
@ ID_VO
Definition: DNA_ID_enums.h:83
@ ID_LA
Definition: DNA_ID_enums.h:55
@ ID_GD
Definition: DNA_ID_enums.h:71
@ ID_CV
Definition: DNA_ID_enums.h:81
@ ID_LP
Definition: DNA_ID_enums.h:80
@ ID_CU_LEGACY
Definition: DNA_ID_enums.h:49
@ ID_ME
Definition: DNA_ID_enums.h:48
@ ID_SPK
Definition: DNA_ID_enums.h:63
@ ID_MB
Definition: DNA_ID_enums.h:50
@ ID_LT
Definition: DNA_ID_enums.h:54
@ ID_OB
Definition: DNA_ID_enums.h:47
@ ID_PT
Definition: DNA_ID_enums.h:82
@ ROT_MODE_QUAT
@ ROT_MODE_MAX
@ ROT_MODE_AXISANGLE
@ ROT_MODE_MIN
@ ROT_MODE_EUL
@ POSE_ROT
@ POSE_LOC
@ POSE_SIZE
@ POSE_CONSTRAINTS_NEED_UPDATE_FLAGS
@ POSE_RECALC
@ BONE_RELATIVE_PARENTING
Object groups, one object can be in many groups at once.
@ CONSTRAINT_OFF
@ CONSTRAINT_TYPE_CAMERASOLVER
@ CONSTRAINT_OBTYPE_OBJECT
@ CAMERASOLVER_ACTIVECLIP
@ CU_FOLLOW
@ CU_PATH
@ CU_PATH_RADIUS
@ CU_PATH_CLAMP
@ CD_ORIGINDEX
@ CD_GRID_PAINT_MASK
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:29
#define EFF_PARTICLE
#define EFF_WAVE
#define EFF_BUILD
@ FLUID_FLOW_NEEDS_UPDATE
@ FLUID_DOMAIN_FILE_LOAD
@ FLUID_EFFECTOR_NEEDS_UPDATE
#define GPENCIL_EDIT_MODE(gpd)
#define IMA_ANIM_ALWAYS
@ KEY_RELATIVE
@ BASE_FROM_DUPLI
@ BASE_VISIBLE_DEPSGRAPH
@ BASE_SELECTED
@ ME_WRAPPER_TYPE_BMESH
#define ME_EDIT_PAINT_SEL_MODE(_me)
@ eModifierFlag_Active
@ eModifierMode_Render
@ eModifierMode_Realtime
@ eParticleSystemFlag_file_loaded
ModifierType
@ eModifierType_ParticleSystem
@ eModifierType_Fluidsim
@ eModifierType_Subsurf
@ eModifierType_Mirror
@ eModifierType_Skin
@ eModifierType_Wave
@ eModifierType_Cloth
@ eModifierType_Fluid
@ eModifierType_MeshSequenceCache
@ eModifierType_Hook
@ eModifierType_Screw
@ eModifierType_Ocean
@ eModifierType_Armature
@ eModifierType_Nodes
@ eModifierType_Collision
@ eModifierType_DynamicPaint
@ eModifierType_MeshCache
@ eModifierType_Array
@ eModifierType_Softbody
@ eModifierType_Multires
@ eModifierType_Build
@ MOD_FLUID_TYPE_EFFEC
@ MOD_FLUID_TYPE_DOMAIN
@ MOD_FLUID_TYPE_FLOW
#define OB_MODE_ALL_MODE_DATA
eObjectMode
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_WEIGHT_GPENCIL
@ OB_MODE_SCULPT
@ OB_MODE_POSE
@ OB_MODE_OBJECT
@ OB_MODE_VERTEX_PAINT
#define OB_MODE_ALL_SCULPT
Object is a sort of wrapper for general info.
@ OB_HIDE_CAMERA
@ OB_SHADOW_CATCHER
@ OB_EMPTY_CONE
@ OB_SINGLE_ARROW
@ OB_PLAINAXES
@ OB_ARROWS
@ OB_CIRCLE
@ OB_CUBE
@ OB_EMPTY_IMAGE
@ OB_EMPTY_SPHERE
#define OB_TYPE_SUPPORT_PARVERT(_type)
@ OB_SPEAKER
@ OB_LATTICE
@ OB_MBALL
@ OB_EMPTY
@ OB_SURF
@ OB_CAMERA
@ OB_FONT
@ OB_ARMATURE
@ OB_LAMP
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_GPENCIL
@ OB_LIGHTPROBE
@ OB_NEGZ
@ OB_POSY
@ OB_POSZ
@ BOUNDBOX_DIRTY
@ OB_LOCK_ROT4D
@ OB_LOCK_ROTX
@ OB_LOCK_SCALEX
@ OB_LOCK_ROTW
@ OB_LOCK_LOCX
@ OB_DUPLI_FLAG_VIEWPORT
@ OB_DUPLI_FLAG_RENDER
@ OB_USE_GPENCIL_LIGHTS
#define OB_DATA_SUPPORT_EDITMODE(_type)
struct Object Object
@ OB_DUPLI
@ OB_NO_CONSTRAINTS
@ OB_NEG_SCALE
@ OB_DUPLICOLLECTION
@ OB_EMPTY_IMAGE_HIDE_FRONT
@ OB_EMPTY_IMAGE_HIDE_NON_AXIS_ALIGNED
@ OB_EMPTY_IMAGE_HIDE_ORTHOGRAPHIC
@ OB_EMPTY_IMAGE_HIDE_BACK
@ OB_EMPTY_IMAGE_HIDE_PERSPECTIVE
#define OB_TYPE_SUPPORT_VGROUP(_type)
@ PARVERT1
@ PARSKEL
@ PAROBJECT
@ PARTYPE
@ PARVERT3
@ PARBONE
#define PSYS_SHARED_CACHES
@ PTCACHE_IGNORE_CLEAR
@ PTCACHE_BAKED
@ PTCACHE_FLAG_INFO_DIRTY
@ PTCACHE_OUTDATED
@ PTCACHE_DISK_CACHE
Types and defines for representing Rigid Body entities.
#define BASE_SELECTED_EDITABLE(v3d, base)
#define BASACT(_view_layer)
#define BASE_EDITABLE(v3d, base)
#define OBACT(_view_layer)
#define SCE_SELECT_VERTEX
#define BASE_VISIBLE(v3d, base)
@ USER_DUP_MAT
@ USER_DUP_SURF
@ USER_DUP_LIGHTPROBE
@ USER_DUP_MBALL
@ USER_DUP_LINKED_ID
@ USER_DUP_CURVE
@ USER_DUP_CAMERA
@ USER_DUP_VOLUME
@ USER_DUP_SPEAKER
@ USER_DUP_PSYS
@ USER_DUP_GPENCIL
@ USER_DUP_CURVES
@ USER_DUP_LAMP
@ USER_DUP_ARM
@ USER_DUP_MESH
@ USER_DUP_POINTCLOUD
@ USER_DUP_FONT
@ USER_DUP_LATTICE
void DRW_drawdata_free(struct ID *id)
Definition: draw_manager.c:911
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
float float3[3]
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
@ BM_VERT
Definition: bmesh_class.h:383
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
Definition: bmesh_mesh.cc:558
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
Definition: bmesh_mesh.h:103
return(oflags[bm->toolflag_index].f &oflag) !=0
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
Scene scene
Curve curve
Light lamp
const Depsgraph * depsgraph
void * user_data
SyclQueue void void size_t num_bytes void
int len
Definition: draw_manager.c:108
void * tree
#define rot(x, k)
int count
#define GS(x)
Definition: iris.c:225
const int state
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
static ulong * next
#define G(x, y, z)
#define copysignf(x, y)
Definition: metal/compat.h:220
#define fabsf(x)
Definition: metal/compat.h:219
bool isfinite(uchar)
Definition: scene/image.cpp:31
static unsigned a[3]
Definition: RandGen.cpp:78
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
vec_base< float, 3 > float3
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
Definition: object.cc:4446
static void lib_link_nlastrips(BlendLibReader *reader, ID *id, ListBase *striplist)
Definition: object.cc:818
static void object_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: object.cc:838
Object * BKE_object_pose_armature_get(Object *ob)
Definition: object.cc:2511
bool BKE_object_obdata_texspace_get(Object *ob, char **r_texflag, float **r_loc, float **r_size)
Definition: object.cc:4328
static void object_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: object.cc:525
void BKE_object_to_mesh_clear(Object *object)
Definition: object.cc:5529
void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *ob)
Definition: object.cc:5245
void BKE_object_empty_draw_type_set(Object *ob, const int value)
Definition: object.cc:3937
bool BKE_object_is_libdata(const Object *ob)
Definition: object.cc:2830
Base ** BKE_object_pose_base_array_get_ex(ViewLayer *view_layer, View3D *v3d, uint *r_bases_len, bool unique)
Definition: object.cc:2603
void BKE_object_to_curve_clear(Object *object)
Definition: object.cc:5547
static KeyBlock * insert_meshkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
Definition: object.cc:4581
Object * BKE_object_add_only_object(Main *bmain, int type, const char *name)
Definition: object.cc:2241
static void object_blend_read_expand(BlendExpander *expander, ID *id)
Definition: object.cc:1040
bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, Scene *scene, Object *ob, bool update_mesh, int parent_recursion, float frame, int type)
Definition: object.cc:5405
void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
Definition: object.cc:3839
static KeyBlock * insert_curvekey(Main *bmain, Object *ob, const char *name, const bool from_mix)
Definition: object.cc:4651
KeyBlock * BKE_object_shapekey_insert(Main *bmain, Object *ob, const char *name, const bool from_mix)
Definition: object.cc:4697
bool BKE_object_flag_test_recursive(const Object *ob, short flag)
Definition: object.cc:4832
#define TFMCPY4D(_v)
void BKE_object_copy_softbody(Object *ob_dst, const Object *ob_src, const int flag)
Definition: object.cc:2322
void BKE_object_sculpt_data_create(Object *ob)
Definition: object.cc:4321
ModifierData * BKE_object_active_modifier(const Object *ob)
Definition: object.cc:1379
bool BKE_object_copy_gpencil_modifier(struct Object *ob_dst, GpencilModifierData *gmd_src)
Definition: object.cc:1581
Object ** BKE_object_pose_array_get_ex(ViewLayer *view_layer, View3D *v3d, uint *r_objects_len, bool unique)
Definition: object.cc:2567
void BKE_object_modifier_set_active(Object *ob, ModifierData *md)
Definition: object.cc:1367
void BKE_object_runtime_reset_on_copy(Object *object, const int UNUSED(flag))
Definition: object.cc:5095
void BKE_object_tfm_restore(Object *ob, void *obtfm_pt)
Definition: object.cc:4242
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:3428
void BKE_object_dimensions_get(Object *ob, float r_vec[3])
Definition: object.cc:3786
bool BKE_object_is_in_editmode(const Object *ob)
Definition: object.cc:1879
bool BKE_object_exists_check(Main *bmain, const Object *obtest)
Definition: object.cc:2077
void BKE_object_handle_update_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, RigidBodyWorld *rbw)
Definition: object.cc:4269
static void foreach_display_point_gpencil_stroke_fn(bGPDlayer *UNUSED(layer), bGPDframe *UNUSED(frame), bGPDstroke *stroke, void *thunk)
Definition: object.cc:4125
static void object_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
Definition: object.cc:181
void BKE_object_modifiers_lib_link_common(void *userData, struct Object *ob, struct ID **idpoin, int cb_flag)
Definition: object.cc:5562
#define TFMCPY3D(_v)
static bool object_modifier_type_copy_check(ModifierType md_type)
Definition: object.cc:1443
static void object_init(Object *ob, const short ob_type)
Definition: object.cc:2135
int BKE_object_obdata_to_type(const ID *id)
Definition: object.cc:2206
MovieClip * BKE_object_movieclip_get(Scene *scene, Object *ob, bool use_default)
Definition: object.cc:5042
void BKE_object_update_select_id(struct Main *bmain)
Definition: object.cc:5504
void BKE_object_dimensions_set(Object *ob, const float value[3], int axis_mask)
Definition: object.cc:3834
Object * BKE_object_add(Main *bmain, ViewLayer *view_layer, int type, const char *name)
Definition: object.cc:2270
void BKE_object_check_uuids_unique_and_report(const Object *object)
Definition: object.cc:5556
void BKE_object_tfm_protected_backup(const Object *ob, ObjectTfmProtectedChannels *obtfm)
Definition: object.cc:2982
bool BKE_object_copy_modifier(Main *bmain, Scene *scene, Object *ob_dst, const Object *ob_src, ModifierData *md_src)
Definition: object.cc:1482
Object * BKE_object_pose_armature_get_visible(Object *ob, ViewLayer *view_layer, View3D *v3d)
Definition: object.cc:2553
void BKE_object_replace_data_on_shallow_copy(Object *ob, ID *new_data)
Definition: object.cc:5590
void BKE_object_workob_clear(Object *workob)
Definition: object.cc:1252
static void library_foreach_gpencil_modifiersForeachIDLink(void *user_data, Object *UNUSED(object), ID **id_pointer, int cb_flag)
Definition: object.cc:331
static void object_lib_override_apply_post(ID *id_dst, ID *id_src)
Definition: object.cc:1125
static void object_asset_pre_save(void *asset_ptr, struct AssetMetaData *asset_data)
Definition: object.cc:1206
static void object_foreach_path(ID *id, BPathForeachPathData *bpath_data)
Definition: object.cc:468
static AssetTypeInfo AssetType_OB
Definition: object.cc:1218
void BKE_object_copy_particlesystems(Object *ob_dst, const Object *ob_src, const int flag)
Definition: object.cc:2429
bool BKE_object_supports_modifiers(const Object *ob)
Definition: object.cc:1401
void BKE_object_runtime_reset(Object *object)
Definition: object.cc:5090
Lattice * BKE_object_get_lattice(const Object *object)
Definition: object.cc:4473
void BKE_object_tfm_copy(Object *object_dst, const Object *object_src)
Definition: object.cc:3045
void BKE_object_obdata_size_init(struct Object *ob, const float size)
Definition: object.cc:2842
Object * BKE_object_duplicate(Main *bmain, Object *ob, uint dupflag, uint duplicate_options)
Definition: object.cc:2661
bool BKE_object_supports_material_slots(struct Object *ob)
Definition: object.cc:5070
static KeyBlock * insert_lattkey(Main *bmain, Object *ob, const char *name, const bool from_mix)
Definition: object.cc:4613
void BKE_boundbox_calc_center_aabb(const BoundBox *bb, float r_cent[3])
Definition: object.cc:3657
static void object_update_from_subsurf_ccg(Object *object)
Definition: object.cc:1673
Object * BKE_object_pose_armature_get_with_wpaint_check(Object *ob)
Definition: object.cc:2531
bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode)
Definition: object.cc:2034
static void library_foreach_particlesystemsObjectLooper(ParticleSystem *UNUSED(psys), ID **id_pointer, void *user_data, int cb_flag)
Definition: object.cc:362
bool BKE_object_pose_context_check(const Object *ob)
Definition: object.cc:2502
static int pc_cmp(const void *a, const void *b)
Definition: object.cc:4510
void * BKE_object_tfm_backup(Object *ob)
Definition: object.cc:4219
Object * BKE_object_add_for_data(Main *bmain, ViewLayer *view_layer, int type, const char *name, ID *data, bool do_id_user)
Definition: object.cc:2299
void BKE_scene_foreach_display_point(Depsgraph *depsgraph, void(*func_cb)(const float[3], void *), void *user_data)
Definition: object.cc:4182
Object ** BKE_object_pose_array_get_unique(ViewLayer *view_layer, View3D *v3d, uint *r_objects_len)
Definition: object.cc:2594
bool BKE_object_shapekey_free(Main *bmain, Object *ob)
Definition: object.cc:4729
static void solve_parenting(Object *ob, Object *par, const bool set_origin, float r_obmat[4][4], float r_originmat[3][3])
Definition: object.cc:3397
int BKE_object_is_deform_modified(Scene *scene, Object *ob)
Definition: object.cc:4982
Lattice * BKE_object_get_evaluated_lattice(const Object *object)
Definition: object.cc:4488
static void expand_object_expandModifiers(void *userData, Object *UNUSED(ob), ID **idpoin, int UNUSED(cb_flag))
Definition: object.cc:1017
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], const bool use_compat, const bool use_parent)
Definition: object.cc:3575
static void library_foreach_modifiersForeachIDLink(void *user_data, Object *UNUSED(object), ID **id_pointer, int cb_flag)
Definition: object.cc:321
void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob, Object *workob)
Definition: object.cc:3501
void BKE_object_boundbox_calc_from_mesh(Object *ob, const Mesh *me_eval)
Definition: object.cc:3724
int BKE_object_insert_ptcache(Object *ob)
Definition: object.cc:4524
Mesh * BKE_object_to_mesh(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
Definition: object.cc:5520
void BKE_boundbox_calc_size_aabb(const BoundBox *bb, float r_size[3])
Definition: object.cc:3664
static void object_cacheIgnoreClear(Object *ob, int state)
Definition: object.cc:5386
const BoundBox * BKE_object_boundbox_get(Object *ob)
Definition: object.cc:3684
bool BKE_object_moves_in_time(const Object *object, bool recurse_parent)
Definition: object.cc:4887
int BKE_object_scenes_users_get(Main *bmain, Object *ob)
Definition: object.cc:5031
static void write_fmaps(BlendWriter *writer, ListBase *fbase)
Definition: object.cc:518
bool BKE_object_shapekey_remove(Main *bmain, Object *ob, KeyBlock *kb)
Definition: object.cc:4746
ParticleSystem * BKE_object_copy_particlesystem(ParticleSystem *psys, const int flag)
Definition: object.cc:2379
void BKE_object_apply_parent_inverse(struct Object *ob)
Definition: object.cc:3583
static void copy_ccg_data(Mesh *mesh_destination, Mesh *mesh_source, int layer_type)
Definition: object.cc:1656
void BKE_object_free_modifiers(Object *ob, const int flag)
Definition: object.cc:1289
static bool modifiers_has_animation_check(const Object *ob)
Definition: object.cc:4958
void * BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
Definition: object.cc:2161
void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd)
Definition: object.cc:1320
static IDProperty * object_asset_dimensions_property(Object *ob)
Definition: object.cc:1188
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:3802
static Object * object_add_common(Main *bmain, ViewLayer *view_layer, int type, const char *name)
Definition: object.cc:2259
void BKE_object_where_is_calc_mat4(Object *ob, float r_obmat[4][4])
Definition: object.cc:3478
bool BKE_object_minmax_empty_drawtype(const struct Object *ob, float r_min[3], float r_max[3])
Definition: object.cc:4011
void BKE_object_runtime_free_data(Object *object)
Definition: object.cc:5110
static void ob_parbone(Object *ob, Object *par, float r_mat[4][4])
Definition: object.cc:3169
void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
Definition: object.cc:3645
LinkNode * BKE_object_relational_superset(struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter)
Definition: object.cc:5157
bool BKE_object_boundbox_calc_from_evaluated_geometry(Object *ob)
Definition: object.cc:3743
bool BKE_object_obdata_is_libdata(const Object *ob)
Definition: object.cc:2835
static void copy_object_pose(Object *obn, const Object *ob, const int flag)
Definition: object.cc:2473
static void object_blend_read_data(BlendDataReader *reader, ID *id)
Definition: object.cc:609
static bool object_moves_in_time(const Object *object)
Definition: object.cc:4902
void BKE_object_free_particlesystems(Object *ob)
Definition: object.cc:1261
void BKE_object_free_curve_cache(Object *ob)
Definition: object.cc:1275
static void library_foreach_constraintObjectLooper(bConstraint *UNUSED(con), ID **id_pointer, bool is_reference, void *user_data)
Definition: object.cc:351
void BKE_object_where_is_calc_ex(Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
Definition: object.cc:3489
bool BKE_object_data_is_in_editmode(const Object *ob, const ID *id)
Definition: object.cc:1914
static void ob_parvert3(Object *ob, Object *par, float r_mat[4][4])
Definition: object.cc:3321
void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
Definition: object.cc:2934
static void object_init_data(ID *id)
Definition: object.cc:165
void BKE_object_scale_to_mat3(Object *ob, float mat[3][3])
Definition: object.cc:2887
static void expand_constraint_channels(BlendExpander *expander, ListBase *chanbase)
Definition: object.cc:1010
KDTree_3d * BKE_object_as_kdtree(Object *ob, int *r_tot)
Definition: object.cc:5260
static void direct_link_nlastrips(BlendDataReader *reader, ListBase *strips)
Definition: object.cc:600
SubsurfModifierData * BKE_object_get_last_subsurf_modifier(const Object *ob)
Definition: object.cc:5575
char * BKE_object_data_editmode_flush_ptr_get(struct ID *id)
Definition: object.cc:1941
void BKE_object_to_mat3(Object *ob, float r_mat[3][3])
Definition: object.cc:3069
void BKE_boundbox_minmax(const BoundBox *bb, const float obmat[4][4], float r_min[3], float r_max[3])
Definition: object.cc:3671
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:4142
void BKE_object_apply_mat4_ex(Object *ob, const float mat[4][4], Object *parent, const float parentinv[4][4], const bool use_compat)
Definition: object.cc:3532
void BKE_object_link_modifiers(Object *ob_dst, const Object *ob_src)
Definition: object.cc:1646
Mesh * BKE_object_get_evaluated_mesh_no_subsurf(const Object *object)
Definition: object.cc:4373
bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
Definition: object.cc:4844
static int pc_findindex(ListBase *listbase, int index)
Definition: object.cc:4546
static const char * get_obdata_defname(int type)
Definition: object.cc:2094
static void give_parvert(Object *par, int nr, float vec[3])
Definition: object.cc:3203
bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
Definition: object.cc:1414
bool BKE_object_modifier_stack_copy(Object *ob_dst, const Object *ob_src, const bool do_copy_all, const int flag_subdata)
Definition: object.cc:1598
static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBase *chanbase)
Definition: object.cc:831
void BKE_object_to_mat4(Object *ob, float r_mat[4][4])
Definition: object.cc:3082
IDTypeInfo IDType_ID_OB
Definition: object.cc:1222
struct LinkNode * BKE_object_groups(Main *bmain, Scene *scene, Object *ob)
Definition: object.cc:5234
bool BKE_object_empty_image_frame_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d)
Definition: object.cc:3954
int BKE_object_visibility(const Object *ob, const int dag_eval_mode)
Definition: object.cc:2039
static bool ob_parcurve(Object *ob, Object *par, float r_mat[4][4])
Definition: object.cc:3110
static CLG_LogRef LOG
Definition: object.cc:149
Object ** BKE_object_pose_array_get(ViewLayer *view_layer, View3D *v3d, uint *r_objects_len)
Definition: object.cc:2598
void BKE_object_modifier_gpencil_hook_reset(Object *ob, HookGpencilModifierData *hmd)
Definition: object.cc:1343
Mesh * BKE_object_get_original_mesh(const Object *object)
Definition: object.cc:4429
bool BKE_object_is_in_wpaint_select_vert(const Object *ob)
Definition: object.cc:1993
void BKE_object_get_parent_matrix(Object *ob, Object *par, float r_parentmat[4][4])
Definition: object.cc:3342
Curve * BKE_object_to_curve(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
Definition: object.cc:5538
BoundBox * BKE_boundbox_alloc_unit()
Definition: object.cc:3638
static bool constructive_modifier_is_deform_modified(Object *ob, ModifierData *md)
Definition: object.cc:4918
void BKE_object_eval_assign_data(Object *object_eval, ID *data_eval, bool is_owned)
Definition: object.cc:1745
void BKE_object_tfm_protected_restore(Object *ob, const ObjectTfmProtectedChannels *obtfm, const short protectflag)
Definition: object.cc:3007
static bool object_deforms_in_time(Object *object)
Definition: object.cc:4907
void BKE_object_handle_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: object.cc:4316
static ParticleSystem * object_copy_modifier_particle_system_ensure(Main *bmain, Scene *scene, Object *ob_dst, ParticleSystem *psys_src)
Definition: object.cc:1457
void BKE_object_delete_ptcache(Object *ob, int index)
Definition: object.cc:4567
bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode)
Definition: object.cc:2004
void BKE_object_free_caches(Object *object)
Definition: object.cc:1832
bool BKE_object_parent_loop_check(const Object *par, const Object *ob)
Definition: object.cc:4820
static void object_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: object.cc:372
void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
Definition: object.cc:3467
bool BKE_object_is_in_editmode_vgroup(const Object *ob)
Definition: object.cc:1909
#define TFMCPY(_v)
Object * BKE_object_add_from(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name, Object *ob_src)
Definition: object.cc:2287
bool BKE_object_empty_image_data_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d)
Definition: object.cc:3964
PartEff * BKE_object_do_version_give_parteff_245(Object *ob)
Definition: object.cc:1026
static void object_free_data(ID *id)
Definition: object.cc:269
Mesh * BKE_object_get_evaluated_mesh(const Object *object)
Definition: object.cc:4400
void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: object.cc:3495
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
Definition: object.cc:2650
void BKE_object_matrix_local_get(struct Object *ob, float r_mat[4][4])
Definition: object.cc:3093
void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot)
Definition: object.cc:2894
int BKE_object_is_modified(Scene *scene, Object *ob)
Definition: object.cc:4854
Mesh * BKE_object_get_editmesh_eval_cage(const Object *object)
Definition: object.cc:4461
static bool obrel_list_test(Object *ob)
Definition: object.cc:5146
Mesh * BKE_object_get_pre_modified_mesh(const Object *object)
Definition: object.cc:4414
static void obrel_list_add(LinkNode **links, Object *ob)
Definition: object.cc:5151
static void library_foreach_shaderfxForeachIDLink(void *user_data, Object *UNUSED(object), ID **id_pointer, int cb_flag)
Definition: object.cc:341
Base ** BKE_object_pose_base_array_get_unique(ViewLayer *view_layer, View3D *v3d, uint *r_bases_len)
Definition: object.cc:2641
void BKE_object_free_derived_caches(Object *ob)
Definition: object.cc:1774
void BKE_object_free_softbody(Object *ob)
Definition: object.cc:1270
static void object_foreach_path_pointcache(ListBase *ptcache_list, BPathForeachPathData *bpath_data)
Definition: object.cc:457
static Object * obrel_armature_find(Object *ob)
Definition: object.cc:5127
bool BKE_object_minmax_dupli(Depsgraph *depsgraph, Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
Definition: object.cc:4075
void BKE_object_free_shaderfx(Object *ob, const int flag)
Definition: object.cc:1311
static ThreadMutex vparent_lock
Definition: object.cc:160
Base ** BKE_object_pose_base_array_get(ViewLayer *view_layer, View3D *v3d, uint *r_bases_len)
Definition: object.cc:2645
const btScalar eps
Definition: poly34.cpp:11
#define min(a, b)
Definition: sort.c:35
bAction * action
ListBase drivers
struct Object * start_cap
struct Object * offset_ob
struct Object * curve_ob
struct Object * end_cap
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
char needs_flush_to_id
Definition: BKE_editmesh.h:68
float co[3]
Definition: bmesh_class.h:87
float vec[4]
struct Object * object
float vec[3][3]
struct BlendFileReadReport::@134 count
int * springs
Definition: BKE_softbody.h:24
short flag
Definition: softbody.c:81
float length
float vec[8][3]
float drawsize
struct ListBase ptcaches
struct PointCache * point_cache
ListBase bev
Definition: BKE_curve.h:34
ListBase disp
Definition: BKE_curve.h:33
ListBase deformed_nurbs
Definition: BKE_curve.h:35
const float * anim_path_accum_length
Definition: BKE_curve.h:42
float loc[3]
struct AnimData * adt
struct Key * key
char texflag
ListBase nurb
float fsize
float ctime
struct Object * taperobj
float size[3]
struct ParticleSystem * psys
struct DynamicPaintCanvasSettings * canvas
struct DynamicPaintBrushSettings * brush
char needs_flush_to_id
Definition: BKE_vfont.h:49
char needs_flush_to_id
struct Lattice * latt
char needs_flush_to_id
struct Collection * group
char cache_directory[1024]
struct ParticleSystem * psys
struct FluidDomainSettings * domain
struct FluidEffectorSettings * effector
struct FluidFlowSettings * flow
struct FluidsimSettings * fss
const float(* obmat)[4]
Definition: object.cc:4119
void(* point_func_cb)(const float co[3], void *user_data)
Definition: object.cc:4121
const Mesh * get_mesh_for_read() const
bool compute_boundbox_without_instances(blender::float3 *r_min, blender::float3 *r_max) const
void(* copyData)(const struct GpencilModifierData *md, struct GpencilModifierData *target)
struct Object * object
Definition: DNA_ID.h:368
void * py_instance
Definition: DNA_ID.h:435
int tag
Definition: DNA_ID.h:387
struct Library * lib
Definition: DNA_ID.h:372
int recalc
Definition: DNA_ID.h:390
struct ID * newid
Definition: DNA_ID.h:370
struct ID * orig_id
Definition: DNA_ID.h:419
void * next
Definition: DNA_ID.h:369
char name[66]
Definition: DNA_ID.h:378
struct ID_Runtime runtime
Definition: DNA_ID.h:445
void * data
Definition: DNA_key_types.h:50
int totkey
Definition: DNA_key_types.h:91
ListBase block
Definition: DNA_key_types.h:84
KeyBlock * refkey
Definition: DNA_key_types.h:72
struct Key * key
struct EditLatt * editlatt
struct BPoint * def
struct Collection * collection
char filepath[1024]
Definition: DNA_ID.h:461
float dist
float area_sizez
float area_sizey
float area_size
void * data
Definition: DNA_listBase.h:26
struct LinkData * next
Definition: DNA_listBase.h:25
void * last
Definition: DNA_listBase.h:31
void * first
Definition: DNA_listBase.h:31
float co[3]
Definition: BKE_main.h:121
ListBase scenes
Definition: BKE_main.h:168
ListBase objects
Definition: BKE_main.h:170
struct SubdivCCG * subdiv_ccg
int subdiv_ccg_tot_level
struct BMEditMesh * edit_mesh
struct MVert * mvert
int totvert
Mesh_Runtime runtime
int totloop
struct Key * key
CustomData ldata
float size[3]
char texflag
float loc[3]
char needs_flush_to_id
struct Object * mirror_ob
struct ModifierData * next
struct ModifierData * prev
void(* modifyGeometrySet)(struct ModifierData *md, const struct ModifierEvalContext *ctx, struct GeometrySet *geometry_set)
Definition: BKE_modifier.h:240
ModifierTypeFlag flags
Definition: BKE_modifier.h:161
ModifierTypeType type
Definition: BKE_modifier.h:160
struct Object * parent
float cent[3]
int * indexar
float falloff
float parentinv[4][4]
float rot[3]
Definition: object.cc:4209
float dquat[4]
Definition: object.cc:4210
float drotAngle
Definition: object.cc:4212
float imat[4][4]
Definition: object.cc:4216
float dscale[3]
Definition: object.cc:4208
float rotAxis[3]
Definition: object.cc:4211
float scale[3]
Definition: object.cc:4208
float dloc[3]
Definition: object.cc:4207
float loc[3]
Definition: object.cc:4207
float obmat[4][4]
Definition: object.cc:4213
float drot[3]
Definition: object.cc:4209
float parentinv[4][4]
Definition: object.cc:4214
float quat[4]
Definition: object.cc:4210
float drotAxis[3]
Definition: object.cc:4211
float rotAngle
Definition: object.cc:4212
float constinv[4][4]
Definition: object.cc:4215
struct BoundBox * editmesh_bb_cage
struct CurveCache * curve_cache
float(* crazyspace_deform_imats)[3][3]
float parent_display_origin[3]
struct Mesh * editmesh_eval_cage
struct Mesh * mesh_deform_eval
struct ID * data_eval
float(* crazyspace_deform_cos)[3]
struct bGPdata * gpd_eval
struct Curve * object_as_temp_curve
struct GeometrySet * geometry_set_eval
struct ID * data_orig
struct BoundBox * bb
struct Mesh * object_as_temp_mesh
struct bAction * poselib
short partype
ListBase particlesystem
struct Object * track
short transflag
ListBase constraints
struct Collection * instance_collection
short base_flag
struct bPose * pose
float drot[3]
ListBase modifiers
float dquat[4]
struct RigidBodyOb * rigidbody_object
float constinv[4][4]
ListBase greasepencil_modifiers
struct PreviewImage * preview
struct Material ** mat
float loc[3]
char * matbits
struct PartDeflect * pd
float dloc[3]
float scale[3]
float imat[4][4]
struct SoftBody * soft
float rot[3]
short shapenr
float parentinv[4][4]
char empty_drawtype
ListBase shader_fx
Object_Runtime runtime
ImageUser * iuser
short visibility_flag
float drotAxis[3]
float empty_drawsize
bMotionPath * mpath
float obmat[4][4]
short softflag
float quat[4]
short rotmode
float rotAngle
ListBase pc_ids
float rotAxis[3]
float drotAngle
struct AnimData * adt
float dscale[3]
struct DrawDataList drawdata
struct Object * parent
short trackflag
char duplicator_visibility_flag
struct SculptSession * sculpt
struct RigidBodyCon * rigidbody_constraint
short upflag
void * data
struct LightgroupMembership * lightgroup
ListBase fmaps
char parsubstr[64]
char empty_image_visibility_flag
bAnimVizSettings avs
float ima_ofs[2]
unsigned int data_types
unsigned int info_types
unsigned int type
struct ListBase * ptcaches
unsigned int default_step
unsigned int file_type
unsigned int max_step
struct PTCacheID * next
struct Object * f_source
Particle * keys
struct PartEff * next
struct Collection * group
struct ParticleSystem * psys
struct PTCacheEdit * edit
struct ListBase ptcaches
struct ListBase targets
ParticleSettings * part
struct ListBase * effectors
struct PointCache * pointcache
struct BVHTree * bvhtree
struct ClothModifierData * clmd
struct ParticleCacheKey ** childcache
struct Mesh * hair_in_mesh
struct KDTree_3d * tree
struct Mesh * hair_out_mesh
struct ParticleDrawData * pdd
struct ParticleCacheKey ** pathcache
struct PointCache * next
Definition: rand.cc:33
float viewinv[4][4]
struct Object * ob1
struct Object * ob2
struct RigidBodyOb_Shared * shared
struct Collection * master_collection
struct RigidBodyWorld * rigidbody_world
struct MovieClip * clip
struct Object * ob_axis
eObjectMode mode_type
Definition: BKE_paint.h:642
struct PointCache * pointcache
struct ListBase ptcaches
SBVertex ** keys
struct SoftBody_Shared * shared
struct Collection * collision_group
struct EffectorWeights * effector_weights
struct BodySpring * bspring
struct SBScratch * scratch
struct BodyPoint * bpoint
struct SubdivCCG::@69 dirty
ListBase object_bases
float timeoffs
float lifetime
ListBase curves
struct AnimData * adt
struct bConstraint * next
bGPDspoint * points
struct Bone * bone
float chan_mat[4][4]
float pose_mat[4][4]
ListBase chanbase
short flag
float max
struct IDPropertyTemplate::@27 array
ccl_device_inline int mod(int x, int m)
Definition: util/math.h:490