Blender V4.3
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
10#include "DNA_mesh_types.h"
11#include "DNA_modifier_types.h"
12#include "DNA_scene_types.h"
13
14#include "BLI_blenlib.h"
15#include "BLI_math_matrix.h"
16#include "BLI_math_vector.h"
17#include "BLI_utildefines.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_object_types.hh"
34#include "BKE_particle.h"
35#include "BKE_pointcache.h"
36#include "BKE_pointcloud.hh"
37#include "BKE_scene.hh"
38#include "BKE_volume.hh"
39
40#include "MEM_guardedalloc.h"
41
42#include "DEG_depsgraph.hh"
45
46namespace deg = blender::deg;
47
52
54{
55 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
56
57 /* calculate local matrix */
58 BKE_object_to_mat4(ob, ob->runtime->object_to_world.ptr());
59}
60
62{
63 /* NOTE: based on `solve_parenting()`, but with the cruft stripped out. */
64
65 Object *par = ob->parent;
66
67 float totmat[4][4];
68 float tmat[4][4];
69 float locmat[4][4];
70
71 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
72
73 /* get local matrix (but don't calculate it, as that was done already!) */
74 /* XXX: redundant? */
75 copy_m4_m4(locmat, ob->object_to_world().ptr());
76
77 /* get parent effect matrix */
78 BKE_object_get_parent_matrix(ob, par, totmat);
79
80 /* total */
81 mul_m4_m4m4(tmat, totmat, ob->parentinv);
82 mul_m4_m4m4(ob->runtime->object_to_world.ptr(), tmat, locmat);
83
84 /* origin, for help line */
85 if ((ob->partype & PARTYPE) == PARSKEL) {
86 copy_v3_v3(ob->runtime->parent_display_origin, par->object_to_world().location());
87 }
88 else {
89 copy_v3_v3(ob->runtime->parent_display_origin, totmat[3]);
90 }
91}
92
94{
95 bConstraintOb *cob;
96 float ctime = BKE_scene_ctime_get(scene);
97
98 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
99
100 /* evaluate constraints stack */
101 /* TODO: split this into:
102 * - pre (i.e. BKE_constraints_make_evalob, per-constraint (i.e.
103 * - inner body of BKE_constraints_solve),
104 * - post (i.e. BKE_constraints_clear_evalob)
105 *
106 * Not sure why, this is from Joshua - sergey
107 */
111}
112
114{
115 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
116 /* Make sure inverse matrix is always up to date. This way users of it
117 * do not need to worry about recalculating it. */
118 invert_m4_m4_safe(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
119 /* Set negative scale flag in object. */
120 if (is_negative_m4(ob->object_to_world().ptr())) {
121 ob->transflag |= OB_NEG_SCALE;
122 }
123 else {
124 ob->transflag &= ~OB_NEG_SCALE;
125 }
126
127 ob->runtime->last_update_transform = DEG_get_update_count(depsgraph);
128}
129
131{
132 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
133
134 /* includes all keys and modifiers */
135 switch (ob->type) {
136 case OB_MESH: {
137 CustomData_MeshMasks cddata_masks = scene->customdata_mask;
139 /* Custom attributes should not be removed automatically. They might be used by the render
140 * engine or scripts. They can still be removed explicitly using geometry nodes.
141 * Vertex groups can be used in arbitrary situations with geometry nodes as well. */
143 cddata_masks.emask |= CD_MASK_PROP_ALL;
144 cddata_masks.fmask |= CD_MASK_PROP_ALL;
145 cddata_masks.pmask |= CD_MASK_PROP_ALL;
146 cddata_masks.lmask |= CD_MASK_PROP_ALL;
147
148 /* Make sure Freestyle edge/face marks appear in evaluated mesh (see #40315).
149 * Due to Line Art implementation, edge marks should also be shown in viewport. */
150#ifdef WITH_FREESTYLE
151 cddata_masks.emask |= CD_MASK_FREESTYLE_EDGE;
152 cddata_masks.pmask |= CD_MASK_FREESTYLE_FACE;
153#endif
155 /* Always compute orcos for render. */
156 cddata_masks.vmask |= CD_MASK_ORCO;
157 }
158 blender::bke::mesh_data_update(*depsgraph, *scene, *ob, cddata_masks);
159 break;
160 }
161 case OB_ARMATURE:
162 BKE_pose_where_is(depsgraph, scene, ob);
163 break;
164
165 case OB_MBALL:
167 break;
168
169 case OB_CURVES_LEGACY:
170 case OB_SURF:
171 case OB_FONT: {
172 bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
173 BKE_displist_make_curveTypes(depsgraph, scene, ob, for_render);
174 break;
175 }
176
177 case OB_LATTICE:
179 break;
180 case OB_CURVES:
182 break;
183 case OB_POINTCLOUD:
185 break;
186 case OB_VOLUME:
188 break;
189 case OB_GREASE_PENCIL:
191 break;
192 }
193
194 /* particles */
195 if (!(ob->mode & OB_MODE_EDIT) && ob->particlesystem.first) {
196 const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
197 ParticleSystem *tpsys, *psys;
198 ob->transflag &= ~OB_DUPLIPARTS;
199 psys = static_cast<ParticleSystem *>(ob->particlesystem.first);
200 while (psys) {
201 if (psys_check_enabled(ob, psys, use_render_params)) {
202 /* check use of dupli objects here */
203 if (psys->part && (psys->part->draw_as == PART_DRAW_REND || use_render_params) &&
204 ((psys->part->ren_as == PART_DRAW_OB && psys->part->instance_object) ||
205 (psys->part->ren_as == PART_DRAW_GR && psys->part->instance_collection)))
206 {
208 }
209
210 particle_system_update(depsgraph, scene, ob, psys, use_render_params);
211 psys = psys->next;
212 }
213 else if (psys->flag & PSYS_DELETE) {
214 tpsys = psys->next;
215 BLI_remlink(&ob->particlesystem, psys);
216 psys_free(ob, psys);
217 psys = tpsys;
218 }
219 else {
220 psys = psys->next;
221 }
222 }
223 }
224
226 Object *object_orig = DEG_get_original_object(ob);
227 object_orig->runtime->bounds_eval = BKE_object_evaluated_geometry_bounds(ob);
228 }
229}
230
232{
233 if (!DEG_is_active(depsgraph)) {
234 return;
235 }
236 Object *object_orig = DEG_get_original_object(object);
237 /* Base flags. */
238 object_orig->base_flag = object->base_flag;
239 /* Transformation flags. */
240 copy_m4_m4(object_orig->runtime->object_to_world.ptr(), object->object_to_world().ptr());
241 copy_m4_m4(object_orig->runtime->world_to_object.ptr(), object->world_to_object().ptr());
242 copy_m4_m4(object_orig->constinv, object->constinv);
243 object_orig->transflag = object->transflag;
244 object_orig->flag = object->flag;
245
246 /* Copy back error messages from modifiers. */
247 for (ModifierData *md = static_cast<ModifierData *>(object->modifiers.first),
248 *md_orig = static_cast<ModifierData *>(object_orig->modifiers.first);
249 md != nullptr && md_orig != nullptr;
250 md = md->next, md_orig = md_orig->next)
251 {
252 BLI_assert(md->type == md_orig->type && STREQ(md->name, md_orig->name));
253 MEM_SAFE_FREE(md_orig->error);
254 if (md->error != nullptr) {
255 md_orig->error = BLI_strdup(md->error);
256 }
257 }
258}
259
260void BKE_object_eval_uber_transform(Depsgraph * /*depsgraph*/, Object * /*object*/) {}
261
263{
264 switch (ob->type) {
265 case OB_MESH:
267 break;
268 case OB_LATTICE:
270 break;
271 case OB_CURVES_LEGACY:
272 case OB_SURF:
273 case OB_FONT:
275 break;
276 case OB_MBALL: {
277 /* This function is currently called on original objects, so to properly
278 * clear the actual displayed geometry, we have to tag the evaluated mesh. */
280 if (mesh) {
282 }
283 break;
284 }
285 case OB_CURVES:
287 break;
288 case OB_POINTCLOUD:
290 break;
291 case OB_VOLUME:
293 break;
294 case OB_GREASE_PENCIL:
297 break;
298 default:
299 break;
300 }
301}
302
303void BKE_object_eval_uber_data(Depsgraph *depsgraph, Scene *scene, Object *ob)
304{
305 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
309
310 ob->runtime->last_update_geometry = DEG_get_update_count(depsgraph);
311}
312
313void BKE_object_eval_ptcache_reset(Depsgraph *depsgraph, Scene *scene, Object *object)
314{
315 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
317}
318
319void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *object)
320{
321 /* This mimics full transform update chain from new depsgraph. */
323 if (object->parent != nullptr) {
325 }
326 if (!BLI_listbase_is_empty(&object->constraints)) {
328 }
331}
332
333void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
334{
335 DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data);
336 switch (GS(object_data->name)) {
337 case ID_ME:
339 break;
340 case ID_CU_LEGACY:
342 break;
343 case ID_LT:
345 break;
346 default:
347 break;
348 }
349}
350
352{
353 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
354 if (object->type == OB_MESH && !object->runtime->is_data_eval_owned) {
355 Mesh *mesh_input = (Mesh *)object->runtime->data_orig;
356 std::lock_guard lock{mesh_input->runtime->eval_mutex};
357 BKE_object_data_select_update(depsgraph, static_cast<ID *>(object->data));
358 }
359 else {
360 BKE_object_data_select_update(depsgraph, static_cast<ID *>(object->data));
361 }
362}
363
365 Scene *scene,
366 const int view_layer_index,
367 Object *object,
368 int base_index,
369 const bool is_from_set)
370{
371 /* TODO(sergey): Avoid list lookup. */
372 BLI_assert(view_layer_index >= 0);
373 ViewLayer *view_layer = static_cast<ViewLayer *>(
374 BLI_findlink(&scene->view_layers, view_layer_index));
375 BLI_assert(view_layer != nullptr);
376 BLI_assert(view_layer->object_bases_array != nullptr);
377 BLI_assert(base_index >= 0);
378 BLI_assert(base_index < MEM_allocN_len(view_layer->object_bases_array) / sizeof(Base *));
379 Base *base = view_layer->object_bases_array[base_index];
380 BLI_assert(base->object == object);
381
382 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
383
384 /* Set base flags based on collection and object restriction. */
386
387 /* For render, compute base visibility again since BKE_base_eval_flags
388 * assumed viewport visibility. Select-ability does not matter here. */
390 if (base->flag & BASE_ENABLED_RENDER) {
392 }
393 else {
394 base->flag &= ~BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT;
395 }
396 }
397
398 /* Copy flags and settings from base. */
399 object->base_flag = base->flag;
400 if (is_from_set) {
401 object->base_flag |= BASE_FROM_SET;
402 object->base_flag &= ~(BASE_SELECTED | BASE_SELECTABLE);
403 }
404 object->base_local_view_bits = base->local_view_bits;
405 object->runtime->local_collections_bits = base->local_collections_bits;
406
407 if (object->mode == OB_MODE_PARTICLE_EDIT) {
408 for (ParticleSystem *psys = static_cast<ParticleSystem *>(object->particlesystem.first);
409 psys != nullptr;
410 psys = psys->next)
411 {
413 }
414 }
415
416 /* Copy base flag back to the original view layer for editing. */
418 Base *base_orig = base->base_orig;
419 BLI_assert(base_orig != nullptr);
420 BLI_assert(base_orig->object != nullptr);
421 base_orig->flag = base->flag;
422 }
423}
424
426{
427 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
428 deg::light_linking::eval_runtime_data(depsgraph, *object);
429}
430
431void BKE_object_eval_shading(Depsgraph *depsgraph, Object *object)
432{
433 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
434
435 object->runtime->last_update_shading = DEG_get_update_count(depsgraph);
436}
void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition armature.cc:2941
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:5511
@ BKE_CURVE_BATCH_DIRTY_SELECT
Definition BKE_curve.hh:376
@ BKE_CURVE_BATCH_DIRTY_ALL
Definition BKE_curve.hh:375
Low-level operations for curves that cannot be defined in the C++ header yet.
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)
@ BKE_CURVES_BATCH_DIRTY_ALL
Definition BKE_curves.h:39
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:91
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_grease_pencil_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
void BKE_lattice_batch_cache_dirty_tag(Lattice *lt, int mode)
Definition lattice.cc:710
@ BKE_LATTICE_BATCH_DIRTY_SELECT
@ BKE_LATTICE_BATCH_DIRTY_ALL
void BKE_lattice_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition lattice.cc:516
void BKE_base_eval_flags(Base *base)
void BKE_mball_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition mball.cc:625
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:706
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:5295
void psys_free(struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:975
@ BKE_PARTICLE_BATCH_DIRTY_ALL
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:2317
Volume data-block.
void BKE_volume_batch_cache_dirty_tag(Volume *volume, int mode)
@ BKE_VOLUME_BATCH_DIRTY_ALL
Definition BKE_volume.hh:57
void BKE_volume_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
#define BLI_assert(a)
Definition BLI_assert.h:50
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:130
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.c:40
#define STREQ(a, b)
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
Definition depsgraph.cc:350
@ DAG_EVAL_RENDER
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:318
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)
Object * DEG_get_original_object(Object *object)
@ ID_CU_LEGACY
@ ID_ME
@ ID_LT
@ CONSTRAINT_OBTYPE_OBJECT
#define CD_MASK_ORCO
#define CD_MASK_MDEFORMVERT
#define CD_MASK_PROP_ALL
#define CD_MASK_FREESTYLE_FACE
#define CD_MASK_FREESTYLE_EDGE
@ BASE_FROM_SET
@ BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT
@ BASE_ENABLED_RENDER
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_EDIT
@ PARSKEL
@ PARTYPE
@ OB_LATTICE
@ OB_MBALL
@ OB_SURF
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_ARMATURE
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_NEG_SCALE
@ OB_DUPLIPARTS
@ PART_DRAW_GR
@ PART_DRAW_OB
@ PART_DRAW_REND
@ PSYS_DELETE
#define BASE_SELECTED(v3d, base)
#define BASE_SELECTABLE(v3d, base)
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
volatile int lock
const Depsgraph * depsgraph
#define GS(x)
Definition iris.cc:202
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 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:413
char name[66]
Definition DNA_ID.h:425
void * first
MeshRuntimeHandle * runtime
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 Base ** object_bases_array