Giter VIP home page Giter VIP logo

bullet-ane's Introduction

Bullet.ane

An Adobe AIR Native Extension for the Bullet Physics Simulation Library

Imbue your AIR mobile and desktop apps with the magic of physics!

Compared with AwayPhysics, Bullet.ane increases performance on mobile apps by an order of magnitude. See a video comparison: http://youtu.be/IH4mrUagA74

Currently written to work with Away3D, but certainly could be made compatible with other Stage3D-based AS3 graphics libraries.

True native implementations are built for iOS (7.0 SDK), iOS Simulator, and Android. All other platforms (which I think is only desktops now that Android is supported, right?) fall back on AwayPhysics, a pure-AS3 implementation of Bullet, meaning the extension will work on all platforms AIR supports.


The rest of the README:

  • Getting Started
  • Building the ANE
  • Comparison to AwayPhysics and Bullet C++ Lib
    • Bullet.ane vs. Bullet C++ Lib
    • Bullet.ane vs. AwayPhysics
    • Nested Meshes
    • A Word on Scaling
  • To-do
  • Links

Getting Started

For convenience, the compiled extension is included in the repository, located at as3/aneBulletTester/ane/Bullet.ane. Usage examples can be found in as3/aneBulletTester/src/.

If you're already familiar with using ANEs, then go wild.

But if this is your first ANE experience... To add it to your ActionScript Mobile project in Flash Builder 4.7 (sorry, I don't know about other IDEs), right-click your project and select Properties, then click ActionScript Build Path on the left side-bar, then Native Extensions across the top, then Add ANE...

Finally, ensure the extension gets packaged with your debug and release builds; from the Properties window, twist open ActionScript Build Packaging on the left and select Apple iOS, then click Native Extensions across the top and ensure that the Package checkbox is checked. Do the same with the Android platform.

Building the ANE

If you're the type that's going to build Bullet.ane from source, this section should help. It might not be very complete, so I apologize -- ask on GitHub if you need help (github.com/mziwisky/bullet-ane).

First off, if you don't have a Mac, I can't help you (yet), because I'm building the native iOS library with Xcode. Also, I rely on Flash Builder for the ActionScript compilation, so I can't help with other IDEs.

OK, you'll need to acquire the following AS3 dependencies:

as3/aneBulletLib depends on Away3D and as3/aneBulletDefault depends on both. Build those two aneBullet* projects.

Then, cd to native/bullet-itself and run ./fetchSourceAndMakeXcodeProjects.bash.

Then, open native/ios/BulletANE/BulletANE.xcodeproj in Xcode and build it for both iOS Device and iPad Simulator.

Then, cd back to the top directory and edit the properties in build.xml to accomodate your system. Most of it should be alright, but you may need to change airsdk.dir and iossdk.dir.

Finally, run ant in the top directory.

Again, if anything goes wrong here that you can't figure out on your own, feel free to contact me on GitHub.

Comparison to AwayPhysics and Bullet C++ Lib

Bullet.ane is certainly inspired by AwayPhysics, but where AwayPhysics methods differ from their Bullet Lib counterpart, Bullet.ane tends to favor the Bullet C++ Lib version over the AwayPhysics version. This choice was made so that the Bullet Lib documentation, forum posts, etc. are more likely to be accurate and helpful in using Bullet.ane.

For example, the AwayPhysics method AWPRigidBody::applyForce() implicitly calls AWPRigidBody::activate() after applying the force. Bullet Lib's btRigidBody::applyForce() does not implicitly call btRigidBody::activate(), and nor does Bullet.ane's RigidBody::applyForce() call RigidBody::activate().

There are, however, a few things I preferred about AwayPhysics' API, so I made some deviations from Bullet Lib in a few spots.

For example, the Generic6DofConstraint constructor takes a position vector and rotation vector argument for each of the two involved bodies' frames, rather than a transform matrix for each of the frames.

I won't make a comprehensive list here of the differences between Bullet.ane and AwayPhysics, but I'll try to note all the differences between the semantics of Bullet.ane and Bullet Lib which might lead to headaches if you don't realize them. I'll also point out a few ways in which Bullet.ane tends to differ from AwayPhysics.

Bullet.ane vs. Bullet C++ Lib

  • The Bullet.ane DiscreteDynamicsWorld constructor will create a world with the same default configuration that AwayPhysics uses in its ::initWithDbvtBroadphase() method. So you don't have to do all the typical boilerplate code that Bullet Lib requires. On the other hand, you don't have control over the things that the boilerplate code constructs, like the CollisionConfiguration and CollisionDispatcher.
  • The Bullet.ane DiscreteDynamicsWorld::addRigidBody() method, when called without the optional group and mask parameters, defaults to group=1 and mask=-1. This is indeed what Bullet Lib does for dynamic (i.e., non-static && non-kinematic) RigidBodies, but not for non-dynamic bodies.
    Bullet.ane does so regardless of the dynamic-ness.
  • The Bullet.ane BoxShape takes full-extents as parameters. The Bullet Lib counterpart takes half-extents.

Bullet.ane vs. AwayPhysics

  • Bullet.ane performs initialization of a DiscreteDynamicsWorld within the constructor as opposed to AwayPhysics, which requires a call to AWPDynamicsWorld::initWithDbvtBroadphase() after construction.
  • AwayPhysics expects any arguments that are rotation vectors to be Euler angles in degrees. Bullet.ane expects them to be Euler angles in radians.
  • Bullet.ane often expects a Matrix3D defining a transform as a method parameter where AwayPhysics would expect a pair of Vector3Ds defining a position and a rotation. E.g., in CompoundShape::addChildShape().

Nested Meshes

Here's what happened. I was building this app which had an ObjectContainer3D hierarchy. (NOTE: I'm going to talk about some Away3D classes here, like ObjectContainer3D. And Mesh.) Each visible Mesh was a child of one of a set of invisible ObjectContainer3Ds, and each of those ObjectContainer3Ds was a child of the Scene3D. The ObjectContainer3Ds each had a non-identity transform, as did each of the visible Meshes.

I wanted the Meshes to act like physical objects, so I associated each one with a RigidBody, but I did not want the ObjectContainer3Ds to be involved in the physics. An Away3D Mesh can have its local transform matrix manipulated directly, but not its scene transform. So when I let Bullet take control over the Meshes transforms, it treated them all as direct children of a single scene, not realizing that their visual representation was actually modulated by the transform of their parent ObjectContainer3Ds. This caused problems such as objects colliding when they were visually very far apart, e.g., if they each have a local transform of identity, but their parents have transforms that are far from each other.

To reconcile this, the DiscreteDynamicsWorld constructor takes a boolean parameter, expectNestedMeshes, which defaults to false. If it's set to true, then the scenario I described above is fixed; the ANE uses the inverse scene transform of each Mesh's parent to figure out how to set the Mesh's local transform such that its scene transform correctly matches its Bullet world transform.

Most people won't need to deal with this, because the typical use case will be to add Bullet-controlled Meshes directly to the Scene3D, not to parent containers.

A Word on Scaling

By default, the Bullet C++ Lib assumes all units to be SI -- sizes and positions are meters, masses are kilograms, time is seconds, etc. Bullet Lib works best when moving objects are in the size range of 0.05 to 10.0 units (meters). Refer to the Bullet wiki page on scaling the world.

As a convenience, the DiscreteDynamicsWorld constructor takes a scaling parameter, and the ANE multiplies all user-specified positions and sizes by (1/scaling) before it passes those values to the Bullet library.

Therefore, 1 Bullet unit equals scaling visual (Away3D) units.

The default scaling is 100. So by default, the ANE will work best when moving objects are created with a size in the range of 5 to 1000.

Note that ONLY sizes and positions get scaled. In spite of what the referred wiki page suggests, we don't scale velocities, torques, etc. So a scaling of 100 can be interpreted as follows. All positions and sizes (both input to and output from the ANE) are in centimeters, but all other units remain SI.
Therefore velocities are m/s (not cm/s), accelerations -- in particular acceleration due to gravity -- are m/s^2, forces are Newtons, torques are Newton-meters, etc. Note that this agrees with the convention that AwayPhysics uses (i.e., only scaling distances and sizes).

To-do

An abbreviated list of things on the to-do list for the ANE. Feel free to contribute!

  • Native Desktop lib. Right now it falls back on AwayPhysics, which is awesome, but performs significantly worse than native code.
  • Add support for other Stage3D-based graphics libraries.
  • Maybe make a big start-to-finish build script if enough people are interested in such a thing.
  • Add collision callbacks.
  • More and more API exposure.

Links

Bullet Physics Library

AIR Native Extensions

bullet-ane's People

Contributors

mziwisky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bullet-ane's Issues

ANE for Android

Hi,

Could you tell me if and when do you plan to release bullet-ane for Android?

Thank you.

Christian

Library doesn't have some Away3d classes

Hello. Your compiled library doesn't have some classes. For example, away3d.materials.lightpickers.StaticLightPicker is missing. And many others. I tried to build aneBulletLib by myself too and got the same results.
Next, aneBulletDefault is not compiled at all. It fails on ane.bulletphysics.collision.dispatch.CollisionWorld in contactTest() method. That's because awayphysics.collision.dispatch.AWPCollisionWorld doesn't have contactTest() method. And there're tons of other errors.

Away3D 4.1.6

Hi!
I'd like to thank you for this extension - You've done a great work! It has a great performance on mobile :)

I've used this ane with away3d 4.1.4 with no problems, but updating to 4.1.6 caused errors:(
because they added (at least) decompose method to away3d.core.math.Matrix3DUtils class.

Other point - x64 support for iOS required from February 2015 (https://forums.adobe.com/message/6850180#68501800 )

I've downloaded your source to re-build by myself.. But (I've just read the readme:( ) I dont have Mac :(
I've downloaded Mac Image for virtual machine (vmware).. with no success 'cause my CPU is AMD..
I'll try completely clear Mac install.. but I'm not sure it will power on (

If you have a configured working project, can you re-build ane with latest away3d framework and iOS-64 support, please? :)

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.