Move Cube conversion into SkinBOXExtensions

This commit is contained in:
miku-666
2024-09-21 10:49:24 +02:00
parent 3c52e863e6
commit 6c38d688e5
4 changed files with 17 additions and 13 deletions

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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<TextureVertex>, ICollection<CubeMesh>
{
private List<CubeMesh> 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<TextureVertex> GetVertices()
=> cubes.Where(c => c.ShouldRender).SelectMany(c => c.GetVertices());

View File

@@ -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();