Fix for two proxy + undo related crashes:
[blender.git] / source / blender / blenkernel / intern / object.c
index e63d6047cc63d55afa005b089227a7ce2d5aefe1..a25afeafaef5fb3edd115b3ff865439c82d6cecb 100644 (file)
@@ -70,6 +70,7 @@
 
 #include "BKE_armature.h"
 #include "BKE_action.h"
 
 #include "BKE_armature.h"
 #include "BKE_action.h"
+#include "BKE_bullet.h"
 #include "BKE_colortools.h"
 #include "BKE_deform.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_colortools.h"
 #include "BKE_deform.h"
 #include "BKE_DerivedMesh.h"
 
 #include "LBM_fluidsim.h"
 
 
 #include "LBM_fluidsim.h"
 
+#ifndef DISABLE_PYTHON
 #include "BPY_extern.h"
 #include "BPY_extern.h"
+#endif
 
 #include "GPU_material.h"
 
 
 #include "GPU_material.h"
 
@@ -179,6 +182,14 @@ void object_free_softbody(Object *ob)
        }
 }
 
        }
 }
 
+void object_free_bulletsoftbody(Object *ob)
+{
+       if(ob->bsoft) {
+               bsbFree(ob->bsoft);
+               ob->bsoft= NULL;
+       }
+}
+
 void object_free_modifiers(Object *ob)
 {
        while (ob->modifiers.first) {
 void object_free_modifiers(Object *ob)
 {
        while (ob->modifiers.first) {
@@ -260,8 +271,10 @@ void free_object(Object *ob)
        free_constraints(&ob->constraints);
        free_constraint_channels(&ob->constraintChannels);
        free_nlastrips(&ob->nlastrips);
        free_constraints(&ob->constraints);
        free_constraint_channels(&ob->constraintChannels);
        free_nlastrips(&ob->nlastrips);
-       
+
+#ifndef DISABLE_PYTHON 
        BPY_free_scriptlink(&ob->scriptlink);
        BPY_free_scriptlink(&ob->scriptlink);
+#endif
        
        if(ob->pd){
                if(ob->pd->tex)
        
        if(ob->pd){
                if(ob->pd->tex)
@@ -269,7 +282,7 @@ void free_object(Object *ob)
                MEM_freeN(ob->pd);
        }
        if(ob->soft) sbFree(ob->soft);
                MEM_freeN(ob->pd);
        }
        if(ob->soft) sbFree(ob->soft);
-       if(ob->fluidsimSettings) fluidsimSettingsFree(ob->fluidsimSettings);
+       if(ob->bsoft) bsbFree(ob->bsoft);
        if(ob->gpulamp.first) GPU_lamp_free(ob);
 }
 
        if(ob->gpulamp.first) GPU_lamp_free(ob);
 }
 
@@ -628,9 +641,9 @@ Camera *copy_camera(Camera *cam)
        
        camn= copy_libblock(cam);
        id_us_plus((ID *)camn->ipo);
        
        camn= copy_libblock(cam);
        id_us_plus((ID *)camn->ipo);
-
+#ifndef DISABLE_PYTHON
        BPY_copy_scriptlink(&camn->scriptlink);
        BPY_copy_scriptlink(&camn->scriptlink);
-       
+#endif 
        return camn;
 }
 
        return camn;
 }
 
@@ -748,6 +761,11 @@ void *add_lamp(char *name)
        la->atm_extinction_factor = 1.0;
        la->atm_distance_factor = 1.0;
        la->sun_intensity = 1.0;
        la->atm_extinction_factor = 1.0;
        la->atm_distance_factor = 1.0;
        la->sun_intensity = 1.0;
+       la->skyblendtype= MA_RAMP_ADD;
+       la->skyblendfac= 1.0f;
+       la->sky_colorspace= BLI_CS_CIE;
+       la->sky_exposure= 1.0f;
+       
        curvemapping_initialize(la->curfalloff);
        return la;
 }
        curvemapping_initialize(la->curfalloff);
        return la;
 }
@@ -772,9 +790,9 @@ Lamp *copy_lamp(Lamp *la)
        id_us_plus((ID *)lan->ipo);
 
        if (la->preview) lan->preview = BKE_previewimg_copy(la->preview);
        id_us_plus((ID *)lan->ipo);
 
        if (la->preview) lan->preview = BKE_previewimg_copy(la->preview);
-
+#ifndef DISABLE_PYTHON
        BPY_copy_scriptlink(&la->scriptlink);
        BPY_copy_scriptlink(&la->scriptlink);
-       
+#endif
        return lan;
 }
 
        return lan;
 }
 
@@ -832,7 +850,9 @@ void make_local_lamp(Lamp *la)
 
 void free_camera(Camera *ca)
 {
 
 void free_camera(Camera *ca)
 {
+#ifndef DISABLE_PYTHON
        BPY_free_scriptlink(&ca->scriptlink);
        BPY_free_scriptlink(&ca->scriptlink);
+#endif
 }
 
 void free_lamp(Lamp *la)
 }
 
 void free_lamp(Lamp *la)
@@ -841,8 +861,9 @@ void free_lamp(Lamp *la)
        int a;
 
        /* scriptlinks */
        int a;
 
        /* scriptlinks */
-               
+#ifndef DISABLE_PYTHON
        BPY_free_scriptlink(&la->scriptlink);
        BPY_free_scriptlink(&la->scriptlink);
+#endif
 
        for(a=0; a<MAX_MTEX; a++) {
                mtex= la->mtex[a];
 
        for(a=0; a<MAX_MTEX; a++) {
                mtex= la->mtex[a];
@@ -960,9 +981,9 @@ Object *add_only_object(int type, char *name)
        ob->anisotropicFriction[0] = 1.0f;
        ob->anisotropicFriction[1] = 1.0f;
        ob->anisotropicFriction[2] = 1.0f;
        ob->anisotropicFriction[0] = 1.0f;
        ob->anisotropicFriction[1] = 1.0f;
        ob->anisotropicFriction[2] = 1.0f;
-       ob->gameflag= OB_PROP|OB_PHYSICS;
+       ob->gameflag= OB_PROP|OB_COLLISION;
        ob->margin = 0.0;
        ob->margin = 0.0;
-
+       
        /* NT fluid sim defaults */
        ob->fluidsimFlag = 0;
        ob->fluidsimSettings = NULL;
        /* NT fluid sim defaults */
        ob->fluidsimFlag = 0;
        ob->fluidsimSettings = NULL;
@@ -1045,6 +1066,17 @@ SoftBody *copy_softbody(SoftBody *sb)
        return sbn;
 }
 
        return sbn;
 }
 
+BulletSoftBody *copy_bulletsoftbody(BulletSoftBody *bsb)
+{
+       BulletSoftBody *bsbn;
+
+       if (bsb == NULL)
+               return NULL;
+       bsbn = MEM_dupallocN(bsb);
+       /* no pointer in this structure yet */
+       return bsbn;
+}
+
 ParticleSystem *copy_particlesystem(ParticleSystem *psys)
 {
        ParticleSystem *psysn;
 ParticleSystem *copy_particlesystem(ParticleSystem *psys)
 {
        ParticleSystem *psysn;
@@ -1131,7 +1163,10 @@ static void copy_object_pose(Object *obn, Object *ob)
                        ListBase targets = {NULL, NULL};
                        bConstraintTarget *ct;
                        
                        ListBase targets = {NULL, NULL};
                        bConstraintTarget *ct;
                        
-                       if(con->ipo) {
+                       /* note that we can't change lib linked ipo blocks. for making
+                        * proxies this still works correct however because the object
+                        * is changed to object->proxy_from when evaluating the driver. */
+                       if(con->ipo && !con->ipo->id.lib) {
                                IpoCurve *icu;
                                for(icu= con->ipo->curve.first; icu; icu= icu->next) {
                                        if(icu->driver && icu->driver->ob==ob)
                                IpoCurve *icu;
                                for(icu= con->ipo->curve.first; icu; icu= icu->next) {
                                        if(icu->driver && icu->driver->ob==ob)
@@ -1177,10 +1212,12 @@ Object *copy_object(Object *ob)
                modifier_copyData(md, nmd);
                BLI_addtail(&obn->modifiers, nmd);
        }
                modifier_copyData(md, nmd);
                BLI_addtail(&obn->modifiers, nmd);
        }
-       
+#ifndef DISABLE_PYTHON 
        BPY_copy_scriptlink(&ob->scriptlink);
        BPY_copy_scriptlink(&ob->scriptlink);
-       
+#endif
+       obn->prop.first = obn->prop.last = NULL;
        copy_properties(&obn->prop, &ob->prop);
        copy_properties(&obn->prop, &ob->prop);
+       
        copy_sensors(&obn->sensors, &ob->sensors);
        copy_controllers(&obn->controllers, &ob->controllers);
        copy_actuators(&obn->actuators, &ob->actuators);
        copy_sensors(&obn->sensors, &ob->sensors);
        copy_controllers(&obn->controllers, &ob->controllers);
        copy_actuators(&obn->actuators, &ob->actuators);
@@ -1213,15 +1250,7 @@ Object *copy_object(Object *ob)
                        id_us_plus(&(obn->pd->tex->id));
        }
        obn->soft= copy_softbody(ob->soft);
                        id_us_plus(&(obn->pd->tex->id));
        }
        obn->soft= copy_softbody(ob->soft);
-
-       /* NT copy fluid sim setting memory */
-       if(obn->fluidsimSettings) {
-               obn->fluidsimSettings = fluidsimSettingsCopy(ob->fluidsimSettings);
-               /* copying might fail... */
-               if(obn->fluidsimSettings) {
-                       obn->fluidsimSettings->orgMesh = (Mesh *)obn->data;
-               }
-       }
+       obn->bsoft = copy_bulletsoftbody(ob->bsoft);
 
        copy_object_particlesystems(obn, ob);
        
 
        copy_object_particlesystems(obn, ob);
        
@@ -1461,22 +1490,42 @@ float bsystem_time(Object *ob, float cfra, float ofs)
        return cfra;
 }
 
        return cfra;
 }
 
-void object_to_mat3(Object *ob, float mat[][3])        /* no parent */
+void object_scale_to_mat3(Object *ob, float mat[][3])
 {
 {
-       float smat[3][3], vec[3];
-       float rmat[3][3];
-       /*float q1[4];*/
-       
-       /* size */
+       float vec[3];
        if(ob->ipo) {
                vec[0]= ob->size[0]+ob->dsize[0];
                vec[1]= ob->size[1]+ob->dsize[1];
                vec[2]= ob->size[2]+ob->dsize[2];
        if(ob->ipo) {
                vec[0]= ob->size[0]+ob->dsize[0];
                vec[1]= ob->size[1]+ob->dsize[1];
                vec[2]= ob->size[2]+ob->dsize[2];
-               SizeToMat3(vec, smat);
+               SizeToMat3(vec, mat);
        }
        else {
        }
        else {
-               SizeToMat3(ob->size, smat);
+               SizeToMat3(ob->size, mat);
        }
        }
+}
+
+void object_rot_to_mat3(Object *ob, float mat[][3])
+{
+       float vec[3];
+       if(ob->ipo) {
+               vec[0]= ob->rot[0]+ob->drot[0];
+               vec[1]= ob->rot[1]+ob->drot[1];
+               vec[2]= ob->rot[2]+ob->drot[2];
+               EulToMat3(vec, mat);
+       }
+       else {
+               EulToMat3(ob->rot, mat);
+       }
+}
+
+void object_to_mat3(Object *ob, float mat[][3])        /* no parent */
+{
+       float smat[3][3];
+       float rmat[3][3];
+       /*float q1[4];*/
+       
+       /* size */
+       object_scale_to_mat3(ob, smat);
 
        /* rot */
        /* Quats arnt used yet */
 
        /* rot */
        /* Quats arnt used yet */
@@ -1490,15 +1539,7 @@ void object_to_mat3(Object *ob, float mat[][3])  /* no parent */
                }
        }
        else {*/
                }
        }
        else {*/
-               if(ob->ipo) {
-                       vec[0]= ob->rot[0]+ob->drot[0];
-                       vec[1]= ob->rot[1]+ob->drot[1];
-                       vec[2]= ob->rot[2]+ob->drot[2];
-                       EulToMat3(vec, rmat);
-               }
-               else {
-                       EulToMat3(ob->rot, rmat);
-               }
+               object_rot_to_mat3(ob, rmat);
        /*}*/
        Mat3MulMat3(mat, rmat, smat);
 }
        /*}*/
        Mat3MulMat3(mat, rmat, smat);
 }
@@ -1887,10 +1928,11 @@ void where_is_object_time(Object *ob, float ctime)
                
                constraints_clear_evalob(cob);
        }
                
                constraints_clear_evalob(cob);
        }
-       
+#ifndef DISABLE_PYTHON
        if(ob->scriptlink.totscript && !during_script()) {
                if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript((ID *)ob, SCRIPT_REDRAW);
        }
        if(ob->scriptlink.totscript && !during_script()) {
                if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript((ID *)ob, SCRIPT_REDRAW);
        }
+#endif
        
        /* set negative scale flag in object */
        Crossf(vec, ob->obmat[0], ob->obmat[1]);
        
        /* set negative scale flag in object */
        Crossf(vec, ob->obmat[0], ob->obmat[1]);
@@ -2257,7 +2299,9 @@ void object_handle_update(Object *ob)
                        }
                        else
                                where_is_object(ob);
                        }
                        else
                                where_is_object(ob);
+#ifndef DISABLE_PYTHON
                        if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript((ID *)ob, SCRIPT_OBJECTUPDATE);
                        if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript((ID *)ob, SCRIPT_OBJECTUPDATE);
+#endif
                }
                
                if(ob->recalc & OB_RECALC_DATA) {
                }
                
                if(ob->recalc & OB_RECALC_DATA) {
@@ -2333,7 +2377,9 @@ void object_handle_update(Object *ob)
                                                psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
                                }
                        }
                                                psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
                                }
                        }
+#ifndef DISABLE_PYTHON
                        if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript((ID *)ob, SCRIPT_OBDATAUPDATE);
                        if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript((ID *)ob, SCRIPT_OBDATAUPDATE);
+#endif
                }
 
                /* the no-group proxy case, we call update */
                }
 
                /* the no-group proxy case, we call update */