@onerjs/core 8.45.3 → 8.45.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.
- package/Materials/Textures/index.d.ts +1 -0
- package/Materials/Textures/index.js +1 -0
- package/Materials/Textures/index.js.map +1 -1
- package/Materials/Textures/reflectionProbeTexture.d.ts +98 -0
- package/Materials/Textures/reflectionProbeTexture.js +217 -0
- package/Materials/Textures/reflectionProbeTexture.js.map +1 -0
- package/Materials/Textures/texture.d.ts +5 -0
- package/Materials/Textures/texture.js +10 -0
- package/Materials/Textures/texture.js.map +1 -1
- package/Misc/sceneSerializer.js +3 -1
- package/Misc/sceneSerializer.js.map +1 -1
- package/Physics/v2/characterController.d.ts +38 -0
- package/Physics/v2/characterController.js +131 -1
- package/Physics/v2/characterController.js.map +1 -1
- package/Probes/reflectionProbe.d.ts +4 -0
- package/Probes/reflectionProbe.js +4 -0
- package/Probes/reflectionProbe.js.map +1 -1
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ export * from "./rawTexture2DArray.js";
|
|
|
22
22
|
export * from "./rawTexture3D.js";
|
|
23
23
|
export * from "./refractionTexture.js";
|
|
24
24
|
export * from "./renderTargetTexture.js";
|
|
25
|
+
export * from "./reflectionProbeTexture.js";
|
|
25
26
|
export * from "./textureMerger.js";
|
|
26
27
|
export * from "./textureSampler.js";
|
|
27
28
|
export * from "./texture.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.js";
|
|
27
|
+
export * from "./reflectionProbeTexture.js";
|
|
27
28
|
export * from "./textureMerger.js";
|
|
28
29
|
export * from "./textureSampler.js";
|
|
29
30
|
export * from "./texture.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/index.ts"],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\nexport * from \"./baseTexture\";\r\n// eslint-disable-next-line import/export\r\nexport * from \"./baseTexture.polynomial\";\r\nexport * from \"./colorGradingTexture\";\r\nexport * from \"./cubeTexture\";\r\nexport * from \"./dynamicTexture\";\r\nexport * from \"./equiRectangularCubeTexture\";\r\nexport * from \"./externalTexture\";\r\nexport * from \"./Filtering/hdrFiltering\";\r\nexport * from \"./envCubeTexture\";\r\nexport * from \"./hdrCubeTexture\";\r\nexport * from \"./exrCubeTexture\";\r\nexport * from \"./htmlElementTexture\";\r\nexport * from \"./internalTexture\";\r\nexport * from \"./Loaders/index\";\r\nexport * from \"./mirrorTexture\";\r\nexport * from \"./multiRenderTarget\";\r\nexport * from \"./Packer/index\";\r\nexport * from \"./Procedurals/index\";\r\nexport * from \"./rawCubeTexture\";\r\nexport * from \"./rawTexture\";\r\nexport * from \"./rawTexture2DArray\";\r\nexport * from \"./rawTexture3D\";\r\nexport * from \"./refractionTexture\";\r\nexport * from \"./renderTargetTexture\";\r\nexport * from \"./textureMerger\";\r\nexport * from \"./textureSampler\";\r\nexport * from \"./texture\";\r\nexport * from \"./thinTexture\";\r\nexport * from \"./thinRenderTargetTexture\";\r\nexport * from \"./videoTexture\";\r\nexport * from \"./ktx2decoderTypes\";\r\nexport * from \"./textureCreationOptions\";\r\n\r\n// Shaders for procedural textures\r\nexport * from \"../../ShadersWGSL/procedural.vertex\";\r\nexport * from \"../../Shaders/procedural.vertex\";\r\n\r\n// HDR filtering\r\nexport * from \"../../Shaders/hdrFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.fragment\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.fragment\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,yCAAyC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAEzC,kCAAkC;AAClC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAEhD,gBAAgB;AAChB,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./baseTexture\";\r\n// eslint-disable-next-line import/export\r\nexport * from \"./baseTexture.polynomial\";\r\nexport * from \"./colorGradingTexture\";\r\nexport * from \"./cubeTexture\";\r\nexport * from \"./dynamicTexture\";\r\nexport * from \"./equiRectangularCubeTexture\";\r\nexport * from \"./externalTexture\";\r\nexport * from \"./Filtering/hdrFiltering\";\r\nexport * from \"./envCubeTexture\";\r\nexport * from \"./hdrCubeTexture\";\r\nexport * from \"./exrCubeTexture\";\r\nexport * from \"./htmlElementTexture\";\r\nexport * from \"./internalTexture\";\r\nexport * from \"./Loaders/index\";\r\nexport * from \"./mirrorTexture\";\r\nexport * from \"./multiRenderTarget\";\r\nexport * from \"./Packer/index\";\r\nexport * from \"./Procedurals/index\";\r\nexport * from \"./rawCubeTexture\";\r\nexport * from \"./rawTexture\";\r\nexport * from \"./rawTexture2DArray\";\r\nexport * from \"./rawTexture3D\";\r\nexport * from \"./refractionTexture\";\r\nexport * from \"./renderTargetTexture\";\r\nexport * from \"./reflectionProbeTexture\";\r\nexport * from \"./textureMerger\";\r\nexport * from \"./textureSampler\";\r\nexport * from \"./texture\";\r\nexport * from \"./thinTexture\";\r\nexport * from \"./thinRenderTargetTexture\";\r\nexport * from \"./videoTexture\";\r\nexport * from \"./ktx2decoderTypes\";\r\nexport * from \"./textureCreationOptions\";\r\n\r\n// Shaders for procedural textures\r\nexport * from \"../../ShadersWGSL/procedural.vertex\";\r\nexport * from \"../../Shaders/procedural.vertex\";\r\n\r\n// HDR filtering\r\nexport * from \"../../Shaders/hdrFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.fragment\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.fragment\";\r\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 "./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
|
+
/** defines the name of the probe */
|
|
35
|
+
name: string;
|
|
36
|
+
private _probeScene;
|
|
37
|
+
private _projectionMatrix;
|
|
38
|
+
private _viewMatrix;
|
|
39
|
+
private _target;
|
|
40
|
+
private _add;
|
|
41
|
+
private _sceneUBOs;
|
|
42
|
+
private _currentSceneUBO;
|
|
43
|
+
private _invertYAxis;
|
|
44
|
+
private _options;
|
|
45
|
+
private _attachedMesh;
|
|
46
|
+
/** Gets or sets probe position (center of the cube map) */
|
|
47
|
+
position: Vector3;
|
|
48
|
+
/**
|
|
49
|
+
* Gets or sets an object used to store user defined information for the reflection probe.
|
|
50
|
+
*/
|
|
51
|
+
metadata: any;
|
|
52
|
+
/** @internal */
|
|
53
|
+
_parentContainer: Nullable<IAssetContainer>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new reflection probe texture
|
|
56
|
+
* @param name defines the name of the probe
|
|
57
|
+
* @param options defines the options for creating the texture
|
|
58
|
+
* @param scene defines the hosting scene
|
|
59
|
+
*/
|
|
60
|
+
constructor(
|
|
61
|
+
/** defines the name of the probe */
|
|
62
|
+
name: string, options: number | IReflectionProbeTextureOptions, scene: Scene);
|
|
63
|
+
/**
|
|
64
|
+
* Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
|
|
65
|
+
* @param mesh defines the mesh to attach to
|
|
66
|
+
*/
|
|
67
|
+
attachToMesh(mesh: Nullable<AbstractMesh>): void;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the mesh attached to this probe
|
|
70
|
+
* @returns the attached mesh or null
|
|
71
|
+
*/
|
|
72
|
+
get attachedMesh(): Nullable<AbstractMesh>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the hosting scene
|
|
75
|
+
* @returns a Scene
|
|
76
|
+
*/
|
|
77
|
+
getScene(): Scene;
|
|
78
|
+
/**
|
|
79
|
+
* Gets the class name of the reflection probe texture
|
|
80
|
+
* @returns "ReflectionProbeTexture"
|
|
81
|
+
*/
|
|
82
|
+
getClassName(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Converts the reflection probe texture information to a readable string for debug purpose
|
|
85
|
+
* @param fullDetails Supports for multiple levels of logging within scene loading
|
|
86
|
+
* @returns the human readable reflection probe texture info
|
|
87
|
+
*/
|
|
88
|
+
toString(fullDetails?: boolean): string;
|
|
89
|
+
/**
|
|
90
|
+
* Used for serializing the probe texture
|
|
91
|
+
* @returns any
|
|
92
|
+
*/
|
|
93
|
+
serialize(): any;
|
|
94
|
+
/**
|
|
95
|
+
* Clean all associated resources
|
|
96
|
+
*/
|
|
97
|
+
dispose(): void;
|
|
98
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { __decorate } from "../../tslib.es6.js";
|
|
2
|
+
import { Vector3 } from "../../Maths/math.vector.js";
|
|
3
|
+
import { Matrix } from "../../Maths/math.vector.js";
|
|
4
|
+
import { serializeAsMeshReference, serializeAsVector3 } from "../../Misc/decorators.js";
|
|
5
|
+
import { RenderTargetTexture } from "./renderTargetTexture.js";
|
|
6
|
+
|
|
7
|
+
import { Texture } from "../../Materials/Textures/texture.js";
|
|
8
|
+
/**
|
|
9
|
+
* Class used to generate realtime reflection / refraction cube textures.
|
|
10
|
+
* This is a simplified version of ReflectionProbe that can be used directly as a RenderTargetTexture.
|
|
11
|
+
* @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
|
|
12
|
+
*/
|
|
13
|
+
export class ReflectionProbeTexture extends RenderTargetTexture {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new reflection probe texture
|
|
16
|
+
* @param name defines the name of the probe
|
|
17
|
+
* @param options defines the options for creating the texture
|
|
18
|
+
* @param scene defines the hosting scene
|
|
19
|
+
*/
|
|
20
|
+
constructor(
|
|
21
|
+
/** defines the name of the probe */
|
|
22
|
+
name, options, scene) {
|
|
23
|
+
const size = typeof options === "number" ? options : options.size;
|
|
24
|
+
const generateMipMaps = typeof options === "number" ? true : (options.generateMipMaps ?? true);
|
|
25
|
+
const useFloat = typeof options === "number" ? false : (options.useFloat ?? false);
|
|
26
|
+
const linearSpace = typeof options === "number" ? false : (options.linearSpace ?? false);
|
|
27
|
+
let textureType = 0;
|
|
28
|
+
if (useFloat) {
|
|
29
|
+
const caps = scene.getEngine().getCaps();
|
|
30
|
+
if (caps.textureHalfFloatRender) {
|
|
31
|
+
textureType = 2;
|
|
32
|
+
}
|
|
33
|
+
else if (caps.textureFloatRender) {
|
|
34
|
+
textureType = 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
super(name, size, scene, generateMipMaps, true, textureType, true, undefined, undefined, undefined, undefined, undefined, linearSpace);
|
|
38
|
+
this.name = name;
|
|
39
|
+
this._viewMatrix = Matrix.Identity();
|
|
40
|
+
this._target = Vector3.Zero();
|
|
41
|
+
this._add = Vector3.Zero();
|
|
42
|
+
this._invertYAxis = false;
|
|
43
|
+
/** Gets or sets probe position (center of the cube map) */
|
|
44
|
+
this.position = Vector3.Zero();
|
|
45
|
+
/**
|
|
46
|
+
* Gets or sets an object used to store user defined information for the reflection probe.
|
|
47
|
+
*/
|
|
48
|
+
this.metadata = null;
|
|
49
|
+
/** @internal */
|
|
50
|
+
this._parentContainer = null;
|
|
51
|
+
this._probeScene = scene;
|
|
52
|
+
this._options = options;
|
|
53
|
+
if (scene.getEngine().supportsUniformBuffers) {
|
|
54
|
+
this._sceneUBOs = [];
|
|
55
|
+
for (let i = 0; i < 6; ++i) {
|
|
56
|
+
this._sceneUBOs.push(scene.createSceneUniformBuffer(`Scene for Reflection Probe (name "${name}") face #${i}`, { forceMono: true }));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.gammaSpace = !linearSpace;
|
|
60
|
+
this.invertZ = scene.useRightHandedSystem;
|
|
61
|
+
const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;
|
|
62
|
+
this.onBeforeRenderObservable.add((faceIndex) => {
|
|
63
|
+
if (this._sceneUBOs) {
|
|
64
|
+
scene.setSceneUniformBuffer(this._sceneUBOs[faceIndex]);
|
|
65
|
+
scene.getSceneUniformBuffer().unbindEffect();
|
|
66
|
+
}
|
|
67
|
+
switch (faceIndex) {
|
|
68
|
+
case 0:
|
|
69
|
+
this._add.copyFromFloats(1, 0, 0);
|
|
70
|
+
break;
|
|
71
|
+
case 1:
|
|
72
|
+
this._add.copyFromFloats(-1, 0, 0);
|
|
73
|
+
break;
|
|
74
|
+
case 2:
|
|
75
|
+
this._add.copyFromFloats(0, this._invertYAxis ? 1 : -1, 0);
|
|
76
|
+
break;
|
|
77
|
+
case 3:
|
|
78
|
+
this._add.copyFromFloats(0, this._invertYAxis ? -1 : 1, 0);
|
|
79
|
+
break;
|
|
80
|
+
case 4:
|
|
81
|
+
this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? -1 : 1);
|
|
82
|
+
break;
|
|
83
|
+
case 5:
|
|
84
|
+
this._add.copyFromFloats(0, 0, scene.useRightHandedSystem ? 1 : -1);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (this._attachedMesh) {
|
|
88
|
+
this.position.copyFrom(this._attachedMesh.getAbsolutePosition());
|
|
89
|
+
}
|
|
90
|
+
this.position.addToRef(this._add, this._target);
|
|
91
|
+
const lookAtFunction = scene.useRightHandedSystem ? Matrix.LookAtRHToRef : Matrix.LookAtLHToRef;
|
|
92
|
+
const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;
|
|
93
|
+
lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);
|
|
94
|
+
if (scene.activeCamera) {
|
|
95
|
+
this._projectionMatrix = perspectiveFunction(Math.PI / 2, 1, useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ, useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ, this._probeScene.getEngine().isNDCHalfZRange);
|
|
96
|
+
scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);
|
|
97
|
+
if (scene.activeCamera.isRigCamera && !this.activeCamera) {
|
|
98
|
+
this.activeCamera = scene.activeCamera.rigParent || null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (this._sceneUBOs) {
|
|
102
|
+
scene.finalizeSceneUbo();
|
|
103
|
+
}
|
|
104
|
+
scene._forcedViewPosition = this.position;
|
|
105
|
+
});
|
|
106
|
+
let currentApplyByPostProcess;
|
|
107
|
+
this.onBeforeBindObservable.add(() => {
|
|
108
|
+
const engine = scene.getEngine();
|
|
109
|
+
this._currentSceneUBO = scene.getSceneUniformBuffer();
|
|
110
|
+
if (engine._enableGPUDebugMarkers) {
|
|
111
|
+
engine._debugPushGroup?.(`reflection probe generation for ${name}`);
|
|
112
|
+
}
|
|
113
|
+
currentApplyByPostProcess = this._probeScene.imageProcessingConfiguration.applyByPostProcess;
|
|
114
|
+
if (linearSpace) {
|
|
115
|
+
scene.imageProcessingConfiguration.applyByPostProcess = true;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
this.onAfterUnbindObservable.add(() => {
|
|
119
|
+
const engine = scene.getEngine();
|
|
120
|
+
scene.imageProcessingConfiguration.applyByPostProcess = currentApplyByPostProcess;
|
|
121
|
+
scene._forcedViewPosition = null;
|
|
122
|
+
if (this._sceneUBOs) {
|
|
123
|
+
scene.setSceneUniformBuffer(this._currentSceneUBO);
|
|
124
|
+
}
|
|
125
|
+
scene.updateTransformMatrix(true);
|
|
126
|
+
if (engine._enableGPUDebugMarkers) {
|
|
127
|
+
engine._debugPopGroup?.();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Attach the probe to a specific mesh (Rendering will be done from attached mesh's position)
|
|
133
|
+
* @param mesh defines the mesh to attach to
|
|
134
|
+
*/
|
|
135
|
+
attachToMesh(mesh) {
|
|
136
|
+
this._attachedMesh = mesh;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Gets the mesh attached to this probe
|
|
140
|
+
* @returns the attached mesh or null
|
|
141
|
+
*/
|
|
142
|
+
get attachedMesh() {
|
|
143
|
+
return this._attachedMesh;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Gets the hosting scene
|
|
147
|
+
* @returns a Scene
|
|
148
|
+
*/
|
|
149
|
+
getScene() {
|
|
150
|
+
return this._probeScene;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Gets the class name of the reflection probe texture
|
|
154
|
+
* @returns "ReflectionProbeTexture"
|
|
155
|
+
*/
|
|
156
|
+
getClassName() {
|
|
157
|
+
return "ReflectionProbeTexture";
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Converts the reflection probe texture information to a readable string for debug purpose
|
|
161
|
+
* @param fullDetails Supports for multiple levels of logging within scene loading
|
|
162
|
+
* @returns the human readable reflection probe texture info
|
|
163
|
+
*/
|
|
164
|
+
toString(fullDetails) {
|
|
165
|
+
let ret = "Name: " + this.name;
|
|
166
|
+
if (fullDetails) {
|
|
167
|
+
ret += ", position: " + this.position.toString();
|
|
168
|
+
if (this._attachedMesh) {
|
|
169
|
+
ret += ", attached mesh: " + this._attachedMesh.name;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return ret;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Used for serializing the probe texture
|
|
176
|
+
* @returns any
|
|
177
|
+
*/
|
|
178
|
+
serialize() {
|
|
179
|
+
const serializationObject = super.serialize();
|
|
180
|
+
if (serializationObject) {
|
|
181
|
+
serializationObject.isReflectionProbe = true;
|
|
182
|
+
if (this._attachedMesh) {
|
|
183
|
+
serializationObject.attachedMesh = this._attachedMesh.id;
|
|
184
|
+
}
|
|
185
|
+
serializationObject.position = this.position.asArray();
|
|
186
|
+
serializationObject.options = this._options;
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Clean all associated resources
|
|
192
|
+
*/
|
|
193
|
+
dispose() {
|
|
194
|
+
if (this._sceneUBOs) {
|
|
195
|
+
for (const ubo of this._sceneUBOs) {
|
|
196
|
+
ubo.dispose();
|
|
197
|
+
}
|
|
198
|
+
this._sceneUBOs = [];
|
|
199
|
+
}
|
|
200
|
+
super.dispose();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
__decorate([
|
|
204
|
+
serializeAsMeshReference()
|
|
205
|
+
], ReflectionProbeTexture.prototype, "_attachedMesh", void 0);
|
|
206
|
+
__decorate([
|
|
207
|
+
serializeAsVector3()
|
|
208
|
+
], ReflectionProbeTexture.prototype, "position", void 0);
|
|
209
|
+
Texture._CreateReflectionProbeTexture = function (name, options, scene, position, attachedMesh) {
|
|
210
|
+
const texture = new ReflectionProbeTexture(name, options, scene);
|
|
211
|
+
texture.position.fromArray(position);
|
|
212
|
+
if (attachedMesh) {
|
|
213
|
+
texture.attachToMesh(scene.getMeshById(attachedMesh) ?? null);
|
|
214
|
+
}
|
|
215
|
+
return texture;
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=reflectionProbeTexture.js.map
|
|
@@ -0,0 +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,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAwB3D;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,mBAAmB;IA0B3D;;;;;OAKG;IACH;IACI,oCAAoC;IACpB,IAAY,EAC5B,OAAgD,EAChD,KAAY;QAEZ,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAA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B,GAAG,UAAU,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY;IAC1F,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACrC,IAAI,YAAY,EAAE,CAAC;QACf,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { Scene } from \"../../scene\";\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\nimport 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 { serializeAsMeshReference, serializeAsVector3 } from \"../../Misc/decorators\";\nimport { RenderTargetTexture } from \"./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 _probeScene: Scene;\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\n @serializeAsMeshReference()\n private _attachedMesh: Nullable<AbstractMesh>;\n\n /** Gets or sets probe position (center of the cube map) */\n @serializeAsVector3()\n public position = Vector3.Zero();\n\n /**\n * Gets or sets an object used to store user defined information for the reflection probe.\n */\n public override metadata: any = null;\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 public override 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._probeScene = scene;\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._probeScene.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 = this._probeScene.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 hosting scene\n * @returns a Scene\n */\n public override getScene(): Scene {\n return this._probeScene;\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 = this._options;\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"]}
|
|
@@ -10,6 +10,7 @@ import type { MirrorTexture } from "../../Materials/Textures/mirrorTexture.js";
|
|
|
10
10
|
import type { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture.js";
|
|
11
11
|
import type { Scene } from "../../scene.js";
|
|
12
12
|
import type { VideoTexture, VideoTextureSettings } from "./videoTexture.js";
|
|
13
|
+
import type { ReflectionProbeTexture } from "../../Materials/Textures/reflectionProbeTexture.js";
|
|
13
14
|
/**
|
|
14
15
|
* Defines the available options when creating a texture
|
|
15
16
|
*/
|
|
@@ -79,6 +80,10 @@ export declare class Texture extends BaseTexture {
|
|
|
79
80
|
* @internal
|
|
80
81
|
*/
|
|
81
82
|
static _CreateRenderTargetTexture: (name: string, renderTargetSize: number, scene: Scene, generateMipMaps: boolean, creationFlags?: number) => RenderTargetTexture;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
static _CreateReflectionProbeTexture: (name: string, options: any, scene: Scene, position: number[], attachedMesh?: string) => ReflectionProbeTexture;
|
|
82
87
|
/**
|
|
83
88
|
* @internal
|
|
84
89
|
*/
|
|
@@ -619,6 +619,9 @@ export class Texture extends BaseTexture {
|
|
|
619
619
|
* @returns The parsed texture if successful
|
|
620
620
|
*/
|
|
621
621
|
static Parse(parsedTexture, scene, rootUrl) {
|
|
622
|
+
if (parsedTexture.isReflectionProbe) {
|
|
623
|
+
return Texture._CreateReflectionProbeTexture(parsedTexture.name, parsedTexture.options, scene, parsedTexture.position, parsedTexture.attachedMesh);
|
|
624
|
+
}
|
|
622
625
|
if (parsedTexture.customType) {
|
|
623
626
|
const customTexture = InstantiationTools.Instantiate(parsedTexture.customType);
|
|
624
627
|
// Update Sampling Mode
|
|
@@ -854,6 +857,13 @@ Texture._CreateMirror = (name, renderTargetSize, scene, generateMipMaps) => {
|
|
|
854
857
|
Texture._CreateRenderTargetTexture = (name, renderTargetSize, scene, generateMipMaps, creationFlags) => {
|
|
855
858
|
throw _WarnImport("RenderTargetTexture");
|
|
856
859
|
};
|
|
860
|
+
/**
|
|
861
|
+
* @internal
|
|
862
|
+
*/
|
|
863
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
864
|
+
Texture._CreateReflectionProbeTexture = (name, options, scene, position, attachedMesh) => {
|
|
865
|
+
throw _WarnImport("ReflectionProbeTexture");
|
|
866
|
+
};
|
|
857
867
|
/** nearest is mag = nearest and min = nearest and no mip */
|
|
858
868
|
Texture.NEAREST_SAMPLINGMODE = 1;
|
|
859
869
|
/** nearest is mag = nearest and min = nearest and mip = linear */
|