diff options
author | Janne Karhu <jhkarh@gmail.com> | 2009-06-21 14:16:52 +0400 |
---|---|---|
committer | Janne Karhu <jhkarh@gmail.com> | 2009-06-21 14:16:52 +0400 |
commit | 6b15024f4a7b999331694d8a9135d47e4b783a34 (patch) | |
tree | 0b5a5c3b02778a7ca9df7628e742f98704505bb7 /source/blender/editors | |
parent | 64274de2fe8ef3b9a98a5cb3bd7d691fa1cee600 (diff) |
Pointcache refresh part 1:
* Particles support larger than 1 frame changes, bigger frame changes can result in inaccurate results, but it's super fast and you get a nice feeling of how the particles behave!
* "Cache to current frame" button calculates the exact result of particles at current frame.
* Current state of cache can be protected by making it a bake.
* Cache is now in memory by default, disk cache is an option.
* Only "viewport %" number of particles are calculated and cached in viewport, baking and rendering calculate all particles.
* Info on cached frames and memory usage given in ui.
* Support for exact "autocaching" of changes and large frame changes(disabled for now until exact place in event system is decided)
* "Continue physics" is probably deprecated after this and should be removed once sb & cloth use the new cache code.
Todo:
* Make softbody & cloth use the new cache things.
Other changes:
* Some cleanup of particle buttons.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_pointcache.h | 38 | ||||
-rw-r--r-- | source/blender/editors/physics/ed_pointcache.c | 270 | ||||
-rw-r--r-- | source/blender/editors/space_api/spacetypes.c | 2 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 2 |
4 files changed, 311 insertions, 1 deletions
diff --git a/source/blender/editors/include/ED_pointcache.h b/source/blender/editors/include/ED_pointcache.h new file mode 100644 index 00000000000..7bf51d9d53d --- /dev/null +++ b/source/blender/editors/include/ED_pointcache.h @@ -0,0 +1,38 @@ +/* + * $Id: ED_editparticle.h $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2007 by Janne Karhu. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef ED_PHYSICS_H +#define ED_PHYSICS_H + +/* operators */ +void ED_operatortypes_pointcache(void); +//void ED_keymap_pointcache(struct wmWindowManager *wm); + +#endif /* ED_PHYSICS_H */ + diff --git a/source/blender/editors/physics/ed_pointcache.c b/source/blender/editors/physics/ed_pointcache.c new file mode 100644 index 00000000000..e47f44c5c1a --- /dev/null +++ b/source/blender/editors/physics/ed_pointcache.c @@ -0,0 +1,270 @@ +/* + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2007 by Janne Karhu. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_scene_types.h" +#include "DNA_object_force.h" + +#include "BKE_context.h" +#include "BKE_particle.h" +#include "BKE_report.h" +#include "BKE_scene.h" +#include "BKE_utildefines.h" +#include "BKE_pointcache.h" +#include "BKE_global.h" +#include "BKE_multires.h" + +#include "BLI_blenlib.h" + +#include "ED_screen.h" +#include "ED_pointcache.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "physics_intern.h" + +static int cache_break_test(void *cbd) { + return G.afbreek==1; +} +/**************************** general **********************************/ +static int ptcache_bake_all_poll(bContext *C) +{ + Scene *scene= CTX_data_scene(C); + + if(!scene) + return 0; + + return 1; +} + +static int ptcache_bake_all_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PTCacheBaker baker; + + + baker.scene = scene; + baker.pid = NULL; + baker.bake = RNA_boolean_get(op->ptr, "bake"); + baker.render = 0; + baker.break_test = cache_break_test; + baker.break_data = NULL; + baker.progressbar = WM_timecursor; + baker.progresscontext = CTX_wm_window(C); + + BKE_ptcache_make_cache(&baker); + + WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); + + return OPERATOR_FINISHED; +} +static int ptcache_free_bake_all_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Base *base; + PTCacheID *pid; + ListBase pidlist; + + for(base=scene->base.first; base; base= base->next) { + BKE_ptcache_ids_from_object(&pidlist, base->object); + + for(pid=pidlist.first; pid; pid=pid->next) { + pid->cache->flag &= ~PTCACHE_BAKED; + BKE_ptcache_id_reset(scene, pid, PTCACHE_RESET_OUTDATED); + } + } + + BLI_freelistN(&pidlist); + + 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->idname= "PTCACHE_OT_bake_all"; + + /* api callbacks */ + ot->exec= ptcache_bake_all_exec; + ot->poll= ptcache_bake_all_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} +void PTCACHE_OT_free_bake_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Free All Physics Bakes"; + ot->idname= "PTCACHE_OT_free_bake_all"; + + /* api callbacks */ + ot->exec= ptcache_free_bake_all_exec; + ot->poll= ptcache_bake_all_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/**************************** particles **********************************/ +static int ptcache_bake_particle_system_poll(bContext *C) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + + if(!scene || !ob || ob->id.lib) + return 0; + + return (ob->particlesystem.first != NULL); +} + +static int ptcache_bake_particle_system_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys =psys_get_current(ob); + PTCacheID pid; + PTCacheBaker baker; + + BKE_ptcache_id_from_particles(&pid, ob, psys); + + baker.scene = scene; + baker.pid = &pid; + baker.bake = RNA_boolean_get(op->ptr, "bake"); + baker.render = 0; + baker.break_test = cache_break_test; + baker.break_data = NULL; + baker.progressbar = WM_timecursor; + baker.progresscontext = CTX_wm_window(C); + + BKE_ptcache_make_cache(&baker); + + WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); + + return OPERATOR_FINISHED; +} +static int ptcache_free_bake_particle_system_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= psys_get_current(ob); + PTCacheID pid; + + BKE_ptcache_id_from_particles(&pid, ob, psys); + psys->pointcache->flag &= ~PTCACHE_BAKED; + BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); + + WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); + + return OPERATOR_FINISHED; +} +void PTCACHE_OT_cache_particle_system(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Bake Particles"; + ot->idname= "PTCACHE_OT_cache_particle_system"; + + /* api callbacks */ + ot->exec= ptcache_bake_particle_system_exec; + ot->poll= ptcache_bake_particle_system_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_boolean(ot->srna, "bake", 0, "Bake", ""); +} +void PTCACHE_OT_free_bake_particle_system(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Free Particles Bake"; + ot->idname= "PTCACHE_OT_free_bake_particle_system"; + + /* api callbacks */ + ot->exec= ptcache_free_bake_particle_system_exec; + ot->poll= ptcache_bake_particle_system_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} +static int ptcache_bake_from_particles_cache_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + ParticleSystem *psys= psys_get_current(ob); + PTCacheID pid; + + BKE_ptcache_id_from_particles(&pid, ob, psys); + psys->pointcache->flag |= PTCACHE_BAKED; + + return OPERATOR_FINISHED; +} +void PTCACHE_OT_bake_from_particles_cache(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Bake From Cache"; + ot->idname= "PTCACHE_OT_bake_from_particles_cache"; + + /* api callbacks */ + ot->exec= ptcache_bake_from_particles_cache_exec; + ot->poll= ptcache_bake_particle_system_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/**************************** registration **********************************/ + +void ED_operatortypes_pointcache(void) +{ + WM_operatortype_append(PTCACHE_OT_bake_all); + WM_operatortype_append(PTCACHE_OT_free_bake_all); + WM_operatortype_append(PTCACHE_OT_cache_particle_system); + WM_operatortype_append(PTCACHE_OT_free_bake_particle_system); + WM_operatortype_append(PTCACHE_OT_bake_from_particles_cache); +} + +//void ED_keymap_pointcache(wmWindowManager *wm) +//{ +// ListBase *keymap= WM_keymap_listbase(wm, "Pointcache", 0, 0); +// +// WM_keymap_add_item(keymap, "PHYSICS_OT_bake_all", AKEY, KM_PRESS, 0, 0); +// WM_keymap_add_item(keymap, "PHYSICS_OT_free_all", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); +// WM_keymap_add_item(keymap, "PHYSICS_OT_bake_particle_system", PADMINUS, KM_PRESS, KM_CTRL, 0); +// WM_keymap_add_item(keymap, "PHYSICS_OT_free_particle_system", LKEY, KM_PRESS, 0, 0); +//} + diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 4f9c1f4b7a7..510103895f4 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -50,6 +50,7 @@ #include "ED_screen.h" #include "ED_space_api.h" #include "ED_uvedit.h" +#include "ED_pointcache.h" /* only call once on startup, storage is global in BKE kernel listbase */ void ED_spacetypes_init(void) @@ -89,6 +90,7 @@ void ED_spacetypes_init(void) ED_operatortypes_curve(); ED_operatortypes_armature(); ED_marker_operatortypes(); + ED_operatortypes_pointcache(); ui_view2d_operatortypes(); diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 6c7aa1ee49d..efe5122ad01 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -4672,7 +4672,7 @@ void special_aftertrans_update(TransInfo *t) if (base->flag & SELECT && (t->mode != TFM_DUMMY)) { /* pointcache refresh */ - if (BKE_ptcache_object_reset(ob, PTCACHE_RESET_DEPSGRAPH)) + if (BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH)) ob->recalc |= OB_RECALC_DATA; /* Set autokey if necessary */ |