mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-22 14:35:48 +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
237 lines
8.5 KiB
C#
237 lines
8.5 KiB
C#
/* Copyright (c) 2024-present miku-666
|
|
* 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;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using OpenTK;
|
|
using OpenTK.Graphics.OpenGL;
|
|
using PckStudio.Core.Extensions;
|
|
using PckStudio.Core;
|
|
using PckStudio.Core.Skin;
|
|
using PckStudio.Rendering.Extension;
|
|
|
|
namespace PckStudio.Rendering
|
|
{
|
|
public static class CubeMeshCollectionExtensions
|
|
{
|
|
public static void AddSkinBox(this CubeMeshCollection cubeMeshes, SkinBOX skinBox, float inflate = 0f)
|
|
{
|
|
var cube = skinBox.ToCube(inflate, cubeMeshes.FlipZMapping);
|
|
cubeMeshes.Add(new CubeMesh(skinBox.Type, cube));
|
|
}
|
|
}
|
|
|
|
public class CubeMeshCollection : GenericMesh<TextureVertex>, ICollection<GenericMesh<TextureVertex>>
|
|
{
|
|
private List<GenericMesh<TextureVertex>> cubes;
|
|
private Dictionary<string, CubeMeshCollection> subCollection;
|
|
|
|
public bool FlipZMapping
|
|
{
|
|
get => _flipZMapping;
|
|
set => _flipZMapping = value;
|
|
}
|
|
|
|
public Vector3 Translation { get; set; }
|
|
public Vector3 Rotation { get; }
|
|
public Vector3 Pivot { get; }
|
|
private Vector3 _offset { get; set; } = Vector3.Zero;
|
|
public Vector3 Offset
|
|
{
|
|
get => _offset;
|
|
set => _offset = value;
|
|
}
|
|
|
|
public override Matrix4 GetTransform()
|
|
{
|
|
Matrix4 rotations = (
|
|
Matrix4.CreateRotationX(MathHelper.DegreesToRadians(Rotation.X)) *
|
|
Matrix4.CreateRotationY(MathHelper.DegreesToRadians(Rotation.Y)) *
|
|
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation.Z))
|
|
);
|
|
Matrix4 translation = Matrix4.CreateTranslation(Translation + Offset);
|
|
return translation * rotations.Pivoted(Pivot - Offset);
|
|
}
|
|
|
|
public int Count => cubes.Count;
|
|
|
|
public bool IsReadOnly => false;
|
|
|
|
private bool _flipZMapping = false;
|
|
|
|
public CubeMeshCollection(string name, bool visible = true) : base(name, visible, PrimitiveType.Triangles, CubeMesh.VertexBufferLayout)
|
|
{
|
|
cubes = new List<GenericMesh<TextureVertex>>(5);
|
|
subCollection = new Dictionary<string, CubeMeshCollection>();
|
|
}
|
|
|
|
public CubeMeshCollection(string name, Vector3 translation, Vector3 pivot, Vector3 rotation = default)
|
|
: this(name)
|
|
{
|
|
Translation = translation;
|
|
Pivot = pivot;
|
|
Rotation = rotation;
|
|
}
|
|
|
|
public override GenericMesh<TextureVertex> SetVisible(bool visible)
|
|
{
|
|
if (Visible == visible)
|
|
return this;
|
|
|
|
var mesh = new CubeMeshCollection(Name, visible);
|
|
mesh.cubes = this.cubes;
|
|
return mesh;
|
|
}
|
|
|
|
public override IEnumerable<TextureVertex> GetVertices()
|
|
=> cubes.Where(c => c.Visible).SelectMany(c =>
|
|
c.GetVertices().Select(vertex => new TextureVertex(Vector3.TransformPosition(vertex.Position, c.GetTransform()), vertex.TexPosition))
|
|
);
|
|
|
|
public override IEnumerable<int> GetIndices()
|
|
{
|
|
int offset = 0;
|
|
IEnumerable<int> selector(GenericMesh<TextureVertex> c)
|
|
{
|
|
IEnumerable<int> result = c.GetIndices().Select(i => i + offset).ToArray();
|
|
int vertexCount = c.GetVertices().Count();
|
|
offset += vertexCount;
|
|
return result;
|
|
}
|
|
return cubes.Where(c => c.Visible).SelectMany(selector);
|
|
}
|
|
|
|
public void Add(Vector3 position, Vector3 size, Vector2 uv, float inflate = 0f, bool mirrorTexture = false)
|
|
{
|
|
var cube = new Cube(position, size, uv, inflate, mirrorTexture, FlipZMapping);
|
|
Add(new CubeMesh(cube));
|
|
}
|
|
|
|
public void AddNamed(string name, Vector3 position, Vector3 size, Vector2 uv, float inflate = 0f, bool mirrorTexture = false)
|
|
{
|
|
var cube = new Cube(position, size, uv, inflate, mirrorTexture, FlipZMapping);
|
|
Add(new CubeMesh(name, cube));
|
|
}
|
|
|
|
internal void AddSubCollection(string name, Vector3 translation, Vector3 pivot, Vector3 rotation = default)
|
|
{
|
|
var item = new CubeMeshCollection(name, translation, pivot, rotation);
|
|
Add(item);
|
|
subCollection.Add(name, item);
|
|
}
|
|
|
|
public CubeMeshCollection GetCollection(string collectionName)
|
|
{
|
|
_ = collectionName ?? throw new ArgumentNullException(nameof(collectionName));
|
|
return ContainsCollection(collectionName) ? subCollection[collectionName] : null;
|
|
}
|
|
|
|
public void Remove(int index)
|
|
{
|
|
if (!cubes.IndexInRange(index))
|
|
throw new IndexOutOfRangeException();
|
|
|
|
cubes.RemoveAt(index);
|
|
}
|
|
|
|
public void ReplaceCube(int index, Vector3 position, Vector3 size, Vector2 uv, float inflate = 0f, bool mirrorTexture = false)
|
|
{
|
|
if (!cubes.IndexInRange(index))
|
|
throw new IndexOutOfRangeException();
|
|
|
|
|
|
if (cubes[index] is CubeMesh cubeMesh)
|
|
cubes[index] = cubeMesh.SetCube(new Cube(position, size, uv, inflate, mirrorTexture, FlipZMapping));
|
|
}
|
|
|
|
public Vector3 GetCenter(int index)
|
|
{
|
|
if (!cubes.IndexInRange(index))
|
|
throw new IndexOutOfRangeException();
|
|
|
|
return cubes[index].GetBounds(GetTransform()).Center;
|
|
}
|
|
|
|
public BoundingBox GetCubeBoundingBox(int index)
|
|
{
|
|
if (!cubes.IndexInRange(index))
|
|
throw new IndexOutOfRangeException();
|
|
|
|
return cubes[index].GetBounds(GetTransform());
|
|
}
|
|
|
|
public override BoundingBox GetBounds(Matrix4 transform)
|
|
{
|
|
return cubes
|
|
.Where(c => c.Visible)
|
|
.Select(c => c.GetBounds(GetTransform() * transform))
|
|
.GetEnclosingBoundingBox();
|
|
}
|
|
|
|
public Vector3 GetFaceCenter(int index, Cube.Face face)
|
|
{
|
|
if (!cubes.IndexInRange(index))
|
|
throw new IndexOutOfRangeException();
|
|
|
|
Vector3 faceCenter = cubes[index] is CubeMesh c ? c.GetCube().GetFaceCenter(face) : Vector3.Zero;
|
|
return Vector3.TransformPosition(faceCenter, GetTransform());
|
|
}
|
|
|
|
public void SetVisible(int index, bool visible)
|
|
{
|
|
if (!cubes.IndexInRange(index))
|
|
throw new IndexOutOfRangeException();
|
|
if (cubes[index].Visible == visible)
|
|
return;
|
|
cubes[index] = cubes[index].SetVisible(visible);
|
|
}
|
|
|
|
public void Add(GenericMesh<TextureVertex> item) => cubes.Add(item);
|
|
|
|
public void Clear()
|
|
{
|
|
subCollection.Clear();
|
|
cubes.Clear();
|
|
}
|
|
|
|
public bool Contains(GenericMesh<TextureVertex> item)
|
|
{
|
|
return cubes.Any(c => c.Name == item.Name);
|
|
}
|
|
|
|
public bool ContainsCollection(string collectionName) => subCollection.ContainsKey(key: collectionName);
|
|
|
|
public bool Contains(GenericMesh<TextureVertex> item, bool searchSubCollections)
|
|
{
|
|
return Contains(item) || (searchSubCollections && subCollection.Values.Any(collection => collection.Contains(item, searchSubCollections)));
|
|
}
|
|
|
|
public void CopyTo(GenericMesh<TextureVertex>[] array, int arrayIndex)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool Remove(GenericMesh<TextureVertex> item) => cubes.Remove(item);
|
|
|
|
public IEnumerator<GenericMesh<TextureVertex>> GetEnumerator() => cubes.GetEnumerator();
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
}
|
|
}
|