Skip to content

Commit a7de6c5

Browse files
authored
GLTFExporter: Support multiple UV sets (#25843)
1 parent 86d77e8 commit a7de6c5

File tree

1 file changed

+68
-16
lines changed

1 file changed

+68
-16
lines changed

examples/jsm/exporters/GLTFExporter.js

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,13 @@ class GLTFWriter {
877877

878878
texture.source = new Source( canvas );
879879
texture.colorSpace = NoColorSpace;
880+
texture.channel = ( metalnessMap || roughnessMap ).channel;
881+
882+
if ( metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel ) {
883+
884+
console.warn( 'THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.' );
885+
886+
}
880887

881888
return texture;
882889

@@ -1417,7 +1424,10 @@ class GLTFWriter {
14171424

14181425
const metalRoughTexture = this.buildMetalRoughTexture( material.metalnessMap, material.roughnessMap );
14191426

1420-
const metalRoughMapDef = { index: this.processTexture( metalRoughTexture ) };
1427+
const metalRoughMapDef = {
1428+
index: this.processTexture( metalRoughTexture ),
1429+
channel: metalRoughTexture.channel
1430+
};
14211431
this.applyTextureTransform( metalRoughMapDef, metalRoughTexture );
14221432
materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
14231433

@@ -1426,7 +1436,10 @@ class GLTFWriter {
14261436
// pbrMetallicRoughness.baseColorTexture
14271437
if ( material.map ) {
14281438

1429-
const baseColorMapDef = { index: this.processTexture( material.map ) };
1439+
const baseColorMapDef = {
1440+
index: this.processTexture( material.map ),
1441+
texCoord: material.map.channel
1442+
};
14301443
this.applyTextureTransform( baseColorMapDef, material.map );
14311444
materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
14321445

@@ -1446,7 +1459,10 @@ class GLTFWriter {
14461459
// emissiveTexture
14471460
if ( material.emissiveMap ) {
14481461

1449-
const emissiveMapDef = { index: this.processTexture( material.emissiveMap ) };
1462+
const emissiveMapDef = {
1463+
index: this.processTexture( material.emissiveMap ),
1464+
texCoord: material.emissiveMap.channel
1465+
};
14501466
this.applyTextureTransform( emissiveMapDef, material.emissiveMap );
14511467
materialDef.emissiveTexture = emissiveMapDef;
14521468

@@ -1457,7 +1473,10 @@ class GLTFWriter {
14571473
// normalTexture
14581474
if ( material.normalMap ) {
14591475

1460-
const normalMapDef = { index: this.processTexture( material.normalMap ) };
1476+
const normalMapDef = {
1477+
index: this.processTexture( material.normalMap ),
1478+
texCoord: material.normalMap.channel
1479+
};
14611480

14621481
if ( material.normalScale && material.normalScale.x !== 1 ) {
14631482

@@ -1477,7 +1496,7 @@ class GLTFWriter {
14771496

14781497
const occlusionMapDef = {
14791498
index: this.processTexture( material.aoMap ),
1480-
texCoord: 1
1499+
texCoord: material.aoMap.channel
14811500
};
14821501

14831502
if ( material.aoMapIntensity !== 1.0 ) {
@@ -2491,7 +2510,10 @@ class GLTFMaterialsClearcoatExtension {
24912510

24922511
if ( material.clearcoatMap ) {
24932512

2494-
const clearcoatMapDef = { index: writer.processTexture( material.clearcoatMap ) };
2513+
const clearcoatMapDef = {
2514+
index: writer.processTexture( material.clearcoatMap ),
2515+
texCoord: material.clearcoatMap.channel
2516+
};
24952517
writer.applyTextureTransform( clearcoatMapDef, material.clearcoatMap );
24962518
extensionDef.clearcoatTexture = clearcoatMapDef;
24972519

@@ -2501,15 +2523,21 @@ class GLTFMaterialsClearcoatExtension {
25012523

25022524
if ( material.clearcoatRoughnessMap ) {
25032525

2504-
const clearcoatRoughnessMapDef = { index: writer.processTexture( material.clearcoatRoughnessMap ) };
2526+
const clearcoatRoughnessMapDef = {
2527+
index: writer.processTexture( material.clearcoatRoughnessMap ),
2528+
texCoord: material.clearcoatRoughnessMap.channel
2529+
};
25052530
writer.applyTextureTransform( clearcoatRoughnessMapDef, material.clearcoatRoughnessMap );
25062531
extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef;
25072532

25082533
}
25092534

25102535
if ( material.clearcoatNormalMap ) {
25112536

2512-
const clearcoatNormalMapDef = { index: writer.processTexture( material.clearcoatNormalMap ) };
2537+
const clearcoatNormalMapDef = {
2538+
index: writer.processTexture( material.clearcoatNormalMap ),
2539+
texCoord: material.clearcoatNormalMap.channel
2540+
};
25132541
writer.applyTextureTransform( clearcoatNormalMapDef, material.clearcoatNormalMap );
25142542
extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
25152543

@@ -2552,7 +2580,10 @@ class GLTFMaterialsIridescenceExtension {
25522580

25532581
if ( material.iridescenceMap ) {
25542582

2555-
const iridescenceMapDef = { index: writer.processTexture( material.iridescenceMap ) };
2583+
const iridescenceMapDef = {
2584+
index: writer.processTexture( material.iridescenceMap ),
2585+
texCoord: material.iridescenceMap.channel
2586+
};
25562587
writer.applyTextureTransform( iridescenceMapDef, material.iridescenceMap );
25572588
extensionDef.iridescenceTexture = iridescenceMapDef;
25582589

@@ -2564,7 +2595,10 @@ class GLTFMaterialsIridescenceExtension {
25642595

25652596
if ( material.iridescenceThicknessMap ) {
25662597

2567-
const iridescenceThicknessMapDef = { index: writer.processTexture( material.iridescenceThicknessMap ) };
2598+
const iridescenceThicknessMapDef = {
2599+
index: writer.processTexture( material.iridescenceThicknessMap ),
2600+
texCoord: material.iridescenceThicknessMap.channel
2601+
};
25682602
writer.applyTextureTransform( iridescenceThicknessMapDef, material.iridescenceThicknessMap );
25692603
extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef;
25702604

@@ -2606,7 +2640,10 @@ class GLTFMaterialsTransmissionExtension {
26062640

26072641
if ( material.transmissionMap ) {
26082642

2609-
const transmissionMapDef = { index: writer.processTexture( material.transmissionMap ) };
2643+
const transmissionMapDef = {
2644+
index: writer.processTexture( material.transmissionMap ),
2645+
texCoord: material.transmissionMap.channel
2646+
};
26102647
writer.applyTextureTransform( transmissionMapDef, material.transmissionMap );
26112648
extensionDef.transmissionTexture = transmissionMapDef;
26122649

@@ -2648,7 +2685,10 @@ class GLTFMaterialsVolumeExtension {
26482685

26492686
if ( material.thicknessMap ) {
26502687

2651-
const thicknessMapDef = { index: writer.processTexture( material.thicknessMap ) };
2688+
const thicknessMapDef = {
2689+
index: writer.processTexture( material.thicknessMap ),
2690+
texCoord: material.thicknessMap.channel
2691+
};
26522692
writer.applyTextureTransform( thicknessMapDef, material.thicknessMap );
26532693
extensionDef.thicknessTexture = thicknessMapDef;
26542694

@@ -2727,15 +2767,21 @@ class GLTFMaterialsSpecularExtension {
27272767

27282768
if ( material.specularIntensityMap ) {
27292769

2730-
const specularIntensityMapDef = { index: writer.processTexture( material.specularIntensityMap ) };
2770+
const specularIntensityMapDef = {
2771+
index: writer.processTexture( material.specularIntensityMap ),
2772+
texCoord: material.specularIntensityMap.channel
2773+
};
27312774
writer.applyTextureTransform( specularIntensityMapDef, material.specularIntensityMap );
27322775
extensionDef.specularTexture = specularIntensityMapDef;
27332776

27342777
}
27352778

27362779
if ( material.specularColorMap ) {
27372780

2738-
const specularColorMapDef = { index: writer.processTexture( material.specularColorMap ) };
2781+
const specularColorMapDef = {
2782+
index: writer.processTexture( material.specularColorMap ),
2783+
texCoord: material.specularColorMap.channel
2784+
};
27392785
writer.applyTextureTransform( specularColorMapDef, material.specularColorMap );
27402786
extensionDef.specularColorTexture = specularColorMapDef;
27412787

@@ -2778,15 +2824,21 @@ class GLTFMaterialsSheenExtension {
27782824

27792825
if ( material.sheenRoughnessMap ) {
27802826

2781-
const sheenRoughnessMapDef = { index: writer.processTexture( material.sheenRoughnessMap ) };
2827+
const sheenRoughnessMapDef = {
2828+
index: writer.processTexture( material.sheenRoughnessMap ),
2829+
texCoord: material.sheenRoughnessMap.channel
2830+
};
27822831
writer.applyTextureTransform( sheenRoughnessMapDef, material.sheenRoughnessMap );
27832832
extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef;
27842833

27852834
}
27862835

27872836
if ( material.sheenColorMap ) {
27882837

2789-
const sheenColorMapDef = { index: writer.processTexture( material.sheenColorMap ) };
2838+
const sheenColorMapDef = {
2839+
index: writer.processTexture( material.sheenColorMap ),
2840+
texCoord: material.sheenColorMap.channel
2841+
};
27902842
writer.applyTextureTransform( sheenColorMapDef, material.sheenColorMap );
27912843
extensionDef.sheenColorTexture = sheenColorMapDef;
27922844

0 commit comments

Comments
 (0)