diff --git a/PCK-Studio/Classes/Conversion/Legacy/JsonDefinitions/BlockbenchBedrockModel.cs b/PCK-Studio/Classes/Conversion/Legacy/JsonDefinitions/BlockbenchBedrockModel.cs new file mode 100644 index 00000000..e0b4de32 --- /dev/null +++ b/PCK-Studio/Classes/Conversion/Legacy/JsonDefinitions/BlockbenchBedrockModel.cs @@ -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; } + } + +} diff --git a/PCK-Studio/Classes/Conversion/Legacy/LegacySkinExporter.cs b/PCK-Studio/Classes/Conversion/Legacy/LegacySkinExporter.cs new file mode 100644 index 00000000..f63676fd --- /dev/null +++ b/PCK-Studio/Classes/Conversion/Legacy/LegacySkinExporter.cs @@ -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 +{ + /// + /// 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 + /// + 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!; + } + + /// + /// Converts a skin(Bedrock Model) made in Blockbench to a valid legacy skin + /// + /// Texture for the model + /// Exported Bedrock Model from Blockbench + /// Legacy skin format + public PckFile.FileData ConvertBlockbenchModel(string blockbenchBedrockJsonData, Image texture) + { + var container = JsonConvert.DeserializeObject(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)), + }; + + } +} diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 512c7ac2..35cc3698 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -183,6 +183,8 @@ + +