├── .gitattributes ├── .gitignore ├── ActiveTextureManagement.sln ├── ActiveTextureManagement ├── ActiveTextureManagement.cs ├── ActiveTextureManagement.csproj ├── CacheController.cs ├── ColorExtensions.cs ├── DatabaseLoaderTexture_ATM.cs ├── Properties │ └── AssemblyInfo.cs ├── TextureConverter.cs └── TextureInfoWrapper.cs ├── Content ├── aggressive │ └── GameData │ │ └── ActiveTextureManagement │ │ └── ActiveTextureManagerConfig.cfg ├── basic │ └── GameData │ │ └── ActiveTextureManagement │ │ └── ActiveTextureManagerConfig.cfg └── common │ └── GameData │ └── ActiveTextureManagement │ ├── ActiveTextureManagerConfigs │ ├── 000_Toolbar.cfg │ ├── AIES_Aerospace.cfg │ ├── ASET.cfg │ ├── AlchemyTechnologies.cfg │ ├── AmericanPack.cfg │ ├── B9_Aerospace.cfg │ ├── BahaSP.cfg │ ├── BahamutoD.cfg │ ├── BetterTimeWarp.cfg │ ├── BobCatind.cfg │ ├── BoulderCo.cfg │ ├── BoxSat alpha.cfg │ ├── Chatterer.cfg │ ├── CleverWalrus.cfg │ ├── DMagic Orbital Science.cfg │ ├── DeadlyReentry.cfg │ ├── DiazoHorizVert.cfg │ ├── ExtraplanetaryLaunchpads.cfg │ ├── FASA.cfg │ ├── FASA_Asteroids.cfg │ ├── FerramAerospaceResearch.cfg │ ├── FilterExtensions.cfg │ ├── Firespitter.cfg │ ├── Goodspeed.cfg │ ├── Green Skull Inc.cfg │ ├── HexCans.cfg │ ├── HooliganLabs.cfg │ ├── HorizonAeronautics.cfg │ ├── HullCameraVDS.cfg │ ├── ISS_Comunity.cfg │ ├── JSI.cfg │ ├── KAS.cfg │ ├── KSO.cfg │ ├── KSPX.cfg │ ├── KWRocketry.cfg │ ├── KerbalEngineer.cfg │ ├── Kethane.cfg │ ├── KipEng.cfg │ ├── LLL-Extra.cfg │ ├── LLL.cfg │ ├── LTech.cfg │ ├── LazTek.cfg │ ├── License.txt │ ├── LifeSupport.cfg │ ├── Lovad.cfg │ ├── MagicSmokeIndustries.cfg │ ├── MarkIVSystem.cfg │ ├── MechJeb2.cfg │ ├── ModsByTal.cfg │ ├── NASAmission.cfg │ ├── NavHud.cfg │ ├── NavyFishDPAI.cfg │ ├── NearFutureTechnologies.cfg │ ├── NehemiahInc.cfg │ ├── Nereid.cfg │ ├── NothkeSerCom.cfg │ ├── NovaPunch2.cfg │ ├── PlanetShine.cfg │ ├── PorkWorks.cfg │ ├── ProceduralFairings.cfg │ ├── ProceduralParts.cfg │ ├── R&SCapsuledyne.cfg │ ├── RCSBuildAid.cfg │ ├── RavienCritTempGauge.cfg │ ├── RealChute.cfg │ ├── SCANsat.cfg │ ├── SXT.cfg │ ├── Sentinel.cfg │ ├── ShipManifest.cfg │ ├── Squad.cfg │ ├── StationPartsExpansion │ ├── StationScience.cfg │ ├── StretchyTanks.cfg │ ├── SwitchVessel.cfg │ ├── TSAS.cfg │ ├── ThunderAerospaceTACLS.cfg │ ├── TreeLoader.cfg │ ├── TriggerTech.cfg │ ├── UmbraSpaceIndustries.cfg │ ├── WarpPlugin.cfg │ ├── WaypointManager.cfg │ ├── WildBlueIndustries │ ├── WombatConversions.cfg │ ├── WorldCup2014.cfg │ ├── ZWheel.cfg │ ├── blackheart.cfg │ ├── kOS.cfg │ ├── masTerTorch.cfg │ └── nothke_DROMOMAN.cfg │ └── License.txt ├── KSPResources ├── readme.txt ├── x64 │ └── Drop Assembly-CSharp.dll and UnityEngine.dll here.txt └── x86 │ └── Drop Assembly-CSharp.dll and UnityEngine.dll here.txt ├── LibSquishPort ├── LibSquishPort.csproj ├── Properties │ └── AssemblyInfo.cs ├── Squish.cs ├── alpha.cs ├── clusterfit.cs ├── colorblock.cs ├── colorfit.cs ├── colourset.cs ├── math.cs ├── rangefit.cs └── singlecolourfit.cs ├── NvidiaTextureTools ├── Color16.cs ├── ColorBlock.cs ├── DXT.cs ├── Fitting.cs ├── NvidiaTextureTools.csproj ├── OptimalCompress.cs ├── Properties │ └── AssemblyInfo.cs ├── QuickCompress.cs ├── Tex2dxt.cs └── TextureTools.cs ├── README.md ├── x64-Aggressive-Release.zip ├── x64-Basic-Release.zip ├── x86-Aggressive-Release.zip └── x86-Basic-Release.zip /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | 217 | *.dll 218 | 219 | pack -------------------------------------------------------------------------------- /ActiveTextureManagement.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Windows Desktop 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActiveTextureManagement", "ActiveTextureManagement\ActiveTextureManagement.csproj", "{838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibSquishPort", "LibSquishPort\LibSquishPort.csproj", "{6EAA2286-2B54-4445-B553-78B67F497BA9}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671} = {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671} 11 | EndProjectSection 12 | EndProject 13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NvidiaTextureTools", "NvidiaTextureTools\NvidiaTextureTools.csproj", "{CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}" 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Debug|Mixed Platforms = Debug|Mixed Platforms 19 | Debug|x64 = Debug|x64 20 | Debug|x86 = Debug|x86 21 | Release|Any CPU = Release|Any CPU 22 | Release|Mixed Platforms = Release|Mixed Platforms 23 | Release|x64 = Release|x64 24 | Release|x86 = Release|x86 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 30 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|Mixed Platforms.Build.0 = Debug|x86 31 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|x64.ActiveCfg = Debug|x64 32 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|x64.Build.0 = Debug|x64 33 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|x86.ActiveCfg = Debug|x86 34 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Debug|x86.Build.0 = Debug|x86 35 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|Mixed Platforms.ActiveCfg = Release|x86 38 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|Mixed Platforms.Build.0 = Release|x86 39 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|x64.ActiveCfg = Release|x64 40 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|x64.Build.0 = Release|x64 41 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|x86.ActiveCfg = Release|x86 42 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD}.Release|x86.Build.0 = Release|x86 43 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 46 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 47 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|x64.ActiveCfg = Debug|x64 48 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|x64.Build.0 = Debug|x64 49 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|x86.ActiveCfg = Debug|x86 50 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Debug|x86.Build.0 = Debug|x86 51 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Release|Any CPU.ActiveCfg = Release|Any CPU 52 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Release|Any CPU.Build.0 = Release|Any CPU 53 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 54 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Release|Mixed Platforms.Build.0 = Release|Any CPU 55 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Release|x64.ActiveCfg = Release|Any CPU 56 | {6EAA2286-2B54-4445-B553-78B67F497BA9}.Release|x86.ActiveCfg = Release|Any CPU 57 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 58 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|Any CPU.Build.0 = Debug|Any CPU 59 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 60 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 61 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|x64.ActiveCfg = Debug|x64 62 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|x64.Build.0 = Debug|x64 63 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|x86.ActiveCfg = Debug|x86 64 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Debug|x86.Build.0 = Debug|x86 65 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Release|Any CPU.ActiveCfg = Release|Any CPU 66 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Release|Any CPU.Build.0 = Release|Any CPU 67 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 68 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Release|Mixed Platforms.Build.0 = Release|Any CPU 69 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Release|x64.ActiveCfg = Release|Any CPU 70 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671}.Release|x86.ActiveCfg = Release|Any CPU 71 | EndGlobalSection 72 | GlobalSection(SolutionProperties) = preSolution 73 | HideSolutionNode = FALSE 74 | EndGlobalSection 75 | EndGlobal 76 | -------------------------------------------------------------------------------- /ActiveTextureManagement/ActiveTextureManagement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using UnityEngine; 10 | 11 | namespace ActiveTextureManagement 12 | { 13 | public class TexInfo 14 | { 15 | public UrlDir.UrlFile file; 16 | public string name; 17 | public int width; 18 | public int height; 19 | public int resizeWidth; 20 | public int resizeHeight; 21 | public string filename; 22 | public TextureInfoWrapper texture; 23 | 24 | public int scale; 25 | public int maxSize; 26 | public int minSize; 27 | public bool isNormalMap; 28 | 29 | public bool loadOriginalFirst; 30 | public bool needsResize; 31 | public bool makeNotReadable; 32 | 33 | public TexInfo(UrlDir.UrlFile file) 34 | { 35 | this.file = file; 36 | this.name = file.url; 37 | this.isNormalMap = DatabaseLoaderTexture_ATM.IsNormal(name); 38 | this.width = 1; 39 | this.height = 1; 40 | loadOriginalFirst = false; 41 | needsResize = false; 42 | makeNotReadable = true; 43 | } 44 | 45 | public void SetScalingParams(int scale, int maxSize, int minSize) 46 | { 47 | this.scale = scale; 48 | this.maxSize = maxSize; 49 | this.minSize = minSize; 50 | } 51 | 52 | public void Resize(int width, int height) 53 | { 54 | this.width = width; 55 | this.height = height; 56 | this.Resize(); 57 | } 58 | 59 | public void Resize() 60 | { 61 | resizeWidth = width / scale; 62 | resizeHeight = height / scale; 63 | 64 | int tmpScale = scale - 1; 65 | while (resizeWidth < minSize && tmpScale > 0) 66 | { 67 | resizeWidth = width / tmpScale--; 68 | } 69 | tmpScale = scale - 1; 70 | while (resizeHeight < minSize && tmpScale > 0) 71 | { 72 | resizeHeight = height / tmpScale--; 73 | } 74 | 75 | if (maxSize != 0) 76 | { 77 | if (resizeWidth > maxSize) 78 | { 79 | resizeWidth = maxSize; 80 | } 81 | if (resizeHeight > maxSize) 82 | { 83 | resizeHeight = maxSize; 84 | } 85 | } 86 | 87 | needsResize = (resizeHeight != height || resizeWidth != width); 88 | } 89 | } 90 | 91 | [KSPAddon(KSPAddon.Startup.EveryScene, false)] 92 | public class ActiveTextureManagement : MonoBehaviour 93 | { 94 | static bool Compressed = false; 95 | static int LastTextureIndex = -1; 96 | static int gcCount = 0; 97 | static long memorySaved = 0; 98 | public static bool DBL_LOG = false; 99 | 100 | const int GC_COUNT_TRIGGER = 20; 101 | 102 | 103 | static Dictionary folderBytesSaved = new Dictionary(); 104 | 105 | static List foldersExList = new List(); 106 | 107 | protected void Start() 108 | { 109 | if (HighLogic.LoadedScene == GameScenes.LOADING) 110 | { 111 | DatabaseLoaderTexture_ATM.PopulateConfig(); 112 | SetupLoaders(); 113 | } 114 | else if (HighLogic.LoadedScene == GameScenes.MAINMENU && !Compressed) 115 | { 116 | Update(); 117 | Compressed = true; 118 | 119 | foreach(GameDatabase.TextureInfo Texture in GameDatabase.Instance.databaseTexture) 120 | { 121 | Texture2D texture = Texture.texture; 122 | Log("--------------------------------------------------------"); 123 | Log("Name: " + texture.name); 124 | Log("Format: " + texture.format.ToString()); 125 | Log("MipMaps: " + texture.mipmapCount.ToString()); 126 | Log("Size: " + texture.width.ToString() + "x" + texture.height); 127 | Log("Readable: " + Texture.isReadable); 128 | bool readable = true; 129 | try { Texture.texture.GetPixel(0, 0); } 130 | catch { readable = false; }; 131 | if (readable != Texture.isReadable) 132 | { ActiveTextureManagement.DBGLog("Readbility does not match!"); } 133 | } 134 | long bSaved = memorySaved; 135 | long kbSaved = (long)(bSaved / 1024f); 136 | long mbSaved = (long)(kbSaved / 1024f); 137 | Log("Memory Saved : " + bSaved.ToString() + "B"); 138 | Log("Memory Saved : " + kbSaved.ToString() + "kB"); 139 | Log("Memory Saved : " + mbSaved.ToString() + "MB"); 140 | 141 | TextureConverter.DestroyImageBuffer(); 142 | Resources.UnloadUnusedAssets(); 143 | System.GC.Collect(); 144 | } 145 | } 146 | 147 | private void SetupLoaders() 148 | { 149 | 150 | // Get the list where the Texture DatabaseLoader are stored 151 | Type gdType = typeof(GameDatabase); 152 | List> textureLoaders = 153 | (from fld in gdType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic) 154 | where fld.FieldType == typeof(List>) 155 | select (List>)fld.GetValue(GameDatabase.Instance)).FirstOrDefault(); 156 | 157 | foreach (var textureLoader in textureLoaders) 158 | { 159 | if (textureLoader.GetType().Name != "DatabaseLoaderTexture_ATM") 160 | { 161 | Log("Disabling " + textureLoader.GetType().Name); 162 | textureLoader.extensions.RemoveAll(i => DatabaseLoaderTexture_ATM.ExtensionList.Contains(i)); 163 | Log(textureLoader.GetType().Name + " now has extensions: " + String.Join(", ", textureLoader.extensions.ToArray())); 164 | } 165 | } 166 | } 167 | 168 | private GUISkin _mySkin; 169 | private Rect _mainWindowRect = new Rect(5, 5, 640, 240); 170 | static Vector2 ScrollFolderList = Vector2.zero; 171 | int selectedFolder = 0; 172 | int selectedMode = 0; 173 | bool guiEnabled = false; 174 | ConfigNode guiConfig = null; 175 | private void OnGUI() 176 | { 177 | GUI.skin = _mySkin; 178 | if (HighLogic.LoadedScene == GameScenes.MAINMENU && guiEnabled) 179 | { 180 | GUI.backgroundColor = new Color(0, 0, 0, 1); 181 | String memFormatString = "{0,7}kB {1,4}MB"; 182 | long bSaved = memorySaved; 183 | long kbSaved = (long)(bSaved / 1024f); 184 | long mbSaved = (long)(kbSaved / 1024f); 185 | String totalMemoryString = String.Format("Total Memory Saved: " + memFormatString, kbSaved, mbSaved); 186 | _mainWindowRect = GUI.Window(0x8100, _mainWindowRect, DrawMainWindow, totalMemoryString); 187 | 188 | } 189 | } 190 | 191 | private void DrawMainWindow(int windowID) 192 | { 193 | GUIStyle gs = new GUIStyle(GUI.skin.label); 194 | GUIStyle gsBox = new GUIStyle(GUI.skin.box); 195 | 196 | int itemFullWidth = (int)_mainWindowRect.width - 30; 197 | int itemHalfWidth = (int)_mainWindowRect.width/2 - 20; 198 | int itemQuarterWidth = (int)_mainWindowRect.width / 4 - 20; 199 | int itemMidStart = (int)_mainWindowRect.width - (15 + itemHalfWidth); 200 | int itemThirdWidth = (int)_mainWindowRect.width / 3 - 20; 201 | int itemTwoThirdStart = itemThirdWidth + 20; 202 | int itemTwoThirdWidth = (int)_mainWindowRect.width - (35+itemThirdWidth); 203 | int itemQuarterThirdWidth = itemHalfWidth + 5 - itemTwoThirdStart; 204 | 205 | GUI.Box(new Rect(0, 0, _mainWindowRect.width, _mainWindowRect.height), ""); 206 | 207 | GUI.Box(new Rect(10, 20, itemThirdWidth, 210), ""); 208 | String[] folderList = foldersExList.ToArray(); 209 | ScrollFolderList = GUI.BeginScrollView(new Rect(15, 25, itemThirdWidth - 10, 195), ScrollFolderList, new Rect(0, 0, itemThirdWidth - 30, 25 * folderList.Length)); 210 | float folderWidth = folderList.Length > 7 ? itemThirdWidth - 30 : itemThirdWidth - 10; 211 | selectedFolder = selectedFolder >= folderList.Length ? 0 : selectedFolder; 212 | int OldSelectedFolder = selectedFolder; 213 | selectedFolder = GUI.SelectionGrid(new Rect(0, 0, folderWidth, 25 * folderList.Length), selectedFolder, folderList, 1); 214 | GUI.EndScrollView(); 215 | 216 | String folder = folderList[selectedFolder]; 217 | 218 | 219 | String memFormatString = "{0,7}kB {1,4}MB"; 220 | long bSaved = folderBytesSaved[folderList[selectedFolder]]; 221 | long kbSaved = (long)(bSaved / 1024f); 222 | long mbSaved = (long)(kbSaved / 1024f); 223 | String memoryString = String.Format("Memory Saved: " + memFormatString, kbSaved, mbSaved); 224 | GUI.Label(new Rect(itemMidStart, 55, itemHalfWidth, 25), memoryString); 225 | 226 | String[] Modes = {"Normal List", "Overrides"}; 227 | //selectedMode = GUI.SelectionGrid(new Rect(itemTwoThirdStart, 25, itemQuarterThirdWidth, 25 * Modes.Length), selectedMode, Modes, 1); 228 | selectedMode = GUI.Toolbar(new Rect(itemMidStart, 25, itemHalfWidth, 25), selectedMode, Modes); 229 | if(selectedMode == 0) 230 | { 231 | GUI.Box(new Rect(itemTwoThirdStart, 85, itemTwoThirdWidth, 145), ""); 232 | 233 | } 234 | GUI.DragWindow(new Rect(0, 0, 10000, 10000)); 235 | 236 | } 237 | 238 | protected void Update() 239 | { 240 | if (HighLogic.LoadedScene == GameScenes.MAINMENU) 241 | { 242 | bool alt = (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)); 243 | if (alt && Input.GetKeyDown(KeyCode.M)) 244 | { 245 | guiEnabled = !guiEnabled; 246 | } 247 | } 248 | } 249 | 250 | 251 | private void updateMemoryCount(int originalWidth, int originalHeight, TextureFormat originalFormat, bool originalMipmaps, GameDatabase.TextureInfo Texture, String folder) 252 | { 253 | int saved = CacheController.MemorySaved(originalWidth, originalHeight, originalFormat, originalMipmaps, Texture); 254 | memorySaved += saved; 255 | 256 | if (!folderBytesSaved.ContainsKey(folder)) 257 | { 258 | folderBytesSaved.Add(folder, 0); 259 | } 260 | long folderSaved = folderBytesSaved[folder] + saved; 261 | folderBytesSaved[folder] = folderSaved; 262 | 263 | Log("Saved " + saved + "B"); 264 | Log("Accumulated Saved " + memorySaved + "B"); 265 | } 266 | 267 | public static void DBGLog(String message) 268 | { 269 | if (DBL_LOG) 270 | { 271 | UnityEngine.Debug.Log("ActiveTextureManagement: " + message); 272 | } 273 | } 274 | public static void Log(String message) 275 | { 276 | UnityEngine.Debug.Log("ActiveTextureManagement: " + message); 277 | } 278 | 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /ActiveTextureManagement/ActiveTextureManagement.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {838C3D0D-94A2-4D2A-9DDE-0C0D551309AD} 8 | Library 9 | Properties 10 | ActiveTextureManagement 11 | ActiveTextureManagement 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | true 35 | bin\x64\Debug\ 36 | DEBUG;TRACE 37 | full 38 | x64 39 | prompt 40 | ManagedMinimumRules.ruleset 41 | 42 | 43 | bin\x64\Release\ 44 | TRACE 45 | true 46 | pdbonly 47 | x64 48 | prompt 49 | ManagedMinimumRules.ruleset 50 | 51 | 52 | true 53 | bin\x86\Debug\ 54 | DEBUG;TRACE 55 | full 56 | x86 57 | prompt 58 | ManagedMinimumRules.ruleset 59 | 60 | 61 | bin\x86\Release\ 62 | TRACE 63 | true 64 | pdbonly 65 | x86 66 | prompt 67 | ManagedMinimumRules.ruleset 68 | 69 | 70 | 71 | False 72 | ..\KSPResources\Assembly-CSharp.dll 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | False 82 | ..\KSPResources\UnityEngine.dll 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | {6eaa2286-2b54-4445-b553-78b67f497ba9} 97 | LibSquishPort 98 | 99 | 100 | {ce10bc3f-c9a4-480a-9e67-fbaea76b2671} 101 | NvidiaTextureTools 102 | 103 | 104 | 105 | 106 | xcopy $(TargetFileName) "$(SolutionDir)Pack\GameData\ActiveTextureManagement\Plugins\" /e /y /i /r 107 | xcopy "$(SolutionDir)Content\aggressive\GameData\*" "$(SolutionDir)Pack\GameData\" /e /y /i /r 108 | xcopy "$(SolutionDir)Content\common\GameData\*" "$(SolutionDir)Pack\GameData" /e /y /i /r 109 | xcopy "$(SolutionDir)Pack\GameData\*" "C:\Users\Ryan\Documents\ksp\ksp-$(PlatformName)-1-0-2\GameData" /e /y /i /r 110 | 7za a -tzip "$(SolutionDir)$(PlatformName)-Aggressive-Release.zip" "$(SolutionDir)Pack\GameData" 111 | xcopy "$(SolutionDir)Content\basic\GameData\*" "$(SolutionDir)Pack\GameData" /e /y /i /r 112 | 7za a -tzip "$(SolutionDir)$(PlatformName)-Basic-Release.zip" "$(SolutionDir)Pack\GameData" 113 | 114 | 115 | copy /Y "$(SolutionDir)KSPResources\$(PlatformName)\*.dll" "$(SolutionDir)KSPResources" 116 | 117 | 124 | -------------------------------------------------------------------------------- /ActiveTextureManagement/CacheController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Security.Cryptography; 6 | using System.Text; 7 | using UnityEngine; 8 | 9 | namespace ActiveTextureManagement 10 | { 11 | 12 | class CacheController 13 | { 14 | static String MD5String = ""; 15 | static String LastFile = ""; 16 | static Dictionary TextureHashTable = new Dictionary(); 17 | static String[] Extensions = { ".png", ".tga", ".mbm", ".jpg", ".jpeg", ".truecolor" }; 18 | 19 | public static TextureInfoWrapper FetchCacheTexture(TexInfo Texture, bool compress, bool mipmaps) 20 | { 21 | String textureName = Texture.name; 22 | String originalTextureFile = KSPUtil.ApplicationRootPath + "GameData/" + textureName; 23 | String cacheFile = KSPUtil.ApplicationRootPath + "GameData/ActiveTextureManagement/textureCache/" + textureName; 24 | String cacheConfigFile = cacheFile + ".tcache"; 25 | cacheFile += ".imgcache"; 26 | 27 | String hashString = GetMD5String(originalTextureFile); 28 | if (TextureHashTable.ContainsKey(hashString)) 29 | { 30 | ActiveTextureManagement.DBGLog("hash triggered... " + textureName); 31 | TextureInfoWrapper tex = TextureHashTable[hashString]; 32 | if (tex.name != textureName) 33 | { 34 | TextureInfoWrapper cacheTexInfo = new TextureInfoWrapper(Texture.file, tex.texture, tex.isNormalMap, tex.isReadable, tex.isCompressed); 35 | cacheTexInfo.name = textureName; 36 | ActiveTextureManagement.DBGLog("Re-using from hash dictionary... " + textureName+" is a duplicate of "+tex.name); 37 | 38 | return cacheTexInfo; 39 | } 40 | } 41 | 42 | if (File.Exists(cacheConfigFile)) 43 | { 44 | ConfigNode config = ConfigNode.Load(cacheConfigFile); 45 | string format = config.GetValue("orig_format"); 46 | String cacheHash = config.GetValue("md5"); 47 | int origWidth, origHeight; 48 | string origWidthString = config.GetValue("orig_width"); 49 | string origHeightString = config.GetValue("orig_height"); 50 | int.TryParse(origWidthString, out origWidth); 51 | int.TryParse(origHeightString, out origHeight); 52 | 53 | 54 | if (origWidthString == null || origHeightString == null || 55 | cacheHash == null || format == null) 56 | { 57 | return RebuildCache(Texture, compress, mipmaps, hashString ); 58 | } 59 | 60 | 61 | originalTextureFile += format; 62 | Texture.Resize(origWidth, origHeight); 63 | 64 | if (format != null && File.Exists(originalTextureFile) && File.Exists(cacheFile)) 65 | { 66 | 67 | String cacheIsNormString = config.GetValue("is_normal"); 68 | String cacheIsCompressed = config.GetValue("is_compressed"); 69 | String cacheWidthString = config.GetValue("width"); 70 | String cacheHeihtString = config.GetValue("height"); 71 | string hasAlphaString = config.GetValue("hasAlpha"); 72 | string hasMipmapsString = config.GetValue("hasMipmaps"); 73 | bool cacheIsNorm = false; 74 | int cacheWidth = 0; 75 | int cacheHeight = 0; 76 | bool hasAlpha = true; 77 | bool hasMipmaps = true; 78 | bool isCompressed = true; 79 | bool.TryParse(cacheIsNormString, out cacheIsNorm); 80 | bool.TryParse(cacheIsCompressed, out isCompressed); 81 | int.TryParse(cacheWidthString, out cacheWidth); 82 | int.TryParse(cacheHeihtString, out cacheHeight); 83 | bool.TryParse(hasAlphaString, out hasAlpha); 84 | bool.TryParse(hasMipmapsString, out hasMipmaps); 85 | 86 | if (cacheHash != hashString || compress != isCompressed || mipmaps != hasMipmaps || cacheIsNorm != Texture.isNormalMap || Texture.resizeWidth != cacheWidth || Texture.resizeHeight != cacheHeight) 87 | { 88 | if (cacheHash != hashString) 89 | { 90 | ActiveTextureManagement.DBGLog(cacheHash + " != " + hashString); 91 | } 92 | if (cacheIsNorm != Texture.isNormalMap) 93 | { 94 | ActiveTextureManagement.DBGLog(cacheIsNorm + " != " + Texture.isNormalMap); 95 | } 96 | if (Texture.resizeWidth != cacheWidth) 97 | { 98 | ActiveTextureManagement.DBGLog(Texture.resizeWidth + " != " + cacheWidth); 99 | } 100 | if (Texture.resizeHeight != cacheHeight) 101 | { 102 | ActiveTextureManagement.DBGLog(Texture.resizeHeight + " != " + cacheHeight); 103 | } 104 | return RebuildCache(Texture, compress, mipmaps, hashString); 105 | } 106 | else 107 | { 108 | ActiveTextureManagement.DBGLog("Loading from cache... " + textureName); 109 | Texture.needsResize = false; 110 | Texture.width = Texture.resizeWidth; 111 | Texture.height = Texture.resizeHeight; 112 | Texture.filename = cacheFile; 113 | TextureInfoWrapper tex = TextureConverter.DDSToTexture(Texture.file, Texture, hasMipmaps, isCompressed, hasAlpha); 114 | if (TextureHashTable.ContainsKey(hashString)) 115 | { 116 | TextureHashTable[hashString] = tex; 117 | } 118 | else 119 | { 120 | TextureHashTable.Add(hashString, tex); 121 | } 122 | 123 | return tex; 124 | } 125 | } 126 | else 127 | { 128 | return RebuildCache(Texture, compress, mipmaps, hashString); 129 | } 130 | } 131 | else 132 | { 133 | return RebuildCache(Texture, compress, mipmaps, hashString); 134 | } 135 | 136 | } 137 | 138 | private static TextureInfoWrapper RebuildCache(TexInfo Texture, bool compress, bool mipmaps, string hashString) 139 | { 140 | Texture.loadOriginalFirst = true; 141 | ActiveTextureManagement.DBGLog("Loading texture..."); 142 | TextureConverter.GetReadable(Texture, mipmaps); 143 | ActiveTextureManagement.DBGLog("Texture loaded."); 144 | 145 | TextureInfoWrapper cacheTexture = Texture.texture; 146 | Texture2D tex = cacheTexture.texture; 147 | 148 | String textureName = cacheTexture.name; 149 | String cacheFile = KSPUtil.ApplicationRootPath + "GameData/ActiveTextureManagement/textureCache/" + textureName; 150 | 151 | ActiveTextureManagement.DBGLog("Rebuilding Cache... " + Texture.name); 152 | 153 | ActiveTextureManagement.DBGLog("Saving cache file " + cacheFile + ".imgcache"); 154 | 155 | Color32[] colors = tex.GetPixels32(); 156 | bool hasAlpha =TextureConverter.WriteTo(tex, cacheFile + ".imgcache", compress); 157 | 158 | String originalTextureFile = Texture.filename; 159 | String cacheConfigFile = cacheFile + ".tcache"; 160 | ActiveTextureManagement.DBGLog("Created Config for" + originalTextureFile); 161 | 162 | 163 | ConfigNode config = new ConfigNode(); 164 | config.AddValue("md5", hashString); ActiveTextureManagement.DBGLog("md5: " + hashString); 165 | config.AddValue("orig_format", Path.GetExtension(originalTextureFile)); ActiveTextureManagement.DBGLog("orig_format: " + Path.GetExtension(originalTextureFile)); 166 | config.AddValue("orig_width", Texture.width.ToString()); ActiveTextureManagement.DBGLog("orig_width: " + Texture.width.ToString()); 167 | config.AddValue("orig_height", Texture.height.ToString()); ActiveTextureManagement.DBGLog("orig_height: " + Texture.height.ToString()); 168 | config.AddValue("is_normal", cacheTexture.isNormalMap.ToString()); ActiveTextureManagement.DBGLog("is_normal: " + cacheTexture.isNormalMap.ToString()); 169 | config.AddValue("is_compressed", compress); ActiveTextureManagement.DBGLog("is_compressed: " + compress); 170 | config.AddValue("width", Texture.resizeWidth.ToString()); ActiveTextureManagement.DBGLog("width: " + Texture.resizeWidth.ToString()); 171 | config.AddValue("height", Texture.resizeHeight.ToString()); ActiveTextureManagement.DBGLog("height: " + Texture.resizeHeight.ToString()); 172 | config.AddValue("hasAlpha", hasAlpha); ActiveTextureManagement.DBGLog("hasAlpha: " + hasAlpha.ToString()); 173 | config.AddValue("hasMipmaps", mipmaps); ActiveTextureManagement.DBGLog("hasMipmaps: " + hasAlpha.ToString()); 174 | config.Save(cacheConfigFile); 175 | ActiveTextureManagement.DBGLog("Saved Config."); 176 | 177 | if (compress) 178 | { 179 | tex.Compress(true); 180 | } 181 | cacheTexture.isCompressed = compress; 182 | tex.Apply(false, Texture.makeNotReadable); 183 | 184 | cacheTexture.isReadable = !Texture.makeNotReadable; 185 | 186 | return cacheTexture; 187 | } 188 | 189 | static String GetMD5String(String file) 190 | { 191 | if(file == LastFile) 192 | { 193 | return MD5String; 194 | } 195 | MD5String = null; 196 | foreach (String extension in Extensions) 197 | { 198 | if (File.Exists(file + extension)) 199 | { 200 | FileStream stream = File.OpenRead(file + extension); 201 | MD5 md5 = MD5.Create(); 202 | byte[] hash = md5.ComputeHash(stream); 203 | stream.Close(); 204 | MD5String = BitConverter.ToString(hash); 205 | LastFile = file; 206 | return MD5String; 207 | } 208 | } 209 | return MD5String; 210 | } 211 | 212 | public static int MemorySaved(int originalWidth, int originalHeight, TextureFormat originalFormat, bool originalMipmaps, GameDatabase.TextureInfo Texture) 213 | { 214 | int width = Texture.texture.width; 215 | int height = Texture.texture.height; 216 | TextureFormat format = Texture.texture.format; 217 | bool mipmaps = Texture.texture.mipmapCount == 1 ? false : true; 218 | ActiveTextureManagement.DBGLog("Texture: " + Texture.name); 219 | ActiveTextureManagement.DBGLog("is normalmap: " + Texture.isNormalMap); 220 | Texture2D tex = Texture.texture; 221 | ActiveTextureManagement.DBGLog("originalWidth: " + originalWidth); 222 | ActiveTextureManagement.DBGLog("originalHeight: " + originalHeight); 223 | ActiveTextureManagement.DBGLog("originalFormat: " + originalFormat); 224 | ActiveTextureManagement.DBGLog("originalMipmaps: " + originalMipmaps); 225 | ActiveTextureManagement.DBGLog("width: " + width); 226 | ActiveTextureManagement.DBGLog("height: " + height); 227 | ActiveTextureManagement.DBGLog("format: " + format); 228 | ActiveTextureManagement.DBGLog("mipmaps: " + mipmaps); 229 | bool readable = true; 230 | try { tex.GetPixel(0, 0); } 231 | catch { readable = false; }; 232 | ActiveTextureManagement.DBGLog("readable: " + readable); 233 | if (readable != Texture.isReadable) 234 | { ActiveTextureManagement.DBGLog("Readbility does not match!"); } 235 | int oldSize = 0; 236 | int newSize = 0; 237 | switch (originalFormat) 238 | { 239 | case TextureFormat.ARGB32: 240 | case TextureFormat.RGBA32: 241 | case TextureFormat.BGRA32: 242 | oldSize = 4 * (originalWidth * originalHeight); 243 | break; 244 | case TextureFormat.RGB24: 245 | oldSize = 3 * (originalWidth * originalHeight); 246 | break; 247 | case TextureFormat.Alpha8: 248 | oldSize = originalWidth * originalHeight; 249 | break; 250 | case TextureFormat.DXT1: 251 | oldSize = (originalWidth * originalHeight) / 2; 252 | break; 253 | case TextureFormat.DXT5: 254 | oldSize = originalWidth * originalHeight; 255 | break; 256 | } 257 | switch (format) 258 | { 259 | case TextureFormat.ARGB32: 260 | case TextureFormat.RGBA32: 261 | case TextureFormat.BGRA32: 262 | newSize = 4 * (width * height); 263 | break; 264 | case TextureFormat.RGB24: 265 | newSize = 3 * (width * height); 266 | break; 267 | case TextureFormat.Alpha8: 268 | newSize = width * height; 269 | break; 270 | case TextureFormat.DXT1: 271 | newSize = (width * height) / 2; 272 | break; 273 | case TextureFormat.DXT5: 274 | newSize = width * height; 275 | break; 276 | } 277 | if (originalMipmaps) 278 | { 279 | oldSize += (int)(oldSize * .33f); 280 | } 281 | if (mipmaps) 282 | { 283 | newSize += (int)(newSize * .33f); 284 | } 285 | return (oldSize - newSize); 286 | } 287 | 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /ActiveTextureManagement/ColorExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Runtime.InteropServices; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace ActiveTextureManagement 8 | { 9 | 10 | public static class ColorExtensions 11 | { 12 | public static uint u(this Color32 color) 13 | { 14 | return (uint)(color.r | (color.g << 8) | (color.b << 16) | (color.a << 24)); 15 | } 16 | 17 | public static byte[] component(this Color32 color) 18 | { 19 | return new byte[4] { color.b, color.g, color.r, color.a }; 20 | } 21 | 22 | public static byte[] bytes(this Texture2D texture, int mipmapLevel, bool hasAlpha = true) 23 | { 24 | Color32[] colors = texture.GetPixels32(mipmapLevel); 25 | byte[] array; 26 | if (hasAlpha) 27 | { 28 | array = new byte[colors.Length * 4]; 29 | for (int i = 0; i < colors.Length; i++) 30 | { 31 | array[(i * 4)] = colors[i].r; 32 | array[(i * 4) + 1] = colors[i].g; 33 | array[(i * 4) + 2] = colors[i].b; 34 | array[(i * 4) + 3] = colors[i].a; 35 | } 36 | } 37 | else 38 | { 39 | array = new byte[colors.Length * 3]; 40 | for (int i = 0; i < colors.Length; i++) 41 | { 42 | array[(i * 3)] = colors[i].r; 43 | array[(i * 3) + 1] = colors[i].g; 44 | array[(i * 3) + 2] = colors[i].b; 45 | } 46 | } 47 | return array; 48 | } 49 | } 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ActiveTextureManagement/DatabaseLoaderTexture_ATM.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using UnityEngine; 9 | 10 | namespace ActiveTextureManagement 11 | { 12 | 13 | 14 | 15 | [DatabaseLoaderAttrib(new string[] { "mbm", "png", "tga", "jpg", "jpeg", "truecolor" })] 16 | public class DatabaseLoaderTexture_ATM : DatabaseLoader 17 | { 18 | public static List ExtensionList = new List( new String[]{"png", "tga", "mbm", "jpg", "jpeg", "truecolor"}); 19 | 20 | static ConfigNode config; 21 | static ConfigNode overrides; 22 | static List overridesList = new List(); 23 | static List foldersList = new List(); 24 | static List readableList = new List(); 25 | static List normalList = new List(); 26 | 27 | static bool config_mipmaps = false; 28 | static bool config_compress = true; 29 | static int config_scale = 1; 30 | static int config_max_size = 0; 31 | static int config_min_size = 128; 32 | static bool config_mipmaps_normals = false; 33 | static bool config_compress_normals = true; 34 | static int config_scale_normals = 1; 35 | static int config_max_size_normals = 0; 36 | static int config_min_size_normals = 128; 37 | static FilterMode config_filter_mode = FilterMode.Bilinear; 38 | static bool config_make_not_readable = false; 39 | static bool useSquish = true; 40 | static bool waitOnDone = false; 41 | 42 | public static bool UseSquish { get { return useSquish; } } 43 | public static bool WaitOnDone { get { return waitOnDone; } } 44 | 45 | public static void PopulateConfig() 46 | { 47 | if (config == null) 48 | { 49 | config = GameDatabase.Instance.GetConfigNodes("ACTIVE_TEXTURE_MANAGER")[0]; 50 | String dbg = config.GetValue("DBG"); 51 | if (dbg != null) 52 | { 53 | ActiveTextureManagement.DBL_LOG = true; 54 | } 55 | String useNvidia = config.GetValue("USE_NVIDIA"); 56 | if (useNvidia != null) 57 | { 58 | useSquish = false; 59 | } 60 | 61 | String wait = config.GetValue("WAIT"); 62 | if (wait != null) 63 | { 64 | waitOnDone = true; 65 | } 66 | overrides = config.GetNode("OVERRIDES"); 67 | ConfigNode folders = config.GetNode("FOLDERS"); 68 | ConfigNode normals = config.GetNode("NORMAL_LIST"); 69 | 70 | if (overrides == null) 71 | { 72 | overrides = new ConfigNode("OVERRIDES"); 73 | } 74 | if (folders == null) 75 | { 76 | folders = new ConfigNode("FOLDERS"); 77 | } 78 | if (normals == null) 79 | { 80 | normals = new ConfigNode("NORMAL_LIST"); 81 | } 82 | 83 | foreach (ConfigNode configFolder in GameDatabase.Instance.GetConfigNodes("ACTIVE_TEXTURE_MANAGER_CONFIG")) 84 | { 85 | String enabledString = configFolder.GetValue("enabled"); 86 | String folder = configFolder.GetValue("folder"); 87 | bool isEnabled = false; 88 | if (enabledString != null) 89 | { 90 | bool.TryParse(enabledString, out isEnabled); 91 | } 92 | DBGLog("folder: " + folder); 93 | DBGLog("enabled: " + isEnabled); 94 | if (isEnabled) 95 | { 96 | folders.AddValue("folder", folder); 97 | ConfigNode modOverrides = configFolder.GetNode("OVERRIDES"); 98 | ConfigNode modNormals = configFolder.GetNode("NORMAL_LIST"); 99 | CopyConfigNode(modOverrides, overrides); 100 | CopyConfigNode(modNormals, normals); 101 | } 102 | } 103 | 104 | foreach (ConfigNode node in overrides.nodes) 105 | { 106 | overridesList.Add(node.name); 107 | } 108 | foreach (ConfigNode.Value folder in folders.values) 109 | { 110 | foldersList.Add(folder.value); 111 | } 112 | foreach (ConfigNode.Value texture in normals.values) 113 | { 114 | normalList.Add(texture.value); 115 | } 116 | 117 | String mipmapsString = config.GetValue("mipmaps"); 118 | String compressString = config.GetValue("compress"); 119 | String scaleString = config.GetValue("scale"); 120 | String max_sizeString = config.GetValue("max_size"); 121 | String min_sizeString = config.GetValue("min_size"); 122 | String filter_modeString = config.GetValue("filter_mode"); 123 | String make_not_readableString = config.GetValue("make_not_readable"); 124 | 125 | bool.TryParse(mipmapsString, out config_mipmaps); 126 | bool.TryParse(compressString, out config_compress); 127 | int.TryParse(scaleString, out config_scale); 128 | int.TryParse(max_sizeString, out config_max_size); 129 | int.TryParse(min_sizeString, out config_min_size); 130 | config_filter_mode = (FilterMode)Enum.Parse(typeof(FilterMode), filter_modeString); 131 | bool.TryParse(make_not_readableString, out config_make_not_readable); 132 | 133 | String mipmapsString_normals = config.GetValue("mipmaps_normals"); 134 | String compressString_normals = config.GetValue("compress_normals"); 135 | String scaleString_normals = config.GetValue("scale_normals"); 136 | String max_sizeString_normals = config.GetValue("max_size_normals"); 137 | String min_sizeString_normals = config.GetValue("min_size_normals"); 138 | 139 | bool.TryParse(mipmapsString_normals, out config_mipmaps_normals); 140 | bool.TryParse(compressString_normals, out config_compress_normals); 141 | int.TryParse(scaleString_normals, out config_scale_normals); 142 | int.TryParse(max_sizeString_normals, out config_max_size_normals); 143 | int.TryParse(min_sizeString_normals, out config_min_size_normals); 144 | 145 | Log("Settings:"); 146 | Log(" mipmaps: " + config_mipmaps); 147 | Log(" compress: " + config_compress); 148 | Log(" scale: " + config_scale); 149 | Log(" max_size: " + config_max_size); 150 | Log(" min_size: " + config_min_size); 151 | Log(" mipmaps_normals: " + config_mipmaps_normals); 152 | Log(" compress_normals: " + config_compress_normals); 153 | Log(" scale_normals: " + config_scale_normals); 154 | Log(" max_size_normals: " + config_max_size_normals); 155 | Log(" filter_mode: " + config_filter_mode); 156 | Log(" make_not_readable: " + config_make_not_readable); 157 | Log(" normal List: "); 158 | foreach (String normal in normalList) 159 | { 160 | DBGLog(" " + normal); 161 | } 162 | } 163 | } 164 | 165 | private static void CopyConfigNode(ConfigNode original, ConfigNode copy) 166 | { 167 | if (original != null) 168 | { 169 | foreach (ConfigNode node in original.nodes) 170 | { 171 | copy.AddNode(node); 172 | } 173 | foreach (ConfigNode.Value value in original.values) 174 | { 175 | copy.AddValue(value.name, value.value); 176 | } 177 | } 178 | } 179 | 180 | static public TextureInfoWrapper UpdateTexture(TexInfo texture) 181 | { 182 | 183 | string overrideName = overridesList.Find(n => texture.name.Length == Regex.Match(texture.name, n).Length); 184 | bool mipmaps = true; 185 | bool compress = texture.isNormalMap ? DatabaseLoaderTexture_ATM.config_compress : 186 | DatabaseLoaderTexture_ATM.config_compress_normals; 187 | int scale = 1; 188 | int maxSize = 0; 189 | int minSize = 64; 190 | FilterMode filterMode = FilterMode.Bilinear; 191 | bool makeNotReadable = false; 192 | 193 | if (foldersList.Exists(n => Regex.Match(texture.name, n).Success)) 194 | { 195 | 196 | if (texture.isNormalMap) 197 | { 198 | mipmaps = DatabaseLoaderTexture_ATM.config_mipmaps_normals; 199 | scale = DatabaseLoaderTexture_ATM.config_scale_normals; 200 | maxSize = DatabaseLoaderTexture_ATM.config_max_size_normals; 201 | minSize = DatabaseLoaderTexture_ATM.config_min_size_normals; 202 | } 203 | else 204 | { 205 | mipmaps = DatabaseLoaderTexture_ATM.config_mipmaps; 206 | scale = DatabaseLoaderTexture_ATM.config_scale; 207 | maxSize = DatabaseLoaderTexture_ATM.config_max_size; 208 | minSize = DatabaseLoaderTexture_ATM.config_min_size; 209 | } 210 | filterMode = config_filter_mode; 211 | makeNotReadable = config_make_not_readable; 212 | 213 | if (overrideName != null) 214 | { 215 | ConfigNode overrideNode = overrides.GetNode(overrideName); 216 | String normalString = texture.isNormalMap ? "_normals" : ""; 217 | String mipmapsString = overrideNode.GetValue("mipmaps" + normalString); 218 | String compressString = overrideNode.GetValue("compress" + normalString); 219 | String scaleString = overrideNode.GetValue("scale" + normalString); 220 | String max_sizeString = overrideNode.GetValue("max_size" + normalString); 221 | String min_sizeString = overrideNode.GetValue("min_size" + normalString); 222 | String filter_modeString = overrideNode.GetValue("filter_mode"); 223 | String make_not_readableString = overrideNode.GetValue("make_not_readable"); 224 | 225 | if (mipmapsString != null) 226 | { 227 | bool.TryParse(mipmapsString, out mipmaps); 228 | } 229 | if (compressString != null) 230 | { 231 | bool.TryParse(compressString, out compress); 232 | } 233 | if (scaleString != null) 234 | { 235 | int.TryParse(scaleString, out scale); 236 | } 237 | if (filter_modeString != null) 238 | { 239 | try 240 | { 241 | filterMode = (FilterMode)Enum.Parse(typeof(FilterMode), filter_modeString); 242 | } 243 | catch 244 | { 245 | filterMode = config_filter_mode; 246 | } 247 | } 248 | if (make_not_readableString != null) 249 | { 250 | bool.TryParse(make_not_readableString, out makeNotReadable); 251 | } 252 | if (max_sizeString != null) 253 | { 254 | int.TryParse(max_sizeString, out maxSize); 255 | } 256 | if (min_sizeString != null) 257 | { 258 | int.TryParse(min_sizeString, out minSize); 259 | } 260 | } 261 | } 262 | texture.SetScalingParams(scale, maxSize, minSize); 263 | texture.makeNotReadable = makeNotReadable && !readableList.Contains(texture.name); 264 | TextureInfoWrapper ret = CacheController.FetchCacheTexture(texture, compress, mipmaps); 265 | ret.texture.filterMode = filterMode; 266 | return ret; 267 | } 268 | 269 | 270 | public static bool IsNormal(String name) 271 | { 272 | bool isNormal = name.EndsWith("NRM") || normalList.Contains(name); 273 | String originalTextureFile = KSPUtil.ApplicationRootPath + "GameData/" + name + ".mbm"; 274 | if (!isNormal && File.Exists(originalTextureFile)) 275 | { 276 | FileStream stream = File.OpenRead(originalTextureFile); 277 | //while stream is open, if it is an MBM, flag normal maps. 278 | stream.Position = 12; 279 | if (stream.ReadByte() == 1) 280 | { 281 | isNormal = true; 282 | } 283 | stream.Close(); 284 | } 285 | return isNormal; 286 | } 287 | 288 | public DatabaseLoaderTexture_ATM() : base() 289 | { 290 | 291 | } 292 | 293 | public override IEnumerator Load(UrlDir.UrlFile urlFile, FileInfo file) 294 | { 295 | TexInfo t = new TexInfo(urlFile); 296 | GameDatabase.TextureInfo texture = UpdateTexture(t); 297 | obj = texture; 298 | successful = true; 299 | yield return null; 300 | } 301 | 302 | public static void DBGLog(String message) 303 | { 304 | if (ActiveTextureManagement.DBL_LOG) 305 | { 306 | UnityEngine.Debug.Log("DatabaseLoaderTexture_ATM: " + message); 307 | } 308 | } 309 | public static void Log(String message) 310 | { 311 | UnityEngine.Debug.Log("DatabaseLoaderTexture_ATM: " + message); 312 | } 313 | 314 | } 315 | } 316 | -------------------------------------------------------------------------------- /ActiveTextureManagement/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ActiveTextureManagement")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ActiveTextureManagement")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("dab4a871-f995-4558-bdd3-d3348814d343")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ActiveTextureManagement/TextureInfoWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace ActiveTextureManagement 8 | { 9 | public class TextureInfoWrapper : GameDatabase.TextureInfo 10 | { 11 | public TextureInfoWrapper(UrlDir.UrlFile file, UnityEngine.Texture2D newTex, bool nrmMap, bool readable, bool compress) 12 | : base(file, newTex, nrmMap, readable, compress) 13 | { 14 | 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Content/aggressive/GameData/ActiveTextureManagement/ActiveTextureManagerConfig.cfg: -------------------------------------------------------------------------------- 1 | ### 2 | ### Global config settings 3 | ### Modify this file to change global texture settings. 4 | ### To manage a mod pack (more than just compress), 5 | ### just add a config file with the exact name of the 6 | ### mod's folder. Look in the same location as this 7 | ### config file for examples. In-depth settings and 8 | ### example overrides can be found below. 9 | ### 10 | ACTIVE_TEXTURE_MANAGER 11 | { 12 | 13 | ###DBG = TRUE 14 | ###Section for global settings 15 | 16 | ### Sets how the shader filters textures. Options are: 17 | ### Point - No filtering is done. Pixels are sampled 18 | ### directly. Results in a "pixelated" object. 19 | ### Good for GUIs and other 2D applications 20 | ### Bilinear - Decent filter. What KSP uses by default. 21 | ### Trilinear - Better filter. Sometimes difference is 22 | ### negligable. Will have small negative affect 23 | ### on performace. 24 | filter_mode = Bilinear 25 | 26 | ### Offload the texture from RAM into Graphics memory. 27 | ### this will mean the textures cannot be sampled by 28 | ### the scripts, but saves a LOT of memory. MBMs are 29 | ### not readable by default. 30 | make_not_readable = true 31 | 32 | ###Section for non-normalmapped textures 33 | ### Normal mapped textures are flagged as normal in MBMs, 34 | ### the file names end in _NRM, or are called out as such 35 | ### in the config files. 36 | 37 | ### Compression flag. Compress all textures that 38 | ### can be. This includes textures in packs that don't 39 | ### have config files. Will reduce quality slightly. 40 | ### Not recomended for normal maps. 41 | compress = true 42 | 43 | ### Generate mipmaps. Mipmaps add smaller, filtered versions 44 | ### of the texture for use at a distance. Adds ~30% more 45 | ### memory. Well worth it on visual textures. 46 | mipmaps = true 47 | 48 | ### Resize the texture by the scale specified. Use powers 49 | ### of two for best efficiency. 1 is no scalling, 2, is 1/2 50 | ### 4 is 1/4, etc. 51 | scale = 2 52 | 53 | ### Specifies a maximum dimension for both width and height 54 | ### of textures, AFTER any scalling. ie. if this is set to 55 | ### 256, and you have a 1024X1024 texture and scale set to 2, 56 | ### the resulting texture will be 256x256. Use it without 57 | ### scalling to only shrink larger textures. 58 | max_size = 0 59 | min_size = 64 60 | 61 | ### Section for normalmapped textures. Same as above, but 62 | ### apply only to normal maps. 63 | compress_normals = true 64 | mipmaps_normals = true 65 | scale_normals = 2 66 | max_size_normals = 256 67 | min_size_normals = 64 68 | 69 | OVERRIDES 70 | { 71 | .*/Props/.* 72 | { 73 | compress = true 74 | mipmaps = true 75 | scale = 1 76 | max_size = 0 77 | } 78 | 79 | .*/Flags/.* 80 | { 81 | compress = true 82 | mipmaps = false 83 | scale = 1 84 | max_size = 0 85 | } 86 | 87 | .*/Agencies/.* 88 | { 89 | compress = false 90 | mipmaps = false 91 | scale = 1 92 | max_size = 0 93 | make_not_readable = false 94 | } 95 | } 96 | 97 | ### Specific sections can be added in config files 98 | ### to allow specifc behaviour. Examples shown are from 99 | ### Squad.cfg and BoulderCo.cfg. 100 | ### 101 | ### Some mods don't mark normal map textures properly, 102 | ### which can cause part errors. 103 | ### Specify the textures to be treaded as normal maps: 104 | ###NORMAL_LIST 105 | ###{ 106 | ### texture = Squad/Spaces/mk1CockpitInternal/model002 107 | ### texture = Squad/Spaces/mk1CockpitInternal/model004 108 | ### texture = Squad/Parts/FuelTank/RCSTank1-2/model001 109 | ### texture = Squad/Parts/Aero/winglet2/model001 110 | ###} 111 | ### 112 | ### Override a specific file/folder using regexes(useful for flag/GUI folders) 113 | ### If any of the fields are ommitted, it is replaced by the global settings: 114 | ###OVERRIDES 115 | ###{ 116 | ### .*/Flags/.* 117 | ### { 118 | ### compress = true 119 | ### mipmaps = false 120 | ### scale = 1 121 | ### max_size = 0 122 | ### compress_normals = false 123 | ### mipmaps_normals = false 124 | ### scale_normals = 1 125 | ### max_size_normals = 0 126 | ### filtering = Bilinear 127 | ### make_not_readable = true 128 | ### } 129 | ###} 130 | ## 131 | 132 | } 133 | 134 | -------------------------------------------------------------------------------- /Content/basic/GameData/ActiveTextureManagement/ActiveTextureManagerConfig.cfg: -------------------------------------------------------------------------------- 1 | ### 2 | ### Global config settings 3 | ### Modify this file to change global texture settings. 4 | ### To manage a mod pack (more than just compress), 5 | ### just add a config file with the exact name of the 6 | ### mod's folder. Look in the same location as this 7 | ### config file for examples. In-depth settings and 8 | ### example overrides can be found below. 9 | ### 10 | ACTIVE_TEXTURE_MANAGER 11 | { 12 | 13 | ###DBG = TRUE 14 | ###Section for global settings 15 | 16 | ### Sets how the shader filters textures. Options are: 17 | ### Point - No filtering is done. Pixels are sampled 18 | ### directly. Results in a "pixelated" object. 19 | ### Good for GUIs and other 2D applications 20 | ### Bilinear - Decent filter. What KSP uses by default. 21 | ### Trilinear - Better filter. Sometimes difference is 22 | ### negligable. Will have small negative affect 23 | ### on performace. 24 | filter_mode = Bilinear 25 | 26 | ### Offload the texture from RAM into Graphics memory. 27 | ### this will mean the textures cannot be sampled by 28 | ### the scripts, but saves a LOT of memory. MBMs are 29 | ### not readable by default. 30 | make_not_readable = true 31 | 32 | ###Section for non-normalmapped textures 33 | ### Normal mapped textures are flagged as normal in MBMs, 34 | ### the file names end in _NRM, or are called out as such 35 | ### in the config files. 36 | 37 | ### Compression flag. Compress all textures that 38 | ### can be. This includes textures in packs that don't 39 | ### have config files. Will reduce quality slightly. 40 | ### Not recomended for normal maps. 41 | compress = true 42 | 43 | ### Generate mipmaps. Mipmaps add smaller, filtered versions 44 | ### of the texture for use at a distance. Adds ~30% more 45 | ### memory. Well worth it on visual textures. 46 | mipmaps = true 47 | 48 | ### Resize the texture by the scale specified. Use powers 49 | ### of two for best efficiency. 1 is no scalling, 2, is 1/2 50 | ### 4 is 1/4, etc. 51 | scale = 1 52 | 53 | ### Specifies a maximum dimension for both width and height 54 | ### of textures, AFTER any scalling. ie. if this is set to 55 | ### 256, and you have a 1024X1024 texture and scale set to 2, 56 | ### the resulting texture will be 256x256. Use it without 57 | ### scalling to only shrink larger textures. 58 | max_size = 0 59 | min_size = 128 60 | 61 | ### Section for normalmapped textures. Same as above, but 62 | ### apply only to normal maps. 63 | compress_normals = true 64 | mipmaps_normals = true 65 | scale_normals = 2 66 | max_size_normals = 512 67 | 68 | OVERRIDES 69 | { 70 | .*/Props/.* 71 | { 72 | compress = true 73 | mipmaps = true 74 | scale = 1 75 | max_size = 0 76 | } 77 | 78 | .*/Flags/.* 79 | { 80 | compress = true 81 | mipmaps = false 82 | scale = 1 83 | max_size = 0 84 | } 85 | .*/Agencies/.* 86 | { 87 | compress = false 88 | mipmaps = false 89 | scale = 1 90 | max_size = 0 91 | make_not_readable = false 92 | } 93 | } 94 | 95 | ### Specific sections can be added in config files 96 | ### to allow specifc behaviour. Examples shown are from 97 | ### Squad.cfg and BoulderCo.cfg. 98 | ### 99 | ### Some mods don't mark normal map textures properly, 100 | ### which can cause part errors. 101 | ### Specify the textures to be treaded as normal maps: 102 | ###NORMAL_LIST 103 | ###{ 104 | ### texture = Squad/Spaces/mk1CockpitInternal/model002 105 | ### texture = Squad/Spaces/mk1CockpitInternal/model004 106 | ### texture = Squad/Parts/FuelTank/RCSTank1-2/model001 107 | ### texture = Squad/Parts/Aero/winglet2/model001 108 | ###} 109 | ### 110 | ### Override a specific file/folder using regexes(useful for flag/GUI folders) 111 | ### If any of the fields are ommitted, it is replaced by the global settings: 112 | ###OVERRIDES 113 | ###{ 114 | ### .*/Flags/.* 115 | ### { 116 | ### compress = true 117 | ### mipmaps = false 118 | ### scale = 1 119 | ### max_size = 0 120 | ### compress_normals = false 121 | ### mipmaps_normals = false 122 | ### scale_normals = 1 123 | ### max_size_normals = 0 124 | ### filtering = Bilinear 125 | ### make_not_readable = true 126 | ### } 127 | ###} 128 | ## 129 | 130 | } 131 | 132 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/000_Toolbar.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = 000_Toolbar 4 | enabled = true 5 | OVERRIDES 6 | { 7 | 000_Toolbar/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/AIES_Aerospace.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = AIES_Aerospace 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ASET.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ASET 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/AlchemyTechnologies.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = AlchemyTechnologies 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/AmericanPack.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = AmericanPack 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/B9_Aerospace.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = B9_Aerospace 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = B9_Aerospace/Parts/Structure_P_Clear-Half/model001 8 | texture = B9_Aerospace/Parts/Structure_P_Standard-Frame/model001_NRM 9 | } 10 | } 11 | ACTIVE_TEXTURE_MANAGER_CONFIG 12 | { 13 | folder = B9_Aerospace_DEPRECATED 14 | enabled = true 15 | NORMAL_LIST 16 | { 17 | texture = B9_Aerospace_DEPRECATED/Parts/Structure_P_Clear-Half/model001 18 | texture = B9_Aerospace_DEPRECATED/Parts/Structure_P_Standard-Frame/model001 19 | } 20 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/BahaSP.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = BahaSP 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/BahamutoD.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = BahamutoD 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/BetterTimeWarp.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = BetterTimeWarp 4 | enabled = true 5 | OVERRIDES 6 | { 7 | BetterTimeWarp/Icons/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/BobCatind.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = BobCatind 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = BobCatind/Parts/SovietPack/ISS_TKS_FGB/model001 8 | texture = BobCatind/Parts/SovietPack/ISS_TKS_FGB/model003 9 | texture = BobCatind/Parts/SovietPack/MIR_ASAS/model001 10 | texture = BobCatind/Parts/SovietPack/MIR_core/model001 11 | texture = BobCatind/Parts/SovietPack/MIR_core_solar/model001 12 | texture = BobCatind/Parts/SovietPack/MIR_core_solar_top/model001 13 | texture = BobCatind/Parts/SovietPack/MIR_probe/model001 14 | texture = BobCatind/Parts/SovietPack/MIR_RCS/model001 15 | texture = BobCatind/Parts/SovietPack/MIR_soviet_dockport/model001 16 | texture = BobCatind/Parts/SovietPack/MIR_soviet_dockport_cap/model001 17 | texture = BobCatind/Parts/SovietPack/MIR_soviet_dockport_papa/model001 18 | texture = BobCatind/Spaces/MIR_core_internal/model001 19 | } 20 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/BoulderCo.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = BoulderCo 4 | enabled = true 5 | OVERRIDES 6 | { 7 | BoulderCo/Clouds/.* 8 | { 9 | compress = true 10 | mipmaps = true 11 | scale = 1 12 | max_size = 0 13 | make_not_readable = false 14 | } 15 | BoulderCo/Atmosphere/.* 16 | { 17 | compress = true 18 | mipmaps = true 19 | scale = 1 20 | max_size = 0 21 | make_not_readable = false 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/BoxSat alpha.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = BoxSat alpha 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Chatterer.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Chatterer 4 | enabled = true 5 | OVERRIDES 6 | { 7 | Chatterer/Textures/chatterer_icon_off 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | Chatterer/Textures/chatterer_icon_on 15 | { 16 | compress = true 17 | mipmaps = false 18 | scale = 1 19 | max_size = 0 20 | } 21 | Chatterer/Textures/chatterer_icon_toolbar 22 | { 23 | compress = true 24 | mipmaps = false 25 | scale = 1 26 | max_size = 0 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/CleverWalrus.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = CleverWalrus 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/DMagic Orbital Science.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = DMagic Orbital Science 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/DeadlyReentry.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = DeadlyReentry 4 | enabled = true 5 | OVERRIDES 6 | { 7 | DeadlyReentry/Assets/.* 8 | { 9 | compress = true 10 | mipmaps = true 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/DiazoHorizVert.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Diazo 4 | enabled = true 5 | OVERRIDES 6 | { 7 | Diazo/.*/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ExtraplanetaryLaunchpads.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ExtraplanetaryLaunchpads 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/FASA.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = FASA 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = FASA/Gemini2/FASA_Gemini_Lander_Eng/model001 8 | texture = FASA/Gemini2/FASA_Gemini_Lander_Legs/model001 9 | texture = FASA/Gemini2/FASA_Gemini_Lander_Leg_Part/model001 10 | texture = FASA/Gemini2/FASA_Gemini_Lander_Pod/model001 11 | texture = FASA/Gemini2/FASA_Gemini_RCS_Thruster/model001 12 | texture = FASA/Gemini2/FASA_OrbitalBerthaEngine_Mini/model001 13 | texture = FASA/Gemini2/FASA_OrbitalBerthaEngine_Mini/model004 14 | texture = FASA/Gemini2/SmallGearBay/model001 15 | texture = FASA/Mercury/FASA_Atlas_LFT_Cone/model001 16 | texture = FASA/Mercury/FASA_Mercury_LFEngine/model001 17 | texture = FASA/Mercury/FASA_Mercury_Parachute_Box/model001 18 | texture = FASA/Gemini2/SmallGearBay/model002 19 | } 20 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/FASA_Asteroids.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = FASA_Asteroids 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/FerramAerospaceResearch.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = FerramAerospaceResearch 4 | enabled = true 5 | OVERRIDES 6 | { 7 | FerramAerospaceResearch/Textures/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/FilterExtensions.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = 000_FilterExtensions 4 | enabled = true 5 | OVERRIDES 6 | { 7 | 000_FilterExtensions/Icons/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Firespitter.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Firespitter 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Goodspeed.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Goodspeed 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Green Skull Inc.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Green Skull Inc 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/HexCans.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = HexCans 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/HooliganLabs.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = HooliganLabs 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/HorizonAeronautics.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = HorizonAeronautics 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/HullCameraVDS.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = HullCameraVDS 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ISS_Comunity.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ISS_Community 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = ISS_Comunity/Parts/ISS_CBM_dockport/model001 8 | texture = ISS_Comunity/Parts/ISS_Columbus/model001 9 | texture = ISS_Comunity/Parts/ISS_Destiny/model001 10 | texture = ISS_Comunity/Parts/ISS_JEM ELM-PS/model001 11 | texture = ISS_Comunity/Parts/ISS_JEM PM/model001 12 | texture = ISS_Comunity/Parts/ISS_JEM PM/model004 13 | texture = ISS_Comunity/Parts/ISS_JEM PM/model006 14 | texture = ISS_Comunity/Parts/ISS_JEM PM/model008 15 | texture = ISS_Comunity/Parts/ISS_MPLM/model001 16 | texture = ISS_Comunity/Parts/ISS_Node2/model001 17 | texture = ISS_Comunity/Parts/ISS_PMA/model001 18 | texture = ISS_Comunity/Parts/ISS_Quest/model001 19 | texture = ISS_Comunity/Parts/ISS_Truss_S0/model001 20 | texture = ISS_Comunity/Parts/ISS_Truss_S1_P1/model001 21 | texture = ISS_Comunity/Parts/ISS_Truss_S1_P1/model003 22 | texture = ISS_Comunity/Parts/ISS_Truss_S3_P3/model001 23 | texture = ISS_Comunity/Parts/ISS_Truss_S3_P3/model003 24 | } 25 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/JSI.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = JSI 4 | enabled = true 5 | OVERRIDES 6 | { 7 | JSI/RasterPropMonitor/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | make_not_readable = false 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/KAS.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = KAS 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/KSO.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = KSO 4 | enabled = true 5 | OVERRIDES 6 | { 7 | KSO/RPM/.* 8 | { 9 | compress = false 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | make_not_readable = false 14 | } 15 | 16 | KSO/Parts/kerbin_orbiter 17 | { 18 | compress = false 19 | mipmaps = true 20 | scale = 1 21 | max_size = 0 22 | make_not_readable = false 23 | } 24 | 25 | KSO/Parts/altnames/mayhem 26 | { 27 | compress = false 28 | mipmaps = true 29 | scale = 1 30 | max_size = 0 31 | make_not_readable = false 32 | } 33 | KSO/Parts/altnames/chaos 34 | { 35 | compress = false 36 | mipmaps = true 37 | scale = 1 38 | max_size = 0 39 | make_not_readable = false 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/KSPX.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = KSPX 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/KWRocketry.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = KWRocketry 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/KerbalEngineer.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = KerbalEngineer 4 | enabled = true 5 | OVERRIDES 6 | { 7 | KerbalEngineer/Textures/.* 8 | { 9 | compress = true 10 | mipmaps = true 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Kethane.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Kethane 4 | enabled = true 5 | OVERRIDES 6 | { 7 | Kethane/toolbar 8 | { 9 | compress = true 10 | mipmaps = true 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/KipEng.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = KipEng 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/LLL-Extra.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = LLL-Extra 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/LLL.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = LLL 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = LLL/Parts/Structural/LLLWindowCircularWalkway/model001 8 | texture = LLL/Parts/Structural/LLL2x1Hull/HullNorm 9 | } 10 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/LTech.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = LTech 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/LazTek.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = LazTek 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/License.txt: -------------------------------------------------------------------------------- 1 | TextureCompressor 2 | ================= 3 | 4 | Compresses the Textures after loading in KSP 5 | 6 | 7 | The MIT License (MIT) 8 | 9 | Copyright (c) 2013 Ryan Bray 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | this software and associated documentation files (the "Software"), to deal in 13 | the Software without restriction, including without limitation the rights to 14 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | the Software, and to permit persons to whom the Software is furnished to do so, 16 | subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 23 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 24 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 25 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/LifeSupport.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = LifeSupport 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Lovad.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Lovad 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/MagicSmokeIndustries.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = MagicSmokeIndustries 4 | enabled = true 5 | OVERRIDES 6 | { 7 | MagicSmokeIndustries/Textures/icon_button 8 | { 9 | compress = true 10 | mipmaps = true 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/MarkIVSystem.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = MarkIVSystem 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/MechJeb2.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = MechJeb2 4 | enabled = true 5 | OVERRIDES 6 | { 7 | MechJeb2/Icons/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ModsByTal.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ModsByTal 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/NASAmission.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = NASAmission 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/NavHud.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = NavHud 4 | enabled = true 5 | OVERRIDES 6 | { 7 | NavHud/*.png 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/NavyFishDPAI.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = NavyFish 4 | enabled = true 5 | OVERRIDES 6 | { 7 | NavyFish/Plugins/ToolbarIcons/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/NearFutureTechnologies.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = NearFutureElectrical 4 | folder = NearFutureSpacecraft 5 | folder = NearFutureProps 6 | folder = NearFutureConstruction 7 | enabled = true 8 | } 9 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/NehemiahInc.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = NehemiahInc 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Nereid.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Nereid 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/NothkeSerCom.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = NothkeSerCom 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/NovaPunch2.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = NovaPunch2 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = NovaPunch2/Parts/CouplersAndAdapters/NP_interstage_1_25m_2_5m_tank/model001 8 | texture = NovaPunch2/Parts/CouplersAndAdapters/NP_interstage_2_5m_1_25m_plate/model001 9 | texture = NovaPunch2/Parts/CouplersAndAdapters/NP_interstage_2_5m_3_75m_tank/model001 10 | texture = NovaPunch2/Parts/CouplersAndAdapters/NP_interstage_3_75m_2_5m_plate/model001 11 | texture = NovaPunch2/Parts/CouplersAndAdapters/NP_interstage_3_75m_5m_tank/model001 12 | texture = NovaPunch2/Parts/CouplersAndAdapters/NP_interstage_5m_3_75m_plate/model001 13 | texture = NovaPunch2/Parts/Decouplers/Decoupler_1_25m_stack/model001 14 | texture = NovaPunch2/Parts/Decouplers/Decoupler_2_5m_stack/model001 15 | texture = NovaPunch2/Parts/Decouplers/Decoupler_3_75m_stack/model001 16 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25mBearcatOld/model001 17 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25mBearcatOld/model003 18 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25mBearcatOld/model005 19 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25m_AerospikeEngine/model001 20 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25m_AerospikeEngine/model004 21 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25m_BerthaQuadEngine/model001 22 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25m_K2XEngine/model001 23 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25m_RMA3_OrbiterEngine/model001 24 | texture = NovaPunch2/Parts/Engines/NP_LFE_1_25m_RMA3_OrbiterEngine/model004 25 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_4X800Engine/model001 26 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_4X800Engine/model004 27 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_BearcatSingle/model001 28 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_BearcatSingle/model004 29 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_NERVA/model001 30 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_NERVA/model004 31 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_OrbitalBerthaEngine/model001 32 | texture = NovaPunch2/Parts/Engines/NP_LFE_2_5m_OrbitalBerthaEngine/model004 33 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_BearCatTriNozzle/model001 34 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_BearCatTriNozzle/model004 35 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_Energia4x/model001 36 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_Energia4x/model003 37 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_Energia4x/model005 38 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_LittleMotherEngine/model001 39 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_LittleMotherEngine/model003 40 | texture = NovaPunch2/Parts/Engines/NP_LFE_3_75m_LittleMotherEngine/model006 41 | texture = NovaPunch2/Parts/Engines/NP_LFE_5m_Bearcat5x/model001 42 | texture = NovaPunch2/Parts/Engines/NP_LFE_5m_TheMatriarch/model001 43 | texture = NovaPunch2/Parts/Engines/NP_LFE_5m_TheMatriarch/model003 44 | texture = NovaPunch2/Parts/Engines/NP_LFE_5m_TheMatriarch/model006 45 | texture = NovaPunch2/Parts/Fairings/NP_Fairings_2_5m_Nose/model001 46 | texture = NovaPunch2/Parts/Fairings/NP_Fairings_2_5m_NoseCone/model001 47 | texture = NovaPunch2/Parts/Fairings/NP_Fairings_2_5m_Plate/model001 48 | texture = NovaPunch2/Parts/Fairings/NP_Fairings_2_5m_Wall/model001 49 | texture = NovaPunch2/Parts/Fairings/NP_Fairings_2_5m_WallShort/model001 50 | texture = NovaPunch2/Parts/Fairings/NP_Fairings_3_75m_Plate/model001 51 | texture = NovaPunch2/Parts/Fairings/NP_Fairings_5m_Plate/model001 52 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_0_625mx1m/model001 53 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_1_25mx1_5m/model001 54 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_1_25mx3_0m/model001 55 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_1_25mx6_0m/model001 56 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_2_5mx12_0m/model001 57 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_2_5mx1_5m/model001 58 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_2_5mx3_0m/model001 59 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_2_5mx6_0m/model001 60 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_3_75mx2_25m/model001 61 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_3_75mx4_5m/model001 62 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_3_75mx9_0m/model001 63 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_5_0mx12_0m/model001 64 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_5_0mx3_0m/model001 65 | texture = NovaPunch2/Parts/FuelTanks/NP_LFT_5_0mx6_0m/model001 66 | texture = NovaPunch2/Parts/RCS/RCS_1_25mx0_5m/model001 67 | texture = NovaPunch2/Parts/RCS/RCS_2_5mx0_5m/model001 68 | texture = NovaPunch2/Parts/RCS/RCS_3_75mx1_0m/model001 69 | texture = NovaPunch2/Parts/SAS/NP_SAS_1_25m/model001 70 | texture = NovaPunch2/Parts/SolidBoosters/NP_SRB_1_25m_SmallStack/model003 71 | texture = NovaPunch2/Parts/SolidBoosters/NP_SRB_2_5m_Short/model001 72 | texture = NovaPunch2/Parts/SolidBoosters/NP_SRB_2_5m_Short/model003 73 | texture = NovaPunch2/Parts/Thor/NP_ThorLanderStrut2/model001 74 | texture = NovaPunch2/Parts/Thor/NP_ThorLanderStrut3/model001 75 | } 76 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/PlanetShine.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = PlanetShine 4 | enabled = true 5 | OVERRIDES 6 | { 7 | PlanetShine/Icons/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/PorkWorks.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = PorkWorks 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ProceduralFairings.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ProceduralFairings 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ProceduralParts.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ProceduralParts 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/R&SCapsuledyne.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = R&SCapsuledyne 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/RCSBuildAid.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = RCSBuildAid 4 | enabled = true 5 | OVERRIDES 6 | { 7 | RCSBuildAid/Textures/iconToolbar 8 | { 9 | compress = true 10 | mipmaps = true 11 | scale = 1 12 | max_size = 0 13 | } 14 | RCSBuildAid/Textures/iconToolbar_active 15 | { 16 | compress = true 17 | mipmaps = true 18 | scale = 1 19 | max_size = 0 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/RavienCritTempGauge.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Ravien 4 | enabled = true 5 | OVERRIDES 6 | { 7 | Ravien/Textures/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/RealChute.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = RealChute 4 | enabled = true 5 | OVERRIDES 6 | { 7 | RealChute/Plugins/PluginData/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/SCANsat.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = SCANsat 4 | enabled = true 5 | OVERRIDES 6 | { 7 | SCANsat/Icons/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/SXT.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = SXT 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Sentinel.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = KSEA 4 | enabled = true 5 | OVERRIDES 6 | { 7 | KSEA/Sentinel/Textures/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ShipManifest.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ShipManifest 4 | enabled = true 5 | OVERRIDES 6 | { 7 | ShipManifest/Images/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/Squad.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = Squad 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = Squad/Spaces/mk1CockpitInternal/model002 8 | texture = Squad/Spaces/mk1CockpitInternal/model004 9 | texture = Squad/Parts/FuelTank/RCSFuelTankR1/model001 10 | texture = Squad/Parts/Aero/wingletAV-R8/model001 11 | } 12 | OVERRIDES 13 | { 14 | Squad/Agencies/.* 15 | { 16 | compress = false 17 | mipmaps = false 18 | scale = 1 19 | max_size = 0 20 | make_not_readable = false 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/StationPartsExpansion: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = StationPartsExpansion 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/StationScience.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = StationScience 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/StretchyTanks.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = StretchyTanks 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = StretchyTanks/Parts/foilthinbump 8 | texture = StretchyTanks/Parts/stocksidenormal 9 | } 10 | 11 | OVERRIDES 12 | { 13 | StretchyTanks/Parts/foilthin 14 | { 15 | compress = true 16 | mipmaps = true 17 | scale = 1 18 | max_size = 0 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/SwitchVessel.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = SwitchVessel 4 | enabled = true 5 | OVERRIDES 6 | { 7 | SwitchVessel/*.png 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/TSAS.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = TSAS 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ThunderAerospaceTACLS.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ThunderAerospace/TacLifeSupport 4 | enabled = true 5 | OVERRIDES 6 | { 7 | ThunderAerospace/TacLifeSupport/Textures/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/TreeLoader.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = TreeLoader 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/TriggerTech.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = TriggerTech 4 | enabled = true 5 | OVERRIDES 6 | { 7 | TriggerTech/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/UmbraSpaceIndustries.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = UmbraSpaceIndustries 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/WarpPlugin.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = WarpPlugin 4 | enabled = true 5 | OVERRIDES 6 | { 7 | WarpPlugin/[^/]* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | make_not_readable = false 14 | } 15 | 16 | WarpPlugin/PlanetResourceData/.* 17 | { 18 | compress = false 19 | mipmaps = false 20 | scale = 1 21 | max_size = 0 22 | make_not_readable = false 23 | } 24 | 25 | WarpPlugin/megajoule_click2 26 | { 27 | compress = false 28 | mipmaps = false 29 | scale = 1 30 | max_size = 0 31 | make_not_readable = false 32 | } 33 | 34 | WarpPlugin/thermal_click 35 | { 36 | compress = false 37 | mipmaps = false 38 | scale = 1 39 | max_size = 0 40 | make_not_readable = false 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/WaypointManager.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = WaypointManager 4 | enabled = true 5 | OVERRIDES 6 | { 7 | WaypointManager/icons/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/WildBlueIndustries: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = WildBlueIndustries 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/WombatConversions.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = WombatConversions 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/WorldCup2014.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = WorldCup2014 4 | enabled = true 5 | } 6 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/ZWheel.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = ZWheel 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/blackheart.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = blackheart 4 | enabled = true 5 | NORMAL_LIST 6 | { 7 | texture = blackheart/Castor/castormap 8 | texture = blackheart/KW/1MMap 9 | texture = blackheart/KW/3MMap 10 | texture = blackheart/KW/BottomMap 11 | texture = blackheart/KW/TopMap 12 | } 13 | 14 | OVERRIDES 15 | { 16 | blackheart/KOSMOS/kosmos2 17 | { 18 | compress = true 19 | mipmaps = true 20 | scale = 1 21 | max_size = 0 22 | } 23 | 24 | blackheart/KOSMOS/kosmoslong 25 | { 26 | compress = true 27 | mipmaps = true 28 | scale = 1 29 | max_size = 0 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/kOS.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = kOS 4 | enabled = true 5 | OVERRIDES 6 | { 7 | kOS/GFX/.* 8 | { 9 | compress = true 10 | mipmaps = false 11 | scale = 1 12 | max_size = 0 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/masTerTorch.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = masTerTorch 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/ActiveTextureManagerConfigs/nothke_DROMOMAN.cfg: -------------------------------------------------------------------------------- 1 | ACTIVE_TEXTURE_MANAGER_CONFIG 2 | { 3 | folder = nothke_DROMOMAN 4 | enabled = true 5 | } -------------------------------------------------------------------------------- /Content/common/GameData/ActiveTextureManagement/License.txt: -------------------------------------------------------------------------------- 1 | TextureCompressor 2 | ================= 3 | 4 | Compresses the Textures after loading in KSP 5 | 6 | 7 | The MIT License (MIT) 8 | 9 | Copyright (c) 2013 Ryan Bray 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | this software and associated documentation files (the "Software"), to deal in 13 | the Software without restriction, including without limitation the rights to 14 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | the Software, and to permit persons to whom the Software is furnished to do so, 16 | subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 23 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 24 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 25 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /KSPResources/readme.txt: -------------------------------------------------------------------------------- 1 | Drop the x86 and x64 libs in the proper directories. 2 | 3 | Assembly-CSharp.dll and UnityEngine.dll -------------------------------------------------------------------------------- /KSPResources/x64/Drop Assembly-CSharp.dll and UnityEngine.dll here.txt: -------------------------------------------------------------------------------- 1 | Drop the x64 libs here. 2 | 3 | Assembly-CSharp.dll and UnityEngine.dll -------------------------------------------------------------------------------- /KSPResources/x86/Drop Assembly-CSharp.dll and UnityEngine.dll here.txt: -------------------------------------------------------------------------------- 1 | Drop the x86 libs here. 2 | 3 | Assembly-CSharp.dll and UnityEngine.dll -------------------------------------------------------------------------------- /LibSquishPort/LibSquishPort.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6EAA2286-2B54-4445-B553-78B67F497BA9} 8 | Library 9 | Properties 10 | LibSquishPort 11 | LibSquishPort 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | true 36 | bin\x64\Debug\ 37 | DEBUG;TRACE 38 | full 39 | x64 40 | prompt 41 | ManagedMinimumRules.ruleset 42 | true 43 | 44 | 45 | bin\x64\Release\ 46 | TRACE 47 | true 48 | pdbonly 49 | x64 50 | prompt 51 | ManagedMinimumRules.ruleset 52 | 53 | 54 | true 55 | bin\x86\Debug\ 56 | DEBUG;TRACE 57 | full 58 | x86 59 | prompt 60 | ManagedMinimumRules.ruleset 61 | true 62 | 63 | 64 | bin\x86\Release\ 65 | TRACE 66 | true 67 | pdbonly 68 | x86 69 | prompt 70 | ManagedMinimumRules.ruleset 71 | 72 | 73 | 74 | ..\KSPResources\Assembly-CSharp.dll 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | ..\KSPResources\UnityEngine.dll 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | copy /Y "$(SolutionDir)KSPResources\$(PlatformName)\*.dll" "$(SolutionDir)KSPResources" 101 | 102 | 103 | xcopy $(TargetFileName) "$(SolutionDir)Pack\GameData\ActiveTextureManagement\Plugins\" /e /y /i /r 104 | 105 | 112 | -------------------------------------------------------------------------------- /LibSquishPort/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("LibSquishPort")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("LibSquishPort")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("456ceaf0-b16b-4248-94a1-f9b4655a2b00")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /LibSquishPort/Squish.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using System.Threading; 30 | 31 | namespace LibSquishPort 32 | { 33 | [Flags] 34 | public enum SquishFlags 35 | { 36 | //! Use DXT1 compression. 37 | kDxt1 = (1 << 0), 38 | 39 | //! Use DXT3 compression. 40 | kDxt3 = (1 << 1), 41 | 42 | //! Use DXT5 compression. 43 | kDxt5 = (1 << 2), 44 | 45 | //! Use a very slow but very high quality colour compressor. 46 | kColourIterativeClusterFit = (1 << 8), 47 | 48 | //! Use a slow but high quality colour compressor (the default). 49 | kColourClusterFit = (1 << 3), 50 | 51 | //! Use a fast but low quality colour compressor. 52 | kColourRangeFit = (1 << 4), 53 | 54 | //! Use a perceptual metric for colour error (the default). 55 | kColourMetricPerceptual = (1 << 5), 56 | 57 | //! Use a uniform metric for colour error. 58 | kColourMetricUniform = (1 << 6), 59 | 60 | //! Weight the colour by alpha during cluster fit (disabled by default). 61 | kWeightColourByAlpha = (1 << 7) 62 | }; 63 | 64 | public class squish 65 | { 66 | static SquishFlags FixFlags(SquishFlags flags) 67 | { 68 | // grab the flag bits 69 | SquishFlags method = flags & (SquishFlags.kDxt1 | SquishFlags.kDxt5); 70 | SquishFlags fit = flags & (SquishFlags.kColourIterativeClusterFit | SquishFlags.kColourClusterFit | SquishFlags.kColourRangeFit); 71 | SquishFlags metric = flags & (SquishFlags.kColourMetricPerceptual | SquishFlags.kColourMetricUniform); 72 | SquishFlags extra = flags & SquishFlags.kWeightColourByAlpha; 73 | 74 | // set defaults 75 | if (method != SquishFlags.kDxt3 && method != SquishFlags.kDxt5) 76 | method = SquishFlags.kDxt1; 77 | if (fit != SquishFlags.kColourRangeFit) 78 | fit = SquishFlags.kColourClusterFit; 79 | if (metric != SquishFlags.kColourMetricUniform) 80 | metric = SquishFlags.kColourMetricPerceptual; 81 | 82 | // done 83 | return method | fit | metric | extra; 84 | } 85 | 86 | unsafe void Compress(byte[] rgba, byte* block, SquishFlags flags) 87 | { 88 | // compress with full mask 89 | CompressMasked(rgba, 0xffff, block, flags); 90 | } 91 | 92 | static unsafe void CompressMasked(byte[] rgba, int mask, byte* pBlock, SquishFlags flags) 93 | { 94 | // fix any bad flags 95 | flags = FixFlags(flags); 96 | 97 | 98 | // get the block locations 99 | byte* colourBlock = pBlock; 100 | byte* alphaBock = pBlock; 101 | if ((flags & (SquishFlags.kDxt3 | SquishFlags.kDxt5)) != 0) 102 | colourBlock = pBlock + 8; 103 | 104 | // create the minimal point set 105 | ColourSet colours = new ColourSet(rgba, mask, flags); 106 | 107 | // check the compression type and compress colour 108 | if (colours.GetCount() == 1) 109 | { 110 | // always do a single colour fit 111 | SingleColourFit fit = new SingleColourFit(colours, flags); 112 | fit.Compress(colourBlock); 113 | } 114 | else if ((flags & SquishFlags.kColourRangeFit) != 0 || colours.GetCount() == 0) 115 | { 116 | // do a range fit 117 | RangeFit fit = new RangeFit(colours, flags); 118 | fit.Compress(colourBlock); 119 | } 120 | else 121 | { 122 | // default to a cluster fit (could be iterative or not) 123 | ClusterFit fit = new ClusterFit(colours, flags); 124 | fit.Compress(colourBlock); 125 | } 126 | 127 | // compress alpha separately if necessary 128 | if ((flags & SquishFlags.kDxt3) != 0) 129 | { 130 | alpha.CompressAlphaDxt3(rgba, mask, alphaBock); 131 | } 132 | else if ((flags & SquishFlags.kDxt5) != 0) 133 | { 134 | alpha.CompressAlphaDxt5(rgba, mask, alphaBock); 135 | } 136 | } 137 | 138 | /* 139 | void Decompress( u8* rgba, void const* block, int flags ) 140 | { 141 | // fix any bad flags 142 | flags = FixFlags( flags ); 143 | 144 | // get the block locations 145 | void const* colourBlock = block; 146 | void const* alphaBock = block; 147 | if( ( flags & ( kDxt3 | kDxt5 ) ) != 0 ) 148 | colourBlock = reinterpret_cast< u8 const* >( block ) + 8; 149 | 150 | // decompress colour 151 | DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 ); 152 | 153 | // decompress alpha separately if necessary 154 | if( ( flags & kDxt3 ) != 0 ) 155 | DecompressAlphaDxt3( rgba, alphaBock ); 156 | else if( ( flags & kDxt5 ) != 0 ) 157 | DecompressAlphaDxt5( rgba, alphaBock ); 158 | } 159 | */ 160 | public static int GetStorageRequirements(int width, int height, SquishFlags flags) 161 | { 162 | // fix any bad flags 163 | flags = FixFlags(flags); 164 | 165 | // compute the storage requirements 166 | int blockcount = ((width + 3) / 4) * ((height + 3) / 4); 167 | int blocksize = ((flags & SquishFlags.kDxt1) != 0) ? 8 : 16; 168 | return blockcount * blocksize; 169 | } 170 | 171 | public static unsafe void CompressImage(byte[] rgba, int width, int height, byte[] blocks, SquishFlags flags, bool waitOnDone) 172 | { 173 | // fix any bad flags 174 | flags = FixFlags(flags); 175 | 176 | // holds the handles to know which thread are free. 177 | // No more than 50 or Mono commplains. 178 | // On my machine Environment.ProcessorCount give me a nice 98% CPU 179 | ManualResetEvent[] doneEvents = new ManualResetEvent[Environment.ProcessorCount]; 180 | for (int i = 0; i < doneEvents.Length; i++) 181 | { 182 | doneEvents[i] = new ManualResetEvent(true); 183 | } 184 | 185 | // initialise the block output 186 | fixed (byte* pblocks = blocks, prgba = rgba) 187 | { 188 | int bytesPerBlock = ((flags & SquishFlags.kDxt1) != 0) ? 8 : 16; 189 | byte* targetBlock = pblocks; 190 | 191 | // loop over blocks 192 | for (int y = 0; y < height; y += 4) 193 | { 194 | int threadIdx = GetFreeThreadIdx(doneEvents); 195 | doneEvents[threadIdx] = new ManualResetEvent(false); 196 | 197 | CompressImageBlockLineArgs args = new CompressImageBlockLineArgs(width, height, flags, y, prgba, targetBlock, bytesPerBlock, doneEvents[threadIdx]); 198 | targetBlock += bytesPerBlock * ((width >> 2) + ((width & 0x3) != 0 ? 1 : 0)); 199 | 200 | // To debug un comment this line and comment the next one 201 | // Threads catch the exceptions (add a try catch ? ) 202 | //CompressImageBlockLineThread(args); 203 | if (waitOnDone && y > (4*Environment.ProcessorCount)) 204 | { 205 | WaitHandle.WaitAny(doneEvents); 206 | } 207 | ThreadPool.QueueUserWorkItem(CompressImageBlockLineThread, args); 208 | } 209 | WaitHandle.WaitAll(doneEvents); 210 | } 211 | } 212 | 213 | private static int GetFreeThreadIdx(ManualResetEvent[] doneEvents) 214 | { 215 | for (int i = 0; i < doneEvents.Length; i++) 216 | { 217 | if (doneEvents[i].WaitOne(0)) 218 | { 219 | return i; 220 | } 221 | } 222 | return WaitHandle.WaitAny(doneEvents); 223 | } 224 | 225 | private unsafe class CompressImageBlockLineArgs 226 | { 227 | 228 | public int width; 229 | public int height; 230 | public SquishFlags flags; 231 | public int y; 232 | public byte* prgba; 233 | public byte* targetBlock; 234 | public int bytesPerBlock; 235 | public ManualResetEvent doneEvent; 236 | 237 | public CompressImageBlockLineArgs( 238 | int width, 239 | int height, 240 | SquishFlags flags, 241 | int y, 242 | byte* prgba, 243 | byte* targetBlock, 244 | int bytesPerBlock, 245 | ManualResetEvent doneEvent) 246 | { 247 | this.width = width; 248 | this.height = height; 249 | this.flags = flags; 250 | this.y = y; 251 | this.prgba = prgba; 252 | this.targetBlock = targetBlock; 253 | this.bytesPerBlock = bytesPerBlock; 254 | this.doneEvent = doneEvent; 255 | } 256 | } 257 | 258 | private static unsafe void CompressImageBlockLineThread(Object obj) 259 | { 260 | CompressImageBlockLineArgs args = (CompressImageBlockLineArgs)obj; 261 | CompressImageBlockLine(args.width, args.height, args.flags, args.y, args.prgba, args.targetBlock, args.bytesPerBlock); 262 | args.doneEvent.Set(); 263 | } 264 | 265 | private static unsafe void CompressImageBlockLine(int width, int height, SquishFlags flags, int y, byte* prgba, byte* targetBlockPtr, int bytesPerBlock) 266 | { 267 | byte* targetBlock = targetBlockPtr; 268 | for (int x = 0; x < width; x += 4) 269 | { 270 | // build the 4x4 block of pixels 271 | byte[] sourceRgba = new byte[16 * 4]; 272 | fixed (byte* psourceRgba = sourceRgba) 273 | { 274 | byte* targetPixel = psourceRgba; 275 | int mask = 0; 276 | for (int py = 0; py < 4; ++py) 277 | { 278 | for (int px = 0; px < 4; ++px) 279 | { 280 | // get the source pixel in the image 281 | int sx = x + px; 282 | int sy = y + py; 283 | 284 | // enable if we're in the image 285 | if (sx < width && sy < height) 286 | { 287 | // copy the rgba value 288 | byte* sourcePixel = prgba + 4 * (width * sy + sx); 289 | for (int i = 0; i < 4; ++i) 290 | { 291 | *targetPixel++ = *sourcePixel++; 292 | } 293 | 294 | // enable this pixel 295 | mask |= (1 << (4 * py + px)); 296 | } 297 | else 298 | { 299 | // skip this pixel as its outside the image 300 | targetPixel += 4; 301 | } 302 | } 303 | } 304 | 305 | // compress it into the output 306 | CompressMasked(sourceRgba, mask, targetBlock, flags); 307 | } 308 | // advance 309 | targetBlock += bytesPerBlock; 310 | } 311 | } 312 | 313 | /* 314 | void DecompressImage( u8* rgba, int width, int height, void const* blocks, int flags ) 315 | { 316 | // fix any bad flags 317 | flags = FixFlags( flags ); 318 | 319 | // initialise the block input 320 | u8 const* sourceBlock = reinterpret_cast< u8 const* >( blocks ); 321 | int bytesPerBlock = ( ( flags & kDxt1 ) != 0 ) ? 8 : 16; 322 | 323 | // loop over blocks 324 | for( int y = 0; y < height; y += 4 ) 325 | { 326 | for( int x = 0; x < width; x += 4 ) 327 | { 328 | // decompress the block 329 | u8 targetRgba[4*16]; 330 | Decompress( targetRgba, sourceBlock, flags ); 331 | 332 | // write the decompressed pixels to the correct image locations 333 | u8 const* sourcePixel = targetRgba; 334 | for( int py = 0; py < 4; ++py ) 335 | { 336 | for( int px = 0; px < 4; ++px ) 337 | { 338 | // get the target location 339 | int sx = x + px; 340 | int sy = y + py; 341 | if( sx < width && sy < height ) 342 | { 343 | u8* targetPixel = rgba + 4*( width*sy + sx ); 344 | 345 | // copy the rgba value 346 | for( int i = 0; i < 4; ++i ) 347 | *targetPixel++ = *sourcePixel++; 348 | } 349 | else 350 | { 351 | // skip this pixel as its outside the image 352 | sourcePixel += 4; 353 | } 354 | } 355 | } 356 | 357 | // advance 358 | sourceBlock += bytesPerBlock; 359 | } 360 | } 361 | }*/ 362 | } 363 | } 364 | -------------------------------------------------------------------------------- /LibSquishPort/alpha.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | 30 | namespace LibSquishPort 31 | { 32 | class alpha 33 | { 34 | static int FloatToInt(float a, int limit) 35 | { 36 | // use ANSI round-to-zero behaviour to get round-to-nearest 37 | int i = (int)(a + 0.5f); 38 | 39 | // clamp to the limit 40 | if (i < 0) 41 | i = 0; 42 | else if (i > limit) 43 | i = limit; 44 | 45 | // done 46 | return i; 47 | } 48 | 49 | public static unsafe void CompressAlphaDxt3(byte[] rgba, int mask, byte* block) 50 | { 51 | byte* bytes = block; 52 | 53 | // quantise and pack the alpha values pairwise 54 | for (int i = 0; i < 8; ++i) 55 | { 56 | // quantise down to 4 bits 57 | float alpha1 = (float)rgba[8 * i + 3] * (15.0f / 255.0f); 58 | float alpha2 = (float)rgba[8 * i + 7] * (15.0f / 255.0f); 59 | int quant1 = FloatToInt(alpha1, 15); 60 | int quant2 = FloatToInt(alpha2, 15); 61 | 62 | // set alpha to zero where masked 63 | int bit1 = 1 << (2 * i); 64 | int bit2 = 1 << (2 * i + 1); 65 | if ((mask & bit1) == 0) 66 | quant1 = 0; 67 | if ((mask & bit2) == 0) 68 | quant2 = 0; 69 | 70 | // pack into the byte 71 | bytes[i] = (byte)(quant1 | (quant2 << 4)); 72 | } 73 | } 74 | 75 | public unsafe void DecompressAlphaDxt3(byte[] rgba, byte* block) 76 | { 77 | byte* bytes = block; 78 | 79 | // unpack the alpha values pairwise 80 | for (int i = 0; i < 8; ++i) 81 | { 82 | // quantise down to 4 bits 83 | byte quant = bytes[i]; 84 | 85 | // unpack the values 86 | byte lo = (byte)(quant & 0x0f); 87 | byte hi = (byte)(quant & 0xf0); 88 | 89 | // convert back up to bytes 90 | rgba[8 * i + 3] = (byte)(lo | (lo << 4)); 91 | rgba[8 * i + 7] = (byte)(hi | (hi >> 4)); 92 | } 93 | } 94 | 95 | static void FixRange(ref int min, ref int max, int steps) 96 | { 97 | if (max - min < steps) 98 | max = Math.Min(min + steps, 255); 99 | if (max - min < steps) 100 | min = Math.Max(0, max - steps); 101 | } 102 | 103 | static int FitCodes(byte[] rgba, int mask, byte[] codes, byte[] indices) 104 | { 105 | // fit each alpha value to the codebook 106 | int err = 0; 107 | for (int i = 0; i < 16; ++i) 108 | { 109 | // check this pixel is valid 110 | int bit = 1 << i; 111 | if ((mask & bit) == 0) 112 | { 113 | // use the first code 114 | indices[i] = 0; 115 | continue; 116 | } 117 | 118 | // find the least error and corresponding index 119 | int value = rgba[4 * i + 3]; 120 | int least = int.MaxValue; 121 | int index = 0; 122 | for (int j = 0; j < 8; ++j) 123 | { 124 | // get the squared error from this code 125 | int dist = (int)value - (int)codes[j]; 126 | dist *= dist; 127 | 128 | // compare with the best so far 129 | if (dist < least) 130 | { 131 | least = dist; 132 | index = j; 133 | } 134 | } 135 | 136 | // save this index and accumulate the error 137 | indices[i] = (byte)index; 138 | err += least; 139 | } 140 | 141 | // return the total error 142 | return err; 143 | } 144 | 145 | public unsafe static void WriteAlphaBlock(int alpha0, int alpha1, byte[] indices, byte* block) 146 | { 147 | byte* bytes = block; 148 | 149 | // write the first two bytes 150 | bytes[0] = (byte)alpha0; 151 | bytes[1] = (byte)alpha1; 152 | 153 | // pack the indices with 3 bits each 154 | byte* dest = bytes + 2; 155 | int src = 0; 156 | for (int i = 0; i < 2; ++i) 157 | { 158 | // pack 8 3-bit values 159 | int value = 0; 160 | for (int j = 0; j < 8; ++j) 161 | { 162 | int index = indices[src++]; 163 | value |= (index << 3 * j); 164 | } 165 | 166 | // store in 3 bytes 167 | for (int j = 0; j < 3; ++j) 168 | { 169 | int u8 = (value >> 8 * j) & 0xff; 170 | *dest++ = (byte)u8; 171 | } 172 | } 173 | } 174 | 175 | public unsafe static void WriteAlphaBlock5(int alpha0, int alpha1, byte[] indices, byte* block) 176 | { 177 | // check the relative values of the endpoints 178 | if (alpha0 > alpha1) 179 | { 180 | // swap the indices 181 | byte[] swapped = new byte[16]; 182 | for (int i = 0; i < 16; ++i) 183 | { 184 | byte index = indices[i]; 185 | if (index == 0) 186 | swapped[i] = 1; 187 | else if (index == 1) 188 | swapped[i] = 0; 189 | else if (index <= 5) 190 | swapped[i] = (byte)(7 - index); 191 | else 192 | swapped[i] = index; 193 | } 194 | 195 | // write the block 196 | WriteAlphaBlock(alpha1, alpha0, swapped, block); 197 | } 198 | else 199 | { 200 | // write the block 201 | WriteAlphaBlock(alpha0, alpha1, indices, block); 202 | } 203 | } 204 | 205 | public unsafe static void WriteAlphaBlock7(int alpha0, int alpha1, byte[] indices, byte* block) 206 | { 207 | // check the relative values of the endpoints 208 | if (alpha0 < alpha1) 209 | { 210 | // swap the indices 211 | byte[] swapped = new byte[16]; 212 | for (int i = 0; i < 16; ++i) 213 | { 214 | byte index = indices[i]; 215 | if (index == 0) 216 | swapped[i] = 1; 217 | else if (index == 1) 218 | swapped[i] = 0; 219 | else 220 | swapped[i] = (byte)(9 - index); 221 | } 222 | 223 | // write the block 224 | WriteAlphaBlock(alpha1, alpha0, swapped, block); 225 | } 226 | else 227 | { 228 | // write the block 229 | WriteAlphaBlock(alpha0, alpha1, indices, block); 230 | } 231 | } 232 | 233 | public static unsafe void CompressAlphaDxt5(byte[] rgba, int mask, byte* block) 234 | { 235 | // get the range for 5-alpha and 7-alpha interpolation 236 | int min5 = 255; 237 | int max5 = 0; 238 | int min7 = 255; 239 | int max7 = 0; 240 | for (int i = 0; i < 16; ++i) 241 | { 242 | // check this pixel is valid 243 | int bit = 1 << i; 244 | if ((mask & bit) == 0) 245 | continue; 246 | 247 | // incorporate into the min/max 248 | int value = rgba[4 * i + 3]; 249 | if (value < min7) 250 | min7 = value; 251 | if (value > max7) 252 | max7 = value; 253 | if (value != 0 && value < min5) 254 | min5 = value; 255 | if (value != 255 && value > max5) 256 | max5 = value; 257 | } 258 | 259 | // handle the case that no valid range was found 260 | if (min5 > max5) 261 | min5 = max5; 262 | if (min7 > max7) 263 | min7 = max7; 264 | 265 | // fix the range to be the minimum in each case 266 | FixRange(ref min5, ref max5, 5); 267 | FixRange(ref min7, ref max7, 7); 268 | 269 | // set up the 5-alpha code book 270 | byte[] codes5 = new byte[8]; 271 | codes5[0] = (byte)min5; 272 | codes5[1] = (byte)max5; 273 | for (int i = 1; i < 5; ++i) 274 | codes5[1 + i] = (byte)(((5 - i) * min5 + i * max5) / 5); 275 | codes5[6] = 0; 276 | codes5[7] = 255; 277 | 278 | // set up the 7-alpha code book 279 | byte[] codes7 = new byte[8]; 280 | codes7[0] = (byte)min7; 281 | codes7[1] = (byte)max7; 282 | for (int i = 1; i < 7; ++i) 283 | codes7[1 + i] = (byte)(((7 - i) * min7 + i * max7) / 7); 284 | 285 | // fit the data to both code books 286 | byte[] indices5 = new byte[16]; 287 | byte[] indices7 = new byte[16]; 288 | int err5 = FitCodes(rgba, mask, codes5, indices5); 289 | int err7 = FitCodes(rgba, mask, codes7, indices7); 290 | 291 | // save the block with least error 292 | if (err5 <= err7) 293 | WriteAlphaBlock5(min5, max5, indices5, block); 294 | else 295 | WriteAlphaBlock7(min7, max7, indices7, block); 296 | } 297 | 298 | public unsafe void DecompressAlphaDxt5(byte[] rgba, byte* block) 299 | { 300 | // get the two alpha values 301 | byte* bytes = block; 302 | int alpha0 = bytes[0]; 303 | int alpha1 = bytes[1]; 304 | 305 | // compare the values to build the codebook 306 | byte[] codes = new byte[8]; 307 | codes[0] = (byte)alpha0; 308 | codes[1] = (byte)alpha1; 309 | if (alpha0 <= alpha1) 310 | { 311 | // use 5-alpha codebook 312 | for (int i = 1; i < 5; ++i) 313 | codes[1 + i] = (byte)(((5 - i) * alpha0 + i * alpha1) / 5); 314 | codes[6] = 0; 315 | codes[7] = 255; 316 | } 317 | else 318 | { 319 | // use 7-alpha codebook 320 | for (int i = 1; i < 7; ++i) 321 | codes[1 + i] = (byte)(((7 - i) * alpha0 + i * alpha1) / 7); 322 | } 323 | 324 | // decode the indices 325 | byte[] indices = new byte[16]; 326 | byte* src = bytes + 2; 327 | int dest = 0; 328 | for (int i = 0; i < 2; ++i) 329 | { 330 | // grab 3 bytes 331 | int value = 0; 332 | for (int j = 0; j < 3; ++j) 333 | { 334 | int u8 = *src++; 335 | value |= (u8 << 8 * j); 336 | } 337 | 338 | // unpack 8 3-bit values from it 339 | for (int j = 0; j < 8; ++j) 340 | { 341 | int index = (value >> 3 * j) & 0x7; 342 | indices[dest++] = (byte)index; 343 | } 344 | } 345 | 346 | // write out the indexed codebook values 347 | for (int i = 0; i < 16; ++i) 348 | rgba[4 * i + 3] = codes[indices[i]]; 349 | } 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /LibSquishPort/colorblock.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Linq; 29 | using System.Text; 30 | using UnityEngine; 31 | 32 | namespace LibSquishPort { 33 | 34 | public static class colorblock 35 | { 36 | private static void swap(ref T a, ref T b) 37 | { 38 | T atmp = a; 39 | a = b; 40 | b = atmp; 41 | } 42 | 43 | static int FloatToInt( float a, int limit ) 44 | { 45 | // use ANSI round-to-zero behaviour to get round-to-nearest 46 | int i = ( int )( a + 0.5f ); 47 | 48 | // clamp to the limit 49 | if( i < 0 ) 50 | i = 0; 51 | else if( i > limit ) 52 | i = limit; 53 | 54 | // done 55 | return i; 56 | } 57 | 58 | static int FloatTo565( Vector3 colour ) 59 | { 60 | // get the components in the correct range 61 | int r = FloatToInt( 31.0f*colour.x, 31 ); 62 | int g = FloatToInt( 63.0f*colour.y, 63 ); 63 | int b = FloatToInt( 31.0f*colour.z, 31 ); 64 | 65 | // pack into a single value 66 | return ( r << 11 ) | ( g << 5 ) | b; 67 | } 68 | 69 | static unsafe void WriteColourBlock( int a, int b, byte[] indices, byte* block ) 70 | { 71 | // get the block as bytes 72 | byte* bytes = block; 73 | 74 | // write the endpoints 75 | bytes[0] = ( byte )( a & 0xff ); 76 | bytes[1] = ( byte )( a >> 8 ); 77 | bytes[2] = ( byte )( b & 0xff ); 78 | bytes[3] = ( byte )( b >> 8 ); 79 | 80 | // write the indices 81 | for( int i = 0; i < 4; ++i ) 82 | { 83 | fixed (byte* pindices= indices) 84 | { 85 | byte * ind = pindices + 4*i; 86 | bytes[4 + i] = (byte)(ind[0] | ( ind[1] << 2 ) | ( ind[2] << 4 ) | ( ind[3] << 6 )); 87 | } 88 | } 89 | } 90 | 91 | public static unsafe void WriteColourBlock3( Vector3 start, Vector3 end, byte[] indices, byte* block ) 92 | { 93 | // get the packed values 94 | int a = FloatTo565( start ); 95 | int b = FloatTo565( end ); 96 | 97 | // remap the indices 98 | byte[] remapped = new byte[16]; 99 | if( a <= b ) 100 | { 101 | // use the indices directly 102 | for( int i = 0; i < 16; ++i ) 103 | remapped[i] = indices[i]; 104 | } 105 | else 106 | { 107 | // swap a and b 108 | swap( ref a, ref b ); 109 | for( int i = 0; i < 16; ++i ) 110 | { 111 | if( indices[i] == 0 ) 112 | remapped[i] = 1; 113 | else if( indices[i] == 1 ) 114 | remapped[i] = 0; 115 | else 116 | remapped[i] = indices[i]; 117 | } 118 | } 119 | 120 | // write the block 121 | WriteColourBlock( a, b, remapped, block ); 122 | } 123 | 124 | public static unsafe void WriteColourBlock4( Vector3 start, Vector3 end, byte[] indices, byte* block ) 125 | { 126 | // get the packed values 127 | int a = FloatTo565( start ); 128 | int b = FloatTo565( end ); 129 | 130 | // remap the indices 131 | byte[] remapped = new byte[16]; 132 | if( a < b ) 133 | { 134 | // swap a and b 135 | swap( ref a, ref b ); 136 | for( int i = 0; i < 16; ++i ) 137 | remapped[i] = (byte)(( indices[i] ^ 0x1 ) & 0x3); 138 | } 139 | else if( a == b ) 140 | { 141 | // use index 0 142 | for( int i = 0; i < 16; ++i ) 143 | remapped[i] = 0; 144 | } 145 | else 146 | { 147 | // use the indices directly 148 | for( int i = 0; i < 16; ++i ) 149 | remapped[i] = indices[i]; 150 | } 151 | 152 | // write the block 153 | WriteColourBlock( a, b, remapped, block ); 154 | } 155 | 156 | static unsafe int Unpack565( byte* packed, byte* colour ) 157 | { 158 | // build the packed value 159 | int value = ( int )packed[0] | ( ( int )packed[1] << 8 ); 160 | 161 | // get the components in the stored range 162 | byte red = ( byte )( ( value >> 11 ) & 0x1f ); 163 | byte green = ( byte )( ( value >> 5 ) & 0x3f ); 164 | byte blue = ( byte )( value & 0x1f ); 165 | 166 | // scale up to 8 bits 167 | colour[0] = (byte)(( red << 3 ) | ( red >> 2 )); 168 | colour[1] = (byte)(( green << 2 ) | ( green >> 4 )); 169 | colour[2] = (byte)(( blue << 3 ) | ( blue >> 2 )); 170 | colour[3] = 255; 171 | 172 | // return the value 173 | return value; 174 | } 175 | 176 | public static unsafe void DecompressColour( byte[] rgba, byte[] block, bool isDxt1 ) 177 | { 178 | // unpack the endpoints 179 | byte[] codes = new byte[16]; 180 | 181 | int a, b; 182 | // get the block bytes 183 | fixed (byte* bytes = block, pcodes = codes ) 184 | { 185 | 186 | a = Unpack565( bytes, pcodes ); 187 | b = Unpack565( bytes + 2, pcodes + 4 ); 188 | } 189 | // generate the midpoints 190 | for( int i = 0; i < 3; ++i ) 191 | { 192 | int c = codes[i]; 193 | int d = codes[4 + i]; 194 | 195 | if( isDxt1 && a <= b ) 196 | { 197 | codes[8 + i] = ( byte )( ( c + d )/2 ); 198 | codes[12 + i] = 0; 199 | } 200 | else 201 | { 202 | codes[8 + i] = ( byte )( ( 2*c + d )/3 ); 203 | codes[12 + i] = ( byte )( ( c + 2*d )/3 ); 204 | } 205 | } 206 | 207 | // fill in alpha for the intermediate values 208 | codes[8 + 3] = 255; 209 | codes[12 + 3] = (byte)(( isDxt1 && a <= b ) ? 0 : 255); 210 | 211 | // unpack the indices 212 | byte[] indices = new byte[16]; 213 | for( int i = 0; i < 4; ++i ) 214 | { 215 | fixed (byte* pindices = indices) 216 | { 217 | byte* ind = pindices + 4 * i; 218 | byte packed = block[4 + i]; 219 | 220 | ind[0] = (byte)(packed & 0x3); 221 | ind[1] = (byte)((packed >> 2) & 0x3); 222 | ind[2] = (byte)((packed >> 4) & 0x3); 223 | ind[3] = (byte)((packed >> 6) & 0x3); 224 | } 225 | } 226 | 227 | // store out the colours 228 | for( int i = 0; i < 16; ++i ) 229 | { 230 | byte offset = (byte)(4*indices[i]); 231 | for( int j = 0; j < 4; ++j ) 232 | rgba[4*i + j] = codes[offset + j]; 233 | } 234 | } 235 | } 236 | } // namespace squish 237 | 238 | -------------------------------------------------------------------------------- /LibSquishPort/colorfit.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | 30 | namespace LibSquishPort 31 | { 32 | class ColourFit 33 | { 34 | public ColourSet m_colours; 35 | public SquishFlags m_flags; 36 | 37 | public virtual unsafe void Compress3( byte* block ){} 38 | public virtual unsafe void Compress4( byte* block ){} 39 | 40 | public ColourFit(ColourSet colours, SquishFlags flags) 41 | { 42 | m_colours = colours; 43 | m_flags = flags; 44 | } 45 | 46 | public unsafe void Compress( byte* block ) 47 | { 48 | bool isDxt1 = ((m_flags & SquishFlags.kDxt1) != 0); 49 | if( isDxt1 ) 50 | { 51 | Compress3( block ); 52 | if( !m_colours.IsTransparent() ) 53 | Compress4( block ); 54 | } 55 | else 56 | Compress4( block ); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /LibSquishPort/colourset.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Linq; 29 | using System.Text; 30 | using UnityEngine; 31 | 32 | namespace LibSquishPort 33 | { 34 | class ColourSet 35 | { 36 | int m_count; 37 | Vector3[] m_points = new Vector3[16]; 38 | float[] m_weights = new float[16]; 39 | int[] m_remap = new int[16]; 40 | bool m_transparent; 41 | 42 | public int GetCount() { return m_count; } 43 | public Vector3[] GetPoints() { return m_points; } 44 | public float[] GetWeights() { return m_weights; } 45 | public bool IsTransparent() { return m_transparent; } 46 | 47 | public ColourSet(byte[] rgba, int mask, SquishFlags flags) 48 | { 49 | m_count = 0; 50 | m_transparent = false; 51 | 52 | // check the compression mode for dxt1 53 | bool isDxt1 = ((flags & SquishFlags.kDxt1) != 0); 54 | bool weightByAlpha = ((flags & SquishFlags.kWeightColourByAlpha) != 0); 55 | 56 | // create the minimal set 57 | for (int i = 0; i < 16; ++i) 58 | { 59 | // check this pixel is enabled 60 | int bit = 1 << i; 61 | if ((mask & bit) == 0) 62 | { 63 | m_remap[i] = -1; 64 | continue; 65 | } 66 | 67 | // check for transparent pixels when using dxt1 68 | if (isDxt1 && rgba[4 * i + 3] < 128) 69 | { 70 | m_remap[i] = -1; 71 | m_transparent = true; 72 | continue; 73 | } 74 | 75 | // loop over previous points for a match 76 | for (int j = 0; ; ++j) 77 | { 78 | // allocate a new point 79 | if (j == i) 80 | { 81 | // normalise coordinates to [0,1] 82 | float x = (float)rgba[4 * i] / 255.0f; 83 | float y = (float)rgba[4 * i + 1] / 255.0f; 84 | float z = (float)rgba[4 * i + 2] / 255.0f; 85 | 86 | // ensure there is always non-zero weight even for zero alpha 87 | float w = (float)(rgba[4 * i + 3] + 1) / 256.0f; 88 | 89 | // add the point 90 | m_points[m_count] = new Vector3(x, y, z); 91 | m_weights[m_count] = (weightByAlpha ? w : 1.0f); 92 | m_remap[i] = m_count; 93 | 94 | // advance 95 | ++m_count; 96 | break; 97 | } 98 | 99 | // check for a match 100 | int oldbit = 1 << j; 101 | bool match = ((mask & oldbit) != 0) 102 | && (rgba[4 * i] == rgba[4 * j]) 103 | && (rgba[4 * i + 1] == rgba[4 * j + 1]) 104 | && (rgba[4 * i + 2] == rgba[4 * j + 2]) 105 | && (rgba[4 * j + 3] >= 128 || !isDxt1); 106 | if (match) 107 | { 108 | // get the index of the match 109 | int index = m_remap[j]; 110 | 111 | // ensure there is always non-zero weight even for zero alpha 112 | float w = (float)(rgba[4 * i + 3] + 1) / 256.0f; 113 | 114 | // map to this point and increase the weight 115 | m_weights[index] += (weightByAlpha ? w : 1.0f); 116 | m_remap[i] = index; 117 | break; 118 | } 119 | } 120 | } 121 | 122 | // square root the weights 123 | for (int i = 0; i < m_count; ++i) 124 | m_weights[i] = Mathf.Sqrt(m_weights[i]); 125 | } 126 | 127 | public void RemapIndices(byte[] source, byte[] target) 128 | { 129 | for (int i = 0; i < 16; ++i) 130 | { 131 | int j = m_remap[i]; 132 | if (j == -1) 133 | target[i] = 3; 134 | else 135 | target[i] = source[j]; 136 | } 137 | } 138 | 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /LibSquishPort/math.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | /*! @file 27 | 28 | The symmetric eigensystem solver algorithm is from 29 | http://www.geometrictools.com/Documentation/EigenSymmetric3x3.pdf 30 | */ 31 | using System; 32 | using System.Collections.Generic; 33 | using System.Linq; 34 | using System.Text; 35 | using UnityEngine; 36 | 37 | namespace LibSquishPort 38 | { 39 | 40 | public class Sym3x3 41 | { 42 | float[] m_x = new float[6]; 43 | 44 | public Sym3x3() 45 | { 46 | } 47 | 48 | public Sym3x3(float s) 49 | { 50 | for (int i = 0; i < 6; ++i) 51 | m_x[i] = s; 52 | } 53 | 54 | public float this[int index] 55 | { 56 | get 57 | { 58 | return m_x[index]; 59 | } 60 | 61 | set 62 | { 63 | m_x[index] = value; 64 | } 65 | } 66 | 67 | } 68 | 69 | public static class math 70 | { 71 | public static Sym3x3 ComputeWeightedCovariance(int n, Vector3[] points, float[] weights) 72 | { 73 | // compute the centroid 74 | float total = 0.0f; 75 | Vector3 centroid = Vector3.zero; 76 | for (int i = 0; i < n; ++i) 77 | { 78 | total += weights[i]; 79 | centroid += weights[i] * points[i]; 80 | } 81 | centroid /= total; 82 | 83 | // accumulate the covariance matrix 84 | Sym3x3 covariance = new Sym3x3(); 85 | for (int i = 0; i < n; ++i) 86 | { 87 | Vector3 a = points[i] - centroid; 88 | Vector3 b = weights[i] * a; 89 | 90 | covariance[0] += a.x * b.x; 91 | covariance[1] += a.x * b.y; 92 | covariance[2] += a.x * b.z; 93 | covariance[3] += a.y * b.y; 94 | covariance[4] += a.y * b.z; 95 | covariance[5] += a.z * b.z; 96 | } 97 | 98 | // return it 99 | return covariance; 100 | } 101 | 102 | public static Vector3 GetMultiplicity1Evector(Sym3x3 matrix, float evalue) 103 | { 104 | // compute M 105 | Sym3x3 m = new Sym3x3(); 106 | m[0] = matrix[0] - evalue; 107 | m[1] = matrix[1]; 108 | m[2] = matrix[2]; 109 | m[3] = matrix[3] - evalue; 110 | m[4] = matrix[4]; 111 | m[5] = matrix[5] - evalue; 112 | 113 | // compute U 114 | Sym3x3 u = new Sym3x3(); 115 | u[0] = m[3] * m[5] - m[4] * m[4]; 116 | u[1] = m[2] * m[4] - m[1] * m[5]; 117 | u[2] = m[1] * m[4] - m[2] * m[3]; 118 | u[3] = m[0] * m[5] - m[2] * m[2]; 119 | u[4] = m[1] * m[2] - m[4] * m[0]; 120 | u[5] = m[0] * m[3] - m[1] * m[1]; 121 | 122 | // find the largest component 123 | float mc = Mathf.Abs(u[0]); 124 | int mi = 0; 125 | for (int i = 1; i < 6; ++i) 126 | { 127 | float c = Mathf.Abs(u[i]); 128 | if (c > mc) 129 | { 130 | mc = c; 131 | mi = i; 132 | } 133 | } 134 | 135 | // pick the column with this component 136 | switch (mi) 137 | { 138 | case 0: 139 | return new Vector3(u[0], u[1], u[2]); 140 | 141 | case 1: 142 | case 3: 143 | return new Vector3(u[1], u[3], u[4]); 144 | 145 | default: 146 | return new Vector3(u[2], u[4], u[5]); 147 | } 148 | } 149 | 150 | public static Vector3 GetMultiplicity2Evector(Sym3x3 matrix, float evalue) 151 | { 152 | // compute M 153 | Sym3x3 m = new Sym3x3(); 154 | m[0] = matrix[0] - evalue; 155 | m[1] = matrix[1]; 156 | m[2] = matrix[2]; 157 | m[3] = matrix[3] - evalue; 158 | m[4] = matrix[4]; 159 | m[5] = matrix[5] - evalue; 160 | 161 | // find the largest component 162 | float mc = Mathf.Abs(m[0]); 163 | int mi = 0; 164 | for (int i = 1; i < 6; ++i) 165 | { 166 | float c = Mathf.Abs(m[i]); 167 | if (c > mc) 168 | { 169 | mc = c; 170 | mi = i; 171 | } 172 | } 173 | 174 | // pick the first eigenvector based on this index 175 | switch (mi) 176 | { 177 | case 0: 178 | case 1: 179 | return new Vector3(-m[1], m[0], 0.0f); 180 | 181 | case 2: 182 | return new Vector3(m[2], 0.0f, -m[0]); 183 | 184 | case 3: 185 | case 4: 186 | return new Vector3(0.0f, -m[4], m[3]); 187 | 188 | default: 189 | return new Vector3(0.0f, -m[5], m[4]); 190 | } 191 | } 192 | 193 | public static Vector3 ComputePrincipleComponent(Sym3x3 matrix) 194 | { 195 | // compute the cubic coefficients 196 | float c0 = matrix[0] * matrix[3] * matrix[5] 197 | + 2.0f * matrix[1] * matrix[2] * matrix[4] 198 | - matrix[0] * matrix[4] * matrix[4] 199 | - matrix[3] * matrix[2] * matrix[2] 200 | - matrix[5] * matrix[1] * matrix[1]; 201 | float c1 = matrix[0] * matrix[3] + matrix[0] * matrix[5] + matrix[3] * matrix[5] 202 | - matrix[1] * matrix[1] - matrix[2] * matrix[2] - matrix[4] * matrix[4]; 203 | float c2 = matrix[0] + matrix[3] + matrix[5]; 204 | 205 | // compute the quadratic coefficients 206 | float a = c1 - (1.0f / 3.0f) * c2 * c2; 207 | float b = (-2.0f / 27.0f) * c2 * c2 * c2 + (1.0f / 3.0f) * c1 * c2 - c0; 208 | 209 | // compute the root count check 210 | float Q = 0.25f * b * b + (1.0f / 27.0f) * a * a * a; 211 | 212 | // test the multiplicity 213 | if (float.Epsilon < Q) 214 | { 215 | // only one root, which implies we have a multiple of the identity 216 | return Vector3.one; 217 | } 218 | else if (Q < -float.Epsilon) 219 | { 220 | // three distinct roots 221 | float theta = Mathf.Atan2(Mathf.Sqrt(-Q), -0.5f * b); 222 | float rho = Mathf.Sqrt(0.25f * b * b - Q); 223 | 224 | float rt = Mathf.Pow(rho, 1.0f / 3.0f); 225 | float ct = Mathf.Cos(theta / 3.0f); 226 | float st = Mathf.Sin(theta / 3.0f); 227 | 228 | float l1 = (1.0f / 3.0f) * c2 + 2.0f * rt * ct; 229 | float l2 = (1.0f / 3.0f) * c2 - rt * (ct + (float)Mathf.Sqrt(3.0f) * st); 230 | float l3 = (1.0f / 3.0f) * c2 - rt * (ct - (float)Mathf.Sqrt(3.0f) * st); 231 | 232 | // pick the larger 233 | if (Mathf.Abs(l2) > Mathf.Abs(l1)) 234 | l1 = l2; 235 | if (Mathf.Abs(l3) > Mathf.Abs(l1)) 236 | l1 = l3; 237 | 238 | // get the eigenvector 239 | return GetMultiplicity1Evector(matrix, l1); 240 | } 241 | else // if( -FLT_EPSILON <= Q && Q <= FLT_EPSILON ) 242 | { 243 | // two roots 244 | float rt; 245 | if (b < 0.0f) 246 | rt = -Mathf.Pow(-0.5f * b, 1.0f / 3.0f); 247 | else 248 | rt = Mathf.Pow(0.5f * b, 1.0f / 3.0f); 249 | 250 | float l1 = (1.0f / 3.0f) * c2 + rt; // repeated 251 | float l2 = (1.0f / 3.0f) * c2 - 2.0f * rt; 252 | 253 | // get the eigenvector 254 | if (Mathf.Abs(l1) > Mathf.Abs(l2)) 255 | return GetMultiplicity2Evector(matrix, l1); 256 | else 257 | return GetMultiplicity1Evector(matrix, l2); 258 | } 259 | } 260 | 261 | public static bool CompareAnyLessThan(Vector4 left, Vector4 right) 262 | { 263 | return left.x < right.x 264 | || left.y < right.y 265 | || left.z < right.z 266 | || left.w < right.w; 267 | } 268 | 269 | public static Vector4 MultiplyAdd(this Vector4 vector, Vector4 a, Vector4 b) 270 | { 271 | return Vector4.Scale(vector, a) + b; 272 | } 273 | 274 | public static Vector4 SplatX(this Vector4 vector) 275 | { 276 | return Vector4.one* vector.x; 277 | } 278 | 279 | public static Vector4 SplatY(this Vector4 vector) 280 | { 281 | return Vector4.one* vector.y; 282 | } 283 | 284 | public static Vector4 SplatZ(this Vector4 vector) 285 | { 286 | return Vector4.one* vector.z; 287 | } 288 | 289 | public static Vector4 SplatW(this Vector4 vector) 290 | { 291 | return Vector4.one* vector.w; 292 | } 293 | 294 | public static Vector4 NegativeMultiplySubtract(this Vector4 vector, Vector4 a, Vector4 b) 295 | { 296 | return b - Vector4.Scale(vector,a); 297 | } 298 | 299 | public static Vector4 Reciprocal(this Vector4 v) 300 | { 301 | return new Vector4( 302 | 1.0f / v.x, 303 | 1.0f / v.y, 304 | 1.0f / v.z, 305 | 1.0f / v.w); 306 | } 307 | 308 | public static Vector4 Truncate( this Vector4 v ) 309 | { 310 | return new Vector4( 311 | v.x > 0.0f ? Mathf.Floor( v.x ) : Mathf.Ceil( v.x ), 312 | v.y > 0.0f ? Mathf.Floor( v.y ) : Mathf.Ceil( v.y ), 313 | v.z > 0.0f ? Mathf.Floor( v.z ) : Mathf.Ceil( v.z ), 314 | v.w > 0.0f ? Mathf.Floor(v.w) : Mathf.Ceil(v.w) 315 | ); 316 | } 317 | 318 | } 319 | 320 | 321 | } 322 | -------------------------------------------------------------------------------- /LibSquishPort/rangefit.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using UnityEngine; 30 | 31 | namespace LibSquishPort 32 | { 33 | class RangeFit : ColourFit 34 | { 35 | Vector3 m_metric; 36 | Vector3 m_start; 37 | Vector3 m_end; 38 | float m_besterror; 39 | static Vector3 grid = new Vector3(31.0f, 63.0f, 31.0f); 40 | static Vector3 gridrcp = new Vector3(1.0f / 31.0f, 1.0f / 63.0f, 1.0f / 31.0f); 41 | 42 | public RangeFit( ColourSet colours, SquishFlags flags ) 43 | : base( colours, flags ) 44 | { 45 | // initialise the metric 46 | bool perceptual = ( ( m_flags & SquishFlags.kColourMetricPerceptual ) != 0 ); 47 | if( perceptual ) 48 | m_metric = new Vector3( 0.2126f, 0.7152f, 0.0722f ); 49 | else 50 | m_metric = Vector3.one; 51 | 52 | // initialise the best error 53 | m_besterror = float.MaxValue; 54 | 55 | // cache some values 56 | int count = m_colours.GetCount(); 57 | Vector3[] values = m_colours.GetPoints(); 58 | float[] weights = m_colours.GetWeights(); 59 | 60 | // get the covariance matrix 61 | Sym3x3 covariance = math.ComputeWeightedCovariance( count, values, weights ); 62 | 63 | // compute the principle component 64 | Vector3 principle = math.ComputePrincipleComponent( covariance ); 65 | 66 | // get the min and max range as the codebook endpoints 67 | Vector3 start = Vector3.zero; 68 | Vector3 end = Vector3.zero; 69 | if( count > 0 ) 70 | { 71 | float min, max; 72 | 73 | // compute the range 74 | start = end = values[0]; 75 | min = max = Vector3.Dot( values[0], principle ); 76 | for( int i = 1; i < count; ++i ) 77 | { 78 | float val = Vector3.Dot( values[i], principle ); 79 | if( val < min ) 80 | { 81 | start = values[i]; 82 | min = val; 83 | } 84 | else if( val > max ) 85 | { 86 | end = values[i]; 87 | max = val; 88 | } 89 | } 90 | } 91 | 92 | // clamp the output to [0, 1] 93 | start = Vector3.Min( Vector3.one,Vector3.Max( Vector3.zero, start ) ); 94 | end = Vector3.Min( Vector3.one, Vector3.Max( Vector3.zero, end ) ); 95 | 96 | // clamp to the grid and save 97 | 98 | Vector3 half = Vector3.one*( 0.5f ); 99 | m_start = Vector3.Scale(math.Truncate( Vector3.Scale(grid,start) + half ),gridrcp); 100 | m_end = Vector3.Scale(math.Truncate( Vector3.Scale(grid,end) + half ),gridrcp); 101 | } 102 | 103 | public override unsafe void Compress3( byte* block ) 104 | { 105 | // cache some values 106 | int count = m_colours.GetCount(); 107 | Vector3[] values = m_colours.GetPoints(); 108 | 109 | // create a codebook 110 | Vector3[] codes = new Vector3[3]; 111 | codes[0] = m_start; 112 | codes[1] = m_end; 113 | codes[2] = 0.5f*m_start + 0.5f*m_end; 114 | 115 | // match each point to the closest code 116 | byte[] closest = new byte[16]; 117 | float error = 0.0f; 118 | for( int i = 0; i < count; ++i ) 119 | { 120 | // find the closest code 121 | float dist = float.MaxValue; 122 | int idx = 0; 123 | for( int j = 0; j < 3; ++j ) 124 | { 125 | float d = Vector3.Scale( m_metric,( values[i] - codes[j] ) ).sqrMagnitude; 126 | if( d < dist ) 127 | { 128 | dist = d; 129 | idx = j; 130 | } 131 | } 132 | 133 | // save the index 134 | closest[i] = ( byte )idx; 135 | 136 | // accumulate the error 137 | error += dist; 138 | } 139 | 140 | // save this scheme if it wins 141 | if( error < m_besterror ) 142 | { 143 | // remap the indices 144 | byte[] indices = new byte[16]; 145 | m_colours.RemapIndices( closest, indices ); 146 | 147 | // save the block 148 | colorblock.WriteColourBlock3( m_start, m_end, indices, block ); 149 | 150 | // save the error 151 | m_besterror = error; 152 | } 153 | } 154 | 155 | public override unsafe void Compress4( byte* block ) 156 | { 157 | // cache some values 158 | int count = m_colours.GetCount(); 159 | Vector3[] values = m_colours.GetPoints(); 160 | 161 | // create a codebook 162 | Vector3[] codes = new Vector3[4]; 163 | codes[0] = m_start; 164 | codes[1] = m_end; 165 | codes[2] = ( 2.0f/3.0f )*m_start + ( 1.0f/3.0f )*m_end; 166 | codes[3] = ( 1.0f/3.0f )*m_start + ( 2.0f/3.0f )*m_end; 167 | 168 | // match each point to the closest code 169 | byte[] closest = new byte[16]; 170 | float error = 0.0f; 171 | for( int i = 0; i < count; ++i ) 172 | { 173 | // find the closest code 174 | float dist = float.MaxValue; 175 | int idx = 0; 176 | for( int j = 0; j < 4; ++j ) 177 | { 178 | float d = Vector3.Scale( m_metric,( values[i] - codes[j] ) ).sqrMagnitude; 179 | if( d < dist ) 180 | { 181 | dist = d; 182 | idx = j; 183 | } 184 | } 185 | 186 | // save the index 187 | closest[i] = ( byte )idx; 188 | 189 | // accumulate the error 190 | error += dist; 191 | } 192 | 193 | // save this scheme if it wins 194 | if( error < m_besterror ) 195 | { 196 | // remap the indices 197 | byte[] indices = new byte[16]; 198 | m_colours.RemapIndices( closest, indices ); 199 | 200 | // save the block 201 | colorblock.WriteColourBlock4(m_start, m_end, indices, block); 202 | 203 | // save the error 204 | m_besterror = error; 205 | } 206 | } 207 | 208 | 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /NvidiaTextureTools/Color16.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Runtime.InteropServices; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace NvidiaTextureTools 8 | { 9 | public class Color16 10 | { 11 | public Color16() { } 12 | public Color16(Color16 c) { u = c.u; } 13 | public Color16(ushort U) { u = U; } 14 | 15 | byte rb;//5 16 | byte gb;//6 17 | byte bb;//5 18 | public byte r 19 | { 20 | set 21 | { 22 | rb = value; 23 | uvalue &= 0x07FF; 24 | uvalue |= (ushort)((value) << 11); 25 | } 26 | get { return rb; } 27 | } 28 | public byte g 29 | { 30 | set 31 | { 32 | gb = value; 33 | uvalue &= 0xF8EF; 34 | uvalue |= (ushort)((value) << 5); 35 | } 36 | get { return gb; } 37 | } 38 | public byte b 39 | { 40 | set 41 | { 42 | bb = value; 43 | uvalue &= 0xFFE0; 44 | uvalue |= (ushort)((value)); 45 | } 46 | get { return bb; } 47 | } 48 | ushort uvalue; 49 | public ushort u 50 | { 51 | set 52 | { 53 | uvalue = value; 54 | rb = (byte)((value >> 11) & 0x1F); 55 | gb = (byte)((value>>5)&0x3F); 56 | bb = (byte)(value & 0x1F); 57 | } 58 | get { return uvalue; } 59 | } 60 | 61 | } 62 | 63 | public static class ColorExtensions 64 | { 65 | public static uint u(this Color32 color) 66 | { 67 | return (uint)(color.r | (color.g << 8) | (color.b << 16) | (color.a << 24)); 68 | } 69 | 70 | public static byte[] component(this Color32 color) 71 | { 72 | return new byte[4] { color.b, color.g, color.r, color.a }; 73 | } 74 | 75 | public static byte[] bytes(this Texture2D texture) 76 | { 77 | byte[] array = new byte[texture.width * texture.height * 4]; 78 | Color32[] colors = texture.GetPixels32(); 79 | for (int i = 0; i < colors.Length; i++ ) 80 | { 81 | array[i*4] = colors[i].r; 82 | array[i*4+1] = colors[i].g; 83 | array[i*4+2] = colors[i].b; 84 | array[i*4+3] = colors[i].a; 85 | } 86 | return array; 87 | } 88 | } 89 | 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /NvidiaTextureTools/ColorBlock.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2011 Ignacio Castano 2 | // Copyright (c) 2007-2009 NVIDIA Corporation -- Ignacio Castano 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using UnityEngine; 30 | 31 | namespace NvidiaTextureTools 32 | { 33 | 34 | public class ColorArray 35 | { 36 | private Color32[] m_color = new Color32[4 * 4]; 37 | public Color32[] Array 38 | { 39 | get { return m_color; } 40 | set { m_color = value; } 41 | } 42 | 43 | public Color32 this[uint i] 44 | { 45 | get { return m_color[i]; } 46 | set { m_color[i] = value; } 47 | } 48 | public Color32 this[uint x, uint y] 49 | { 50 | get { return m_color[y * 4 + x]; } 51 | set { m_color[y * 4 + x] = value; } 52 | } 53 | } 54 | 55 | /// Uncompressed 4x4 color block. 56 | public class ColorBlock 57 | { 58 | //ColorBlock(); 59 | //ColorBlock(uint * linearImage); 60 | //ColorBlock(ref ColorBlock block); 61 | //ColorBlock(Image * img, uint x, uint y); 62 | 63 | //void init(Image * img, uint x, uint y); 64 | //void init(uint w, uint h, uint[] data, uint x, uint y); 65 | //void init(uint w, uint h, float[] data, uint x, uint y); 66 | 67 | //void swizzle(uint x, uint y, uint z, uint w); // 0=r, 1=g, 2=b, 3=a, 4=0xFF, 5=0 68 | public ColorBlock() 69 | { 70 | 71 | } 72 | 73 | public bool isSingleColor() 74 | { 75 | uint u = m_color[0].u(); 76 | 77 | for (uint i = 1; i < 16; i++) 78 | { 79 | if (u != (m_color[i].u())) 80 | { 81 | return false; 82 | } 83 | } 84 | 85 | return true; 86 | } 87 | //bool hasAlpha(); 88 | 89 | 90 | // Accessors 91 | public Color32[] colors() 92 | { 93 | return m_color.Array; 94 | } 95 | 96 | public ColorArray color 97 | { 98 | get { return m_color; } 99 | } 100 | 101 | private ColorArray m_color = new ColorArray(); 102 | 103 | public ColorBlock(Color32[] sourceRgba) 104 | { 105 | m_color.Array = sourceRgba; 106 | } 107 | 108 | public void init(uint w, uint h, Color32[] data, uint x, uint y) 109 | { 110 | 111 | uint bw = Math.Min(w - x, 4U); 112 | uint bh = Math.Min(h - y, 4U); 113 | 114 | // Blocks that are smaller than 4x4 are handled by repeating the pixels. 115 | // @@ Thats only correct when block size is 1, 2 or 4, but not with 3. :( 116 | // @@ Ideally we should zero the weights of the pixels out of range. 117 | 118 | for (uint i = 0; i < 4; i++) 119 | { 120 | uint by = i % bh; 121 | 122 | for (uint e = 0; e < 4; e++) 123 | { 124 | uint bx = e % bw; 125 | uint idx = (y + by) * w + x + bx; 126 | 127 | m_color[e, i] = data[idx]; 128 | } 129 | } 130 | } 131 | 132 | } 133 | 134 | public class VectorArray 135 | { 136 | private Vector4[] m_color = new Vector4[4 * 4]; 137 | public Vector4[] Array 138 | { 139 | get { return m_color; } 140 | } 141 | 142 | public Vector4 this[uint i] 143 | { 144 | get { return m_color[i]; } 145 | set { m_color[i] = value; } 146 | } 147 | public Vector4 this[int x, int y] 148 | { 149 | get { return m_color[y * 4 + x]; } 150 | set { m_color[y * 4 + x] = value; } 151 | } 152 | } 153 | 154 | public class ColorSet 155 | { 156 | ColorSet() 157 | { 158 | colorCount = 0; 159 | indexCount = 0; 160 | w = 0; 161 | h = 0; 162 | } 163 | //~ColorSet() {} 164 | 165 | //void allocate(uint w, uint h); 166 | 167 | //void setColors(float * data, uint img_w, uint img_h, uint img_x, uint img_y); 168 | //void setColors(Vector3[] colors, float[] weights); 169 | //void setColors(Vector4[] colors, float[] weights); 170 | 171 | //void setAlphaWeights(); 172 | //void setUniformWeights(); 173 | 174 | //void createMinimalSet(bool ignoreTransparent); 175 | //void wrapIndices(); 176 | 177 | //void swizzle(uint x, uint y, uint z, uint w); // 0=r, 1=g, 2=b, 3=a, 4=0xFF, 5=0 178 | 179 | //bool isSingleColor(bool ignoreAlpha); 180 | //bool hasAlpha(); 181 | 182 | float weight(uint i) { return weights[indices[i]]; } 183 | 184 | public bool isValidIndex(uint i) { return i < indexCount && indices[i] >= 0; } 185 | 186 | uint colorCount; 187 | uint indexCount; // Fixed to 16 188 | uint w, h; // Fixed to 4x4 189 | 190 | public VectorArray color 191 | { 192 | get { return colors; } 193 | } 194 | 195 | private VectorArray colors = new VectorArray(); 196 | 197 | public float[] weights = new float[16]; // @@ Add mask to indicate what color components are weighted? 198 | int[] indices = new int[16]; 199 | } 200 | 201 | /// Uncompressed 4x4 alpha block. 202 | class AlphaBlock4x4 203 | { 204 | public void init(byte a) 205 | { 206 | for (int i = 0; i < 16; i++) 207 | { 208 | alpha[i] = a; 209 | weights[i] = 1.0f; 210 | } 211 | } 212 | public void init(ColorBlock src, uint channel) 213 | { 214 | // Colors are in BGRA format. 215 | if (channel == 0) channel = 2; 216 | else if (channel == 2) channel = 0; 217 | 218 | for (uint i = 0; i < 16; i++) 219 | { 220 | alpha[i] = src.color[i].component()[channel]; 221 | weights[i] = 1.0f; 222 | } 223 | } 224 | //void init(ColorSet src, uint channel); 225 | 226 | //void initMaxRGB(ColorSet src, float threshold); 227 | //void initWeights(ColorSet src); 228 | 229 | public byte[] alpha = new byte[4 * 4]; 230 | public float[] weights = new float[16]; 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /NvidiaTextureTools/DXT.cs: -------------------------------------------------------------------------------- 1 | // Copyright NVIDIA Corporation 2007 -- Ignacio Castano 2 | // 3 | // Permission is hereby granted, free of charge, to any person 4 | // obtaining a copy of this software and associated documentation 5 | // files (the "Software"), to deal in the Software without 6 | // restriction, including without limitation the rights to use, 7 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the 9 | // Software is furnished to do so, subject to the following 10 | // conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | // OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using UnityEngine; 30 | 31 | namespace NvidiaTextureTools 32 | { 33 | 34 | /// DXT1 block. 35 | public class BlockDXT1 36 | { 37 | public Color16 col0 = new Color16(); 38 | public Color16 col1 = new Color16(); 39 | 40 | //union 41 | byte[] row = new byte[4]; 42 | public uint indices 43 | { 44 | get{ return BitConverter.ToUInt32(row,0);} 45 | set{ row = BitConverter.GetBytes(value);} 46 | } 47 | // 48 | public void WriteBytes(byte[] dst, int index) 49 | { 50 | BitConverter.GetBytes(col0.u).CopyTo(dst, index); 51 | BitConverter.GetBytes(col1.u).CopyTo(dst, index+2); 52 | row.CopyTo(dst, index + 4); 53 | } 54 | 55 | public uint evaluatePalette(Color32[] color_array, bool d3d9) 56 | { 57 | // Does bit expansion before interpolation. 58 | color_array[0].b = (byte)((col0.b << 3) | (col0.b >> 2)); 59 | color_array[0].g = (byte)((col0.g << 2) | (col0.g >> 4)); 60 | color_array[0].r = (byte)((col0.r << 3) | (col0.r >> 2)); 61 | color_array[0].a = 0xFF; 62 | 63 | // @@ Same as above, but faster? 64 | // Color32 c; 65 | // c.u = ((col0.u << 3) & 0xf8) | ((col0.u << 5) & 0xfc00) | ((col0.u << 8) & 0xf80000); 66 | // c.u |= (c.u >> 5) & 0x070007; 67 | // c.u |= (c.u >> 6) & 0x000300; 68 | // color_array[0].u = c.u; 69 | 70 | color_array[1].r = (byte)((col1.r << 3) | (col1.r >> 2)); 71 | color_array[1].g = (byte)((col1.g << 2) | (col1.g >> 4)); 72 | color_array[1].b = (byte)((col1.b << 3) | (col1.b >> 2)); 73 | color_array[1].a = 0xFF; 74 | 75 | // @@ Same as above, but faster? 76 | // c.u = ((col1.u << 3) & 0xf8) | ((col1.u << 5) & 0xfc00) | ((col1.u << 8) & 0xf80000); 77 | // c.u |= (c.u >> 5) & 0x070007; 78 | // c.u |= (c.u >> 6) & 0x000300; 79 | // color_array[1].u = c.u; 80 | 81 | if (col0.u > col1.u) 82 | { 83 | int bias = 0; 84 | if (d3d9) bias = 1; 85 | 86 | // Four-color block: derive the other two colors. 87 | color_array[2].r = (byte)((2 * color_array[0].r + color_array[1].r + bias) / 3); 88 | color_array[2].g = (byte)((2 * color_array[0].g + color_array[1].g + bias) / 3); 89 | color_array[2].b = (byte)((2 * color_array[0].b + color_array[1].b + bias) / 3); 90 | color_array[2].a = 0xFF; 91 | 92 | color_array[3].r = (byte)((2 * color_array[1].r + color_array[0].r + bias) / 3); 93 | color_array[3].g = (byte)((2 * color_array[1].g + color_array[0].g + bias) / 3); 94 | color_array[3].b = (byte)((2 * color_array[1].b + color_array[0].b + bias) / 3); 95 | color_array[3].a = 0xFF; 96 | 97 | return 4; 98 | } 99 | else 100 | { 101 | // Three-color block: derive the other color. 102 | color_array[2].r = (byte)((color_array[0].r + color_array[1].r) / 2); 103 | color_array[2].g = (byte)((color_array[0].g + color_array[1].g) / 2); 104 | color_array[2].b = (byte)((color_array[0].b + color_array[1].b) / 2); 105 | color_array[2].a = 0xFF; 106 | 107 | // Set all components to 0 to match DXT specs. 108 | color_array[3].r = 0x00; // color_array[2].r; 109 | color_array[3].g = 0x00; // color_array[2].g; 110 | color_array[3].b = 0x00; // color_array[2].b; 111 | color_array[3].a = 0x00; 112 | 113 | return 3; 114 | } 115 | } 116 | //uint evaluatePaletteNV5x(Color32[] color_array); 117 | 118 | //void evaluatePalette3(Color32[] color_array, bool d3d9); 119 | //void evaluatePalette4(Color32[] color_array, bool d3d9); 120 | 121 | //void decodeBlock(ColorBlock block, bool d3d9 = false); 122 | //void decodeBlockNV5x(ColorBlock block); 123 | 124 | //void setIndices(int * idx); 125 | 126 | //void flip4(); 127 | //void flip2(); 128 | 129 | /// Return true if the block uses four color mode, false otherwise. 130 | public bool isFourColorMode() 131 | { 132 | return col0.u > col1.u; 133 | } 134 | } 135 | 136 | /// DXT5 alpha block. 137 | public class AlphaBlockDXT5 138 | { 139 | //union 140 | 141 | byte alpha0b; // 8 142 | byte alpha1b; // 16 143 | public byte alpha0 144 | { 145 | get 146 | { 147 | return alpha0b; 148 | } 149 | set 150 | { 151 | alpha0b = value; 152 | uvalue &= 0xFFFFFFFFFFFFFF00; 153 | uvalue |= value; 154 | } 155 | } 156 | public byte alpha1 157 | { 158 | get 159 | { 160 | return alpha1b; 161 | } 162 | set 163 | { 164 | alpha1b = value; 165 | uvalue &= 0xFFFFFFFFFFFF00FF; 166 | uvalue |= (byte)(value<<8); 167 | } 168 | } 169 | /* 170 | byte bits0; // 3 - 19 171 | byte bits1; // 6 - 22 172 | byte bits2; // 9 - 25 173 | byte bits3; // 12 - 28 174 | byte bits4; // 15 - 31 175 | byte bits5; // 18 - 34 176 | byte bits6; // 21 - 37 177 | byte bits7; // 24 - 40 178 | byte bits8; // 27 - 43 179 | byte bits9; // 30 - 46 180 | byte bitsA; // 33 - 49 181 | byte bitsB; // 36 - 52 182 | byte bitsC; // 39 - 55 183 | byte bitsD; // 42 - 58 184 | byte bitsE; // 45 - 61 185 | byte bitsF; // 48 - 64 186 | */ 187 | ulong uvalue; 188 | public ulong u 189 | { 190 | set 191 | { 192 | uvalue = value; 193 | alpha0b = (byte)((value)&0xFF); 194 | alpha1b = (byte)((value>>8)&0xFF); 195 | /* 196 | bits0 = (byte)((value>>16)&0x07); 197 | bits1 = (byte)((value>>19)&0x07); 198 | bits2 = (byte)((value>>22)&0x07); 199 | bits3 = (byte)((value>>25)&0x07); 200 | bits4 = (byte)((value>>28)&0x07); 201 | bits5 = (byte)((value>>31)&0x07); 202 | bits6 = (byte)((value>>34)&0x07); 203 | bits7 = (byte)((value>>37)&0x07); 204 | bits8 = (byte)((value>>40)&0x07); 205 | bits9 = (byte)((value>>43)&0x07); 206 | bitsA = (byte)((value>>46)&0x07); 207 | bitsB = (byte)((value>>49)&0x07); 208 | bitsC = (byte)((value>>52)&0x07); 209 | bitsD = (byte)((value>>55)&0x07); 210 | bitsE = (byte)((value>>58)&0x07); 211 | bitsF = (byte)((value>>61)&0x07);*/ 212 | } 213 | get{return uvalue;} 214 | } 215 | 216 | public void evaluatePalette(byte[] alpha, bool d3d9) 217 | { 218 | if (alpha0 > alpha1) { 219 | evaluatePalette8(alpha, d3d9); 220 | } 221 | else { 222 | evaluatePalette6(alpha, d3d9); 223 | } 224 | } 225 | 226 | void evaluatePalette8(byte[] alpha, bool d3d9) 227 | { 228 | int bias = 0; 229 | if (d3d9) bias = 3; 230 | 231 | // 8-alpha block: derive the other six alphas. 232 | // Bit code 000 = alpha0, 001 = alpha1, others are interpolated. 233 | alpha[0] = alpha0; 234 | alpha[1] = alpha1; 235 | alpha[2] = (byte)((6 * alpha[0] + 1 * alpha[1] + bias) / 7); // bit code 010 236 | alpha[3] = (byte)((5 * alpha[0] + 2 * alpha[1] + bias) / 7); // bit code 011 237 | alpha[4] = (byte)((4 * alpha[0] + 3 * alpha[1] + bias) / 7); // bit code 100 238 | alpha[5] = (byte)((3 * alpha[0] + 4 * alpha[1] + bias) / 7); // bit code 101 239 | alpha[6] = (byte)((2 * alpha[0] + 5 * alpha[1] + bias) / 7); // bit code 110 240 | alpha[7] = (byte)((1 * alpha[0] + 6 * alpha[1] + bias) / 7); // bit code 111 241 | } 242 | 243 | void evaluatePalette6(byte[] alpha, bool d3d9) 244 | { 245 | int bias = 0; 246 | if (d3d9) bias = 2; 247 | 248 | // 6-alpha block. 249 | // Bit code 000 = alpha0, 001 = alpha1, others are interpolated. 250 | alpha[0] = alpha0; 251 | alpha[1] = alpha1; 252 | alpha[2] = (byte)((4 * alpha[0] + 1 * alpha[1] + bias) / 5); // Bit code 010 253 | alpha[3] = (byte)((3 * alpha[0] + 2 * alpha[1] + bias) / 5); // Bit code 011 254 | alpha[4] = (byte)((2 * alpha[0] + 3 * alpha[1] + bias) / 5); // Bit code 100 255 | alpha[5] = (byte)((1 * alpha[0] + 4 * alpha[1] + bias) / 5); // Bit code 101 256 | alpha[6] = 0x00; // Bit code 110 257 | alpha[7] = 0xFF; // Bit code 111 258 | } 259 | //void indices(byte[] index_array); 260 | 261 | public uint index(uint index) 262 | { 263 | uint offset = (3 * index + 16); 264 | return (uint)((this.u >> (int)offset) & 0x7); 265 | } 266 | public void setIndex(uint index, uint value) 267 | { 268 | uint offset = (3 * index + 16); 269 | ulong mask = (ulong)((0x7) << (int) offset); 270 | this.u = (this.u & ~mask) | ((ulong)((value) << (int)offset)); 271 | } 272 | //void decodeBlock(ColorBlock block, bool d3d9 = false); 273 | //void decodeBlock(AlphaBlock4x4 block, bool d3d9 = false); 274 | 275 | //void flip4(); 276 | //void flip2(); 277 | 278 | internal void WriteBytes(byte[] dst, int index) 279 | { 280 | BitConverter.GetBytes(uvalue).CopyTo(dst, index); 281 | } 282 | } 283 | 284 | 285 | /// DXT5 block. 286 | public class BlockDXT5 287 | { 288 | public AlphaBlockDXT5 alpha = new AlphaBlockDXT5(); 289 | public BlockDXT1 color = new BlockDXT1(); 290 | 291 | //void decodeBlock(ColorBlock block, bool d3d9 = false); 292 | //void decodeBlockNV5x(ColorBlock block); 293 | 294 | //void flip4(); 295 | //void flip2(); 296 | public void WriteBytes(byte[] dst, int index) 297 | { 298 | alpha.WriteBytes(dst, index); 299 | color.WriteBytes(dst, index+8); 300 | } 301 | } 302 | 303 | 304 | } 305 | 306 | -------------------------------------------------------------------------------- /NvidiaTextureTools/Fitting.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2011 Ignacio Castano 2 | // Copyright (c) 2007-2009 NVIDIA Corporation -- Ignacio Castano 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using UnityEngine; 30 | 31 | namespace NvidiaTextureTools 32 | { 33 | class Fitting 34 | { 35 | private static void swap(ref T a, ref T b) 36 | { 37 | T atmp = a; 38 | a = b; 39 | b = atmp; 40 | } 41 | 42 | static Vector3 computeCentroid(int n, Vector3[] points) 43 | { 44 | Vector3 centroid = Vector3.zero; 45 | 46 | for (int i = 0; i < n; i++) 47 | { 48 | centroid += points[i]; 49 | } 50 | centroid /= (float)n; 51 | 52 | return centroid; 53 | } 54 | 55 | static Vector3 computeCentroid(int n, Vector3[] points, float[] weights, Vector3 metric) 56 | { 57 | Vector3 centroid = Vector3.zero; 58 | float total = 0.0f; 59 | 60 | for (int i = 0; i < n; i++) 61 | { 62 | total += weights[i]; 63 | centroid += weights[i] * points[i]; 64 | } 65 | centroid /= total; 66 | 67 | return centroid; 68 | } 69 | 70 | static Vector3 computeCovariance(int n, Vector3[] points, float[] weights, Vector3 metric, float[] covariance) 71 | { 72 | // compute the centroid 73 | Vector3 centroid = computeCentroid(n, points, weights, metric); 74 | 75 | // compute covariance matrix 76 | for (int i = 0; i < 6; i++) 77 | { 78 | covariance[i] = 0.0f; 79 | } 80 | 81 | for (int i = 0; i < n; i++) 82 | { 83 | Vector3 a = Vector3.Scale((points[i] - centroid), metric); 84 | Vector3 b = weights[i] * a; 85 | 86 | covariance[0] += a.x * b.x; 87 | covariance[1] += a.x * b.y; 88 | covariance[2] += a.x * b.z; 89 | covariance[3] += a.y * b.y; 90 | covariance[4] += a.y * b.z; 91 | covariance[5] += a.z * b.z; 92 | } 93 | 94 | return centroid; 95 | } 96 | 97 | static Vector3 estimatePrincipalComponent(float[] matrix) 98 | { 99 | Vector3 row0 = new Vector3(matrix[0], matrix[1], matrix[2]); 100 | Vector3 row1 = new Vector3(matrix[1], matrix[3], matrix[4]); 101 | Vector3 row2 = new Vector3(matrix[2], matrix[4], matrix[5]); 102 | 103 | float r0 = (row0).sqrMagnitude; 104 | float r1 = (row1).sqrMagnitude; 105 | float r2 = (row2).sqrMagnitude; 106 | 107 | if (r0 > r1 && r0 > r2) return row0; 108 | if (r1 > r2) return row1; 109 | return row2; 110 | } 111 | 112 | 113 | static Vector3 firstEigenVector_PowerMethod(float[] matrix) 114 | { 115 | if (matrix[0] == 0 && matrix[3] == 0 && matrix[5] == 0) 116 | { 117 | return Vector3.zero; 118 | } 119 | 120 | Vector3 v = estimatePrincipalComponent(matrix); 121 | 122 | const int NUM = 8; 123 | for (int i = 0; i < NUM; i++) 124 | { 125 | float x = v.x * matrix[0] + v.y * matrix[1] + v.z * matrix[2]; 126 | float y = v.x * matrix[1] + v.y * matrix[3] + v.z * matrix[4]; 127 | float z = v.x * matrix[2] + v.y * matrix[4] + v.z * matrix[5]; 128 | 129 | float norm = Mathf.Max(Mathf.Max(x, y), z); 130 | 131 | v = new Vector3(x, y, z) / norm; 132 | } 133 | 134 | return v; 135 | } 136 | 137 | public static int compute4Means(int n, Vector3[] points, float[] weights, Vector3 metric, Vector3[] cluster) 138 | { 139 | // Compute principal component. 140 | float[] matrix = new float[6]; 141 | Vector3 centroid = computeCovariance(n, points, weights, metric, matrix); 142 | Vector3 principal = firstEigenVector_PowerMethod(matrix); 143 | 144 | // Pick initial solution. 145 | int mini, maxi; 146 | mini = maxi = 0; 147 | 148 | float mindps, maxdps; 149 | mindps = maxdps = Vector3.Dot(points[0] - centroid, principal); 150 | 151 | for (int i = 1; i < n; ++i) 152 | { 153 | float dps = Vector3.Dot(points[i] - centroid, principal); 154 | 155 | if (dps < mindps) 156 | { 157 | mindps = dps; 158 | mini = i; 159 | } 160 | else 161 | { 162 | maxdps = dps; 163 | maxi = i; 164 | } 165 | } 166 | 167 | cluster[0] = centroid + mindps * principal; 168 | cluster[1] = centroid + maxdps * principal; 169 | cluster[2] = (2.0f * cluster[0] + cluster[1]) / 3.0f; 170 | cluster[3] = (2.0f * cluster[1] + cluster[0]) / 3.0f; 171 | 172 | // Now we have to iteratively refine the clusters. 173 | while (true) 174 | { 175 | Vector3[] newCluster = new Vector3[4] { Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero }; 176 | float[] total = new float[4] { 0, 0, 0, 0 }; 177 | 178 | for (int i = 0; i < n; ++i) 179 | { 180 | // Find nearest cluster. 181 | int nearest = 0; 182 | float mindist = float.MaxValue; 183 | for (int j = 0; j < 4; j++) 184 | { 185 | float dist = Vector3.Scale((cluster[j] - points[i]), metric).sqrMagnitude; 186 | if (dist < mindist) 187 | { 188 | mindist = dist; 189 | nearest = j; 190 | } 191 | } 192 | 193 | newCluster[nearest] += weights[i] * points[i]; 194 | total[nearest] += weights[i]; 195 | } 196 | 197 | for (int j = 0; j < 4; j++) 198 | { 199 | if (total[j] != 0) 200 | newCluster[j] /= total[j]; 201 | } 202 | 203 | if (equal(cluster[0], newCluster[0]) && equal(cluster[1], newCluster[1]) && 204 | equal(cluster[2], newCluster[2]) && equal(cluster[3], newCluster[3])) 205 | { 206 | return ((total[0] != 0) ? 1 : 0) + ((total[1] != 0) ? 1 : 0) + ((total[2] != 0) ? 1 : 0) + ((total[3] != 0) ? 1 : 0); 207 | } 208 | 209 | cluster[0] = newCluster[0]; 210 | cluster[1] = newCluster[1]; 211 | cluster[2] = newCluster[2]; 212 | cluster[3] = newCluster[3]; 213 | 214 | // Sort clusters by weight. 215 | for (int i = 0; i < 4; i++) 216 | { 217 | for (int j = i; j > 0 && total[j] > total[j - 1]; j--) 218 | { 219 | swap(ref total[j], ref total[j - 1]); 220 | swap(ref cluster[j], ref cluster[j - 1]); 221 | } 222 | } 223 | } 224 | } 225 | 226 | static bool equal(Vector3 vector1, Vector3 vector2) 227 | { 228 | return (Vector3.Distance(vector1, vector2) < 0.000001f); 229 | } 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /NvidiaTextureTools/NvidiaTextureTools.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {CE10BC3F-C9A4-480A-9E67-FBAEA76B2671} 8 | Library 9 | Properties 10 | NvidiaTextureTools 11 | NvidiaTextureTools 12 | v3.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | true 35 | bin\x64\Debug\ 36 | DEBUG;TRACE 37 | full 38 | x64 39 | prompt 40 | ManagedMinimumRules.ruleset 41 | 42 | 43 | bin\x64\Release\ 44 | TRACE 45 | true 46 | pdbonly 47 | x64 48 | prompt 49 | ManagedMinimumRules.ruleset 50 | 51 | 52 | true 53 | bin\x86\Debug\ 54 | DEBUG;TRACE 55 | full 56 | x86 57 | prompt 58 | ManagedMinimumRules.ruleset 59 | 60 | 61 | bin\x86\Release\ 62 | TRACE 63 | true 64 | pdbonly 65 | x86 66 | prompt 67 | ManagedMinimumRules.ruleset 68 | 69 | 70 | 71 | ..\KSPResources\Assembly-CSharp.dll 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | ..\KSPResources\UnityEngine.dll 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | copy /Y "$(SolutionDir)KSPResources\$(PlatformName)\*.dll" "$(SolutionDir)KSPResources" 97 | 98 | 99 | xcopy $(TargetFileName) "$(SolutionDir)Pack\GameData\ActiveTextureManagement\Plugins\" /e /y /i /r 100 | 101 | 108 | -------------------------------------------------------------------------------- /NvidiaTextureTools/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NvidiaTextureTools")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("NvidiaTextureTools")] 13 | [assembly: AssemblyCopyright("Copyright © 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c0f765e4-4d5d-485b-858a-16fa002c01e4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /NvidiaTextureTools/Tex2dxt.cs: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | 3 | Copyright (c) 2006 Simon Brown si@sjbrown.co.uk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | -------------------------------------------------------------------------- */ 25 | 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Linq; 29 | using System.Text; 30 | using UnityEngine; 31 | 32 | namespace NvidiaTextureTools 33 | { 34 | class Tex2dxt 35 | { 36 | public byte[] dxt1(Texture2D texture) 37 | { 38 | 39 | return new byte[2]; 40 | 41 | } 42 | 43 | public byte[] dxt5(Texture2D texture) 44 | { 45 | return new byte[2]; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /NvidiaTextureTools/TextureTools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using UnityEngine; 6 | 7 | namespace NvidiaTextureTools 8 | { 9 | public class TextureToolsDXT 10 | { 11 | 12 | public static void GetDXT(Texture2D texture, int i, byte[] bytes, TextureFormat format) 13 | { 14 | Color32[] colors = texture.GetPixels32(i); 15 | uint w = (uint) texture.width>>i; 16 | uint h = (uint) texture.height>>i; 17 | 18 | ColorBlock rgba = new ColorBlock(); 19 | BlockDXT1 block1 = new BlockDXT1(); 20 | BlockDXT5 block5 = new BlockDXT5(); 21 | 22 | int blocksize = format == TextureFormat.DXT1 ? 8 : 16; 23 | int index = 0; 24 | for (uint y = 0; y < h; y += 4) { 25 | for (uint x = 0; x < w; x += 4) { 26 | rgba.init(w, h, colors, x, y); 27 | 28 | if (format == TextureFormat.DXT1) 29 | { 30 | QuickCompress.compressDXT1(rgba, block1); 31 | block1.WriteBytes(bytes, index); 32 | } 33 | else 34 | { 35 | QuickCompress.compressDXT5(rgba, block5, 0); 36 | block5.WriteBytes(bytes, index); 37 | } 38 | 39 | index += blocksize; 40 | } 41 | } 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TextureCompressor 2 | ================= 3 | 4 | Compresses the Textures after loading in KSP 5 | 6 | 7 | The MIT License (MIT) 8 | 9 | Copyright (c) 2013 Ryan Bray 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy of 12 | this software and associated documentation files (the "Software"), to deal in 13 | the Software without restriction, including without limitation the rights to 14 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | the Software, and to permit persons to whom the Software is furnished to do so, 16 | subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 23 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 24 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 25 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /x64-Aggressive-Release.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbray89/ActiveTextureManagement/8216c3b6ace916551d236f6ccf6eb774dd7e1ce0/x64-Aggressive-Release.zip -------------------------------------------------------------------------------- /x64-Basic-Release.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbray89/ActiveTextureManagement/8216c3b6ace916551d236f6ccf6eb774dd7e1ce0/x64-Basic-Release.zip -------------------------------------------------------------------------------- /x86-Aggressive-Release.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbray89/ActiveTextureManagement/8216c3b6ace916551d236f6ccf6eb774dd7e1ce0/x86-Aggressive-Release.zip -------------------------------------------------------------------------------- /x86-Basic-Release.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbray89/ActiveTextureManagement/8216c3b6ace916551d236f6ccf6eb774dd7e1ce0/x86-Basic-Release.zip --------------------------------------------------------------------------------