@@ -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;
3940const MAIN_COLOUR_CODE = '16' ;
4041const MAIN_EDGE_COLOUR_CODE = '24' ;
4142
43+ const COLOR_SPACE_LDRAW = SRGBColorSpace ;
44+
4245const _tempVec0 = new Vector3 ( ) ;
4346const _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
0 commit comments