|
@@ -5,6 +5,8 @@ module BABYLON {
|
|
friction?: number;
|
|
friction?: number;
|
|
restitution?: number;
|
|
restitution?: number;
|
|
nativeOptions?: any;
|
|
nativeOptions?: any;
|
|
|
|
+ ignoreParent?: boolean;
|
|
|
|
+ disableBidirectionalTransformation?: boolean;
|
|
}
|
|
}
|
|
|
|
|
|
export interface IPhysicsEnabledObject {
|
|
export interface IPhysicsEnabledObject {
|
|
@@ -80,7 +82,7 @@ module BABYLON {
|
|
set restitution(value: number) {
|
|
set restitution(value: number) {
|
|
if (!this._physicsEngine) {
|
|
if (!this._physicsEngine) {
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
|
|
+ }
|
|
this._physicsEngine.getPhysicsPlugin().setBodyRestitution(this, value);
|
|
this._physicsEngine.getPhysicsPlugin().setBodyRestitution(this, value);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -126,9 +128,10 @@ module BABYLON {
|
|
this._options.mass = (_options.mass === void 0) ? 0 : _options.mass
|
|
this._options.mass = (_options.mass === void 0) ? 0 : _options.mass
|
|
this._options.friction = (_options.friction === void 0) ? 0.2 : _options.friction
|
|
this._options.friction = (_options.friction === void 0) ? 0.2 : _options.friction
|
|
this._options.restitution = (_options.restitution === void 0) ? 0.2 : _options.restitution
|
|
this._options.restitution = (_options.restitution === void 0) ? 0.2 : _options.restitution
|
|
|
|
+
|
|
this._joints = [];
|
|
this._joints = [];
|
|
//If the mesh has a parent, don't initialize the physicsBody. Instead wait for the parent to do that.
|
|
//If the mesh has a parent, don't initialize the physicsBody. Instead wait for the parent to do that.
|
|
- if (!this.object.parent) {
|
|
|
|
|
|
+ if (!this.object.parent || this._options.ignoreParent) {
|
|
this._init();
|
|
this._init();
|
|
} else if (this.object.parent.physicsImpostor) {
|
|
} else if (this.object.parent.physicsImpostor) {
|
|
Tools.Warn("You must affect impostors to children before affecting impostor to parent.");
|
|
Tools.Warn("You must affect impostors to children before affecting impostor to parent.");
|
|
@@ -150,7 +153,7 @@ module BABYLON {
|
|
this._physicsEngine.removeImpostor(this);
|
|
this._physicsEngine.removeImpostor(this);
|
|
this.physicsBody = null;
|
|
this.physicsBody = null;
|
|
this._parent = this._parent || this._getPhysicsParent();
|
|
this._parent = this._parent || this._getPhysicsParent();
|
|
- if (!this.parent) {
|
|
|
|
|
|
+ if (!this.parent || this._options.ignoreParent) {
|
|
this._physicsEngine.addImpostor(this);
|
|
this._physicsEngine.addImpostor(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -180,7 +183,7 @@ module BABYLON {
|
|
*/
|
|
*/
|
|
public forceUpdate() {
|
|
public forceUpdate() {
|
|
this._init();
|
|
this._init();
|
|
- if (this.parent) {
|
|
|
|
|
|
+ if (this.parent && !this._options.ignoreParent) {
|
|
this.parent.forceUpdate();
|
|
this.parent.forceUpdate();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -193,11 +196,11 @@ module BABYLON {
|
|
* Gets the body that holds this impostor. Either its own, or its parent.
|
|
* Gets the body that holds this impostor. Either its own, or its parent.
|
|
*/
|
|
*/
|
|
public get physicsBody(): any {
|
|
public get physicsBody(): any {
|
|
- return this._parent ? this._parent.physicsBody : this._physicsBody;
|
|
|
|
|
|
+ return (this._parent && !this._options.ignoreParent) ? this._parent.physicsBody : this._physicsBody;
|
|
}
|
|
}
|
|
|
|
|
|
public get parent(): PhysicsImpostor {
|
|
public get parent(): PhysicsImpostor {
|
|
- return this._parent;
|
|
|
|
|
|
+ return !this._options.ignoreParent && this._parent;
|
|
}
|
|
}
|
|
|
|
|
|
public set parent(value: PhysicsImpostor) {
|
|
public set parent(value: PhysicsImpostor) {
|
|
@@ -377,7 +380,13 @@ module BABYLON {
|
|
if (!this._physicsEngine) {
|
|
if (!this._physicsEngine) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this.object.position.subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
|
|
|
|
|
|
+
|
|
|
|
+ if (this._options.ignoreParent && this.object.parent) {
|
|
|
|
+ this._tmpPositionWithDelta.copyFrom(this.object.getAbsolutePosition());
|
|
|
|
+ //this.object.getAbsolutePosition().subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
|
|
|
|
+ } else {
|
|
|
|
+ this.object.position.subtractToRef(this._deltaPosition, this._tmpPositionWithDelta);
|
|
|
|
+ }
|
|
//conjugate deltaRotation
|
|
//conjugate deltaRotation
|
|
if (this.object.rotationQuaternion) {
|
|
if (this.object.rotationQuaternion) {
|
|
if (this._deltaRotationConjugated) {
|
|
if (this._deltaRotationConjugated) {
|
|
@@ -386,8 +395,10 @@ module BABYLON {
|
|
this._tmpRotationWithDelta.copyFrom(this.object.rotationQuaternion);
|
|
this._tmpRotationWithDelta.copyFrom(this.object.rotationQuaternion);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- this._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(this, this._tmpPositionWithDelta, this._tmpRotationWithDelta);
|
|
|
|
|
|
+ // Only if not disabled
|
|
|
|
+ if (!this._options.disableBidirectionalTransformation) {
|
|
|
|
+ this._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(this, this._tmpPositionWithDelta, this._tmpRotationWithDelta);
|
|
|
|
+ }
|
|
|
|
|
|
this._onBeforePhysicsStepCallbacks.forEach((func) => {
|
|
this._onBeforePhysicsStepCallbacks.forEach((func) => {
|
|
func(this);
|
|
func(this);
|
|
@@ -408,7 +419,12 @@ module BABYLON {
|
|
|
|
|
|
this._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(this);
|
|
this._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(this);
|
|
|
|
|
|
- this.object.position.addInPlace(this._deltaPosition)
|
|
|
|
|
|
+ if (this._options.ignoreParent && this.object.parent) {
|
|
|
|
+ this.object.position.subtractInPlace(this.object.parent.getAbsolutePosition());
|
|
|
|
+ } else {
|
|
|
|
+ this.object.position.addInPlace(this._deltaPosition)
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this._deltaRotation && this.object.rotationQuaternion) {
|
|
if (this._deltaRotation && this.object.rotationQuaternion) {
|
|
this.object.rotationQuaternion.multiplyInPlace(this._deltaRotation);
|
|
this.object.rotationQuaternion.multiplyInPlace(this._deltaRotation);
|
|
}
|
|
}
|