Blender V4.5
object_update.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2014 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "DNA_mesh_types.h"
11#include "DNA_modifier_types.h"
12#include "DNA_scene_types.h"
13
14#include "BLI_listbase.h"
15#include "BLI_math_matrix.h"
16#include "BLI_math_vector.h"
17#include "BLI_string.h"
18
19#include "BKE_armature.hh"
20#include "BKE_constraint.h"
21#include "BKE_curve.hh"
22#include "BKE_curves.h"
23#include "BKE_displist.h"
24#include "BKE_editmesh.hh"
25#include "BKE_gpencil_legacy.h"
26#include "BKE_grease_pencil.h"
27#include "BKE_grease_pencil.hh"
28#include "BKE_lattice.hh"
29#include "BKE_layer.hh"
30#include "BKE_mball.hh"
31#include "BKE_mesh.hh"
32#include "BKE_object.hh"
33#include "BKE_particle.h"
34#include "BKE_pointcache.h"
35#include "BKE_pointcloud.hh"
36#include "BKE_scene.hh"
37#include "BKE_volume.hh"
38
39#include "MEM_guardedalloc.h"
40
41#include "DEG_depsgraph.hh"
44
45namespace deg = blender::deg;
46
51
53{
54 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
55
56 /* calculate local matrix */
57 BKE_object_to_mat4(ob, ob->runtime->object_to_world.ptr());
58}
59
61{
62 /* NOTE: based on `solve_parenting()`, but with the cruft stripped out. */
63
64 Object *par = ob->parent;
65
66 float totmat[4][4];
67 float tmat[4][4];
68 float locmat[4][4];
69
70 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
71
72 /* get local matrix (but don't calculate it, as that was done already!) */
73 /* XXX: redundant? */
74 copy_m4_m4(locmat, ob->object_to_world().ptr());
75
76 /* get parent effect matrix */
77 BKE_object_get_parent_matrix(ob, par, totmat);
78
79 /* total */
80 mul_m4_m4m4(tmat, totmat, ob->parentinv);
81 mul_m4_m4m4(ob->runtime->object_to_world.ptr(), tmat, locmat);
82
83 /* origin, for help line */
84 if ((ob->partype & PARTYPE) == PARSKEL) {
85 copy_v3_v3(ob->runtime->parent_display_origin, par->object_to_world().location());
86 }
87 else {
88 copy_v3_v3(ob->runtime->parent_display_origin, totmat[3]);
89 }
90}
91
93{
94 bConstraintOb *cob;
95 float ctime = BKE_scene_ctime_get(scene);
96
97 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
98
99 /* evaluate constraints stack */
100 /* TODO: split this into:
101 * - pre (i.e. BKE_constraints_make_evalob, per-constraint (i.e.
102 * - inner body of BKE_constraints_solve),
103 * - post (i.e. BKE_constraints_clear_evalob)
104 *
105 * Not sure why, this is from Joshua - sergey
106 */
110}
111
113{
114 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
115 /* Make sure inverse matrix is always up to date. This way users of it
116 * do not need to worry about recalculating it. */
117 invert_m4_m4_safe(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
118 /* Set negative scale flag in object. */
119 if (is_negative_m4(ob->object_to_world().ptr())) {
120 ob->transflag |= OB_NEG_SCALE;
121 }
122 else {
124 }
125
126 ob->runtime->last_update_transform = DEG_get_update_count(depsgraph);
127}
128
130{
131 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
132
133 /* includes all keys and modifiers */
134 switch (ob->type) {
135 case OB_MESH: {
136 CustomData_MeshMasks cddata_masks = scene->customdata_mask;
138 /* Custom attributes should not be removed automatically. They might be used by the render
139 * engine or scripts. They can still be removed explicitly using geometry nodes.
140 * Vertex groups can be used in arbitrary situations with geometry nodes as well. */
142 cddata_masks.emask |= CD_MASK_PROP_ALL;
143 cddata_masks.fmask |= CD_MASK_PROP_ALL;
144 cddata_masks.pmask |= CD_MASK_PROP_ALL;
145 cddata_masks.lmask |= CD_MASK_PROP_ALL;
146
147 /* Make sure Freestyle edge/face marks appear in evaluated mesh (see #40315).
148 * Due to Line Art implementation, edge marks should also be shown in viewport. */
149#ifdef WITH_FREESTYLE
150 cddata_masks.emask |= CD_MASK_FREESTYLE_EDGE;
151 cddata_masks.pmask |= CD_MASK_FREESTYLE_FACE;
152#endif
154 /* Always compute orcos for render. */
155 cddata_masks.vmask |= CD_MASK_ORCO;
156 }
157 blender::bke::mesh_data_update(*depsgraph, *scene, *ob, cddata_masks);
158 break;
159 }
160 case OB_ARMATURE:
161 BKE_pose_where_is(depsgraph, scene, ob);
162 break;
163
164 case OB_MBALL:
166 break;
167
168 case OB_CURVES_LEGACY:
169 case OB_SURF:
170 case OB_FONT: {
171 bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
172 BKE_displist_make_curveTypes(depsgraph, scene, ob, for_render);
173 break;
174 }
175
176 case OB_LATTICE:
178 break;
179 case OB_CURVES:
181 break;
182 case OB_POINTCLOUD:
184 break;
185 case OB_VOLUME:
187 break;
188 case OB_GREASE_PENCIL:
190 break;
191 }
192
193 /* particles */
194 if (!(ob->mode & OB_MODE_EDIT) && ob->particlesystem.first) {
195 const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
196 ParticleSystem *tpsys, *psys;
198 psys = static_cast<ParticleSystem *>(ob->particlesystem.first);
199 while (psys) {
200 if (psys_check_enabled(ob, psys, use_render_params)) {
201 /* check use of dupli objects here */
202 if (psys->part && (psys->part->draw_as == PART_DRAW_REND || use_render_params) &&
203 ((psys->part->ren_as == PART_DRAW_OB && psys->part->instance_object) ||
204 (psys->part->ren_as == PART_DRAW_GR && psys->part->instance_collection)))
205 {
207 }
208
209 particle_system_update(depsgraph, scene, ob, psys, use_render_params);
210 psys = psys->next;
211 }
212 else if (psys->flag & PSYS_DELETE) {
213 tpsys = psys->next;
214 BLI_remlink(&ob->particlesystem, psys);
215 psys_free(ob, psys);
216 psys = tpsys;
217 }
218 else {
219 psys = psys->next;
220 }
221 }
222 }
223
225 Object *object_orig = DEG_get_original(ob);
226 object_orig->runtime->bounds_eval = BKE_object_evaluated_geometry_bounds(ob);
227 }
228}
229
231{
232 if (!DEG_is_active(depsgraph)) {
233 return;
234 }
235 Object *object_orig = DEG_get_original(object);
236 /* Base flags. */
237 object_orig->base_flag = object->base_flag;
238 /* Transformation flags. */
239 copy_m4_m4(object_orig->runtime->object_to_world.ptr(), object->object_to_world().ptr());
240 copy_m4_m4(object_orig->runtime->world_to_object.ptr(), object->world_to_object().ptr());
241 copy_m4_m4(object_orig->constinv, object->constinv);
242 object_orig->transflag = object->transflag;
243 object_orig->flag = object->flag;
244
245 /* Copy back error messages from modifiers. */
246 for (ModifierData *md = static_cast<ModifierData *>(object->modifiers.first),
247 *md_orig = static_cast<ModifierData *>(object_orig->modifiers.first);
248 md != nullptr && md_orig != nullptr;
249 md = md->next, md_orig = md_orig->next)
250 {
251 BLI_assert(md->type == md_orig->type && STREQ(md->name, md_orig->name));
252 MEM_SAFE_FREE(md_orig->error);
253 if (md->error != nullptr) {
254 md_orig->error = BLI_strdup(md->error);
255 }
256 }
257}
258
259void BKE_object_eval_uber_transform(Depsgraph * /*depsgraph*/, Object * /*object*/) {}
260
262{
263 switch (ob->type) {
264 case OB_MESH:
266 break;
267 case OB_LATTICE:
269 break;
270 case OB_CURVES_LEGACY:
271 case OB_SURF:
272 case OB_FONT:
274 break;
275 case OB_MBALL: {
276 /* This function is currently called on original objects, so to properly
277 * clear the actual displayed geometry, we have to tag the evaluated mesh. */
279 if (mesh) {
281 }
282 break;
283 }
284 case OB_CURVES:
286 break;
287 case OB_POINTCLOUD:
289 break;
290 case OB_VOLUME:
292 break;
293 case OB_GREASE_PENCIL:
296 break;
297 default:
298 break;
299 }
300}
301
302void BKE_object_eval_uber_data(Depsgraph *depsgraph, Scene *scene, Object *ob)
303{
304 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
308
309 ob->runtime->last_update_geometry = DEG_get_update_count(depsgraph);
310}
311
312void BKE_object_eval_ptcache_reset(Depsgraph *depsgraph, Scene *scene, Object *object)
313{
314 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
316}
317
318void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *object)
319{
320 /* This mimics full transform update chain from new depsgraph. */
322 if (object->parent != nullptr) {
324 }
325 if (!BLI_listbase_is_empty(&object->constraints)) {
327 }
330}
331
332void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
333{
334 DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data);
335 switch (GS(object_data->name)) {
336 case ID_ME:
338 break;
339 case ID_CU_LEGACY:
341 break;
342 case ID_LT:
344 break;
345 default:
346 break;
347 }
348}
349
351{
352 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
353 if (object->type == OB_MESH && !object->runtime->is_data_eval_owned) {
354 Mesh *mesh_input = (Mesh *)object->runtime->data_orig;
355 std::lock_guard lock{mesh_input->runtime->eval_mutex};
356 BKE_object_data_select_update(depsgraph, static_cast<ID *>(object->data));
357 }
358 else {
359 BKE_object_data_select_update(depsgraph, static_cast<ID *>(object->data));
360 }
361}
362
364 Scene *scene,
365 const int view_layer_index,
366 Object *object,
367 int base_index,
368 const bool is_from_set)
369{
370 /* TODO(sergey): Avoid list lookup. */
371 BLI_assert(view_layer_index >= 0);
372 ViewLayer *view_layer = static_cast<ViewLayer *>(
373 BLI_findlink(&scene->view_layers, view_layer_index));
374 BLI_assert(view_layer != nullptr);
375 BLI_assert(view_layer->object_bases_array != nullptr);
376 BLI_assert(base_index >= 0);
377 BLI_assert(base_index < MEM_allocN_len(view_layer->object_bases_array) / sizeof(Base *));
378 Base *base = view_layer->object_bases_array[base_index];
379 BLI_assert(base->object == object);
380
381 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
382
383 /* Set base flags based on collection and object restriction. */
385
386 /* For render, compute base visibility again since BKE_base_eval_flags
387 * assumed viewport visibility. Select-ability does not matter here. */
389 if (base->flag & BASE_ENABLED_RENDER) {
391 }
392 else {
394 }
395 }
396
397 /* Copy flags and settings from base. */
398 object->base_flag = base->flag;
399 if (is_from_set) {
400 object->base_flag |= BASE_FROM_SET;
401 object->base_flag &= ~(BASE_SELECTED | BASE_SELECTABLE);
402 }
403 object->base_local_view_bits = base->local_view_bits;
404 object->runtime->local_collections_bits = base->local_collections_bits;
405
406 if (object->mode == OB_MODE_PARTICLE_EDIT) {
407 for (ParticleSystem *psys = static_cast<ParticleSystem *>(object->particlesystem.first);
408 psys != nullptr;
409 psys = psys->next)
410 {
412 }
413 }
414
415 /* Copy base flag back to the original view layer for editing. */
417 Base *base_orig = base->base_orig;
418 BLI_assert(base_orig != nullptr);
419 BLI_assert(base_orig->object != nullptr);
420 base_orig->flag = base->flag;
421 }
422}
423
425{
426 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
428}
429
430void BKE_object_eval_shading(Depsgraph *depsgraph, Object *object)
431{
432 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
433
434 object->runtime->last_update_shading = DEG_get_update_count(depsgraph);
435}
void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition armature.cc:3051
void BKE_constraints_solve(struct Depsgraph *depsgraph, struct ListBase *conlist, struct bConstraintOb *cob, float ctime)
void BKE_constraints_clear_evalob(struct bConstraintOb *cob)
struct bConstraintOb * BKE_constraints_make_evalob(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, void *subdata, short datatype)
void BKE_curve_batch_cache_dirty_tag(Curve *cu, int mode)
Definition curve.cc:5513
@ BKE_CURVE_BATCH_DIRTY_SELECT
Definition BKE_curve.hh:380
@ BKE_CURVE_BATCH_DIRTY_ALL
Definition BKE_curve.hh:379
Low-level operations for curves that cannot be defined in the C++ header yet.
@ BKE_CURVES_BATCH_DIRTY_ALL
Definition BKE_curves.h:37
void BKE_curves_data_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *object)
void BKE_curves_batch_cache_dirty_tag(struct Curves *curves, int mode)
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:94
const CustomData_MeshMasks CD_MASK_BAREMESH
display list (or rather multi purpose list) stuff.
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
Low-level operations for grease pencil that cannot be defined in the C++ header yet.
void BKE_grease_pencil_batch_cache_dirty_tag(GreasePencil *grease_pencil, int mode)
@ BKE_GREASEPENCIL_BATCH_DIRTY_ALL
Low-level operations for grease pencil.
void BKE_object_eval_grease_pencil(Depsgraph *depsgraph, Scene *scene, Object *object)
void BKE_lattice_batch_cache_dirty_tag(Lattice *lt, int mode)
Definition lattice.cc:709
@ BKE_LATTICE_BATCH_DIRTY_SELECT
@ BKE_LATTICE_BATCH_DIRTY_ALL
void BKE_lattice_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition lattice.cc:519
void BKE_base_eval_flags(Base *base)
void BKE_mball_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition mball.cc:655
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
@ BKE_MESH_BATCH_DIRTY_ALL
Definition BKE_mesh.h:38
@ BKE_MESH_BATCH_DIRTY_SELECT
Definition BKE_mesh.h:39
General operations, lookup, etc. for blender objects.
Mesh * BKE_object_get_evaluated_mesh_no_subsurf(const Object *object_eval)
void BKE_object_get_parent_matrix(const Object *ob, Object *par, float r_parentmat[4][4])
std::optional< blender::Bounds< blender::float3 > > BKE_object_evaluated_geometry_bounds(const Object *ob)
void BKE_object_to_mat4(const Object *ob, float r_mat[4][4])
void BKE_object_free_derived_caches(Object *ob)
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
Definition particle.cc:709
@ BKE_PARTICLE_BATCH_DIRTY_ALL
void particle_system_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
void BKE_particle_batch_cache_dirty_tag(struct ParticleSystem *psys, int mode)
Definition particle.cc:5286
void psys_free(struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:977
int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode)
#define PTCACHE_RESET_DEPSGRAPH
General operations for point clouds.
void BKE_pointcloud_batch_cache_dirty_tag(PointCloud *pointcloud, int mode)
@ BKE_POINTCLOUD_BATCH_DIRTY_ALL
void BKE_pointcloud_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
float BKE_scene_ctime_get(const Scene *scene)
Definition scene.cc:2367
Volume data-block.
void BKE_volume_batch_cache_dirty_tag(Volume *volume, int mode)
@ BKE_VOLUME_BATCH_DIRTY_ALL
Definition BKE_volume.hh:61
void BKE_volume_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
#define BLI_assert(a)
Definition BLI_assert.h:46
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:534
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void invert_m4_m4_safe(float inverse[4][4], const float mat[4][4])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
bool is_negative_m4(const float mat[4][4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
#define STREQ(a, b)
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
Definition depsgraph.cc:355
@ DAG_EVAL_RENDER
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:323
void DEG_debug_print_eval(Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
T * DEG_get_original(T *id)
@ ID_CU_LEGACY
@ ID_ME
@ ID_LT
@ CONSTRAINT_OBTYPE_OBJECT
@ BASE_FROM_SET
@ BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT
@ BASE_ENABLED_RENDER
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_EDIT
@ OB_NEG_SCALE
@ OB_DUPLIPARTS
@ OB_LATTICE
@ OB_MBALL
@ OB_SURF
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_ARMATURE
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
@ PARSKEL
@ PARTYPE
@ PSYS_DELETE
@ PART_DRAW_GR
@ PART_DRAW_OB
@ PART_DRAW_REND
#define BASE_SELECTED(v3d, base)
#define BASE_SELECTABLE(v3d, base)
Read Guarded memory(de)allocation.
volatile int lock
BPy_StructRNA * depsgraph
#define CD_MASK_ORCO
#define CD_MASK_MDEFORMVERT
#define MEM_SAFE_FREE(v)
#define CD_MASK_PROP_ALL
#define CD_MASK_FREESTYLE_FACE
#define GS(a)
#define CD_MASK_FREESTYLE_EDGE
size_t(* MEM_allocN_len)(const void *vmemh)
Definition mallocn.cc:36
void mesh_data_update(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask)
void eval_runtime_data(const ::Depsgraph *depsgraph, Object &object_eval)
void BKE_object_select_update(Depsgraph *depsgraph, Object *object)
void BKE_object_eval_reset(Object *ob_eval)
void BKE_object_eval_parent(Depsgraph *depsgraph, Object *ob)
void BKE_object_eval_local_transform(Depsgraph *depsgraph, Object *ob)
void BKE_object_eval_uber_transform(Depsgraph *, Object *)
void BKE_object_batch_cache_dirty_tag(Object *ob)
void BKE_object_sync_to_original(Depsgraph *depsgraph, Object *object)
void BKE_object_eval_constraints(Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_object_eval_shading(Depsgraph *depsgraph, Object *object)
void BKE_object_eval_uber_data(Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
void BKE_object_eval_light_linking(Depsgraph *depsgraph, Object *object)
void BKE_object_eval_eval_base_flags(Depsgraph *depsgraph, Scene *scene, const int view_layer_index, Object *object, int base_index, const bool is_from_set)
void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *object)
void BKE_object_eval_transform_final(Depsgraph *depsgraph, Object *ob)
void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_object_eval_ptcache_reset(Depsgraph *depsgraph, Scene *scene, Object *object)
short flag
struct Object * object
unsigned short local_view_bits
unsigned short local_collections_bits
struct Base * base_orig
Definition DNA_ID.h:404
char name[66]
Definition DNA_ID.h:415
void * first
MeshRuntimeHandle * runtime
struct ModifierData * next
ListBase particlesystem
short transflag
ListBase constraints
short base_flag
ObjectRuntimeHandle * runtime
ListBase modifiers
float constinv[4][4]
float parentinv[4][4]
struct Object * parent
struct Collection * instance_collection
struct Object * instance_object
ParticleSettings * part
struct ParticleSystem * next
struct CustomData_MeshMasks customdata_mask
ListBase view_layers
struct Base ** object_bases_array