|
@@ -6564,12 +6564,24 @@ var BABYLON;
|
|
*/
|
|
*/
|
|
var EventState = /** @class */ (function () {
|
|
var EventState = /** @class */ (function () {
|
|
/**
|
|
/**
|
|
- * If the callback of a given Observer set skipNextObservers to true the following observers will be ignored
|
|
|
|
- */
|
|
|
|
|
|
+ * Create a new EventState
|
|
|
|
+ * @param mask defines the mask associated with this state
|
|
|
|
+ * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true
|
|
|
|
+ * @param target defines the original target of the state
|
|
|
|
+ * @param currentTarget defines the current target of the state
|
|
|
|
+ */
|
|
function EventState(mask, skipNextObservers, target, currentTarget) {
|
|
function EventState(mask, skipNextObservers, target, currentTarget) {
|
|
if (skipNextObservers === void 0) { skipNextObservers = false; }
|
|
if (skipNextObservers === void 0) { skipNextObservers = false; }
|
|
this.initalize(mask, skipNextObservers, target, currentTarget);
|
|
this.initalize(mask, skipNextObservers, target, currentTarget);
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * Initialize the current event state
|
|
|
|
+ * @param mask defines the mask associated with this state
|
|
|
|
+ * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true
|
|
|
|
+ * @param target defines the original target of the state
|
|
|
|
+ * @param currentTarget defines the current target of the state
|
|
|
|
+ * @returns the current event state
|
|
|
|
+ */
|
|
EventState.prototype.initalize = function (mask, skipNextObservers, target, currentTarget) {
|
|
EventState.prototype.initalize = function (mask, skipNextObservers, target, currentTarget) {
|
|
if (skipNextObservers === void 0) { skipNextObservers = false; }
|
|
if (skipNextObservers === void 0) { skipNextObservers = false; }
|
|
this.mask = mask;
|
|
this.mask = mask;
|
|
@@ -6585,11 +6597,33 @@ var BABYLON;
|
|
* Represent an Observer registered to a given Observable object.
|
|
* Represent an Observer registered to a given Observable object.
|
|
*/
|
|
*/
|
|
var Observer = /** @class */ (function () {
|
|
var Observer = /** @class */ (function () {
|
|
- function Observer(callback, mask, scope) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Creates a new observer
|
|
|
|
+ * @param callback defines the callback to call when the observer is notified
|
|
|
|
+ * @param mask defines the mask of the observer (used to filter notifications)
|
|
|
|
+ * @param scope defines the current scope used to restore the JS context
|
|
|
|
+ */
|
|
|
|
+ function Observer(
|
|
|
|
+ /**
|
|
|
|
+ * Defines the callback to call when the observer is notified
|
|
|
|
+ */
|
|
|
|
+ callback,
|
|
|
|
+ /**
|
|
|
|
+ * Defines the mask of the observer (used to filter notifications)
|
|
|
|
+ */
|
|
|
|
+ mask,
|
|
|
|
+ /**
|
|
|
|
+ * Defines the current scope used to restore the JS context
|
|
|
|
+ */
|
|
|
|
+ scope) {
|
|
if (scope === void 0) { scope = null; }
|
|
if (scope === void 0) { scope = null; }
|
|
this.callback = callback;
|
|
this.callback = callback;
|
|
this.mask = mask;
|
|
this.mask = mask;
|
|
this.scope = scope;
|
|
this.scope = scope;
|
|
|
|
+ /**
|
|
|
|
+ * Gets or sets a property defining that the observer as to be unregistered after the next notification
|
|
|
|
+ */
|
|
|
|
+ this.unregisterOnNextCall = false;
|
|
}
|
|
}
|
|
return Observer;
|
|
return Observer;
|
|
}());
|
|
}());
|
|
@@ -6600,6 +6634,9 @@ var BABYLON;
|
|
var MultiObserver = /** @class */ (function () {
|
|
var MultiObserver = /** @class */ (function () {
|
|
function MultiObserver() {
|
|
function MultiObserver() {
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * Release associated resources
|
|
|
|
+ */
|
|
MultiObserver.prototype.dispose = function () {
|
|
MultiObserver.prototype.dispose = function () {
|
|
if (this._observers && this._observables) {
|
|
if (this._observers && this._observables) {
|
|
for (var index = 0; index < this._observers.length; index++) {
|
|
for (var index = 0; index < this._observers.length; index++) {
|
|
@@ -6609,6 +6646,14 @@ var BABYLON;
|
|
this._observers = null;
|
|
this._observers = null;
|
|
this._observables = null;
|
|
this._observables = null;
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Raise a callback when one of the observable will notify
|
|
|
|
+ * @param observables defines a list of observables to watch
|
|
|
|
+ * @param callback defines the callback to call on notification
|
|
|
|
+ * @param mask defines the mask used to filter notifications
|
|
|
|
+ * @param scope defines the current scope used to restore the JS context
|
|
|
|
+ * @returns the new MultiObserver
|
|
|
|
+ */
|
|
MultiObserver.Watch = function (observables, callback, mask, scope) {
|
|
MultiObserver.Watch = function (observables, callback, mask, scope) {
|
|
if (mask === void 0) { mask = -1; }
|
|
if (mask === void 0) { mask = -1; }
|
|
if (scope === void 0) { scope = null; }
|
|
if (scope === void 0) { scope = null; }
|
|
@@ -6635,6 +6680,10 @@ var BABYLON;
|
|
* A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.
|
|
* A given observer can register itself with only Move and Stop (mask = 0x03), then it will only be notified when one of these two occurs and will never be for Turn Left/Right.
|
|
*/
|
|
*/
|
|
var Observable = /** @class */ (function () {
|
|
var Observable = /** @class */ (function () {
|
|
|
|
+ /**
|
|
|
|
+ * Creates a new observable
|
|
|
|
+ * @param onObserverAdded defines a callback to call when a new observer is added
|
|
|
|
+ */
|
|
function Observable(onObserverAdded) {
|
|
function Observable(onObserverAdded) {
|
|
this._observers = new Array();
|
|
this._observers = new Array();
|
|
this._eventState = new EventState(0);
|
|
this._eventState = new EventState(0);
|
|
@@ -6648,15 +6697,19 @@ var BABYLON;
|
|
* @param mask the mask used to filter observers
|
|
* @param mask the mask used to filter observers
|
|
* @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.
|
|
* @param insertFirst if true the callback will be inserted at the first position, hence executed before the others ones. If false (default behavior) the callback will be inserted at the last position, executed after all the others already present.
|
|
* @param scope optional scope for the callback to be called from
|
|
* @param scope optional scope for the callback to be called from
|
|
|
|
+ * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification
|
|
|
|
+ * @returns the new observer created for the callback
|
|
*/
|
|
*/
|
|
- Observable.prototype.add = function (callback, mask, insertFirst, scope) {
|
|
|
|
|
|
+ Observable.prototype.add = function (callback, mask, insertFirst, scope, unregisterOnFirstCall) {
|
|
if (mask === void 0) { mask = -1; }
|
|
if (mask === void 0) { mask = -1; }
|
|
if (insertFirst === void 0) { insertFirst = false; }
|
|
if (insertFirst === void 0) { insertFirst = false; }
|
|
if (scope === void 0) { scope = null; }
|
|
if (scope === void 0) { scope = null; }
|
|
|
|
+ if (unregisterOnFirstCall === void 0) { unregisterOnFirstCall = false; }
|
|
if (!callback) {
|
|
if (!callback) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
var observer = new Observer(callback, mask, scope);
|
|
var observer = new Observer(callback, mask, scope);
|
|
|
|
+ observer.unregisterOnNextCall = unregisterOnFirstCall;
|
|
if (insertFirst) {
|
|
if (insertFirst) {
|
|
this._observers.unshift(observer);
|
|
this._observers.unshift(observer);
|
|
}
|
|
}
|
|
@@ -6670,7 +6723,8 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Remove an Observer from the Observable object
|
|
* Remove an Observer from the Observable object
|
|
- * @param observer the instance of the Observer to remove. If it doesn't belong to this Observable, false will be returned.
|
|
|
|
|
|
+ * @param observer the instance of the Observer to remove
|
|
|
|
+ * @returns false if it doesn't belong to this Observable
|
|
*/
|
|
*/
|
|
Observable.prototype.remove = function (observer) {
|
|
Observable.prototype.remove = function (observer) {
|
|
if (!observer) {
|
|
if (!observer) {
|
|
@@ -6685,8 +6739,9 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Remove a callback from the Observable object
|
|
* Remove a callback from the Observable object
|
|
- * @param callback the callback to remove. If it doesn't belong to this Observable, false will be returned.
|
|
|
|
- * @param scope optional scope. If used only the callbacks with this scope will be removed.
|
|
|
|
|
|
+ * @param callback the callback to remove
|
|
|
|
+ * @param scope optional scope. If used only the callbacks with this scope will be removed
|
|
|
|
+ * @returns false if it doesn't belong to this Observable
|
|
*/
|
|
*/
|
|
Observable.prototype.removeCallback = function (callback, scope) {
|
|
Observable.prototype.removeCallback = function (callback, scope) {
|
|
for (var index = 0; index < this._observers.length; index++) {
|
|
for (var index = 0; index < this._observers.length; index++) {
|
|
@@ -6697,11 +6752,20 @@ var BABYLON;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
};
|
|
};
|
|
|
|
+ Observable.prototype._deferUnregister = function (observer) {
|
|
|
|
+ var _this = this;
|
|
|
|
+ BABYLON.Tools.SetImmediate(function () {
|
|
|
|
+ _this.remove(observer);
|
|
|
|
+ });
|
|
|
|
+ };
|
|
/**
|
|
/**
|
|
* Notify all Observers by calling their respective callback with the given data
|
|
* Notify all Observers by calling their respective callback with the given data
|
|
* Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute
|
|
* Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute
|
|
- * @param eventData
|
|
|
|
- * @param mask
|
|
|
|
|
|
+ * @param eventData defines the data to send to all observers
|
|
|
|
+ * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)
|
|
|
|
+ * @param target defines the original target of the state
|
|
|
|
+ * @param currentTarget defines the current target of the state
|
|
|
|
+ * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)
|
|
*/
|
|
*/
|
|
Observable.prototype.notifyObservers = function (eventData, mask, target, currentTarget) {
|
|
Observable.prototype.notifyObservers = function (eventData, mask, target, currentTarget) {
|
|
if (mask === void 0) { mask = -1; }
|
|
if (mask === void 0) { mask = -1; }
|
|
@@ -6723,6 +6787,9 @@ var BABYLON;
|
|
else {
|
|
else {
|
|
state.lastReturnValue = obs.callback(eventData, state);
|
|
state.lastReturnValue = obs.callback(eventData, state);
|
|
}
|
|
}
|
|
|
|
+ if (obs.unregisterOnNextCall) {
|
|
|
|
+ this._deferUnregister(obs);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (state.skipNextObservers) {
|
|
if (state.skipNextObservers) {
|
|
return false;
|
|
return false;
|
|
@@ -6739,11 +6806,12 @@ var BABYLON;
|
|
*
|
|
*
|
|
* @param eventData The data to be sent to each callback
|
|
* @param eventData The data to be sent to each callback
|
|
* @param mask is used to filter observers defaults to -1
|
|
* @param mask is used to filter observers defaults to -1
|
|
- * @param target the callback target (see EventState)
|
|
|
|
- * @param currentTarget The current object in the bubbling phase
|
|
|
|
|
|
+ * @param target defines the callback target (see EventState)
|
|
|
|
+ * @param currentTarget defines he current object in the bubbling phase
|
|
* @returns {Promise<T>} will return a Promise than resolves when all callbacks executed successfully.
|
|
* @returns {Promise<T>} will return a Promise than resolves when all callbacks executed successfully.
|
|
*/
|
|
*/
|
|
Observable.prototype.notifyObserversWithPromise = function (eventData, mask, target, currentTarget) {
|
|
Observable.prototype.notifyObserversWithPromise = function (eventData, mask, target, currentTarget) {
|
|
|
|
+ var _this = this;
|
|
if (mask === void 0) { mask = -1; }
|
|
if (mask === void 0) { mask = -1; }
|
|
// create an empty promise
|
|
// create an empty promise
|
|
var p = Promise.resolve(eventData);
|
|
var p = Promise.resolve(eventData);
|
|
@@ -6774,6 +6842,9 @@ var BABYLON;
|
|
return obs.callback(eventData, state);
|
|
return obs.callback(eventData, state);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ if (obs.unregisterOnNextCall) {
|
|
|
|
+ _this._deferUnregister(obs);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
// return the eventData
|
|
// return the eventData
|
|
@@ -6781,8 +6852,9 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Notify a specific observer
|
|
* Notify a specific observer
|
|
- * @param eventData
|
|
|
|
- * @param mask
|
|
|
|
|
|
+ * @param observer defines the observer to notify
|
|
|
|
+ * @param eventData defines the data to be sent to each callback
|
|
|
|
+ * @param mask is used to filter observers defaults to -1
|
|
*/
|
|
*/
|
|
Observable.prototype.notifyObserver = function (observer, eventData, mask) {
|
|
Observable.prototype.notifyObserver = function (observer, eventData, mask) {
|
|
if (mask === void 0) { mask = -1; }
|
|
if (mask === void 0) { mask = -1; }
|
|
@@ -6792,7 +6864,8 @@ var BABYLON;
|
|
observer.callback(eventData, state);
|
|
observer.callback(eventData, state);
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * return true is the Observable has at least one Observer registered
|
|
|
|
|
|
+ * Gets a boolean indicating if the observable has at least one observer
|
|
|
|
+ * @returns true is the Observable has at least one Observer registered
|
|
*/
|
|
*/
|
|
Observable.prototype.hasObservers = function () {
|
|
Observable.prototype.hasObservers = function () {
|
|
return this._observers.length > 0;
|
|
return this._observers.length > 0;
|
|
@@ -6805,8 +6878,9 @@ var BABYLON;
|
|
this._onObserverAdded = null;
|
|
this._onObserverAdded = null;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * Clone the current observable
|
|
|
|
- */
|
|
|
|
|
|
+ * Clone the current observable
|
|
|
|
+ * @returns a new observable
|
|
|
|
+ */
|
|
Observable.prototype.clone = function () {
|
|
Observable.prototype.clone = function () {
|
|
var result = new Observable();
|
|
var result = new Observable();
|
|
result._observers = this._observers.slice(0);
|
|
result._observers = this._observers.slice(0);
|
|
@@ -6814,8 +6888,8 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Does this observable handles observer registered with a given mask
|
|
* Does this observable handles observer registered with a given mask
|
|
- * @param {number} trigger - the mask to be tested
|
|
|
|
- * @return {boolean} whether or not one observer registered with the given mask is handeled
|
|
|
|
|
|
+ * @param mask defines the mask to be tested
|
|
|
|
+ * @return whether or not one observer registered with the given mask is handeled
|
|
**/
|
|
**/
|
|
Observable.prototype.hasSpecificMask = function (mask) {
|
|
Observable.prototype.hasSpecificMask = function (mask) {
|
|
if (mask === void 0) { mask = -1; }
|
|
if (mask === void 0) { mask = -1; }
|
|
@@ -15195,13 +15269,21 @@ var BABYLON;
|
|
configurable: true
|
|
configurable: true
|
|
});
|
|
});
|
|
/**
|
|
/**
|
|
|
|
+ * Sets a new matrix to apply before all other transformation
|
|
|
|
+ * @param matrix defines the transform matrix
|
|
|
|
+ * @returns the current TransformNode
|
|
|
|
+ */
|
|
|
|
+ TransformNode.prototype.setPreTransformMatrix = function (matrix) {
|
|
|
|
+ return this.setPivotMatrix(matrix, false);
|
|
|
|
+ };
|
|
|
|
+ /**
|
|
* Sets a new pivot matrix to the current node
|
|
* Sets a new pivot matrix to the current node
|
|
* @param matrix defines the new pivot matrix to use
|
|
* @param matrix defines the new pivot matrix to use
|
|
- * @param postMultiplyPivotMatrix defines if the pivot matrix must be cancelled in the world matrix. By default the pivot matrix is just applied at the beginning of the world matrix. When this parameter is set to true, the inverse of the pivot matrix is also applied at the end to cancel the transformation effect
|
|
|
|
|
|
+ * @param postMultiplyPivotMatrix defines if the pivot matrix must be cancelled in the world matrix. When this parameter is set to true (default), the inverse of the pivot matrix is also applied at the end to cancel the transformation effect
|
|
* @returns the current TransformNode
|
|
* @returns the current TransformNode
|
|
*/
|
|
*/
|
|
TransformNode.prototype.setPivotMatrix = function (matrix, postMultiplyPivotMatrix) {
|
|
TransformNode.prototype.setPivotMatrix = function (matrix, postMultiplyPivotMatrix) {
|
|
- if (postMultiplyPivotMatrix === void 0) { postMultiplyPivotMatrix = false; }
|
|
|
|
|
|
+ if (postMultiplyPivotMatrix === void 0) { postMultiplyPivotMatrix = true; }
|
|
this._pivotMatrix = matrix.clone();
|
|
this._pivotMatrix = matrix.clone();
|
|
this._cache.pivotMatrixUpdated = true;
|
|
this._cache.pivotMatrixUpdated = true;
|
|
this._postMultiplyPivotMatrix = postMultiplyPivotMatrix;
|
|
this._postMultiplyPivotMatrix = postMultiplyPivotMatrix;
|
|
@@ -15379,12 +15461,10 @@ var BABYLON;
|
|
* Sets a new pivot point to the current node
|
|
* Sets a new pivot point to the current node
|
|
* @param point defines the new pivot point to use
|
|
* @param point defines the new pivot point to use
|
|
* @param space defines if the point is in world or local space (local by default)
|
|
* @param space defines if the point is in world or local space (local by default)
|
|
- * @param postMultiplyPivotMatrix defines if the pivot transformation must be cancelled in the world matrix. By default the pivot matrix is just applied at the beginning of the world matrix. When this parameter is set to true, the inverse of the pivot matrix is also applied at the end to cancel the transformation effect
|
|
|
|
* @returns the current TransformNode
|
|
* @returns the current TransformNode
|
|
*/
|
|
*/
|
|
- TransformNode.prototype.setPivotPoint = function (point, space, postMultiplyPivotMatrix) {
|
|
|
|
|
|
+ TransformNode.prototype.setPivotPoint = function (point, space) {
|
|
if (space === void 0) { space = BABYLON.Space.LOCAL; }
|
|
if (space === void 0) { space = BABYLON.Space.LOCAL; }
|
|
- if (postMultiplyPivotMatrix === void 0) { postMultiplyPivotMatrix = false; }
|
|
|
|
if (this.getScene().getRenderId() == 0) {
|
|
if (this.getScene().getRenderId() == 0) {
|
|
this.computeWorldMatrix(true);
|
|
this.computeWorldMatrix(true);
|
|
}
|
|
}
|
|
@@ -15394,20 +15474,7 @@ var BABYLON;
|
|
wm.invertToRef(tmat);
|
|
wm.invertToRef(tmat);
|
|
point = BABYLON.Vector3.TransformCoordinates(point, tmat);
|
|
point = BABYLON.Vector3.TransformCoordinates(point, tmat);
|
|
}
|
|
}
|
|
- BABYLON.Vector3.TransformCoordinatesToRef(point, wm, this.position);
|
|
|
|
- this._pivotMatrix.m[12] = -point.x;
|
|
|
|
- this._pivotMatrix.m[13] = -point.y;
|
|
|
|
- this._pivotMatrix.m[14] = -point.z;
|
|
|
|
- if (this._postMultiplyPivotMatrix) {
|
|
|
|
- if (!this._pivotMatrixInverse) {
|
|
|
|
- this._pivotMatrixInverse = BABYLON.Matrix.Invert(this._pivotMatrix);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- this._pivotMatrix.invertToRef(this._pivotMatrixInverse);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- this._cache.pivotMatrixUpdated = true;
|
|
|
|
- return this;
|
|
|
|
|
|
+ return this.setPivotMatrix(BABYLON.Matrix.Translation(point.x, point.y, point.z), true);
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Returns a new Vector3 set with the mesh pivot point coordinates in the local space.
|
|
* Returns a new Vector3 set with the mesh pivot point coordinates in the local space.
|