@@ -374,10 +374,6 @@ public MaterialId ExportMaterial(Material materialObj)
374374
375375 material . OcclusionTexture = ExportOcclusionTextureInfo ( occTex , TextureMapType . Occlusion , materialObj , sharedTextureId ) ;
376376 ExportTextureTransform ( material . OcclusionTexture , materialObj , propName ) ;
377- material . OcclusionTexture . TexCoord = materialObj . HasProperty ( "occlusionTextureTexCoord" ) ?
378- Mathf . RoundToInt ( materialObj . GetFloat ( "occlusionTextureTexCoord" ) ) :
379- materialObj . HasProperty ( "_OcclusionTextureTexCoord" ) ?
380- Mathf . RoundToInt ( materialObj . GetFloat ( "_OcclusionTextureTexCoord" ) ) : 0 ;
381377 }
382378 else
383379 {
@@ -460,13 +456,36 @@ private static bool CheckForPropertyInShader(Shader shader, string name, ShaderP
460456 }
461457#endif
462458
463- private void ExportTextureTransform ( TextureInfo def , Material mat , string texName )
459+ private int GetUvChannel ( Material mat , string texName )
464460 {
465- if ( def == null ) return ;
461+ if ( mat == null ) return 0 ;
462+
463+ var uvProp = texName + "TexCoord" ;
464+ #if UNITY_2021_1_OR_NEWER
465+ if ( mat . HasFloat ( uvProp ) )
466+ #else
467+ if ( mat . HasProperty ( uvProp )
468+ #if UNITY_2019_1_OR_NEWER
469+ & & CheckForPropertyInShader ( mat . shader , uvProp , ShaderPropertyType . Float )
470+ #endif
471+ )
472+ #endif
473+ return Mathf . RoundToInt ( mat . GetFloat ( uvProp ) ) ;
474+
475+ return 0 ;
476+ }
477+
478+ private bool ExportTextureTransform ( TextureInfo def , Material mat , string texName )
479+ {
480+ if ( def == null ) return false ;
466481
467482 // early out if texture transform is explicitly disabled
468483 if ( mat . HasProperty ( "_TEXTURE_TRANSFORM" ) && ! mat . IsKeywordEnabled ( "_TEXTURE_TRANSFORM_ON" ) )
469- return ;
484+ {
485+ // even without texture transform, set the uv channel in case the user has modified it (normally the slider is not visible in the inspector but if texture transform was enabled, uv modified and then disabled the uv channel setting will still be used by Unity and should then be exported)
486+ def . TexCoord = GetUvChannel ( mat , texName ) ;
487+ return false ;
488+ }
470489
471490 Vector2 offset = mat . GetTextureOffset ( texName ) ;
472491 Vector2 scale = mat . GetTextureScale ( texName ) ;
@@ -488,16 +507,7 @@ private void ExportTextureTransform(TextureInfo def, Material mat, string texNam
488507#endif
489508 rotation = mat . GetFloat ( rotProp ) ;
490509
491- #if UNITY_2021_1_OR_NEWER
492- if ( mat . HasFloat ( uvProp ) )
493- #else
494- if ( mat . HasProperty ( uvProp )
495- #if UNITY_2019_1_OR_NEWER
496- & & CheckForPropertyInShader ( mat . shader , uvProp , ShaderPropertyType . Float )
497- #endif
498- )
499- #endif
500- uvChannel = mat . GetFloat ( uvProp ) ;
510+ uvChannel = GetUvChannel ( mat , texName ) ;
501511
502512
503513
@@ -586,6 +596,8 @@ private void ExportTextureTransform(TextureInfo def, Material mat, string texNam
586596 new GLTF . Math . Vector2 ( scale . x , scale . y ) ,
587597 ( int ) uvChannel
588598 ) ;
599+
600+ return true ;
589601 }
590602
591603 public NormalTextureInfo ExportNormalTextureInfo (
0 commit comments