@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
438 lines (437 loc) • 18.9 kB
TypeScript
import type { Scene, IDisposable } from "../scene.js";
import { Observable } from "./observable.js";
/**
* Defines the root class used to create scene optimization to use with SceneOptimizer
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class SceneOptimization {
/**
* [0] Defines the priority of this optimization (0 by default which means first in the list)
*/
priority: number;
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
/**
* Creates the SceneOptimization object
* @param priority defines the priority of this optimization (0 by default which means first in the list)
*/
constructor(
/**
* [0] Defines the priority of this optimization (0 by default which means first in the list)
*/
priority?: number);
}
/**
* Defines an optimization used to reduce the size of render target textures
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class TextureOptimization extends SceneOptimization {
/**
* [0] Defines the priority of this optimization (0 by default which means first in the list)
*/
priority: number;
/**
* [1024] Defines the maximum sized allowed for textures (1024 is the default value). If a texture is bigger, it will be scaled down using a factor defined by the step parameter
*/
maximumSize: number;
/**
* [0.5] Defines the factor (0.5 by default) used to scale down textures bigger than maximum sized allowed.
*/
step: number;
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* Creates the TextureOptimization object
* @param priority defines the priority of this optimization (0 by default which means first in the list)
* @param maximumSize defines the maximum sized allowed for textures (1024 is the default value). If a texture is bigger, it will be scaled down using a factor defined by the step parameter
* @param step defines the factor (0.5 by default) used to scale down textures bigger than maximum sized allowed.
*/
constructor(
/**
* [0] Defines the priority of this optimization (0 by default which means first in the list)
*/
priority?: number,
/**
* [1024] Defines the maximum sized allowed for textures (1024 is the default value). If a texture is bigger, it will be scaled down using a factor defined by the step parameter
*/
maximumSize?: number,
/**
* [0.5] Defines the factor (0.5 by default) used to scale down textures bigger than maximum sized allowed.
*/
step?: number);
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization used to increase or decrease the rendering resolution
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class HardwareScalingOptimization extends SceneOptimization {
/**
* [0] Defines the priority of this optimization (0 by default which means first in the list)
*/
priority: number;
/**
* [2] Defines the maximum scale to use (2 by default)
*/
maximumScale: number;
/**
* [0.25] Defines the step to use between two passes (0.5 by default)
*/
step: number;
private _currentScale;
private _directionOffset;
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* Creates the HardwareScalingOptimization object
* @param priority defines the priority of this optimization (0 by default which means first in the list)
* @param maximumScale defines the maximum scale to use (2 by default)
* @param step defines the step to use between two passes (0.5 by default)
*/
constructor(
/**
* [0] Defines the priority of this optimization (0 by default which means first in the list)
*/
priority?: number,
/**
* [2] Defines the maximum scale to use (2 by default)
*/
maximumScale?: number,
/**
* [0.25] Defines the step to use between two passes (0.5 by default)
*/
step?: number);
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization used to remove shadows
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class ShadowsOptimization extends SceneOptimization {
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization used to turn post-processes off
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class PostProcessesOptimization extends SceneOptimization {
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization used to turn lens flares off
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class LensFlaresOptimization extends SceneOptimization {
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization based on user defined callback.
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class CustomOptimization extends SceneOptimization {
/**
* Callback called to apply the custom optimization.
*/
onApply: (scene: Scene, optimizer: SceneOptimizer) => boolean;
/**
* Callback called to get custom description
*/
onGetDescription: () => string;
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization used to turn particles off
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class ParticlesOptimization extends SceneOptimization {
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization used to turn render targets off
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class RenderTargetsOptimization extends SceneOptimization {
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer): boolean;
}
/**
* Defines an optimization used to merge meshes with compatible materials
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class MergeMeshesOptimization extends SceneOptimization {
private static _UpdateSelectionTree;
/**
* Gets or sets a boolean which defines if optimization octree has to be updated
*/
static get UpdateSelectionTree(): boolean;
/**
* Gets or sets a boolean which defines if optimization octree has to be updated
*/
static set UpdateSelectionTree(value: boolean);
/**
* Gets a string describing the action executed by the current optimization
* @returns description string
*/
getDescription(): string;
private _canBeMerged;
/**
* This function will be called by the SceneOptimizer when its priority is reached in order to apply the change required by the current optimization
* @param scene defines the current scene where to apply this optimization
* @param optimizer defines the current optimizer
* @param updateSelectionTree defines that the selection octree has to be updated (false by default)
* @returns true if everything that can be done was applied
*/
apply(scene: Scene, optimizer: SceneOptimizer, updateSelectionTree?: boolean): boolean;
}
/**
* Defines a list of options used by SceneOptimizer
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class SceneOptimizerOptions {
/**
* [60] Defines the target frame rate to reach (60 by default)
*/
targetFrameRate: number;
/**
* [2000] Defines the interval between two checks (2000ms by default)
*/
trackerDuration: number;
/**
* Gets the list of optimizations to apply
*/
optimizations: SceneOptimization[];
/**
* Creates a new list of options used by SceneOptimizer
* @param targetFrameRate defines the target frame rate to reach (60 by default)
* @param trackerDuration defines the interval between two checks (2000ms by default)
*/
constructor(
/**
* [60] Defines the target frame rate to reach (60 by default)
*/
targetFrameRate?: number,
/**
* [2000] Defines the interval between two checks (2000ms by default)
*/
trackerDuration?: number);
/**
* Add a new optimization
* @param optimization defines the SceneOptimization to add to the list of active optimizations
* @returns the current SceneOptimizerOptions
*/
addOptimization(optimization: SceneOptimization): SceneOptimizerOptions;
/**
* Add a new custom optimization
* @param onApply defines the callback called to apply the custom optimization (true if everything that can be done was applied)
* @param onGetDescription defines the callback called to get the description attached with the optimization.
* @param priority defines the priority of this optimization (0 by default which means first in the list)
* @returns the current SceneOptimizerOptions
*/
addCustomOptimization(onApply: (scene: Scene, optimizer: SceneOptimizer) => boolean, onGetDescription: () => string, priority?: number): SceneOptimizerOptions;
/**
* Creates a list of pre-defined optimizations aimed to reduce the visual impact on the scene
* @param targetFrameRate defines the target frame rate (60 by default)
* @returns a SceneOptimizerOptions object
*/
static LowDegradationAllowed(targetFrameRate?: number): SceneOptimizerOptions;
/**
* Creates a list of pre-defined optimizations aimed to have a moderate impact on the scene visual
* @param targetFrameRate defines the target frame rate (60 by default)
* @returns a SceneOptimizerOptions object
*/
static ModerateDegradationAllowed(targetFrameRate?: number): SceneOptimizerOptions;
/**
* Creates a list of pre-defined optimizations aimed to have a big impact on the scene visual
* @param targetFrameRate defines the target frame rate (60 by default)
* @returns a SceneOptimizerOptions object
*/
static HighDegradationAllowed(targetFrameRate?: number): SceneOptimizerOptions;
}
/**
* Class used to run optimizations in order to reach a target frame rate
* @description More details at https://doc.babylonjs.com/features/featuresDeepDive/scene/sceneOptimizer
*/
export declare class SceneOptimizer implements IDisposable {
private _isRunning;
private _options;
private _scene;
private _currentPriorityLevel;
private _targetFrameRate;
private _trackerDuration;
private _currentFrameRate;
private _sceneDisposeObserver;
private _improvementMode;
/**
* Defines an observable called when the optimizer reaches the target frame rate
*/
onSuccessObservable: Observable<SceneOptimizer>;
/**
* Defines an observable called when the optimizer enables an optimization
*/
onNewOptimizationAppliedObservable: Observable<SceneOptimization>;
/**
* Defines an observable called when the optimizer is not able to reach the target frame rate
*/
onFailureObservable: Observable<SceneOptimizer>;
/**
* Gets or sets a boolean indicating if the optimizer is in improvement mode
*/
get isInImprovementMode(): boolean;
set isInImprovementMode(value: boolean);
/**
* Gets the current priority level (0 at start)
*/
get currentPriorityLevel(): number;
/**
* Gets the current frame rate checked by the SceneOptimizer
*/
get currentFrameRate(): number;
/**
* Gets or sets the current target frame rate (60 by default)
*/
get targetFrameRate(): number;
/**
* Gets or sets the current target frame rate (60 by default)
*/
set targetFrameRate(value: number);
/**
* Gets or sets the current interval between two checks (every 2000ms by default)
*/
get trackerDuration(): number;
/**
* Gets or sets the current interval between two checks (every 2000ms by default)
*/
set trackerDuration(value: number);
/**
* Gets the list of active optimizations
*/
get optimizations(): SceneOptimization[];
/**
* Creates a new SceneOptimizer
* @param scene defines the scene to work on
* @param options defines the options to use with the SceneOptimizer
* @param autoGeneratePriorities defines if priorities must be generated and not read from SceneOptimization property (true by default)
* @param improvementMode defines if the scene optimizer must run the maximum optimization while staying over a target frame instead of trying to reach the target framerate (false by default)
*/
constructor(scene: Scene, options?: SceneOptimizerOptions, autoGeneratePriorities?: boolean, improvementMode?: boolean);
/**
* Stops the current optimizer
*/
stop(): void;
/**
* Reset the optimizer to initial step (current priority level = 0)
*/
reset(): void;
/**
* Start the optimizer. By default it will try to reach a specific framerate
* but if the optimizer is set with improvementMode === true then it will run all optimization while frame rate is above the target frame rate
*/
start(): void;
private _checkCurrentState;
/**
* Release all resources
*/
dispose(): void;
/**
* Helper function to create a SceneOptimizer with one single line of code
* @param scene defines the scene to work on
* @param options defines the options to use with the SceneOptimizer
* @param onSuccess defines a callback to call on success
* @param onFailure defines a callback to call on failure
* @returns the new SceneOptimizer object
*/
static OptimizeAsync(scene: Scene, options?: SceneOptimizerOptions, onSuccess?: () => void, onFailure?: () => void): SceneOptimizer;
}