mirror of
				https://gitgud.io/AbstractConcept/rimworld-animations-patch.git
				synced 2024-08-15 00:43:27 +00:00 
			
		
		
		
	v2.0.2
- Implemented texture caching to reduce the performance hit induced by dynamically cropping apparel - Dynamically cropping apparel is now compatible with Sized Apparel
This commit is contained in:
		
							parent
							
								
									767317773b
								
							
						
					
					
						commit
						9144029fec
					
				
					 15 changed files with 108 additions and 25 deletions
				
			
		
							
								
								
									
										57
									
								
								Source/Scripts/Defs/ApparelTexture2DPack.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								Source/Scripts/Defs/ApparelTexture2DPack.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,57 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Verse;
 | 
			
		||||
using RimWorld;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
 | 
			
		||||
namespace Rimworld_Animations_Patch
 | 
			
		||||
{
 | 
			
		||||
    public class ApparelTexture2DPack
 | 
			
		||||
    {
 | 
			
		||||
        public List<Texture2D> textures = new List<Texture2D>();
 | 
			
		||||
 | 
			
		||||
        private static Dictionary<string, ApparelTexture2DPack> cachedMaskTextures = new Dictionary<string, ApparelTexture2DPack>();
 | 
			
		||||
 | 
			
		||||
        public static ApparelTexture2DPack PackMaskTextures(string path)
 | 
			
		||||
        {
 | 
			
		||||
            ApparelTexture2DPack pack = new ApparelTexture2DPack();
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < 3; i++)
 | 
			
		||||
            {
 | 
			
		||||
                string direction = new Rot4(i).ToStringWord().ToLower();
 | 
			
		||||
                Texture2D maskTexture = ContentFinder<Texture2D>.Get(path + "_" + direction, true);
 | 
			
		||||
 | 
			
		||||
                pack.textures.Add(maskTexture);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return pack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static ApparelTexture2DPack GetCachedMaskTexturesForBodyType(BodyTypeDef bodyType)
 | 
			
		||||
        {
 | 
			
		||||
            string path = "Masks/apparel_shirt_mask_" + bodyType.defName;
 | 
			
		||||
 | 
			
		||||
            if (cachedMaskTextures.TryGetValue(path, out ApparelTexture2DPack pack) == false)
 | 
			
		||||
            { pack = PackMaskTextures(path); }
 | 
			
		||||
 | 
			
		||||
            return pack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void PackTexturesForBodyType(Graphic graphic, BodyTypeDef bodyType)
 | 
			
		||||
        {
 | 
			
		||||
            textures.Clear();
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < 3; i++)
 | 
			
		||||
            {
 | 
			
		||||
                Texture2D origTexture = (Texture2D)graphic.MatAt(new Rot4(i)).mainTexture;
 | 
			
		||||
                Texture2D maskTexture = GetCachedMaskTexturesForBodyType(bodyType).textures[i];
 | 
			
		||||
                Texture2D maskedTexture = GraphicMaskingUtility.ApplyMaskToTexture2D(origTexture, maskTexture, true);
 | 
			
		||||
 | 
			
		||||
                textures.Add(maskedTexture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue