From 6c38d688e5af81c9ecd8d25911d39e7544d9bcd1 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:49:24 +0200 Subject: [PATCH] Move Cube conversion into SkinBOXExtensions --- PCK-Studio/Extensions/SkinBOXExtensions.cs | 6 ++++++ PCK-Studio/Rendering/Cube.cs | 5 ----- PCK-Studio/Rendering/CubeMeshCollection.cs | 15 +++++++++------ PCK-Studio/Rendering/SkinRenderer.cs | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PCK-Studio/Extensions/SkinBOXExtensions.cs b/PCK-Studio/Extensions/SkinBOXExtensions.cs index 6a686e77..6c8d138a 100644 --- a/PCK-Studio/Extensions/SkinBOXExtensions.cs +++ b/PCK-Studio/Extensions/SkinBOXExtensions.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using PckStudio.Internal; using PckStudio.Internal.Skin; +using PckStudio.Rendering; namespace PckStudio.Extensions { @@ -62,5 +63,10 @@ namespace PckStudio.Extensions int index = Array.IndexOf(SkinBOX.OverlayTypes, type); return SkinBOX.BaseTypes.IndexInRange(index) ? SkinBOX.BaseTypes[index] : ""; } + + internal static Cube ToCube(this SkinBOX skinBOX) => skinBOX.ToCube(0f); + + internal static Cube ToCube(this SkinBOX skinBOX, float inflate, bool flipZMapping = false) + => new Cube(skinBOX.Pos.ToOpenTKVector(), skinBOX.Size.ToOpenTKVector(), skinBOX.UV.ToOpenTKVector(), skinBOX.Scale + inflate, skinBOX.Mirror, flipZMapping); } } diff --git a/PCK-Studio/Rendering/Cube.cs b/PCK-Studio/Rendering/Cube.cs index 24523120..f176ba59 100644 --- a/PCK-Studio/Rendering/Cube.cs +++ b/PCK-Studio/Rendering/Cube.cs @@ -50,11 +50,6 @@ namespace PckStudio.Rendering Right } - internal static Cube FromSkinBox(SkinBOX skinBOX) => FromSkinBox(skinBOX, 0f); - - internal static Cube FromSkinBox(SkinBOX skinBOX, float inflate, bool flipZMapping = false) - => new Cube(skinBOX.Pos.ToOpenTKVector(), skinBOX.Size.ToOpenTKVector(), skinBOX.UV.ToOpenTKVector(), skinBOX.Scale + inflate, skinBOX.Mirror, flipZMapping); - public Cube(Vector3 position, Vector3 size, Vector2 uv, float inflate, bool mirrorTexture, bool flipZMapping) { Position = position; diff --git a/PCK-Studio/Rendering/CubeMeshCollection.cs b/PCK-Studio/Rendering/CubeMeshCollection.cs index ce671ac1..3bb215da 100644 --- a/PCK-Studio/Rendering/CubeMeshCollection.cs +++ b/PCK-Studio/Rendering/CubeMeshCollection.cs @@ -28,6 +28,15 @@ using PckStudio.Internal.Skin; namespace PckStudio.Rendering { + static class CubeMeshCollectionExtensions + { + internal static void AddSkinBox(this CubeMeshCollection cubeMeshes, SkinBOX skinBox, float inflate = 0f) + { + var cube = skinBox.ToCube(inflate, cubeMeshes.FlipZMapping); + cubeMeshes.Add(new CubeMesh(cube).SetName(skinBox.Type)); + } + } + internal class CubeMeshCollection : GenericMesh, ICollection { private List cubes; @@ -81,12 +90,6 @@ namespace PckStudio.Rendering transform = Matrix4.CreateTranslation(Translation) * Matrix4.CreateScale(1f, -1f, -1f); } - internal void AddSkinBox(SkinBOX skinBox, float inflate = 0f) - { - var cube = Cube.FromSkinBox(skinBox, inflate, FlipZMapping); - cubes.Add(new CubeMesh(cube).SetName(skinBox.Type)); - } - internal override IEnumerable GetVertices() => cubes.Where(c => c.ShouldRender).SelectMany(c => c.GetVertices()); diff --git a/PCK-Studio/Rendering/SkinRenderer.cs b/PCK-Studio/Rendering/SkinRenderer.cs index 7f2407b1..16cbb3fc 100644 --- a/PCK-Studio/Rendering/SkinRenderer.cs +++ b/PCK-Studio/Rendering/SkinRenderer.cs @@ -805,7 +805,7 @@ namespace PckStudio.Rendering } CubeMeshCollection cubeMesh = meshStorage[skinBox.Type]; - Vector3 center = Cube.FromSkinBox(skinBox).Center; + Vector3 center = skinBox.ToCube().Center; Matrix4 camMat = (Matrix4.CreateTranslation(cubeMesh.Translation) * Matrix4.CreateTranslation(center + cubeMesh.Offset) * Matrix4.CreateScale(-1, 1, 1)); Vector3 camPos = camMat.ExtractTranslation(); Camera.FocalPoint = camPos; @@ -995,7 +995,7 @@ namespace PckStudio.Rendering SkinBOX box = ModelData[SelectedIndex]; float inflate = autoInflateOverlayParts && box.IsOverlayPart() ? box.Type == "HEADWEAR" ? OverlayScale * 2 : OverlayScale : 0f; - Cube cube = Cube.FromSkinBox(box, inflate); + Cube cube = box.ToCube(inflate); BoundingBox cubeBoundingBox = cube.GetBoundingBox();