diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-20 20:05:51 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-20 20:05:51 +0400 |
commit | 8eb41f0fdb77062d5828dd2c3e18ffeab5fd428c (patch) | |
tree | 1b81bf423db957bf39dc01521533f8a0872842d0 /source/blender/blenkernel | |
parent | 3c8d86e117b54914524cbc49a8678ecaad8671cf (diff) | |
parent | f1eb66aa68105ac27f371f4f708d8abf3b7da38b (diff) |
svn merge ^/trunk/blender -r41998:42009
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_modifier.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_ocean.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/camera.c | 72 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/dynamicpaint.c | 32 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 38 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/ocean.c | 25 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 7 |
9 files changed, 122 insertions, 69 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index adb34f4c501..a3e0b5b6d5a 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -52,7 +52,7 @@ void BKE_stamp_buf(struct Scene *scene, struct Object *camera, unsigned char *re int BKE_alphatest_ibuf(struct ImBuf *ibuf); int BKE_write_ibuf_stamp(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality); int BKE_write_ibuf(struct ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality); -void BKE_makepicstring(char *string, const char *base, int frame, int imtype, const short use_ext, const short use_frames); +void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, int imtype, const short use_ext, const short use_frames); int BKE_add_image_extension(char *string, int imtype); int BKE_ftype_to_imtype(int ftype); int BKE_imtype_to_ftype(int imtype); diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index db57f2e30fa..3063d9bc40a 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -365,5 +365,8 @@ void test_object_modifiers(struct Object *ob); /* here for do_versions */ void modifier_mdef_compact_influences(struct ModifierData *md); +void modifier_path_init(char *path, int path_maxlen, const char *name); +const char *modifier_path_relbase(struct Object *ob); + #endif diff --git a/source/blender/blenkernel/BKE_ocean.h b/source/blender/blenkernel/BKE_ocean.h index c1f228fe186..c8ce3f8ce63 100644 --- a/source/blender/blenkernel/BKE_ocean.h +++ b/source/blender/blenkernel/BKE_ocean.h @@ -48,7 +48,8 @@ typedef struct OceanCache { struct ImBuf **ibufs_foam; struct ImBuf **ibufs_norm; - char *bakepath; + const char *bakepath; + const char *relbase; /* precalculated for time range */ float *time; @@ -92,8 +93,9 @@ void BKE_ocean_eval_ij(struct Ocean * oc, struct OceanResult *ocr, int i, int j) /* ocean cache handling */ -struct OceanCache *BKE_init_ocean_cache(char *bakepath, int start, int end, float wave_scale, - float chop_amount, float foam_coverage, float foam_fade, int resolution); +struct OceanCache *BKE_init_ocean_cache(const char *bakepath, const char *relbase, + int start, int end, float wave_scale, + float chop_amount, float foam_coverage, float foam_fade, int resolution); void BKE_simulate_ocean_cache(struct OceanCache *och, int frame); void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(void *, float progress, int *cancel), void *update_cb_data); diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index da7c0ab1774..08e8a80750e 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -456,7 +456,7 @@ static void camera_to_frame_view_cb(const float co[3], void *user_data) unsigned int i; for (i= 0; i < 4; i++) { - float nd= -dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]); + float nd= dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]); if (nd < data->dist_vals[i]) { data->dist_vals[i]= nd; } @@ -530,55 +530,49 @@ int camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object *cam mul_v3_v3fl(plane_tx[i], data_cb.normal_tx[i], data_cb.dist_vals[i]); } - if ( (isect_plane_plane_v3(plane_isect_1, plane_isect_1_no, - plane_tx[0], data_cb.normal_tx[0], - plane_tx[2], data_cb.normal_tx[2]) == 0) || - (isect_plane_plane_v3(plane_isect_2, plane_isect_2_no, - plane_tx[1], data_cb.normal_tx[1], - plane_tx[3], data_cb.normal_tx[3]) == 0)) + isect_plane_plane_v3(plane_isect_1, plane_isect_1_no, + plane_tx[0], data_cb.normal_tx[0], + plane_tx[2], data_cb.normal_tx[2]); + isect_plane_plane_v3(plane_isect_2, plane_isect_2_no, + plane_tx[1], data_cb.normal_tx[1], + plane_tx[3], data_cb.normal_tx[3]); + + add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no); + add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no); + + if (isect_line_line_v3(plane_isect_1, plane_isect_1_other, + plane_isect_2, plane_isect_2_other, + plane_isect_pt_1, plane_isect_pt_2) == 0) { - /* this is very unlikely */ return FALSE; } else { + float cam_plane_no[3]= {0.0f, 0.0f, -1.0f}; + float plane_isect_delta[3]; + float plane_isect_delta_len; - add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no); - add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no); - - if (isect_line_line_v3(plane_isect_1, plane_isect_1_other, - plane_isect_2, plane_isect_2_other, - plane_isect_pt_1, plane_isect_pt_2) == 0) - { - return FALSE; - } - else { - float cam_plane_no[3]= {0.0f, 0.0f, -1.0f}; - float plane_isect_delta[3]; - float plane_isect_delta_len; - - mul_m3_v3(rot_obmat, cam_plane_no); + mul_m3_v3(rot_obmat, cam_plane_no); - sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1); - plane_isect_delta_len= len_v3(plane_isect_delta); + sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1); + plane_isect_delta_len= len_v3(plane_isect_delta); - if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) { - copy_v3_v3(r_co, plane_isect_pt_1); + if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) { + copy_v3_v3(r_co, plane_isect_pt_1); - /* offset shift */ - normalize_v3(plane_isect_1_no); - madd_v3_v3fl(r_co, plane_isect_1_no, shift[1] * -plane_isect_delta_len); - } - else { - copy_v3_v3(r_co, plane_isect_pt_2); + /* offset shift */ + normalize_v3(plane_isect_1_no); + madd_v3_v3fl(r_co, plane_isect_1_no, shift[1] * -plane_isect_delta_len); + } + else { + copy_v3_v3(r_co, plane_isect_pt_2); - /* offset shift */ - normalize_v3(plane_isect_2_no); - madd_v3_v3fl(r_co, plane_isect_2_no, shift[0] * -plane_isect_delta_len); - } + /* offset shift */ + normalize_v3(plane_isect_2_no); + madd_v3_v3fl(r_co, plane_isect_2_no, shift[0] * -plane_isect_delta_len); + } - return TRUE; - } + return TRUE; } } } diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 11fe79daa51..aa2790fca2e 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -976,8 +976,8 @@ struct DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSett surface->wave_timescale = 1.0f; surface->wave_spring = 0.20f; - BLI_snprintf(surface->image_output_path, sizeof(surface->image_output_path), "%sdynamicpaint", U.textudir); - BLI_cleanup_dir(NULL, surface->image_output_path); + modifier_path_init(surface->image_output_path, sizeof(surface->image_output_path), "dynamicpaint"); + dynamicPaintSurface_setUniqueName(surface, "Surface"); surface->effector_weights = BKE_add_effector_weights(NULL); @@ -1475,11 +1475,12 @@ int dynamicPaint_resetSurface(DynamicPaintSurface *surface) } /* make sure allocated surface size matches current requirements */ -static void dynamicPaint_checkSurfaceData(DynamicPaintSurface *surface) +static int dynamicPaint_checkSurfaceData(DynamicPaintSurface *surface) { if (!surface->data || ((dynamicPaint_surfaceNumOfPoints(surface) != surface->data->total_points))) { - dynamicPaint_resetSurface(surface); + return dynamicPaint_resetSurface(surface); } + return 1; } @@ -1614,6 +1615,10 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* paint layer */ col = CustomData_get_layer_named(&result->faceData, CD_MCOL, surface->output_name); + /* if output layer is lost from a constructive modifier, re-add it */ + if (!col && dynamicPaint_outputLayerExists(surface, ob, 0)) + col = CustomData_add_layer_named(&result->faceData, CD_MCOL, CD_CALLOC, NULL, numOfFaces, surface->output_name); + /* apply color */ if (col) { #pragma omp parallel for schedule(static) for (i=0; i<numOfFaces; i++) { @@ -1634,6 +1639,10 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData /* wet layer */ col = CustomData_get_layer_named(&result->faceData, CD_MCOL, surface->output_name2); + /* if output layer is lost from a constructive modifier, re-add it */ + if (!col && dynamicPaint_outputLayerExists(surface, ob, 1)) + col = CustomData_add_layer_named(&result->faceData, CD_MCOL, CD_CALLOC, NULL, numOfFaces, surface->output_name2); + /* apply color */ if (col) { #pragma omp parallel for schedule(static) for (i=0; i<numOfFaces; i++) { @@ -1792,7 +1801,7 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene if (!(surface->flags & MOD_DPAINT_ACTIVE)) continue; /* make sure surface is valid */ - dynamicPaint_checkSurfaceData(surface); + if (!dynamicPaint_checkSurfaceData(surface)) continue; /* limit frame range */ CLAMP(current_frame, surface->start_frame, surface->end_frame); @@ -3396,7 +3405,8 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, velocity_val = len_v3(velocity); /* if brush has smudge enabled store brush velocity */ - if (brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && + brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { copy_v3_v3(&bData->brush_velocity[index*4], velocity); mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); bData->brush_velocity[index*4+3] = velocity_val; @@ -3690,7 +3700,8 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, velocity_val = len_v3(velocity); /* store brush velocity for smudge */ - if (brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && + brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { copy_v3_v3(&bData->brush_velocity[index*4], velocity); mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); bData->brush_velocity[index*4+3] = velocity_val; @@ -3788,7 +3799,8 @@ static int dynamicPaint_paintSinglePoint(DynamicPaintSurface *surface, float *po velocity_val = len_v3(velocity); /* store brush velocity for smudge */ - if (brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && + brush->flags & MOD_DPAINT_DO_SMUDGE && bData->brush_velocity) { copy_v3_v3(&bData->brush_velocity[index*4], velocity); mul_v3_fl(&bData->brush_velocity[index*4], 1.0f/velocity_val); bData->brush_velocity[index*4+3] = velocity_val; @@ -4802,7 +4814,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su BrushMaterials bMats = {0}; /* calculate brush speed vectors if required */ - if (brush->flags & MOD_DPAINT_DO_SMUDGE) { + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE) { bData->brush_velocity = MEM_callocN(sData->total_points*sizeof(float)*4, "Dynamic Paint brush velocity"); /* init adjacency data if not already */ if (!sData->adj_data) @@ -4852,7 +4864,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su /* process special brush effects, like smudge */ if (bData->brush_velocity) { - if (brush->flags & MOD_DPAINT_DO_SMUDGE) + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE) dynamicPaint_doSmudge(surface, brush, timescale); MEM_freeN(bData->brush_velocity); bData->brush_velocity = NULL; diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 08440849a4e..a61ae705020 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -1484,11 +1484,11 @@ int BKE_write_ibuf_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const } -void BKE_makepicstring(char *string, const char *base, int frame, int imtype, const short use_ext, const short use_frames) +void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, int imtype, const short use_ext, const short use_frames) { if (string==NULL) return; BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ - BLI_path_abs(string, G.main->name); + BLI_path_abs(string, relbase); if(use_frames) BLI_path_frame(string, frame, 4); diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index bbc1b596889..f09be8c34ad 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -60,6 +60,11 @@ #include "BKE_key.h" #include "BKE_multires.h" +/* may move these, only for modifier_path_relbase */ +#include "BKE_global.h" /* ugh, G.main->name only */ +#include "BKE_main.h" +/* end */ + #include "MOD_modifiertypes.h" ModifierTypeInfo *modifierType_getInfo(ModifierType type) @@ -573,3 +578,36 @@ void test_object_modifiers(Object *ob) } } } + +/* where should this go?, it doesnt fit well anywhere :S - campbell */ + +/* elubie: changed this to default to the same dir as the render output + * to prevent saving to C:\ on Windows */ + +/* campbell: logic behind this... + * + * - if the ID is from a library, return library path + * - else if the file has been saved return the blend file path. + * - else if the file isn't saved and the ID isnt from a library, return the temp dir. + */ +const char *modifier_path_relbase(Object *ob) +{ + if (G.relbase_valid || ob->id.lib) { + return ID_BLEND_PATH(G.main, &ob->id); + } + else { + /* last resort, better then using "" which resolves to the current + * working directory */ + return BLI_temporary_dir(); + } +} + +/* initializes the path with either */ +void modifier_path_init(char *path, int path_maxlen, const char *name) +{ + /* elubie: changed this to default to the same dir as the render output + * to prevent saving to C:\ on Windows */ + BLI_join_dirfile(path, path_maxlen, + G.relbase_valid ? "//" : BLI_temporary_dir(), + name); +} diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index df4cd94cf38..5cf0b8c2348 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -998,7 +998,7 @@ void BKE_free_ocean(struct Ocean *oc) #define CACHE_TYPE_FOAM 2 #define CACHE_TYPE_NORMAL 3 -static void cache_filename(char *string, const char *path, int frame, int type) +static void cache_filename(char *string, const char *path, const char *relbase, int frame, int type) { char cachepath[FILE_MAX]; const char *fname; @@ -1018,7 +1018,7 @@ static void cache_filename(char *string, const char *path, int frame, int type) BLI_join_dirfile(cachepath, sizeof(cachepath), path, fname); - BKE_makepicstring(string, cachepath, frame, R_OPENEXR, 1, TRUE); + BKE_makepicstring(string, cachepath, relbase, frame, R_OPENEXR, 1, TRUE); } void BKE_free_ocean_cache(struct OceanCache *och) @@ -1119,12 +1119,15 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, in } } -struct OceanCache *BKE_init_ocean_cache(char *bakepath, int start, int end, float wave_scale, - float chop_amount, float foam_coverage, float foam_fade, int resolution) +struct OceanCache *BKE_init_ocean_cache(const char *bakepath, const char *relbase, + int start, int end, float wave_scale, + float chop_amount, float foam_coverage, float foam_fade, int resolution) { OceanCache *och = MEM_callocN(sizeof(OceanCache), "ocean cache data"); och->bakepath = bakepath; + och->relbase = relbase; + och->start = start; och->end = end; och->duration = (end - start) + 1; @@ -1158,17 +1161,17 @@ void BKE_simulate_ocean_cache(struct OceanCache *och, int frame) if (och->ibufs_disp[f] != NULL ) return; - cache_filename(string, och->bakepath, frame, CACHE_TYPE_DISPLACE); + cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE); och->ibufs_disp[f] = IMB_loadiffname(string, 0); //if (och->ibufs_disp[f] == NULL) printf("error loading %s \n", string); //else printf("loaded cache %s \n", string); - cache_filename(string, och->bakepath, frame, CACHE_TYPE_FOAM); + cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_FOAM); och->ibufs_foam[f] = IMB_loadiffname(string, 0); //if (och->ibufs_foam[f] == NULL) printf("error loading %s \n", string); //else printf("loaded cache %s \n", string); - cache_filename(string, och->bakepath, frame, CACHE_TYPE_NORMAL); + cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_NORMAL); och->ibufs_norm[f] = IMB_loadiffname(string, 0); //if (och->ibufs_norm[f] == NULL) printf("error loading %s \n", string); //else printf("loaded cache %s \n", string); @@ -1288,18 +1291,18 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v } /* write the images */ - cache_filename(string, och->bakepath, f, CACHE_TYPE_DISPLACE); + cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_DISPLACE); if(0 == BKE_write_ibuf(ibuf_disp, string, R_OPENEXR, R_OPENEXR_HALF, 2)) // 2 == ZIP exr codec printf("Cannot save Displacement File Output to %s\n", string); if (o->_do_jacobian) { - cache_filename(string, och->bakepath, f, CACHE_TYPE_FOAM); + cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_FOAM); if(0 == BKE_write_ibuf(ibuf_foam, string, R_OPENEXR, R_OPENEXR_HALF, 2)) // 2 == ZIP exr codec printf("Cannot save Foam File Output to %s\n", string); } if (o->_do_normals) { - cache_filename(string, och->bakepath, f, CACHE_TYPE_NORMAL); + cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_NORMAL); if(0 == BKE_write_ibuf(ibuf_normal, string, R_OPENEXR, R_OPENEXR_HALF, 2)) // 2 == ZIP exr codec printf("Cannot save Normal File Output to %s\n", string); } @@ -1409,7 +1412,7 @@ struct OceanCache *BKE_init_ocean_cache(char *UNUSED(bakepath), int UNUSED(start return och; } -void BKE_simulate_ocean_cache(struct OceanCache *UNUSED(och), int UNUSED(frame)) +void BKE_simulate_ocean_cache(struct OceanCache *UNUSED(och), const char *UNUSED(relbase), int UNUSED(frame)) { } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 3f127c7656b..3c5674f0b0f 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -3936,9 +3936,10 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) // return; // ok, start loading - BLI_snprintf(filename, sizeof(filename), "%sfluidsurface_particles_####.gz", fss->surfdataPath); - - BLI_path_abs(filename, G.main->name); + BLI_join_dirfile(filename, sizeof(filename), fss->surfdataPath, OB_FLUIDSIM_SURF_PARTICLES_FNAME); + + BLI_path_abs(filename, modifier_path_relbase(sim->ob)); + BLI_path_frame(filename, curFrame, 0); // fixed #frame-no gzf = gzopen(filename, "rb"); |