mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-22 18:55:37 +00:00
* Add 'Validate Skin Dimension' setting * AddNewSkin - Fix cape box not showing after skin selection * Extended ResourceLocation for better atlas handling * ModelImporter - Add block bench export for models inside models.bin * ModelIporter - Rename 'GetPivot' to 'GetSkinBoxPivot' * ModelImporter - Fix ANIM2BOX to properly support slim skin models * ModelImporter - Update BedrockModel json class * ModelImporter - Update 'FixTexture' to be more generic * Update ModelContainer API inside OMI-Lib * Update skin vertex shader to not swap yz * Update CubeMesh class * SkinRenderer - Move framebuffer and error checking function to SceneViewport * SceneViewport - Change OnUpdate parameter * SkinRenderer - Fix Highlight part having wrong transform * SkinRenderer - Move call to 'SwapBuffers' into SceneViewport.OnUpdate * AppSettingsForm - Update API to be more flexible * SkinBOXExtensions - Update 'GetUVGraphicsPath' * SkinRenderer - Update 'OnUpdate' function * SkinRenderer - Add 'LockMousePosition' option * CustomSkinEditor - Update HighlightlingColor when selecting a part * CustomSkinEditor - Add render settings * CustomSkinEditor - Small non-technical changes * SkinRenderer - Small non-technical changes * CustomSkinEditor - Load render settings when 'OnLoad' is called * SkinRenderer - Fix centering leg0/1 * SkinRenderer - Update 'ReInitialzeSkinData' to upload new data to shader * Rename 'ModelImporter' -> 'SkinModelImporter' and add api interface to add custom import/export providers * CubeGroupMesh - Fix overlay parts not showing proerly * SkinRenderer - Fix part highlighting respecting inflate * Split up model and skin importer into seperate classes and improved api * IModelImportProvider - Add 'SupportImport' and 'SupportExport' property fields * ModelImporter - Rename 'SimpleSkinImportProvider' to 'InternalImportProvider' * modelTextureLocations.json - Add todo * SkinModelImporter - Move 'ModelTextureLocations' to GameModelImporter * CustomSkinEditor - Add SettingsManager for RenderSettings * ModelImporter::Import - Check if file exists * Rename 'modelTextureLocations' to 'modelMetaData' * GameModelImporter - Change blockbench name when exporting * SettingsManager - Add functionality to create internal settings object and add settings to it * GameModelImporter - Fully implemented game-model export to block bench * AppSettingsForm - Fix re-adding settings description to default settings * AppSettingsForm - Add settings description to 'ValidateImageDimension' * GameModelImporter - Add copyright notice and remove unnecessary using statements * ModelImporter - Add copyright notice and remove unnecessary using statements * BlockBenchModel - Fix Texture class json deserialization * SkinModelImporter - Add 'TryConvertToSkinBoxType' function * modelMetaData - Remove comments * SkinModelImporter - Fix 'GetSkinBoxPivot' function * SkinModelImporter - Add null check in 'FixTexture' function * SkinModelImporter - Add offset detection when importing skin model * CustomSkinEditor - Add 'export template' button * GameModelImporter - Rename 'ModelTextureLocations' -> 'ModelMetaData' * ModelImporter - Add summary to 'SupportedModelFileFormatsFilter' property * GameModelImporter - Change function signature of 'CreateElement' * GameModelImporter - Add options to create root outline * GameModelImporter - Update Debug message in 'TraverseChildren' * MainForm - Small code refactor * Rename class 'Meta' ->'BlockBenchFormatInfo' and update BlockBenchModel.Create function signature * MainForm - Update 'GetModelTextures' local function * GameModelImporter - Check model metadata before conversion * GameModelInfo - Mark class as sealed * SkinModelImporter - Check if blockbench model uses box uv * BlockBenchModel - Add export property to class 'Element' * CustomSkinEditor - Remove unused 'PreviewImage' property * CustomSkinEditor - Change highlight color on texture * SkinModelImporter - Fix Block Bench Model import * modelMetaData - Add meta data for 1.14 models * SkinModelImporter - Update 'TryConvertToSkinBoxType' function * SkinModelExporter - Fix model export for bbmodel and bedrock model * SkinRenderer - Fix order of applying anim animations to match the game * SkinModelImporter - Fix exception thrown in 'FixTexture' * CustomSkinEditor - Add Anim editor button and fix anim not being updated when exporting * SkinModelImporter - Fix offset detection when importing * SkinModelImporter - Swap box bottom texture when texture is available * GameModelImporter - Sort using statements * SkinModelImporter - Small code clean up inside 'ImportBedrockJson' * SkinModelImporter - Update 'AddBone' function inside 'ExportBedrockJson' * SkinModelImporter - Fix bottom texture swaping being done bofre parts where imported * SkinMoelImporter - Rename 'GetSkinBoxPivot' to 'GetSkinPartPivot' * SceneViewport - Rename 'Init' to 'Initialize' * SkinModelImporter - Add texture import in 'ImportBedrockJson' * SkinModelImporter - Fix becrock model import * Skin-/GameModelImporter - Rename 'fileName' parameter to 'filepath' * Add ModelEditor * modelMetaData - Add cavespider texture location * GameModelImporter - Update 'ExportBlockBenchModel' function * GameModelImporter - Mark 'ModelExportSettings' as sealed * ModelEditor -Add Save tool menu item & add TrySetTexture Delegate * ModelEditor - Add model node icons * Update CubeMesh & rename CubeGroupMesh to CubeMeshCollection * ModelEditor - Rename 'GetModelNodes' & 'GetModelPartNodeChildren' * Update GenericMesh & mesh rendering * Move Cube conversion into SkinBOXExtensions * GenericMesh - Made 'Transform' property abstract * SceneViewport - Add shaderLibrary and api to it * Rename 'skin...' shaders to 'texturedCube...' * Update modelMetaData part hierarchy structure * ShaderProgram - Add 'SetUniform2' overload for System.Drawing.Size * ModelEditor - Create factory methods for custom model treenodes * modelMetaData - Add 'slime.armor' texture location & pattern texture locations for 'tropicalfish_-a/-b' * Move Debug & Camera control into SceneViewport * Update BoundingBox * Add ModelRenderer * ShaderProgram - Update GetUniformLocation to retrive all active uniforms when linking program * ModelEditor - Add option to show bounding box of the model * SceneViewport - Add OnPaint override to clear color and depth buffer and enable depth testing * Update OMI submodule * Update Texture base class to accept slot when calling Bind * Plain color fragment shader - Update uniform names to be PascalCase * SceneViewport - Add 'ResetCamera' virtual function * CustomSkinEditor - Add missing render setting 'Show Armor' * ModelRenderer - Fix centering model after selecting * Move 'SceneViewport.GetBounds' to 'BoundingBox.GetEnclosingBoundingBox' * CubeMeshCollection - Implemented 'GetBounds' * SkinRenderer - Add option to show skins bounding box * ModelEditor - Update 'GetModelImageIndex' * SceneViewport - Disable blend when rendering debug graphics * ModelEditor - Remove 'Model' property in favor to 'LoadModel' function * JsonModelMetaData - Initialize 'RootParts' to empty array * BoundingBox - Fix exception when empty enumerable was passed * CubeMesh - Remove 'SetName' and add constructor with 'name' parameter * SkinBOX - Change class to record & make member properties getter only * BoundingBox - Move 'Abs' function into extension class * SceneViewport - Change 'Transform' to 'GetTransform' * BoundingBox - Make 'GetVertices' static & add GetTransform * SkinRenderer - Fix bounds calculation when offset is set & fix part highlighting * CubeMesh - Move translation & scaling into 'GetTransform' * CubeMeshCollection - Update 'Contains' overload function & 'SetVisible' * ModelRenderer - Fix pivot point rendering * ModelRenderer - Add part highlighting * modelMetaData - Add missing part to dolphin * modelMetaData - Add missing parts to dragon * CubeMesh - Fix 'GetTransform' function * ModelRenderer - Fix model rotation, pivot & translation issues * ModelRenderer - Add offset to render transform & camera * ModelRenderer - Tried fixing alpha rendering issues * modelMetaData - Add missing part to dragon & add comment * Add 'ITryGetSet.cs' and useful wrappers for it * ModelRenderer - Rename 'HighlightInfo.Pivot' to 'HighlightInfo.Translation' * ITryGetSet - mark classes and interfaces public * ModelEditor - Add material render support * ModelRenderer - Add 'TryGetModelMetaData' method * Fix rendering invisible vertecies * ModelRenderer - Simplefied populating 'metaData.RootParts' property * ModelRenderer - Add 'modelOffset' field * ModelRenderer - Update 'SetModelMaterial' * ModelRenderer - Add simple way of rendering a 2nd layer of a model(the bed model only for now) * ModelRenderer - Fix pivot points not working on horse model properly * ResourceLocation - Add 'Unknown' ResourceLocation instance & improved 'ResourceLocation.GetFromPath' * ResourceCategory - Add 'MobEntityTextures' & 'ItemEntityTextures' * Add default model handling (defaults unfinished) * Add Default Bed model * Add default chicken model * Add default cow model * AddSkinPrompt - Fix Custom skin editor not having anim flag properly set * SceneViewport - Fix Designer crashing when trying to call 'OnPaint' * Update OMI submodule * SceneViewport - Call 'base.OnMouseUp' before our own code * BlockBenchModel - Fix 'Texture.Name' being null * ItemSelectionPopUp - Fix 'okBtn_Click' condition * MainForm - Add export function for default models * MainForm - Fix model selector ignoring cancel button * MainForm - Remove unnecessary wrapper for 'entityMaterials.TryGetValue' * ModelEditor - Add remove model to context menu * ModelEditor - Add 'GetModelContainer' function * GameModelImporter - Add import functionality * MainForm - Add texture when exporting default models * Add default model for: redcow, pig, snowgolem & dragon head * Add SkinModel & SkinIdentifier class * Refactor Skin.cs - Move texture from 'SkinModel' to Skin.cs - Move 'Id' from SkinMetaData into it's own class(SkinIdentifier.cs) - Create SkinModelInfo class for keeping skin conversion simple * Skin.cs - Rename 'ANIM' property to 'Anim' * Move 'hasInvalidEntries' into 'MaterialExtensions.HasInvalidEntries' * Add ISaveContext * PckAssetExt - Rename parameter names for 'GetSkin' * Add Editor.cs * Update most editors to use new Editor class and save context * CustomSkinEditor - Use Editor as base class * SkinMetaData - Change to Immutable data type * PckAssetExtension - [SetSkin] Change adding loc key to setting loc key * ImageDeserializer - Add format check when deserializing * MainForm - [HandleSkinFile] Rename some varibale names * ModelEditor - Use Editor as base class * Move static variables from 'ModelPartSpecifics' to 'GameConstants' * Texture.cs - Add IDisposable interface * PckAssetExtensions - [SetSkin] Add null check for loc file * AnimationEditor - Fix auto save check * TextureAtlasEditor - Refactor animation access control * TextureAtlasEditor - Sort using directives * MainForm - [HandleTextureFile] Add Debug message when animation has no frames to save * AddSkinPrompt - Update save context for custom skin editor * Editor - Move autosave check in 'OnFormClosing' * ModelRenderer - Update designer specifics * Merge 'multi-pck-files-feature' into '3dSkinRenderer' * [WIP] Sub-pck in new tab with savecontext etc. * SceneViewport - Change base refresh rate to 60 fps * CustomSkinEditor - Move max offset value into a constant * ModelEditor - Add highlighting of sinfgle model boxes * MainForm - Add constant for max pck id value * CustomSkinEditor - Remove fps slider and re-ordered ui * EditorForm - Remove abstract from class declaration * EditorControl - Made virtual funtion throw `NotImplementedException` * CustomSkinEditor - Fix naming violations * CustomSkinEditor - Move initialization of render settings into a seperate funtion & remove `show armor` setting * Move Common functionality to Core project & rendering and Model support as well * Change namespace of EditorForm & EditorControl * Add Constant 'NDEBUG' to Core, Rendering & ModelSupport project * PckStudio.csproj - Remove `defaultModels.json` & `modelMetaData.json` - files were moved to PckStuido.ModelSupport * PckStudio.csproj - Remove unused `ApplicationBuildInfo.cs` * PckStudio.Core - Add NamedData.cs * PckStudio - Move some Resources to Core * Add Altas class & refactored Atlas editor * Update OMI Submodule * TextureAtlasEditor - Fix clear button not reseting color * Fix PackInfo.cs - OMI.Endianess -> OMI.ByteOrder * TextureAtlas - Impl extraction&import of large tiles * PckStudio.Core - Remove duplicated resources * LOCEditor - Added menu item for copying loc id * Core - Move 'MAX_PACK_ID' into GameConstants * TextureAtlasEditor - small refactor + TODOs * Update OMI submodule ref
227 lines
8.4 KiB
C#
227 lines
8.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Drawing;
|
|
using System.Diagnostics;
|
|
using System.Collections.Generic;
|
|
|
|
using OMI.Formats.Languages;
|
|
using OMI.Formats.Pck;
|
|
using OMI.Workers;
|
|
|
|
using PckStudio.Interfaces;
|
|
using PckStudio.Core.Deserializer;
|
|
using PckStudio.Core.Serializer;
|
|
using PckStudio.Core.Skin;
|
|
|
|
namespace PckStudio.Core.Extensions
|
|
{
|
|
public static class PckAssetExtensions
|
|
{
|
|
private const string MipMap = "MipMapLevel";
|
|
|
|
public static PckAsset CreateNewAssetIf(this PckFile pck, bool condition, string filename, PckAssetType filetype, IDataFormatWriter writer)
|
|
{
|
|
if (condition)
|
|
{
|
|
return pck.CreateNewAsset(filename, filetype, writer);
|
|
}
|
|
return default;
|
|
}
|
|
|
|
public static PckAsset CreateNewAsset(this PckFile pck, string filename, PckAssetType filetype, IDataFormatWriter writer)
|
|
{
|
|
PckAsset asset = pck.CreateNewAsset(filename, filetype);
|
|
asset.SetData(writer);
|
|
return asset;
|
|
}
|
|
|
|
public static Image GetTexture(this PckAsset asset)
|
|
{
|
|
if (asset.Type != PckAssetType.SkinFile &&
|
|
asset.Type != PckAssetType.CapeFile &&
|
|
asset.Type != PckAssetType.TextureFile)
|
|
{
|
|
throw new Exception("Asset is not suitable to contain image data.");
|
|
}
|
|
return asset.GetDeserializedData(ImageDeserializer.DefaultDeserializer);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to get the skin id of the skin <paramref name="asset"/>
|
|
/// </summary>
|
|
/// <param name="asset"></param>
|
|
/// <returns>Non-zero base number on success, otherwise 0</returns>
|
|
/// <exception cref="InvalidOperationException"></exception>
|
|
public static int GetSkinId(this PckAsset asset)
|
|
{
|
|
if (asset.Type != PckAssetType.SkinFile)
|
|
throw new InvalidOperationException("Asset is not a skin.");
|
|
|
|
const string skinAssetnamePrefix = "dlcskin";
|
|
|
|
string assetPath = Path.GetFileNameWithoutExtension(asset.Filename);
|
|
if (!assetPath.StartsWith(skinAssetnamePrefix))
|
|
{
|
|
Trace.TraceWarning($"[{nameof(GetSkinId)}] Asset name does not start with '{skinAssetnamePrefix}'");
|
|
return 0;
|
|
}
|
|
|
|
int skinId = 0;
|
|
if (!int.TryParse(assetPath.Substring(skinAssetnamePrefix.Length), out skinId))
|
|
{
|
|
Trace.TraceWarning($"[{nameof(GetSkinId)}] Failed to parse Skin Id");
|
|
}
|
|
return skinId;
|
|
}
|
|
|
|
public static Skin.Skin GetSkin(this PckAsset asset)
|
|
{
|
|
if (asset.Type != PckAssetType.SkinFile)
|
|
throw new InvalidOperationException("Asset is not a skin.");
|
|
|
|
int skinId = asset.GetSkinId();
|
|
|
|
string name = asset.GetProperty("DISPLAYNAME");
|
|
Image texture = asset.GetTexture();
|
|
SkinANIM anim = asset.GetProperty("ANIM", SkinANIM.FromString);
|
|
IEnumerable<SkinBOX> boxes = asset.GetMultipleProperties("BOX").Select(kv => SkinBOX.FromString(kv.Value));
|
|
IEnumerable<SkinPartOffset> offsets = asset.GetMultipleProperties("OFFSET").Select(kv => SkinPartOffset.FromString(kv.Value));
|
|
return new Skin.Skin(name, skinId, texture, anim, boxes, offsets);
|
|
}
|
|
|
|
public static void SetSkin(this PckAsset asset, Skin.Skin skin, LOCFile localizationFile)
|
|
{
|
|
if (asset.Type != PckAssetType.SkinFile)
|
|
throw new InvalidOperationException("Asset is not a skin file");
|
|
|
|
asset.SetTexture(skin.Texture);
|
|
|
|
string skinId = skin.Identifier.ToString("d08");
|
|
|
|
// TODO: keep filepath
|
|
asset.Filename = $"dlcskin{skinId}.png";
|
|
|
|
asset.SetProperty("DISPLAYNAME", skin.MetaData.Name);
|
|
|
|
if (localizationFile is not null)
|
|
{
|
|
string skinLocKey = $"IDS_dlcskin{skinId}_DISPLAYNAME";
|
|
asset.SetProperty("DISPLAYNAMEID", skinLocKey);
|
|
localizationFile.SetLocEntry(skinLocKey, skin.MetaData.Name);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(skin.MetaData.Theme))
|
|
{
|
|
asset.SetProperty("THEMENAME", skin.MetaData.Theme);
|
|
|
|
if (localizationFile is not null)
|
|
{
|
|
string skinThemeLocKey = $"IDS_dlcskin{skinId}_THEMENAME";
|
|
asset.SetProperty("THEMENAMEID", skinThemeLocKey);
|
|
localizationFile.SetLocEntry(skinThemeLocKey, skin.MetaData.Theme);
|
|
}
|
|
}
|
|
|
|
if (skin.HasCape)
|
|
{
|
|
asset.SetProperty("CAPEPATH", $"dlccape{skinId}.png");
|
|
}
|
|
|
|
asset.SetProperty("ANIM", skin.Anim.ToString());
|
|
asset.SetProperty("GAME_FLAGS", "0x18");
|
|
asset.SetProperty("FREE", "1");
|
|
|
|
asset.RemoveProperties("BOX");
|
|
asset.RemoveProperties("OFFSET");
|
|
|
|
foreach (SkinBOX box in skin.Model.AdditionalBoxes)
|
|
{
|
|
asset.AddProperty(box.ToProperty());
|
|
}
|
|
foreach (SkinPartOffset offset in skin.Model.PartOffsets)
|
|
{
|
|
asset.AddProperty(offset.ToProperty());
|
|
}
|
|
}
|
|
|
|
public static T GetDeserializedData<T>(this PckAsset asset, IPckAssetDeserializer<T> deserializer)
|
|
{
|
|
return deserializer.Deserialize(asset);
|
|
}
|
|
|
|
public static T GetData<T>(this PckAsset asset, IDataFormatReader<T> formatReader) where T : class
|
|
{
|
|
using var ms = new MemoryStream(asset.Data);
|
|
return formatReader.FromStream(ms);
|
|
}
|
|
|
|
public static void SetSerializedData<T>(this PckAsset asset, T obj, IPckAssetSerializer<T> serializer)
|
|
{
|
|
serializer.Serialize(obj, ref asset);
|
|
}
|
|
|
|
public static void SetData(this PckAsset asset, IDataFormatWriter formatWriter)
|
|
{
|
|
using (var stream = new MemoryStream())
|
|
{
|
|
formatWriter.WriteToStream(stream);
|
|
asset.SetData(stream.ToArray());
|
|
}
|
|
}
|
|
|
|
public static void SetTexture(this PckAsset asset, Image image)
|
|
{
|
|
if (asset.Type != PckAssetType.SkinFile &&
|
|
asset.Type != PckAssetType.CapeFile &&
|
|
asset.Type != PckAssetType.TextureFile)
|
|
{
|
|
throw new Exception("Asset is not suitable to contain image data.");
|
|
}
|
|
asset.SetSerializedData(image, ImageSerializer.DefaultSerializer);
|
|
}
|
|
|
|
public static bool IsMipmappedFile(this PckAsset asset)
|
|
{
|
|
// We only want to test the file name itself. ex: "terrainMipMapLevel2"
|
|
string name = Path.GetFileNameWithoutExtension(asset.Filename);
|
|
|
|
// check if last character is a digit (0-9). If not return false
|
|
if (!char.IsDigit(name[name.Length - 1]))
|
|
return false;
|
|
|
|
// If string does not end with MipMapLevel, then it's not MipMapped
|
|
if (!name.Remove(name.Length - 1, 1).EndsWith(MipMap))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
public static string GetNormalPath(this PckAsset asset)
|
|
{
|
|
if (!asset.IsMipmappedFile())
|
|
return asset.Filename;
|
|
string ext = Path.GetExtension(asset.Filename);
|
|
return asset.Filename.Remove(asset.Filename.Length - (MipMap.Length + 1) - ext.Length) + ext;
|
|
}
|
|
|
|
public static void DeserializeProperties(this PckAsset asset, IEnumerable<string> serializedData)
|
|
{
|
|
IEnumerable<KeyValuePair<string, string>> lines = serializedData
|
|
.Select(line => line.Split([' '], 2))
|
|
.Where (keyValue => keyValue.Length == 2)
|
|
.Select(keyValue => new KeyValuePair<string, string>(keyValue[0].Replace(":", ""), keyValue[1]));
|
|
foreach (KeyValuePair<string, string> kv in lines)
|
|
{
|
|
asset.AddProperty(kv);
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<string> SerializeProperties(this PckAsset asset, string seperater = ":")
|
|
{
|
|
IReadOnlyList<KeyValuePair<string, string>> properties = asset.GetProperties();
|
|
return properties.Select(property => property.Key + seperater + property.Value);
|
|
}
|
|
}
|
|
}
|