|
@@ -4,6 +4,7 @@ import {
|
|
DoubleSide,
|
|
DoubleSide,
|
|
InterpolateDiscrete,
|
|
InterpolateDiscrete,
|
|
InterpolateLinear,
|
|
InterpolateLinear,
|
|
|
|
+ LinearEncoding,
|
|
LinearFilter,
|
|
LinearFilter,
|
|
LinearMipmapLinearFilter,
|
|
LinearMipmapLinearFilter,
|
|
LinearMipmapNearestFilter,
|
|
LinearMipmapNearestFilter,
|
|
@@ -18,6 +19,7 @@ import {
|
|
RepeatWrapping,
|
|
RepeatWrapping,
|
|
Scene,
|
|
Scene,
|
|
Source,
|
|
Source,
|
|
|
|
+ sRGBEncoding,
|
|
Vector3
|
|
Vector3
|
|
} from 'three';
|
|
} from 'three';
|
|
|
|
|
|
@@ -732,6 +734,26 @@ class GLTFWriter {
|
|
|
|
|
|
if ( metalnessMap === roughnessMap ) return metalnessMap;
|
|
if ( metalnessMap === roughnessMap ) return metalnessMap;
|
|
|
|
|
|
|
|
+ function getEncodingConversion( map ) {
|
|
|
|
+
|
|
|
|
+ if ( map.encoding === sRGBEncoding ) {
|
|
|
|
+
|
|
|
|
+ return function SRGBToLinear( c ) {
|
|
|
|
+
|
|
|
|
+ return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return function LineatToLinear( c ) {
|
|
|
|
+
|
|
|
|
+ return c;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );
|
|
console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );
|
|
|
|
|
|
const metalness = metalnessMap?.image;
|
|
const metalness = metalnessMap?.image;
|
|
@@ -754,11 +776,12 @@ class GLTFWriter {
|
|
|
|
|
|
context.drawImage( metalness, 0, 0, width, height );
|
|
context.drawImage( metalness, 0, 0, width, height );
|
|
|
|
|
|
|
|
+ const convert = getEncodingConversion( metalnessMap );
|
|
const data = context.getImageData( 0, 0, width, height ).data;
|
|
const data = context.getImageData( 0, 0, width, height ).data;
|
|
|
|
|
|
for ( let i = 2; i < data.length; i += 4 ) {
|
|
for ( let i = 2; i < data.length; i += 4 ) {
|
|
|
|
|
|
- composite.data[ i ] = data[ i ];
|
|
|
|
|
|
+ composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -768,11 +791,12 @@ class GLTFWriter {
|
|
|
|
|
|
context.drawImage( roughness, 0, 0, width, height );
|
|
context.drawImage( roughness, 0, 0, width, height );
|
|
|
|
|
|
|
|
+ const convert = getEncodingConversion( roughnessMap );
|
|
const data = context.getImageData( 0, 0, width, height ).data;
|
|
const data = context.getImageData( 0, 0, width, height ).data;
|
|
|
|
|
|
for ( let i = 1; i < data.length; i += 4 ) {
|
|
for ( let i = 1; i < data.length; i += 4 ) {
|
|
|
|
|
|
- composite.data[ i ] = data[ i ];
|
|
|
|
|
|
+ composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -787,6 +811,7 @@ class GLTFWriter {
|
|
const texture = reference.clone();
|
|
const texture = reference.clone();
|
|
|
|
|
|
texture.source = new Source( canvas );
|
|
texture.source = new Source( canvas );
|
|
|
|
+ texture.encoding = LinearEncoding;
|
|
|
|
|
|
return texture;
|
|
return texture;
|
|
|
|
|