Skip to content

Commit

Permalink
Push
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Aug 17, 2019
1 parent 46e25f7 commit 2abac0a
Show file tree
Hide file tree
Showing 8 changed files with 665 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
*.exe
*.out
*.app
/x64
/Debug
/.vs
172 changes: 172 additions & 0 deletions MipMapTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#include <iostream>
#include <regex>
#include "TextureFile.hpp"

void printStart() {
std::cout << "MipMap Tool v1 OwO\n";
}
#include <windows.h>
void printHelp() {
HANDLE output_handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
if (output_handle != INVALID_HANDLE_VALUE) {
SMALL_RECT rect = {};
rect.Bottom = static_cast<SHORT>(100);
rect.Right = static_cast<SHORT>(80);
SetConsoleWindowInfo(output_handle, TRUE, &rect);

COORD coord = {};
coord.X = 100;
coord.Y = 80;

SetConsoleScreenBufferSize(output_handle, coord);
}

HWND console = GetConsoleWindow();
RECT r;
GetWindowRect(console, &r); //stores the console's current dimensions

MoveWindow(console, r.left, r.top, 1000, 800, TRUE); // 800 width, 100 height

std::cout
<< "Hewo! I'm the MipMap tool and I'll Map Mips for you.\n\n"

<< "I can unpack your textures like so:\n"
<< " mipmaptool unpack \"P:/file1_co.paa\" \"P:\\file2_co.paa\"\n"
<< "I can combine the best mipmaps like so:\n"
<< " mipmaptool \"P:/tex_mip4096_co.paa\" \"P:\\tex_mip2048_co.paa\" \"P:/tex_mip4_co.paa\"\n"
<< " These filenames have to be in a specific format xxx_mip1234_yy.paa, output file will be xxx_yy.paa\n"
<< " (for you nerds out there the regex is (.*)_mip(\\d*)(.*)\\.paa )\n"
<< "Or I also can combine the best mipmaps like so:\n"
<< " mipmaptool output \"P:/output_co.paa\" \"P:/file1_co.paa\" \"P:\\file2_co.paa\"\n"
<< " (which writes into specified output file)\n"

<< "File paths have to always be encased in quotes like shown.\n"
<< "Windows does that automatically if you just drag&drop files onto the binary.\n"
<< "As you can see / and \\ are allowed, anything that works in windows should work.\n\n"

<< "I hav been made by dedmen who has a patreon UwU: https://patreon.com/dedmen\n(Just so you know)";
std::cin.get();
}

int main(int argc, char* argv[]) {
if (argc <= 1) {
printHelp();
return 0;
}

std::string_view firstArg = argv[1];

if (firstArg == "help") {
printHelp();
return 0;
}

std::vector<std::string> allArguments;
for (int i = 1; i < argc; ++i) {
allArguments.push_back(argv[i]);
}

if (firstArg == "unpack") {
std::cout << "Unpacking files:\n";
allArguments.erase(allArguments.begin());
for (auto& file : allArguments) {
auto texFile = std::make_shared<TextureFile>();
std::filesystem::path inputFile(file);//#TODO file exists check
texFile->readFromFile(inputFile);
//texFile->writeToFile("P:/outtest.paa");

for (auto& mipmap : texFile->mipmaps) {
auto newFile = texFile->copyNoMipmap();
newFile->mipmaps.push_back(mipmap);
std::filesystem::path outputPath = (inputFile.parent_path() / (inputFile.filename().stem().string() + "_mip" + std::to_string(mipmap->getRealSize()) + inputFile.extension().string()));

std::regex reg("(.*)_(.*?)\\.paa");
std::cmatch cm;
std::regex_match(inputFile.filename().string().c_str(), cm, reg);
if (cm.size() == 3) {
outputPath = (inputFile.parent_path() / (std::string(cm[1]) + "_mip" + std::to_string(mipmap->getRealSize()) + "_" + std::string(cm[2]) + inputFile.extension().string()));

}

newFile->writeToFile(outputPath);
}
}
return 0;
}

std::filesystem::path output;
bool hasOutput = false;

if (firstArg == "output") {
allArguments.erase(allArguments.begin());
output = allArguments.front();
allArguments.erase(allArguments.begin());
hasOutput = true;
}

if (!hasOutput) {

for (auto& file : allArguments) {
std::filesystem::path inputFile(file);
auto filename = inputFile.filename().string();

std::regex reg("(.*)_mip(\\d*)(.*)\\.paa");
std::cmatch cm;
std::regex_match(filename.c_str(), cm, reg);
if (cm.size() != 3) {
std::cerr << "ERROR filename " << filename << " doesn't match correct format";
std::cin.get();
return 1;
}

if (!hasOutput) {
output = inputFile.parent_path() / (std::string(cm[1]) + std::string(cm[2]) + ".paa");
hasOutput = true;
} else {
if ((std::string(cm[1]) + std::string(cm[2]) + ".paa") != output.filename()) {
std::cerr << "ERROR filename " << filename << " doesn't match previously determined filename " << output.filename();
std::cin.get();
return 1;
}
}
}
}

std::vector<std::shared_ptr<TextureFile>> textures;
for (auto& file : allArguments) {
auto texFile = std::make_shared<TextureFile>();
std::filesystem::path inputFile(file);
texFile->readFromFile(inputFile);
textures.push_back(texFile);
}

//Sort by their max mipmap size
std::sort(textures.begin(), textures.end(), [](auto& left, auto& right) {
return left->mipmaps.front()->width > right->mipmaps.front()->width;
});

std::map<uint16_t, std::shared_ptr<MipMap>> mipmaps;

for (auto& texture : textures) {
for (auto& mipmap : texture->mipmaps) {
mipmaps.insert_or_assign(mipmap->width, mipmap);
}
}

auto result = textures.back()->copyNoMipmap();

std::cout << "packing mipmaps...\n";

for (auto& [key, val] : mipmaps) {
std::cout << "\t" << val->height << "-> \t" << val->inputPath << "\n";

result->mipmaps.push_back(val);
}

if (hasOutput) {
result->writeToFile(output);
}
std::cout << "packed new texture file with " << result->mipmaps.size() << " mipmaps in " << output << "\n";

return 0;
}
31 changes: 31 additions & 0 deletions MipMapTool.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29209.152
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MipMapTool", "MipMapTool.vcxproj", "{7EFAB10A-D329-477F-92FB-B3838EA142B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Debug|x64.ActiveCfg = Debug|x64
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Debug|x64.Build.0 = Debug|x64
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Debug|x86.ActiveCfg = Debug|Win32
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Debug|x86.Build.0 = Debug|Win32
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Release|x64.ActiveCfg = Release|x64
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Release|x64.Build.0 = Release|x64
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Release|x86.ActiveCfg = Release|Win32
{7EFAB10A-D329-477F-92FB-B3838EA142B6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {990EE7C1-E66C-4D06-AFD6-7A5C7977B4A9}
EndGlobalSection
EndGlobal
167 changes: 167 additions & 0 deletions MipMapTool.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{7EFAB10A-D329-477F-92FB-B3838EA142B6}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MipMapTool</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="MipMapTool.cpp" />
<ClCompile Include="TextureFile.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="TextureFile.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading

0 comments on commit 2abac0a

Please sign in to comment.