@babylonjs/core 5.43.0 → 5.43.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.
- package/Audio/sound.d.ts +2 -1
- package/Audio/sound.js +27 -26
- package/Audio/sound.js.map +1 -1
- package/Debug/physicsViewer.d.ts +59 -4
- package/Debug/physicsViewer.js +115 -7
- package/Debug/physicsViewer.js.map +1 -1
- package/Engines/ICanvas.d.ts +1 -1
- package/Engines/ICanvas.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTarget.js +10 -9
- package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Materials/effect.js +1 -1
- package/Materials/effect.js.map +1 -1
- package/Meshes/linesMesh.d.ts +2 -1
- package/Meshes/linesMesh.js +1 -2
- package/Meshes/linesMesh.js.map +1 -1
- package/Misc/observable.js +7 -4
- package/Misc/observable.js.map +1 -1
- package/Physics/joinedPhysicsEngineComponent.d.ts +84 -0
- package/Physics/joinedPhysicsEngineComponent.js +144 -0
- package/Physics/joinedPhysicsEngineComponent.js.map +1 -0
- package/Physics/physicsEngineComponent.d.ts +2 -84
- package/Physics/physicsEngineComponent.js +3 -143
- package/Physics/physicsEngineComponent.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +4 -2
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +126 -28
- package/Physics/v2/physicsBody.js +127 -31
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsConstraint.d.ts +26 -7
- package/Physics/v2/physicsConstraint.js +23 -7
- package/Physics/v2/physicsConstraint.js.map +1 -1
- package/Physics/v2/physicsEngine.js +0 -7
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/Physics/v2/physicsEngineComponent.d.ts +4 -3
- package/Physics/v2/physicsEngineComponent.js +6 -5
- package/Physics/v2/physicsEngineComponent.js.map +1 -1
- package/Physics/v2/physicsMaterial.d.ts +38 -11
- package/Physics/v2/physicsMaterial.js +35 -11
- package/Physics/v2/physicsMaterial.js.map +1 -1
- package/Physics/v2/physicsShape.d.ts +24 -15
- package/Physics/v2/physicsShape.js +17 -11
- package/Physics/v2/physicsShape.js.map +1 -1
- package/Shaders/fluidRenderingBilateralBlur.fragment.js +1 -1
- package/Shaders/fluidRenderingBilateralBlur.fragment.js.map +1 -1
- package/Shaders/fluidRenderingRender.fragment.js +2 -2
- package/Shaders/fluidRenderingRender.fragment.js.map +1 -1
- package/Shaders/fluidRenderingStandardBlur.fragment.js +1 -1
- package/Shaders/fluidRenderingStandardBlur.fragment.js.map +1 -1
- package/assetContainer.d.ts +4 -0
- package/assetContainer.js +17 -0
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
package/Misc/observable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../../lts/core/generated/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,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;CAgCJ;AAED;;GAEG;AACH,MAAM,OAAO,QAAQ;IAQjB;;;;;OA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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 * 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/**\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\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 */\r\n constructor(onObserverAdded?: (observer: Observer<T>) => void) {\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(\r\n callback: (eventData: T, eventState: EventState) => void,\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 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: (eventData: T, eventState: EventState) => void): 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 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 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>>): 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 this._numObserversMarkedAsDeleted--;\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);\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);\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 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 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 this._observers = new Array<Observer<T>>();\r\n this._onObserverAdded = null;\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":["../../../../lts/core/generated/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,CAAC;QACjB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,CAAC;CAgCJ;AAED;;GAEG;AACH,MAAM,OAAO,QAAQ;IAQjB;;;;;OAKG;IACH;IACI;;OAEG;IACI,QAAwD;IAC/D;;OAEG;IACI,IAAY;IACnB;;OAEG;IACI,QAAa,IAAI;QARjB,aAAQ,GAAR,QAAQ,CAAgD;QAIxD,SAAI,GAAJ,IAAI,CAAQ;QAIZ,UAAK,GAAL,KAAK,CAAY;QAzB5B,gBAAgB;QACT,wBAAmB,GAAG,KAAK,CA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E;YAC9B,OAAO;SACV;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;QAC/B,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,KAAK,CAAC,iBAAiB,GAAG,KAAK,CAAC;QAEhC,IAAI,QAAQ,CAAC,oBAAoB,EAAE;YAC/B,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;SACnC;QAED,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,YAAY;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACI,KAAK;QACR,IAAI,CAAC,UAAU,GAAG,IAAI,KAAK,EAAe,CAAC;QAC3C,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,4BAA4B,GAAG,CAAC,CAAC;IAC1C,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 * 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/**\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\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 */\r\n constructor(onObserverAdded?: (observer: Observer<T>) => void) {\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(\r\n callback: (eventData: T, eventState: EventState) => void,\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 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: (eventData: T, eventState: EventState) => void): 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 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 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 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 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 this._observers = new Array<Observer<T>>();\r\n this._onObserverAdded = null;\r\n this._numObserversMarkedAsDeleted = 0;\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"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Nullable } from "../types";
|
|
2
|
+
import { Observable } from "../Misc/observable";
|
|
3
|
+
import type { Vector3 } from "../Maths/math.vector";
|
|
4
|
+
import type { ISceneComponent } from "../sceneComponent";
|
|
5
|
+
import { Scene } from "../scene";
|
|
6
|
+
import type { IPhysicsEngine } from "./IPhysicsEngine";
|
|
7
|
+
import type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from "./v1/IPhysicsEnginePlugin";
|
|
8
|
+
import type { IPhysicsEnginePluginV2 } from "./v2/IPhysicsEnginePlugin";
|
|
9
|
+
declare module "../scene" {
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
interface Scene {
|
|
14
|
+
/** @internal (Backing field) */
|
|
15
|
+
_physicsEngine: Nullable<IPhysicsEngine>;
|
|
16
|
+
/** @internal */
|
|
17
|
+
_physicsTimeAccumulator: number;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current physics engine
|
|
20
|
+
* @returns a IPhysicsEngine or null if none attached
|
|
21
|
+
*/
|
|
22
|
+
getPhysicsEngine(): Nullable<IPhysicsEngine>;
|
|
23
|
+
/**
|
|
24
|
+
* Enables physics to the current scene
|
|
25
|
+
* @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)
|
|
26
|
+
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
27
|
+
* @returns a boolean indicating if the physics engine was initialized
|
|
28
|
+
*/
|
|
29
|
+
enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Disables and disposes the physics engine associated with the scene
|
|
32
|
+
*/
|
|
33
|
+
disablePhysicsEngine(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Gets a boolean indicating if there is an active physics engine
|
|
36
|
+
* @returns a boolean indicating if there is an active physics engine
|
|
37
|
+
*/
|
|
38
|
+
isPhysicsEnabled(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Deletes a physics compound impostor
|
|
41
|
+
* @param compound defines the compound to delete
|
|
42
|
+
*/
|
|
43
|
+
deleteCompoundImpostor(compound: any): void;
|
|
44
|
+
/**
|
|
45
|
+
* An event triggered when physic simulation is about to be run
|
|
46
|
+
*/
|
|
47
|
+
onBeforePhysicsObservable: Observable<Scene>;
|
|
48
|
+
/**
|
|
49
|
+
* An event triggered when physic simulation has been done
|
|
50
|
+
*/
|
|
51
|
+
onAfterPhysicsObservable: Observable<Scene>;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Defines the physics engine scene component responsible to manage a physics engine
|
|
56
|
+
*/
|
|
57
|
+
export declare class PhysicsEngineSceneComponent implements ISceneComponent {
|
|
58
|
+
/**
|
|
59
|
+
* The component name helpful to identify the component in the list of scene components.
|
|
60
|
+
*/
|
|
61
|
+
readonly name = "PhysicsEngine";
|
|
62
|
+
/**
|
|
63
|
+
* The scene the component belongs to.
|
|
64
|
+
*/
|
|
65
|
+
scene: Scene;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new instance of the component for the given scene
|
|
68
|
+
* @param scene Defines the scene to register the component in
|
|
69
|
+
*/
|
|
70
|
+
constructor(scene: Scene);
|
|
71
|
+
/**
|
|
72
|
+
* Registers the component in a given scene
|
|
73
|
+
*/
|
|
74
|
+
register(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Rebuilds the elements related to this component in case of
|
|
77
|
+
* context lost for instance.
|
|
78
|
+
*/
|
|
79
|
+
rebuild(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Disposes the component and the associated resources
|
|
82
|
+
*/
|
|
83
|
+
dispose(): void;
|
|
84
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Logger } from "../Misc/logger.js";
|
|
2
|
+
import { Observable } from "../Misc/observable.js";
|
|
3
|
+
import { SceneComponentConstants } from "../sceneComponent.js";
|
|
4
|
+
import { Scene } from "../scene.js";
|
|
5
|
+
import { PhysicsEngine as PhysicsEngineV1 } from "./v1/physicsEngine.js";
|
|
6
|
+
import { PhysicsEngine as PhysicsEngineV2 } from "./v2/physicsEngine.js";
|
|
7
|
+
/**
|
|
8
|
+
* Gets the current physics engine
|
|
9
|
+
* @returns a IPhysicsEngine or null if none attached
|
|
10
|
+
*/
|
|
11
|
+
Scene.prototype.getPhysicsEngine = function () {
|
|
12
|
+
return this._physicsEngine;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Enables physics to the current scene
|
|
16
|
+
* @param gravity defines the scene's gravity for the physics engine
|
|
17
|
+
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
18
|
+
* @returns a boolean indicating if the physics engine was initialized
|
|
19
|
+
*/
|
|
20
|
+
Scene.prototype.enablePhysics = function (gravity = null, plugin) {
|
|
21
|
+
if (this._physicsEngine) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
// Register the component to the scene
|
|
25
|
+
let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE);
|
|
26
|
+
if (!component) {
|
|
27
|
+
component = new PhysicsEngineSceneComponent(this);
|
|
28
|
+
this._addComponent(component);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
if (!plugin || (plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 1) {
|
|
32
|
+
this._physicsEngine = new PhysicsEngineV1(gravity, plugin);
|
|
33
|
+
}
|
|
34
|
+
else if ((plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 2) {
|
|
35
|
+
this._physicsEngine = new PhysicsEngineV2(gravity, plugin);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error("Unsupported Physics plugin version.");
|
|
39
|
+
}
|
|
40
|
+
this._physicsTimeAccumulator = 0;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
Logger.Error(e.message);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Disables and disposes the physics engine associated with the scene
|
|
50
|
+
*/
|
|
51
|
+
Scene.prototype.disablePhysicsEngine = function () {
|
|
52
|
+
if (!this._physicsEngine) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this._physicsEngine.dispose();
|
|
56
|
+
this._physicsEngine = null;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Gets a boolean indicating if there is an active physics engine
|
|
60
|
+
* @returns a boolean indicating if there is an active physics engine
|
|
61
|
+
*/
|
|
62
|
+
Scene.prototype.isPhysicsEnabled = function () {
|
|
63
|
+
return this._physicsEngine !== undefined;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Deletes a physics compound impostor
|
|
67
|
+
* @param compound defines the compound to delete
|
|
68
|
+
*/
|
|
69
|
+
Scene.prototype.deleteCompoundImpostor = function (compound) {
|
|
70
|
+
const mesh = compound.parts[0].mesh;
|
|
71
|
+
if (mesh.physicsImpostor) {
|
|
72
|
+
mesh.physicsImpostor.dispose( /*true*/);
|
|
73
|
+
mesh.physicsImpostor = null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
Scene.prototype._advancePhysicsEngineStep = function (step) {
|
|
80
|
+
if (this._physicsEngine) {
|
|
81
|
+
const subTime = this._physicsEngine.getSubTimeStep();
|
|
82
|
+
if (subTime > 0) {
|
|
83
|
+
this._physicsTimeAccumulator += step;
|
|
84
|
+
while (this._physicsTimeAccumulator > subTime) {
|
|
85
|
+
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
86
|
+
this._physicsEngine._step(subTime / 1000);
|
|
87
|
+
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
88
|
+
this._physicsTimeAccumulator -= subTime;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
93
|
+
this._physicsEngine._step(step / 1000);
|
|
94
|
+
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Defines the physics engine scene component responsible to manage a physics engine
|
|
100
|
+
*/
|
|
101
|
+
export class PhysicsEngineSceneComponent {
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new instance of the component for the given scene
|
|
104
|
+
* @param scene Defines the scene to register the component in
|
|
105
|
+
*/
|
|
106
|
+
constructor(scene) {
|
|
107
|
+
/**
|
|
108
|
+
* The component name helpful to identify the component in the list of scene components.
|
|
109
|
+
*/
|
|
110
|
+
this.name = SceneComponentConstants.NAME_PHYSICSENGINE;
|
|
111
|
+
this.scene = scene;
|
|
112
|
+
this.scene.onBeforePhysicsObservable = new Observable();
|
|
113
|
+
this.scene.onAfterPhysicsObservable = new Observable();
|
|
114
|
+
// Replace the function used to get the deterministic frame time
|
|
115
|
+
this.scene.getDeterministicFrameTime = () => {
|
|
116
|
+
if (this.scene._physicsEngine) {
|
|
117
|
+
return this.scene._physicsEngine.getTimeStep() * 1000;
|
|
118
|
+
}
|
|
119
|
+
return 1000.0 / 60.0;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Registers the component in a given scene
|
|
124
|
+
*/
|
|
125
|
+
register() { }
|
|
126
|
+
/**
|
|
127
|
+
* Rebuilds the elements related to this component in case of
|
|
128
|
+
* context lost for instance.
|
|
129
|
+
*/
|
|
130
|
+
rebuild() {
|
|
131
|
+
// Nothing to do for this component
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Disposes the component and the associated resources
|
|
135
|
+
*/
|
|
136
|
+
dispose() {
|
|
137
|
+
this.scene.onBeforePhysicsObservable.clear();
|
|
138
|
+
this.scene.onAfterPhysicsObservable.clear();
|
|
139
|
+
if (this.scene._physicsEngine) {
|
|
140
|
+
this.scene.disablePhysicsEngine();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=joinedPhysicsEngineComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"joinedPhysicsEngineComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/joinedPhysicsEngineComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAuDtE;;;GAGG;AACH,KAAK,CAAC,SAAS,CAAC,gBAAgB,GAAG;IAC/B,OAAO,IAAI,CAAC,cAAc,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,UAAU,UAA6B,IAAI,EAAE,MAAwD;IACjI,IAAI,IAAI,CAAC,cAAc,EAAE;QACrB,OAAO,IAAI,CAAC;KACf;IAED,sCAAsC;IACtC,IAAI,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,uBAAuB,C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AAK,CAAC,yBAAyB,GAAG,IAAI,UAAU,EAAS,CAAC;QAC/D,IAAI,CAAC,KAAK,CAAC,wBAAwB,GAAG,IAAI,UAAU,EAAS,CAAC;QAE9D,gEAAgE;QAChE,IAAI,CAAC,KAAK,CAAC,yBAAyB,GAAG,GAAG,EAAE;YACxC,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;gBAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC;aACzD;YAED,OAAO,MAAM,GAAG,IAAI,CAAC;QACzB,CAAC,CAAC;IACN,CAAC;IAED;;OAEG;IACI,QAAQ,KAAU,CAAC;IAE1B;;;OAGG;IACI,OAAO;QACV,mCAAmC;IACvC,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAE5C,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC;SACrC;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { Scene } from \"../scene\";\r\nimport type { IPhysicsEngine } from \"./IPhysicsEngine\";\r\nimport type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from \"./v1/IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2 } from \"./v2/IPhysicsEnginePlugin\";\r\nimport { PhysicsEngine as PhysicsEngineV1 } from \"./v1/physicsEngine\";\r\nimport { PhysicsEngine as PhysicsEngineV2 } from \"./v2/physicsEngine\";\r\n\r\ndeclare module \"../scene\" {\r\n /**\r\n *\r\n */\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _physicsEngine: Nullable<IPhysicsEngine>;\r\n /** @internal */\r\n _physicsTimeAccumulator: number;\r\n\r\n /**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\n getPhysicsEngine(): Nullable<IPhysicsEngine>;\r\n\r\n /**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\n enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;\r\n\r\n /**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\n disablePhysicsEngine(): void;\r\n\r\n /**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\n isPhysicsEnabled(): boolean;\r\n\r\n /**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\n deleteCompoundImpostor(compound: any): void;\r\n\r\n /**\r\n * An event triggered when physic simulation is about to be run\r\n */\r\n onBeforePhysicsObservable: Observable<Scene>;\r\n\r\n /**\r\n * An event triggered when physic simulation has been done\r\n */\r\n onAfterPhysicsObservable: Observable<Scene>;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\nScene.prototype.getPhysicsEngine = function (): Nullable<IPhysicsEngine> {\r\n return this._physicsEngine;\r\n};\r\n\r\n/**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\nScene.prototype.enablePhysics = function (gravity: Nullable<Vector3> = null, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean {\r\n if (this._physicsEngine) {\r\n return true;\r\n }\r\n\r\n // Register the component to the scene\r\n let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE) as PhysicsEngineSceneComponent;\r\n if (!component) {\r\n component = new PhysicsEngineSceneComponent(this);\r\n this._addComponent(component);\r\n }\r\n\r\n try {\r\n if (!plugin || plugin?.getPluginVersion() === 1) {\r\n this._physicsEngine = new PhysicsEngineV1(gravity, plugin as IPhysicsEnginePluginV1);\r\n } else if (plugin?.getPluginVersion() === 2) {\r\n this._physicsEngine = new PhysicsEngineV2(gravity, plugin as IPhysicsEnginePluginV2);\r\n } else {\r\n throw new Error(\"Unsupported Physics plugin version.\");\r\n }\r\n this._physicsTimeAccumulator = 0;\r\n return true;\r\n } catch (e) {\r\n Logger.Error(e.message);\r\n return false;\r\n }\r\n};\r\n\r\n/**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\nScene.prototype.disablePhysicsEngine = function (): void {\r\n if (!this._physicsEngine) {\r\n return;\r\n }\r\n\r\n this._physicsEngine.dispose();\r\n this._physicsEngine = null;\r\n};\r\n\r\n/**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\nScene.prototype.isPhysicsEnabled = function (): boolean {\r\n return this._physicsEngine !== undefined;\r\n};\r\n\r\n/**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\nScene.prototype.deleteCompoundImpostor = function (compound: any): void {\r\n const mesh: AbstractMesh = compound.parts[0].mesh;\r\n\r\n if (mesh.physicsImpostor) {\r\n mesh.physicsImpostor.dispose(/*true*/);\r\n mesh.physicsImpostor = null;\r\n }\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nScene.prototype._advancePhysicsEngineStep = function (step: number) {\r\n if (this._physicsEngine) {\r\n const subTime = this._physicsEngine.getSubTimeStep();\r\n if (subTime > 0) {\r\n this._physicsTimeAccumulator += step;\r\n while (this._physicsTimeAccumulator > subTime) {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(subTime / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n this._physicsTimeAccumulator -= subTime;\r\n }\r\n } else {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(step / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Defines the physics engine scene component responsible to manage a physics engine\r\n */\r\nexport class PhysicsEngineSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_PHYSICSENGINE;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n this.scene.onBeforePhysicsObservable = new Observable<Scene>();\r\n this.scene.onAfterPhysicsObservable = new Observable<Scene>();\r\n\r\n // Replace the function used to get the deterministic frame time\r\n this.scene.getDeterministicFrameTime = () => {\r\n if (this.scene._physicsEngine) {\r\n return this.scene._physicsEngine.getTimeStep() * 1000;\r\n }\r\n\r\n return 1000.0 / 60.0;\r\n };\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {}\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do for this component\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n this.scene.onBeforePhysicsObservable.clear();\r\n this.scene.onAfterPhysicsObservable.clear();\r\n\r\n if (this.scene._physicsEngine) {\r\n this.scene.disablePhysicsEngine();\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,84 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import type { Vector3 } from "../Maths/math.vector";
|
|
4
|
-
import type { ISceneComponent } from "../sceneComponent";
|
|
5
|
-
import { Scene } from "../scene";
|
|
6
|
-
import type { IPhysicsEngine } from "./IPhysicsEngine";
|
|
7
|
-
import type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from "./v1/IPhysicsEnginePlugin";
|
|
8
|
-
import type { IPhysicsEnginePluginV2 } from "./v2/IPhysicsEnginePlugin";
|
|
9
|
-
declare module "../scene" {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
interface Scene {
|
|
14
|
-
/** @internal (Backing field) */
|
|
15
|
-
_physicsEngine: Nullable<IPhysicsEngine>;
|
|
16
|
-
/** @internal */
|
|
17
|
-
_physicsTimeAccumulator: number;
|
|
18
|
-
/**
|
|
19
|
-
* Gets the current physics engine
|
|
20
|
-
* @returns a IPhysicsEngine or null if none attached
|
|
21
|
-
*/
|
|
22
|
-
getPhysicsEngine(): Nullable<IPhysicsEngine>;
|
|
23
|
-
/**
|
|
24
|
-
* Enables physics to the current scene
|
|
25
|
-
* @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)
|
|
26
|
-
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
27
|
-
* @returns a boolean indicating if the physics engine was initialized
|
|
28
|
-
*/
|
|
29
|
-
enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Disables and disposes the physics engine associated with the scene
|
|
32
|
-
*/
|
|
33
|
-
disablePhysicsEngine(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Gets a boolean indicating if there is an active physics engine
|
|
36
|
-
* @returns a boolean indicating if there is an active physics engine
|
|
37
|
-
*/
|
|
38
|
-
isPhysicsEnabled(): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Deletes a physics compound impostor
|
|
41
|
-
* @param compound defines the compound to delete
|
|
42
|
-
*/
|
|
43
|
-
deleteCompoundImpostor(compound: any): void;
|
|
44
|
-
/**
|
|
45
|
-
* An event triggered when physic simulation is about to be run
|
|
46
|
-
*/
|
|
47
|
-
onBeforePhysicsObservable: Observable<Scene>;
|
|
48
|
-
/**
|
|
49
|
-
* An event triggered when physic simulation has been done
|
|
50
|
-
*/
|
|
51
|
-
onAfterPhysicsObservable: Observable<Scene>;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Defines the physics engine scene component responsible to manage a physics engine
|
|
56
|
-
*/
|
|
57
|
-
export declare class PhysicsEngineSceneComponent implements ISceneComponent {
|
|
58
|
-
/**
|
|
59
|
-
* The component name helpful to identify the component in the list of scene components.
|
|
60
|
-
*/
|
|
61
|
-
readonly name = "PhysicsEngine";
|
|
62
|
-
/**
|
|
63
|
-
* The scene the component belongs to.
|
|
64
|
-
*/
|
|
65
|
-
scene: Scene;
|
|
66
|
-
/**
|
|
67
|
-
* Creates a new instance of the component for the given scene
|
|
68
|
-
* @param scene Defines the scene to register the component in
|
|
69
|
-
*/
|
|
70
|
-
constructor(scene: Scene);
|
|
71
|
-
/**
|
|
72
|
-
* Registers the component in a given scene
|
|
73
|
-
*/
|
|
74
|
-
register(): void;
|
|
75
|
-
/**
|
|
76
|
-
* Rebuilds the elements related to this component in case of
|
|
77
|
-
* context lost for instance.
|
|
78
|
-
*/
|
|
79
|
-
rebuild(): void;
|
|
80
|
-
/**
|
|
81
|
-
* Disposes the component and the associated resources
|
|
82
|
-
*/
|
|
83
|
-
dispose(): void;
|
|
84
|
-
}
|
|
1
|
+
import "./joinedPhysicsEngineComponent";
|
|
2
|
+
import "./v1/physicsEngineComponent";
|
|
@@ -1,144 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Scene } from "../scene.js";
|
|
5
|
-
import { PhysicsEngine as PhysicsEngineV1 } from "./v1/physicsEngine.js";
|
|
6
|
-
import { PhysicsEngine as PhysicsEngineV2 } from "./v2/physicsEngine.js";
|
|
7
|
-
/**
|
|
8
|
-
* Gets the current physics engine
|
|
9
|
-
* @returns a IPhysicsEngine or null if none attached
|
|
10
|
-
*/
|
|
11
|
-
Scene.prototype.getPhysicsEngine = function () {
|
|
12
|
-
return this._physicsEngine;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Enables physics to the current scene
|
|
16
|
-
* @param gravity defines the scene's gravity for the physics engine
|
|
17
|
-
* @param plugin defines the physics engine to be used. defaults to CannonJS.
|
|
18
|
-
* @returns a boolean indicating if the physics engine was initialized
|
|
19
|
-
*/
|
|
20
|
-
Scene.prototype.enablePhysics = function (gravity = null, plugin) {
|
|
21
|
-
if (this._physicsEngine) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
// Register the component to the scene
|
|
25
|
-
let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE);
|
|
26
|
-
if (!component) {
|
|
27
|
-
component = new PhysicsEngineSceneComponent(this);
|
|
28
|
-
this._addComponent(component);
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
if (!plugin || (plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 1) {
|
|
32
|
-
this._physicsEngine = new PhysicsEngineV1(gravity, plugin);
|
|
33
|
-
}
|
|
34
|
-
else if ((plugin === null || plugin === void 0 ? void 0 : plugin.getPluginVersion()) === 2) {
|
|
35
|
-
this._physicsEngine = new PhysicsEngineV2(gravity, plugin);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error("Unsupported Physics plugin version.");
|
|
39
|
-
}
|
|
40
|
-
this._physicsTimeAccumulator = 0;
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
Logger.Error(e.message);
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Disables and disposes the physics engine associated with the scene
|
|
50
|
-
*/
|
|
51
|
-
Scene.prototype.disablePhysicsEngine = function () {
|
|
52
|
-
if (!this._physicsEngine) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
this._physicsEngine.dispose();
|
|
56
|
-
this._physicsEngine = null;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Gets a boolean indicating if there is an active physics engine
|
|
60
|
-
* @returns a boolean indicating if there is an active physics engine
|
|
61
|
-
*/
|
|
62
|
-
Scene.prototype.isPhysicsEnabled = function () {
|
|
63
|
-
return this._physicsEngine !== undefined;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Deletes a physics compound impostor
|
|
67
|
-
* @param compound defines the compound to delete
|
|
68
|
-
*/
|
|
69
|
-
Scene.prototype.deleteCompoundImpostor = function (compound) {
|
|
70
|
-
const mesh = compound.parts[0].mesh;
|
|
71
|
-
if (mesh.physicsImpostor) {
|
|
72
|
-
mesh.physicsImpostor.dispose( /*true*/);
|
|
73
|
-
mesh.physicsImpostor = null;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
Scene.prototype._advancePhysicsEngineStep = function (step) {
|
|
80
|
-
if (this._physicsEngine) {
|
|
81
|
-
const subTime = this._physicsEngine.getSubTimeStep();
|
|
82
|
-
if (subTime > 0) {
|
|
83
|
-
this._physicsTimeAccumulator += step;
|
|
84
|
-
while (this._physicsTimeAccumulator > subTime) {
|
|
85
|
-
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
86
|
-
this._physicsEngine._step(subTime / 1000);
|
|
87
|
-
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
88
|
-
this._physicsTimeAccumulator -= subTime;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.onBeforePhysicsObservable.notifyObservers(this);
|
|
93
|
-
this._physicsEngine._step(step / 1000);
|
|
94
|
-
this.onAfterPhysicsObservable.notifyObservers(this);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Defines the physics engine scene component responsible to manage a physics engine
|
|
100
|
-
*/
|
|
101
|
-
export class PhysicsEngineSceneComponent {
|
|
102
|
-
/**
|
|
103
|
-
* Creates a new instance of the component for the given scene
|
|
104
|
-
* @param scene Defines the scene to register the component in
|
|
105
|
-
*/
|
|
106
|
-
constructor(scene) {
|
|
107
|
-
/**
|
|
108
|
-
* The component name helpful to identify the component in the list of scene components.
|
|
109
|
-
*/
|
|
110
|
-
this.name = SceneComponentConstants.NAME_PHYSICSENGINE;
|
|
111
|
-
this.scene = scene;
|
|
112
|
-
this.scene.onBeforePhysicsObservable = new Observable();
|
|
113
|
-
this.scene.onAfterPhysicsObservable = new Observable();
|
|
114
|
-
// Replace the function used to get the deterministic frame time
|
|
115
|
-
this.scene.getDeterministicFrameTime = () => {
|
|
116
|
-
if (this.scene._physicsEngine) {
|
|
117
|
-
return this.scene._physicsEngine.getTimeStep() * 1000;
|
|
118
|
-
}
|
|
119
|
-
return 1000.0 / 60.0;
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Registers the component in a given scene
|
|
124
|
-
*/
|
|
125
|
-
register() { }
|
|
126
|
-
/**
|
|
127
|
-
* Rebuilds the elements related to this component in case of
|
|
128
|
-
* context lost for instance.
|
|
129
|
-
*/
|
|
130
|
-
rebuild() {
|
|
131
|
-
// Nothing to do for this component
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Disposes the component and the associated resources
|
|
135
|
-
*/
|
|
136
|
-
dispose() {
|
|
137
|
-
this.scene.onBeforePhysicsObservable.clear();
|
|
138
|
-
this.scene.onAfterPhysicsObservable.clear();
|
|
139
|
-
if (this.scene._physicsEngine) {
|
|
140
|
-
this.scene.disablePhysicsEngine();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
1
|
+
// back compat
|
|
2
|
+
import "./joinedPhysicsEngineComponent.js";
|
|
3
|
+
import "./v1/physicsEngineComponent.js";
|
|
144
4
|
//# sourceMappingURL=physicsEngineComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/physicsEngineComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAuDtE;;;GAGG;AACH,KAAK,CAAC,SAAS,CAAC,gBAAgB,GAAG;IAC/B,OAAO,IAAI,CAAC,cAAc,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;GAKG;AACH,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,UAAU,UAA6B,IAAI,EAAE,MAAwD;IACjI,IAAI,IAAI,CAAC,cAAc,EAAE;QACrB,OAAO,IAAI,CAAC;KACf;IAED,sCAAsC;IACtC,IAAI,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,kBAAkB,CAAgC,CAAC;IAC9G,IAAI,CAAC,SAAS,EAAE;QACZ,SAAS,GAAG,IAAI,2BAA2B,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;KACjC;IAED,IAAI;QACA,IAAI,CAAC,MAAM,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,EAAE,MAAK,CAAC,EAAE;YA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AC,WAAW,EAAE,GAAG,IAAI,CAAC;aACzD;YAED,OAAO,MAAM,GAAG,IAAI,CAAC;QACzB,CAAC,CAAC;IACN,CAAC;IAED;;OAEG;IACI,QAAQ,KAAU,CAAC;IAE1B;;;OAGG;IACI,OAAO;QACV,mCAAmC;IACvC,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAE5C,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC;SACrC;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { ISceneComponent } from \"../sceneComponent\";\r\nimport { SceneComponentConstants } from \"../sceneComponent\";\r\nimport { Scene } from \"../scene\";\r\nimport type { IPhysicsEngine } from \"./IPhysicsEngine\";\r\nimport type { IPhysicsEnginePlugin as IPhysicsEnginePluginV1 } from \"./v1/IPhysicsEnginePlugin\";\r\nimport type { IPhysicsEnginePluginV2 } from \"./v2/IPhysicsEnginePlugin\";\r\nimport { PhysicsEngine as PhysicsEngineV1 } from \"./v1/physicsEngine\";\r\nimport { PhysicsEngine as PhysicsEngineV2 } from \"./v2/physicsEngine\";\r\n\r\ndeclare module \"../scene\" {\r\n /**\r\n *\r\n */\r\n export interface Scene {\r\n /** @internal (Backing field) */\r\n _physicsEngine: Nullable<IPhysicsEngine>;\r\n /** @internal */\r\n _physicsTimeAccumulator: number;\r\n\r\n /**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\n getPhysicsEngine(): Nullable<IPhysicsEngine>;\r\n\r\n /**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine. defaults to real earth gravity : (0, -9.81, 0)\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\n enablePhysics(gravity?: Nullable<Vector3>, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean;\r\n\r\n /**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\n disablePhysicsEngine(): void;\r\n\r\n /**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\n isPhysicsEnabled(): boolean;\r\n\r\n /**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\n deleteCompoundImpostor(compound: any): void;\r\n\r\n /**\r\n * An event triggered when physic simulation is about to be run\r\n */\r\n onBeforePhysicsObservable: Observable<Scene>;\r\n\r\n /**\r\n * An event triggered when physic simulation has been done\r\n */\r\n onAfterPhysicsObservable: Observable<Scene>;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the current physics engine\r\n * @returns a IPhysicsEngine or null if none attached\r\n */\r\nScene.prototype.getPhysicsEngine = function (): Nullable<IPhysicsEngine> {\r\n return this._physicsEngine;\r\n};\r\n\r\n/**\r\n * Enables physics to the current scene\r\n * @param gravity defines the scene's gravity for the physics engine\r\n * @param plugin defines the physics engine to be used. defaults to CannonJS.\r\n * @returns a boolean indicating if the physics engine was initialized\r\n */\r\nScene.prototype.enablePhysics = function (gravity: Nullable<Vector3> = null, plugin?: IPhysicsEnginePluginV1 | IPhysicsEnginePluginV2): boolean {\r\n if (this._physicsEngine) {\r\n return true;\r\n }\r\n\r\n // Register the component to the scene\r\n let component = this._getComponent(SceneComponentConstants.NAME_PHYSICSENGINE) as PhysicsEngineSceneComponent;\r\n if (!component) {\r\n component = new PhysicsEngineSceneComponent(this);\r\n this._addComponent(component);\r\n }\r\n\r\n try {\r\n if (!plugin || plugin?.getPluginVersion() === 1) {\r\n this._physicsEngine = new PhysicsEngineV1(gravity, plugin as IPhysicsEnginePluginV1);\r\n } else if (plugin?.getPluginVersion() === 2) {\r\n this._physicsEngine = new PhysicsEngineV2(gravity, plugin as IPhysicsEnginePluginV2);\r\n } else {\r\n throw new Error(\"Unsupported Physics plugin version.\");\r\n }\r\n this._physicsTimeAccumulator = 0;\r\n return true;\r\n } catch (e) {\r\n Logger.Error(e.message);\r\n return false;\r\n }\r\n};\r\n\r\n/**\r\n * Disables and disposes the physics engine associated with the scene\r\n */\r\nScene.prototype.disablePhysicsEngine = function (): void {\r\n if (!this._physicsEngine) {\r\n return;\r\n }\r\n\r\n this._physicsEngine.dispose();\r\n this._physicsEngine = null;\r\n};\r\n\r\n/**\r\n * Gets a boolean indicating if there is an active physics engine\r\n * @returns a boolean indicating if there is an active physics engine\r\n */\r\nScene.prototype.isPhysicsEnabled = function (): boolean {\r\n return this._physicsEngine !== undefined;\r\n};\r\n\r\n/**\r\n * Deletes a physics compound impostor\r\n * @param compound defines the compound to delete\r\n */\r\nScene.prototype.deleteCompoundImpostor = function (compound: any): void {\r\n const mesh: AbstractMesh = compound.parts[0].mesh;\r\n\r\n if (mesh.physicsImpostor) {\r\n mesh.physicsImpostor.dispose(/*true*/);\r\n mesh.physicsImpostor = null;\r\n }\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nScene.prototype._advancePhysicsEngineStep = function (step: number) {\r\n if (this._physicsEngine) {\r\n const subTime = this._physicsEngine.getSubTimeStep();\r\n if (subTime > 0) {\r\n this._physicsTimeAccumulator += step;\r\n while (this._physicsTimeAccumulator > subTime) {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(subTime / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n this._physicsTimeAccumulator -= subTime;\r\n }\r\n } else {\r\n this.onBeforePhysicsObservable.notifyObservers(this);\r\n this._physicsEngine._step(step / 1000);\r\n this.onAfterPhysicsObservable.notifyObservers(this);\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Defines the physics engine scene component responsible to manage a physics engine\r\n */\r\nexport class PhysicsEngineSceneComponent implements ISceneComponent {\r\n /**\r\n * The component name helpful to identify the component in the list of scene components.\r\n */\r\n public readonly name = SceneComponentConstants.NAME_PHYSICSENGINE;\r\n\r\n /**\r\n * The scene the component belongs to.\r\n */\r\n public scene: Scene;\r\n\r\n /**\r\n * Creates a new instance of the component for the given scene\r\n * @param scene Defines the scene to register the component in\r\n */\r\n constructor(scene: Scene) {\r\n this.scene = scene;\r\n this.scene.onBeforePhysicsObservable = new Observable<Scene>();\r\n this.scene.onAfterPhysicsObservable = new Observable<Scene>();\r\n\r\n // Replace the function used to get the deterministic frame time\r\n this.scene.getDeterministicFrameTime = () => {\r\n if (this.scene._physicsEngine) {\r\n return this.scene._physicsEngine.getTimeStep() * 1000;\r\n }\r\n\r\n return 1000.0 / 60.0;\r\n };\r\n }\r\n\r\n /**\r\n * Registers the component in a given scene\r\n */\r\n public register(): void {}\r\n\r\n /**\r\n * Rebuilds the elements related to this component in case of\r\n * context lost for instance.\r\n */\r\n public rebuild(): void {\r\n // Nothing to do for this component\r\n }\r\n\r\n /**\r\n * Disposes the component and the associated resources\r\n */\r\n public dispose(): void {\r\n this.scene.onBeforePhysicsObservable.clear();\r\n this.scene.onAfterPhysicsObservable.clear();\r\n\r\n if (this.scene._physicsEngine) {\r\n this.scene.disablePhysicsEngine();\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../lts/core/generated/Physics/physicsEngineComponent.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,OAAO,gCAAgC,CAAC;AACxC,OAAO,6BAA6B,CAAC","sourcesContent":["// back compat\r\n\r\nimport \"./joinedPhysicsEngineComponent\";\r\nimport \"./v1/physicsEngineComponent\";\r\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Vector3, Quaternion } from "../../Maths/math.vector";
|
|
2
|
-
import type { AbstractMesh } from "../../Meshes/abstractMesh";
|
|
3
2
|
import type { PhysicsRaycastResult } from "../physicsRaycastResult";
|
|
4
3
|
import type { PhysicsBody } from "./physicsBody";
|
|
5
4
|
import type { PhysicsShape } from "./physicsShape";
|
|
@@ -58,7 +57,8 @@ export interface PhysicsShapeParameters {
|
|
|
58
57
|
pointB?: Vector3;
|
|
59
58
|
rotation?: Quaternion;
|
|
60
59
|
extents?: Vector3;
|
|
61
|
-
mesh?:
|
|
60
|
+
mesh?: Mesh;
|
|
61
|
+
includeChildMeshes?: boolean;
|
|
62
62
|
}
|
|
63
63
|
/** @internal */
|
|
64
64
|
export interface PhysicsConstraintParameters {
|
|
@@ -106,6 +106,8 @@ export interface IPhysicsEnginePluginV2 {
|
|
|
106
106
|
getPluginVersion(): number;
|
|
107
107
|
initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;
|
|
108
108
|
initBodyInstances(body: PhysicsBody, mesh: Mesh): void;
|
|
109
|
+
sync(body: PhysicsBody): void;
|
|
110
|
+
syncTransform(body: PhysicsBody, transformNode: TransformNode): void;
|
|
109
111
|
setShape(body: PhysicsBody, shape: PhysicsShape): void;
|
|
110
112
|
getShape(body: PhysicsBody): PhysicsShape;
|
|
111
113
|
setFilterGroup(body: PhysicsBody, group: number): void;
|