Fix #107956: Simulation reset on fps change #108004

Merged
YimingWu merged 5 commits from ChengduLittleA/blender:fix-107956 into main 2023-05-31 10:06:05 +02:00
4 changed files with 25 additions and 0 deletions

View File

@ -17,6 +17,8 @@ void BKE_simulation_data_update(struct Depsgraph *depsgraph,
struct Scene *scene,
struct Simulation *simulation);
void BKE_simulation_reset_scene(Scene *scene);
#ifdef __cplusplus
}
#endif

View File

@ -162,6 +162,8 @@ class ModifierSimulationCache {
CacheState cache_state_ = CacheState::Valid;
bool failed_finding_bake_ = false;
float last_fps_ = 0.0f;
ChengduLittleA marked this conversation as resolved Outdated

That does not seem quite right, not sure why delta_seconds_ should be stored. It kind of conflicts with the future possibility to have adaptive subframes. Would likely be better to just store the fps here. Even better might to somehow hook the reset up to rna_Scene_fps_update but that can also be done later.

That does not seem quite right, not sure why `delta_seconds_` should be stored. It kind of conflicts with the future possibility to have adaptive subframes. Would likely be better to just store the fps here. Even better might to somehow hook the reset up to `rna_Scene_fps_update` but that can also be done later.
void try_discover_bake(StringRefNull absolute_bake_dir);
bool has_state_at_frame(const SubFrame &frame) const;

View File

@ -10,6 +10,7 @@
#include "DNA_ID.h"
#include "DNA_defaults.h"
#include "DNA_modifier_types.h"
#include "DNA_scene_types.h"
#include "DNA_simulation_types.h"
@ -24,15 +25,18 @@
#include "BKE_anim_data.h"
#include "BKE_animsys.h"
#include "BKE_collection.h"
#include "BKE_customdata.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_lib_remap.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
#include "BKE_node.hh"
#include "BKE_pointcache.h"
#include "BKE_simulation.h"
#include "BKE_simulation_state.hh"
#include "NOD_geometry.h"
@ -181,3 +185,17 @@ void BKE_simulation_data_update(Depsgraph * /*depsgraph*/,
Simulation * /*simulation*/)
{
}
void BKE_simulation_reset_scene(Scene *scene)
{
FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
if (md->type != eModifierType_Nodes) {
continue;
}
NodesModifierData *nmd = (NodesModifierData *)md;
nmd->simulation_cache->reset();

Please try it, but I'd assume that you can work on nmd directly instead of using nmd_orig.

Please try it, but I'd assume that you can work on `nmd` directly instead of using `nmd_orig`.
}
}
FOREACH_SCENE_OBJECT_END;
}

View File

@ -712,6 +712,7 @@ static const EnumPropertyItem snap_to_items[] = {
# include "BKE_pointcache.h"
# include "BKE_scene.h"
# include "BKE_screen.h"
# include "BKE_simulation.h"
# include "BKE_unit.h"
# include "NOD_composite.h"
@ -930,6 +931,8 @@ static void rna_Scene_fps_update(Main *bmain, Scene *UNUSED(active_scene), Point
* however, changes in FPS actually modifies an original skip length,
* so this we take care about here. */
SEQ_sound_update_length(bmain, scene);
/* Reset simulation states because new frame interval doesn't apply anymore. */
BKE_simulation_reset_scene(scene);
}
static void rna_Scene_listener_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)