mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-25 22:25:33 +00:00
Added LegacySkinExporter
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using PckStudio.Conversion.Common.JsonDefinitions;
|
||||
|
||||
namespace PckStudio.Classes.Conversion.Legacy.JsonDefinitions
|
||||
{
|
||||
internal class BlockbenchBedrockModel
|
||||
{
|
||||
internal class BedrockModelDescription
|
||||
{
|
||||
public Size TextureSize => new Size(TextureWidth, TextureHeight);
|
||||
|
||||
[JsonProperty("identifier")]
|
||||
public string Identifier { get; set; }
|
||||
|
||||
[JsonProperty("texture_width")]
|
||||
public int TextureWidth { get; set; }
|
||||
|
||||
[JsonProperty("texture_height")]
|
||||
public int TextureHeight { get; set; }
|
||||
|
||||
[JsonProperty("visible_bounds_width")]
|
||||
public int VisibleBoundsWidth { get; set; }
|
||||
|
||||
[JsonProperty("visible_bounds_height")]
|
||||
public int VisibleBoundsHeight { get; set; }
|
||||
|
||||
[JsonProperty("visible_bounds_offset")]
|
||||
public float[] VisibleBoundsOffset { get; set; }
|
||||
}
|
||||
|
||||
internal class BedrockModel
|
||||
{
|
||||
[JsonProperty("description")]
|
||||
public BedrockModelDescription Description { get; set; }
|
||||
|
||||
[JsonProperty("bones")]
|
||||
public GeometryBone[] Bones { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("format_version")]
|
||||
public string FormatVersion { get; set; }
|
||||
|
||||
[JsonProperty("minecraft:geometry")]
|
||||
public BedrockModel[] Models { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
85
PCK-Studio/Classes/Conversion/Legacy/LegacySkinExporter.cs
Normal file
85
PCK-Studio/Classes/Conversion/Legacy/LegacySkinExporter.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OMI.Formats.Pck;
|
||||
using PckStudio.Classes.Conversion.Legacy.JsonDefinitions;
|
||||
using PckStudio.Classes.Extentions;
|
||||
using PckStudio.Conversion.Common.JsonDefinitions;
|
||||
|
||||
namespace PckStudio.Conversion.Legacy
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows Converting Bedrock model file (*.geo.json) to a legacy type version
|
||||
/// as well as whole bedrock skin pack https://learn.microsoft.com/en-us/minecraft/creator/documents/packagingaskinpack
|
||||
/// </summary>
|
||||
internal class LegacySkinExporter
|
||||
{
|
||||
public PckFile ConvertPack(DirectoryInfo directory)
|
||||
{
|
||||
var jsonFiles = directory.GetFiles("*.json", SearchOption.TopDirectoryOnly);
|
||||
var textureFiles = directory.GetFiles("*.png", SearchOption.TopDirectoryOnly);
|
||||
var textsDir = directory.GetDirectories("texts", SearchOption.TopDirectoryOnly);
|
||||
var localsDir = textsDir.Length > 0 ? textsDir[0] : null;
|
||||
|
||||
return default!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a skin(Bedrock Model) made in Blockbench to a valid legacy skin
|
||||
/// </summary>
|
||||
/// <param name="texture">Texture for the model</param>
|
||||
/// <param name="blockbenchBedrockJsonData">Exported Bedrock Model from Blockbench</param>
|
||||
/// <returns>Legacy skin format</returns>
|
||||
public PckFile.FileData ConvertBlockbenchModel(string blockbenchBedrockJsonData, Image texture)
|
||||
{
|
||||
var container = JsonConvert.DeserializeObject<BlockbenchBedrockModel>(blockbenchBedrockJsonData);
|
||||
if (container.Models.Length > 0)
|
||||
{
|
||||
var model = container.Models[0];
|
||||
if (texture.Size != model.Description.TextureSize)
|
||||
throw new ArgumentException("Model texture size does not match supplied Image size.");
|
||||
|
||||
var file = new PckFile.FileData("", PckFile.FileData.FileType.SkinFile);
|
||||
|
||||
|
||||
return default!;
|
||||
}
|
||||
return default!;
|
||||
}
|
||||
|
||||
private static GeometryCube[] defaultSkinParts = new GeometryCube[8]
|
||||
{
|
||||
// head
|
||||
new GeometryCube(new Vector3(-4, 24, -4), new Vector3(8), new Vector2(0)),
|
||||
|
||||
// body
|
||||
new GeometryCube(new Vector3(-4, 12, -2), new Vector3(8, 12, 4), new Vector2(16)),
|
||||
|
||||
// leg0
|
||||
new GeometryCube(new Vector3(-4, 0, -2), new Vector3(4, 12, 4), new Vector2(0, 16)),
|
||||
|
||||
// leg1
|
||||
new GeometryCube(new Vector3(0, 0, -2), new Vector3(4, 12, 4), new Vector2(16, 48)),
|
||||
|
||||
// arm0
|
||||
new GeometryCube(new Vector3(-7, 12, -2), new Vector3(4, 12, 4), new Vector2(40, 16)),
|
||||
|
||||
// arm1
|
||||
new GeometryCube(new Vector3(4, 24, -2), new Vector3(4, 12, 4), new Vector2(32, 48)),
|
||||
|
||||
// arm0 slim
|
||||
new GeometryCube(new Vector3(-7, 12, -2), new Vector3(3, 12, 4), new Vector2(40, 16)),
|
||||
|
||||
// arm1 slim
|
||||
new GeometryCube(new Vector3(4, 24, -2), new Vector3(3, 12, 4), new Vector2(32, 48)),
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -183,6 +183,8 @@
|
||||
<Compile Include="Classes\Conversion\CommonJsonDefinitions\ManifestHeader.cs" />
|
||||
<Compile Include="Classes\Conversion\CommonJsonDefinitions\SkinObject.cs" />
|
||||
<Compile Include="Classes\Conversion\Bedrock\ZipExportContext.cs" />
|
||||
<Compile Include="Classes\Conversion\Legacy\JsonDefinitions\BlockbenchBedrockModel.cs" />
|
||||
<Compile Include="Classes\Conversion\Legacy\LegacySkinExporter.cs" />
|
||||
<Compile Include="Classes\Extentions\EnumerableExtentions.cs" />
|
||||
<Compile Include="Classes\FileTypes\CSMBFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\PCKAudioFile.cs" />
|
||||
|
||||
Reference in New Issue
Block a user