progress on texture packer
This commit is contained in:
parent
10a3faacf7
commit
c4661b1fef
@ -3,6 +3,16 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<ApplicationIcon />
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0005" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RecrownedAthenaeum.Pipeline\RecrownedAthenaeum.Pipeline.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user