@@ -144,10 +144,31 @@ class ColladaExporter {
144144
145145 // gets the attribute array. Generate a new array if the attribute is interleaved
146146 const getFuncs = [ 'getX' , 'getY' , 'getZ' , 'getW' ] ;
147+ const tempColor = new Color ( ) ;
147148
148- function attrBufferToArray ( attr ) {
149+ function attrBufferToArray ( attr , isColor = false ) {
149150
150- if ( attr . isInterleavedBufferAttribute ) {
151+ console . log ( attr , attr . count , isColor )
152+ if ( isColor ) {
153+
154+ // convert the colors to srgb before export
155+ // colors are always written as floats
156+ const arr = new Float32Array ( attr . count * 3 ) ;
157+ for ( let i = 0 , l = attr . count ; i < l ; i ++ ) {
158+
159+ tempColor
160+ . fromBufferAttribute ( attr , i )
161+ . convertLinearToSRGB ( ) ;
162+
163+ arr [ 3 * i + 0 ] = tempColor . r ;
164+ arr [ 3 * i + 1 ] = tempColor . g ;
165+ arr [ 3 * i + 2 ] = tempColor . b ;
166+
167+ }
168+
169+ return arr ;
170+
171+ } else if ( attr . isInterleavedBufferAttribute ) {
151172
152173 // use the typed array constructor to save on memory
153174 const arr = new attr . array . constructor ( attr . count * attr . itemSize ) ;
@@ -183,9 +204,9 @@ class ColladaExporter {
183204 }
184205
185206 // Returns the string for a geometry's attribute
186- function getAttribute ( attr , name , params , type ) {
207+ function getAttribute ( attr , name , params , type , isColor = false ) {
187208
188- const array = attrBufferToArray ( attr ) ;
209+ const array = attrBufferToArray ( attr , isColor ) ;
189210 const res =
190211 `<source id="${ name } ">` +
191212
@@ -296,8 +317,9 @@ class ColladaExporter {
296317 // serialize colors
297318 if ( 'color' in bufferGeometry . attributes ) {
298319
320+ // colors are always written as floats
299321 const colName = `${ meshid } -color` ;
300- gnode += getAttribute ( bufferGeometry . attributes . color , colName , [ 'X ' , 'Y ' , 'Z ' ] , 'uint8' ) ;
322+ gnode += getAttribute ( bufferGeometry . attributes . color , colName , [ 'R ' , 'G ' , 'B ' ] , 'float' , true ) ;
301323 triangleInputs += `<input semantic="COLOR" source="#${ colName } " offset="0" />` ;
302324
303325 }
@@ -419,6 +441,10 @@ class ColladaExporter {
419441 const shininess = m . shininess || 0 ;
420442 const reflectivity = m . reflectivity || 0 ;
421443
444+ emissive . convertLinearToSRGB ( ) ;
445+ specular . convertLinearToSRGB ( ) ;
446+ diffuse . convertLinearToSRGB ( ) ;
447+
422448 // Do not export and alpha map for the reasons mentioned in issue (#13792)
423449 // in three.js alpha maps are black and white, but collada expects the alpha
424450 // channel to specify the transparency
0 commit comments