progress on texture packer

This commit is contained in:
Harrison Deng 2018-12-06 12:19:30 -06:00
parent 10a3faacf7
commit c4661b1fef
2 changed files with 90 additions and 0 deletions

View File

@ -3,6 +3,16 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<ApplicationIcon />
<StartupObject />
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0005" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RecrownedAthenaeum.Pipeline\RecrownedAthenaeum.Pipeline.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
namespace RecrownedAthenaeum.ConsoleTools.TextureAtlasTools
{
internal class TexturePacker
{
private enum SupportedExtensions
{
jpeg, jpg, png
}
Rectangle theoreticalSpace;
Node masterNode;
internal TexturePacker(string rootDirectoryPath)
{
string[] paths = Directory.GetFiles(rootDirectoryPath);
int minArea = 0;
int currentPoTArea = 2 * 2;
List<TheoreticalImage> theoreticalImages = new List<TheoreticalImage>();
for (int pathID = 0; pathID < paths.Length; pathID++)
{
SupportedExtensions extension;
if (Enum.TryParse(Path.GetExtension(paths[pathID]), out extension))
{
using (FileStream stream = new FileStream(paths[pathID], FileMode.Open))
{
IImageInfo info = Image.Identify(stream);
TheoreticalImage ti = new TheoreticalImage(info.Width, info.Height, paths[pathID]);
theoreticalImages.Add(ti);
minArea += ti.Area;
while (currentPoTArea < minArea)
{
currentPoTArea *= 2 * 2;
}
}
}
}
}
private class Node
{
public Node parent;
public Node[] branches = new Node[2];
public readonly TheoreticalImage theoreticalImage;
public Node(TheoreticalImage theoreticalImage)
{
this.theoreticalImage = theoreticalImage;
}
}
private struct TheoreticalImage
{
public Rectangle bounds;
public readonly string path;
public int Area { get { return bounds.Width * bounds.Height; } }
public TheoreticalImage(int width, int height, string path)
{
bounds = new Rectangle();
bounds.Width = width;
bounds.Height = height;
this.path = path;
}
}
}
}