@babylonjs/core 7.11.1 → 7.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,7 @@ export declare class Observer<T> {
59
59
  */
60
60
  mask: number;
61
61
  /**
62
- * Defines the current scope used to restore the JS context
62
+ * [scope] Defines the current scope used to restore the JS context
63
63
  */
64
64
  scope: any;
65
65
  /** @internal */
@@ -78,7 +78,7 @@ export declare class Observer<T> {
78
78
  * Creates a new observer
79
79
  * @param callback defines the callback to call when the observer is notified
80
80
  * @param mask defines the mask of the observer (used to filter notifications)
81
- * @param scope defines the current scope used to restore the JS context
81
+ * @param [scope] defines the current scope used to restore the JS context
82
82
  */
83
83
  constructor(
84
84
  /**
@@ -90,7 +90,7 @@ export declare class Observer<T> {
90
90
  */
91
91
  mask: number,
92
92
  /**
93
- * Defines the current scope used to restore the JS context
93
+ * [scope] Defines the current scope used to restore the JS context
94
94
  */
95
95
  scope?: any);
96
96
  /**
@@ -109,7 +109,7 @@ export declare class Observer<T> {
109
109
  */
110
110
  export declare class Observable<T> {
111
111
  /**
112
- * If set to true the observable will notify when an observer was added if the observable was already triggered.
112
+ * [notifyIfTriggered] If set to true the observable will notify when an observer was added if the observable was already triggered.
113
113
  * This is helpful to single-state observables like the scene onReady or the dispose observable.
114
114
  */
115
115
  notifyIfTriggered: boolean;
@@ -137,11 +137,11 @@ export declare class Observable<T> {
137
137
  /**
138
138
  * Creates a new observable
139
139
  * @param onObserverAdded defines a callback to call when a new observer is added
140
- * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.
140
+ * @param [notifyIfTriggered] If set to true the observable will notify when an observer was added if the observable was already triggered.
141
141
  */
142
142
  constructor(onObserverAdded?: (observer: Observer<T>) => void,
143
143
  /**
144
- * If set to true the observable will notify when an observer was added if the observable was already triggered.
144
+ * [notifyIfTriggered] If set to true the observable will notify when an observer was added if the observable was already triggered.
145
145
  * This is helpful to single-state observables like the scene onReady or the dispose observable.
146
146
  */
147
147
  notifyIfTriggered?: boolean);
@@ -36,7 +36,7 @@ export class Observer {
36
36
  * Creates a new observer
37
37
  * @param callback defines the callback to call when the observer is notified
38
38
  * @param mask defines the mask of the observer (used to filter notifications)
39
- * @param scope defines the current scope used to restore the JS context
39
+ * @param [scope] defines the current scope used to restore the JS context
40
40
  */
41
41
  constructor(
42
42
  /**
@@ -48,7 +48,7 @@ export class Observer {
48
48
  */
49
49
  mask,
50
50
  /**
51
- * Defines the current scope used to restore the JS context
51
+ * [scope] Defines the current scope used to restore the JS context
52
52
  */
53
53
  scope = null) {
54
54
  this.callback = callback;
@@ -118,11 +118,11 @@ export class Observable {
118
118
  /**
119
119
  * Creates a new observable
120
120
  * @param onObserverAdded defines a callback to call when a new observer is added
121
- * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.
121
+ * @param [notifyIfTriggered] If set to true the observable will notify when an observer was added if the observable was already triggered.
122
122
  */
123
123
  constructor(onObserverAdded,
124
124
  /**
125
- * If set to true the observable will notify when an observer was added if the observable was already triggered.
125
+ * [notifyIfTriggered] If set to true the observable will notify when an observer was added if the observable was already triggered.
126
126
  * This is helpful to single-state observables like the scene onReady or the dispose observable.
127
127
  */
128
128
  notifyIfTriggered = false) {
@@ -1 +1 @@
1
- {"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/observable.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QAClF,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;OAOG;IACI,UAAU,CAAC,IAAY,EAAE,iBAAiB,GAAG,KAAK,EAAE,MAAY,EAAE,aAAmB;QACxF,IAAI,CAAC,IAAI,GAAG,IAAI,CA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I,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE7C,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;QAII;IACG,eAAe,CAAC,OAAe,CAAC,CAAC;QACpC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;YAC/B,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE;gBACtC,OAAO,IAAI,CAAC;aACf;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * A class serves as a medium between the observable and its observers\r\n */\r\nexport class EventState {\r\n /**\r\n * Create a new EventState\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n */\r\n constructor(mask: number, skipNextObservers = false, target?: any, currentTarget?: any) {\r\n this.initialize(mask, skipNextObservers, target, currentTarget);\r\n }\r\n\r\n /**\r\n * Initialize the current event state\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @returns the current event state\r\n */\r\n public initialize(mask: number, skipNextObservers = false, target?: any, currentTarget?: any): EventState {\r\n this.mask = mask;\r\n this.skipNextObservers = skipNextObservers;\r\n this.target = target;\r\n this.currentTarget = currentTarget;\r\n return this;\r\n }\r\n\r\n /**\r\n * An Observer can set this property to true to prevent subsequent observers of being notified\r\n */\r\n public skipNextObservers: boolean;\r\n\r\n /**\r\n * Get the mask value that were used to trigger the event corresponding to this EventState object\r\n */\r\n public mask: number;\r\n\r\n /**\r\n * The object that originally notified the event\r\n */\r\n public target?: any;\r\n\r\n /**\r\n * The current object in the bubbling phase\r\n */\r\n public currentTarget?: any;\r\n\r\n /**\r\n * This will be populated with the return value of the last function that was executed.\r\n * If it is the first function in the callback chain it will be the event data.\r\n */\r\n public lastReturnValue?: any;\r\n\r\n /**\r\n * User defined information that will be sent to observers\r\n */\r\n public userInfo?: any;\r\n}\r\n\r\n/**\r\n * Represent an Observer registered to a given Observable object.\r\n */\r\nexport class Observer<T> {\r\n /** @internal */\r\n public _willBeUnregistered = false;\r\n /**\r\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\r\n */\r\n public unregisterOnNextCall = false;\r\n\r\n /**\r\n * this function can be used to remove the observer from the observable.\r\n * It will be set by the observable that the observer belongs to.\r\n * @internal\r\n */\r\n public _remove: Nullable<() => void> = null;\r\n\r\n /**\r\n * Creates a new observer\r\n * @param callback defines the callback to call when the observer is notified\r\n * @param mask defines the mask of the observer (used to filter notifications)\r\n * @param scope defines the current scope used to restore the JS context\r\n */\r\n constructor(\r\n /**\r\n * Defines the callback to call when the observer is notified\r\n */\r\n public callback: (eventData: T, eventState: EventState) => void,\r\n /**\r\n * Defines the mask of the observer (used to filter notifications)\r\n */\r\n public mask: number,\r\n /**\r\n * Defines the current scope used to restore the JS context\r\n */\r\n public scope: any = null\r\n ) {}\r\n\r\n /**\r\n * Remove the observer from its observable\r\n * This can be used instead of using the observable's remove function.\r\n */\r\n public remove() {\r\n if (this._remove) {\r\n this._remove();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The Observable class is a simple implementation of the Observable pattern.\r\n *\r\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\r\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\r\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\r\n * 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.\r\n */\r\nexport class Observable<T> {\r\n private _observers = new Array<Observer<T>>();\r\n private _numObserversMarkedAsDeleted = 0;\r\n private _hasNotified = false;\r\n private _lastNotifiedValue?: T;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _eventState: EventState;\r\n\r\n private _onObserverAdded: Nullable<(observer: Observer<T>) => void>;\r\n\r\n /**\r\n * Create an observable from a Promise.\r\n * @param promise a promise to observe for fulfillment.\r\n * @param onErrorObservable an observable to notify if a promise was rejected.\r\n * @returns the new Observable\r\n */\r\n public static FromPromise<T, E = Error>(promise: Promise<T>, onErrorObservable?: Observable<E>): Observable<T> {\r\n const observable = new Observable<T>();\r\n\r\n promise\r\n .then((ret: T) => {\r\n observable.notifyObservers(ret);\r\n })\r\n .catch((err) => {\r\n if (onErrorObservable) {\r\n onErrorObservable.notifyObservers(err as E);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n\r\n return observable;\r\n }\r\n\r\n /**\r\n * Gets the list of observers\r\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\r\n */\r\n public get observers(): Array<Observer<T>> {\r\n return this._observers;\r\n }\r\n\r\n /**\r\n * Creates a new observable\r\n * @param onObserverAdded defines a callback to call when a new observer is added\r\n * @param notifyIfTriggered If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n */\r\n constructor(\r\n onObserverAdded?: (observer: Observer<T>) => void,\r\n /**\r\n * If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\r\n */\r\n public notifyIfTriggered = false\r\n ) {\r\n this._eventState = new EventState(0);\r\n\r\n if (onObserverAdded) {\r\n this._onObserverAdded = onObserverAdded;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @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.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n public add(callback?: null | undefined, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): null;\r\n public add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): Observer<T>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null | undefined,\r\n mask?: number,\r\n insertFirst?: boolean,\r\n scope?: any,\r\n unregisterOnFirstCall?: boolean\r\n ): Nullable<Observer<T>>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null | undefined,\r\n mask: number = -1,\r\n insertFirst = false,\r\n scope: any = null,\r\n unregisterOnFirstCall = false\r\n ): Nullable<Observer<T>> {\r\n if (!callback) {\r\n return null;\r\n }\r\n\r\n const observer = new Observer(callback, mask, scope);\r\n observer.unregisterOnNextCall = unregisterOnFirstCall;\r\n\r\n if (insertFirst) {\r\n this._observers.unshift(observer);\r\n } else {\r\n this._observers.push(observer);\r\n }\r\n\r\n if (this._onObserverAdded) {\r\n this._onObserverAdded(observer);\r\n }\r\n\r\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\r\n if (this._hasNotified && this.notifyIfTriggered) {\r\n if (this._lastNotifiedValue !== undefined) {\r\n this.notifyObserver(observer, this._lastNotifiedValue);\r\n }\r\n }\r\n // attach the remove function to the observer\r\n observer._remove = () => {\r\n this.remove(observer);\r\n };\r\n\r\n return observer;\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n public addOnce(callback?: null | undefined): null;\r\n public addOnce(callback: (eventData: T, eventState: EventState) => void): Observer<T>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null | undefined): Nullable<Observer<T>>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null | undefined): Nullable<Observer<T>> {\r\n return this.add(callback, undefined, undefined, undefined, true);\r\n }\r\n\r\n /**\r\n * Remove an Observer from the Observable object\r\n * @param observer the instance of the Observer to remove\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public remove(observer: Nullable<Observer<T>>): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n observer._remove = null;\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Remove a callback from the Observable object\r\n * @param callback the callback to remove\r\n * @param scope optional scope. If used only the callbacks with this scope will be removed\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {\r\n for (let index = 0; index < this._observers.length; index++) {\r\n const observer = this._observers[index];\r\n if (observer._willBeUnregistered) {\r\n continue;\r\n }\r\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deferUnregister(observer: Observer<T>): void {\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n this._numObserversMarkedAsDeleted++;\r\n observer.unregisterOnNextCall = false;\r\n observer._willBeUnregistered = true;\r\n setTimeout(() => {\r\n this._remove(observer);\r\n }, 0);\r\n }\r\n\r\n // This should only be called when not iterating over _observers to avoid callback skipping.\r\n // Removes an observer from the _observer Array.\r\n private _remove(observer: Nullable<Observer<T>>, updateCounter = true): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n if (updateCounter) {\r\n this._numObserversMarkedAsDeleted--;\r\n }\r\n this._observers.splice(index, 1);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Moves the observable to the top of the observer list making it get called first when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverTopPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.unshift(observer);\r\n }\r\n\r\n /**\r\n * Moves the observable to the bottom of the observer list making it get called last when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverBottomPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.push(observer);\r\n }\r\n\r\n /**\r\n * Notify all Observers by calling their respective callback with the given data\r\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\r\n * @param eventData defines the data to send to all observers\r\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @param userInfo defines any user info to send to observers\r\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\r\n */\r\n public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any, userInfo?: any): boolean {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (!this._observers.length) {\r\n return true;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.target = target;\r\n state.currentTarget = currentTarget;\r\n state.skipNextObservers = false;\r\n state.lastReturnValue = eventData;\r\n state.userInfo = userInfo;\r\n\r\n for (const obs of this._observers) {\r\n if (obs._willBeUnregistered) {\r\n continue;\r\n }\r\n\r\n if (obs.mask & mask) {\r\n if (obs.unregisterOnNextCall) {\r\n this._deferUnregister(obs);\r\n }\r\n\r\n if (obs.scope) {\r\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\r\n } else {\r\n state.lastReturnValue = obs.callback(eventData, state);\r\n }\r\n }\r\n if (state.skipNextObservers) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Notify a specific observer\r\n * @param observer defines the observer to notify\r\n * @param eventData defines the data to be sent to each callback\r\n * @param mask is used to filter observers defaults to -1\r\n */\r\n public notifyObserver(observer: Observer<T>, eventData: T, mask: number = -1): void {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.skipNextObservers = false;\r\n\r\n if (observer.unregisterOnNextCall) {\r\n this._deferUnregister(observer);\r\n }\r\n\r\n observer.callback(eventData, state);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the observable has at least one observer\r\n * @returns true is the Observable has at least one Observer registered\r\n */\r\n public hasObservers(): boolean {\r\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\r\n }\r\n\r\n /**\r\n * Clear the list of observers\r\n */\r\n public clear(): void {\r\n while (this._observers.length) {\r\n const o = this._observers.pop();\r\n if (o) {\r\n o._remove = null;\r\n }\r\n }\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\r\n this.cleanLastNotifiedState();\r\n }\r\n\r\n /**\r\n * Clean the last notified state - both the internal last value and the has-notified flag\r\n */\r\n public cleanLastNotifiedState(): void {\r\n this._hasNotified = false;\r\n this._lastNotifiedValue = undefined;\r\n }\r\n\r\n /**\r\n * Clone the current observable\r\n * @returns a new observable\r\n */\r\n public clone(): Observable<T> {\r\n const result = new Observable<T>();\r\n\r\n result._observers = this._observers.slice(0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Does this observable handles observer registered with a given mask\r\n * @param mask defines the mask to be tested\r\n * @returns whether or not one observer registered with the given mask is handled\r\n **/\r\n public hasSpecificMask(mask: number = -1): boolean {\r\n for (const obs of this._observers) {\r\n if (obs.mask & mask || obs.mask === mask) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/observable.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,UAAU;IACnB;;;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4BAA4B,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,sBAAsB;QACzB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,KAAK;QACR,MAAM,MAAM,GAAG,IAAI,UAAU,EAAK,CAAC;QAEnC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE7C,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;;QAII;IACG,eAAe,CAAC,OAAe,CAAC,CAAC;QACpC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE;YAC/B,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE;gBACtC,OAAO,IAAI,CAAC;aACf;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * A class serves as a medium between the observable and its observers\r\n */\r\nexport class EventState {\r\n /**\r\n * Create a new EventState\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n */\r\n constructor(mask: number, skipNextObservers = false, target?: any, currentTarget?: any) {\r\n this.initialize(mask, skipNextObservers, target, currentTarget);\r\n }\r\n\r\n /**\r\n * Initialize the current event state\r\n * @param mask defines the mask associated with this state\r\n * @param skipNextObservers defines a flag which will instruct the observable to skip following observers when set to true\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @returns the current event state\r\n */\r\n public initialize(mask: number, skipNextObservers = false, target?: any, currentTarget?: any): EventState {\r\n this.mask = mask;\r\n this.skipNextObservers = skipNextObservers;\r\n this.target = target;\r\n this.currentTarget = currentTarget;\r\n return this;\r\n }\r\n\r\n /**\r\n * An Observer can set this property to true to prevent subsequent observers of being notified\r\n */\r\n public skipNextObservers: boolean;\r\n\r\n /**\r\n * Get the mask value that were used to trigger the event corresponding to this EventState object\r\n */\r\n public mask: number;\r\n\r\n /**\r\n * The object that originally notified the event\r\n */\r\n public target?: any;\r\n\r\n /**\r\n * The current object in the bubbling phase\r\n */\r\n public currentTarget?: any;\r\n\r\n /**\r\n * This will be populated with the return value of the last function that was executed.\r\n * If it is the first function in the callback chain it will be the event data.\r\n */\r\n public lastReturnValue?: any;\r\n\r\n /**\r\n * User defined information that will be sent to observers\r\n */\r\n public userInfo?: any;\r\n}\r\n\r\n/**\r\n * Represent an Observer registered to a given Observable object.\r\n */\r\nexport class Observer<T> {\r\n /** @internal */\r\n public _willBeUnregistered = false;\r\n /**\r\n * Gets or sets a property defining that the observer as to be unregistered after the next notification\r\n */\r\n public unregisterOnNextCall = false;\r\n\r\n /**\r\n * this function can be used to remove the observer from the observable.\r\n * It will be set by the observable that the observer belongs to.\r\n * @internal\r\n */\r\n public _remove: Nullable<() => void> = null;\r\n\r\n /**\r\n * Creates a new observer\r\n * @param callback defines the callback to call when the observer is notified\r\n * @param mask defines the mask of the observer (used to filter notifications)\r\n * @param [scope] defines the current scope used to restore the JS context\r\n */\r\n constructor(\r\n /**\r\n * Defines the callback to call when the observer is notified\r\n */\r\n public callback: (eventData: T, eventState: EventState) => void,\r\n /**\r\n * Defines the mask of the observer (used to filter notifications)\r\n */\r\n public mask: number,\r\n /**\r\n * [scope] Defines the current scope used to restore the JS context\r\n */\r\n public scope: any = null\r\n ) {}\r\n\r\n /**\r\n * Remove the observer from its observable\r\n * This can be used instead of using the observable's remove function.\r\n */\r\n public remove() {\r\n if (this._remove) {\r\n this._remove();\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The Observable class is a simple implementation of the Observable pattern.\r\n *\r\n * There's one slight particularity though: a given Observable can notify its observer using a particular mask value, only the Observers registered with this mask value will be notified.\r\n * This enable a more fine grained execution without having to rely on multiple different Observable objects.\r\n * For instance you may have a given Observable that have four different types of notifications: Move (mask = 0x01), Stop (mask = 0x02), Turn Right (mask = 0X04), Turn Left (mask = 0X08).\r\n * 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.\r\n */\r\nexport class Observable<T> {\r\n private _observers = new Array<Observer<T>>();\r\n private _numObserversMarkedAsDeleted = 0;\r\n private _hasNotified = false;\r\n private _lastNotifiedValue?: T;\r\n\r\n /**\r\n * @internal\r\n */\r\n public _eventState: EventState;\r\n\r\n private _onObserverAdded: Nullable<(observer: Observer<T>) => void>;\r\n\r\n /**\r\n * Create an observable from a Promise.\r\n * @param promise a promise to observe for fulfillment.\r\n * @param onErrorObservable an observable to notify if a promise was rejected.\r\n * @returns the new Observable\r\n */\r\n public static FromPromise<T, E = Error>(promise: Promise<T>, onErrorObservable?: Observable<E>): Observable<T> {\r\n const observable = new Observable<T>();\r\n\r\n promise\r\n .then((ret: T) => {\r\n observable.notifyObservers(ret);\r\n })\r\n .catch((err) => {\r\n if (onErrorObservable) {\r\n onErrorObservable.notifyObservers(err as E);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n\r\n return observable;\r\n }\r\n\r\n /**\r\n * Gets the list of observers\r\n * Note that observers that were recently deleted may still be present in the list because they are only really deleted on the next javascript tick!\r\n */\r\n public get observers(): Array<Observer<T>> {\r\n return this._observers;\r\n }\r\n\r\n /**\r\n * Creates a new observable\r\n * @param onObserverAdded defines a callback to call when a new observer is added\r\n * @param [notifyIfTriggered] If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n */\r\n constructor(\r\n onObserverAdded?: (observer: Observer<T>) => void,\r\n /**\r\n * [notifyIfTriggered] If set to true the observable will notify when an observer was added if the observable was already triggered.\r\n * This is helpful to single-state observables like the scene onReady or the dispose observable.\r\n */\r\n public notifyIfTriggered = false\r\n ) {\r\n this._eventState = new EventState(0);\r\n\r\n if (onObserverAdded) {\r\n this._onObserverAdded = onObserverAdded;\r\n }\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback\r\n * @param callback the callback that will be executed for that Observer\r\n * @param mask the mask used to filter observers\r\n * @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.\r\n * @param scope optional scope for the callback to be called from\r\n * @param unregisterOnFirstCall defines if the observer as to be unregistered after the next notification\r\n * @returns the new observer created for the callback\r\n */\r\n public add(callback?: null | undefined, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): null;\r\n public add(callback: (eventData: T, eventState: EventState) => void, mask?: number, insertFirst?: boolean, scope?: any, unregisterOnFirstCall?: boolean): Observer<T>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null | undefined,\r\n mask?: number,\r\n insertFirst?: boolean,\r\n scope?: any,\r\n unregisterOnFirstCall?: boolean\r\n ): Nullable<Observer<T>>;\r\n public add(\r\n callback?: ((eventData: T, eventState: EventState) => void) | null | undefined,\r\n mask: number = -1,\r\n insertFirst = false,\r\n scope: any = null,\r\n unregisterOnFirstCall = false\r\n ): Nullable<Observer<T>> {\r\n if (!callback) {\r\n return null;\r\n }\r\n\r\n const observer = new Observer(callback, mask, scope);\r\n observer.unregisterOnNextCall = unregisterOnFirstCall;\r\n\r\n if (insertFirst) {\r\n this._observers.unshift(observer);\r\n } else {\r\n this._observers.push(observer);\r\n }\r\n\r\n if (this._onObserverAdded) {\r\n this._onObserverAdded(observer);\r\n }\r\n\r\n // If the observable was already triggered and the observable is set to notify if triggered, notify the new observer\r\n if (this._hasNotified && this.notifyIfTriggered) {\r\n if (this._lastNotifiedValue !== undefined) {\r\n this.notifyObserver(observer, this._lastNotifiedValue);\r\n }\r\n }\r\n // attach the remove function to the observer\r\n observer._remove = () => {\r\n this.remove(observer);\r\n };\r\n\r\n return observer;\r\n }\r\n\r\n /**\r\n * Create a new Observer with the specified callback and unregisters after the next notification\r\n * @param callback the callback that will be executed for that Observer\r\n * @returns the new observer created for the callback\r\n */\r\n public addOnce(callback?: null | undefined): null;\r\n public addOnce(callback: (eventData: T, eventState: EventState) => void): Observer<T>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null | undefined): Nullable<Observer<T>>;\r\n public addOnce(callback?: ((eventData: T, eventState: EventState) => void) | null | undefined): Nullable<Observer<T>> {\r\n return this.add(callback, undefined, undefined, undefined, true);\r\n }\r\n\r\n /**\r\n * Remove an Observer from the Observable object\r\n * @param observer the instance of the Observer to remove\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public remove(observer: Nullable<Observer<T>>): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n observer._remove = null;\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Remove a callback from the Observable object\r\n * @param callback the callback to remove\r\n * @param scope optional scope. If used only the callbacks with this scope will be removed\r\n * @returns false if it doesn't belong to this Observable\r\n */\r\n public removeCallback(callback: (eventData: T, eventState: EventState) => void, scope?: any): boolean {\r\n for (let index = 0; index < this._observers.length; index++) {\r\n const observer = this._observers[index];\r\n if (observer._willBeUnregistered) {\r\n continue;\r\n }\r\n if (observer.callback === callback && (!scope || scope === observer.scope)) {\r\n this._deferUnregister(observer);\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _deferUnregister(observer: Observer<T>): void {\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n this._numObserversMarkedAsDeleted++;\r\n observer.unregisterOnNextCall = false;\r\n observer._willBeUnregistered = true;\r\n setTimeout(() => {\r\n this._remove(observer);\r\n }, 0);\r\n }\r\n\r\n // This should only be called when not iterating over _observers to avoid callback skipping.\r\n // Removes an observer from the _observer Array.\r\n private _remove(observer: Nullable<Observer<T>>, updateCounter = true): boolean {\r\n if (!observer) {\r\n return false;\r\n }\r\n\r\n const index = this._observers.indexOf(observer);\r\n\r\n if (index !== -1) {\r\n if (updateCounter) {\r\n this._numObserversMarkedAsDeleted--;\r\n }\r\n this._observers.splice(index, 1);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Moves the observable to the top of the observer list making it get called first when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverTopPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.unshift(observer);\r\n }\r\n\r\n /**\r\n * Moves the observable to the bottom of the observer list making it get called last when notified\r\n * @param observer the observer to move\r\n */\r\n public makeObserverBottomPriority(observer: Observer<T>) {\r\n this._remove(observer, false);\r\n this._observers.push(observer);\r\n }\r\n\r\n /**\r\n * Notify all Observers by calling their respective callback with the given data\r\n * Will return true if all observers were executed, false if an observer set skipNextObservers to true, then prevent the subsequent ones to execute\r\n * @param eventData defines the data to send to all observers\r\n * @param mask defines the mask of the current notification (observers with incompatible mask (ie mask & observer.mask === 0) will not be notified)\r\n * @param target defines the original target of the state\r\n * @param currentTarget defines the current target of the state\r\n * @param userInfo defines any user info to send to observers\r\n * @returns false if the complete observer chain was not processed (because one observer set the skipNextObservers to true)\r\n */\r\n public notifyObservers(eventData: T, mask: number = -1, target?: any, currentTarget?: any, userInfo?: any): boolean {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (!this._observers.length) {\r\n return true;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.target = target;\r\n state.currentTarget = currentTarget;\r\n state.skipNextObservers = false;\r\n state.lastReturnValue = eventData;\r\n state.userInfo = userInfo;\r\n\r\n for (const obs of this._observers) {\r\n if (obs._willBeUnregistered) {\r\n continue;\r\n }\r\n\r\n if (obs.mask & mask) {\r\n if (obs.unregisterOnNextCall) {\r\n this._deferUnregister(obs);\r\n }\r\n\r\n if (obs.scope) {\r\n state.lastReturnValue = obs.callback.apply(obs.scope, [eventData, state]);\r\n } else {\r\n state.lastReturnValue = obs.callback(eventData, state);\r\n }\r\n }\r\n if (state.skipNextObservers) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Notify a specific observer\r\n * @param observer defines the observer to notify\r\n * @param eventData defines the data to be sent to each callback\r\n * @param mask is used to filter observers defaults to -1\r\n */\r\n public notifyObserver(observer: Observer<T>, eventData: T, mask: number = -1): void {\r\n // this prevents potential memory leaks - if an object is disposed but the observable doesn't get cleared.\r\n if (this.notifyIfTriggered) {\r\n this._hasNotified = true;\r\n this._lastNotifiedValue = eventData;\r\n }\r\n if (observer._willBeUnregistered) {\r\n return;\r\n }\r\n\r\n const state = this._eventState;\r\n state.mask = mask;\r\n state.skipNextObservers = false;\r\n\r\n if (observer.unregisterOnNextCall) {\r\n this._deferUnregister(observer);\r\n }\r\n\r\n observer.callback(eventData, state);\r\n }\r\n\r\n /**\r\n * Gets a boolean indicating if the observable has at least one observer\r\n * @returns true is the Observable has at least one Observer registered\r\n */\r\n public hasObservers(): boolean {\r\n return this._observers.length - this._numObserversMarkedAsDeleted > 0;\r\n }\r\n\r\n /**\r\n * Clear the list of observers\r\n */\r\n public clear(): void {\r\n while (this._observers.length) {\r\n const o = this._observers.pop();\r\n if (o) {\r\n o._remove = null;\r\n }\r\n }\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\r\n this.cleanLastNotifiedState();\r\n }\r\n\r\n /**\r\n * Clean the last notified state - both the internal last value and the has-notified flag\r\n */\r\n public cleanLastNotifiedState(): void {\r\n this._hasNotified = false;\r\n this._lastNotifiedValue = undefined;\r\n }\r\n\r\n /**\r\n * Clone the current observable\r\n * @returns a new observable\r\n */\r\n public clone(): Observable<T> {\r\n const result = new Observable<T>();\r\n\r\n result._observers = this._observers.slice(0);\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Does this observable handles observer registered with a given mask\r\n * @param mask defines the mask to be tested\r\n * @returns whether or not one observer registered with the given mask is handled\r\n **/\r\n public hasSpecificMask(mask: number = -1): boolean {\r\n for (const obs of this._observers) {\r\n if (obs.mask & mask || obs.mask === mask) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
@@ -174,8 +174,8 @@ export class FluidRenderingObject {
174
174
  * Releases the ressources used by the class
175
175
  */
176
176
  dispose() {
177
- this._depthEffectWrapper?.dispose();
178
- this._thicknessEffectWrapper?.dispose();
177
+ this._depthEffectWrapper?.dispose(false);
178
+ this._thicknessEffectWrapper?.dispose(false);
179
179
  }
180
180
  }
181
181
  //# sourceMappingURL=fluidRenderingObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fluidRenderingObject.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/fluidRenderer/fluidRenderingObject.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,mCAA+B;AAEnD,OAAO,EAAE,aAAa,EAAE,0CAAsC;AAC9D,OAAO,EAAE,UAAU,EAAE,iCAA6B;AAIlD;;;GAGG;AACH,MAAM,OAAgB,oBAAoB;IAetC,4CAA4C;IAC5C,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,IAAW,YAAY,CAAC,IAAY;QAChC,IAAI,IAAI,KAAK,IAAI,CAAC,aAAa,EAAE;YAC7B,OAAO;SACV;QAED,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,qBAAqB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAKD,qDAAqD;IACrD,IAAW,aAAa;QACpB,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC;IAC7B,CAAC;IAID,4JAA4J;IAC5J,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAW,WAAW,CAAC,GAAY;QAC/B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ACI,OAAO;QACV,IAAI,CAAC,mBAAmB,EAAE,OAAO,EAAE,CAAC;QACpC,IAAI,CAAC,uBAAuB,EAAE,OAAO,EAAE,CAAC;IAC5C,CAAC;CACJ","sourcesContent":["import type { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport { EffectWrapper } from \"core/Materials/effectRenderer\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/**\r\n * Defines the base object used for fluid rendering.\r\n * It is based on a list of vertices (particles)\r\n */\r\nexport abstract class FluidRenderingObject {\r\n protected _scene: Scene;\r\n protected _engine: AbstractEngine;\r\n protected _effectsAreDirty: boolean;\r\n protected _depthEffectWrapper: Nullable<EffectWrapper>;\r\n protected _thicknessEffectWrapper: Nullable<EffectWrapper>;\r\n\r\n /** Defines the priority of the object. Objects will be rendered in ascending order of priority */\r\n public priority = 0;\r\n\r\n protected _particleSize = 0.1;\r\n\r\n /** Observable triggered when the size of the particle is changed */\r\n public onParticleSizeChanged = new Observable<FluidRenderingObject>();\r\n\r\n /** Gets or sets the size of the particle */\r\n public get particleSize() {\r\n return this._particleSize;\r\n }\r\n\r\n public set particleSize(size: number) {\r\n if (size === this._particleSize) {\r\n return;\r\n }\r\n\r\n this._particleSize = size;\r\n this.onParticleSizeChanged.notifyObservers(this);\r\n }\r\n\r\n /** Defines the alpha value of a particle */\r\n public particleThicknessAlpha = 0.05;\r\n\r\n /** Indicates if the object uses instancing or not */\r\n public get useInstancing() {\r\n return !this.indexBuffer;\r\n }\r\n\r\n private _useVelocity = false;\r\n\r\n /** Indicates if velocity of particles should be used when rendering the object. The vertex buffer set must contain a \"velocity\" buffer for this to work! */\r\n public get useVelocity() {\r\n return this._useVelocity;\r\n }\r\n\r\n public set useVelocity(use: boolean) {\r\n if (this._useVelocity === use || !this._hasVelocity()) {\r\n return;\r\n }\r\n\r\n this._useVelocity = use;\r\n this._effectsAreDirty = true;\r\n }\r\n\r\n private _hasVelocity() {\r\n return !!this.vertexBuffers?.velocity;\r\n }\r\n\r\n /**\r\n * Gets the vertex buffers\r\n */\r\n public abstract get vertexBuffers(): { [key: string]: VertexBuffer };\r\n\r\n /**\r\n * Gets the index buffer (or null if the object is using instancing)\r\n */\r\n public get indexBuffer(): Nullable<DataBuffer> {\r\n return null;\r\n }\r\n\r\n /**\r\n * @returns the name of the class\r\n */\r\n public getClassName(): string {\r\n return \"FluidRenderingObject\";\r\n }\r\n\r\n /**\r\n * Instantiates a fluid rendering object\r\n * @param scene The scene the object is part of\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n this._effectsAreDirty = true;\r\n this._depthEffectWrapper = null;\r\n this._thicknessEffectWrapper = null;\r\n }\r\n\r\n protected _createEffects(): void {\r\n const uniformNames = [\"view\", \"projection\", \"particleRadius\", \"size\"];\r\n const attributeNames = [\"position\", \"offset\"];\r\n const defines: string[] = [];\r\n\r\n this._effectsAreDirty = false;\r\n\r\n if (this.useVelocity) {\r\n attributeNames.push(\"velocity\");\r\n defines.push(\"#define FLUIDRENDERING_VELOCITY\");\r\n }\r\n\r\n if (this._scene.useRightHandedSystem) {\r\n defines.push(\"#define FLUIDRENDERING_RHS\");\r\n }\r\n\r\n this._depthEffectWrapper = new EffectWrapper({\r\n engine: this._engine,\r\n useShaderStore: true,\r\n vertexShader: \"fluidRenderingParticleDepth\",\r\n fragmentShader: \"fluidRenderingParticleDepth\",\r\n attributeNames,\r\n uniformNames,\r\n samplerNames: [],\r\n defines,\r\n });\r\n\r\n uniformNames.push(\"particleAlpha\");\r\n\r\n this._thicknessEffectWrapper = new EffectWrapper({\r\n engine: this._engine,\r\n useShaderStore: true,\r\n vertexShader: \"fluidRenderingParticleThickness\",\r\n fragmentShader: \"fluidRenderingParticleThickness\",\r\n attributeNames: [\"position\", \"offset\"],\r\n uniformNames,\r\n samplerNames: [],\r\n });\r\n }\r\n\r\n /**\r\n * Indicates if the object is ready to be rendered\r\n * @returns True if everything is ready for the object to be rendered, otherwise false\r\n */\r\n public isReady(): boolean {\r\n if (this._effectsAreDirty) {\r\n this._createEffects();\r\n }\r\n\r\n if (!this._depthEffectWrapper || !this._thicknessEffectWrapper) {\r\n return false;\r\n }\r\n\r\n const depthEffect = this._depthEffectWrapper._drawWrapper.effect!;\r\n const thicknessEffect = this._thicknessEffectWrapper._drawWrapper.effect!;\r\n\r\n return depthEffect.isReady() && thicknessEffect.isReady();\r\n }\r\n\r\n /**\r\n * Gets the number of particles (vertices) of this object\r\n * @returns The number of particles\r\n */\r\n public abstract get numParticles(): number;\r\n\r\n /**\r\n * Render the depth texture for this object\r\n */\r\n public renderDepthTexture(): void {\r\n const numParticles = this.numParticles;\r\n\r\n if (!this._depthEffectWrapper || numParticles === 0) {\r\n return;\r\n }\r\n\r\n const depthDrawWrapper = this._depthEffectWrapper._drawWrapper;\r\n const depthEffect = depthDrawWrapper.effect!;\r\n\r\n this._engine.enableEffect(depthDrawWrapper);\r\n this._engine.bindBuffers(this.vertexBuffers, this.indexBuffer, depthEffect);\r\n\r\n depthEffect.setMatrix(\"view\", this._scene.getViewMatrix());\r\n depthEffect.setMatrix(\"projection\", this._scene.getProjectionMatrix());\r\n depthEffect.setFloat2(\"size\", this._particleSize, this._particleSize);\r\n depthEffect.setFloat(\"particleRadius\", this._particleSize / 2);\r\n\r\n if (this.useInstancing) {\r\n this._engine.drawArraysType(Constants.MATERIAL_TriangleStripDrawMode, 0, 4, numParticles);\r\n } else {\r\n this._engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, numParticles);\r\n }\r\n }\r\n\r\n /**\r\n * Render the thickness texture for this object\r\n */\r\n public renderThicknessTexture(): void {\r\n const numParticles = this.numParticles;\r\n\r\n if (!this._thicknessEffectWrapper || numParticles === 0) {\r\n return;\r\n }\r\n\r\n const thicknessDrawWrapper = this._thicknessEffectWrapper._drawWrapper;\r\n const thicknessEffect = thicknessDrawWrapper.effect!;\r\n\r\n this._engine.setAlphaMode(Constants.ALPHA_ONEONE);\r\n this._engine.setDepthWrite(false);\r\n\r\n this._engine.enableEffect(thicknessDrawWrapper);\r\n this._engine.bindBuffers(this.vertexBuffers, this.indexBuffer, thicknessEffect);\r\n\r\n thicknessEffect.setMatrix(\"view\", this._scene.getViewMatrix());\r\n thicknessEffect.setMatrix(\"projection\", this._scene.getProjectionMatrix());\r\n thicknessEffect.setFloat(\"particleAlpha\", this.particleThicknessAlpha);\r\n thicknessEffect.setFloat2(\"size\", this._particleSize, this._particleSize);\r\n\r\n if (this.useInstancing) {\r\n this._engine.drawArraysType(Constants.MATERIAL_TriangleStripDrawMode, 0, 4, numParticles);\r\n } else {\r\n this._engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, numParticles);\r\n }\r\n\r\n this._engine.setDepthWrite(true);\r\n this._engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n }\r\n\r\n /**\r\n * Render the diffuse texture for this object\r\n */\r\n public renderDiffuseTexture(): void {\r\n // do nothing by default\r\n }\r\n\r\n /**\r\n * Releases the ressources used by the class\r\n */\r\n public dispose(): void {\r\n this._depthEffectWrapper?.dispose();\r\n this._thicknessEffectWrapper?.dispose();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"fluidRenderingObject.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/fluidRenderer/fluidRenderingObject.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,mCAA+B;AAEnD,OAAO,EAAE,aAAa,EAAE,0CAAsC;AAC9D,OAAO,EAAE,UAAU,EAAE,iCAA6B;AAIlD;;;GAGG;AACH,MAAM,OAAgB,oBAAoB;IAetC,4CAA4C;IAC5C,IAAW,YAAY;QACnB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,IAAW,YAAY,C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,SAAS,CAAC,8BAA8B,EAAE,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;SAC7F;aAAM;YACH,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,yBAAyB,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;SACvF;QAED,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACI,oBAAoB;QACvB,wBAAwB;IAC5B,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,uBAAuB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;CACJ","sourcesContent":["import type { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport { EffectWrapper } from \"core/Materials/effectRenderer\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/**\r\n * Defines the base object used for fluid rendering.\r\n * It is based on a list of vertices (particles)\r\n */\r\nexport abstract class FluidRenderingObject {\r\n protected _scene: Scene;\r\n protected _engine: AbstractEngine;\r\n protected _effectsAreDirty: boolean;\r\n protected _depthEffectWrapper: Nullable<EffectWrapper>;\r\n protected _thicknessEffectWrapper: Nullable<EffectWrapper>;\r\n\r\n /** Defines the priority of the object. Objects will be rendered in ascending order of priority */\r\n public priority = 0;\r\n\r\n protected _particleSize = 0.1;\r\n\r\n /** Observable triggered when the size of the particle is changed */\r\n public onParticleSizeChanged = new Observable<FluidRenderingObject>();\r\n\r\n /** Gets or sets the size of the particle */\r\n public get particleSize() {\r\n return this._particleSize;\r\n }\r\n\r\n public set particleSize(size: number) {\r\n if (size === this._particleSize) {\r\n return;\r\n }\r\n\r\n this._particleSize = size;\r\n this.onParticleSizeChanged.notifyObservers(this);\r\n }\r\n\r\n /** Defines the alpha value of a particle */\r\n public particleThicknessAlpha = 0.05;\r\n\r\n /** Indicates if the object uses instancing or not */\r\n public get useInstancing() {\r\n return !this.indexBuffer;\r\n }\r\n\r\n private _useVelocity = false;\r\n\r\n /** Indicates if velocity of particles should be used when rendering the object. The vertex buffer set must contain a \"velocity\" buffer for this to work! */\r\n public get useVelocity() {\r\n return this._useVelocity;\r\n }\r\n\r\n public set useVelocity(use: boolean) {\r\n if (this._useVelocity === use || !this._hasVelocity()) {\r\n return;\r\n }\r\n\r\n this._useVelocity = use;\r\n this._effectsAreDirty = true;\r\n }\r\n\r\n private _hasVelocity() {\r\n return !!this.vertexBuffers?.velocity;\r\n }\r\n\r\n /**\r\n * Gets the vertex buffers\r\n */\r\n public abstract get vertexBuffers(): { [key: string]: VertexBuffer };\r\n\r\n /**\r\n * Gets the index buffer (or null if the object is using instancing)\r\n */\r\n public get indexBuffer(): Nullable<DataBuffer> {\r\n return null;\r\n }\r\n\r\n /**\r\n * @returns the name of the class\r\n */\r\n public getClassName(): string {\r\n return \"FluidRenderingObject\";\r\n }\r\n\r\n /**\r\n * Instantiates a fluid rendering object\r\n * @param scene The scene the object is part of\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n this._effectsAreDirty = true;\r\n this._depthEffectWrapper = null;\r\n this._thicknessEffectWrapper = null;\r\n }\r\n\r\n protected _createEffects(): void {\r\n const uniformNames = [\"view\", \"projection\", \"particleRadius\", \"size\"];\r\n const attributeNames = [\"position\", \"offset\"];\r\n const defines: string[] = [];\r\n\r\n this._effectsAreDirty = false;\r\n\r\n if (this.useVelocity) {\r\n attributeNames.push(\"velocity\");\r\n defines.push(\"#define FLUIDRENDERING_VELOCITY\");\r\n }\r\n\r\n if (this._scene.useRightHandedSystem) {\r\n defines.push(\"#define FLUIDRENDERING_RHS\");\r\n }\r\n\r\n this._depthEffectWrapper = new EffectWrapper({\r\n engine: this._engine,\r\n useShaderStore: true,\r\n vertexShader: \"fluidRenderingParticleDepth\",\r\n fragmentShader: \"fluidRenderingParticleDepth\",\r\n attributeNames,\r\n uniformNames,\r\n samplerNames: [],\r\n defines,\r\n });\r\n\r\n uniformNames.push(\"particleAlpha\");\r\n\r\n this._thicknessEffectWrapper = new EffectWrapper({\r\n engine: this._engine,\r\n useShaderStore: true,\r\n vertexShader: \"fluidRenderingParticleThickness\",\r\n fragmentShader: \"fluidRenderingParticleThickness\",\r\n attributeNames: [\"position\", \"offset\"],\r\n uniformNames,\r\n samplerNames: [],\r\n });\r\n }\r\n\r\n /**\r\n * Indicates if the object is ready to be rendered\r\n * @returns True if everything is ready for the object to be rendered, otherwise false\r\n */\r\n public isReady(): boolean {\r\n if (this._effectsAreDirty) {\r\n this._createEffects();\r\n }\r\n\r\n if (!this._depthEffectWrapper || !this._thicknessEffectWrapper) {\r\n return false;\r\n }\r\n\r\n const depthEffect = this._depthEffectWrapper._drawWrapper.effect!;\r\n const thicknessEffect = this._thicknessEffectWrapper._drawWrapper.effect!;\r\n\r\n return depthEffect.isReady() && thicknessEffect.isReady();\r\n }\r\n\r\n /**\r\n * Gets the number of particles (vertices) of this object\r\n * @returns The number of particles\r\n */\r\n public abstract get numParticles(): number;\r\n\r\n /**\r\n * Render the depth texture for this object\r\n */\r\n public renderDepthTexture(): void {\r\n const numParticles = this.numParticles;\r\n\r\n if (!this._depthEffectWrapper || numParticles === 0) {\r\n return;\r\n }\r\n\r\n const depthDrawWrapper = this._depthEffectWrapper._drawWrapper;\r\n const depthEffect = depthDrawWrapper.effect!;\r\n\r\n this._engine.enableEffect(depthDrawWrapper);\r\n this._engine.bindBuffers(this.vertexBuffers, this.indexBuffer, depthEffect);\r\n\r\n depthEffect.setMatrix(\"view\", this._scene.getViewMatrix());\r\n depthEffect.setMatrix(\"projection\", this._scene.getProjectionMatrix());\r\n depthEffect.setFloat2(\"size\", this._particleSize, this._particleSize);\r\n depthEffect.setFloat(\"particleRadius\", this._particleSize / 2);\r\n\r\n if (this.useInstancing) {\r\n this._engine.drawArraysType(Constants.MATERIAL_TriangleStripDrawMode, 0, 4, numParticles);\r\n } else {\r\n this._engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, numParticles);\r\n }\r\n }\r\n\r\n /**\r\n * Render the thickness texture for this object\r\n */\r\n public renderThicknessTexture(): void {\r\n const numParticles = this.numParticles;\r\n\r\n if (!this._thicknessEffectWrapper || numParticles === 0) {\r\n return;\r\n }\r\n\r\n const thicknessDrawWrapper = this._thicknessEffectWrapper._drawWrapper;\r\n const thicknessEffect = thicknessDrawWrapper.effect!;\r\n\r\n this._engine.setAlphaMode(Constants.ALPHA_ONEONE);\r\n this._engine.setDepthWrite(false);\r\n\r\n this._engine.enableEffect(thicknessDrawWrapper);\r\n this._engine.bindBuffers(this.vertexBuffers, this.indexBuffer, thicknessEffect);\r\n\r\n thicknessEffect.setMatrix(\"view\", this._scene.getViewMatrix());\r\n thicknessEffect.setMatrix(\"projection\", this._scene.getProjectionMatrix());\r\n thicknessEffect.setFloat(\"particleAlpha\", this.particleThicknessAlpha);\r\n thicknessEffect.setFloat2(\"size\", this._particleSize, this._particleSize);\r\n\r\n if (this.useInstancing) {\r\n this._engine.drawArraysType(Constants.MATERIAL_TriangleStripDrawMode, 0, 4, numParticles);\r\n } else {\r\n this._engine.drawElementsType(Constants.MATERIAL_TriangleFillMode, 0, numParticles);\r\n }\r\n\r\n this._engine.setDepthWrite(true);\r\n this._engine.setAlphaMode(Constants.ALPHA_DISABLE);\r\n }\r\n\r\n /**\r\n * Render the diffuse texture for this object\r\n */\r\n public renderDiffuseTexture(): void {\r\n // do nothing by default\r\n }\r\n\r\n /**\r\n * Releases the ressources used by the class\r\n */\r\n public dispose(): void {\r\n this._depthEffectWrapper?.dispose(false);\r\n this._thicknessEffectWrapper?.dispose(false);\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/core",
3
- "version": "7.11.1",
3
+ "version": "7.11.2",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",