Rigid body point cache jumps #50230

Closed
opened 2016-12-11 11:29:27 +01:00 by Kai Kostack · 9 comments

We noticed some unclean behaviour when working with rigid bodies, which leads to bad simulation results. When scrubbing through the timeline the last simulation state is being used for later continuation of the "main" simulation, which doesn't always work as shown in the following example.

Steps to reproduce based on the attached blend file:
rigid-body-cache-jump.png

  1. Start simulation (Alt+a)
  2. Stop simulation (Alt+a)
  3. Jump to a future point in the timeline and simulate a bit further and stop again
  4. Jump back to start range and continue the already cached simulation (or press Bake)

Resulting simulation with motion path and frame numbers:
rigid-body-cache-jump2.png

rigid-body-cache-jump.blend

Tested on Windows 7 x64 with the official buildbot version.

We noticed some unclean behaviour when working with rigid bodies, which leads to bad simulation results. When scrubbing through the timeline the last simulation state is being used for later continuation of the "main" simulation, which doesn't always work as shown in the following example. Steps to reproduce based on the attached blend file: ![rigid-body-cache-jump.png](https://archive.blender.org/developer/F416619/rigid-body-cache-jump.png) 1. Start simulation (Alt+a) 2. Stop simulation (Alt+a) 3. Jump to a future point in the timeline and simulate a bit further and stop again 4. Jump back to start range and continue the already cached simulation (or press Bake) Resulting simulation with motion path and frame numbers: ![rigid-body-cache-jump2.png](https://archive.blender.org/developer/F416621/rigid-body-cache-jump2.png) [rigid-body-cache-jump.blend](https://archive.blender.org/developer/F416626/rigid-body-cache-jump.blend) Tested on Windows 7 x64 with the official buildbot version.
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @KaiKostack-3

Added subscriber: @KaiKostack-3
Member

Added subscriber: @LucaRood-3

Added subscriber: @LucaRood-3
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Luca Rood self-assigned this 2017-01-08 04:54:20 +01:00
Member

I finally had some time to look into this...

The issue is that the rigid body simulation state isn't updated when read from cache. But the greater issue is that rigid body cache is currently only storing positions and rotations, so even if the simulation state is updated from the cache, we can only update the positions/rotations, and not the velocities.

This little diff calls a simulation state update when the cache is read, and thus correctly sets the position even when the timeline is set back to the initial cached bit after having jumped a few frames... But notice that the speed is reset to 0, so despite being in the correct location, you'll see your objects suddenly stopping, and re-accelerating.

P435: Rigid body cache update

diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index b5f34a2..447f459 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1583,6 +1583,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 	bool can_simulate = (ctime == rbw->ltime + 1) && !(cache->flag & PTCACHE_BAKED);
 
 	if (BKE_ptcache_read(&pid, ctime, can_simulate)) {
+		rigidbody_update_simulation(scene, rbw, true);
 		BKE_ptcache_validate(cache, (int)ctime);
 		rbw->ltime = ctime;
 		return;

So this diff is only really a demonstration, and doesn't really fix the issue at all. To resolve this, the velocities would have to be cached as well, which isn't really worth the trouble for now, especially with this outdated caching system...

So I'm closing this for the time being... But I have added this to ToDo, and this shall probably be addressed with an eventual cache overhaul (provided it is even possible to get/set the velocities from Bullet...).
https://wiki.blender.org/index.php/Dev:Source/Development/Todo/Tools#Rigid_Body

I finally had some time to look into this... The issue is that the rigid body simulation state isn't updated when read from cache. But the greater issue is that rigid body cache is currently only storing positions and rotations, so even if the simulation state is updated from the cache, we can only update the positions/rotations, and not the velocities. This little diff calls a simulation state update when the cache is read, and thus correctly sets the position even when the timeline is set back to the initial cached bit after having jumped a few frames... But notice that the speed is reset to 0, so despite being in the correct location, you'll see your objects suddenly stopping, and re-accelerating. [P435: Rigid body cache update](https://archive.blender.org/developer/P435.txt) ``` diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index b5f34a2..447f459 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1583,6 +1583,7 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime) bool can_simulate = (ctime == rbw->ltime + 1) && !(cache->flag & PTCACHE_BAKED); if (BKE_ptcache_read(&pid, ctime, can_simulate)) { + rigidbody_update_simulation(scene, rbw, true); BKE_ptcache_validate(cache, (int)ctime); rbw->ltime = ctime; return; ``` So this diff is only really a demonstration, and doesn't really fix the issue at all. To resolve this, the velocities would have to be cached as well, which isn't really worth the trouble for now, especially with this outdated caching system... So I'm closing this for the time being... But I have added this to ToDo, and this shall probably be addressed with an eventual cache overhaul (provided it is even possible to get/set the velocities from Bullet...). https://wiki.blender.org/index.php/Dev:Source/Development/Todo/Tools#Rigid_Body
Member

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'
Member

I'm reopening this, because I realized that I shouldn't try to fix it by having everything cached and then rolling back once you go to to a point in time before a cache gap. Having a simulation with a time gap in it doesn't actually make any sense at all, so I realized that I should rather prevent the cache from forming such a gap in the first place.

That is a trivial fix, and should prevent accidental rigid body cache corruption by the user if playing outside of the currently cached period.

I'm reopening this, because I realized that I shouldn't try to fix it by having everything cached and then rolling back once you go to to a point in time before a cache gap. Having a simulation with a time gap in it doesn't actually make any sense at all, so I realized that I should rather prevent the cache from forming such a gap in the first place. That is a trivial fix, and should prevent accidental rigid body cache corruption by the user if playing outside of the currently cached period.

This issue was referenced by 9cd6b03187

This issue was referenced by 9cd6b03187b91bb2c267a45eac3cee7738e0e220
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#50230
No description provided.