Skip to content

Commit e0ce20c

Browse files
donmccurdyemmanueljl
authored andcommitted
Examples: Update more examples for color management. (mrdoob#25882)
* Examples: Update misc_exporter_gltf and misc_exporter_ply for color management. * Examples: Update 3MF examples for color management. * Examples: Update webgl_loader_draco for color management. * Examples: Update LDraw examples for color management. * Loaders: Update color space assignmentin 3MF, LDraw, and SVG loaders. * LDrawLoader: Clean up, fix emissive. * LDrawLoader: Clean up
1 parent 1ac0e98 commit e0ce20c

File tree

10 files changed

+37
-45
lines changed

10 files changed

+37
-45
lines changed

examples/jsm/loaders/3MFLoader.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
} from 'three';
2222
import * as fflate from '../libs/fflate.module.js';
2323

24+
const COLOR_SPACE_3MF = SRGBColorSpace;
25+
2426
/**
2527
*
2628
* 3D Manufacturing Format (3MF) specification: https://3mf.io/specification/
@@ -359,8 +361,7 @@ class ThreeMFLoader extends Loader {
359361
const colorNode = colorNodes[ i ];
360362
const color = colorNode.getAttribute( 'color' );
361363

362-
colorObject.setStyle( color.substring( 0, 7 ) );
363-
colorObject.convertSRGBToLinear(); // color is in sRGB
364+
colorObject.setStyle( color.substring( 0, 7 ), COLOR_SPACE_3MF );
364365

365366
colors.push( colorObject.r, colorObject.g, colorObject.b );
366367

@@ -789,7 +790,7 @@ class ThreeMFLoader extends Loader {
789790

790791
} );
791792

792-
texture.colorSpace = SRGBColorSpace;
793+
texture.colorSpace = COLOR_SPACE_3MF;
793794

794795
// texture parameters
795796

@@ -1281,8 +1282,7 @@ class ThreeMFLoader extends Loader {
12811282
const displaycolor = materialData.displaycolor;
12821283

12831284
const color = displaycolor.substring( 0, 7 );
1284-
material.color.setStyle( color );
1285-
material.color.convertSRGBToLinear(); // displaycolor is in sRGB
1285+
material.color.setStyle( color, COLOR_SPACE_3MF );
12861286

12871287
// process alpha if set
12881288

examples/jsm/loaders/LDrawLoader.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Mesh,
1212
MeshStandardMaterial,
1313
ShaderMaterial,
14+
SRGBColorSpace,
1415
UniformsLib,
1516
UniformsUtils,
1617
Vector3,
@@ -39,6 +40,8 @@ const FILE_LOCATION_NOT_FOUND = 6;
3940
const MAIN_COLOUR_CODE = '16';
4041
const MAIN_EDGE_COLOUR_CODE = '24';
4142

43+
const COLOR_SPACE_LDRAW = SRGBColorSpace;
44+
4245
const _tempVec0 = new Vector3();
4346
const _tempVec1 = new Vector3();
4447

@@ -2162,8 +2165,8 @@ class LDrawLoader extends Loader {
21622165
let code = null;
21632166

21642167
// Triangle and line colors
2165-
let color = 0xFF00FF;
2166-
let edgeColor = 0xFF00FF;
2168+
let fillColor = '#FF00FF';
2169+
let edgeColor = '#FF00FF';
21672170

21682171
// Transparency
21692172
let alpha = 1;
@@ -2205,12 +2208,12 @@ class LDrawLoader extends Loader {
22052208

22062209
case 'VALUE':
22072210

2208-
color = lineParser.getToken();
2209-
if ( color.startsWith( '0x' ) ) {
2211+
fillColor = lineParser.getToken();
2212+
if ( fillColor.startsWith( '0x' ) ) {
22102213

2211-
color = '#' + color.substring( 2 );
2214+
fillColor = '#' + fillColor.substring( 2 );
22122215

2213-
} else if ( ! color.startsWith( '#' ) ) {
2216+
} else if ( ! fillColor.startsWith( '#' ) ) {
22142217

22152218
throw new Error( 'LDrawLoader: Invalid color while parsing material' + lineParser.getLineNumberString() + '.' );
22162219

@@ -2312,37 +2315,37 @@ class LDrawLoader extends Loader {
23122315

23132316
case FINISH_TYPE_DEFAULT:
23142317

2315-
material = new MeshStandardMaterial( { color: color, roughness: 0.3, metalness: 0 } );
2318+
material = new MeshStandardMaterial( { roughness: 0.3, metalness: 0 } );
23162319
break;
23172320

23182321
case FINISH_TYPE_PEARLESCENT:
23192322

23202323
// Try to imitate pearlescency by making the surface glossy
2321-
material = new MeshStandardMaterial( { color: color, roughness: 0.3, metalness: 0.25 } );
2324+
material = new MeshStandardMaterial( { roughness: 0.3, metalness: 0.25 } );
23222325
break;
23232326

23242327
case FINISH_TYPE_CHROME:
23252328

23262329
// Mirror finish surface
2327-
material = new MeshStandardMaterial( { color: color, roughness: 0, metalness: 1 } );
2330+
material = new MeshStandardMaterial( { roughness: 0, metalness: 1 } );
23282331
break;
23292332

23302333
case FINISH_TYPE_RUBBER:
23312334

23322335
// Rubber finish
2333-
material = new MeshStandardMaterial( { color: color, roughness: 0.9, metalness: 0 } );
2336+
material = new MeshStandardMaterial( { roughness: 0.9, metalness: 0 } );
23342337
break;
23352338

23362339
case FINISH_TYPE_MATTE_METALLIC:
23372340

23382341
// Brushed metal finish
2339-
material = new MeshStandardMaterial( { color: color, roughness: 0.8, metalness: 0.4 } );
2342+
material = new MeshStandardMaterial( { roughness: 0.8, metalness: 0.4 } );
23402343
break;
23412344

23422345
case FINISH_TYPE_METAL:
23432346

23442347
// Average metal finish
2345-
material = new MeshStandardMaterial( { color: color, roughness: 0.2, metalness: 0.85 } );
2348+
material = new MeshStandardMaterial( { roughness: 0.2, metalness: 0.85 } );
23462349
break;
23472350

23482351
default:
@@ -2351,45 +2354,44 @@ class LDrawLoader extends Loader {
23512354

23522355
}
23532356

2357+
material.color.setStyle( fillColor, COLOR_SPACE_LDRAW );
23542358
material.transparent = isTransparent;
23552359
material.premultipliedAlpha = true;
23562360
material.opacity = alpha;
23572361
material.depthWrite = ! isTransparent;
2358-
material.color.convertSRGBToLinear();
23592362

23602363
material.polygonOffset = true;
23612364
material.polygonOffsetFactor = 1;
23622365

23632366
if ( luminance !== 0 ) {
23642367

2365-
material.emissive.set( material.color ).multiplyScalar( luminance );
2368+
material.emissive.setStyle( fillColor, COLOR_SPACE_LDRAW ).multiplyScalar( luminance );
23662369

23672370
}
23682371

23692372
if ( ! edgeMaterial ) {
23702373

23712374
// This is the material used for edges
23722375
edgeMaterial = new LineBasicMaterial( {
2373-
color: edgeColor,
2376+
color: new Color().setStyle( edgeColor, COLOR_SPACE_LDRAW ),
23742377
transparent: isTransparent,
23752378
opacity: alpha,
23762379
depthWrite: ! isTransparent
23772380
} );
2381+
edgeMaterial.color;
23782382
edgeMaterial.userData.code = code;
23792383
edgeMaterial.name = name + ' - Edge';
2380-
edgeMaterial.color.convertSRGBToLinear();
23812384

23822385
// This is the material used for conditional edges
23832386
edgeMaterial.userData.conditionalEdgeMaterial = new LDrawConditionalLineMaterial( {
23842387

23852388
fog: true,
23862389
transparent: isTransparent,
23872390
depthWrite: ! isTransparent,
2388-
color: edgeColor,
2391+
color: new Color().setStyle( edgeColor, COLOR_SPACE_LDRAW ),
23892392
opacity: alpha,
23902393

23912394
} );
2392-
edgeMaterial.userData.conditionalEdgeMaterial.color.convertSRGBToLinear();
23932395
edgeMaterial.userData.conditionalEdgeMaterial.userData.code = code;
23942396
edgeMaterial.userData.conditionalEdgeMaterial.name = name + ' - Conditional Edge';
23952397

examples/jsm/loaders/SVGLoader.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import {
99
Shape,
1010
ShapePath,
1111
ShapeUtils,
12+
SRGBColorSpace,
1213
Vector2,
1314
Vector3
1415
} from 'three';
1516

17+
const COLOR_SPACE_SVG = SRGBColorSpace;
18+
1619
class SVGLoader extends Loader {
1720

1821
constructor( manager ) {
@@ -155,7 +158,7 @@ class SVGLoader extends Loader {
155158

156159
if ( style.fill !== undefined && style.fill !== 'none' ) {
157160

158-
path.color.setStyle( style.fill );
161+
path.color.setStyle( style.fill, COLOR_SPACE_SVG );
159162

160163
}
161164

examples/misc_exporter_gltf.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
3333
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
3434

35-
THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.
36-
3735
function exportGLTF( input ) {
3836

3937
const gltfExporter = new GLTFExporter();
@@ -180,7 +178,7 @@
180178
// ---------------------------------------------------------------------
181179
// Grid
182180
// ---------------------------------------------------------------------
183-
gridHelper = new THREE.GridHelper( 2000, 20, 0x888888, 0x444444 );
181+
gridHelper = new THREE.GridHelper( 2000, 20, 0xc1c1c1, 0x8d8d8d );
184182
gridHelper.position.y = - 50;
185183
gridHelper.name = 'Grid';
186184
scene1.add( gridHelper );

examples/misc_exporter_ply.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import { PLYExporter } from 'three/addons/exporters/PLYExporter.js';
3333
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
3434

35-
THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.
36-
3735
let scene, camera, renderer, exporter, mesh;
3836

3937
const params = {
@@ -58,7 +56,7 @@
5856

5957
//
6058

61-
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
59+
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x8d8d8d );
6260
hemiLight.position.set( 0, 200, 0 );
6361
scene.add( hemiLight );
6462

@@ -73,7 +71,7 @@
7371

7472
// ground
7573

76-
const ground = new THREE.Mesh( new THREE.PlaneGeometry( 2000, 2000 ), new THREE.MeshPhongMaterial( { color: 0x999999, depthWrite: false } ) );
74+
const ground = new THREE.Mesh( new THREE.PlaneGeometry( 2000, 2000 ), new THREE.MeshPhongMaterial( { color: 0xcbcbcb, depthWrite: false } ) );
7775
ground.rotation.x = - Math.PI / 2;
7876
ground.receiveShadow = true;
7977
scene.add( ground );
-20 Bytes
Loading

examples/webgl_loader_3mf.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import { ThreeMFLoader } from 'three/addons/loaders/3MFLoader.js';
4141
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
4242

43-
THREE.ColorManagement.enabled = false; // TODO: Confirm correct color management.
44-
4543
let camera, scene, renderer, object, loader, controls;
4644

4745
const params = {
@@ -62,7 +60,6 @@
6260
renderer = new THREE.WebGLRenderer( { antialias: true } );
6361
renderer.setPixelRatio( window.devicePixelRatio );
6462
renderer.setSize( window.innerWidth, window.innerHeight );
65-
renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
6663
document.body.appendChild( renderer.domElement );
6764

6865
scene = new THREE.Scene();

examples/webgl_loader_3mf_materials.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3838
import { ThreeMFLoader } from 'three/addons/loaders/3MFLoader.js';
3939

40-
THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.
41-
4240
let camera, scene, renderer;
4341

4442
init();
@@ -55,7 +53,7 @@
5553

5654
//
5755

58-
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444 );
56+
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x8d8d8d );
5957
hemiLight.position.set( 0, 100, 0 );
6058
scene.add( hemiLight );
6159

@@ -102,7 +100,7 @@
102100

103101
//
104102

105-
const ground = new THREE.Mesh( new THREE.PlaneGeometry( 1000, 1000 ), new THREE.MeshPhongMaterial( { color: 0x999999, depthWrite: false } ) );
103+
const ground = new THREE.Mesh( new THREE.PlaneGeometry( 1000, 1000 ), new THREE.MeshPhongMaterial( { color: 0xcbcbcb, depthWrite: false } ) );
106104
ground.rotation.x = - Math.PI / 2;
107105
ground.position.y = 11;
108106
ground.receiveShadow = true;

examples/webgl_loader_draco.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
3434

35-
THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.
36-
3735
let camera, scene, renderer;
3836

3937
const container = document.querySelector( '#container' );
@@ -58,15 +56,15 @@
5856
// Ground
5957
const plane = new THREE.Mesh(
6058
new THREE.PlaneGeometry( 8, 8 ),
61-
new THREE.MeshPhongMaterial( { color: 0x999999, specular: 0x101010 } )
59+
new THREE.MeshPhongMaterial( { color: 0xcbcbcb, specular: 0x101010 } )
6260
);
6361
plane.rotation.x = - Math.PI / 2;
6462
plane.position.y = 0.03;
6563
plane.receiveShadow = true;
6664
scene.add( plane );
6765

6866
// Lights
69-
const hemiLight = new THREE.HemisphereLight( 0x443333, 0x111122 );
67+
const hemiLight = new THREE.HemisphereLight( 0x8d7c7c, 0x494966 );
7068
scene.add( hemiLight );
7169

7270
const spotLight = new THREE.SpotLight();
@@ -80,7 +78,7 @@
8078

8179
geometry.computeVertexNormals();
8280

83-
const material = new THREE.MeshStandardMaterial( { color: 0x606060 } );
81+
const material = new THREE.MeshStandardMaterial( { color: 0xa5a5a5 } );
8482
const mesh = new THREE.Mesh( geometry, material );
8583
mesh.castShadow = true;
8684
mesh.receiveShadow = true;

examples/webgl_loader_ldraw.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
import { LDrawLoader } from 'three/addons/loaders/LDrawLoader.js';
4646
import { LDrawUtils } from 'three/addons/utils/LDrawUtils.js';
4747

48-
THREE.ColorManagement.enabled = false; // TODO: Consider enabling color management.
49-
5048
let container, progressBarDiv;
5149

5250
let camera, scene, renderer, controls, gui, guiData;

0 commit comments

Comments
 (0)