This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/physics/physics_fluid.c

874 lines
26 KiB
C
Raw Normal View History

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) Blender Foundation
* All rights reserved.
*/
/** \file
* \ingroup edphys
2011-02-27 20:29:51 +00:00
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "MEM_guardedalloc.h"
/* types */
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.
2010-03-25 06:27:25 +00:00
#include "DNA_action_types.h"
#include "DNA_object_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_path_util.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_fluid.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "DEG_depsgraph.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "PIL_time.h"
2011-03-23 01:50:14 +00:00
#include "WM_api.h"
#include "WM_types.h"
#include "manta_fluid_API.h"
#include "physics_intern.h" // own include
#include "DNA_fluid_types.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
#define FLUID_JOB_BAKE_ALL "FLUID_OT_bake_all"
#define FLUID_JOB_BAKE_DATA "FLUID_OT_bake_data"
#define FLUID_JOB_BAKE_NOISE "FLUID_OT_bake_noise"
#define FLUID_JOB_BAKE_MESH "FLUID_OT_bake_mesh"
#define FLUID_JOB_BAKE_PARTICLES "FLUID_OT_bake_particles"
#define FLUID_JOB_BAKE_GUIDES "FLUID_OT_bake_guides"
#define FLUID_JOB_FREE_ALL "FLUID_OT_free_all"
#define FLUID_JOB_FREE_DATA "FLUID_OT_free_data"
#define FLUID_JOB_FREE_NOISE "FLUID_OT_free_noise"
#define FLUID_JOB_FREE_MESH "FLUID_OT_free_mesh"
#define FLUID_JOB_FREE_PARTICLES "FLUID_OT_free_particles"
#define FLUID_JOB_FREE_GUIDES "FLUID_OT_free_guides"
#define FLUID_JOB_BAKE_PAUSE "FLUID_OT_pause_bake"
typedef struct FluidJob {
/* from wmJob */
void *owner;
short *stop, *do_update;
float *progress;
const char *type;
const char *name;
Sorry, three commits in one, became difficult to untangle.. Editors Modules * render/ module added in editors, moved the preview render code there and also shading related operators. * physics/ module made more consistent with other modules. renaming files, making a single physics_ops.c for operators and keymaps. Also move all particle related operators here now. * space_buttons/ now should have only operators relevant to the buttons specificially. Updates & Notifiers * Material/Texture/World/Lamp can now be passed to DAG_id_flush_update, which will go back to a callback in editors. Eventually these should be in the depsgraph itself, but for now this gives a unified call for doing updates. * GLSL materials are now refreshed on changes. There's still various cases missing, * Preview icons now hook into this system, solving various update cases that were missed before. * Also fixes issue in my last commit, where some preview would not render, problem is avoided in the new system. Icon Rendering * On systems with support for non-power of two textures, an OpenGL texture is now used instead of glDrawPixels. This avoids problems with icons get clipped on region borders. On my Linux desktop, this gives an 1.1x speedup, and on my Mac laptop a 2.3x speedup overall in redrawing the full window, with the default setup. The glDrawPixels implementation on Mac seems to have a lot of overhread. * Preview icons are now drawn using proper premul alpha, and never faded so you can see them clearly. * Also tried to fix issue with texture node preview rendering, globals can't be used with threads reliably.
2009-09-29 19:12:12 +00:00
struct Main *bmain;
Scene *scene;
Depsgraph *depsgraph;
Object *ob;
FluidModifierData *fmd;
2018-04-01 07:24:45 +02:00
int success;
double start;
int *pause_frame;
} FluidJob;
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.
2010-03-25 06:27:25 +00:00
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_bake_all(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_BAKE_ALL));
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.
2010-03-25 06:27:25 +00:00
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_bake_data(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_BAKE_DATA));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_bake_noise(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_BAKE_NOISE));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_bake_mesh(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_BAKE_MESH));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_bake_particle(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_BAKE_PARTICLES));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_bake_guiding(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_BAKE_GUIDES));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_free_all(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_FREE_ALL));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_free_data(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_FREE_DATA));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_free_noise(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_FREE_NOISE));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_free_mesh(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_FREE_MESH));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_free_particles(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_FREE_PARTICLES));
}
2019-12-17 08:58:43 +11:00
static inline bool fluid_is_free_guiding(FluidJob *job)
{
return (STREQ(job->type, FLUID_JOB_FREE_GUIDES));
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.
2010-03-25 06:27:25 +00:00
}
static bool fluid_initjob(
bContext *C, FluidJob *job, wmOperator *op, char *error_msg, int error_size)
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.
2010-03-25 06:27:25 +00:00
{
FluidModifierData *fmd = NULL;
FluidDomainSettings *fds;
Object *ob = ED_object_active_context(C);
fmd = (FluidModifierData *)BKE_modifiers_findby_type(ob, eModifierType_Fluid);
if (!fmd) {
BLI_strncpy(error_msg, N_("Bake failed: no Fluid modifier found"), error_size);
return false;
}
fds = fmd->domain;
if (!fds) {
BLI_strncpy(error_msg, N_("Bake failed: invalid domain"), error_size);
return false;
}
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.
2010-03-25 06:27:25 +00:00
job->bmain = CTX_data_main(C);
job->scene = CTX_data_scene(C);
job->depsgraph = CTX_data_depsgraph_pointer(C);
job->ob = ob;
job->fmd = fmd;
job->type = op->type->idname;
job->name = op->type->name;
return true;
}
static bool fluid_validatepaths(FluidJob *job, ReportList *reports)
2011-12-30 07:55:15 +00:00
{
FluidDomainSettings *fds = job->fmd->domain;
char temp_dir[FILE_MAX];
temp_dir[0] = '\0';
bool is_relative = false;
const char *relbase = BKE_modifier_path_relbase(job->bmain, job->ob);
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.
2010-03-25 06:27:25 +00:00
/* We do not accept empty paths, they can end in random places silently, see T51176. */
if (fds->cache_directory[0] == '\0') {
char cache_name[64];
BKE_fluid_cache_new_name_for_current_session(sizeof(cache_name), cache_name);
BKE_modifier_path_init(fds->cache_directory, sizeof(fds->cache_directory), cache_name);
BKE_reportf(reports,
RPT_WARNING,
"Fluid: Empty cache path, reset to default '%s'",
fds->cache_directory);
}
BLI_strncpy(temp_dir, fds->cache_directory, FILE_MAXDIR);
is_relative = BLI_path_abs(temp_dir, relbase);
/* Ensure whole path exists */
const bool dir_exists = BLI_dir_create_recursive(temp_dir);
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.
2010-03-25 06:27:25 +00:00
/* We change path to some presumably valid default value, but do not allow bake process to
* continue, this gives user chance to set manually another path. */
if (!dir_exists) {
char cache_name[64];
BKE_fluid_cache_new_name_for_current_session(sizeof(cache_name), cache_name);
BKE_modifier_path_init(fds->cache_directory, sizeof(fds->cache_directory), cache_name);
BKE_reportf(reports,
RPT_ERROR,
"Fluid: Could not create cache directory '%s', reset to default '%s'",
temp_dir,
fds->cache_directory);
/* Ensure whole path exists and is writable. */
if (!BLI_dir_create_recursive(temp_dir)) {
BKE_reportf(reports,
RPT_ERROR,
"Fluid: Could not use default cache directory '%s', "
"please define a valid cache path manually",
temp_dir);
return false;
}
/* Copy final dir back into domain settings */
BLI_strncpy(fds->cache_directory, temp_dir, FILE_MAXDIR);
return false;
}
/* Change path back to is original state (ie relative or absolute). */
if (is_relative) {
BLI_path_rel(temp_dir, relbase);
}
/* Copy final dir back into domain settings */
BLI_strncpy(fds->cache_directory, temp_dir, FILE_MAXDIR);
return true;
}
static void fluid_bake_free(void *customdata)
{
FluidJob *job = customdata;
MEM_freeN(job);
}
static void fluid_bake_sequence(FluidJob *job)
{
FluidDomainSettings *fds = job->fmd->domain;
Scene *scene = job->scene;
int frame = 1, orig_frame;
int frames;
int *pause_frame = NULL;
bool is_first_frame;
frames = fds->cache_frame_end - fds->cache_frame_start + 1;
if (frames <= 0) {
BLI_strncpy(fds->error, N_("No frames to bake"), sizeof(fds->error));
return;
}
/* Show progress bar. */
2019-12-17 09:51:38 +11:00
if (job->do_update) {
*(job->do_update) = true;
2019-12-17 09:51:38 +11:00
}
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.
2010-03-25 06:27:25 +00:00
/* Get current pause frame (pointer) - depending on bake type. */
pause_frame = job->pause_frame;
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.
2010-03-25 06:27:25 +00:00
/* Set frame to start point (depending on current pause frame value). */
is_first_frame = ((*pause_frame) == 0);
frame = is_first_frame ? fds->cache_frame_start : (*pause_frame);
/* Save orig frame and update scene frame. */
orig_frame = CFRA;
CFRA = frame;
/* Loop through selected frames. */
for (; frame <= fds->cache_frame_end; frame++) {
const float progress = (frame - fds->cache_frame_start) / (float)frames;
/* Keep track of pause frame - needed to init future loop. */
(*pause_frame) = frame;
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.
2010-03-25 06:27:25 +00:00
/* If user requested stop, quit baking. */
if (G.is_break) {
job->success = 0;
return;
}
/* Update progress bar. */
2019-12-17 09:51:38 +11:00
if (job->do_update) {
*(job->do_update) = true;
2019-12-17 09:51:38 +11:00
}
if (job->progress) {
*(job->progress) = progress;
2019-12-17 09:51:38 +11:00
}
CFRA = frame;
/* Update animation system. */
ED_update_for_newframe(job->bmain, job->depsgraph);
/* If user requested stop, quit baking. */
if (G.is_break) {
job->success = 0;
return;
}
}
/* Restore frame position that we were on before bake. */
CFRA = orig_frame;
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.
2010-03-25 06:27:25 +00:00
}
static void fluid_bake_endjob(void *customdata)
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.
2010-03-25 06:27:25 +00:00
{
FluidJob *job = customdata;
FluidDomainSettings *fds = job->fmd->domain;
if (fluid_is_bake_noise(job) || fluid_is_bake_all(job)) {
fds->cache_flag &= ~FLUID_DOMAIN_BAKING_NOISE;
fds->cache_flag |= FLUID_DOMAIN_BAKED_NOISE;
fds->cache_flag &= ~FLUID_DOMAIN_OUTDATED_NOISE;
}
if (fluid_is_bake_mesh(job) || fluid_is_bake_all(job)) {
fds->cache_flag &= ~FLUID_DOMAIN_BAKING_MESH;
fds->cache_flag |= FLUID_DOMAIN_BAKED_MESH;
fds->cache_flag &= ~FLUID_DOMAIN_OUTDATED_MESH;
}
if (fluid_is_bake_particle(job) || fluid_is_bake_all(job)) {
fds->cache_flag &= ~FLUID_DOMAIN_BAKING_PARTICLES;
fds->cache_flag |= FLUID_DOMAIN_BAKED_PARTICLES;
fds->cache_flag &= ~FLUID_DOMAIN_OUTDATED_PARTICLES;
}
if (fluid_is_bake_guiding(job) || fluid_is_bake_all(job)) {
fds->cache_flag &= ~FLUID_DOMAIN_BAKING_GUIDE;
fds->cache_flag |= FLUID_DOMAIN_BAKED_GUIDE;
fds->cache_flag &= ~FLUID_DOMAIN_OUTDATED_GUIDE;
}
if (fluid_is_bake_data(job) || fluid_is_bake_all(job)) {
fds->cache_flag &= ~FLUID_DOMAIN_BAKING_DATA;
fds->cache_flag |= FLUID_DOMAIN_BAKED_DATA;
fds->cache_flag &= ~FLUID_DOMAIN_OUTDATED_DATA;
}
DEG_id_tag_update(&job->ob->id, ID_RECALC_GEOMETRY);
G.is_rendering = false;
BKE_spacedata_draw_locks(false);
WM_set_locked_interface(G_MAIN->wm.first, false);
/* Bake was successful:
* Report for ended bake and how long it took. */
if (job->success) {
/* Show bake info. */
2019-12-17 08:58:43 +11:00
WM_reportf(
RPT_INFO, "Fluid: %s complete! (%.2f)", job->name, PIL_check_seconds_timer() - job->start);
2019-04-22 09:19:45 +10:00
}
else {
if (fds->error[0] != '\0') {
WM_reportf(RPT_ERROR, "Fluid: %s failed: %s", job->name, fds->error);
}
else { /* User canceled the bake. */
WM_reportf(RPT_WARNING, "Fluid: %s canceled!", job->name);
}
}
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.
2010-03-25 06:27:25 +00:00
}
static void fluid_bake_startjob(void *customdata, short *stop, short *do_update, float *progress)
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.
2010-03-25 06:27:25 +00:00
{
FluidJob *job = customdata;
FluidDomainSettings *fds = job->fmd->domain;
char temp_dir[FILE_MAX];
const char *relbase = BKE_modifier_path_relbase_from_global(job->ob);
job->stop = stop;
job->do_update = do_update;
job->progress = progress;
job->start = PIL_check_seconds_timer();
job->success = 1;
G.is_break = false;
G.is_rendering = true;
BKE_spacedata_draw_locks(true);
if (fluid_is_bake_noise(job) || fluid_is_bake_all(job)) {
BLI_path_join(temp_dir, sizeof(temp_dir), fds->cache_directory, FLUID_DOMAIN_DIR_NOISE, NULL);
BLI_path_abs(temp_dir, relbase);
BLI_dir_create_recursive(temp_dir); /* Create 'noise' subdir if it does not exist already */
fds->cache_flag &= ~(FLUID_DOMAIN_BAKED_NOISE | FLUID_DOMAIN_OUTDATED_NOISE);
fds->cache_flag |= FLUID_DOMAIN_BAKING_NOISE;
job->pause_frame = &fds->cache_frame_pause_noise;
}
if (fluid_is_bake_mesh(job) || fluid_is_bake_all(job)) {
BLI_path_join(temp_dir, sizeof(temp_dir), fds->cache_directory, FLUID_DOMAIN_DIR_MESH, NULL);
BLI_path_abs(temp_dir, relbase);
BLI_dir_create_recursive(temp_dir); /* Create 'mesh' subdir if it does not exist already */
fds->cache_flag &= ~(FLUID_DOMAIN_BAKED_MESH | FLUID_DOMAIN_OUTDATED_MESH);
fds->cache_flag |= FLUID_DOMAIN_BAKING_MESH;
job->pause_frame = &fds->cache_frame_pause_mesh;
}
if (fluid_is_bake_particle(job) || fluid_is_bake_all(job)) {
BLI_path_join(
temp_dir, sizeof(temp_dir), fds->cache_directory, FLUID_DOMAIN_DIR_PARTICLES, NULL);
BLI_path_abs(temp_dir, relbase);
BLI_dir_create_recursive(
temp_dir); /* Create 'particles' subdir if it does not exist already */
fds->cache_flag &= ~(FLUID_DOMAIN_BAKED_PARTICLES | FLUID_DOMAIN_OUTDATED_PARTICLES);
fds->cache_flag |= FLUID_DOMAIN_BAKING_PARTICLES;
job->pause_frame = &fds->cache_frame_pause_particles;
}
if (fluid_is_bake_guiding(job) || fluid_is_bake_all(job)) {
BLI_path_join(temp_dir, sizeof(temp_dir), fds->cache_directory, FLUID_DOMAIN_DIR_GUIDE, NULL);
BLI_path_abs(temp_dir, relbase);
BLI_dir_create_recursive(temp_dir); /* Create 'guiding' subdir if it does not exist already */
fds->cache_flag &= ~(FLUID_DOMAIN_BAKED_GUIDE | FLUID_DOMAIN_OUTDATED_GUIDE);
fds->cache_flag |= FLUID_DOMAIN_BAKING_GUIDE;
job->pause_frame = &fds->cache_frame_pause_guide;
}
if (fluid_is_bake_data(job) || fluid_is_bake_all(job)) {
BLI_path_join(temp_dir, sizeof(temp_dir), fds->cache_directory, FLUID_DOMAIN_DIR_CONFIG, NULL);
BLI_path_abs(temp_dir, relbase);
BLI_dir_create_recursive(temp_dir); /* Create 'config' subdir if it does not exist already */
BLI_path_join(temp_dir, sizeof(temp_dir), fds->cache_directory, FLUID_DOMAIN_DIR_DATA, NULL);
BLI_path_abs(temp_dir, relbase);
BLI_dir_create_recursive(temp_dir); /* Create 'data' subdir if it does not exist already */
fds->cache_flag &= ~(FLUID_DOMAIN_BAKED_DATA | FLUID_DOMAIN_OUTDATED_DATA);
fds->cache_flag |= FLUID_DOMAIN_BAKING_DATA;
job->pause_frame = &fds->cache_frame_pause_data;
if (fds->flags & FLUID_DOMAIN_EXPORT_MANTA_SCRIPT) {
BLI_path_join(
temp_dir, sizeof(temp_dir), fds->cache_directory, FLUID_DOMAIN_DIR_SCRIPT, NULL);
BLI_path_abs(temp_dir, relbase);
BLI_dir_create_recursive(temp_dir); /* Create 'script' subdir if it does not exist already */
}
}
DEG_id_tag_update(&job->ob->id, ID_RECALC_GEOMETRY);
fluid_bake_sequence(job);
2019-12-17 09:51:38 +11:00
if (do_update) {
*do_update = true;
2019-12-17 09:51:38 +11:00
}
if (stop) {
*stop = 0;
2019-12-17 09:51:38 +11:00
}
}
static void fluid_free_endjob(void *customdata)
{
FluidJob *job = customdata;
FluidDomainSettings *fds = job->fmd->domain;
G.is_rendering = false;
BKE_spacedata_draw_locks(false);
WM_set_locked_interface(G_MAIN->wm.first, false);
/* Reflect the now empty cache in the viewport too. */
DEG_id_tag_update(&job->ob->id, ID_RECALC_GEOMETRY);
/* Free was successful:
* Report for ended free job and how long it took */
if (job->success) {
/* Show free job info */
2019-12-17 08:58:43 +11:00
WM_reportf(
RPT_INFO, "Fluid: %s complete! (%.2f)", job->name, PIL_check_seconds_timer() - job->start);
}
else {
if (fds->error[0] != '\0') {
WM_reportf(RPT_ERROR, "Fluid: %s failed: %s", job->name, fds->error);
}
else { /* User canceled the free job */
WM_reportf(RPT_WARNING, "Fluid: %s canceled!", job->name);
}
}
}
static void fluid_free_startjob(void *customdata, short *stop, short *do_update, float *progress)
{
FluidJob *job = customdata;
FluidDomainSettings *fds = job->fmd->domain;
job->stop = stop;
job->do_update = do_update;
job->progress = progress;
job->start = PIL_check_seconds_timer();
job->success = 1;
G.is_break = false;
G.is_rendering = true;
BKE_spacedata_draw_locks(true);
int cache_map = 0;
if (fluid_is_free_data(job) || fluid_is_free_all(job)) {
cache_map |= (FLUID_DOMAIN_OUTDATED_DATA | FLUID_DOMAIN_OUTDATED_NOISE |
FLUID_DOMAIN_OUTDATED_MESH | FLUID_DOMAIN_OUTDATED_PARTICLES);
}
if (fluid_is_free_noise(job) || fluid_is_free_all(job)) {
cache_map |= FLUID_DOMAIN_OUTDATED_NOISE;
}
if (fluid_is_free_mesh(job) || fluid_is_free_all(job)) {
cache_map |= FLUID_DOMAIN_OUTDATED_MESH;
}
if (fluid_is_free_particles(job) || fluid_is_free_all(job)) {
cache_map |= FLUID_DOMAIN_OUTDATED_PARTICLES;
}
if (fluid_is_free_guiding(job) || fluid_is_free_all(job)) {
cache_map |= (FLUID_DOMAIN_OUTDATED_DATA | FLUID_DOMAIN_OUTDATED_NOISE |
FLUID_DOMAIN_OUTDATED_MESH | FLUID_DOMAIN_OUTDATED_PARTICLES |
FLUID_DOMAIN_OUTDATED_GUIDE);
}
2019-12-17 08:38:08 +11:00
#ifdef WITH_FLUID
BKE_fluid_cache_free(fds, job->ob, cache_map);
2020-01-16 16:25:12 +11:00
#else
UNUSED_VARS(fds);
2019-12-17 08:38:08 +11:00
#endif
*do_update = true;
*stop = 0;
/* Update scene so that viewport shows freed up scene */
ED_update_for_newframe(job->bmain, job->depsgraph);
}
/***************************** Operators ******************************/
static int fluid_bake_exec(struct bContext *C, struct wmOperator *op)
{
FluidJob *job = MEM_mallocN(sizeof(FluidJob), "FluidJob");
char error_msg[256] = "\0";
if (!fluid_initjob(C, job, op, error_msg, sizeof(error_msg))) {
if (error_msg[0]) {
BKE_report(op->reports, RPT_ERROR, error_msg);
2019-04-22 09:19:45 +10:00
}
fluid_bake_free(job);
return OPERATOR_CANCELLED;
}
if (!fluid_validatepaths(job, op->reports)) {
fluid_bake_free(job);
return OPERATOR_CANCELLED;
}
WM_report_banners_cancel(job->bmain);
fluid_bake_startjob(job, NULL, NULL, NULL);
fluid_bake_endjob(job);
fluid_bake_free(job);
return OPERATOR_FINISHED;
}
static int fluid_bake_invoke(struct bContext *C,
struct wmOperator *op,
const wmEvent *UNUSED(_event))
{
Scene *scene = CTX_data_scene(C);
FluidJob *job = MEM_mallocN(sizeof(FluidJob), "FluidJob");
char error_msg[256] = "\0";
if (!fluid_initjob(C, job, op, error_msg, sizeof(error_msg))) {
if (error_msg[0]) {
BKE_report(op->reports, RPT_ERROR, error_msg);
}
fluid_bake_free(job);
return OPERATOR_CANCELLED;
}
if (!fluid_validatepaths(job, op->reports)) {
fluid_bake_free(job);
return OPERATOR_CANCELLED;
}
/* Clear existing banners so that the upcoming progress bar from this job has more room. */
WM_report_banners_cancel(job->bmain);
wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
CTX_wm_window(C),
scene,
"Fluid Bake",
WM_JOB_PROGRESS,
WM_JOB_TYPE_OBJECT_SIM_FLUID);
WM_jobs_customdata_set(wm_job, job, fluid_bake_free);
WM_jobs_timer(wm_job, 0.01, NC_OBJECT | ND_MODIFIER, NC_OBJECT | ND_MODIFIER);
WM_jobs_callbacks(wm_job, fluid_bake_startjob, NULL, NULL, fluid_bake_endjob);
WM_set_locked_interface(CTX_wm_manager(C), true);
WM_jobs_start(CTX_wm_manager(C), wm_job);
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
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.
2010-03-25 06:27:25 +00:00
}
static int fluid_bake_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
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.
2010-03-25 06:27:25 +00:00
{
/* no running blender, remove handler and pass through */
2019-12-17 09:51:38 +11:00
if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_SIM_FLUID)) {
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
2019-12-17 09:51:38 +11:00
}
switch (event->type) {
case EVT_ESCKEY:
return OPERATOR_RUNNING_MODAL;
}
return OPERATOR_PASS_THROUGH;
}
static int fluid_free_exec(struct bContext *C, struct wmOperator *op)
{
FluidModifierData *fmd = NULL;
FluidDomainSettings *fds;
Object *ob = ED_object_active_context(C);
Scene *scene = CTX_data_scene(C);
/*
* Get modifier data
*/
fmd = (FluidModifierData *)BKE_modifiers_findby_type(ob, eModifierType_Fluid);
if (!fmd) {
BKE_report(op->reports, RPT_ERROR, "Bake free failed: no Fluid modifier found");
return OPERATOR_CANCELLED;
}
fds = fmd->domain;
if (!fds) {
BKE_report(op->reports, RPT_ERROR, "Bake free failed: invalid domain");
return OPERATOR_CANCELLED;
}
/* Cannot free data if other bakes currently working */
if (fmd->domain->cache_flag & (FLUID_DOMAIN_BAKING_DATA | FLUID_DOMAIN_BAKING_NOISE |
FLUID_DOMAIN_BAKING_MESH | FLUID_DOMAIN_BAKING_PARTICLES)) {
BKE_report(op->reports, RPT_ERROR, "Bake free failed: pending bake jobs found");
return OPERATOR_CANCELLED;
}
FluidJob *job = MEM_mallocN(sizeof(FluidJob), "FluidJob");
job->bmain = CTX_data_main(C);
job->scene = scene;
job->depsgraph = CTX_data_depsgraph_pointer(C);
job->ob = ob;
job->fmd = fmd;
job->type = op->type->idname;
job->name = op->type->name;
if (!fluid_validatepaths(job, op->reports)) {
fluid_bake_free(job);
return OPERATOR_CANCELLED;
}
/* Clear existing banners so that the upcoming progress bar from this job has more room. */
WM_report_banners_cancel(job->bmain);
wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
CTX_wm_window(C),
scene,
"Fluid Free",
WM_JOB_PROGRESS,
WM_JOB_TYPE_OBJECT_SIM_FLUID);
WM_jobs_customdata_set(wm_job, job, fluid_bake_free);
WM_jobs_timer(wm_job, 0.01, NC_OBJECT | ND_MODIFIER, NC_OBJECT | ND_MODIFIER);
WM_jobs_callbacks(wm_job, fluid_free_startjob, NULL, NULL, fluid_free_endjob);
WM_set_locked_interface(CTX_wm_manager(C), true);
/* Free Fluid Geometry */
WM_jobs_start(CTX_wm_manager(C), wm_job);
return OPERATOR_FINISHED;
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.
2010-03-25 06:27:25 +00:00
}
static int fluid_pause_exec(struct bContext *C, struct wmOperator *op)
{
FluidModifierData *fmd = NULL;
FluidDomainSettings *fds;
Object *ob = ED_object_active_context(C);
/*
* Get modifier data
*/
fmd = (FluidModifierData *)BKE_modifiers_findby_type(ob, eModifierType_Fluid);
if (!fmd) {
BKE_report(op->reports, RPT_ERROR, "Bake free failed: no Fluid modifier found");
return OPERATOR_CANCELLED;
}
fds = fmd->domain;
if (!fds) {
BKE_report(op->reports, RPT_ERROR, "Bake free failed: invalid domain");
return OPERATOR_CANCELLED;
}
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.
2010-03-25 06:27:25 +00:00
G.is_break = true;
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.
2010-03-25 06:27:25 +00:00
return OPERATOR_FINISHED;
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.
2010-03-25 06:27:25 +00:00
}
void FLUID_OT_bake_all(wmOperatorType *ot)
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.
2010-03-25 06:27:25 +00:00
{
/* identifiers */
ot->name = "Bake All";
ot->description = "Bake Entire Fluid Simulation";
ot->idname = FLUID_JOB_BAKE_ALL;
/* api callbacks */
ot->exec = fluid_bake_exec;
ot->invoke = fluid_bake_invoke;
ot->modal = fluid_bake_modal;
ot->poll = ED_operator_object_active_editable;
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.
2010-03-25 06:27:25 +00:00
}
void FLUID_OT_free_all(wmOperatorType *ot)
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.
2010-03-25 06:27:25 +00:00
{
/* identifiers */
ot->name = "Free All";
ot->description = "Free Entire Fluid Simulation";
ot->idname = FLUID_JOB_FREE_ALL;
/* api callbacks */
ot->exec = fluid_free_exec;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_bake_data(wmOperatorType *ot)
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.
2010-03-25 06:27:25 +00:00
{
/* identifiers */
ot->name = "Bake Data";
ot->description = "Bake Fluid Data";
ot->idname = FLUID_JOB_BAKE_DATA;
/* api callbacks */
ot->exec = fluid_bake_exec;
ot->invoke = fluid_bake_invoke;
ot->modal = fluid_bake_modal;
ot->poll = ED_operator_object_active_editable;
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.
2010-03-25 06:27:25 +00:00
}
void FLUID_OT_free_data(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Free Data";
ot->description = "Free Fluid Data";
ot->idname = FLUID_JOB_FREE_DATA;
/* api callbacks */
ot->exec = fluid_free_exec;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_bake_noise(wmOperatorType *ot)
2011-12-30 07:55:15 +00:00
{
/* identifiers */
ot->name = "Bake Noise";
ot->description = "Bake Fluid Noise";
ot->idname = FLUID_JOB_BAKE_NOISE;
/* api callbacks */
ot->exec = fluid_bake_exec;
ot->invoke = fluid_bake_invoke;
ot->modal = fluid_bake_modal;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_free_noise(wmOperatorType *ot)
2010-06-03 07:28:47 +00:00
{
/* identifiers */
ot->name = "Free Noise";
ot->description = "Free Fluid Noise";
ot->idname = FLUID_JOB_FREE_NOISE;
/* api callbacks */
ot->exec = fluid_free_exec;
ot->poll = ED_operator_object_active_editable;
2010-06-03 07:28:47 +00:00
}
void FLUID_OT_bake_mesh(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Bake Mesh";
ot->description = "Bake Fluid Mesh";
ot->idname = FLUID_JOB_BAKE_MESH;
/* api callbacks */
ot->exec = fluid_bake_exec;
ot->invoke = fluid_bake_invoke;
ot->modal = fluid_bake_modal;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_free_mesh(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Free Mesh";
ot->description = "Free Fluid Mesh";
ot->idname = FLUID_JOB_FREE_MESH;
/* api callbacks */
ot->exec = fluid_free_exec;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_bake_particles(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Bake Particles";
ot->description = "Bake Fluid Particles";
ot->idname = FLUID_JOB_BAKE_PARTICLES;
/* api callbacks */
ot->exec = fluid_bake_exec;
ot->invoke = fluid_bake_invoke;
ot->modal = fluid_bake_modal;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_free_particles(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Free Particles";
ot->description = "Free Fluid Particles";
ot->idname = FLUID_JOB_FREE_PARTICLES;
/* api callbacks */
ot->exec = fluid_free_exec;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_bake_guides(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Bake Guides";
ot->description = "Bake Fluid Guiding";
ot->idname = FLUID_JOB_BAKE_GUIDES;
/* api callbacks */
ot->exec = fluid_bake_exec;
ot->invoke = fluid_bake_invoke;
ot->modal = fluid_bake_modal;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_free_guides(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Free Guides";
ot->description = "Free Fluid Guiding";
ot->idname = FLUID_JOB_FREE_GUIDES;
/* api callbacks */
ot->exec = fluid_free_exec;
ot->poll = ED_operator_object_active_editable;
}
void FLUID_OT_pause_bake(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Pause Bake";
ot->description = "Pause Bake";
ot->idname = FLUID_JOB_BAKE_PAUSE;
/* api callbacks */
ot->exec = fluid_pause_exec;
ot->poll = ED_operator_object_active_editable;
}