@@ -408,62 +408,90 @@ protected void ImportTextures(List<B> blobs)
408408 }
409409 }
410410
411- Dictionary < T , List < PositionedTexture > > texturePositions = new ( ) ;
412-
411+ var texturePositions = new Dictionary < T , List < PositionedTexture > > ( ) ;
413412 foreach ( B blob in blobs )
414413 {
415414 if ( blob . IsDependencyOnly )
416- continue ;
417-
418- Dictionary < int , int > remap = new ( ) ;
419- foreach ( TRTextileRegion region in blob . Textures )
420415 {
421- foreach ( int oldIndex in globalRemap [ region . ID ] . Keys )
422- {
423- remap [ oldIndex ] = globalRemap [ region . ID ] [ oldIndex ] ;
424- }
416+ continue ;
425417 }
426418
427- List < TRMesh > meshes = new ( ) ;
428- if ( blob . Model != null )
419+ if ( blob . Type == TRBlobType . Sprite )
429420 {
430- meshes . AddRange ( blob . Model . Meshes ) ;
421+ MapSpriteTextures ( blob , texturePositions ) ;
431422 }
432- if ( blob . StaticMesh != null )
423+ else
433424 {
434- meshes . Add ( blob . StaticMesh . Mesh ) ;
425+ MapObjectTextures ( blob , globalRemap , texturePositions ) ;
435426 }
427+ }
436428
437- IEnumerable < TRMeshFace > faces = meshes
438- . Where ( m => m != null )
439- . SelectMany ( m => m . TexturedFaces ) ;
440- foreach ( TRMeshFace face in faces )
441- {
442- face . Texture = ( ushort ) remap [ face . Texture ] ;
443- }
429+ TextureMonitor ? . OnTexturesPositioned ( texturePositions ) ;
430+ }
444431
445- faces = meshes
446- . Where ( m => m != null )
447- . SelectMany ( m => m . ColouredFaces ) ;
448- foreach ( TRMeshFace face in faces )
432+ private static void MapSpriteTextures ( B blob , Dictionary < T , List < PositionedTexture > > texturePositions )
433+ {
434+ texturePositions [ blob . Alias ] = [ ] ;
435+ foreach ( var segment in blob . Textures . SelectMany ( t => t . Segments ) )
436+ {
437+ texturePositions [ blob . Alias ] . Add ( new ( )
449438 {
450- face . Texture = ImportColour ( blob , face . Texture ) ;
451- }
439+ OriginalIndex = segment . Index ,
440+ TileIndex = segment . Atlas ,
441+ Position = segment . Position ,
442+ } ) ;
443+ }
444+ }
452445
453- texturePositions [ blob . Alias ] = new ( ) ;
454- foreach ( var ( oldIndex , newIndex ) in remap )
446+ private void MapObjectTextures ( B blob , Dictionary < string , Dictionary < int , int > > globalRemap ,
447+ Dictionary < T , List < PositionedTexture > > texturePositions )
448+ {
449+ var remap = new Dictionary < int , int > ( ) ;
450+ foreach ( var region in blob . Textures )
451+ {
452+ foreach ( int oldIndex in globalRemap [ region . ID ] . Keys )
455453 {
456- TRObjectTexture texture = Level . ObjectTextures [ newIndex ] ;
457- texturePositions [ blob . Alias ] . Add ( new ( )
458- {
459- OriginalIndex = oldIndex ,
460- TileIndex = texture . Atlas ,
461- Position = texture . Position
462- } ) ;
454+ remap [ oldIndex ] = globalRemap [ region . ID ] [ oldIndex ] ;
463455 }
464456 }
465457
466- TextureMonitor ? . OnTexturesPositioned ( texturePositions ) ;
458+ var meshes = new List < TRMesh > ( ) ;
459+ if ( blob . Model != null )
460+ {
461+ meshes . AddRange ( blob . Model . Meshes ) ;
462+ }
463+ if ( blob . StaticMesh != null )
464+ {
465+ meshes . Add ( blob . StaticMesh . Mesh ) ;
466+ }
467+
468+ var faces = meshes
469+ . Where ( m => m != null )
470+ . SelectMany ( m => m . TexturedFaces ) ;
471+ foreach ( var face in faces )
472+ {
473+ face . Texture = ( ushort ) remap [ face . Texture ] ;
474+ }
475+
476+ faces = meshes
477+ . Where ( m => m != null )
478+ . SelectMany ( m => m . ColouredFaces ) ;
479+ foreach ( var face in faces )
480+ {
481+ face . Texture = ImportColour ( blob , face . Texture ) ;
482+ }
483+
484+ texturePositions [ blob . Alias ] = [ ] ;
485+ foreach ( var ( oldIndex , newIndex ) in remap )
486+ {
487+ var texture = Level . ObjectTextures [ newIndex ] ;
488+ texturePositions [ blob . Alias ] . Add ( new ( )
489+ {
490+ OriginalIndex = oldIndex ,
491+ TileIndex = texture . Atlas ,
492+ Position = texture . Position ,
493+ } ) ;
494+ }
467495 }
468496
469497 protected void ImportData ( List < B > blobs , TRMesh oldDummyMesh )
0 commit comments