@@ -707,30 +707,42 @@ def __init__(
707
707
else :
708
708
raise ValueError ("Expected verts_uvs to be a tensor or list" )
709
709
710
+ if isinstance (maps , (list , tuple )):
711
+ self ._maps_list = maps
712
+ else :
713
+ self ._maps_list = None
714
+ self ._maps_padded = self ._format_maps_padded (maps )
715
+
716
+ if self ._maps_padded .device != self .device :
717
+ raise ValueError ("maps must be on the same device as verts/faces uvs." )
718
+
719
+ self .valid = torch .ones ((self ._N ,), dtype = torch .bool , device = self .device )
720
+
721
+ def _format_maps_padded (
722
+ self , maps : Union [torch .Tensor , List [torch .Tensor ]]
723
+ ) -> torch .Tensor :
710
724
if isinstance (maps , torch .Tensor ):
711
725
if maps .ndim != 4 or maps .shape [0 ] != self ._N :
712
726
msg = "Expected maps to be of shape (N, H, W, C); got %r"
713
727
raise ValueError (msg % repr (maps .shape ))
714
- self . _maps_padded = maps
715
- self . _maps_list = None
716
- elif isinstance (maps , (list , tuple )):
728
+ return maps
729
+
730
+ if isinstance (maps , (list , tuple )):
717
731
if len (maps ) != self ._N :
718
732
raise ValueError ("Expected one texture map per mesh in the batch." )
719
- self ._maps_list = maps
720
733
if self ._N > 0 :
721
- maps = _pad_texture_maps (maps , align_corners = self .align_corners )
734
+ if not all (map .ndim == 3 for map in maps ):
735
+ raise ValueError ("Invalid number of dimensions in texture maps" )
736
+ if not all (map .shape [2 ] == maps [0 ].shape [2 ] for map in maps ):
737
+ raise ValueError ("Inconsistent number of channels in maps" )
738
+ maps_padded = _pad_texture_maps (maps , align_corners = self .align_corners )
722
739
else :
723
- maps = torch .empty (
740
+ maps_padded = torch .empty (
724
741
(self ._N , 0 , 0 , 3 ), dtype = torch .float32 , device = self .device
725
742
)
726
- self ._maps_padded = maps
727
- else :
728
- raise ValueError ("Expected maps to be a tensor or list." )
743
+ return maps_padded
729
744
730
- if self ._maps_padded .device != self .device :
731
- raise ValueError ("maps must be on the same device as verts/faces uvs." )
732
-
733
- self .valid = torch .ones ((self ._N ,), dtype = torch .bool , device = self .device )
745
+ raise ValueError ("Expected maps to be a tensor or list of tensors." )
734
746
735
747
def clone (self ) -> "TexturesUV" :
736
748
tex = self .__class__ (
0 commit comments