Merging fluidcontrol to trunk from rev16649 fluidcontrol branch. Code provided by...
[blender-staging.git] / source / blender / blenkernel / intern / object.c
index a2a7894e3ce024af8f219327ce5abcb4bcd641af..5d352c1e11db51f4aeb7a4cb61ab3383c838ee5c 100644 (file)
 
 #include "BPY_extern.h"
 
+#include "GPU_material.h"
+
 #include "blendef.h"
 
 /* Local function protos */
@@ -267,7 +269,7 @@ void free_object(Object *ob)
                MEM_freeN(ob->pd);
        }
        if(ob->soft) sbFree(ob->soft);
-       if(ob->fluidsimSettings) fluidsimSettingsFree(ob->fluidsimSettings);
+       if(ob->gpulamp.first) GPU_lamp_free(ob);
 }
 
 static void unlink_object__unlinkModifierLinks(void *userData, Object *ob, Object **obpoin)
@@ -694,9 +696,11 @@ float dof_camera(Object *ob)
        if (cam->dof_ob) {      
                /* too simple, better to return the distance on the view axis only
                 * return VecLenf(ob->obmat[3], cam->dof_ob->obmat[3]); */
+               float mat[4][4], obmat[4][4];
                
-               float mat[4][4];
-               Mat4Invert(ob->imat, ob->obmat);
+               Mat4CpyMat4(obmat, ob->obmat);
+               Mat4Ortho(obmat);
+               Mat4Invert(ob->imat, obmat);
                Mat4MulMat4(mat, cam->dof_ob->obmat, ob->imat);
                return fabs(mat[3][2]);
        }
@@ -732,6 +736,20 @@ void *add_lamp(char *name)
        la->preview=NULL;
        la->falloff_type = LA_FALLOFF_INVLINEAR;
        la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
+       la->sun_effect_type = 0;
+       la->horizon_brightness = 1.0;
+       la->spread = 1.0;
+       la->sun_brightness = 1.0;
+       la->sun_size = 1.0;
+       la->backscattered_light = 1.0;
+       la->atm_turbidity = 2.0;
+       la->atm_inscattering_factor = 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;
+
        curvemapping_initialize(la->curfalloff);
        return la;
 }
@@ -907,7 +925,7 @@ Object *add_only_object(int type, char *name)
        QuatOne(ob->dquat);
 #endif 
 
-       ob->col[0]= ob->col[1]= ob->col[2]= 0.0;
+       ob->col[0]= ob->col[1]= ob->col[2]= 1.0;
        ob->col[3]= 1.0;
 
        ob->loc[0]= ob->loc[1]= ob->loc[2]= 0.0;
@@ -944,7 +962,8 @@ Object *add_only_object(int type, char *name)
        ob->anisotropicFriction[0] = 1.0f;
        ob->anisotropicFriction[1] = 1.0f;
        ob->anisotropicFriction[2] = 1.0f;
-       ob->gameflag= OB_PROP;
+       ob->gameflag= OB_PROP|OB_COLLISION;
+       ob->margin = 0.0;
 
        /* NT fluid sim defaults */
        ob->fluidsimFlag = 0;
@@ -1056,6 +1075,7 @@ ParticleSystem *copy_particlesystem(ParticleSystem *psys)
        psysn->effectors.first= psysn->effectors.last= 0;
        
        psysn->pathcachebufs.first = psysn->pathcachebufs.last = NULL;
+       psysn->childcachebufs.first = psysn->childcachebufs.last = NULL;
        psysn->reactevents.first = psysn->reactevents.last = NULL;
        psysn->renderdata = NULL;
        
@@ -1099,6 +1119,8 @@ static void copy_object_pose(Object *obn, Object *ob)
 {
        bPoseChannel *chan;
        
+       /* note: need to clear obn->pose pointer first, so that copy_pose works (otherwise there's a crash) */
+       obn->pose= NULL;
        copy_pose(&obn->pose, ob->pose, 1);     /* 1 = copy constraints */
 
        for (chan = obn->pose->chanbase.first; chan; chan=chan->next){
@@ -1194,15 +1216,6 @@ Object *copy_object(Object *ob)
        }
        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;
-               }
-       }
-
        copy_object_particlesystems(obn, ob);
        
        obn->derivedDeform = NULL;
@@ -1212,6 +1225,7 @@ Object *copy_object(Object *ob)
        obn->vnode = NULL;
 #endif
 
+       obn->gpulamp.first = obn->gpulamp.last = NULL;
 
        return obn;
 }
@@ -1613,7 +1627,7 @@ static void give_parvert(Object *par, int nr, float *vec)
                        
                        for(eve= em->verts.first; eve; eve= eve->next) {
                                if(eve->keyindex==nr) {
-                                       memcpy(vec, eve->co, 12);
+                                       memcpy(vec, eve->co, sizeof(float)*3);
                                        break;
                                }
                        }
@@ -1651,18 +1665,20 @@ static void give_parvert(Object *par, int nr, float *vec)
                Curve *cu;
                BPoint *bp;
                BezTriple *bezt;
+               int found= 0;
                
                cu= par->data;
                nu= cu->nurb.first;
                if(par==G.obedit) nu= editNurb.first;
                
                count= 0;
-               while(nu) {
+               while(nu && !found) {
                        if((nu->type & 7)==CU_BEZIER) {
                                bezt= nu->bezt;
                                a= nu->pntsu;
                                while(a--) {
                                        if(count==nr) {
+                                               found= 1;
                                                VECCOPY(vec, bezt->vec[1]);
                                                break;
                                        }
@@ -1675,7 +1691,8 @@ static void give_parvert(Object *par, int nr, float *vec)
                                a= nu->pntsu*nu->pntsv;
                                while(a--) {
                                        if(count==nr) {
-                                               memcpy(vec, bp->vec, 12);
+                                               found= 1;
+                                               memcpy(vec, bp->vec, sizeof(float)*3);
                                                break;
                                        }
                                        count++;
@@ -2376,3 +2393,31 @@ int give_obdata_texspace(Object *ob, int **texflag, float **loc, float **size, f
        }
        return 1;
 }
+
+/*
+ * Test a bounding box for ray intersection
+ * assumes the ray is already local to the boundbox space
+ */
+int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3])
+{
+       static int triangle_indexes[12][3] = {{0, 1, 2}, {0, 2, 3},
+                                                                                 {3, 2, 6}, {3, 6, 7},
+                                                                                 {1, 2, 6}, {1, 6, 5}, 
+                                                                                 {5, 6, 7}, {4, 5, 7},
+                                                                                 {0, 3, 7}, {0, 4, 7},
+                                                                                 {0, 1, 5}, {0, 4, 5}};
+       int result = 0;
+       int i;
+       
+       for (i = 0; i < 12 && result == 0; i++)
+       {
+               float lambda;
+               int v1, v2, v3;
+               v1 = triangle_indexes[i][0];
+               v2 = triangle_indexes[i][1];
+               v3 = triangle_indexes[i][2];
+               result = RayIntersectsTriangle(ray_start, ray_normal, bb->vec[v1], bb->vec[v2], bb->vec[v3], &lambda, NULL);
+       }
+       
+       return result;
+}