mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-12 14:41:54 +00:00
SkinRenderer - Fix rendering guidelines
This commit is contained in:
21
PCK-Studio/Extensions/OpenTkMatrixExtensions.cs
Normal file
21
PCK-Studio/Extensions/OpenTkMatrixExtensions.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTK;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
internal static class OpenTkMatrixExtensions
|
||||
{
|
||||
internal static Matrix4 Pivoted(this Matrix4 target, Vector3 translation, Vector3 pivot)
|
||||
{
|
||||
var model = Matrix4.CreateTranslation(translation);
|
||||
model *= Matrix4.CreateTranslation(pivot);
|
||||
model *= target;
|
||||
model *= Matrix4.CreateTranslation(pivot).Inverted();
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,7 @@
|
||||
<Reference Include="WindowsFormsIntegration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions\OpenTkMatrixExtensions.cs" />
|
||||
<Compile Include="Internal\IO\PSM\PSMFileReader.cs" />
|
||||
<Compile Include="Internal\IO\PSM\PSMFileWriter.cs" />
|
||||
<Compile Include="Internal\IO\TGA\TGADeserializer.cs" />
|
||||
|
||||
@@ -136,12 +136,12 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
private Matrix4 Transform
|
||||
internal Matrix4 Transform
|
||||
{
|
||||
get => Matrix4.CreateTranslation(Translation) * Matrix4.CreateTranslation(Pivot * 2);
|
||||
get => Matrix4.Identity.Pivoted(Translation - Offset, Pivot + Offset);
|
||||
}
|
||||
|
||||
internal Vector3 GetWorldPosition(Vector3 localPosition) => Vector3.TransformPosition(localPosition, Transform);
|
||||
internal Vector3 GetWorldPosition(Vector3 localPosition) => (Matrix4.CreateTranslation(localPosition) * Transform).Inverted().ExtractTranslation();
|
||||
|
||||
internal Vector3 GetCenter(int index)
|
||||
{
|
||||
@@ -157,14 +157,15 @@ namespace PckStudio.Rendering
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
CubeMesh cube = cubes[index];
|
||||
return cube.GetBoundingBox(Transform);
|
||||
var bb = cube.GetBoundingBox();
|
||||
return new BoundingBox(GetWorldPosition(bb.Start.ToOpenTKVector() * new Vector3(1, -1, -1)).ToNumericsVector(), GetWorldPosition(bb.End.ToOpenTKVector() * new Vector3(1, -1, -1)).ToNumericsVector());
|
||||
}
|
||||
|
||||
internal Vector3 GetFaceCenter(int index, Cube.Face face)
|
||||
{
|
||||
if (!cubes.IndexInRange(index))
|
||||
throw new IndexOutOfRangeException();
|
||||
return GetWorldPosition(cubes[index].GetFaceCenter(face));
|
||||
return GetWorldPosition(cubes[index].GetFaceCenter(face) * new Vector3(1,-1,-1));
|
||||
}
|
||||
|
||||
internal void SetEnabled(int index, bool enable)
|
||||
|
||||
@@ -1040,7 +1040,8 @@ namespace PckStudio.Rendering
|
||||
{
|
||||
if (ANIM.GetFlag(SkinAnimFlag.DINNERBONE))
|
||||
{
|
||||
transform = Pivot(head.GetFaceCenter(0, Cube.Face.Top), Vector3.UnitY * 12f, transform * Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(-180f)));
|
||||
transform *= Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(-180f));
|
||||
transform = transform.Pivoted(head.GetFaceCenter(0, Cube.Face.Top), Vector3.UnitY * 12f);
|
||||
}
|
||||
|
||||
if (!ANIM.GetFlag(SkinAnimFlag.STATIC_ARMS))
|
||||
@@ -1165,10 +1166,10 @@ namespace PckStudio.Rendering
|
||||
{
|
||||
case "ARM0":
|
||||
case "SLEEVE0":
|
||||
return RightArmMatrix * armRightMatrix;
|
||||
return armRightMatrix;
|
||||
case "ARM1":
|
||||
case "SLEEVE1":
|
||||
return LeftArmMatrix * armLeftMatrix;
|
||||
return armLeftMatrix;
|
||||
case "LEG0":
|
||||
case "PANTS0":
|
||||
return legRightMatrix;
|
||||
@@ -1181,9 +1182,7 @@ namespace PckStudio.Rendering
|
||||
}
|
||||
|
||||
transform *= GetGroupTransform(box.Type);
|
||||
Vector3 translation = cubeMesh.Translation - cubeMesh.Offset;
|
||||
Vector3 pivot = cubeMesh.Pivot + cubeMesh.Offset;
|
||||
transform = Pivot(translation, pivot, transform);
|
||||
transform *= cubeMesh.Transform;
|
||||
GL.BlendFunc(BlendingFactor.DstAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
DrawBoundingBox(transform, cubeBoundingBox, HighlightlingColor);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
@@ -1293,23 +1292,13 @@ namespace PckStudio.Rendering
|
||||
|
||||
private void RenderPart(ShaderProgram shader, CubeGroupMesh cubeMesh, Matrix4 partMatrix, Matrix4 globalMatrix)
|
||||
{
|
||||
Vector3 translation = cubeMesh.Translation - cubeMesh.Offset;
|
||||
Vector3 pivot = cubeMesh.Pivot + cubeMesh.Offset;
|
||||
Matrix4 transform = Pivot(translation, pivot, partMatrix);
|
||||
Matrix4 transform = partMatrix;
|
||||
transform *= cubeMesh.Transform;
|
||||
transform *= globalMatrix;
|
||||
shader.SetUniformMat4("u_Transform", ref transform);
|
||||
cubeMesh.Draw(shader);
|
||||
}
|
||||
|
||||
private static Matrix4 Pivot(Vector3 translation, Vector3 pivot, Matrix4 target)
|
||||
{
|
||||
var model = Matrix4.CreateTranslation(translation);
|
||||
model *= Matrix4.CreateTranslation(pivot);
|
||||
model *= target;
|
||||
model *= Matrix4.CreateTranslation(pivot).Inverted();
|
||||
return model;
|
||||
}
|
||||
|
||||
protected override void OnUpdate(object sender, TimestepEventArgs e)
|
||||
{
|
||||
base.OnUpdate(sender, e);
|
||||
|
||||
Reference in New Issue
Block a user