Skip to content

Commit

Permalink
updated builds, plus wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Aug 16, 2011
1 parent 51da16b commit 0d605ae
Show file tree
Hide file tree
Showing 6 changed files with 2,581 additions and 2,351 deletions.
11 changes: 10 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ autogenerated binding code. A complete example appears in
examples/hello_world.js

That is HelloWorld.cpp from Bullet, translated to JavaScript. Other examples
in that directory might be useful as well. In particular see the webgl
in that directory might be useful as well. In particular see the WebGL
demo code in

examples/webgl_demo/ammo.html

The WebGL demo by default uses builds/ammo.js, which is a wrapped build.
Wrapped builds enclose all of ammo.js in a closure (using wrap.py). This keeps
the global namespace free and avoids name collisions with the rest of your
code (but it has a minor speed penalty). In a wrapped build, accessing ammo.js
elements is through Ammo.*, for example, Ammo.btVector3, etc.

Note that most of the example code in examples/ does not assume a wrapped
build, for simplicity.


API Differences
===============
Expand Down
4,233 changes: 2,124 additions & 2,109 deletions builds/ammo.js

Large diffs are not rendered by default.

616 changes: 396 additions & 220 deletions builds/ammo.slow.js

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions examples/webgl_demo/ammo.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,44 @@

// Bullet-interfacing code

var collisionConfiguration = new btDefaultCollisionConfiguration();
var dispatcher = new btCollisionDispatcher(collisionConfiguration);
var overlappingPairCache = new btDbvtBroadphase();
var solver = new btSequentialImpulseConstraintSolver();
var dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld.setGravity(new btVector3(0, -10, 0));
var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration();
var dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration);
var overlappingPairCache = new Ammo.btDbvtBroadphase();
var solver = new Ammo.btSequentialImpulseConstraintSolver();
var dynamicsWorld = new Ammo.btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Ammo.btVector3(0, -10, 0));

var groundShape = new btBoxShape(new btVector3(50, 50, 50));
var groundShape = new Ammo.btBoxShape(new Ammo.btVector3(50, 50, 50));

var bodies = [];

var groundTransform = new btTransform();
var groundTransform = new Ammo.btTransform();
groundTransform.setIdentity();
groundTransform.setOrigin(new btVector3(0, -56, 0));
groundTransform.setOrigin(new Ammo.btVector3(0, -56, 0));

(function() {
var mass = 0;
var localInertia = new btVector3(0, 0, 0);
var myMotionState = new btDefaultMotionState(groundTransform);
var rbInfo = new btRigidBodyConstructionInfo(0, myMotionState, groundShape, localInertia);
var body = new btRigidBody(rbInfo);
var localInertia = new Ammo.btVector3(0, 0, 0);
var myMotionState = new Ammo.btDefaultMotionState(groundTransform);
var rbInfo = new Ammo.btRigidBodyConstructionInfo(0, myMotionState, groundShape, localInertia);
var body = new Ammo.btRigidBody(rbInfo);

dynamicsWorld.addRigidBody(body);
bodies.push(body);
})();

var boxShape = new btBoxShape(new btVector3(1, 1, 1));
var boxShape = new Ammo.btBoxShape(new Ammo.btVector3(1, 1, 1));

NUMRANGE.forEach(function(i) {
var startTransform = new btTransform();
var startTransform = new Ammo.btTransform();
startTransform.setIdentity();
var mass = 1;
var localInertia = new btVector3(0, 0, 0);
var localInertia = new Ammo.btVector3(0, 0, 0);
boxShape.calculateLocalInertia(mass, localInertia);

var myMotionState = new btDefaultMotionState(startTransform);
var rbInfo = new btRigidBodyConstructionInfo(mass, myMotionState, boxShape, localInertia);
var body = new btRigidBody(rbInfo);
var myMotionState = new Ammo.btDefaultMotionState(startTransform);
var rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, boxShape, localInertia);
var body = new Ammo.btRigidBody(rbInfo);

dynamicsWorld.addRigidBody(body);
bodies.push(body);
Expand All @@ -69,7 +69,7 @@

resetPositions();

var trans = new btTransform(); // taking this out of readBulletObject reduces the leaking
var trans = new Ammo.btTransform(); // taking this out of readBulletObject reduces the leaking
function readBulletObject(i, pos, quat) {
var body = bodies[i];
body.getMotionState().getWorldTransform(trans);
Expand Down
3 changes: 2 additions & 1 deletion make.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,6 @@ def stage(text):
bundle.close()

# Recommended: Also do closure compiler:
# java -jar /home/alon/Dev/closure-compiler-read-only/build/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --variable_map_output_file builds/ammo.vars --js builds/ammo.new.js --js_output_file builds/ammo.js
# java -jar /home/alon/Dev/closure-compiler-read-only/build/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --variable_map_output_file builds/ammo.vars --js builds/ammo.new.js --js_output_file builds/ammo.cc.js
# and wrap.py after it

29 changes: 29 additions & 0 deletions wrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python

'''
Wraps in a closure. Run this after closure compiler.
'''

import os, sys

infile = os.path.join('builds', 'ammo.cc.js') if len(sys.argv) < 2 else sys.argv[1]
print 'Input:', infile

outfile = os.path.join('builds', 'ammo.js') if len(sys.argv) < 3 else sys.argv[2]
print 'Output:', outfile

bundle = open(outfile, 'w')
bundle.write('''
// This is ammo.js, a port of Bullet to JavaScript. zlib licensed.
var Ammo = (function() {
var Module = this;
''')
bundle.write(open(infile, 'r').read())
bundle.write('''
return this;
}).call({});
''')
bundle.close()

0 comments on commit 0d605ae

Please sign in to comment.