Blender V5.0
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_grease_pencil.h"
26#include "BKE_grease_pencil.hh"
27#include "BKE_lattice.hh"
28#include "BKE_layer.hh"
29#include "BKE_mball.hh"
30#include "BKE_mesh.hh"
31#include "BKE_object.hh"
32#include "BKE_particle.h"
33#include "BKE_pointcache.h"
34#include "BKE_pointcloud.hh"
35#include "BKE_scene.hh"
36#include "BKE_volume.hh"
37
38#include "MEM_guardedalloc.h"
39
40#include "DEG_depsgraph.hh"
43
44namespace deg = blender::deg;
45
50
52{
53 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
54
55 /* calculate local matrix */
56 BKE_object_to_mat4(ob, ob->runtime->object_to_world.ptr());
57}
58
60{
61 /* NOTE: based on `solve_parenting()`, but with the cruft stripped out. */
62
63 Object *par = ob->parent;
64
65 float totmat[4][4];
66 float tmat[4][4];
67 float locmat[4][4];
68
69 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
70
71 /* get local matrix (but don't calculate it, as that was done already!) */
72 /* XXX: redundant? */
73 copy_m4_m4(locmat, ob->object_to_world().ptr());
74
75 /* get parent effect matrix */
76 BKE_object_get_parent_matrix(ob, par, totmat);
77
78 /* total */
79 mul_m4_m4m4(tmat, totmat, ob->parentinv);
80 mul_m4_m4m4(ob->runtime->object_to_world.ptr(), tmat, locmat);
81
82 /* origin, for help line */
83 if ((ob->partype & PARTYPE) == PARSKEL) {
84 copy_v3_v3(ob->runtime->parent_display_origin, par->object_to_world().location());
85 }
86 else {
87 copy_v3_v3(ob->runtime->parent_display_origin, totmat[3]);
88 }
89}
90
92{
93 bConstraintOb *cob;
94 float ctime = BKE_scene_ctime_get(scene);
95
96 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
97
98 /* evaluate constraints stack */
99 /* TODO: split this into:
100 * - pre (i.e. BKE_constraints_make_evalob, per-constraint (i.e.
101 * - inner body of BKE_constraints_solve),
102 * - post (i.e. BKE_constraints_clear_evalob)
103 *
104 * Not sure why, this is from Joshua - sergey
105 */
109}
110
112{
113 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
114 /* Make sure inverse matrix is always up to date. This way users of it
115 * do not need to worry about recalculating it. */
116 invert_m4_m4_safe(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
117 /* Set negative scale flag in object. */
118 if (is_negative_m4(ob->object_to_world().ptr())) {
119 ob->transflag |= OB_NEG_SCALE;
120 }
121 else {
123 }
124
125 ob->runtime->last_update_transform = DEG_get_update_count(depsgraph);
126}
127
129{
130 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
131
132 /* includes all keys and modifiers */
133 switch (ob->type) {
134 case OB_MESH: {
135 CustomData_MeshMasks cddata_masks = scene->customdata_mask;
137 /* Custom attributes should not be removed automatically. They might be used by the render
138 * engine or scripts. They can still be removed explicitly using geometry nodes.
139 * Vertex groups can be used in arbitrary situations with geometry nodes as well. */
141 cddata_masks.emask |= CD_MASK_PROP_ALL;
142 cddata_masks.fmask |= CD_MASK_PROP_ALL;
143 cddata_masks.pmask |= CD_MASK_PROP_ALL;
144 cddata_masks.lmask |= CD_MASK_PROP_ALL;
146 /* Always compute orcos for render. */
147 cddata_masks.vmask |= CD_MASK_ORCO;
148 }
149 blender::bke::mesh_data_update(*depsgraph, *scene, *ob, cddata_masks);
150 break;
151 }
152 case OB_ARMATURE:
153 BKE_pose_where_is(depsgraph, scene, ob);
154 break;
155
156 case OB_MBALL:
158 break;
159
160 case OB_CURVES_LEGACY:
161 case OB_SURF:
162 case OB_FONT: {
163 bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
164 BKE_displist_make_curveTypes(depsgraph, scene, ob, for_render);
165 break;
166 }
167
168 case OB_LATTICE:
170 break;
171 case OB_CURVES:
173 break;
174 case OB_POINTCLOUD:
176 break;
177 case OB_VOLUME:
179 break;
180 case OB_GREASE_PENCIL:
182 break;
183 }
184
185 /* particles */
186 if (!(ob->mode & OB_MODE_EDIT) && ob->particlesystem.first) {
187 const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
188 ParticleSystem *tpsys, *psys;
190 psys = static_cast<ParticleSystem *>(ob->particlesystem.first);
191 while (psys) {
192 if (psys_check_enabled(ob, psys, use_render_params)) {
193 /* check use of dupli objects here */
194 if (psys->part && (psys->part->draw_as == PART_DRAW_REND || use_render_params) &&
195 ((psys->part->ren_as == PART_DRAW_OB && psys->part->instance_object) ||
196 (psys->part->ren_as == PART_DRAW_GR && psys->part->instance_collection)))
197 {
199 }
200
201 particle_system_update(depsgraph, scene, ob, psys, use_render_params);
202 psys = psys->next;
203 }
204 else if (psys->flag & PSYS_DELETE) {
205 tpsys = psys->next;
206 BLI_remlink(&ob->particlesystem, psys);
207 psys_free(ob, psys);
208 psys = tpsys;
209 }
210 else {
211 psys = psys->next;
212 }
213 }
214 }
215
217 Object *object_orig = DEG_get_original(ob);
218 object_orig->runtime->bounds_eval = BKE_object_evaluated_geometry_bounds(ob);
219 }
220}
221
223{
224 if (!DEG_is_active(depsgraph)) {
225 return;
226 }
227 Object *object_orig = DEG_get_original(object);
228 /* Base flags. */
229 object_orig->base_flag = object->base_flag;
230 object_orig->base_local_view_bits = object->base_local_view_bits;
231 /* Transformation flags. */
232 copy_m4_m4(object_orig->runtime->object_to_world.ptr(), object->object_to_world().ptr());
233 copy_m4_m4(object_orig->runtime->world_to_object.ptr(), object->world_to_object().ptr());
234 copy_m4_m4(object_orig->constinv, object->constinv);
235 object_orig->transflag = object->transflag;
236 object_orig->flag = object->flag;
237
238 /* Copy back error messages from modifiers. */
239 for (ModifierData *md = static_cast<ModifierData *>(object->modifiers.first),
240 *md_orig = static_cast<ModifierData *>(object_orig->modifiers.first);
241 md != nullptr && md_orig != nullptr;
242 md = md->next, md_orig = md_orig->next)
243 {
244 BLI_assert(md->type == md_orig->type && STREQ(md->name, md_orig->name));
245 MEM_SAFE_FREE(md_orig->error);
246 if (md->error != nullptr) {
247 md_orig->error = BLI_strdup(md->error);
248 }
249 }
250}
251
252void BKE_object_eval_uber_transform(Depsgraph * /*depsgraph*/, Object * /*object*/) {}
253
255{
256 switch (ob->type) {
257 case OB_MESH:
259 break;
260 case OB_LATTICE:
262 break;
263 case OB_CURVES_LEGACY:
264 case OB_SURF:
265 case OB_FONT:
267 break;
268 case OB_MBALL: {
269 /* This function is currently called on original objects, so to properly
270 * clear the actual displayed geometry, we have to tag the evaluated mesh. */
272 if (mesh) {
274 }
275 break;
276 }
277 case OB_CURVES:
279 break;
280 case OB_POINTCLOUD:
282 break;
283 case OB_VOLUME:
285 break;
286 case OB_GREASE_PENCIL:
289 break;
290 default:
291 break;
292 }
293}
294
295void BKE_object_eval_uber_data(Depsgraph *depsgraph, Scene *scene, Object *ob)
296{
297 DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
301
302 ob->runtime->last_update_geometry = DEG_get_update_count(depsgraph);
303}
304
305void BKE_object_eval_ptcache_reset(Depsgraph *depsgraph, Scene *scene, Object *object)
306{
307 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
309}
310
311void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *object)
312{
313 /* This mimics full transform update chain from new depsgraph. */
315 if (object->parent != nullptr) {
317 }
318 if (!BLI_listbase_is_empty(&object->constraints)) {
320 }
323}
324
325void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
326{
327 DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data);
328 switch (GS(object_data->name)) {
329 case ID_ME:
331 break;
332 case ID_CU_LEGACY:
334 break;
335 case ID_LT:
337 break;
338 default:
339 break;
340 }
341}
342
344{
345 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
346 if (object->type == OB_MESH && !object->runtime->is_data_eval_owned) {
347 Mesh *mesh_input = (Mesh *)object->runtime->data_orig;
348 std::lock_guard lock{mesh_input->runtime->eval_mutex};
349 BKE_object_data_select_update(depsgraph, static_cast<ID *>(object->data));
350 }
351 else {
352 BKE_object_data_select_update(depsgraph, static_cast<ID *>(object->data));
353 }
354}
355
357 Scene *scene,
358 const int view_layer_index,
359 Object *object,
360 int base_index,
361 const bool is_from_set)
362{
363 /* TODO(sergey): Avoid list lookup. */
364 BLI_assert(view_layer_index >= 0);
365 ViewLayer *view_layer = static_cast<ViewLayer *>(
366 BLI_findlink(&scene->view_layers, view_layer_index));
367 BLI_assert(view_layer != nullptr);
368 BLI_assert(view_layer->object_bases_array != nullptr);
369 BLI_assert(base_index >= 0);
370 BLI_assert(base_index < MEM_allocN_len(view_layer->object_bases_array) / sizeof(Base *));
371 Base *base = view_layer->object_bases_array[base_index];
372 BLI_assert(base->object == object);
373
374 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
375
376 /* Set base flags based on collection and object restriction. */
378
379 /* For render, compute base visibility again since BKE_base_eval_flags
380 * assumed viewport visibility. Select-ability does not matter here. */
382 if (base->flag & BASE_ENABLED_RENDER) {
384 }
385 else {
387 }
388 }
389
390 /* Copy flags and settings from base. */
391 object->base_flag = base->flag;
392 if (is_from_set) {
393 object->base_flag |= BASE_FROM_SET;
394 object->base_flag &= ~(BASE_SELECTED | BASE_SELECTABLE);
395 }
396 object->base_local_view_bits = base->local_view_bits;
397 object->runtime->local_collections_bits = base->local_collections_bits;
398
399 if (object->mode == OB_MODE_PARTICLE_EDIT) {
400 for (ParticleSystem *psys = static_cast<ParticleSystem *>(object->particlesystem.first);
401 psys != nullptr;
402 psys = psys->next)
403 {
405 }
406 }
407
408 /* Copy base flag back to the original view layer for editing. */
410 Base *base_orig = base->base_orig;
411 BLI_assert(base_orig != nullptr);
412 BLI_assert(base_orig->object != nullptr);
413 base_orig->flag = base->flag;
414 }
415}
416
418{
419 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
421}
422
423void BKE_object_eval_shading(Depsgraph *depsgraph, Object *object)
424{
425 DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
426
427 object->runtime->last_update_shading = DEG_get_update_count(depsgraph);
428}
void BKE_pose_where_is(Depsgraph *depsgraph, Scene *scene, Object *ob)
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:5502
@ 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.
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:37
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:96
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)
@ BKE_LATTICE_BATCH_DIRTY_SELECT
@ BKE_LATTICE_BATCH_DIRTY_ALL
void BKE_lattice_batch_cache_dirty_tag(Lattice *lt, int mode)
Definition lattice.cc:704
void BKE_lattice_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition lattice.cc:514
void BKE_base_eval_flags(Base *base)
void BKE_mball_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition mball.cc:650
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:710
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:5288
@ BKE_PARTICLE_BATCH_DIRTY_ALL
void psys_free(struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:978
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:2370
Volume data-block.
@ BKE_VOLUME_BATCH_DIRTY_ALL
Definition BKE_volume.hh:61
void BKE_volume_batch_cache_dirty_tag(Volume *volume, int mode)
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
#define CD_MASK_ORCO
#define CD_MASK_MDEFORMVERT
#define CD_MASK_PROP_ALL
@ 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
@ 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.
#define MEM_SAFE_FREE(v)
volatile int lock
BPy_StructRNA * depsgraph
#define GS(x)
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:414
char name[258]
Definition DNA_ID.h:432
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
unsigned short base_local_view_bits
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