@onerjs/core 8.52.2 → 8.52.4

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.
@@ -23,6 +23,7 @@ export * from "./rawTexture2DArray.js";
23
23
  export * from "./rawTexture3D.js";
24
24
  export * from "./refractionTexture.js";
25
25
  export * from "./renderTargetTexture.pure.js";
26
+ export * from "./reflectionProbeTexture.pure.js";
26
27
  export * from "./textureMerger.js";
27
28
  export * from "./textureSampler.js";
28
29
  export * from "./textureProcessor.js";
@@ -24,6 +24,7 @@ export * from "./rawTexture2DArray.js";
24
24
  export * from "./rawTexture3D.js";
25
25
  export * from "./refractionTexture.js";
26
26
  export * from "./renderTargetTexture.pure.js";
27
+ export * from "./reflectionProbeTexture.pure.js";
27
28
  export * from "./textureMerger.js";
28
29
  export * from "./textureSampler.js";
29
30
  export * from "./textureProcessor.js";
@@ -1 +1 @@
1
- {"version":3,"file":"pure.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,6DAA6D;AAC7D,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC","sourcesContent":["/** Pure barrel — re-exports only side-effect-free modules */\n/* eslint-disable @typescript-eslint/no-restricted-imports */\nexport * from \"./baseTexture.pure\";\nexport * from \"./baseTexture.polynomial.pure\";\nexport * from \"./colorGradingTexture.pure\";\nexport * from \"./cubeTexture.pure\";\nexport * from \"./dynamicTexture.pure\";\nexport * from \"./equiRectangularCubeTexture.pure\";\nexport * from \"./externalTexture\";\nexport * from \"./Filtering/hdrFiltering\";\nexport * from \"./envCubeTexture.pure\";\nexport * from \"./hdrCubeTexture.pure\";\nexport * from \"./exrCubeTexture.pure\";\nexport * from \"./htmlElementTexture.pure\";\nexport * from \"./internalTexture\";\nexport * from \"./Loaders/pure\";\nexport * from \"./mirrorTexture.pure\";\nexport * from \"./multiRenderTarget.pure\";\nexport * from \"./Packer/pure\";\nexport * from \"./Procedurals/pure\";\nexport * from \"./rawCubeTexture\";\nexport * from \"./rawTexture\";\nexport * from \"./rawTexture2DArray\";\nexport * from \"./rawTexture3D\";\nexport * from \"./refractionTexture\";\nexport * from \"./renderTargetTexture.pure\";\nexport * from \"./textureMerger\";\nexport * from \"./textureSampler\";\nexport * from \"./textureProcessor\";\nexport * from \"./texture.pure\";\nexport * from \"./thinTexture\";\nexport * from \"./thinRenderTargetTexture\";\nexport * from \"./videoTexture.pure\";\nexport * from \"./ktx2decoderTypes\";\nexport * from \"./textureCreationOptions\";\n"]}
1
+ {"version":3,"file":"pure.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,6DAA6D;AAC7D,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC","sourcesContent":["/** Pure barrel — re-exports only side-effect-free modules */\n/* eslint-disable @typescript-eslint/no-restricted-imports */\nexport * from \"./baseTexture.pure\";\nexport * from \"./baseTexture.polynomial.pure\";\nexport * from \"./colorGradingTexture.pure\";\nexport * from \"./cubeTexture.pure\";\nexport * from \"./dynamicTexture.pure\";\nexport * from \"./equiRectangularCubeTexture.pure\";\nexport * from \"./externalTexture\";\nexport * from \"./Filtering/hdrFiltering\";\nexport * from \"./envCubeTexture.pure\";\nexport * from \"./hdrCubeTexture.pure\";\nexport * from \"./exrCubeTexture.pure\";\nexport * from \"./htmlElementTexture.pure\";\nexport * from \"./internalTexture\";\nexport * from \"./Loaders/pure\";\nexport * from \"./mirrorTexture.pure\";\nexport * from \"./multiRenderTarget.pure\";\nexport * from \"./Packer/pure\";\nexport * from \"./Procedurals/pure\";\nexport * from \"./rawCubeTexture\";\nexport * from \"./rawTexture\";\nexport * from \"./rawTexture2DArray\";\nexport * from \"./rawTexture3D\";\nexport * from \"./refractionTexture\";\nexport * from \"./renderTargetTexture.pure\";\nexport * from \"./reflectionProbeTexture.pure\";\nexport * from \"./textureMerger\";\nexport * from \"./textureSampler\";\nexport * from \"./textureProcessor\";\nexport * from \"./texture.pure\";\nexport * from \"./thinTexture\";\nexport * from \"./thinRenderTargetTexture\";\nexport * from \"./videoTexture.pure\";\nexport * from \"./ktx2decoderTypes\";\nexport * from \"./textureCreationOptions\";\n"]}
@@ -1,86 +1 @@
1
- import type { Scene } from "../../scene.js";
2
- import type { AbstractMesh } from "../../Meshes/abstractMesh.js";
3
- import type { Nullable } from "../../types.js";
4
- import { Vector3 } from "../../Maths/math.vector.js";
5
- import type { IAssetContainer } from "../../IAssetContainer.js";
6
- import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
7
- /**
8
- * Options for creating a ReflectionProbeTexture
9
- */
10
- export interface IReflectionProbeTextureOptions {
11
- /**
12
- * The texture resolution (for each face)
13
- */
14
- size: number;
15
- /**
16
- * Defines if mip maps should be generated automatically (true by default)
17
- */
18
- generateMipMaps?: boolean;
19
- /**
20
- * Defines if HDR data (float data) should be used to store colors (false by default)
21
- */
22
- useFloat?: boolean;
23
- /**
24
- * Defines if the probe should be generated in linear space or not (false by default)
25
- */
26
- linearSpace?: boolean;
27
- }
28
- /**
29
- * Class used to generate realtime reflection / refraction cube textures.
30
- * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.
31
- * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
32
- */
33
- export declare class ReflectionProbeTexture extends RenderTargetTexture {
34
- private _projectionMatrix;
35
- private _viewMatrix;
36
- private _target;
37
- private _add;
38
- private _sceneUBOs;
39
- private _currentSceneUBO;
40
- private _invertYAxis;
41
- private _options;
42
- private _attachedMesh;
43
- /** Gets or sets probe position (center of the cube map) */
44
- position: Vector3;
45
- /** @internal */
46
- _parentContainer: Nullable<IAssetContainer>;
47
- /**
48
- * Creates a new reflection probe texture
49
- * @param name defines the name of the probe
50
- * @param options defines the options for creating the texture
51
- * @param scene defines the hosting scene
52
- */
53
- constructor(
54
- /** defines the name of the probe */
55
- name: string, options: number | IReflectionProbeTextureOptions, scene: Scene);
56
- /**
57
- * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
58
- * @param mesh defines the mesh to attach to
59
- */
60
- attachToMesh(mesh: Nullable<AbstractMesh>): void;
61
- /**
62
- * Gets the mesh attached to this probe
63
- * @returns the attached mesh or null
64
- */
65
- get attachedMesh(): Nullable<AbstractMesh>;
66
- /**
67
- * Gets the class name of the reflection probe texture
68
- * @returns "ReflectionProbeTexture"
69
- */
70
- getClassName(): string;
71
- /**
72
- * Converts the reflection probe texture information to a readable string for debug purpose
73
- * @param fullDetails Supports for multiple levels of logging within scene loading
74
- * @returns the human readable reflection probe texture info
75
- */
76
- toString(fullDetails?: boolean): string;
77
- /**
78
- * Used for serializing the probe texture
79
- * @returns any
80
- */
81
- serialize(): any;
82
- /**
83
- * Clean all associated resources
84
- */
85
- dispose(): void;
86
- }
1
+ export * from "./reflectionProbeTexture.pure.js";
@@ -1,197 +1,4 @@
1
- import { Vector3 } from "../../Maths/math.vector.js";
2
- import { Matrix } from "../../Maths/math.vector.js";
3
- import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
4
-
5
- import { Texture } from "../../Materials/Textures/texture.js";
6
- /**
7
- * Class used to generate realtime reflection / refraction cube textures.
8
- * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.
9
- * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
10
- */
11
- export class ReflectionProbeTexture extends RenderTargetTexture {
12
- /**
13
- * Creates a new reflection probe texture
14
- * @param name defines the name of the probe
15
- * @param options defines the options for creating the texture
16
- * @param scene defines the hosting scene
17
- */
18
- constructor(
19
- /** defines the name of the probe */
20
- name, options, scene) {
21
- const size = typeof options === "number" ? options : options.size;
22
- const generateMipMaps = typeof options === "number" ? true : (options.generateMipMaps ?? true);
23
- const useFloat = typeof options === "number" ? false : (options.useFloat ?? false);
24
- const linearSpace = typeof options === "number" ? false : (options.linearSpace ?? false);
25
- let textureType = 0;
26
- if (useFloat) {
27
- const caps = scene.getEngine().getCaps();
28
- if (caps.textureHalfFloatRender) {
29
- textureType = 2;
30
- }
31
- else if (caps.textureFloatRender) {
32
- textureType = 1;
33
- }
34
- }
35
- super(name, size, scene, generateMipMaps, true, textureType, true, undefined, undefined, undefined, undefined, undefined, linearSpace);
36
- this._viewMatrix = Matrix.Identity();
37
- this._target = Vector3.Zero();
38
- this._add = Vector3.Zero();
39
- this._invertYAxis = false;
40
- /** Gets or sets probe position (center of the cube map) */
41
- this.position = Vector3.Zero();
42
- /** @internal */
43
- this._parentContainer = null;
44
- this._options = options;
45
- if (scene.getEngine().supportsUniformBuffers) {
46
- this._sceneUBOs = [];
47
- for (let i = 0; i < 6; ++i) {
48
- this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name "${name}") face #${i}`, { forceMono: true }));
49
- }
50
- }
51
- this.gammaSpace = !linearSpace;
52
- this.invertZ = scene.useRightHandedSystem;
53
- const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;
54
- this.onBeforeRenderObservable.add((faceIndex) => {
55
- if (this._sceneUBOs) {
56
- scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);
57
- scene.getSceneUniformBuffer().unbindEffect();
58
- }
59
- switch (faceIndex) {
60
- case 0:
61
- this._add.copyFromFloats(1, 0, 0);
62
- break;
63
- case 1:
64
- this._add.copyFromFloats(-1, 0, 0);
65
- break;
66
- case 2:
67
- this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);
68
- break;
69
- case 3:
70
- this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);
71
- break;
72
- case 4:
73
- this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);
74
- break;
75
- case 5:
76
- this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);
77
- break;
78
- }
79
- if (this._attachedMesh) {
80
- this.position.copyFrom(this._attachedMesh.getAbsolutePosition());
81
- }
82
- this.position.addToRef(this._add, this._target);
83
- const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;
84
- const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;
85
- lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);
86
- if (scene.activeCamera) {
87
- this._projectionMatrix = perspectiveFunction(Math.PI / 2, 1, useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ, useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ, this._getEngine().isNDCHalfZRange);
88
- scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);
89
- if (scene.activeCamera.isRigCamera && !this.activeCamera) {
90
- this.activeCamera = scene.activeCamera.rigParent || null;
91
- }
92
- }
93
- if (this._sceneUBOs) {
94
- scene.finalizeSceneUbo();
95
- }
96
- scene._forcedViewPosition = this.position;
97
- });
98
- let currentApplyByPostProcess;
99
- this.onBeforeBindObservable.add(() => {
100
- const engine = scene.getEngine();
101
- this._currentSceneUBO = scene.getSceneUniformBuffer();
102
- if (engine._enableGPUDebugMarkers) {
103
- engine._debugPushGroup?.(`reflection probe generation for ${name}`);
104
- }
105
- currentApplyByPostProcess = scene.imageProcessingConfiguration.applyByPostProcess;
106
- if (linearSpace) {
107
- scene.imageProcessingConfiguration.applyByPostProcess = true;
108
- }
109
- });
110
- this.onAfterUnbindObservable.add(() => {
111
- const engine = scene.getEngine();
112
- scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;
113
- scene._forcedViewPosition = null;
114
- if (this._sceneUBOs) {
115
- scene.setSceneUniformBuffer(this._currentSceneUBO);
116
- }
117
- scene.updateTransformMatrix(true);
118
- if (engine._enableGPUDebugMarkers) {
119
- engine._debugPopGroup?.();
120
- }
121
- });
122
- }
123
- /**
124
- * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
125
- * @param mesh defines the mesh to attach to
126
- */
127
- attachToMesh(mesh) {
128
- this._attachedMesh = mesh;
129
- }
130
- /**
131
- * Gets the mesh attached to this probe
132
- * @returns the attached mesh or null
133
- */
134
- get attachedMesh() {
135
- return this._attachedMesh;
136
- }
137
- /**
138
- * Gets the class name of the reflection probe texture
139
- * @returns "ReflectionProbeTexture"
140
- */
141
- getClassName() {
142
- return "ReflectionProbeTexture";
143
- }
144
- /**
145
- * Converts the reflection probe texture information to a readable string for debug purpose
146
- * @param fullDetails Supports for multiple levels of logging within scene loading
147
- * @returns the human readable reflection probe texture info
148
- */
149
- toString(fullDetails) {
150
- let ret = "Name: " + this.name;
151
- if (fullDetails) {
152
- ret += ", position: " + this.position.toString();
153
- if (this._attachedMesh) {
154
- ret += ", attached mesh: " + this._attachedMesh.name;
155
- }
156
- }
157
- return ret;
158
- }
159
- /**
160
- * Used for serializing the probe texture
161
- * @returns any
162
- */
163
- serialize() {
164
- const serializationObject = super.serialize();
165
- if (serializationObject) {
166
- serializationObject.isReflectionProbe = true;
167
- if (this._attachedMesh) {
168
- serializationObject.attachedMesh = this._attachedMesh.id;
169
- }
170
- serializationObject.position = this.position.asArray();
171
- serializationObject.options = structuredClone(this._options);
172
- return serializationObject;
173
- }
174
- return null;
175
- }
176
- /**
177
- * Clean all associated resources
178
- */
179
- dispose() {
180
- if (this._sceneUBOs) {
181
- for (const ubo of this._sceneUBOs) {
182
- ubo.dispose();
183
- }
184
- this._sceneUBOs = [];
185
- }
186
- super.dispose();
187
- }
188
- }
189
- Texture._CreateReflectionProbeTexture = function (name, options, scene, position, attachedMesh) {
190
- const texture = new ReflectionProbeTexture(name, options, scene);
191
- texture.position.fromArray(position);
192
- if (attachedMesh) {
193
- texture.attachToMesh(scene.getMeshById(attachedMesh) ?? null);
194
- }
195
- return texture;
196
- };
1
+ import { RegisterReflectionProbeTexture } from "./reflectionProbeTexture.pure.js";
2
+ export * from "./reflectionProbeTexture.pure.js";
3
+ RegisterReflectionProbeTexture();
197
4
  //# sourceMappingURL=reflectionProbeTexture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reflectionProbeTexture.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/reflectionProbeTexture.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAwB3D;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,mBAAmB;IAiB3D;;;;;OAKG;IACH;IACI,oCAAoC;IACpC,IAAY,EACZ,OAAgD,EAChD,KAAY;QAEZ,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QAClE,MAAM,eAAe,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC,CAAC;QAC/F,MAAM,QAAQ,GAAG,OAAO,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port type { Nullable } from \"../../types\";\nimport { Vector3 } from \"../../Maths/math.vector\";\nimport { Matrix } from \"../../Maths/math.vector\";\nimport type { UniformBuffer } from \"../../Materials/uniformBuffer\";\nimport type { IAssetContainer } from \"core/IAssetContainer\";\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture\";\nimport { Constants } from \"../../Engines/constants\";\nimport { Texture } from \"../../Materials/Textures/texture\";\n\n/**\n * Options for creating a ReflectionProbeTexture\n */\nexport interface IReflectionProbeTextureOptions {\n /**\n * The texture resolution (for each face)\n */\n size: number;\n /**\n * Defines if mip maps should be generated automatically (true by default)\n */\n generateMipMaps?: boolean;\n /**\n * Defines if HDR data (float data) should be used to store colors (false by default)\n */\n useFloat?: boolean;\n /**\n * Defines if the probe should be generated in linear space or not (false by default)\n */\n linearSpace?: boolean;\n}\n\n/**\n * Class used to generate realtime reflection / refraction cube textures.\n * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes\n */\nexport class ReflectionProbeTexture extends RenderTargetTexture {\n private _projectionMatrix: Matrix;\n private _viewMatrix = Matrix.Identity();\n private _target = Vector3.Zero();\n private _add = Vector3.Zero();\n private _sceneUBOs: UniformBuffer[];\n private _currentSceneUBO: UniformBuffer;\n private _invertYAxis = false;\n private _options: number | IReflectionProbeTextureOptions;\n private _attachedMesh: Nullable<AbstractMesh>;\n\n /** Gets or sets probe position (center of the cube map) */\n public position = Vector3.Zero();\n\n /** @internal */\n public override _parentContainer: Nullable<IAssetContainer> = null;\n\n /**\n * Creates a new reflection probe texture\n * @param name defines the name of the probe\n * @param options defines the options for creating the texture\n * @param scene defines the hosting scene\n */\n constructor(\n /** defines the name of the probe */\n name: string,\n options: number | IReflectionProbeTextureOptions,\n scene: Scene\n ) {\n const size = typeof options === \"number\" ? options : options.size;\n const generateMipMaps = typeof options === \"number\" ? true : (options.generateMipMaps ?? true);\n const useFloat = typeof options === \"number\" ? false : (options.useFloat ?? false);\n const linearSpace = typeof options === \"number\" ? false : (options.linearSpace ?? false);\n\n let textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE;\n if (useFloat) {\n const caps = scene.getEngine().getCaps();\n if (caps.textureHalfFloatRender) {\n textureType = Constants.TEXTURETYPE_HALF_FLOAT;\n } else if (caps.textureFloatRender) {\n textureType = Constants.TEXTURETYPE_FLOAT;\n }\n }\n\n super(name, size, scene, generateMipMaps, true, textureType, true, undefined, undefined, undefined, undefined, undefined, linearSpace);\n this._options = options;\n\n if (scene.getEngine().supportsUniformBuffers) {\n this._sceneUBOs = [];\n for (let i = 0; i < 6; ++i) {\n this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name \"${name}\") face #${i}`, { forceMono: true }));\n }\n }\n\n this.gammaSpace = !linearSpace;\n this.invertZ = scene.useRightHandedSystem;\n\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\n\n this.onBeforeRenderObservable.add((faceIndex: number) => {\n if (this._sceneUBOs) {\n scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);\n scene.getSceneUniformBuffer().unbindEffect();\n }\n switch (faceIndex) {\n case 0:\n this._add.copyFromFloats(1, 0, 0);\n break;\n case 1:\n this._add.copyFromFloats(-1, 0, 0);\n break;\n case 2:\n this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);\n break;\n case 3:\n this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);\n break;\n case 4:\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);\n break;\n case 5:\n this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);\n break;\n }\n\n if (this._attachedMesh) {\n this.position.copyFrom(this._attachedMesh.getAbsolutePosition());\n }\n\n this.position.addToRef(this._add, this._target);\n\n const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;\n const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;\n\n lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);\n\n if (scene.activeCamera) {\n this._projectionMatrix = perspectiveFunction(\n Math.PI / 2,\n 1,\n useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ,\n useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ,\n this._getEngine()!.isNDCHalfZRange\n );\n scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);\n if (scene.activeCamera.isRigCamera && !this.activeCamera) {\n this.activeCamera = scene.activeCamera.rigParent || null;\n }\n }\n if (this._sceneUBOs) {\n scene.finalizeSceneUbo();\n }\n scene._forcedViewPosition = this.position;\n });\n\n let currentApplyByPostProcess: boolean;\n\n this.onBeforeBindObservable.add(() => {\n const engine = scene.getEngine();\n this._currentSceneUBO = scene.getSceneUniformBuffer();\n if (engine._enableGPUDebugMarkers) {\n engine._debugPushGroup?.(`reflection probe generation for ${name}`);\n }\n currentApplyByPostProcess = scene.imageProcessingConfiguration.applyByPostProcess;\n if (linearSpace) {\n scene.imageProcessingConfiguration.applyByPostProcess = true;\n }\n });\n\n this.onAfterUnbindObservable.add(() => {\n const engine = scene.getEngine();\n scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;\n scene._forcedViewPosition = null;\n if (this._sceneUBOs) {\n scene.setSceneUniformBuffer(this._currentSceneUBO);\n }\n scene.updateTransformMatrix(true);\n if (engine._enableGPUDebugMarkers) {\n engine._debugPopGroup?.();\n }\n });\n }\n\n /**\n * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)\n * @param mesh defines the mesh to attach to\n */\n public attachToMesh(mesh: Nullable<AbstractMesh>): void {\n this._attachedMesh = mesh;\n }\n\n /**\n * Gets the mesh attached to this probe\n * @returns the attached mesh or null\n */\n public get attachedMesh(): Nullable<AbstractMesh> {\n return this._attachedMesh;\n }\n\n /**\n * Gets the class name of the reflection probe texture\n * @returns \"ReflectionProbeTexture\"\n */\n public override getClassName(): string {\n return \"ReflectionProbeTexture\";\n }\n\n /**\n * Converts the reflection probe texture information to a readable string for debug purpose\n * @param fullDetails Supports for multiple levels of logging within scene loading\n * @returns the human readable reflection probe texture info\n */\n public override toString(fullDetails?: boolean): string {\n let ret = \"Name: \" + this.name;\n\n if (fullDetails) {\n ret += \", position: \" + this.position.toString();\n\n if (this._attachedMesh) {\n ret += \", attached mesh: \" + this._attachedMesh.name;\n }\n }\n\n return ret;\n }\n\n /**\n * Used for serializing the probe texture\n * @returns any\n */\n public override serialize(): any {\n const serializationObject = super.serialize();\n if (serializationObject) {\n serializationObject.isReflectionProbe = true;\n if (this._attachedMesh) {\n serializationObject.attachedMesh = this._attachedMesh.id;\n }\n serializationObject.position = this.position.asArray();\n serializationObject.options = structuredClone(this._options);\n return serializationObject;\n }\n return null;\n }\n\n /**\n * Clean all associated resources\n */\n public override dispose() {\n if (this._sceneUBOs) {\n for (const ubo of this._sceneUBOs) {\n ubo.dispose();\n }\n this._sceneUBOs = [];\n }\n\n super.dispose();\n }\n}\n\nTexture._CreateReflectionProbeTexture = function (name, options, scene, position, attachedMesh) {\n const texture = new ReflectionProbeTexture(name, options, scene);\n texture.position.fromArray(position);\n if (attachedMesh) {\n texture.attachToMesh(scene.getMeshById(attachedMesh) ?? null);\n }\n return texture;\n};\n"]}
1
+ {"version":3,"file":"reflectionProbeTexture.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/reflectionProbeTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAE/E,cAAc,+BAA+B,CAAC;AAE9C,8BAA8B,EAAE,CAAC","sourcesContent":["import { RegisterReflectionProbeTexture } from \"./reflectionProbeTexture.pure\";\n\nexport * from \"./reflectionProbeTexture.pure\";\n\nRegisterReflectionProbeTexture();\n"]}
@@ -0,0 +1,91 @@
1
+ import { type Scene } from "../../scene.js";
2
+ import { type AbstractMesh } from "../../Meshes/abstractMesh.js";
3
+ import { type Nullable } from "../../types.js";
4
+ import { Vector3 } from "../../Maths/math.vector.pure.js";
5
+ import { type IAssetContainer } from "../../IAssetContainer.js";
6
+ import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.pure.js";
7
+ /**
8
+ * Options for creating a ReflectionProbeTexture
9
+ */
10
+ export interface IReflectionProbeTextureOptions {
11
+ /**
12
+ * The texture resolution (for each face)
13
+ */
14
+ size: number;
15
+ /**
16
+ * Defines if mip maps should be generated automatically (true by default)
17
+ */
18
+ generateMipMaps?: boolean;
19
+ /**
20
+ * Defines if HDR data (float data) should be used to store colors (false by default)
21
+ */
22
+ useFloat?: boolean;
23
+ /**
24
+ * Defines if the probe should be generated in linear space or not (false by default)
25
+ */
26
+ linearSpace?: boolean;
27
+ }
28
+ /**
29
+ * Class used to generate realtime reflection / refraction cube textures.
30
+ * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.
31
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
32
+ */
33
+ export declare class ReflectionProbeTexture extends RenderTargetTexture {
34
+ private _projectionMatrix;
35
+ private _viewMatrix;
36
+ private _target;
37
+ private _add;
38
+ private _sceneUBOs;
39
+ private _currentSceneUBO;
40
+ private _invertYAxis;
41
+ private _options;
42
+ private _attachedMesh;
43
+ /** Gets or sets probe position (center of the cube map) */
44
+ position: Vector3;
45
+ /** @internal */
46
+ _parentContainer: Nullable<IAssetContainer>;
47
+ /**
48
+ * Creates a new reflection probe texture
49
+ * @param name defines the name of the probe
50
+ * @param options defines the options for creating the texture
51
+ * @param scene defines the hosting scene
52
+ */
53
+ constructor(
54
+ /** defines the name of the probe */
55
+ name: string, options: number | IReflectionProbeTextureOptions, scene: Scene);
56
+ /**
57
+ * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
58
+ * @param mesh defines the mesh to attach to
59
+ */
60
+ attachToMesh(mesh: Nullable<AbstractMesh>): void;
61
+ /**
62
+ * Gets the mesh attached to this probe
63
+ * @returns the attached mesh or null
64
+ */
65
+ get attachedMesh(): Nullable<AbstractMesh>;
66
+ /**
67
+ * Gets the class name of the reflection probe texture
68
+ * @returns "ReflectionProbeTexture"
69
+ */
70
+ getClassName(): string;
71
+ /**
72
+ * Converts the reflection probe texture information to a readable string for debug purpose
73
+ * @param fullDetails Supports for multiple levels of logging within scene loading
74
+ * @returns the human readable reflection probe texture info
75
+ */
76
+ toString(fullDetails?: boolean): string;
77
+ /**
78
+ * Used for serializing the probe texture
79
+ * @returns any
80
+ */
81
+ serialize(): any;
82
+ /**
83
+ * Clean all associated resources
84
+ */
85
+ dispose(): void;
86
+ }
87
+ /**
88
+ * Register side effects for renderTargetTexture.
89
+ * Safe to call multiple times; only the first call has an effect.
90
+ */
91
+ export declare function RegisterReflectionProbeTexture(): void;
@@ -0,0 +1,208 @@
1
+ import { Vector3, Matrix } from "../../Maths/math.vector.pure.js";
2
+ import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.pure.js";
3
+
4
+ import { Texture } from "../../Materials/Textures/texture.pure.js";
5
+ /**
6
+ * Class used to generate realtime reflection / refraction cube textures.
7
+ * This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.
8
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
9
+ */
10
+ export class ReflectionProbeTexture extends RenderTargetTexture {
11
+ /**
12
+ * Creates a new reflection probe texture
13
+ * @param name defines the name of the probe
14
+ * @param options defines the options for creating the texture
15
+ * @param scene defines the hosting scene
16
+ */
17
+ constructor(
18
+ /** defines the name of the probe */
19
+ name, options, scene) {
20
+ const size = typeof options === "number" ? options : options.size;
21
+ const generateMipMaps = typeof options === "number" ? true : (options.generateMipMaps ?? true);
22
+ const useFloat = typeof options === "number" ? false : (options.useFloat ?? false);
23
+ const linearSpace = typeof options === "number" ? false : (options.linearSpace ?? false);
24
+ let textureType = 0;
25
+ if (useFloat) {
26
+ const caps = scene.getEngine().getCaps();
27
+ if (caps.textureHalfFloatRender) {
28
+ textureType = 2;
29
+ }
30
+ else if (caps.textureFloatRender) {
31
+ textureType = 1;
32
+ }
33
+ }
34
+ super(name, size, scene, generateMipMaps, true, textureType, true, undefined, undefined, undefined, undefined, undefined, linearSpace);
35
+ this._viewMatrix = Matrix.Identity();
36
+ this._target = Vector3.Zero();
37
+ this._add = Vector3.Zero();
38
+ this._invertYAxis = false;
39
+ /** Gets or sets probe position (center of the cube map) */
40
+ this.position = Vector3.Zero();
41
+ /** @internal */
42
+ this._parentContainer = null;
43
+ this._options = options;
44
+ if (scene.getEngine().supportsUniformBuffers) {
45
+ this._sceneUBOs = [];
46
+ for (let i = 0; i < 6; ++i) {
47
+ this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name "${name}") face #${i}`, { forceMono: true }));
48
+ }
49
+ }
50
+ this.gammaSpace = !linearSpace;
51
+ this.invertZ = scene.useRightHandedSystem;
52
+ const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;
53
+ this.onBeforeRenderObservable.add((faceIndex) => {
54
+ if (this._sceneUBOs) {
55
+ scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);
56
+ scene.getSceneUniformBuffer().unbindEffect();
57
+ }
58
+ switch (faceIndex) {
59
+ case 0:
60
+ this._add.copyFromFloats(1, 0, 0);
61
+ break;
62
+ case 1:
63
+ this._add.copyFromFloats(-1, 0, 0);
64
+ break;
65
+ case 2:
66
+ this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);
67
+ break;
68
+ case 3:
69
+ this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);
70
+ break;
71
+ case 4:
72
+ this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);
73
+ break;
74
+ case 5:
75
+ this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);
76
+ break;
77
+ }
78
+ if (this._attachedMesh) {
79
+ this.position.copyFrom(this._attachedMesh.getAbsolutePosition());
80
+ }
81
+ this.position.addToRef(this._add, this._target);
82
+ const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;
83
+ const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;
84
+ lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);
85
+ if (scene.activeCamera) {
86
+ this._projectionMatrix = perspectiveFunction(Math.PI / 2, 1, useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ, useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ, this._getEngine().isNDCHalfZRange);
87
+ scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);
88
+ if (scene.activeCamera.isRigCamera && !this.activeCamera) {
89
+ this.activeCamera = scene.activeCamera.rigParent || null;
90
+ }
91
+ }
92
+ if (this._sceneUBOs) {
93
+ scene.finalizeSceneUbo();
94
+ }
95
+ scene._forcedViewPosition = this.position;
96
+ });
97
+ let currentApplyByPostProcess;
98
+ this.onBeforeBindObservable.add(() => {
99
+ const engine = scene.getEngine();
100
+ this._currentSceneUBO = scene.getSceneUniformBuffer();
101
+ if (engine._enableGPUDebugMarkers) {
102
+ engine._debugPushGroup?.(`reflection probe generation for ${name}`);
103
+ }
104
+ currentApplyByPostProcess = scene.imageProcessingConfiguration.applyByPostProcess;
105
+ if (linearSpace) {
106
+ scene.imageProcessingConfiguration.applyByPostProcess = true;
107
+ }
108
+ });
109
+ this.onAfterUnbindObservable.add(() => {
110
+ const engine = scene.getEngine();
111
+ scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;
112
+ scene._forcedViewPosition = null;
113
+ if (this._sceneUBOs) {
114
+ scene.setSceneUniformBuffer(this._currentSceneUBO);
115
+ }
116
+ scene.updateTransformMatrix(true);
117
+ if (engine._enableGPUDebugMarkers) {
118
+ engine._debugPopGroup?.();
119
+ }
120
+ });
121
+ }
122
+ /**
123
+ * Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
124
+ * @param mesh defines the mesh to attach to
125
+ */
126
+ attachToMesh(mesh) {
127
+ this._attachedMesh = mesh;
128
+ }
129
+ /**
130
+ * Gets the mesh attached to this probe
131
+ * @returns the attached mesh or null
132
+ */
133
+ get attachedMesh() {
134
+ return this._attachedMesh;
135
+ }
136
+ /**
137
+ * Gets the class name of the reflection probe texture
138
+ * @returns "ReflectionProbeTexture"
139
+ */
140
+ getClassName() {
141
+ return "ReflectionProbeTexture";
142
+ }
143
+ /**
144
+ * Converts the reflection probe texture information to a readable string for debug purpose
145
+ * @param fullDetails Supports for multiple levels of logging within scene loading
146
+ * @returns the human readable reflection probe texture info
147
+ */
148
+ toString(fullDetails) {
149
+ let ret = "Name: " + this.name;
150
+ if (fullDetails) {
151
+ ret += ", position: " + this.position.toString();
152
+ if (this._attachedMesh) {
153
+ ret += ", attached mesh: " + this._attachedMesh.name;
154
+ }
155
+ }
156
+ return ret;
157
+ }
158
+ /**
159
+ * Used for serializing the probe texture
160
+ * @returns any
161
+ */
162
+ serialize() {
163
+ const serializationObject = super.serialize();
164
+ if (serializationObject) {
165
+ serializationObject.isReflectionProbe = true;
166
+ if (this._attachedMesh) {
167
+ serializationObject.attachedMesh = this._attachedMesh.id;
168
+ }
169
+ serializationObject.position = this.position.asArray();
170
+ serializationObject.options = structuredClone(this._options);
171
+ return serializationObject;
172
+ }
173
+ return null;
174
+ }
175
+ /**
176
+ * Clean all associated resources
177
+ */
178
+ dispose() {
179
+ if (this._sceneUBOs) {
180
+ for (const ubo of this._sceneUBOs) {
181
+ ubo.dispose();
182
+ }
183
+ this._sceneUBOs = [];
184
+ }
185
+ super.dispose();
186
+ }
187
+ }
188
+ let _Registered = false;
189
+ /**
190
+ * Register side effects for renderTargetTexture.
191
+ * Safe to call multiple times; only the first call has an effect.
192
+ */
193
+ export function RegisterReflectionProbeTexture() {
194
+ if (_Registered) {
195
+ return;
196
+ }
197
+ _Registered = true;
198
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
199
+ Texture._CreateReflectionProbeTexture = function (name, options, scene, position, attachedMesh) {
200
+ const texture = new ReflectionProbeTexture(name, options, scene);
201
+ texture.position.fromArray(position);
202
+ if (attachedMesh) {
203
+ texture.attachToMesh(scene.getMeshById(attachedMesh) ?? null);
204
+ }
205
+ return texture;
206
+ };
207
+ }
208
+ //# sourceMappingURL=reflectionProbeTexture.pure.js.map