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