Skip to content

Commit cd0505a

Browse files
committed
refactor: update deprecated Three.js encoding API to colorSpace
Replace deprecated outputEncoding/encoding with outputColorSpace/colorSpace in preparation for Three.js r158+ compatibility. Changes: - BasicRenderer.js: outputEncoding → outputColorSpace (lines 46, 90) - BasicRenderer.js: THREE.sRGBEncoding → THREE.SRGBColorSpace - BasicRenderer.js: THREE.LinearEncoding → THREE.LinearSRGBColorSpace - Renderer.js: outputEncoding → outputColorSpace (lines 51, 104) - Renderer.js: Update encoding types map to colorSpace types - EnvironmentManager.js: texture.encoding → texture.colorSpace (line 145) Updated files: - src/core/renderers/BasicRenderer.js - src/core/renderers/Renderer.js - src/core/managers/EnvironmentManager.js Ref: https://threejs.org/docs/#manual/en/introduction/Color-management Breaking change in Three.js r152+
1 parent dac9ff5 commit cd0505a

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/core/managers/EnvironmentManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ export class EnvironmentManager {
137137
*/
138138
async loadLDR(path) {
139139
return new Promise((resolve, reject) => {
140-
new THREE.TextureLoader().load(path,
140+
new THREE.TextureLoader().load(path,
141141
texture => {
142142
texture.minFilter = THREE.NearestFilter;
143143
texture.magFilter = THREE.NearestFilter;
144144
texture.type = THREE.UnsignedByteType;
145-
texture.encoding = THREE.sRGBEncoding;
145+
texture.colorSpace = THREE.SRGBColorSpace;
146146
texture.generateMipmaps = false;
147147
texture.flipY = false;
148148
resolve(texture);

src/core/renderers/BasicRenderer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export class BasicRenderer extends THREE.WebGLRenderer {
4141
this.setPixelRatio(Math.min(window.devicePixelRatio, 2));
4242
this.setClearColor(0x000000, 0);
4343
this.setSize(window.innerWidth, window.innerHeight);
44-
44+
4545
this.physicallyCorrectLights = true;
46-
this.outputEncoding = THREE.sRGBEncoding;
46+
this.outputColorSpace = THREE.SRGBColorSpace;
4747
this.toneMapping = THREE.ACESFilmicToneMapping;
4848
this.toneMappingExposure = 1;
4949
this.shadowMap.enabled = true;
@@ -77,17 +77,17 @@ export class BasicRenderer extends THREE.WebGLRenderer {
7777
this.toneMapping = toneMappingTypes[this.debugObject.toneMapping];
7878
this.toneMappingExposure = this.debugObject.toneMappingExposure;
7979

80-
// Update encoding
81-
const encodingTypes = {
82-
'Linear': THREE.LinearEncoding,
83-
'sRGB': THREE.sRGBEncoding
80+
// Update color space
81+
const colorSpaceTypes = {
82+
'Linear': THREE.LinearSRGBColorSpace,
83+
'sRGB': THREE.SRGBColorSpace
8484
};
8585
if (this.debugObject.outputEncoding === 'Gamma') {
8686
console.warn(
87-
'[BasicRenderer] GammaEncoding is not available in this version of three.js; falling back to sRGBEncoding.'
87+
'[BasicRenderer] GammaEncoding is not available in this version of three.js; falling back to SRGBColorSpace.'
8888
);
8989
}
90-
this.outputEncoding = encodingTypes[this.debugObject.outputEncoding] ?? THREE.sRGBEncoding;
90+
this.outputColorSpace = colorSpaceTypes[this.debugObject.outputEncoding] ?? THREE.SRGBColorSpace;
9191

9292
// Update shadow map type
9393
const shadowMapTypes = {

src/core/renderers/Renderer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Renderer extends THREE.WebGLRenderer {
4848

4949
// Physical settings
5050
this.physicallyCorrectLights = true;
51-
this.outputEncoding = THREE.sRGBEncoding;
51+
this.outputColorSpace = THREE.SRGBColorSpace;
5252
this.toneMapping = THREE.ACESFilmicToneMapping;
5353
this.toneMappingExposure = 1;
5454

@@ -85,10 +85,10 @@ export class Renderer extends THREE.WebGLRenderer {
8585
'ACESFilmic': THREE.ACESFilmicToneMapping
8686
};
8787

88-
const encodingTypes = {
89-
'Linear': THREE.LinearEncoding,
90-
'sRGB': THREE.sRGBEncoding,
91-
'Gamma': THREE.GammaEncoding
88+
const colorSpaceTypes = {
89+
'Linear': THREE.LinearSRGBColorSpace,
90+
'sRGB': THREE.SRGBColorSpace,
91+
'Gamma': THREE.SRGBColorSpace // Gamma is deprecated, map to sRGB
9292
};
9393

9494
const shadowMapTypes = {
@@ -101,7 +101,7 @@ export class Renderer extends THREE.WebGLRenderer {
101101
this.setClearColor(this.debugObject.clearColor, this.debugObject.clearAlpha);
102102
this.toneMapping = toneMappingTypes[this.debugObject.toneMapping];
103103
this.toneMappingExposure = this.debugObject.toneMappingExposure;
104-
this.outputEncoding = encodingTypes[this.debugObject.outputEncoding];
104+
this.outputColorSpace = colorSpaceTypes[this.debugObject.outputEncoding];
105105
this.shadowMap.type = shadowMapTypes[this.debugObject.shadowMapType];
106106
this.shadowMap.needsUpdate = true;
107107
this.physicallyCorrectLights = this.debugObject.physicallyCorrectLights;

0 commit comments

Comments
 (0)