3d skin renderer (#50)

* 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
This commit is contained in:
Miku-666
2025-11-11 21:53:32 +01:00
committed by GitHub
parent 6b0f233390
commit 8dfe9cf5b0
287 changed files with 33729 additions and 13307 deletions
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PckStudio.Core.Skin
{
public sealed class Skin
{
public SkinMetaData MetaData { get; set; }
public SkinIdentifier Identifier { get; set; }
public SkinANIM Anim { get; set; }
public SkinModel Model { get; set; }
public Image Texture { get; set; }
public Image CapeTexture { get; set; }
public bool HasCape => CapeTexture is not null;
public Skin(string name, Image texture)
{
MetaData = new SkinMetaData(name, string.Empty);
Texture = texture;
Model = new SkinModel();
}
public Skin(string name, Image texture, Image capeTexture)
: this(name, texture)
{
CapeTexture = capeTexture;
}
public Skin(string name, SkinANIM anim, Image texture, IEnumerable<SkinBOX> additionalBoxes, IEnumerable<SkinPartOffset> partOffsets)
: this(name, texture)
{
Model.AdditionalBoxes.AddRange(additionalBoxes);
Model.PartOffsets.AddRange(partOffsets);
Anim = anim;
}
public Skin(string name, int id, Image texture, SkinANIM anim, IEnumerable<SkinBOX> additionalBoxes, IEnumerable<SkinPartOffset> partOffsets)
: this(name, anim, texture, additionalBoxes, partOffsets)
{
Identifier = new(id);
}
}
}
+115
View File
@@ -0,0 +1,115 @@
/* Copyright (c) 2022-present miku-666, MattNL
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
using System;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
namespace PckStudio.Core.Skin
{
/// <summary>
/// Represents a Skin Anim value where flags can be set
/// </summary>
public class SkinANIM : ICloneable, IEquatable<SkinANIM>, IEquatable<SkinAnimMask>
{
public static readonly SkinANIM Empty = new SkinANIM(0);
private BitVector32 _flags;
private static readonly Regex _validator = new Regex(@"^0x[0-9a-f]{1,8}\b", RegexOptions.IgnoreCase);
public SkinANIM(SkinAnimMask mask)
: this((int)mask)
{
}
private SkinANIM(int mask)
{
_flags = new BitVector32(mask);
}
public override string ToString() => "0x" + _flags.Data.ToString("x8");
public static bool IsValidANIM(string anim)
{
return !string.IsNullOrWhiteSpace(anim) && _validator.IsMatch(anim);
}
public static SkinANIM FromString(string value)
=> IsValidANIM(value)
? new SkinANIM(Convert.ToInt32(value.TrimEnd(' ', '\n', '\r'), 16))
: Empty;
public static SkinANIM operator |(SkinANIM @this, SkinANIM other) => new SkinANIM(@this._flags.Data | other._flags.Data);
public static SkinANIM operator |(SkinANIM @this, SkinAnimMask mask) => new SkinANIM(@this._flags.Data | (int)mask);
public static SkinANIM operator &(SkinANIM @this, SkinAnimMask mask) => new SkinANIM(@this._flags.Data & (int)mask);
public static SkinANIM FromValue(int value) => new SkinANIM(value);
public int ToValue() => _flags.Data;
public static implicit operator SkinANIM(SkinAnimMask mask) => new SkinANIM(mask);
public static bool operator ==(SkinANIM @this, SkinAnimMask mask) => @this.Equals(mask);
public static bool operator !=(SkinANIM @this, SkinAnimMask mask) => !@this.Equals(mask);
public static bool operator ==(SkinANIM @this, SkinANIM other) => @this.Equals(other);
public static bool operator !=(SkinANIM @this, SkinANIM other) => !@this.Equals(other);
public bool Equals(SkinANIM other)
{
return _flags.Data == other._flags.Data;
}
public bool Equals(SkinAnimMask other)
{
return _flags.Data == (int)other;
}
public override bool Equals(object obj) => obj is SkinANIM a && Equals(a);
public override int GetHashCode() => _flags.Data;
/// <summary>
/// Sets the desired flag in the bitfield
/// </summary>
/// <param name="flag">ANIM Flag to set</param>
/// <param name="state">State of the flag</param>
public SkinANIM SetFlag(SkinAnimFlag flag, bool state)
{
if (!Enum.IsDefined(typeof(SkinAnimFlag), flag))
throw new ArgumentOutOfRangeException(nameof(flag));
return new SkinANIM(state ? _flags.Data | 1 << (int)flag : _flags.Data & ~(1 << (int)flag));
}
/// <summary>
/// Gets flag state
/// </summary>
/// <param name="flag">Flag to check</param>
/// <returns>True if flag is set, otherwise false</returns>
public bool GetFlag(SkinAnimFlag flag)
{
if (!Enum.IsDefined(typeof(SkinAnimFlag), flag))
throw new ArgumentOutOfRangeException(nameof(flag));
return _flags[1 << (int)flag];
}
public object Clone()
{
return MemberwiseClone();
}
}
}
+66
View File
@@ -0,0 +1,66 @@
/* Copyright (c) 2022-present miku-666, MattNL
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
namespace PckStudio.Core.Skin
{
/// <summary>
/// For usage see <see cref="SkinANIM"/>
/// </summary>
public enum SkinAnimFlag : int
{
STATIC_ARMS = 0, // 0x01
ZOMBIE_ARMS = 1, // 0x02
STATIC_LEGS = 2, // 0x04
BAD_SANTA = 3, // 0x08
//
__BIT_4 = 4, // 0x10 - Unused??
SYNCED_LEGS = 5, // 0x20
SYNCED_ARMS = 6, // 0x40
STATUE_OF_LIBERTY = 7, // 0x80
ALL_ARMOR_DISABLED = 8, // 0x100
HEAD_BOBBING_DISABLED = 9, // 0x200
HEAD_DISABLED = 10, // 0x400
RIGHT_ARM_DISABLED = 11, // 0x800
LEFT_ARM_DISABLED = 12, // 0x1000
BODY_DISABLED = 13, // 0x2000
RIGHT_LEG_DISABLED = 14, // 0x4000
LEFT_LEG_DISABLED = 15, // 0x8000
HEAD_OVERLAY_DISABLED = 16, // 0x10000
DO_BACKWARDS_CROUCH = 17, // 0x20000
RESOLUTION_64x64 = 18, // 0x40000
SLIM_MODEL = 19, // 0x80000
LEFT_ARM_OVERLAY_DISABLED = 20, // 0x100000
RIGHT_ARM_OVERLAY_DISABLED = 21, // 0x200000
LEFT_LEG_OVERLAY_DISABLED = 22, // 0x400000
RIGHT_LEG_OVERLAY_DISABLED = 23, // 0x800000
BODY_OVERLAY_DISABLED = 24, // 0x1000000
FORCE_HEAD_ARMOR = 25, // 0x2000000
FORCE_RIGHT_ARM_ARMOR = 26, // 0x4000000
FORCE_LEFT_ARM_ARMOR = 27, // 0x8000000
FORCE_BODY_ARMOR = 28, // 0x10000000
FORCE_RIGHT_LEG_ARMOR = 29, // 0x20000000
FORCE_LEFT_LEG_ARMOR = 30, // 0x40000000
DINNERBONE = 31, // 0x80000000
}
}
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PckStudio.Core.Skin
{
[Flags]
public enum SkinAnimMask : int
{
NONE = 0, // 0x00
STATIC_ARMS = 1 << 0, // 0x01
ZOMBIE_ARMS = 1 << 1, // 0x02
STATIC_LEGS = 1 << 2, // 0x04
BAD_SANTA = 1 << 3, // 0x08
__BIT_4 = 1 << 4, // 0x10 - Unused??
SYNCED_LEGS = 1 << 5, // 0x20
SYNCED_ARMS = 1 << 6, // 0x40
STATUE_OF_LIBERTY = 1 << 7, // 0x80
ALL_ARMOR_DISABLED = 1 << 8, // 0x100
HEAD_BOBBING_DISABLED = 1 << 9, // 0x200
HEAD_DISABLED = 1 << 10, // 0x400
RIGHT_ARM_DISABLED = 1 << 11, // 0x800
LEFT_ARM_DISABLED = 1 << 12, // 0x1000
BODY_DISABLED = 1 << 13, // 0x2000
RIGHT_LEG_DISABLED = 1 << 14, // 0x4000
LEFT_LEG_DISABLED = 1 << 15, // 0x8000
HEAD_OVERLAY_DISABLED = 1 << 16, // 0x10000
DO_BACKWARDS_CROUCH = 1 << 17, // 0x20000
RESOLUTION_64x64 = 1 << 18, // 0x40000
SLIM_MODEL = 1 << 19, // 0x80000
LEFT_ARM_OVERLAY_DISABLED = 1 << 20, // 0x100000
RIGHT_ARM_OVERLAY_DISABLED = 1 << 21, // 0x200000
LEFT_LEG_OVERLAY_DISABLED = 1 << 22, // 0x400000
RIGHT_LEG_OVERLAY_DISABLED = 1 << 23, // 0x800000
BODY_OVERLAY_DISABLED = 1 << 24, // 0x1000000
FORCE_HEAD_ARMOR = 1 << 25, // 0x2000000
FORCE_RIGHT_ARM_ARMOR = 1 << 26, // 0x4000000
FORCE_LEFT_ARM_ARMOR = 1 << 27, // 0x8000000
FORCE_BODY_ARMOR = 1 << 28, // 0x10000000
FORCE_RIGHT_LEG_ARMOR = 1 << 29, // 0x20000000
FORCE_LEFT_LEG_ARMOR = 1 << 30, // 0x40000000
DINNERBONE = 1 << 31, // 0x80000000
}
}
+180
View File
@@ -0,0 +1,180 @@
/* Copyright (c) 2023-present miku-666, MattNL
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1.The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using PckStudio.Core.Extensions;
namespace PckStudio.Core.Skin
{
public record SkinBOX : IEquatable<SkinBOX>
{
public static readonly SkinBOX DefaultHead = new SkinBOX("HEAD", new Vector3(-4, -8, -4), new Vector3(8), Vector2.Zero);
public static readonly string[] BaseTypes = new string[]
{
"HEAD",
"BODY",
"ARM0",
"ARM1",
"LEG0",
"LEG1",
};
public static readonly string[] OverlayTypes = new string[]
{
"HEADWEAR",
"JACKET",
"SLEEVE0",
"SLEEVE1",
"PANTS0",
"PANTS1",
};
public static Dictionary<int, SkinAnimFlag> KnownHashes = new Dictionary<int, SkinAnimFlag>()
{
[unchecked((int)0x9560320c)] = SkinAnimFlag.HEAD_DISABLED, // HEAD -4 -8 -4 8 8 8 0 0 0 0 0
[unchecked((int)0x1f13e4a3)] = SkinAnimFlag.BODY_DISABLED, // BODY -4 0 -2 8 12 4 16 16 0 0 0
[unchecked((int)0x407c9b27)] = SkinAnimFlag.RIGHT_ARM_DISABLED, // ARM0 -3 -2 -2 4 12 4 40 16 0 0 0 // standard (64x64)
[unchecked((int)0x867c9b27)] = SkinAnimFlag.RIGHT_ARM_DISABLED, // ARM0 -2 -2 -2 3 12 4 40 16 0 0 0 // slim
[unchecked((int)0xca3cf050)] = SkinAnimFlag.LEFT_ARM_DISABLED, // ARM1 -1 -2 -2 4 12 4 40 16 0 1 0 // classic (64x32)
[unchecked((int)0x879b27)] = SkinAnimFlag.LEFT_ARM_DISABLED, // ARM1 -1 -2 -2 4 12 4 32 48 0 0 0 // standard (64x64)
[unchecked((int)0xe8c79b27)] = SkinAnimFlag.LEFT_ARM_DISABLED, // ARM1 -1 -2 -2 3 12 4 32 48 0 0 0 // slim
[unchecked((int)0x1910e24a)] = SkinAnimFlag.LEFT_LEG_DISABLED, // LEG1 -2 0 -2 4 12 4 16 48 0 0 0 // 64x64
[unchecked((int)0xce263773)] = SkinAnimFlag.LEFT_LEG_DISABLED, // LEG1 -2 0 -2 4 12 4 0 16 0 1 0 // 64x32
[unchecked((int)0x5da5e24a)] = SkinAnimFlag.RIGHT_LEG_DISABLED, // LEG0 -2 0 -2 4 12 4 0 16 0 0 0
[unchecked((int)0x4bfe0142)] = SkinAnimFlag.HEAD_OVERLAY_DISABLED, // HEADWEAR -4 -8 -4 8 8 8 32 0 0 0 0
// ------------------------------------------------------------------------------------------------------------------------------------
[unchecked((int)0xe693e4a3)] = SkinAnimFlag.BODY_OVERLAY_DISABLED, // BODY -4 0 -2 8 12 4 16 32 0 0 0
[unchecked((int)0x8e322609)] = SkinAnimFlag.BODY_OVERLAY_DISABLED, // JACKET -4 0 -2 8 12 4 16 32 0 0 0
[unchecked((int)0x860c4433)] = SkinAnimFlag.RIGHT_ARM_OVERLAY_DISABLED, // SLEEVE0 -3 -2 -2 4 12 4 40 32 0 0 0 // classic
[unchecked((int)0xcc0c4433)] = SkinAnimFlag.RIGHT_ARM_OVERLAY_DISABLED, // SLEEVE0 -2 -2 -2 3 12 4 40 32 0 0 0 // slim
[unchecked((int)0x91407908)] = SkinAnimFlag.LEFT_ARM_OVERLAY_DISABLED, // SLEEVE1 -1 -2 -2 4 12 4 48 48 0 0 0 // classic
[unchecked((int)0x79807908)] = SkinAnimFlag.LEFT_ARM_OVERLAY_DISABLED, // SLEEVE1 -1 -2 -2 3 12 4 48 48 0 0 0 // slim
[unchecked((int)0x4de0238a)] = SkinAnimFlag.RIGHT_LEG_OVERLAY_DISABLED, // PANTS0 -2 0 -2 4 12 4 0 32 0 0 0
[unchecked((int)0x176f238a)] = SkinAnimFlag.LEFT_LEG_OVERLAY_DISABLED, // PANTS1 -2 0 -2 4 12 4 0 48 0 0 0
};
public static readonly string[] ValidBoxTypes = BaseTypes.Concat(OverlayTypes).ToArray();
public string Type { get; }
public Vector3 Pos { get; }
public Vector3 Size { get; }
public Vector2 UV { get; }
public bool HideWithArmor { get; }
public bool Mirror { get; }
public float Scale { get; }
public SkinBOX(string type, Vector3 pos, Vector3 size, Vector2 uv,
bool hideWithArmor = false, bool mirror = false, float scale = 0.0f)
{
Type = type;
Pos = pos;
Size = size;
UV = uv;
HideWithArmor = hideWithArmor;
Mirror = mirror;
Scale = scale;
}
public static SkinBOX FromString(string value)
{
var arguments = value.TrimEnd('\n', '\r', ' ').Split(' ');
if (arguments.Length < 9)
{
throw new ArgumentException("Arguments must have at least a length of 9");
}
var type = arguments[0];
Vector3 pos = TryGetVector3(arguments, 1);
Vector3 size = TryGetVector3(arguments, 4);
Vector2 uv = TryGetVector2(arguments, 7);
bool hideWithArmor = arguments.IndexInRange(9) && arguments[9] == "1";
bool mirror = arguments.IndexInRange(10) && arguments[10] == "1";
float scale = default;
if (arguments.IndexInRange(11))
float.TryParse(arguments[11], out scale);
return new SkinBOX(type, pos, size, uv, hideWithArmor, mirror, scale);
}
public bool IsValidType() => IsValidType(Type);
public static bool IsValidType(string type) => ValidBoxTypes.Contains(type);
public bool IsBasePart() => IsBasePart(Type);
public static bool IsBasePart(string type) => BaseTypes.Contains(type);
public bool IsOverlayPart() => IsOverlayPart(Type);
public static bool IsOverlayPart(string type) => OverlayTypes.Contains(type);
public KeyValuePair<string, string> ToProperty()
{
return new KeyValuePair<string, string>("BOX", ToString());
}
public override string ToString()
{
return
$"{Type} {Pos.X} {Pos.Y} {Pos.Z} {Size.X} {Size.Y} {Size.Z} {UV.X} {UV.Y} {Convert.ToInt32(HideWithArmor)} {Convert.ToInt32(Mirror)} {Scale}"
.Replace(',', '.');
}
private static Vector2 TryGetVector2(string[] arguments, int startIndex)
{
float.TryParse(arguments[startIndex], out float x);
float.TryParse(arguments[startIndex + 1], out float y);
return new Vector2(x, y);
}
private static Vector3 TryGetVector3(string[] arguments, int startIndex)
{
Vector2 xy = TryGetVector2(arguments, startIndex);
float.TryParse(arguments[startIndex + 2], out float z);
return new Vector3(xy, z);
}
public override int GetHashCode()
{
int hashCode = -1311939065;
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Type);
hashCode = hashCode * -1521134295 + Pos.GetHashCode();
hashCode = hashCode * -1521134295 + Size.GetHashCode();
hashCode = hashCode * -1521134295 + UV.GetHashCode();
hashCode = hashCode * -1521134295 + HideWithArmor.GetHashCode();
hashCode = hashCode * -1521134295 + Mirror.GetHashCode();
hashCode = hashCode * -1521134295 + Scale.GetHashCode();
return hashCode;
}
}
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
namespace PckStudio.Core.Skin
{
public sealed class SkinIdentifier : IFormattable
{
public int Id { get; }
public SkinIdentifier(int id)
{
Id = id;
}
public static implicit operator int(SkinIdentifier _this) => _this.Id;
public string ToString(string format, IFormatProvider formatProvider) => Id.ToString(format, formatProvider);
public string ToString(string format) => Id.ToString(format, NumberFormatInfo.CurrentInfo);
public override string ToString() => Id.ToString(NumberFormatInfo.CurrentInfo);
}
}
+14
View File
@@ -0,0 +1,14 @@
namespace PckStudio.Core.Skin
{
public sealed class SkinMetaData
{
public string Name { get; }
public string Theme { get; }
public SkinMetaData(string name, string theme)
{
Name = name;
Theme = theme;
}
}
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using OMI.Formats.Pck;
namespace PckStudio.Core.Skin
{
public sealed class SkinModel
{
public readonly List<SkinBOX> AdditionalBoxes;
public readonly List<SkinPartOffset> PartOffsets;
public SkinModel()
{
AdditionalBoxes = new List<SkinBOX>();
PartOffsets = new List<SkinPartOffset>(5);
}
public SkinModel(IEnumerable<SkinBOX> additionalBoxes, IEnumerable<SkinPartOffset> partOffsets)
{
AdditionalBoxes = new List<SkinBOX>(additionalBoxes);
PartOffsets = new List<SkinPartOffset>(partOffsets);
}
}
}
+81
View File
@@ -0,0 +1,81 @@
using System;
using System.Linq;
using System.IO;
using PckStudio.Core.Extensions;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace PckStudio.Core.Skin
{
public readonly struct SkinPartOffset
{
private static readonly Regex sWhitespace = new Regex(@"\s+");
public static string ReplaceWhitespace(string input, string replacement)
{
return sWhitespace.Replace(input, replacement);
}
public static readonly string[] ValidModelOffsetTypes = new string[]
{
//! See: 0x02af8a20 - 0x02af8ed8 (Wii U Editon)
"HEAD",
"BODY",
"ARM0",
"ARM1",
"LEG0",
"LEG1",
"TOOL0",
"TOOL1",
"HELMET",
"SHOULDER0",
"SHOULDER1",
"CHEST",
"WAIST",
"PANTS0",
"PANTS1",
"BOOT0",
"BOOT1",
};
public string Type { get; }
public float Value { get; }
public SkinPartOffset(string type, float value)
{
Type = type;
Value = value;
}
public static SkinPartOffset FromString(string offsetFormatString)
{
string[] offset = ReplaceWhitespace(offsetFormatString.TrimEnd('\n', '\r', ' '), ",").Split(',');
if (offset.Length < 3)
throw new InvalidDataException("Format string does not contain enough data.");
string type = offset[0];
if (!ValidModelOffsetTypes.Contains(type))
{
Debug.WriteLine($"'{type}' is an invalid offset type.", category: nameof(SkinPartOffset));
}
// Ignore => Y assumed
//if (offset[1] != "Y")
if (!float.TryParse(offset[2], out float value))
{
Debug.WriteLine($"Failed to parse y offset for: '{type}'", category: nameof(SkinPartOffset));
}
return new SkinPartOffset(type, value);
}
public KeyValuePair<string, string> ToProperty()
{
string value = $"{Type} Y {Value}";
return new KeyValuePair<string, string>("OFFSET", value.Replace(',', '.'));
}
}
}