From 33f880e8666e9bb0ed954fccb82bc23255a97868 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Thu, 25 Mar 2010 06:27:25 +0000 Subject: Restored Fluid Sim baking This commit restores fluid sim baking functionality in 2.5, it's been on the todo for a while, and was previously almost completely non-functional. The old code was quite complicated and specific to the 2.4 animation system, so I've pretty much rewritten most of it. This includes: * Animated variables work again - just key them in the UI. Non-animateable values should be already set non-animateable in RNA, hopefully I got them all. Available are: Domain Gravity / Domain Viscosity / Object loc/rot/scale / Object initial velocity / Deforming meshes / Fluid control Attract strength / Fluid control Attract radius / Fluid control Velocity strength / Fluid control Velocity radius / Object Active status (checkbox next to fluid type) The Domain time scale is still not yet implemented. * Fluid sim now use global scene units data by default - when enabled, the scene's global gravity value is used and when units are set (metric/imperial) the simulation real world size is taken from the object's actual measurements. * The baking process is now done in the background, using the nifty threaded Jobs system. It's non-blocking and your domain object will show the simulated fluid as it becomes available for that frame. A nice extra thing for the future would be to improve the visualisation of the object's state while baking, and also the jobs system/ui could do with some touchups - currently it has to share a bit from the 'render' job, and appears as 'Render' in the header. Progress bars for jobs in the header would be great too. --- source/blender/blenkernel/BKE_object.h | 2 ++ source/blender/blenkernel/intern/fluidsim.c | 2 +- source/blender/blenkernel/intern/object.c | 38 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 1362a191919..84995b60f4b 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -111,6 +111,8 @@ void where_is_object_simul(struct Scene *scene, struct Object *ob); struct BoundBox *unit_boundbox(void); void boundbox_set_from_min_max(struct BoundBox *bb, float min[3], float max[3]); struct BoundBox *object_get_boundbox(struct Object *ob); +void object_get_dimensions(struct Object *ob, float *value); +void object_set_dimensions(struct Object *ob, const float *value); void object_boundbox_flag(struct Object *ob, int flag, int set); void minmax_object(struct Object *ob, float *min, float *max); int minmax_object_duplis(struct Scene *scene, struct Object *ob, float *min, float *max); diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c index fe0f52e9b00..118a44507c9 100644 --- a/source/blender/blenkernel/intern/fluidsim.c +++ b/source/blender/blenkernel/intern/fluidsim.c @@ -148,7 +148,7 @@ void fluidsim_init(FluidsimModifierData *fluidmd) fss->lastgoodframe = -1; - fss->flag = 0; + fss->flag |= OB_FLUIDSIM_ACTIVE; } #endif diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 64abffa5119..e4350cfde7f 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2305,6 +2305,44 @@ void object_boundbox_flag(Object *ob, int flag, int set) } } +void object_get_dimensions(Object *ob, float *value) +{ + BoundBox *bb = NULL; + + bb= object_get_boundbox(ob); + if (bb) { + float scale[3]; + + mat4_to_size( scale,ob->obmat); + + value[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]); + value[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]); + value[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]); + } else { + value[0] = value[1] = value[2] = 0.f; + } +} + +void object_set_dimensions(Object *ob, const float *value) +{ + BoundBox *bb = NULL; + + bb= object_get_boundbox(ob); + if (bb) { + float scale[3], len[3]; + + mat4_to_size( scale,ob->obmat); + + len[0] = bb->vec[4][0] - bb->vec[0][0]; + len[1] = bb->vec[2][1] - bb->vec[0][1]; + len[2] = bb->vec[1][2] - bb->vec[0][2]; + + if (len[0] > 0.f) ob->size[0] = value[0] / len[0]; + if (len[1] > 0.f) ob->size[1] = value[1] / len[1]; + if (len[2] > 0.f) ob->size[2] = value[2] / len[2]; + } +} + void minmax_object(Object *ob, float *min, float *max) { BoundBox bb; -- cgit v1.2.3