|
@@ -41,6 +41,7 @@ module BABYLON {
|
|
|
mesh.computeWorldMatrix(true);
|
|
|
|
|
|
var bodyConfig: any = {
|
|
|
+ name: mesh.uniqueId,
|
|
|
pos: [bbox.center.x, bbox.center.y, bbox.center.z],
|
|
|
rot: [rot.x / OIMO.TO_RAD, rot.y / OIMO.TO_RAD, rot.z / OIMO.TO_RAD],
|
|
|
move: options.mass != 0,
|
|
@@ -121,6 +122,7 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
var body = new OIMO.Body({
|
|
|
+ name: initialMesh.uniqueId,
|
|
|
type: types,
|
|
|
size: sizes,
|
|
|
pos: positions,
|
|
@@ -156,6 +158,7 @@ module BABYLON {
|
|
|
var rot = new OIMO.Euler().setFromQuaternion({ x: mesh.rotationQuaternion.x, y: mesh.rotationQuaternion.y, z: mesh.rotationQuaternion.z, s: mesh.rotationQuaternion.w });
|
|
|
|
|
|
var bodyParameters: any = {
|
|
|
+ name: mesh.uniqueId,
|
|
|
pos: [mesh.position.x, mesh.position.y, mesh.position.z],
|
|
|
//A bug in Oimo (Body class) prevents us from using rot directly.
|
|
|
rot: [0, 0, 0],
|
|
@@ -379,6 +382,23 @@ module BABYLON {
|
|
|
mesh.rotationQuaternion.copyFrom(body.getQuaternion());
|
|
|
mesh.computeWorldMatrix();
|
|
|
}
|
|
|
+
|
|
|
+ //check if the collide callback is set.
|
|
|
+ if(mesh.onPhysicsCollide) {
|
|
|
+ var meshUniqueName = mesh.uniqueId;
|
|
|
+ var contact = this._world.contacts;
|
|
|
+ while(contact!==null){
|
|
|
+ //is this body colliding with any other?
|
|
|
+ if((contact.body1.name == mesh.uniqueId || contact.body2.name == mesh.uniqueId) && contact.touching && /* !contact.sleeping*/ !contact.body1.sleeping && !contact.body2.sleeping) {
|
|
|
+ var otherUniqueId = contact.body1.name == mesh.uniqueId ? contact.body2.name : contact.body1.name;
|
|
|
+ //get the mesh and execute the callback
|
|
|
+ var otherMesh = mesh.getScene().getMeshByUniqueID(otherUniqueId);
|
|
|
+ if(otherMesh)
|
|
|
+ mesh.onPhysicsCollide(otherMesh);
|
|
|
+ }
|
|
|
+ contact = contact.next;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|