From ad21793c69429dea4489603a77b95ac733966bcc Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 11 Oct 2018 14:06:34 +0200 Subject: Interactive mode: new scene.flag SCE_INTERACTIVE to update the depsgraph without frame change but running physics. Interactive button added on time line. --- release/scripts/addons | 2 +- release/scripts/addons_contrib | 2 +- release/scripts/startup/bl_ui/space_time.py | 2 ++ source/blender/blenkernel/intern/rigidbody.c | 18 ++++++++++++++++++ source/blender/editors/screen/screen_ops.c | 6 +++++- source/blender/makesdna/DNA_scene_types.h | 1 + source/blender/makesrna/intern/rna_scene.c | 7 +++++++ 7 files changed, 35 insertions(+), 3 deletions(-) diff --git a/release/scripts/addons b/release/scripts/addons index 5f7fba0565a..0923bdf725b 160000 --- a/release/scripts/addons +++ b/release/scripts/addons @@ -1 +1 @@ -Subproject commit 5f7fba0565a7c9ae93eae31a08fc9bbbd16d333a +Subproject commit 0923bdf725b088ba584e6b1246f1ad986be436b3 diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib index fecc0db5600..15b25a42783 160000 --- a/release/scripts/addons_contrib +++ b/release/scripts/addons_contrib @@ -1 +1 @@ -Subproject commit fecc0db5600405a0c14c70120ae279222861ef80 +Subproject commit 15b25a42783d1e516b5298d70b582fae2559ae17 diff --git a/release/scripts/startup/bl_ui/space_time.py b/release/scripts/startup/bl_ui/space_time.py index 10cd2f6d47b..d9b0e2e6298 100644 --- a/release/scripts/startup/bl_ui/space_time.py +++ b/release/scripts/startup/bl_ui/space_time.py @@ -38,6 +38,8 @@ class TIME_HT_editor_buttons(Header): layout.separator_spacer() + layout.prop(scene, "use_interactive_mode", text="", icon='GAME', toggle=True) + layout.prop(toolsettings, "use_keyframe_insert_auto", text="", toggle=True) row = layout.row(align=True) diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 95b558f5b43..737359aae93 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1661,6 +1661,24 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime PTCacheID pid; int startframe, endframe; + if (scene->flag & SCE_INTERACTIVE) { + /* No caching when in interactive mode */ + if (rbw->shared->physics_world == NULL) + return; + else if (rbw->objects == NULL) + rigidbody_update_ob_array(rbw); + + rigidbody_update_simulation(depsgraph, scene, rbw, false); + + /* TODO: get the actual time difference from previous step so that the physics simulation is real time */ + timestep = 1.0f / (float)FPS * rbw->time_scale; + /* step simulation by the requested timestep, steps per second are adjusted to take time scale into account */ + RB_dworld_step_simulation(rbw->shared->physics_world, timestep, INT_MAX, 1.0f / (float)rbw->steps_per_second * min_ff(rbw->time_scale, 1.0f)); + + rigidbody_update_simulation_post_step(depsgraph, rbw); + return; + } + BKE_ptcache_id_from_rigidbody(&pid, NULL, rbw); BKE_ptcache_id_time(&pid, scene, ctime, &startframe, &endframe, NULL); cache = rbw->shared->pointcache; diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 9ce0956aa66..fad9990409e 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -3882,6 +3882,7 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv ScrArea *sa; int sync; float time; + int pfra = scene->r.cfra; /* sync, don't sync, or follow scene setting */ if (sad->flag & ANIMPLAY_FLAG_SYNC) sync = 1; @@ -3939,7 +3940,10 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv /* reset 'jumped' flag before checking if we need to jump... */ sad->flag &= ~ANIMPLAY_FLAG_JUMPED; - if (sad->flag & ANIMPLAY_FLAG_REVERSE) { + if (scene->flag & SCE_INTERACTIVE) { + /* TODO: remember what was the frame increment so that it can be used in physics simulation to stick to real time */ + scene->r.cfra = pfra; + } else if (sad->flag & ANIMPLAY_FLAG_REVERSE) { /* jump back to end? */ if (PRVRANGEON) { if (scene->r.cfra < scene->r.psfra) { diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 15e8f950686..0ed0ffcdc15 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1936,6 +1936,7 @@ typedef enum eVGroupSelect { #define SCE_NLA_EDIT_ON (1<<2) #define SCE_FRAME_DROP (1<<3) #define SCE_KEYS_NO_SELONLY (1<<4) +#define SCE_INTERACTIVE (1<<5) /* return flag BKE_scene_base_iter_next functions */ /* #define F_ERROR -1 */ /* UNUSED */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 11d56206d6e..c3d5b8adf13 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -6194,6 +6194,13 @@ void RNA_def_scene(BlenderRNA *brna) "(in timeline and when jumping between keyframes)"); RNA_def_property_update(prop, NC_SCENE | ND_FRAME, NULL); + /* Timeline / Interactive mode */ + prop = RNA_def_property(srna, "use_interactive_mode", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", SCE_INTERACTIVE); + RNA_def_property_ui_text(prop, "Run interactive mode for physics", + "The scene frame is no longer incrementing (and thus animation is stopped) but the physics engine still executes"); + RNA_def_property_update(prop, NC_SCENE | ND_FRAME, NULL); + /* Stamp */ prop = RNA_def_property(srna, "use_stamp_note", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "r.stamp_udata"); -- cgit v1.2.3