Commit Graph

52 Commits

Author SHA1 Message Date
2ac9e8587b Dirty fix for memory corruption in the rigid body API.
Problem happens when removing a rigid body reference in a constraint,
and then jumping to the start frame right away. This will cause a full
rebuild of the rigid body world. However, the btRigidBodys are removed
before the constraints, and this leaves dangling pointers in the
btTypedConstraints, which causes corruption when deleting those
constraints later.

Fix for now is to explicitly delete constraints in advance when
rebuilding, while they still have valid btRigidBody pointers.

Ultimately the whole memory management and ownership of Bullet data
needs redesign. This is already happening in the particles_refactor
branch and could be ported to master separately:
https://developer.blender.org/diffusion/B/browse/particles_refactor/source/blender/blenkernel/intern/rigidbody.c
2014-05-14 11:51:24 +02:00
e2672a433b Fix crash removing objects rigid body constraints 2014-05-12 14:55:54 +10:00
4ca67869cc Code cleanup: remove unused includes
Opted to keep includes if they are used indirectly (even if removing is possible).
2014-05-01 04:47:51 +10:00
617557b08e Code cleanup: remove TRUE/FALSE & WITH_BOOL_COMPAT define 2014-04-01 15:22:28 +11:00
30c9fe19a3 Fix for crash caused by effectors doing precalculation //during// DAG
updates.

This file crashes on loading with NULL pointer access to curve_cache:
{F77132}

The pdInitEffectors function was amalgamating the simple
collection of effector objects with an automatic precalculation for
curve guides and the like. This precalculation requires object data
that may not be available until the DAG has finished.

Since for DAG dependencies only the list of effectors is required,
added an argument to disable precalculation when collecting effectors.
2014-02-14 12:58:43 +01:00
f17a1bd58b Fix T38388: Creating a new scene with full copy sets rigidbody collision shapes to box.
Tweak world rebuilding logic, so it's not done before object data was
updated.
2014-01-29 15:03:41 +01:00
ea1ed3f4aa Rigidbody: Code cleanup
Convert int to bool.
2014-01-04 04:22:20 +01:00
24c807ffd4 Code Cleanup: unused defines & style 2013-12-30 10:58:18 +11:00
4841acbecd Rigidbody: Code cleanup
Make some functions private.
Remove unneeded nested if statements.
Avoid mixing short and bool.
2013-12-26 21:33:58 +01:00
ceb2430dd7 Rigidbody: Allow triangle mesh shapes to deform during simulation
Only supported when using the "Deform" mesh source.
2013-12-26 18:38:06 +01:00
c96601138d Rigidbody: Use own structure to store mesh data for collision shapes
This gives us better access to the data and should also be faster to
create.
2013-12-26 18:38:06 +01:00
2260a7dbc0 Rigidbody: Add option to choose mesh source for collision shapes
The options are:
Base: Base mesh
Deform: shape keys and deform modifiers
Final: All deformations and modifiers

It would be nice to have a way of specifying where exactly in the
modifier stack the collision shape is generated. However this is not
staight forward since the rigid body simulation is not part of the
modifier system and would require hacks to make it work.
2013-12-26 18:38:05 +01:00
a5606fadbb Code Cleanup: remove object arg to CDDM_from_mesh mesh_create_derived 2013-12-26 08:27:08 +11:00
beae4f498d code cleanup: spelling 2013-10-31 14:10:01 +00:00
af915b443a Fix [#36847] If Force Field in Ridgid Body group, crash at first frame of animation on playback
Not all objects in RB group actually have a "rigid body object", needs to be checked.
2013-09-29 13:38:56 +00:00
08ef5adb93 Fixes for recent Wlimit stuff, which makes strict gcc freak out 2013-07-21 14:26:27 +00:00
7db1d6556d code cleanup: add break statements in switch ()'s, (even at the last case). 2013-07-21 08:16:37 +00:00
a51b5c676e rigidbody: Code clenup
Remove duplicate null check.
2013-07-04 08:52:27 +00:00
734e49ade6 rigidbody: Remove constraint when removing one of it's objects
This is not the nicest behaviour but trying to keep both bullet and
blender side objects in sync breaks in this case.
There might be a better soluion but this avoids crashes for now.

Fixes: [#35995] Delete crash on specific scene (Physics)
2013-07-04 08:52:24 +00:00
ec8d277c64 BLI_math rename functions:
- mult_m4_m4m4 -> mul_m4_m4m4
- mult_m3_m3m4 -> mul_m3_m3m4

these temporary names were used to avoid problems when argument order was switched.
2013-05-26 18:36:25 +00:00
ed68497700 style cleanup 2013-04-25 16:35:57 +00:00
2043d801e8 Fix #34806: rigid body world settings were not copied with a full scene copy.
Now copying a scene will also duplicate groups that consist entirely of objects
that are duplicated with the scene. The rigid body world will then also pointers
to these new groups.
2013-04-24 23:09:25 +00:00
42e8f3e889 rigidbody: Fix/workaround for transforming rigid bodies with parents
Since we use the rigid body transform when transforming rigid bodies
things like parents and constraints add an offset because rigid body
transforms are in global space.

Now we just don't take rigid body transform into account on simulation
start frame so there are no problems when doing the initial setup.

The problem still exists when simulation is running of course.
To properly fix this we'd have to solve parenting and constratins while
taking rigid bodies into account before and after transform.
We'll have to see if it's really needed, would like to avoid it though.
2013-04-07 14:09:29 +00:00
879e4fd9be sequencer gaps
- remove unneeded checks (poll checks editor is non-null)
- use booleans
- rename operator SEQUENCER_OT_gap_remove, _gap_insert

also quiet shadow warning in rigidbody.c (shadowing 'loc')
2013-03-26 20:34:13 +00:00
0807c976f4 code cleanup: rename BKE_mesh_to_curve_ex --> BKE_mesh_to_curve_nurblist,
also correct odd indentation.
2013-03-15 10:48:48 +00:00
2921d48239 code cleanup: unused vars in collada, preprocessor formatting & warning in mingw.
also compiling without bullet needed a stub added.
2013-03-04 00:53:57 +00:00
ceaf8e48ef rigidbody: Revert to running simulation on frame update
Instead of flagging the rigid body world for frame update just call
BKE_rigidbody_do_simulation() recursively for all scenes.

This avoids having to constantly check if the simulation needs to be
updated.
2013-03-03 06:09:48 +00:00
5ff6a5c6ab rigidbody: Fix inconsistency with world rebuilding
The rigid body world could be rebuilt on start frame and one frame after
start frame. The latter was necessary sice animation playback usually
doesn't start at start frame.
This lead to different simulations depending on which frame the
simulaton was rebuilt when animation was involved.

Now we only rebuild the world on start frame.
This is actually tricky to do since, as mentioned above, animation
playback starts on second frame. To work around this we rebuild the
world before the actual update.
The alternative would be to rebuld the world on every simulation change
(like the other simulations do it) but this is an expensive operation
and would be too slow.
2013-03-03 06:09:45 +00:00
be8bda5abc rigidbody: Don't embed collision margin if object has no volume
While it's not a good idea to create convex hull shapes from objects
with no volume, this makes them behave a little nicer.

Fixes [#34410] Planes with Rigid Body always keep distance to colliding objects
2013-02-25 15:51:53 +00:00
c82213359a rigidbody: Add motor constraint
It's implemented as a separate constraint instead of adding properties
to the existing constraints.
Motors only apply linear and angular impulses and don't limit the
movement of rigid bodies, so it's best to use them in conjunction with
other constraints to limit the degrees of freedom.

Thanks to Markus Kasten (markus111) for the initial patch.
2013-02-23 23:04:07 +00:00
2f0eec488c rigidbody: Properly handle constrained objects not having rigid bodies
This is a pretty rare case that can be triggered by switching rigid body
and constraint groups before simulation was validated.
Code checked for existing physics objects but was missing else block.
2013-02-20 00:45:53 +00:00
3e5f6293b6 rigidbody: Don't run simulation if cache is baked
In rare cases this would allow the simulation to run before being
initialized (if cache is baked and reading cache fails after undo or
loading a file).
2013-02-19 20:04:08 +00:00
2e0017efd4 code cleanup: change order of args in void BKE_object_where_is_calc_time_ex() so extra arg is at the end (loose convention for *_ex() funcs). also some style cleanup. 2013-02-17 03:57:20 +00:00
fda8927d01 rigidbody: Further fix for background scenes
Since rigid bodies need their world to be be updated correctly we now
pass it alongside the parent scene in scene_update_tagged_recursive().

Add BKE_object_handle_update_ex() as well as other object functions
that take a RigidBodyWorld for this.

Ideally this shouldn't be needed but we'd have to restructure scene
handling for that. It's not a small taks however and definitely not
something that can be done before release.

Thanks to Campbell for review.
2013-02-16 16:17:45 +00:00
6072322312 rigidbody: Avoid unnecessary simulation updates
Now we flag the world for update on frame change and only call
BKE_rigidbody_do_simulation() when needed.
2013-02-15 23:48:36 +00:00
4d32e9a49e Bugfix [#33970] Background Scene does not show animation of rigid body objects
This was caused by multiple instantiations of the same basic problem. The
rigidbody handling code often assumed that "scene" pointers referred to the
scene where an object participating in the sim resided (and where the rigidbody
world for that sim lived). However, when dealing with background sets, "scene"
often only refers to the active scene, and not the set that the object actually
came from. Hence, the rigidbody code would often (wrongly) conclude that there
was nothing to do.

For example, we may have the following backgound set/scene chaining scenario:
"active"  <-- ... <-- set i (rigidbody objects live here) <-- ... <-- set n

The fix here is a multi-part fix:
1) Moved sim-world calculation from BKE_scene_update_newframe() to
scene_update_tagged_recursive()
    + This is currently the only way that rigidbody sims in background sets will
get calculated, as part of the recursion
     - These checks will get run on each update. <--- FIXME!!!

2) Tweaked depsgraph code so that when checking if there are any time-dependent
features on objects to tag for updating, the checking is done relative to the
scene that the object actually resides in (and not the active scene). Otherwise,
even if we recalculate the sim, the affected objects won't get tagged for
updating. This tagging is needed to actually flush the transforms out of the
RigidBodyObject structs (written by the sim/cache) and into the Object
transforms (obmat's)

3) Removed the requirement for rigidbody world to actually exist before we can
flush rigidbody transforms. In many cases, it should be sufficient to assume
that because the object with rigidbody data attached has been tagged for
updates, it should have updates to perform. Of course, we still check on this
data if we've got it, but that's only if the sim is in the active scene.
   - TODO: if we have further problems, we should investigate passing the
"actual" scene down alongside the "active" scene for BKE_object_handle_update().
2013-02-15 11:49:22 +00:00
6738c941ff rigidbody: Relink constraints when duplicating objects
This will preserve constraint <-> rigid body realationships so
constraint setups aren't broken after duplication.

Based on a patch by Brandon Hechinger (jaggz), thanks.
2013-02-09 10:04:25 +00:00
296444e1dc style cleanup: some warnigs & spelling. 2013-02-06 14:02:19 +00:00
e9ef8d6eff rigidbody: Avoid always making passive objects kinematic
It's only needed when they're being transformed.
Also deactivate passive objects after transformation so they don't keep
acitvating deactivated objects.

Fixes issues with using "start deactivated".
2013-02-04 23:50:38 +00:00
ace88b6962 rigidbody: Fix [#34108] Rigid body with no polygons crashes blender
Fall back to using box shape in case creating shape from mesh fails.
2013-02-04 23:50:36 +00:00
ae27a548f8 rigidbody: Fix [#34106] Deleting an object with Bullet Constraint crashes Blender
Constraints are deleted before rigid bodies so need to check if constraint
exists in case both the constraint and ridid body are on the same object.
2013-02-04 23:50:31 +00:00
5489d5c2b5 rigidbody: Fix [#33971] Bullet Physics crash + patch
BKE_rigidbody_aftertrans_update() can be called before rigid body is
validated so check before updating physics_object.

Thanks to Antony Riakiotakis (psy-fi) for the initial patch.
2013-01-24 03:49:30 +00:00
c24777ee9e style cleanup 2013-01-23 23:42:18 +00:00
Lukas Toenne
6558a22b91 Fix for missing function stub when WITH_BULLET is disabled. 2013-01-23 14:55:41 +00:00
419ce840f9 rigidbody: Make rigid bodies kinematic during transformation
This allows moving rigid bodies on frame > startframe.
Also rigid bodies can now be picked up and trown around while the
simulation is running.

Note: There is a small glitch with cancelling tansform during simulation
but it's tricky to get rid of.

TODO: Avoid static-static collision warnings
2013-01-23 12:06:18 +00:00
69ddc5eb99 make bullet optional again 2013-01-23 07:26:39 +00:00
c48238fac6 rigidbody: Add generic spring constraint
Behaves like the generic constraint but has optional spring on each axis.

TODO: Add option to set rest length.

Patch by Markus Kasten (markus111), thanks!
2013-01-23 05:57:01 +00:00
47c96081d0 rigidbody: Add rigid body constraints
Constraints connect two rigid bodies.
Depending on which constraint is used different degrees of freedom
are limited, e.g. a hinge constraint only allows the objects to rotate
around a common axis.

Constraints are implemented as individual objects and bahave similar to
rigid bodies in terms of adding/removing/validating.

The position and orientation of the constraint object is the pivot point
of the constraint.

Constraints have their own group in the rigid body world.

To make connecting rigid bodies easier, there is a "Connect" operator that
creates an empty objects with a rigid body constraint connecting the selected
objects to active.

Currently the following constraints are implemented:
* Fixed
* Point
* Hinge
* Slider
* Piston
* Generic

Note: constraint limits aren't animatable yet).
2013-01-23 05:56:56 +00:00
2d8637946b rigidbody: Add rigid body simulation
Add operators to add/remove rigid body world and objects.
Add UI scripts.

The rigid body simulation works on scene level and overrides the
position/orientation of rigid bodies when active.
It does not deform meshes or generate data so there is no modifier.

Usage:
* Add rigid body world in the scene tab
* Create a group
* Add objects to the group
* Assign group to the rigid body world
* Play animation
For convenience the rigid body tools operators in the tools panel of the 3d view
will add a world, group and add objects to the group automatically so you only have
to press one button to add/remove rigid bodies to the simulation.

Part of GSoC 2010 and 2012.
Authors: Joshua Leung (aligorith), Sergej Reich (sergof)
2013-01-23 05:56:44 +00:00
089cf12435 rigidbody: Add point cache support
Add read/write/interpolate functions.

In order to get rigid body point cache id from object it's now required to pass the
scene to BKE_ptcache_ids_from_object().

Rigid body cache is drawn in the orange color of the bullet logo.
2013-01-23 05:56:34 +00:00