Merge branch 'master' into soc-2013-depsgraph_mt soc-2013-depsgraph_mt
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 27 Dec 2013 11:05:49 +0000 (17:05 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 27 Dec 2013 11:05:49 +0000 (17:05 +0600)
Conflicts:
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/shrinkwrap.c
source/blender/collada/AnimationExporter.cpp
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_view3d/view3d_view.c
source/blender/makesrna/intern/rna_scene.c
source/blender/modifiers/intern/MOD_util.c
source/blender/render/intern/source/pipeline.c

1  2 
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/scene.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/space_view3d/drawobject.c
source/blender/modifiers/intern/MOD_util.c
source/blender/render/intern/source/pipeline.c

index f5f6cab60a231be5a141316515247c3228bab9f5,6ffa126713d2f26bd81d52e540c9c2410c4fe5a6..b4550584b4d26bdfcbd853c031802a8385c15d18
@@@ -651,7 -651,7 +651,7 @@@ DerivedMesh *getEditDerivedBMesh(struc
  DerivedMesh *mesh_create_derived_index_render(struct Scene *scene, struct Object *ob, CustomDataMask dataMask, int index);
  
  /* same as above but wont use render settings */
- DerivedMesh *mesh_create_derived(struct Mesh *me, struct Object *ob, float (*vertCos)[3]);
+ DerivedMesh *mesh_create_derived(struct Mesh *me, float (*vertCos)[3]);
  DerivedMesh *mesh_create_derived_view(struct Scene *scene, struct Object *ob,
                                        CustomDataMask dataMask);
  DerivedMesh *mesh_create_derived_no_deform(struct Scene *scene, struct Object *ob,
@@@ -676,7 -676,6 +676,7 @@@ float (*editbmesh_get_vertex_cos(struc
  int editbmesh_modifier_is_enabled(struct Scene *scene, struct ModifierData *md, DerivedMesh *dm);
  void makeDerivedMesh(struct Scene *scene, struct Object *ob, struct BMEditMesh *em, 
                       CustomDataMask dataMask, int build_shapekey_layers);
 +void makeDerivedMeshRender(struct Scene *scene, struct Object *ob, CustomDataMask dataMask);
  
  /** returns an array of deform matrices for crazyspace correction, and the
   * number of modifiers left */
index b5e757296592ff821968cd60e3001dec191ce6e3,419b8de2bc3027b6a0e296183dc58e085960f0fd..6ed8406d9a4cd5edf81617d0541189ec54d30f7d
@@@ -66,6 -66,7 +66,7 @@@ void BKE_object_free_curve_cache(struc
  void BKE_object_update_base_layer(struct Scene *scene, struct Object *ob);
  
  void BKE_object_free(struct Object *ob);
+ void BKE_object_free_ex(struct Object *ob, bool do_id_user);
  void BKE_object_free_derived_caches(struct Object *ob);
  
  void BKE_object_modifier_hook_reset(struct Object *ob, struct HookModifierData *hmd);
@@@ -114,10 -115,10 +115,10 @@@ bool BKE_object_pose_context_check(stru
  struct Object *BKE_object_pose_armature_get(struct Object *ob);
  
  void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob);
 -void BKE_object_where_is_calc_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, float r_originmat[3][3]);
 +void BKE_object_where_is_calc_ex(struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, bool for_render, float r_originmat[3][3]);
  void BKE_object_where_is_calc_time(struct Scene *scene, struct Object *ob, float ctime);
  void BKE_object_where_is_calc_time_ex(struct Scene *scene, struct Object *ob, float ctime,
 -                                      struct RigidBodyWorld *rbw, float r_originmat[3][3]);
 +                                      struct RigidBodyWorld *rbw, bool for_render, float r_originmat[3][3]);
  void BKE_object_where_is_calc_simul(struct Scene *scene, struct Object *ob);
  void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]);
  
index fa0f6e3af28ad99331e4f1a4eb944b1b0f0542a4,341e8e671c7b1b66c73388182cad2d66251b0bb1..b48b7629d411482ec99ada01d7708444645abb11
@@@ -838,9 -838,9 +838,9 @@@ void DM_interp_poly_data(DerivedMesh *s
  }
  
  ///
- DerivedMesh *mesh_create_derived(Mesh *me, Object *ob, float (*vertCos)[3])
+ DerivedMesh *mesh_create_derived(Mesh *me, float (*vertCos)[3])
  {
-       DerivedMesh *dm = CDDM_from_mesh(me, ob);
+       DerivedMesh *dm = CDDM_from_mesh(me);
        
        if (!dm)
                return NULL;
@@@ -874,7 -874,7 +874,7 @@@ DerivedMesh *mesh_create_derived_for_mo
                float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts);
  
                modwrap_deformVerts(md, ob, NULL, deformedVerts, numVerts, 0);
-               dm = mesh_create_derived(me, ob, deformedVerts);
+               dm = mesh_create_derived(me, deformedVerts);
  
                if (build_shapekey_layers)
                        add_shapekey_layers(dm, me, ob);
                MEM_freeN(deformedVerts);
        }
        else {
-               DerivedMesh *tdm = mesh_create_derived(me, ob, NULL);
+               DerivedMesh *tdm = mesh_create_derived(me, NULL);
  
                if (build_shapekey_layers)
                        add_shapekey_layers(tdm, me, ob);
@@@ -953,7 -953,7 +953,7 @@@ static DerivedMesh *create_orco_dm(Obje
        int free;
  
        if (em) dm = CDDM_from_editbmesh(em, FALSE, FALSE);
-       else dm = CDDM_from_mesh(me, ob);
+       else dm = CDDM_from_mesh(me);
  
        orco = get_orco_coords_dm(ob, em, layer, &free);
  
@@@ -1533,7 -1533,7 +1533,7 @@@ static void mesh_calc_modifiers(Scene *
                 * coordinates (vpaint, etc.)
                 */
                if (deform_r) {
-                       *deform_r = CDDM_from_mesh(me, ob);
+                       *deform_r = CDDM_from_mesh(me);
                         
                        if (build_shapekey_layers)
                                add_shapekey_layers(dm, me, ob);
                                }
                        }
                        else {
-                               dm = CDDM_from_mesh(me, ob);
+                               dm = CDDM_from_mesh(me);
                                ASSERT_IS_VALID_DM(dm);
  
                                if (build_shapekey_layers)
  #endif
        }
        else {
-               finaldm = CDDM_from_mesh(me, ob);
+               finaldm = CDDM_from_mesh(me);
                
                if (build_shapekey_layers) {
                        add_shapekey_layers(finaldm, me, ob);
@@@ -2356,7 -2356,7 +2356,7 @@@ DerivedMesh *mesh_get_derived_deform(Sc
  DerivedMesh *mesh_create_derived_render(Scene *scene, Object *ob, CustomDataMask dataMask)
  {
        DerivedMesh *final;
 -      
 +    
        mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, -1, 0, 0);
  
        return final;
index 26684d19507e05ad0c355e00386dbd8d5f6d453b,c069abfaf355e70ee81a20064758a95d7840cb0c..711065b0e8b2d481b88632eb4796b42cc11206e1
@@@ -321,7 -321,7 +321,7 @@@ void BKE_object_free_derived_caches(Obj
  }
  
  /* do not free object itself */
- void BKE_object_free(Object *ob)
+ void BKE_object_free_ex(Object *ob, bool do_id_user)
  {
        int a;
        
        if (ob->defbase.first)
                BLI_freelistN(&ob->defbase);
        if (ob->pose)
-               BKE_pose_free(ob->pose);
+               BKE_pose_free_ex(ob->pose, do_id_user);
        if (ob->mpath)
                animviz_free_motionpath(ob->mpath);
        BKE_bproperty_free_list(&ob->prop);
        }
  }
  
+ void BKE_object_free(Object *ob)
+ {
+       BKE_object_free_ex(ob, true);
+ }
  static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin)
  {
        Object *unlinkOb = userData;
@@@ -2330,8 -2335,7 +2335,8 @@@ static int where_is_object_parslow(Obje
  
  /* note, scene is the active scene while actual_scene is the scene the object resides in */
  void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
 -                                      RigidBodyWorld *rbw, float r_originmat[3][3])
 +                                      RigidBodyWorld *rbw, bool for_render,
 +                                      float r_originmat[3][3])
  {
        if (ob == NULL) return;
        
        /* solve constraints */
        if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
                bConstraintOb *cob;
 -              cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
 +
 +              (void) for_render;  /* Currently unused. */
 +
 +              /* TODO(sergey): Mixing viewport/render evaluation leads to conflicts because
 +               *               of shared ob->obmat.
 +               *               To preserve regressions for now don't use render evaluation
 +               *               for now.
 +               */
 +              cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT, false);
                BKE_solve_constraints(&ob->constraints, cob, ctime);
                BKE_constraints_clear_evalob(cob);
        }
  
  void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
  {
 -      BKE_object_where_is_calc_time_ex(scene, ob, ctime, NULL, NULL);
 +      /* TODO(sergey): We might need real for_render flag here */
 +      BKE_object_where_is_calc_time_ex(scene, ob, ctime, NULL, false, NULL);
  }
  
  /* get object transformation matrix without recalculating dependencies and
@@@ -2410,14 -2405,13 +2415,14 @@@ void BKE_object_where_is_calc_mat4(Scen
        }
  }
  
 -void BKE_object_where_is_calc_ex(Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
 +void BKE_object_where_is_calc_ex(Scene *scene, RigidBodyWorld *rbw, Object *ob, bool for_render, float r_originmat[3][3])
  {
 -      BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), rbw, r_originmat);
 +      BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), rbw, for_render, r_originmat);
  }
  void BKE_object_where_is_calc(Scene *scene, Object *ob)
  {
 -      BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), NULL, NULL);
 +      /* TODO(sergey): We might need real for_render flag here */
 +      BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), NULL, false, NULL);
  }
  
  /* was written for the old game engine (until 2.04) */
@@@ -2455,8 -2449,7 +2460,8 @@@ void BKE_object_where_is_calc_simul(Sce
        if (ob->constraints.first) {
                bConstraintOb *cob;
                
 -              cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
 +              /* TODO(sergey): We need a proper for_render flag here. */
 +              cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT, false);
                BKE_solve_constraints(&ob->constraints, cob, BKE_scene_frame_get(scene));
                BKE_constraints_clear_evalob(cob);
        }
@@@ -2900,7 -2893,7 +2905,7 @@@ void BKE_object_handle_update_ex(Evalua
                                        copy_m4_m4(ob->obmat, ob->proxy_from->obmat);
                        }
                        else
 -                              BKE_object_where_is_calc_ex(scene, rbw, ob, NULL);
 +                              BKE_object_where_is_calc_ex(scene, rbw, ob, eval_ctx->for_render, NULL);
                }
                
                if (ob->recalc & OB_RECALC_DATA) {
                                case OB_CURVE:
                                case OB_SURF:
                                case OB_FONT:
 -                                      BKE_displist_make_curveTypes(scene, ob, 0);
 +                                      if (eval_ctx->for_render == false) {
 +                                              BKE_displist_make_curveTypes(scene, ob, 0);
 +                                      }
                                        break;
                                
                                case OB_LATTICE:
index 84b9b0aadf42e998701f3ca23d73232df3a93fca,6de75215ae1127bb5f6aa6112e622a7fd7368718..3ca702e0068df11190c917c71931e30d81265124
@@@ -1184,7 -1184,7 +1184,7 @@@ static void scene_do_rb_simulation_recu
  
  /* Mballs evaluation uses BKE_scene_base_iter_next which calls
   * duplilist for all objects in the scene. This leads to conflict
 - * accessing and writting same data from multipl threads.
 + * accessing and writing same data from multiple threads.
   *
   * Ideally Mballs shouldn't do such an iteration and use DAG
   * queries instead. For the time being we've got new DAG
@@@ -1293,7 -1293,7 +1293,7 @@@ static void scene_update_object_func(Ta
        }
  
        /* Update will decrease child's valency and schedule child with zero valency. */
-       DAG_threaded_update_handle_node_updated(node,scene_update_object_add_task, pool);
+       DAG_threaded_update_handle_node_updated(node, scene_update_object_add_task, pool);
  
  #undef PRINT
  }
index 4d9234e18bc08b4670956d54f35f8ec80493ffb6,035a917d37f2d0ec6dcaba38dae51dba95fdcb79..8cb9853aa47bc6b01cc6dd4c12db04ff3017eeb5
@@@ -1354,7 -1354,13 +1354,13 @@@ void blo_end_image_pointer_map(FileDat
        }
        
        for (; ima; ima = ima->id.next) {
-               ima->cache = newmclipadr(fd, ima->cache);
+               ima->cache = newimaadr(fd, ima->cache);
+               if (ima->cache == NULL) {
+                       ima->bindcode = 0;
+                       ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
+                       ima->gputexture = NULL;
+                       ima->rr = NULL;
+               }
                for (i = 0; i < IMA_MAX_RENDER_SLOT; i++)
                        ima->renders[i] = newimaadr(fd, ima->renders[i]);
                
@@@ -3277,7 -3283,7 +3283,7 @@@ static void direct_link_image(FileData 
                ima->cache = NULL;
  
        /* if not restored, we keep the binded opengl index */
-       if (!fd->imamap) {
+       if (!ima->cache) {
                ima->bindcode = 0;
                ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
                ima->gputexture = NULL;
@@@ -5541,7 -5547,6 +5547,7 @@@ static void direct_link_windowmanager(F
        wm->winactive = NULL;
        wm->initialized = 0;
        wm->op_undo_depth = 0;
 +      wm->is_interface_locked = 0;
  }
  
  static void lib_link_windowmanager(FileData *fd, Main *main)
index 5b8c4a92555e53ddf238921845f780181439dd08,9eb3fb320be4dc79ea2664894ee7e8f687e6e781..02e981f2ffd409d2e85b9c471c971719de0fff5c
@@@ -6201,7 -6201,7 +6201,7 @@@ static void get_local_bounds(Object *ob
  }
  #endif
  
- static void draw_bb_quadric(BoundBox *bb, char type)
+ static void draw_bb_quadric(BoundBox *bb, char type, bool around_origin)
  {
        float size[3], cent[3];
        GLUquadricObj *qobj = gluNewQuadric();
        size[1] = 0.5f * fabsf(bb->vec[0][1] - bb->vec[2][1]);
        size[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]);
  
-       cent[0] = 0.5f * (bb->vec[0][0] + bb->vec[4][0]);
-       cent[1] = 0.5f * (bb->vec[0][1] + bb->vec[2][1]);
-       cent[2] = 0.5f * (bb->vec[0][2] + bb->vec[1][2]);
+       if (around_origin) {
+               zero_v3(cent);
+       }
+       else {
+               cent[0] = 0.5f * (bb->vec[0][0] + bb->vec[4][0]);
+               cent[1] = 0.5f * (bb->vec[0][1] + bb->vec[2][1]);
+               cent[2] = 0.5f * (bb->vec[0][2] + bb->vec[1][2]);
+       }
        
        glPushMatrix();
        if (type == OB_BOUND_SPHERE) {
@@@ -6278,11 -6283,37 +6283,37 @@@ static void draw_bounding_volume(Scene 
                BKE_boundbox_init_from_minmax(bb, min, max);
        }
        
-       if (bb == NULL) return;
-       
-       if (type == OB_BOUND_BOX) draw_box(bb->vec);
-       else draw_bb_quadric(bb, type);
+       if (bb == NULL)
+               return;
        
+       if (ob->gameflag & OB_BOUNDS) { /* bounds need to be drawn around origin for game engine */
+               if (type == OB_BOUND_BOX) {
+                       float vec[8][3], size[3];
+                       
+                       size[0] = 0.5f * fabsf(bb->vec[0][0] - bb->vec[4][0]);
+                       size[1] = 0.5f * fabsf(bb->vec[0][1] - bb->vec[2][1]);
+                       size[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]);
+                       
+                       vec[0][0] = vec[1][0] = vec[2][0] = vec[3][0] = -size[0];
+                       vec[4][0] = vec[5][0] = vec[6][0] = vec[7][0] = +size[0];
+                       vec[0][1] = vec[1][1] = vec[4][1] = vec[5][1] = -size[1];
+                       vec[2][1] = vec[3][1] = vec[6][1] = vec[7][1] = +size[1];
+                       vec[0][2] = vec[3][2] = vec[4][2] = vec[7][2] = -size[2];
+                       vec[1][2] = vec[2][2] = vec[5][2] = vec[6][2] = +size[2];
+                       
+                       draw_box(vec);
+               }
+               else {
+                       draw_bb_quadric(bb, type, true);
+               }
+       }
+       else {
+               if (type == OB_BOUND_BOX)
+                       draw_box(bb->vec);
+               else
+                       draw_bb_quadric(bb, type, false);
+       }
  }
  
  static void drawtexspace(Object *ob)
@@@ -6565,6 -6596,48 +6596,48 @@@ static void draw_object_matcap_check(Sc
  
  }
  
+ static void draw_rigidbody_shape(Object *ob)
+ {
+       BoundBox *bb = NULL;
+       float size[3], vec[8][3];
+       if (ob->type == OB_MESH) {
+               bb = BKE_mesh_boundbox_get(ob);
+       }
+       if (bb == NULL)
+               return;
+       switch (ob->rigidbody_object->shape) {
+               case RB_SHAPE_BOX:
+                       size[0] = 0.5f * fabsf(bb->vec[0][0] - bb->vec[4][0]);
+                       size[1] = 0.5f * fabsf(bb->vec[0][1] - bb->vec[2][1]);
+                       size[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]);
+                       
+                       vec[0][0] = vec[1][0] = vec[2][0] = vec[3][0] = -size[0];
+                       vec[4][0] = vec[5][0] = vec[6][0] = vec[7][0] = +size[0];
+                       vec[0][1] = vec[1][1] = vec[4][1] = vec[5][1] = -size[1];
+                       vec[2][1] = vec[3][1] = vec[6][1] = vec[7][1] = +size[1];
+                       vec[0][2] = vec[3][2] = vec[4][2] = vec[7][2] = -size[2];
+                       vec[1][2] = vec[2][2] = vec[5][2] = vec[6][2] = +size[2];
+                       
+                       draw_box(vec);
+                       break;
+               case RB_SHAPE_SPHERE:
+                       draw_bb_quadric(bb, OB_BOUND_SPHERE, true);
+                       break;
+               case RB_SHAPE_CONE:
+                       draw_bb_quadric(bb, OB_BOUND_CONE, true);
+                       break;
+               case RB_SHAPE_CYLINDER:
+                       draw_bb_quadric(bb, OB_BOUND_CYLINDER, true);
+                       break;
+               case RB_SHAPE_CAPSULE:
+                       draw_bb_quadric(bb, OB_BOUND_CAPSULE, true);
+                       break;
+       }
+ }
  /**
   * main object drawing function, draws in selection
   * \param dflag (draw flag) can be DRAW_PICKING and/or DRAW_CONSTCOLOR, DRAW_SCENESET
@@@ -7129,6 -7202,9 +7202,9 @@@ void draw_object(Scene *scene, ARegion 
                                setlinestyle(0);
                        }
                }
+               if (ob->rigidbody_object) {
+                       draw_rigidbody_shape(ob);
+               }
  
                /* draw extra: after normal draw because of makeDispList */
                if (dtx && (G.f & G_RENDER_OGL) == 0) {
                        UI_make_axis_color(col1, col2, 'Z');
                        glColor3ubv(col2);
                        
 -                      cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
 +                      cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT, false);
                        
                        for (curcon = list->first; curcon; curcon = curcon->next) {
                                if (ELEM(curcon->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_OBJECTSOLVER)) {
index 0c3746fc570bed6045bda3ad72e48ef03a02df1b,bde30fb23ae35ae6b09edea75c1f5ed824982770..c087a7870c0dbdfc784e68a5b307339818af903c
@@@ -183,7 -183,7 +183,7 @@@ DerivedMesh *get_dm(Object *ob, struct 
        }
        else if (ob->type == OB_MESH) {
                if (em) dm = CDDM_from_editbmesh(em, FALSE, FALSE);
-               else dm = CDDM_from_mesh((struct Mesh *)(ob->data), ob);
+               else dm = CDDM_from_mesh((struct Mesh *)(ob->data));
  
                if (vertexCos) {
                        CDDM_apply_vert_coords(dm, vertexCos);
  DerivedMesh *get_dm_for_modifier(Object *ob, ModifierApplyFlag flag)
  {
        if (flag & MOD_APPLY_RENDER) {
 -              /* TODO(sergey): Use proper derived render in the future. */
 +              /* TODO(sergey): Use proper derivedRender when known. */
                return ob->derivedFinal;
        }
        else {
index afff90feb49ad6a0790d51658870ee517b2d8896,4ec7ce1c0d284fcc6f8dd5c3b3eb624147b34106..78434427b18f0c5d93cbe71017f2e512f6f01704
@@@ -1612,6 -1612,7 +1612,7 @@@ static bool rlayer_node_uses_alpha(bNod
   */
  #define DEPSGRAPH_WORKAROUND_HACK
  
+ #ifdef DEPSGRAPH_WORKAROUND_HACK
  static bool allow_render_mesh_object(Object *ob)
  {
        /* override not showing object when duplis are used with particles */
        else if ((ob->transflag & OB_DUPLI) && !(ob->transflag & OB_DUPLIFRAMES)) {
                return false;
        }
 +
        return true;
  }
  
- #ifdef DEPSGRAPH_WORKAROUND_HACK
  static void tag_dependend_objects_for_render(Scene *scene, int renderlay)
  {
        Scene *sce_iter;