|
@@ -27804,7 +27804,7 @@ var BABYLON;
|
|
// Physics
|
|
// Physics
|
|
if (this._physicsEngine) {
|
|
if (this._physicsEngine) {
|
|
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
- this._physicsEngine._step(defaultFrameTime / 1000);
|
|
|
|
|
|
+ this._physicsEngine.step(defaultFrameTime / 1000);
|
|
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
}
|
|
}
|
|
this.onAfterStepObservable.notifyObservers(this);
|
|
this.onAfterStepObservable.notifyObservers(this);
|
|
@@ -27823,7 +27823,7 @@ var BABYLON;
|
|
// Physics
|
|
// Physics
|
|
if (this._physicsEngine) {
|
|
if (this._physicsEngine) {
|
|
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
- this._physicsEngine._step(deltaTime / 1000.0);
|
|
|
|
|
|
+ this._physicsEngine.step(deltaTime / 1000.0);
|
|
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -28552,61 +28552,6 @@ var BABYLON;
|
|
return this._pointerOverMesh;
|
|
return this._pointerOverMesh;
|
|
};
|
|
};
|
|
// Physics
|
|
// Physics
|
|
- /**
|
|
|
|
- * Gets the current physics engine
|
|
|
|
- * @returns a PhysicsEngine or null if none attached
|
|
|
|
- */
|
|
|
|
- Scene.prototype.getPhysicsEngine = function () {
|
|
|
|
- return this._physicsEngine;
|
|
|
|
- };
|
|
|
|
- /**
|
|
|
|
- * Enables physics to the current scene
|
|
|
|
- * @param gravity defines the scene's gravity for the physics engine
|
|
|
|
- * @param plugin defines the physics engine to be used. defaults to OimoJS.
|
|
|
|
- * @return a boolean indicating if the physics engine was initialized
|
|
|
|
- */
|
|
|
|
- Scene.prototype.enablePhysics = function (gravity, plugin) {
|
|
|
|
- if (gravity === void 0) { gravity = null; }
|
|
|
|
- if (this._physicsEngine) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- this._physicsEngine = new BABYLON.PhysicsEngine(gravity, plugin);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- catch (e) {
|
|
|
|
- BABYLON.Tools.Error(e.message);
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- /**
|
|
|
|
- * Disables and disposes the physics engine associated with the scene
|
|
|
|
- */
|
|
|
|
- Scene.prototype.disablePhysicsEngine = function () {
|
|
|
|
- if (!this._physicsEngine) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- this._physicsEngine.dispose();
|
|
|
|
- this._physicsEngine = null;
|
|
|
|
- };
|
|
|
|
- /**
|
|
|
|
- * Gets a boolean indicating if there is an active physics engine
|
|
|
|
- * @returns a boolean indicating if there is an active physics engine
|
|
|
|
- */
|
|
|
|
- Scene.prototype.isPhysicsEnabled = function () {
|
|
|
|
- return this._physicsEngine !== undefined;
|
|
|
|
- };
|
|
|
|
- /**
|
|
|
|
- * Deletes a physics compound impostor
|
|
|
|
- * @param compound defines the compound to delete
|
|
|
|
- */
|
|
|
|
- Scene.prototype.deleteCompoundImpostor = function (compound) {
|
|
|
|
- var mesh = compound.parts[0].mesh;
|
|
|
|
- if (mesh.physicsImpostor) {
|
|
|
|
- mesh.physicsImpostor.dispose( /*true*/);
|
|
|
|
- mesh.physicsImpostor = null;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
// Misc.
|
|
// Misc.
|
|
/** @hidden */
|
|
/** @hidden */
|
|
Scene.prototype._rebuildGeometries = function () {
|
|
Scene.prototype._rebuildGeometries = function () {
|
|
@@ -89685,11 +89630,19 @@ var BABYLON;
|
|
|
|
|
|
var BABYLON;
|
|
var BABYLON;
|
|
(function (BABYLON) {
|
|
(function (BABYLON) {
|
|
|
|
+ /**
|
|
|
|
+ * Class used to control physics engine
|
|
|
|
+ * @see http://doc.babylonjs.com/how_to/using_the_physics_engine
|
|
|
|
+ */
|
|
var PhysicsEngine = /** @class */ (function () {
|
|
var PhysicsEngine = /** @class */ (function () {
|
|
|
|
+ /**
|
|
|
|
+ * Creates a new Physics Engine
|
|
|
|
+ * @param gravity defines the gravity vector used by the simulation
|
|
|
|
+ * @param _physicsPlugin defines the plugin to use (CannonJS by default)
|
|
|
|
+ */
|
|
function PhysicsEngine(gravity, _physicsPlugin) {
|
|
function PhysicsEngine(gravity, _physicsPlugin) {
|
|
if (_physicsPlugin === void 0) { _physicsPlugin = new BABYLON.CannonJSPlugin(); }
|
|
if (_physicsPlugin === void 0) { _physicsPlugin = new BABYLON.CannonJSPlugin(); }
|
|
this._physicsPlugin = _physicsPlugin;
|
|
this._physicsPlugin = _physicsPlugin;
|
|
- //new methods and parameters
|
|
|
|
this._impostors = [];
|
|
this._impostors = [];
|
|
this._joints = [];
|
|
this._joints = [];
|
|
if (!this._physicsPlugin.isSupported()) {
|
|
if (!this._physicsPlugin.isSupported()) {
|
|
@@ -89700,16 +89653,20 @@ var BABYLON;
|
|
this.setGravity(gravity);
|
|
this.setGravity(gravity);
|
|
this.setTimeStep();
|
|
this.setTimeStep();
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * Sets the gravity vector used by the simulation
|
|
|
|
+ * @param gravity defines the gravity vector to use
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.setGravity = function (gravity) {
|
|
PhysicsEngine.prototype.setGravity = function (gravity) {
|
|
this.gravity = gravity;
|
|
this.gravity = gravity;
|
|
this._physicsPlugin.setGravity(this.gravity);
|
|
this._physicsPlugin.setGravity(this.gravity);
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Set the time step of the physics engine.
|
|
* Set the time step of the physics engine.
|
|
- * default is 1/60.
|
|
|
|
|
|
+ * Default is 1/60.
|
|
* To slow it down, enter 1/600 for example.
|
|
* To slow it down, enter 1/600 for example.
|
|
* To speed it up, 1/30
|
|
* To speed it up, 1/30
|
|
- * @param {number} newTimeStep the new timestep to apply to this world.
|
|
|
|
|
|
+ * @param newTimeStep defines the new timestep to apply to this world.
|
|
*/
|
|
*/
|
|
PhysicsEngine.prototype.setTimeStep = function (newTimeStep) {
|
|
PhysicsEngine.prototype.setTimeStep = function (newTimeStep) {
|
|
if (newTimeStep === void 0) { newTimeStep = 1 / 60; }
|
|
if (newTimeStep === void 0) { newTimeStep = 1 / 60; }
|
|
@@ -89717,23 +89674,31 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Get the time step of the physics engine.
|
|
* Get the time step of the physics engine.
|
|
|
|
+ * @returns the current time step
|
|
*/
|
|
*/
|
|
PhysicsEngine.prototype.getTimeStep = function () {
|
|
PhysicsEngine.prototype.getTimeStep = function () {
|
|
return this._physicsPlugin.getTimeStep();
|
|
return this._physicsPlugin.getTimeStep();
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Release all resources
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.dispose = function () {
|
|
PhysicsEngine.prototype.dispose = function () {
|
|
this._impostors.forEach(function (impostor) {
|
|
this._impostors.forEach(function (impostor) {
|
|
impostor.dispose();
|
|
impostor.dispose();
|
|
});
|
|
});
|
|
this._physicsPlugin.dispose();
|
|
this._physicsPlugin.dispose();
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Gets the name of the current physics plugin
|
|
|
|
+ * @returns the name of the plugin
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.getPhysicsPluginName = function () {
|
|
PhysicsEngine.prototype.getPhysicsPluginName = function () {
|
|
return this._physicsPlugin.name;
|
|
return this._physicsPlugin.name;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Adding a new impostor for the impostor tracking.
|
|
* Adding a new impostor for the impostor tracking.
|
|
* This will be done by the impostor itself.
|
|
* This will be done by the impostor itself.
|
|
- * @param {PhysicsImpostor} impostor the impostor to add
|
|
|
|
|
|
+ * @param impostor the impostor to add
|
|
*/
|
|
*/
|
|
PhysicsEngine.prototype.addImpostor = function (impostor) {
|
|
PhysicsEngine.prototype.addImpostor = function (impostor) {
|
|
impostor.uniqueId = this._impostors.push(impostor);
|
|
impostor.uniqueId = this._impostors.push(impostor);
|
|
@@ -89745,7 +89710,7 @@ var BABYLON;
|
|
/**
|
|
/**
|
|
* Remove an impostor from the engine.
|
|
* Remove an impostor from the engine.
|
|
* This impostor and its mesh will not longer be updated by the physics engine.
|
|
* This impostor and its mesh will not longer be updated by the physics engine.
|
|
- * @param {PhysicsImpostor} impostor the impostor to remove
|
|
|
|
|
|
+ * @param impostor the impostor to remove
|
|
*/
|
|
*/
|
|
PhysicsEngine.prototype.removeImpostor = function (impostor) {
|
|
PhysicsEngine.prototype.removeImpostor = function (impostor) {
|
|
var index = this._impostors.indexOf(impostor);
|
|
var index = this._impostors.indexOf(impostor);
|
|
@@ -89760,9 +89725,9 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Add a joint to the physics engine
|
|
* Add a joint to the physics engine
|
|
- * @param {PhysicsImpostor} mainImpostor the main impostor to which the joint is added.
|
|
|
|
- * @param {PhysicsImpostor} connectedImpostor the impostor that is connected to the main impostor using this joint
|
|
|
|
- * @param {PhysicsJoint} the joint that will connect both impostors.
|
|
|
|
|
|
+ * @param mainImpostor defines the main impostor to which the joint is added.
|
|
|
|
+ * @param connectedImpostor defines the impostor that is connected to the main impostor using this joint
|
|
|
|
+ * @param joint defines the joint that will connect both impostors.
|
|
*/
|
|
*/
|
|
PhysicsEngine.prototype.addJoint = function (mainImpostor, connectedImpostor, joint) {
|
|
PhysicsEngine.prototype.addJoint = function (mainImpostor, connectedImpostor, joint) {
|
|
var impostorJoint = {
|
|
var impostorJoint = {
|
|
@@ -89774,6 +89739,12 @@ var BABYLON;
|
|
this._joints.push(impostorJoint);
|
|
this._joints.push(impostorJoint);
|
|
this._physicsPlugin.generateJoint(impostorJoint);
|
|
this._physicsPlugin.generateJoint(impostorJoint);
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Removes a joint from the simulation
|
|
|
|
+ * @param mainImpostor defines the impostor used with the joint
|
|
|
|
+ * @param connectedImpostor defines the other impostor connected to the main one by the joint
|
|
|
|
+ * @param joint defines the joint to remove
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.removeJoint = function (mainImpostor, connectedImpostor, joint) {
|
|
PhysicsEngine.prototype.removeJoint = function (mainImpostor, connectedImpostor, joint) {
|
|
var matchingJoints = this._joints.filter(function (impostorJoint) {
|
|
var matchingJoints = this._joints.filter(function (impostorJoint) {
|
|
return (impostorJoint.connectedImpostor === connectedImpostor
|
|
return (impostorJoint.connectedImpostor === connectedImpostor
|
|
@@ -89786,10 +89757,10 @@ var BABYLON;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * Called by the scene. no need to call it.
|
|
|
|
- * @hidden
|
|
|
|
|
|
+ * Called by the scene. No need to call it.
|
|
|
|
+ * @param delta defines the timespam between frames
|
|
*/
|
|
*/
|
|
- PhysicsEngine.prototype._step = function (delta) {
|
|
|
|
|
|
+ PhysicsEngine.prototype.step = function (delta) {
|
|
var _this = this;
|
|
var _this = this;
|
|
//check if any mesh has no body / requires an update
|
|
//check if any mesh has no body / requires an update
|
|
this._impostors.forEach(function (impostor) {
|
|
this._impostors.forEach(function (impostor) {
|
|
@@ -89805,12 +89776,25 @@ var BABYLON;
|
|
}
|
|
}
|
|
this._physicsPlugin.executeStep(delta, this._impostors);
|
|
this._physicsPlugin.executeStep(delta, this._impostors);
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Gets the current plugin used to run the simulation
|
|
|
|
+ * @returns current plugin
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.getPhysicsPlugin = function () {
|
|
PhysicsEngine.prototype.getPhysicsPlugin = function () {
|
|
return this._physicsPlugin;
|
|
return this._physicsPlugin;
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Gets the list of physic impostors
|
|
|
|
+ * @returns an array of PhysicsImpostor
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.getImpostors = function () {
|
|
PhysicsEngine.prototype.getImpostors = function () {
|
|
return this._impostors;
|
|
return this._impostors;
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Gets the impostor for a physics enabled object
|
|
|
|
+ * @param object defines the object impersonated by the impostor
|
|
|
|
+ * @returns the PhysicsImpostor or null if not found
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.getImpostorForPhysicsObject = function (object) {
|
|
PhysicsEngine.prototype.getImpostorForPhysicsObject = function (object) {
|
|
for (var i = 0; i < this._impostors.length; ++i) {
|
|
for (var i = 0; i < this._impostors.length; ++i) {
|
|
if (this._impostors[i].object === object) {
|
|
if (this._impostors[i].object === object) {
|
|
@@ -89819,6 +89803,11 @@ var BABYLON;
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Gets the impostor for a physics body object
|
|
|
|
+ * @param body defines physics body used by the impostor
|
|
|
|
+ * @returns the PhysicsImpostor or null if not found
|
|
|
|
+ */
|
|
PhysicsEngine.prototype.getImpostorWithPhysicsBody = function (body) {
|
|
PhysicsEngine.prototype.getImpostorWithPhysicsBody = function (body) {
|
|
for (var i = 0; i < this._impostors.length; ++i) {
|
|
for (var i = 0; i < this._impostors.length; ++i) {
|
|
if (this._impostors[i].physicsBody === body) {
|
|
if (this._impostors[i].physicsBody === body) {
|
|
@@ -89827,7 +89816,9 @@ var BABYLON;
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
};
|
|
};
|
|
- // Statics
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Global value used to control the smallest number supported by the simulation
|
|
|
|
+ */
|
|
PhysicsEngine.Epsilon = 0.001;
|
|
PhysicsEngine.Epsilon = 0.001;
|
|
return PhysicsEngine;
|
|
return PhysicsEngine;
|
|
}());
|
|
}());
|
|
@@ -91353,6 +91344,67 @@ var BABYLON;
|
|
|
|
|
|
var BABYLON;
|
|
var BABYLON;
|
|
(function (BABYLON) {
|
|
(function (BABYLON) {
|
|
|
|
+ /**
|
|
|
|
+ * Gets the current physics engine
|
|
|
|
+ * @returns a IPhysicsEngine or null if none attached
|
|
|
|
+ */
|
|
|
|
+ BABYLON.Scene.prototype.getPhysicsEngine = function () {
|
|
|
|
+ return this._physicsEngine;
|
|
|
|
+ };
|
|
|
|
+ /**
|
|
|
|
+ * Enables physics to the current scene
|
|
|
|
+ * @param gravity defines the scene's gravity for the physics engine
|
|
|
|
+ * @param plugin defines the physics engine to be used. defaults to OimoJS.
|
|
|
|
+ * @return a boolean indicating if the physics engine was initialized
|
|
|
|
+ */
|
|
|
|
+ BABYLON.Scene.prototype.enablePhysics = function (gravity, plugin) {
|
|
|
|
+ if (gravity === void 0) { gravity = null; }
|
|
|
|
+ if (this._physicsEngine) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ this._physicsEngine = new BABYLON.PhysicsEngine(gravity, plugin);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ catch (e) {
|
|
|
|
+ BABYLON.Tools.Error(e.message);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ /**
|
|
|
|
+ * Disables and disposes the physics engine associated with the scene
|
|
|
|
+ */
|
|
|
|
+ BABYLON.Scene.prototype.disablePhysicsEngine = function () {
|
|
|
|
+ if (!this._physicsEngine) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this._physicsEngine.dispose();
|
|
|
|
+ this._physicsEngine = null;
|
|
|
|
+ };
|
|
|
|
+ /**
|
|
|
|
+ * Gets a boolean indicating if there is an active physics engine
|
|
|
|
+ * @returns a boolean indicating if there is an active physics engine
|
|
|
|
+ */
|
|
|
|
+ BABYLON.Scene.prototype.isPhysicsEnabled = function () {
|
|
|
|
+ return this._physicsEngine !== undefined;
|
|
|
|
+ };
|
|
|
|
+ /**
|
|
|
|
+ * Deletes a physics compound impostor
|
|
|
|
+ * @param compound defines the compound to delete
|
|
|
|
+ */
|
|
|
|
+ BABYLON.Scene.prototype.deleteCompoundImpostor = function (compound) {
|
|
|
|
+ var mesh = compound.parts[0].mesh;
|
|
|
|
+ if (mesh.physicsImpostor) {
|
|
|
|
+ mesh.physicsImpostor.dispose( /*true*/);
|
|
|
|
+ mesh.physicsImpostor = null;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+})(BABYLON || (BABYLON = {}));
|
|
|
|
+
|
|
|
|
+//# sourceMappingURL=babylon.physicsEngineComponent.js.map
|
|
|
|
+
|
|
|
|
+var BABYLON;
|
|
|
|
+(function (BABYLON) {
|
|
// Based on demo done by Brandon Jones - http://media.tojicode.com/webgl-samples/dds.html
|
|
// Based on demo done by Brandon Jones - http://media.tojicode.com/webgl-samples/dds.html
|
|
// All values and structures referenced from:
|
|
// All values and structures referenced from:
|
|
// http://msdn.microsoft.com/en-us/library/bb943991.aspx/
|
|
// http://msdn.microsoft.com/en-us/library/bb943991.aspx/
|