@onerjs/core 8.45.5 → 8.45.6
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.
|
@@ -31,7 +31,6 @@ export interface IReflectionProbeTextureOptions {
|
|
|
31
31
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/environment/reflectionProbes
|
|
32
32
|
*/
|
|
33
33
|
export declare class ReflectionProbeTexture extends RenderTargetTexture {
|
|
34
|
-
private _probeScene;
|
|
35
34
|
private _projectionMatrix;
|
|
36
35
|
private _viewMatrix;
|
|
37
36
|
private _target;
|
|
@@ -68,11 +67,6 @@ export declare class ReflectionProbeTexture extends RenderTargetTexture {
|
|
|
68
67
|
* @returns the attached mesh or null
|
|
69
68
|
*/
|
|
70
69
|
get attachedMesh(): Nullable<AbstractMesh>;
|
|
71
|
-
/**
|
|
72
|
-
* Gets the hosting scene
|
|
73
|
-
* @returns a Scene
|
|
74
|
-
*/
|
|
75
|
-
getScene(): Scene;
|
|
76
70
|
/**
|
|
77
71
|
* Gets the class name of the reflection probe texture
|
|
78
72
|
* @returns "ReflectionProbeTexture"
|
|
@@ -45,7 +45,6 @@ export class ReflectionProbeTexture extends RenderTargetTexture {
|
|
|
45
45
|
this.metadata = null;
|
|
46
46
|
/** @internal */
|
|
47
47
|
this._parentContainer = null;
|
|
48
|
-
this._probeScene = scene;
|
|
49
48
|
this._options = options;
|
|
50
49
|
if (scene.getEngine().supportsUniformBuffers) {
|
|
51
50
|
this._sceneUBOs = [];
|
|
@@ -89,7 +88,7 @@ export class ReflectionProbeTexture extends RenderTargetTexture {
|
|
|
89
88
|
const perspectiveFunction = scene.useRightHandedSystem ? Matrix.PerspectiveFovRH : Matrix.PerspectiveFovLH;
|
|
90
89
|
lookAtFunction(this.position, this._target, Vector3.Up(), this._viewMatrix);
|
|
91
90
|
if (scene.activeCamera) {
|
|
92
|
-
this._projectionMatrix = perspectiveFunction(Math.PI / 2, 1, useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ, useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ, this.
|
|
91
|
+
this._projectionMatrix = perspectiveFunction(Math.PI / 2, 1, useReverseDepthBuffer ? scene.activeCamera.maxZ : scene.activeCamera.minZ, useReverseDepthBuffer ? scene.activeCamera.minZ : scene.activeCamera.maxZ, this._getEngine().isNDCHalfZRange);
|
|
93
92
|
scene.setTransformMatrix(this._viewMatrix, this._projectionMatrix);
|
|
94
93
|
if (scene.activeCamera.isRigCamera && !this.activeCamera) {
|
|
95
94
|
this.activeCamera = scene.activeCamera.rigParent || null;
|
|
@@ -107,7 +106,7 @@ export class ReflectionProbeTexture extends RenderTargetTexture {
|
|
|
107
106
|
if (engine._enableGPUDebugMarkers) {
|
|
108
107
|
engine._debugPushGroup?.(`reflection probe generation for ${name}`);
|
|
109
108
|
}
|
|
110
|
-
currentApplyByPostProcess =
|
|
109
|
+
currentApplyByPostProcess = scene.imageProcessingConfiguration.applyByPostProcess;
|
|
111
110
|
if (linearSpace) {
|
|
112
111
|
scene.imageProcessingConfiguration.applyByPostProcess = true;
|
|
113
112
|
}
|
|
@@ -139,13 +138,6 @@ export class ReflectionProbeTexture extends RenderTargetTexture {
|
|
|
139
138
|
get attachedMesh() {
|
|
140
139
|
return this._attachedMesh;
|
|
141
140
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Gets the hosting scene
|
|
144
|
-
* @returns a Scene
|
|
145
|
-
*/
|
|
146
|
-
getScene() {
|
|
147
|
-
return this._probeScene;
|
|
148
|
-
}
|
|
149
141
|
/**
|
|
150
142
|
* Gets the class name of the reflection probe texture
|
|
151
143
|
* @returns "ReflectionProbeTexture"
|
|
@@ -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,OA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OAEG;IACa,OAAO;QACnB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChC,GAAG,CAAC,OAAO,EAAE,CAAC;YAClB,CAAC;YACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ;AAED,OAAO,CAAC,6BAA6B,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 { 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 _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 private _attachedMesh: Nullable<AbstractMesh>;\n\n /** Gets or sets probe position (center of the cube map) */\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 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"]}
|
|
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;IAsB3D;;;;;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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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 { 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 /**\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 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 = 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"]}
|