== SoC Bullet - Bullet Upgrade to 2.76 ==

Updated Blender's Bullet to 2.76 in this branch only.

This update was done by:
1) deleting the contents of the existing extern/bullet2/src directory (leaving the .svn folder in place),
2) copy/pasting the contents of the bullet/src directory (from unzipped Bullet archive) into this newly cleared folder. 

Hopefully there aren't any patches that are still needed from the Bullet we had in source.

---

Note: I didn't use Moguri's patch, since that was giving me compile errors with headers not being able to be found.

[[Split portion of a mixed commit.]]
== SoC Bullet - Bullet Upgrade to 2.76 ==

Crossing fingers that this time it goes into my branch, not trunk...
== Bullet SoC - Initial Commit of 'Prototype' ==

This commit is my first attempt at implemented the plan described in the design docs I posted. Most of the key architectural details mentioned there are implemented, however, this is really not intended for general user consumption yet.

What is done:
* Basic evaluation loop to run Bullet simulations within normal Blender, and see the results of this in realtime in the viewport
* A few operators to set up a simulation to run in this loop. Use 'Add Active' (Ctrl-R) to add an object controlled by Physics, and 'Add Passive' (Ctrl-Shift-R) to add an object controlled by AnimSys but affecting physics.
* Two basic collision shapes hacked in - cube and sphere. A more refined setup still needed for setting up other collision shapes.
* Basic/key parts of the framework proposed in the design doc - datastructures + core api's

Please be aware that this is a very WIP commit. There are many things missing, especially:
* File I/O Support - this includes undo. So, be very careful with this. Don't try saving out files with it yet, else you'll get some nasty surprises.
* Changing the parameters of the sim will not work yet force a refresh
* Gravity is currently hardcoded (it should take value from scene instead). This is done with a hack to Bullet's C-API, which should be removed later (see next point)
* A better C-API for interfacing with Bullet. I'm currently using the one Bullet supplies, but a new one, tailored better for Blender and more powerful will be the next target.
* Sims can currently only be run once. The new C-API should help with this...

Check the "Bullet SoC - Sneak Peek" post on my blog (http://aligorith.blogspot.com/) for more details and a few video demos...
== Bullet SoC - (WIP Commit) New C-API... ==

This is just a WIP commit for backup purposes. Nothing is guaranteed to compile, so syntax errors/typos are probably abound in this code.

What's done:
* Added new 'RigidBody' module in source/blender to contain our Bullet (and potential other Physics Engine) C-API plugins.
-- Only scons stuff is really setup nicely. I've copied across cmake stuff too, but that'll probably need checking. Makefiles are still missing, but probably best wait on that until I get scons working, to see everything that'll be needed then...

* Added most of the C-API necessary for Bullet. 
-- I've defined access for most of the settings which appear to be actually needed / understandable in physics terms (mass, friction, angular/linear velocities, and a few others)
-- Rigid Bodies are added and use MotionStates now. Hopefully this will get reverse playback working when hooked up
-- Access for all standard collision shapes is ready

* Missing from this API are:
-- Setting/disabling 'activation' - this has yet to be coded
-- Changing collision shape for an object - not yet defined yet
-- Creating collision shapes from meshes - not yet defined yet

* Moved helper function to get the active RigidBodyWorld from Editors to blenkernel

* Added 'start_frame' parameter to RigidBodyWorld, to be hooked up in due course. This should define the reference frame from which all sim parameters can get recalibrated to reduce numerical error accumulation.
== Bullet SoC - (WIP Commit) Everything compiles again ==

* Compiling fixes for Blender and also the RigidBody C-API. Overall, there weren't as many bugs as anticipated :)

* Scons files for RigidBody API are now set up ok...

* Added API calls for getting and setting collision shapes of Rigid Bodies.
Bullet Soc - Renaming RigidBody Module Include File
== Bullet SoC - New API Integrated ==

Changes:
* Replaced calls to the old API with calls to the new one
* Removed temp hack code from Bullet C-API
* Tweaked scons files more so that the libs link ok. This currently doesn't work ok if compiling without Bullet. Requires a bit more work to figure out what to do in that case.
* Removed unneeded cruft from RigidBody structs 

Current Status:
- We're now getting some minimal reverse movement now during reverse playback, but not as much as much as it should be. I'll need to investigate further why this is the case.
- Some of the hackier aspects of the current integration now need to be cleaned up to work with the new API
Bullet SoC - Some tweaks/fixes

Still trying to get to the bottom of a few annoying bugs. In the meantime, worked on a few tweaks to diagnose other problems.

* Added handling for resetting sims. Currently isn't working for undiagnosed reasons yet.
* Figured out how to implement a few settings (angular/linear damping and sleeping thresholds). These turned out to only be settable together in Bullet-API, but here I've allowed to set separately too for more consistent API.
* Tweaked way that 'rbSetTransformMatrix' was working, since the old code wasn't actually setting the intended matrices at all
Bullet SoC - RNA Tweaks:

Rigid Body Worlds
* Added 'Name' property, which just uses the name of the associated group usually, or a dummy
* List box widget now displays Rigid Body Worlds with their name (due to first change) and a checkbox to turn simulation on/off. Inverted name/purpose of the muting property to make this work

Rigid Bodies
* Mass can now be animated
* Added 'Friction' attribute, but this isn't exposed in UI yet
* Changing the type of the RigidBody now works, and can be animated like Mass

Building:
* RNA now depends on the RigidBody C-API too, since that allows the settings to be animated via RNA, and then only the changed properties will be updated by the Animation System (via RNA) instead of requiring a special property syncing step later.
NOTE: as with other changes, I've only tested/fixed this for scons only
== Bullet SoC - Collisions and More ==

Collision Shapes now work properly:
* Fixed implementation of Box and Sphere types so that they result in actual collisions. They were using the full dimensions instead of the distance from the boundbox corners to the center of mass. Now, these calculations assume centered distributions of mass (i.e. pivot is not off to one side of the object)
* Implemented Capsule, Cylinder, and Cone types too while I was at it. 'Mesh' type will have to wait a while, but will be available eventually (more API work needed first) :)
* By default, collision shapes are now automatically set to the most appropriate type based on the type of bounding-box shown for the object (i.e. see 'bounds' setting)
* The 'Shape' property also now works. I've hooked this up so that it can now be changed. As side effect, you can also animate this :)

Improved Blender-Side API's:
* Made the calls to create physics-sim data able to be called outside of rigidbody.c
* Cleaned up some code in preparation for motion-cache support

Playback Bugfix:
* Resetting sims now works properly. 
-- The problem was that objects were not being recalculated on frame changes (missing depsgraph code. More depsgraph changes will still be needed for other things later...). 
-- Also, this is now done by fully refreshing all sim objects instead of trying to get away with resetting some settings, avoiding some internal vars being outdated still.
Bullet SoC - Operator Work...

* Added Add/Remove operators for the active object only, and also tweaked the UI so that the Rigid Body panel shows with these buttons as in all the other Physics Systems.

* Hooked up freeing code, so that there aren't warnings about unfreed stuff on exit anymore. Still need to double-check all that all the Bullet-side stuff does get freed, so I might need to make some tweaks there too

* Added operators to remove objects from RigidBody simulations

* Friction is now exposed in UI. Also, it gets a default value of 0.5 (which Bullet also seems to use). In Bullet code, there's a comment that this should be non-zero for the best results (i.e. in real-world terms, ice should have friction of 0 and is slippery/floaty...)
== Bullet SoC - RNA Fixes + Error Handling ==

* Added error checks when trying to add objects to rigidbody sims. These enforce that active objects can only belong in one sim at a time. Also, it warns when an object already exists in the current sim world.

* Added RNA path-building functions so that settings can have keyframes set. For some reason, some settings don't seem to be animating correctly though. Then again, trying to playback again those settings fails too. To be investigated further...

* Added a few helper macros for a few useful situations...

* Removed some unused code
Bullet SoC - Doh!

Bugfix for crashes when changing collision shapes. Bullet was not being informed about the shape change.
Bullet SoC - WIP Commit (File IO)

I've started coding the File IO stuff. However, I've run into some problems trying to get the data to load again (which I've never ever seen before so far), which currently seem like they're caused by the data not being saved at all. Ideas on solving this are welcome.

Also fixed extra warning print for remove rigidbody operator.
Bullet SoC - File IO Fixed

It turns out that makesdna was getting confused by some temp comments I had left in, resulting in the relevant structs being assumed to be of length 0.
Bullet SoC - Sim Loop Tweaks

Removed the special skip-everything case for timestep=0 case, since this resulted in jumpy and seemingly erratic results. Better just run the sim normally in this case for now. Later, it might be possible to use the cached results too or instead.
Bullet SoC - Fixes for collision problems seen while creating latest set of videos

* Shapes for cone, cylinder, and capsule were using the Bullet calls (default versions, as seen in old Bullet C-API were Y-Axis, while we should have used Z-Axis versions), subsequently resulting in incorrect collision detection during the demos at times. This manisfested as the shapes passing through the ground plane during demo 5.

* Capsule shape now uses the proper Bullet shapes instead of using a hack of joined multi-spheres

* All 'passive' RigidBodies are now treated as 'kinetic' for now. This means that they are treated as all being animated, which should allow interaction between animated objects and sim objects again, so I should be able to record demo 6 later today at last :). Later, I might add a separate API call to set this, but I'll leave that for now...
Bullet SoC - Exposing some more collision parameters:

* 'Bounciness' of object - this is known in Bullet terms as 'Restitution' (http://en.wikipedia.org/wiki/Coefficient_of_restitution). However, since I had to look this up to understand it, I'm guessing that choosing a more common name may be more suitable.

* Collision Margin - threshold for sensitivity of collision detection. This should be left on its default value for spheres.
Bullet SoC - More UI/Property Tweaks...

* Revamped UI for Rigid Body Worlds and Rigid Body Objects, with the latter now being split into two panels (Rigid Body, and Rigid Body Collision) to hopefully reveal the structure of the settings better. I'm still not too sure about whether one or two tweaks there make things harder to quickly set in practice, but hopefully there shouldn't be any problems :)

* Revamped the Scene settings regarding substeps. These are now available in the UI, and can be used to improve collision accuracy. 
-- Added new RB-API call which accomodates these settings, leaving the other version to do default values only, though that isn't used now...
-- Any files saved previously may now have some problems with playback. For reference/manual fixing, the 'Substeps' parameters should be 1/60 and 10.

* Added 'Reset' operator for Rigid Body Worlds, which changes the current frame to the 'start' frame for the world or worlds based on its primary parameter. 
-- The version called from the Scene buttons resets with respect to the current/active world only
-- Search for the other operator to use it. It will take the earliest start-frame value for a Rigid Body World in the Scene
Bullet SoC - Influence Controls:

It is now possible to control the amount the physics simulation contributes to a simulation, and the transform channels this occurs for.