2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 20014 by Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Sergey Sharybin.
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file blender/blenkernel/intern/object_update.c
30 #include "DNA_anim_types.h"
31 #include "DNA_constraint_types.h"
32 #include "DNA_group_types.h"
33 #include "DNA_key_types.h"
34 #include "DNA_material_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
38 #include "BLI_blenlib.h"
39 #include "BLI_utildefines.h"
41 #include "BLI_threads.h"
43 #include "BKE_global.h"
44 #include "BKE_armature.h"
45 #include "BKE_action.h"
46 #include "BKE_constraint.h"
47 #include "BKE_depsgraph.h"
48 #include "BKE_DerivedMesh.h"
49 #include "BKE_animsys.h"
50 #include "BKE_displist.h"
51 #include "BKE_effect.h"
54 #include "BKE_lattice.h"
55 #include "BKE_editmesh.h"
56 #include "BKE_object.h"
57 #include "BKE_scene.h"
58 #include "BKE_material.h"
59 #include "BKE_image.h"
61 #include "DEG_depsgraph.h"
63 #ifdef WITH_LEGACY_DEPSGRAPH
64 # define DEBUG_PRINT if (!DEG_depsgraph_use_legacy() && G.debug & G_DEBUG_DEPSGRAPH) printf
66 # define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf
69 static ThreadMutex material_lock = BLI_MUTEX_INITIALIZER;
71 void BKE_object_eval_local_transform(EvaluationContext *UNUSED(eval_ctx),
75 DEBUG_PRINT("%s on %s\n", __func__, ob->id.name);
77 /* calculate local matrix */
78 BKE_object_to_mat4(ob, ob->obmat);
82 /* NOTE: based on solve_parenting(), but with the cruft stripped out */
83 void BKE_object_eval_parent(EvaluationContext *UNUSED(eval_ctx),
87 Object *par = ob->parent;
93 DEBUG_PRINT("%s on %s\n", __func__, ob->id.name);
95 /* get local matrix (but don't calculate it, as that was done already!) */
97 copy_m4_m4(locmat, ob->obmat);
99 /* get parent effect matrix */
100 BKE_object_get_parent_matrix(scene, ob, par, totmat);
103 mul_m4_m4m4(tmat, totmat, ob->parentinv);
104 mul_m4_m4m4(ob->obmat, tmat, locmat);
106 /* origin, for help line */
107 if ((ob->partype & PARTYPE) == PARSKEL) {
108 copy_v3_v3(ob->orig, par->obmat[3]);
111 copy_v3_v3(ob->orig, totmat[3]);
115 void BKE_object_eval_constraints(EvaluationContext *UNUSED(eval_ctx),
120 float ctime = BKE_scene_frame_get(scene);
122 DEBUG_PRINT("%s on %s\n", __func__, ob->id.name);
124 /* evaluate constraints stack */
125 /* TODO: split this into:
126 * - pre (i.e. BKE_constraints_make_evalob, per-constraint (i.e.
127 * - inner body of BKE_constraints_solve),
128 * - post (i.e. BKE_constraints_clear_evalob)
130 * Not sure why, this is from Joshua - sergey
133 cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
134 BKE_constraints_solve(&ob->constraints, cob, ctime);
135 BKE_constraints_clear_evalob(cob);
138 void BKE_object_eval_done(EvaluationContext *UNUSED(eval_ctx), Object *ob)
140 DEBUG_PRINT("%s on %s\n", __func__, ob->id.name);
142 /* Set negative scale flag in object. */
143 if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE;
144 else ob->transflag &= ~OB_NEG_SCALE;
147 void BKE_object_eval_modifier(struct EvaluationContext *eval_ctx,
150 struct ModifierData *md)
152 DEBUG_PRINT("%s on %s\n", __func__, ob->id.name);
153 (void) eval_ctx; /* Ignored. */
154 (void) scene; /* Ignored. */
155 (void) ob; /* Ignored. */
156 (void) md; /* Ignored. */
159 void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
163 ID *data_id = (ID *)ob->data;
164 AnimData *adt = BKE_animdata_from_id(data_id);
166 float ctime = BKE_scene_frame_get(scene);
168 if (G.debug & G_DEBUG_DEPSGRAPH)
169 printf("recalcdata %s\n", ob->id.name + 2);
171 /* TODO(sergey): Only used by legacy depsgraph. */
173 /* evaluate drivers - datalevel */
174 /* XXX: for mesh types, should we push this to derivedmesh instead? */
175 BKE_animsys_evaluate_animdata(scene, data_id, adt, ctime, ADT_RECALC_DRIVERS);
178 /* TODO(sergey): Only used by legacy depsgraph. */
179 key = BKE_key_from_object(ob);
180 if (key && key->block.first) {
181 if (!(ob->shapeflag & OB_SHAPE_LOCK))
182 BKE_animsys_evaluate_animdata(scene, &key->id, key->adt, ctime, ADT_RECALC_DRIVERS);
185 /* includes all keys and modifiers */
189 BMEditMesh *em = (ob == scene->obedit) ? BKE_editmesh_from_object(ob) : NULL;
190 uint64_t data_mask = scene->customdata_mask | CD_MASK_BAREMESH;
191 #ifdef WITH_FREESTYLE
192 /* make sure Freestyle edge/face marks appear in DM for render (see T40315) */
193 if (eval_ctx->mode != DAG_EVAL_VIEWPORT) {
194 data_mask |= CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
198 makeDerivedMesh(scene, ob, em, data_mask, false); /* was CD_MASK_BAREMESH */
201 makeDerivedMesh(scene, ob, NULL, data_mask, false);
206 if (ob->id.lib && ob->proxy_from) {
207 if (BKE_pose_copy_result(ob->pose, ob->proxy_from->pose) == false) {
208 printf("Proxy copy error, lib Object: %s proxy Object: %s\n",
209 ob->id.name + 2, ob->proxy_from->id.name + 2);
213 BKE_pose_where_is(scene, ob);
218 BKE_displist_make_mball(eval_ctx, scene, ob);
224 BKE_displist_make_curveTypes(scene, ob, 0);
228 BKE_lattice_modifiers_calc(scene, ob);
232 if (ob->empty_drawtype == OB_EMPTY_IMAGE && ob->data)
233 if (BKE_image_is_animated(ob->data))
234 BKE_image_user_check_frame_calc(ob->iuser, (int)ctime, 0);
238 /* related materials */
239 /* XXX: without depsgraph tagging, this will always need to be run, which will be slow!
240 * However, not doing anything (or trying to hack around this lack) is not an option
241 * anymore, especially due to Cycles [#31834]
245 if (ob->totcol != 0) {
246 BLI_mutex_lock(&material_lock);
247 for (a = 1; a <= ob->totcol; a++) {
248 Material *ma = give_current_material(ob, a);
250 /* recursively update drivers for this material */
251 material_drivers_update(scene, ma, ctime);
254 BLI_mutex_unlock(&material_lock);
257 else if (ob->type == OB_LAMP)
258 lamp_drivers_update(scene, ob->data, ctime);
260 /* quick cache removed */
263 void BKE_object_eval_uber_transform(EvaluationContext *UNUSED(eval_ctx),
264 Scene *UNUSED(scene),
267 /* TODO(sergey): Currently it's a duplicate of logic in BKE_object_handle_update_ex(). */
268 // XXX: it's almost redundant now...
270 /* Handle proxy copy for target, */
271 if (ob->id.lib && ob->proxy_from) {
272 if (ob->proxy_from->proxy_group) {
273 /* Transform proxy into group space. */
274 Object *obg = ob->proxy_from->proxy_group;
276 invert_m4_m4(imat, obg->obmat);
277 mul_m4_m4m4(ob->obmat, imat, ob->proxy_from->obmat);
278 /* Should always be true. */
279 if (obg->dup_group) {
280 add_v3_v3(ob->obmat[3], obg->dup_group->dupli_ofs);
284 copy_m4_m4(ob->obmat, ob->proxy_from->obmat);
287 ob->recalc &= ~(OB_RECALC_OB | OB_RECALC_TIME);
288 if (ob->data == NULL) {
289 ob->recalc &= ~OB_RECALC_DATA;
293 void BKE_object_eval_uber_data(EvaluationContext *eval_ctx,
297 DEBUG_PRINT("%s on %s\n", __func__, ob->id.name);
298 BLI_assert(ob->type != OB_ARMATURE);
299 BKE_object_handle_data_update(eval_ctx, scene, ob);
301 ob->recalc &= ~(OB_RECALC_DATA | OB_RECALC_TIME);
304 void BKE_object_eval_proxy_backlink(EvaluationContext *UNUSED(eval_ctx), Object *ob)
307 ob->proxy->proxy_from = ob;