|
@@ -11,11 +11,10 @@ module BABYLON {
|
|
|
|
|
|
constructor(iterations?: number) {
|
|
constructor(iterations?: number) {
|
|
this.BJSOIMO = typeof OIMO !== 'undefined' ? OIMO : (typeof require !== 'undefined' ? require('./Oimo') : undefined);
|
|
this.BJSOIMO = typeof OIMO !== 'undefined' ? OIMO : (typeof require !== 'undefined' ? require('./Oimo') : undefined);
|
|
- this.world = new this.BJSOIMO.World(1 / 60, 2, iterations, true);
|
|
|
|
- this.world.worldscale(1);
|
|
|
|
|
|
+ this.world = new this.BJSOIMO.World({
|
|
|
|
+ iterations: iterations
|
|
|
|
+ });
|
|
this.world.clear();
|
|
this.world.clear();
|
|
- //making sure no stats are calculated
|
|
|
|
- this.world.isNoStat = true;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public setGravity(gravity: Vector3) {
|
|
public setGravity(gravity: Vector3) {
|
|
@@ -71,8 +70,8 @@ module BABYLON {
|
|
}
|
|
}
|
|
|
|
|
|
public applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
|
|
public applyImpulse(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
|
|
- var mass = impostor.physicsBody.massInfo.mass;
|
|
|
|
- impostor.physicsBody.applyImpulse(contactPoint.scale(this.BJSOIMO.INV_SCALE), force.scale(this.BJSOIMO.INV_SCALE * mass));
|
|
|
|
|
|
+ var mass = impostor.physicsBody.mass;
|
|
|
|
+ impostor.physicsBody.applyImpulse(contactPoint.scale(this.world.invScale), force.scale(this.world.invScale * mass));
|
|
}
|
|
}
|
|
public applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
|
|
public applyForce(impostor: PhysicsImpostor, force: Vector3, contactPoint: Vector3) {
|
|
Tools.Warn("Oimo doesn't support applying force. Using impule instead.");
|
|
Tools.Warn("Oimo doesn't support applying force. Using impule instead.");
|
|
@@ -97,8 +96,13 @@ module BABYLON {
|
|
size: [],
|
|
size: [],
|
|
type: [],
|
|
type: [],
|
|
pos: [],
|
|
pos: [],
|
|
|
|
+ posShape: [],
|
|
rot: [],
|
|
rot: [],
|
|
|
|
+ rotShape: [],
|
|
move: impostor.getParam("mass") !== 0,
|
|
move: impostor.getParam("mass") !== 0,
|
|
|
|
+ density: impostor.getParam("mass"),
|
|
|
|
+ friction: impostor.getParam("friction"),
|
|
|
|
+ restitution: impostor.getParam("restitution"),
|
|
//Supporting older versions of Oimo
|
|
//Supporting older versions of Oimo
|
|
world: this.world
|
|
world: this.world
|
|
};
|
|
};
|
|
@@ -120,21 +124,17 @@ module BABYLON {
|
|
}
|
|
}
|
|
|
|
|
|
impostors.forEach((i) => {
|
|
impostors.forEach((i) => {
|
|
- if (!impostor.object.rotationQuaternion) {
|
|
|
|
|
|
+ if (!i.object.rotationQuaternion) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//get the correct bounding box
|
|
//get the correct bounding box
|
|
var oldQuaternion = i.object.rotationQuaternion;
|
|
var oldQuaternion = i.object.rotationQuaternion;
|
|
- var rot = new this.BJSOIMO.Euler().setFromQuaternion({
|
|
|
|
- x: impostor.object.rotationQuaternion.x,
|
|
|
|
- y: impostor.object.rotationQuaternion.y,
|
|
|
|
- z: impostor.object.rotationQuaternion.z,
|
|
|
|
- s: impostor.object.rotationQuaternion.w
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+ var rot = oldQuaternion.toEulerAngles();
|
|
var extendSize = i.getObjectExtendSize();
|
|
var extendSize = i.getObjectExtendSize();
|
|
|
|
|
|
|
|
+ const radToDeg = 57.295779513082320876;
|
|
|
|
+
|
|
if (i === impostor) {
|
|
if (i === impostor) {
|
|
var center = impostor.getObjectCenter();
|
|
var center = impostor.getObjectCenter();
|
|
|
|
|
|
@@ -145,27 +145,33 @@ module BABYLON {
|
|
bodyConfig.pos.push(center.x);
|
|
bodyConfig.pos.push(center.x);
|
|
bodyConfig.pos.push(center.y);
|
|
bodyConfig.pos.push(center.y);
|
|
bodyConfig.pos.push(center.z);
|
|
bodyConfig.pos.push(center.z);
|
|
|
|
+ bodyConfig.posShape.push(0, 0, 0);
|
|
|
|
|
|
//tmp solution
|
|
//tmp solution
|
|
- bodyConfig.rot.push(rot.x / (this.BJSOIMO.degtorad || this.BJSOIMO.TO_RAD));
|
|
|
|
- bodyConfig.rot.push(rot.y / (this.BJSOIMO.degtorad || this.BJSOIMO.TO_RAD));
|
|
|
|
- bodyConfig.rot.push(rot.z / (this.BJSOIMO.degtorad || this.BJSOIMO.TO_RAD));
|
|
|
|
|
|
+ bodyConfig.rot.push(rot.x * radToDeg);
|
|
|
|
+ bodyConfig.rot.push(rot.y * radToDeg);
|
|
|
|
+ bodyConfig.rot.push(rot.z * radToDeg);
|
|
|
|
+ bodyConfig.rotShape.push(0, 0, 0);
|
|
} else {
|
|
} else {
|
|
let localPosition = i.object.getAbsolutePosition().subtract(impostor.object.getAbsolutePosition());
|
|
let localPosition = i.object.getAbsolutePosition().subtract(impostor.object.getAbsolutePosition());
|
|
- bodyConfig.pos.push(localPosition.x);
|
|
|
|
- bodyConfig.pos.push(localPosition.y);
|
|
|
|
- bodyConfig.pos.push(localPosition.z);
|
|
|
|
|
|
+ bodyConfig.posShape.push(localPosition.x);
|
|
|
|
+ bodyConfig.posShape.push(localPosition.y);
|
|
|
|
+ bodyConfig.posShape.push(localPosition.z);
|
|
|
|
+ bodyConfig.pos.push(0, 0, 0);
|
|
|
|
|
|
//tmp solution until https://github.com/lo-th/OIMO.js/pull/37 is merged
|
|
//tmp solution until https://github.com/lo-th/OIMO.js/pull/37 is merged
|
|
bodyConfig.rot.push(0);
|
|
bodyConfig.rot.push(0);
|
|
bodyConfig.rot.push(0);
|
|
bodyConfig.rot.push(0);
|
|
bodyConfig.rot.push(0);
|
|
bodyConfig.rot.push(0);
|
|
|
|
+ bodyConfig.rotShape.push(rot.x * radToDeg);
|
|
|
|
+ bodyConfig.rotShape.push(rot.y * radToDeg);
|
|
|
|
+ bodyConfig.rotShape.push(rot.z * radToDeg);
|
|
}
|
|
}
|
|
|
|
|
|
// register mesh
|
|
// register mesh
|
|
switch (i.type) {
|
|
switch (i.type) {
|
|
case PhysicsImpostor.ParticleImpostor:
|
|
case PhysicsImpostor.ParticleImpostor:
|
|
- Tools.Warn("No Particle support in this.BJSOIMO.js. using SphereImpostor instead");
|
|
|
|
|
|
+ Tools.Warn("No Particle support in OIMO.js. using SphereImpostor instead");
|
|
case PhysicsImpostor.SphereImpostor:
|
|
case PhysicsImpostor.SphereImpostor:
|
|
var radiusX = extendSize.x;
|
|
var radiusX = extendSize.x;
|
|
var radiusY = extendSize.y;
|
|
var radiusY = extendSize.y;
|
|
@@ -200,10 +206,15 @@ module BABYLON {
|
|
var sizeY = checkWithEpsilon(extendSize.y);
|
|
var sizeY = checkWithEpsilon(extendSize.y);
|
|
var sizeZ = checkWithEpsilon(extendSize.z);
|
|
var sizeZ = checkWithEpsilon(extendSize.z);
|
|
|
|
|
|
|
|
+
|
|
bodyConfig.type.push('box');
|
|
bodyConfig.type.push('box');
|
|
|
|
+ //if (i === impostor) {
|
|
bodyConfig.size.push(sizeX);
|
|
bodyConfig.size.push(sizeX);
|
|
bodyConfig.size.push(sizeY);
|
|
bodyConfig.size.push(sizeY);
|
|
bodyConfig.size.push(sizeZ);
|
|
bodyConfig.size.push(sizeZ);
|
|
|
|
+ //} else {
|
|
|
|
+ // bodyConfig.size.push(0,0,0);
|
|
|
|
+ //}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -211,7 +222,7 @@ module BABYLON {
|
|
i.object.rotationQuaternion = oldQuaternion;
|
|
i.object.rotationQuaternion = oldQuaternion;
|
|
});
|
|
});
|
|
|
|
|
|
- impostor.physicsBody = new this.BJSOIMO.Body(bodyConfig).body//this.world.add(bodyConfig);
|
|
|
|
|
|
+ impostor.physicsBody = this.world.add(bodyConfig);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
this._tmpPositionVector.copyFromFloats(0, 0, 0);
|
|
this._tmpPositionVector.copyFromFloats(0, 0, 0);
|
|
@@ -264,7 +275,7 @@ module BABYLON {
|
|
type = "jointBall";
|
|
type = "jointBall";
|
|
break;
|
|
break;
|
|
case PhysicsJoint.SpringJoint:
|
|
case PhysicsJoint.SpringJoint:
|
|
- Tools.Warn("this.BJSOIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");
|
|
|
|
|
|
+ Tools.Warn("OIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");
|
|
var springData = <SpringJointData>jointData;
|
|
var springData = <SpringJointData>jointData;
|
|
nativeJointData.min = springData.length || nativeJointData.min;
|
|
nativeJointData.min = springData.length || nativeJointData.min;
|
|
//Max should also be set, just make sure it is at least min
|
|
//Max should also be set, just make sure it is at least min
|
|
@@ -288,7 +299,7 @@ module BABYLON {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
nativeJointData.type = type;
|
|
nativeJointData.type = type;
|
|
- impostorJoint.joint.physicsJoint = new this.BJSOIMO.Link(nativeJointData).joint//this.world.add(nativeJointData);
|
|
|
|
|
|
+ impostorJoint.joint.physicsJoint = this.world.add(nativeJointData);
|
|
}
|
|
}
|
|
|
|
|
|
public removeJoint(impostorJoint: PhysicsImpostorJoint) {
|
|
public removeJoint(impostorJoint: PhysicsImpostorJoint) {
|
|
@@ -310,40 +321,35 @@ module BABYLON {
|
|
public setTransformationFromPhysicsBody(impostor: PhysicsImpostor) {
|
|
public setTransformationFromPhysicsBody(impostor: PhysicsImpostor) {
|
|
if (!impostor.physicsBody.sleeping) {
|
|
if (!impostor.physicsBody.sleeping) {
|
|
//TODO check that
|
|
//TODO check that
|
|
- if (impostor.physicsBody.shapes.next) {
|
|
|
|
|
|
+ /*if (impostor.physicsBody.shapes.next) {
|
|
var parentShape = this._getLastShape(impostor.physicsBody);
|
|
var parentShape = this._getLastShape(impostor.physicsBody);
|
|
- impostor.object.position.x = parentShape.position.x * this.BJSOIMO.WORLD_SCALE;
|
|
|
|
- impostor.object.position.y = parentShape.position.y * this.BJSOIMO.WORLD_SCALE;
|
|
|
|
- impostor.object.position.z = parentShape.position.z * this.BJSOIMO.WORLD_SCALE;
|
|
|
|
- } else {
|
|
|
|
- impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ impostor.object.position.copyFrom(parentShape.position);
|
|
|
|
+ console.log(parentShape.position);
|
|
|
|
+ } else {*/
|
|
|
|
+ impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
|
|
|
|
+ //}
|
|
|
|
|
|
if (impostor.object.rotationQuaternion) {
|
|
if (impostor.object.rotationQuaternion) {
|
|
impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
|
|
impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
|
|
- impostor.object.rotationQuaternion.normalize();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
|
|
public setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion) {
|
|
var body = impostor.physicsBody;
|
|
var body = impostor.physicsBody;
|
|
-
|
|
|
|
- body.position.init(newPosition.x * this.BJSOIMO.INV_SCALE, newPosition.y * this.BJSOIMO.INV_SCALE, newPosition.z * this.BJSOIMO.INV_SCALE);
|
|
|
|
-
|
|
|
|
- body.orientation.init(newRotation.w, newRotation.x, newRotation.y, newRotation.z);
|
|
|
|
|
|
+ body.position.copy(newPosition);
|
|
|
|
+ body.orientation.copy(newRotation);
|
|
body.syncShapes();
|
|
body.syncShapes();
|
|
body.awake();
|
|
body.awake();
|
|
}
|
|
}
|
|
|
|
|
|
- private _getLastShape(body: any): any {
|
|
|
|
|
|
+ /*private _getLastShape(body: any): any {
|
|
var lastShape = body.shapes;
|
|
var lastShape = body.shapes;
|
|
while (lastShape.next) {
|
|
while (lastShape.next) {
|
|
lastShape = lastShape.next;
|
|
lastShape = lastShape.next;
|
|
}
|
|
}
|
|
return lastShape;
|
|
return lastShape;
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
public setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
|
|
public setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
|
|
impostor.physicsBody.linearVelocity.init(velocity.x, velocity.y, velocity.z);
|
|
impostor.physicsBody.linearVelocity.init(velocity.x, velocity.y, velocity.z);
|