2016-12-28 17:30:58 +01:00
|
|
|
/*
|
|
|
|
* 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,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2007 by Janne Karhu.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edphys
|
2016-12-28 17:30:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_global.h"
|
2017-02-14 16:33:13 +01:00
|
|
|
#include "BKE_layer.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_pointcache.h"
|
|
|
|
|
2019-01-25 12:31:24 +01:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "ED_particle.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#include "physics_intern.h"
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool ptcache_bake_all_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
return CTX_data_scene(C) != NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool ptcache_poll(bContext *C)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
|
2020-11-13 14:20:10 +01:00
|
|
|
|
|
|
|
ID *id = ptr.owner_id;
|
|
|
|
PointCache *point_cache = ptr.data;
|
|
|
|
|
|
|
|
if (id == NULL || point_cache == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ID_IS_OVERRIDE_LIBRARY_REAL(id) && (point_cache->flag & PTCACHE_DISK_CACHE) == false) {
|
2020-11-17 21:33:28 +01:00
|
|
|
CTX_wm_operator_poll_msg_set(C,
|
|
|
|
"Library override data-blocks only support Disk Cache storage");
|
2020-11-13 14:20:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ID_IS_LINKED(id) && (point_cache->flag & PTCACHE_DISK_CACHE) == false) {
|
2020-11-18 16:14:48 -05:00
|
|
|
CTX_wm_operator_poll_msg_set(C, "Linked data-blocks do not allow editing caches");
|
2020-11-13 14:20:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ptcache_add_remove_poll(bContext *C)
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
|
|
|
|
|
|
|
|
ID *id = ptr.owner_id;
|
|
|
|
PointCache *point_cache = ptr.data;
|
|
|
|
|
|
|
|
if (id == NULL || point_cache == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ID_IS_OVERRIDE_LIBRARY_REAL(id) || ID_IS_LINKED(id)) {
|
2020-11-17 21:33:28 +01:00
|
|
|
CTX_wm_operator_poll_msg_set(
|
2020-11-18 16:14:48 -05:00
|
|
|
C, "Linked or library override data-blocks do not allow adding or removing caches");
|
2020-11-13 14:20:10 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct PointCacheJob {
|
Physics baking: tag interface locked during backing
This is a variation of older hach which was setting is_rendering
to truth to tell window manager to not do dependency graph update.
In the nowadays reality window manager is supposed to do dependency
graph update during rendering, that was the whole purpose of CoW
project. This works fine for rendering, since render engines has
their own dependency graphs.
Physics, on the other hand, is using same dependency graph as used
for the viewport, and what's worse: it modifies objects from it.
For example, in a single threaded evaluation ASAN instantly catches
case when cached BVH constructed by smoke is referencing looptri
layer which is freed by viewport's update.
Now we are locking interface, allowing only a subset of navigation
operators to run. This seems to be safest way of dealing with the
problem. There are following variations which we can consider
doing:
- Allow viewport navigation, which will require making it so draw
manager does not write to the objects.
A bit dangerous, since smoke simulation might in theory modify
data which is also used by a draw manager.
- Make physics simulation to have own dedicated dependency graph,
solving all threading conflicts all together.
This fixes crash when baking smoke. Steps to reproduce:
- Call "Quick Smoke"
- In smoke panel, click "Bake".
2018-11-07 13:40:41 +01:00
|
|
|
wmWindowManager *wm;
|
2016-12-28 17:30:58 +01:00
|
|
|
void *owner;
|
|
|
|
short *stop, *do_update;
|
|
|
|
float *progress;
|
|
|
|
|
|
|
|
PTCacheBaker *baker;
|
|
|
|
} PointCacheJob;
|
|
|
|
|
|
|
|
static void ptcache_job_free(void *customdata)
|
|
|
|
{
|
|
|
|
PointCacheJob *job = customdata;
|
|
|
|
MEM_freeN(job->baker);
|
|
|
|
MEM_freeN(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ptcache_job_break(void *customdata)
|
|
|
|
{
|
|
|
|
PointCacheJob *job = customdata;
|
|
|
|
|
|
|
|
if (G.is_break) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (job->stop && *(job->stop)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ptcache_job_update(void *customdata, float progress, int *cancel)
|
|
|
|
{
|
2017-06-12 13:35:00 +10:00
|
|
|
PointCacheJob *job = customdata;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-06-12 13:35:00 +10:00
|
|
|
if (ptcache_job_break(job)) {
|
|
|
|
*cancel = 1;
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-06-12 13:35:00 +10:00
|
|
|
*(job->do_update) = true;
|
|
|
|
*(job->progress) = progress;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ptcache_job_startjob(void *customdata, short *stop, short *do_update, float *progress)
|
|
|
|
{
|
2017-06-12 13:35:00 +10:00
|
|
|
PointCacheJob *job = customdata;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-06-12 13:35:00 +10:00
|
|
|
job->stop = stop;
|
|
|
|
job->do_update = do_update;
|
|
|
|
job->progress = progress;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-06-12 13:35:00 +10:00
|
|
|
G.is_break = false;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-06-12 13:35:00 +10:00
|
|
|
/* XXX annoying hack: needed to prevent data corruption when changing
|
|
|
|
* scene frame in separate threads
|
|
|
|
*/
|
Physics baking: tag interface locked during backing
This is a variation of older hach which was setting is_rendering
to truth to tell window manager to not do dependency graph update.
In the nowadays reality window manager is supposed to do dependency
graph update during rendering, that was the whole purpose of CoW
project. This works fine for rendering, since render engines has
their own dependency graphs.
Physics, on the other hand, is using same dependency graph as used
for the viewport, and what's worse: it modifies objects from it.
For example, in a single threaded evaluation ASAN instantly catches
case when cached BVH constructed by smoke is referencing looptri
layer which is freed by viewport's update.
Now we are locking interface, allowing only a subset of navigation
operators to run. This seems to be safest way of dealing with the
problem. There are following variations which we can consider
doing:
- Allow viewport navigation, which will require making it so draw
manager does not write to the objects.
A bit dangerous, since smoke simulation might in theory modify
data which is also used by a draw manager.
- Make physics simulation to have own dedicated dependency graph,
solving all threading conflicts all together.
This fixes crash when baking smoke. Steps to reproduce:
- Call "Quick Smoke"
- In smoke panel, click "Bake".
2018-11-07 13:40:41 +01:00
|
|
|
WM_set_locked_interface(job->wm, true);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
BKE_ptcache_bake(job->baker);
|
|
|
|
|
2017-06-12 13:35:00 +10:00
|
|
|
*do_update = true;
|
|
|
|
*stop = 0;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ptcache_job_endjob(void *customdata)
|
|
|
|
{
|
2017-06-12 13:35:00 +10:00
|
|
|
PointCacheJob *job = customdata;
|
2016-12-28 17:30:58 +01:00
|
|
|
Scene *scene = job->baker->scene;
|
|
|
|
|
Physics baking: tag interface locked during backing
This is a variation of older hach which was setting is_rendering
to truth to tell window manager to not do dependency graph update.
In the nowadays reality window manager is supposed to do dependency
graph update during rendering, that was the whole purpose of CoW
project. This works fine for rendering, since render engines has
their own dependency graphs.
Physics, on the other hand, is using same dependency graph as used
for the viewport, and what's worse: it modifies objects from it.
For example, in a single threaded evaluation ASAN instantly catches
case when cached BVH constructed by smoke is referencing looptri
layer which is freed by viewport's update.
Now we are locking interface, allowing only a subset of navigation
operators to run. This seems to be safest way of dealing with the
problem. There are following variations which we can consider
doing:
- Allow viewport navigation, which will require making it so draw
manager does not write to the objects.
A bit dangerous, since smoke simulation might in theory modify
data which is also used by a draw manager.
- Make physics simulation to have own dedicated dependency graph,
solving all threading conflicts all together.
This fixes crash when baking smoke. Steps to reproduce:
- Call "Quick Smoke"
- In smoke panel, click "Bake".
2018-11-07 13:40:41 +01:00
|
|
|
WM_set_locked_interface(job->wm, false);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
WM_main_add_notifier(NC_SCENE | ND_FRAME, scene);
|
2020-06-30 18:23:56 +02:00
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_POINTCACHE, job->baker->pid.owner_id);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ptcache_free_bake(PointCache *cache)
|
|
|
|
{
|
|
|
|
if (cache->edit) {
|
|
|
|
if (!cache->edit->edited || 1) { // XXX okee("Lose changes done in particle mode?")) {
|
|
|
|
PE_free_ptcache_edit(cache->edit);
|
|
|
|
cache->edit = NULL;
|
|
|
|
cache->flag &= ~PTCACHE_BAKED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cache->flag &= ~PTCACHE_BAKED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all)
|
|
|
|
{
|
|
|
|
PTCacheBaker *baker = MEM_callocN(sizeof(PTCacheBaker), "PTCacheBaker");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-13 10:57:10 +02:00
|
|
|
baker->bmain = CTX_data_main(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
baker->scene = CTX_data_scene(C);
|
2017-11-22 10:52:39 -02:00
|
|
|
baker->view_layer = CTX_data_view_layer(C);
|
2019-07-25 16:36:22 +02:00
|
|
|
/* Depsgraph is used to sweep the frame range and evaluate scene at different times. */
|
|
|
|
baker->depsgraph = CTX_data_depsgraph_pointer(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
baker->bake = RNA_boolean_get(op->ptr, "bake");
|
|
|
|
baker->render = 0;
|
|
|
|
baker->anim_init = 0;
|
|
|
|
baker->quick_step = 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (!all) {
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
PointCache *cache = ptr.data;
|
2018-04-12 18:43:43 +02:00
|
|
|
baker->pid = BKE_ptcache_id_find(ob, baker->scene, cache);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return baker;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ptcache_bake_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bool all = STREQ(op->type->idname, "PTCACHE_OT_bake_all");
|
|
|
|
|
|
|
|
PTCacheBaker *baker = ptcache_baker_create(C, op, all);
|
|
|
|
BKE_ptcache_bake(baker);
|
|
|
|
MEM_freeN(baker);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ptcache_bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
{
|
|
|
|
bool all = STREQ(op->type->idname, "PTCACHE_OT_bake_all");
|
|
|
|
|
|
|
|
PointCacheJob *job = MEM_mallocN(sizeof(PointCacheJob), "PointCacheJob");
|
Physics baking: tag interface locked during backing
This is a variation of older hach which was setting is_rendering
to truth to tell window manager to not do dependency graph update.
In the nowadays reality window manager is supposed to do dependency
graph update during rendering, that was the whole purpose of CoW
project. This works fine for rendering, since render engines has
their own dependency graphs.
Physics, on the other hand, is using same dependency graph as used
for the viewport, and what's worse: it modifies objects from it.
For example, in a single threaded evaluation ASAN instantly catches
case when cached BVH constructed by smoke is referencing looptri
layer which is freed by viewport's update.
Now we are locking interface, allowing only a subset of navigation
operators to run. This seems to be safest way of dealing with the
problem. There are following variations which we can consider
doing:
- Allow viewport navigation, which will require making it so draw
manager does not write to the objects.
A bit dangerous, since smoke simulation might in theory modify
data which is also used by a draw manager.
- Make physics simulation to have own dedicated dependency graph,
solving all threading conflicts all together.
This fixes crash when baking smoke. Steps to reproduce:
- Call "Quick Smoke"
- In smoke panel, click "Bake".
2018-11-07 13:40:41 +01:00
|
|
|
job->wm = CTX_wm_manager(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
job->baker = ptcache_baker_create(C, op, all);
|
|
|
|
job->baker->bake_job = job;
|
|
|
|
job->baker->update_progress = ptcache_job_update;
|
|
|
|
|
|
|
|
wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
|
|
|
|
CTX_wm_window(C),
|
|
|
|
CTX_data_scene(C),
|
|
|
|
"Point Cache",
|
|
|
|
WM_JOB_PROGRESS,
|
|
|
|
WM_JOB_TYPE_POINTCACHE);
|
|
|
|
|
|
|
|
WM_jobs_customdata_set(wm_job, job, ptcache_job_free);
|
|
|
|
WM_jobs_timer(wm_job, 0.1, NC_OBJECT | ND_POINTCACHE, NC_OBJECT | ND_POINTCACHE);
|
|
|
|
WM_jobs_callbacks(wm_job, ptcache_job_startjob, NULL, NULL, ptcache_job_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);
|
|
|
|
|
|
|
|
/* we must run modal until the bake job is done, otherwise the undo push
|
|
|
|
* happens before the job ends, which can lead to race conditions between
|
|
|
|
* the baking and file writing code */
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ptcache_bake_modal(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
{
|
|
|
|
Scene *scene = (Scene *)op->customdata;
|
|
|
|
|
|
|
|
/* no running blender, remove handler and pass through */
|
|
|
|
if (0 == WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_POINTCACHE)) {
|
|
|
|
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ptcache_bake_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
Scene *scene = (Scene *)op->customdata;
|
|
|
|
|
|
|
|
/* kill on cancel, because job is using op->reports */
|
|
|
|
WM_jobs_kill_type(wm, scene, WM_JOB_TYPE_POINTCACHE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ptcache_free_bake_all_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2017-02-14 16:33:13 +01:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2016-12-28 17:30:58 +01:00
|
|
|
PTCacheID *pid;
|
|
|
|
ListBase pidlist;
|
|
|
|
|
2018-03-01 19:00:54 +11:00
|
|
|
FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
|
2017-02-14 16:33:13 +01:00
|
|
|
BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2017-02-14 16:33:13 +01:00
|
|
|
for (pid = pidlist.first; pid; pid = pid->next) {
|
2016-12-28 17:30:58 +01:00
|
|
|
ptcache_free_bake(pid->cache);
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
BLI_freelistN(&pidlist);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2017-02-14 16:33:13 +01:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, ob);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2018-03-09 11:44:42 +11:00
|
|
|
FOREACH_SCENE_OBJECT_END;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PTCACHE_OT_bake_all(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Bake All Physics";
|
|
|
|
ot->description = "Bake all physics";
|
|
|
|
ot->idname = "PTCACHE_OT_bake_all";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ptcache_bake_exec;
|
|
|
|
ot->invoke = ptcache_bake_invoke;
|
|
|
|
ot->modal = ptcache_bake_modal;
|
|
|
|
ot->cancel = ptcache_bake_cancel;
|
|
|
|
ot->poll = ptcache_bake_all_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
RNA_def_boolean(ot->srna, "bake", 1, "Bake", "");
|
|
|
|
}
|
|
|
|
void PTCACHE_OT_free_bake_all(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2019-01-31 19:49:47 +01:00
|
|
|
ot->name = "Delete All Physics Bakes";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->idname = "PTCACHE_OT_free_bake_all";
|
2019-01-31 19:49:47 +01:00
|
|
|
ot->description = "Delete all baked caches of all objects in the current scene";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ptcache_free_bake_all_exec;
|
|
|
|
ot->poll = ptcache_bake_all_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ptcache_free_bake_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
|
|
|
|
PointCache *cache = ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
ptcache_free_bake(cache);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, ob);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
static int ptcache_bake_from_cache_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
|
|
|
|
PointCache *cache = ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
cache->flag |= PTCACHE_BAKED;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, ob);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
void PTCACHE_OT_bake(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Bake Physics";
|
|
|
|
ot->description = "Bake physics";
|
|
|
|
ot->idname = "PTCACHE_OT_bake";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ptcache_bake_exec;
|
|
|
|
ot->invoke = ptcache_bake_invoke;
|
|
|
|
ot->modal = ptcache_bake_modal;
|
|
|
|
ot->cancel = ptcache_bake_cancel;
|
|
|
|
ot->poll = ptcache_poll;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
RNA_def_boolean(ot->srna, "bake", 0, "Bake", "");
|
|
|
|
}
|
|
|
|
void PTCACHE_OT_free_bake(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2019-01-31 19:49:47 +01:00
|
|
|
ot->name = "Delete Physics Bake";
|
|
|
|
ot->description = "Delete physics bake";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->idname = "PTCACHE_OT_free_bake";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ptcache_free_bake_exec;
|
|
|
|
ot->poll = ptcache_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
void PTCACHE_OT_bake_from_cache(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2020-10-07 08:04:53 -05:00
|
|
|
ot->name = "Bake from Cache";
|
2016-12-28 17:30:58 +01:00
|
|
|
ot->description = "Bake from cache";
|
|
|
|
ot->idname = "PTCACHE_OT_bake_from_cache";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ptcache_bake_from_cache_exec;
|
|
|
|
ot->poll = ptcache_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ptcache_add_new_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
PointCache *cache = ptr.data;
|
2018-04-12 18:43:43 +02:00
|
|
|
PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-12 18:43:43 +02:00
|
|
|
if (pid.cache) {
|
|
|
|
PointCache *cache_new = BKE_ptcache_add(pid.ptcaches);
|
|
|
|
cache_new->step = pid.default_step;
|
|
|
|
*(pid.cache_ptr) = cache_new;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-25 19:51:38 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_POINT_CACHE);
|
2019-01-25 12:31:24 +01:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, ob);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
static int ptcache_remove_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2019-08-23 09:52:12 +02:00
|
|
|
Object *ob = (Object *)ptr.owner_id;
|
2016-12-28 17:30:58 +01:00
|
|
|
PointCache *cache = ptr.data;
|
2018-04-12 18:43:43 +02:00
|
|
|
PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-12 18:43:43 +02:00
|
|
|
/* don't delete last cache */
|
|
|
|
if (pid.cache && pid.ptcaches->first != pid.ptcaches->last) {
|
|
|
|
BLI_remlink(pid.ptcaches, pid.cache);
|
|
|
|
BKE_ptcache_free(pid.cache);
|
|
|
|
*(pid.cache_ptr) = pid.ptcaches->first;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-25 12:31:24 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, ob);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
void PTCACHE_OT_add(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Add New Cache";
|
|
|
|
ot->description = "Add new cache";
|
|
|
|
ot->idname = "PTCACHE_OT_add";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ptcache_add_new_exec;
|
2020-11-13 14:20:10 +01:00
|
|
|
ot->poll = ptcache_add_remove_poll;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
void PTCACHE_OT_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Delete Current Cache";
|
|
|
|
ot->description = "Delete current cache";
|
|
|
|
ot->idname = "PTCACHE_OT_remove";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = ptcache_remove_exec;
|
2020-11-13 14:20:10 +01:00
|
|
|
ot->poll = ptcache_add_remove_poll;
|
2016-12-28 17:30:58 +01:00
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|