|
@@ -1,6 +1,17 @@
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
+ /**
|
|
|
+ * ActionEvent is the event beint sent when an action is triggered.
|
|
|
+ */
|
|
|
var ActionEvent = (function () {
|
|
|
+ /**
|
|
|
+ * @constructor
|
|
|
+ * @param source The mesh that triggered the action.
|
|
|
+ * @param pointerX the X mouse cursor position at the time of the event
|
|
|
+ * @param pointerY the Y mouse cursor position at the time of the event
|
|
|
+ * @param meshUnderPointer The mesh that is currently pointed at (can be null)
|
|
|
+ * @param sourceEvent the original (browser) event that triggered the ActionEvent
|
|
|
+ */
|
|
|
function ActionEvent(source, pointerX, pointerY, meshUnderPointer, sourceEvent) {
|
|
|
this.source = source;
|
|
|
this.pointerX = pointerX;
|
|
@@ -8,11 +19,21 @@
|
|
|
this.meshUnderPointer = meshUnderPointer;
|
|
|
this.sourceEvent = sourceEvent;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * Helper function to auto-create an ActionEvent from a source mesh.
|
|
|
+ * @param source the source mesh that triggered the event
|
|
|
+ * @param evt {Event} The original (browser) event
|
|
|
+ */
|
|
|
ActionEvent.CreateNew = function (source, evt) {
|
|
|
var scene = source.getScene();
|
|
|
return new ActionEvent(source, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper function to auto-create an ActionEvent from a scene. If triggered by a mesh use ActionEvent.CreateNew
|
|
|
+ * @param scene the scene where the event occurred
|
|
|
+ * @param evt {Event} The original (browser) event
|
|
|
+ */
|
|
|
ActionEvent.CreateNewFromScene = function (scene, evt) {
|
|
|
return new ActionEvent(null, scene.pointerX, scene.pointerY, scene.meshUnderPointer, evt);
|
|
|
};
|
|
@@ -20,6 +41,10 @@
|
|
|
})();
|
|
|
BABYLON.ActionEvent = ActionEvent;
|
|
|
|
|
|
+ /**
|
|
|
+ * Action Manager manages all events to be triggered on a given mesh or the global scene.
|
|
|
+ * A single scene can have many Action Managers to handle predefined actions on specific meshes.
|
|
|
+ */
|
|
|
var ActionManager = (function () {
|
|
|
function ActionManager(scene) {
|
|
|
// Members
|
|
@@ -137,6 +162,11 @@
|
|
|
return this._scene;
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Does this action manager handles actions of any of the given triggers
|
|
|
+ * @param triggers {number[]} the triggers to be tested
|
|
|
+ * @return {boolean} whether one (or more) of the triggers is handeled
|
|
|
+ */
|
|
|
ActionManager.prototype.hasSpecificTriggers = function (triggers) {
|
|
|
for (var index = 0; index < this.actions.length; index++) {
|
|
|
var action = this.actions[index];
|
|
@@ -150,6 +180,10 @@
|
|
|
};
|
|
|
|
|
|
Object.defineProperty(ActionManager.prototype, "hasPointerTriggers", {
|
|
|
+ /**
|
|
|
+ * Does this action manager has pointer triggers
|
|
|
+ * @return {boolean} whether or not it has pointer triggers
|
|
|
+ */
|
|
|
get: function () {
|
|
|
for (var index = 0; index < this.actions.length; index++) {
|
|
|
var action = this.actions[index];
|
|
@@ -166,6 +200,10 @@
|
|
|
});
|
|
|
|
|
|
Object.defineProperty(ActionManager.prototype, "hasPickTriggers", {
|
|
|
+ /**
|
|
|
+ * Does this action manager has pick triggers
|
|
|
+ * @return {boolean} whether or not it has pick triggers
|
|
|
+ */
|
|
|
get: function () {
|
|
|
for (var index = 0; index < this.actions.length; index++) {
|
|
|
var action = this.actions[index];
|
|
@@ -181,6 +219,11 @@
|
|
|
configurable: true
|
|
|
});
|
|
|
|
|
|
+ /**
|
|
|
+ * Registers an action to this action manager
|
|
|
+ * @param action {BABYLON.Action} the action to be registered
|
|
|
+ * @return {BABYLON.Action} the action amended (prepared) after registration
|
|
|
+ */
|
|
|
ActionManager.prototype.registerAction = function (action) {
|
|
|
if (action.trigger === ActionManager.OnEveryFrameTrigger) {
|
|
|
if (this.getScene().actionManager !== this) {
|
|
@@ -197,6 +240,11 @@
|
|
|
return action;
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Process a specific trigger
|
|
|
+ * @param trigger {number} the trigger to process
|
|
|
+ * @param evt {BABYLON.ActionEvent} the event details to be processed
|
|
|
+ */
|
|
|
ActionManager.prototype.processTrigger = function (trigger, evt) {
|
|
|
for (var index = 0; index < this.actions.length; index++) {
|
|
|
var action = this.actions[index];
|