@@ -87,17 +87,23 @@ def format_texture_source(texture, target_channels="RGB"):
8787 if texture .shape [2 ] == 1 :
8888 texture = np .repeat (texture , 3 , axis = 2 )
8989 elif texture .shape [2 ] == 2 :
90- raise ValueError ("Cannot reformat 2-channel texture into RGB" )
90+ # Convert 2-channel texture to grayscale RGB by duplicating the first channel
91+ texture = texture [:, :, (0 , 0 , 0 )]
9192 else :
9293 texture = texture [:, :, (0 , 1 , 2 )]
9394 elif target_channels == "RGBA" :
9495 if texture .shape [2 ] == 1 :
9596 texture = np .repeat (texture , 4 , axis = 2 )
9697 texture [:, :, 3 ] = 255
9798 elif texture .shape [2 ] == 2 :
98- raise ValueError ("Cannot reformat 2-channel texture into RGBA" )
99+ # Convert 2-channel texture (luminance + alpha) to RGBA by duplicating luminance to RGB
100+ luminance = texture [:, :, :1 ]
101+ alpha = texture [:, :, 1 ]
102+ texture = np .empty ((* texture .shape [:2 ], 4 ), dtype = texture .dtype )
103+ texture [:, :, :3 ] = luminance
104+ texture [:, :, 3 ] = alpha
99105 elif texture .shape [2 ] == 3 :
100- tx = np .empty ((texture .shape [0 ], texture . shape [ 1 ], 4 ), dtype = np .uint8 )
106+ tx = np .empty ((* texture .shape [: 2 ], 4 ), dtype = np .uint8 )
101107 tx [:, :, :3 ] = texture
102108 tx [:, :, 3 ] = 255
103109 texture = tx
0 commit comments