Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenkernel / intern / object.c
index 3795e1bbf0e84ca74e721f0ceb6c5d50386c1f81..f58a0d76b6ab7532151ede3f43760f173d44c17f 100644 (file)
@@ -2664,6 +2664,28 @@ bool BKE_object_parent_loop_check(const Object *par, const Object *ob)
        return BKE_object_parent_loop_check(par->parent, ob);
 }
 
+static void object_handle_update_proxy(const EvaluationContext *eval_ctx,
+                                       Scene *scene,
+                                       Object *object,
+                                       const bool do_proxy_update)
+{
+       /* The case when this is a group proxy, object_update is called in group.c */
+       if (object->proxy == NULL) {
+               return;
+       }
+       /* set pointer in library proxy target, for copying, but restore it */
+       object->proxy->proxy_from = object;
+       // printf("set proxy pointer for later group stuff %s\n", ob->id.name);
+
+       /* the no-group proxy case, we call update */
+       if (object->proxy_group == NULL) {
+               if (do_proxy_update) {
+                       // printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name);
+                       BKE_object_handle_update(eval_ctx, scene, object->proxy);
+               }
+       }
+}
+
 /* proxy rule: lib_object->proxy_from == the one we borrow from, only set temporal and cleared here */
 /*           local_object->proxy      == pointer to library object, saved in files and read */
 
@@ -2677,75 +2699,49 @@ void BKE_object_handle_update_ex(const EvaluationContext *eval_ctx,
                                  RigidBodyWorld *rbw,
                                  const bool do_proxy_update)
 {
-       if (ob->recalc & OB_RECALC_ALL) {
-               /* speed optimization for animation lookups */
-               if (ob->pose) {
-                       BKE_pose_channels_hash_make(ob->pose);
-                       if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
-                               BKE_pose_update_constraint_flags(ob->pose);
-                       }
+       if ((ob->recalc & OB_RECALC_ALL) == 0) {
+               object_handle_update_proxy(eval_ctx, scene, ob, do_proxy_update);
+               return;
+       }
+       /* Speed optimization for animation lookups. */
+       if (ob->pose != NULL) {
+               BKE_pose_channels_hash_make(ob->pose);
+               if (ob->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
+                       BKE_pose_update_constraint_flags(ob->pose);
                }
-
-               if (ob->recalc & OB_RECALC_DATA) {
-                       if (ob->type == OB_ARMATURE) {
-                               /* this happens for reading old files and to match library armatures
-                                * with poses we do it ahead of BKE_object_where_is_calc to ensure animation
-                                * is evaluated on the rebuilt pose, otherwise we get incorrect poses
-                                * on file load */
-                               if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC))
-                                       BKE_pose_rebuild(ob, ob->data);
-                       }
+       }
+       if (ob->recalc & OB_RECALC_DATA) {
+               if (ob->type == OB_ARMATURE) {
+                       /* this happens for reading old files and to match library armatures
+                        * with poses we do it ahead of BKE_object_where_is_calc to ensure animation
+                        * is evaluated on the rebuilt pose, otherwise we get incorrect poses
+                        * on file load */
+                       if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC))
+                               BKE_pose_rebuild(ob, ob->data);
                }
-
-               /* XXX new animsys warning: depsgraph tag OB_RECALC_DATA should not skip drivers, 
-                * which is only in BKE_object_where_is_calc now */
-               /* XXX: should this case be OB_RECALC_OB instead? */
-               if (ob->recalc & OB_RECALC_ALL) {
-                       
-                       if (G.debug & G_DEBUG_DEPSGRAPH)
-                               printf("recalcob %s\n", ob->id.name + 2);
-                       
-                       /* handle proxy copy for target */
-                       if (ID_IS_LINKED(ob) && ob->proxy_from) {
-                               // printf("ob proxy copy, lib ob %s proxy %s\n", ob->id.name, ob->proxy_from->id.name);
-                               if (ob->proxy_from->proxy_group) { /* transform proxy into group space */
-                                       Object *obg = ob->proxy_from->proxy_group;
-                                       float imat[4][4];
-                                       invert_m4_m4(imat, obg->obmat);
-                                       mul_m4_m4m4(ob->obmat, imat, ob->proxy_from->obmat);
-                                       if (obg->dup_group) { /* should always be true */
-                                               add_v3_v3(ob->obmat[3], obg->dup_group->dupli_ofs);
-                                       }
-                               }
-                               else
-                                       copy_m4_m4(ob->obmat, ob->proxy_from->obmat);
-                       }
-                       else
-                               BKE_object_where_is_calc_ex(eval_ctx, scene, rbw, ob, NULL);
+       }
+       /* XXX new animsys warning: depsgraph tag OB_RECALC_DATA should not skip drivers,
+        * which is only in BKE_object_where_is_calc now */
+       /* XXX: should this case be OB_RECALC_OB instead? */
+       if (ob->recalc & OB_RECALC_ALL) {
+               if (G.debug & G_DEBUG_DEPSGRAPH) {
+                       printf("recalcob %s\n", ob->id.name + 2);
                }
-               
-               if (ob->recalc & OB_RECALC_DATA) {
-                       BKE_object_handle_data_update(eval_ctx, scene, ob);
+               /* Handle proxy copy for target. */
+               if (!BKE_object_eval_proxy_copy(eval_ctx, ob)) {
+                       BKE_object_where_is_calc_ex(eval_ctx, scene, rbw, ob, NULL);
                }
+       }
 
-               ob->recalc &= ~OB_RECALC_ALL;
+       if (ob->recalc & OB_RECALC_DATA) {
+               BKE_object_handle_data_update(eval_ctx, scene, ob);
        }
 
-       /* the case when this is a group proxy, object_update is called in group.c */
-       if (ob->proxy) {
-               /* set pointer in library proxy target, for copying, but restore it */
-               ob->proxy->proxy_from = ob;
-               // printf("set proxy pointer for later group stuff %s\n", ob->id.name);
+       ob->recalc &= ~OB_RECALC_ALL;
 
-               /* the no-group proxy case, we call update */
-               if (ob->proxy_group == NULL) {
-                       if (do_proxy_update) {
-                               // printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name);
-                               BKE_object_handle_update(eval_ctx, scene, ob->proxy);
-                       }
-               }
-       }
+       object_handle_update_proxy(eval_ctx, scene, ob, do_proxy_update);
 }
+
 /* WARNING: "scene" here may not be the scene object actually resides in. 
  * When dealing with background-sets, "scene" is actually the active scene.
  * e.g. "scene" <-- set 1 <-- set 2 ("ob" lives here) <-- set 3 <-- ... <-- set n