diff options
author | Miika Hamalainen <blender@miikah.org> | 2011-11-05 12:04:49 +0400 |
---|---|---|
committer | Miika Hamalainen <blender@miikah.org> | 2011-11-05 12:04:49 +0400 |
commit | 2ed6f077b3952123d56916980d18a379ecb3e5ac (patch) | |
tree | 1aa273e5566c95214739fb224d4c6cf115417882 /source/blender/blenkernel/intern/object.c | |
parent | b9c83456b27da57a14bcf8d274b460e670d49990 (diff) | |
parent | 62f22185546e80b661424b45c88006f8b592d8b1 (diff) |
Merge with trunk r41545
Diffstat (limited to 'source/blender/blenkernel/intern/object.c')
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 134 |
1 files changed, 98 insertions, 36 deletions
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 0d0552cf3b3..b09d1ea98aa 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -86,6 +86,7 @@ #include "BKE_mesh.h" #include "BKE_mball.h" #include "BKE_modifier.h" +#include "BKE_node.h" #include "BKE_object.h" #include "BKE_paint.h" #include "BKE_particle.h" @@ -302,8 +303,6 @@ void free_object(Object *ob) ob->matbits= NULL; if(ob->bb) MEM_freeN(ob->bb); ob->bb= NULL; - if(ob->path) free_path(ob->path); - ob->path= NULL; if(ob->adt) BKE_free_animdata((ID *)ob); if(ob->poselib) ob->poselib->id.us--; if(ob->gpd) ((ID *)ob->gpd)->us--; @@ -723,6 +722,8 @@ void *add_camera(const char *name) cam= alloc_libblock(&G.main->camera, ID_CA, name); cam->lens= 35.0f; + cam->sensor_x= 32.0f; + cam->sensor_y= 18.0f; cam->clipsta= 0.1f; cam->clipend= 100.0f; cam->drawsize= 0.5f; @@ -772,13 +773,12 @@ void make_local_camera(Camera *cam) id_clear_lib_data(bmain, &cam->id); } else if(is_local && is_lib) { - char *bpath_user_data[2]= {bmain->name, cam->id.lib->filepath}; Camera *camn= copy_camera(cam); camn->id.us= 0; /* Remap paths of new ID using old library as base. */ - bpath_traverse_id(bmain, &camn->id, bpath_relocate_visitor, 0, bpath_user_data); + BKE_id_lib_local_paths(bmain, &camn->id); for(ob= bmain->object.first; ob; ob= ob->id.next) { if(ob->data == cam) { @@ -878,6 +878,9 @@ Lamp *copy_lamp(Lamp *la) } lan->curfalloff = curvemapping_copy(la->curfalloff); + + if(la->nodetree) + lan->nodetree= ntreeCopyTree(la->nodetree); if(la->preview) lan->preview = BKE_previewimg_copy(la->preview); @@ -904,6 +907,9 @@ Lamp *localize_lamp(Lamp *la) lan->curfalloff = curvemapping_copy(la->curfalloff); + if(la->nodetree) + lan->nodetree= ntreeLocalize(la->nodetree); + lan->preview= NULL; return lan; @@ -939,13 +945,11 @@ void make_local_lamp(Lamp *la) id_clear_lib_data(bmain, &la->id); } else if(is_local && is_lib) { - char *bpath_user_data[2]= {bmain->name, la->id.lib->filepath}; Lamp *lan= copy_lamp(la); lan->id.us= 0; - /* Remap paths of new ID using old library as base. */ - bpath_traverse_id(bmain, &lan->id, bpath_relocate_visitor, 0, bpath_user_data); + BKE_id_lib_local_paths(bmain, &lan->id); ob= bmain->object.first; while(ob) { @@ -981,6 +985,12 @@ void free_lamp(Lamp *la) BKE_free_animdata((ID *)la); curvemapping_free(la->curfalloff); + + /* is no lib link block, but lamp extension */ + if(la->nodetree) { + ntreeFreeTree(la->nodetree); + MEM_freeN(la->nodetree); + } BKE_previewimg_free(&la->preview); BKE_icon_delete(&la->id); @@ -1095,7 +1105,6 @@ Object *add_only_object(int type, const char *name) ob->obstacleRad = 1.; /* NT fluid sim defaults */ - ob->fluidsimFlag = 0; ob->fluidsimSettings = NULL; ob->pc_ids.first = ob->pc_ids.last = NULL; @@ -1365,7 +1374,6 @@ Object *copy_object(Object *ob) } if(ob->bb) obn->bb= MEM_dupallocN(ob->bb); - obn->path= NULL; obn->flag &= ~OB_FROMGROUP; obn->modifiers.first = obn->modifiers.last= NULL; @@ -1486,13 +1494,12 @@ void make_local_object(Object *ob) extern_local_object(ob); } else if(is_local && is_lib) { - char *bpath_user_data[2]= {bmain->name, ob->id.lib->filepath}; Object *obn= copy_object(ob); obn->id.us= 0; /* Remap paths of new ID using old library as base. */ - bpath_traverse_id(bmain, &obn->id, bpath_relocate_visitor, 0, bpath_user_data); + BKE_id_lib_local_paths(bmain, &obn->id); sce= bmain->scene.first; while(sce) { @@ -2945,27 +2952,23 @@ void object_camera_mode(RenderData *rd, Object *camera) } } -/* 'lens' may be set for envmap only */ -void object_camera_matrix( - RenderData *rd, Object *camera, int winx, int winy, short field_second, - float winmat[][4], rctf *viewplane, float *clipsta, float *clipend, float *lens, float *ycor, - float *viewdx, float *viewdy -) { - Camera *cam=NULL; - float pixsize; - float shiftx=0.0, shifty=0.0, winside, viewfac; - short is_ortho= FALSE; +void object_camera_intrinsics(Object *camera, Camera **cam_r, short *is_ortho, float *shiftx, float *shifty, + float *clipsta, float *clipend, float *lens, float *sensor_x, float *sensor_y, short *sensor_fit) +{ + Camera *cam= NULL; - /* question mark */ - (*ycor)= rd->yasp / rd->xasp; - if(rd->mode & R_FIELDS) - (*ycor) *= 2.0f; + (*shiftx)= 0.0f; + (*shifty)= 0.0f; + + (*sensor_x)= DEFAULT_SENSOR_WIDTH; + (*sensor_y)= DEFAULT_SENSOR_HEIGHT; + (*sensor_fit)= CAMERA_SENSOR_FIT_AUTO; if(camera->type==OB_CAMERA) { cam= camera->data; if(cam->type == CAM_ORTHO) { - is_ortho= TRUE; + *is_ortho= TRUE; } /* solve this too... all time depending stuff is in convertblender.c? @@ -2978,11 +2981,14 @@ void object_camera_matrix( execute_ipo(&cam->id, cam->ipo); } #endif // XXX old animation system - shiftx=cam->shiftx; - shifty=cam->shifty; + (*shiftx)=cam->shiftx; + (*shifty)=cam->shifty; (*lens)= cam->lens; + (*sensor_x)= cam->sensor_x; + (*sensor_y)= cam->sensor_y; (*clipsta)= cam->clipsta; (*clipend)= cam->clipend; + (*sensor_fit)= cam->sensor_fit; } else if(camera->type==OB_LAMP) { Lamp *la= camera->data; @@ -2996,7 +3002,7 @@ void object_camera_matrix( (*clipend)= la->clipend; } else { /* envmap exception... */; - if((*lens)==0.0f) + if((*lens)==0.0f) /* is this needed anymore? */ (*lens)= 16.0f; if((*clipsta)==0.0f || (*clipend)==0.0f) { @@ -3005,25 +3011,69 @@ void object_camera_matrix( } } + (*cam_r)= cam; +} + +/* 'lens' may be set for envmap only */ +void object_camera_matrix( + RenderData *rd, Object *camera, int winx, int winy, short field_second, + float winmat[][4], rctf *viewplane, float *clipsta, float *clipend, float *lens, + float *sensor_x, float *sensor_y, short *sensor_fit, float *ycor, + float *viewdx, float *viewdy) +{ + Camera *cam=NULL; + float pixsize; + float shiftx=0.0, shifty=0.0, winside, viewfac; + short is_ortho= FALSE; + + /* question mark */ + (*ycor)= rd->yasp / rd->xasp; + if(rd->mode & R_FIELDS) + (*ycor) *= 2.0f; + + object_camera_intrinsics(camera, &cam, &is_ortho, &shiftx, &shifty, clipsta, clipend, lens, sensor_x, sensor_y, sensor_fit); + /* ortho only with camera available */ if(cam && is_ortho) { - if(rd->xasp*winx >= rd->yasp*winy) { + if((*sensor_fit)==CAMERA_SENSOR_FIT_AUTO) { + if(rd->xasp*winx >= rd->yasp*winy) viewfac= winx; + else viewfac= (*ycor) * winy; + } + else if((*sensor_fit)==CAMERA_SENSOR_FIT_HOR) { viewfac= winx; } - else { + else { /* if((*sensor_fit)==CAMERA_SENSOR_FIT_VERT) { */ viewfac= (*ycor) * winy; } + /* ortho_scale == 1.0 means exact 1 to 1 mapping */ pixsize= cam->ortho_scale/viewfac; } else { - if(rd->xasp*winx >= rd->yasp*winy) viewfac= ((*lens) * winx)/32.0f; - else viewfac= (*ycor) * ((*lens) * winy)/32.0f; + if((*sensor_fit)==CAMERA_SENSOR_FIT_AUTO) { + if(rd->xasp*winx >= rd->yasp*winy) viewfac= ((*lens) * winx) / (*sensor_x); + else viewfac= (*ycor) * ((*lens) * winy) / (*sensor_x); + } + else if((*sensor_fit)==CAMERA_SENSOR_FIT_HOR) { + viewfac= ((*lens) * winx) / (*sensor_x); + } + else { /* if((*sensor_fit)==CAMERA_SENSOR_FIT_VERT) { */ + viewfac= ((*lens) * winy) / (*sensor_y); + } + pixsize= (*clipsta) / viewfac; } /* viewplane fully centered, zbuffer fills in jittered between -.5 and +.5 */ winside= MAX2(winx, winy); + + if(cam) { + if(cam->sensor_fit==CAMERA_SENSOR_FIT_HOR) + winside= winx; + else if(cam->sensor_fit==CAMERA_SENSOR_FIT_VERT) + winside= winy; + } + viewplane->xmin= -0.5f*(float)winx + shiftx*winside; viewplane->ymin= -0.5f*(*ycor)*(float)winy + shifty*winside; viewplane->xmax= 0.5f*(float)winx + shiftx*winside; @@ -3067,7 +3117,17 @@ void camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, const sh float aspx= (float) scene->r.xsch*scene->r.xasp; float aspy= (float) scene->r.ysch*scene->r.yasp; - if(aspx < aspy) { + if(camera->sensor_fit==CAMERA_SENSOR_FIT_AUTO) { + if(aspx < aspy) { + r_asp[0]= aspx / aspy; + r_asp[1]= 1.0; + } + else { + r_asp[0]= 1.0; + r_asp[1]= aspy / aspx; + } + } + else if(camera->sensor_fit==CAMERA_SENSOR_FIT_AUTO) { r_asp[0]= aspx / aspy; r_asp[1]= 1.0; } @@ -3093,16 +3153,18 @@ void camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, const sh else { /* that way it's always visible - clipsta+0.1 */ float fac; + float half_sensor= 0.5f*((camera->sensor_fit==CAMERA_SENSOR_FIT_VERT) ? (camera->sensor_y) : (camera->sensor_x)); + *r_drawsize= drawsize / ((scale[0] + scale[1] + scale[2]) / 3.0f); if(do_clip) { /* fixed depth, variable size (avoids exceeding clipping range) */ depth = -(camera->clipsta + 0.1f); - fac = depth / (camera->lens/-16.0f * scale[2]); + fac = depth / (camera->lens/(-half_sensor) * scale[2]); } else { /* fixed size, variable depth (stays a reasonable size in the 3D view) */ - depth= *r_drawsize * camera->lens/-16.0f * scale[2]; + depth= *r_drawsize * camera->lens/(-half_sensor) * scale[2]; fac= *r_drawsize; } |