SceneViewport - Change 'Transform' to 'GetTransform'

This commit is contained in:
miku-666
2024-10-23 10:32:53 +02:00
parent 1effa243fd
commit d523572235
5 changed files with 26 additions and 14 deletions

View File

@@ -51,8 +51,6 @@ namespace PckStudio.Rendering
22, 23, 20
];
public override Matrix4 Transform => Matrix4.Identity;
internal static VertexBufferLayout VertexBufferLayout { get; } = new VertexBufferLayout().Add(ShaderDataType.Float3).Add(ShaderDataType.Float2);
public CubeMesh(Cube cube) : this(nameof(CubeMesh), cube)
@@ -79,9 +77,14 @@ namespace PckStudio.Rendering
public Cube GetCube() => _cube;
public override Matrix4 GetTransform()
{
return Matrix4.Identity;
}
public override BoundingBox GetBounds(Matrix4 transform)
{
return _cube.GetBoundingBox(Transform * transform);
return _cube.GetBoundingBox(GetTransform() * transform);
}
internal override IEnumerable<TextureVertex> GetVertices()
@@ -90,7 +93,7 @@ namespace PckStudio.Rendering
Vector2 uv = _cube.Uv;
BoundingBox boundingBox = GetBounds(Transform);
BoundingBox boundingBox = GetBounds(GetTransform());
Vector3 from = boundingBox.Start;
Vector3 to = boundingBox.End;

View File

@@ -58,7 +58,16 @@ namespace PckStudio.Rendering
set => _offset = value;
}
public override Matrix4 Transform => (Matrix4.CreateRotationX(MathHelper.DegreesToRadians(Rotation.X)) * Matrix4.CreateRotationY(MathHelper.DegreesToRadians(Rotation.Y)) * Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation.Z))).Pivoted(Translation + _offset, Pivot);
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;
@@ -92,7 +101,7 @@ namespace PckStudio.Rendering
internal override IEnumerable<TextureVertex> GetVertices()
=> cubes.Where(c => c.Visible).SelectMany(c =>
c.GetVertices().Select(vertex => new TextureVertex(Vector3.TransformPosition(vertex.Position, c.Transform), vertex.TexPosition))
c.GetVertices().Select(vertex => new TextureVertex(Vector3.TransformPosition(vertex.Position, c.GetTransform()), vertex.TexPosition))
);
internal override IEnumerable<int> GetIndices()
@@ -156,7 +165,7 @@ namespace PckStudio.Rendering
if (!cubes.IndexInRange(index))
throw new IndexOutOfRangeException();
return cubes[index].GetBounds(Transform).Center;
return cubes[index].GetBounds(GetTransform()).Center;
}
internal BoundingBox GetCubeBoundingBox(int index)
@@ -164,14 +173,14 @@ namespace PckStudio.Rendering
if (!cubes.IndexInRange(index))
throw new IndexOutOfRangeException();
return cubes[index].GetBounds(Transform);
return cubes[index].GetBounds(GetTransform());
}
public override BoundingBox GetBounds(Matrix4 transform)
{
IEnumerable<BoundingBox> boundingBoxes = cubes
.Where(c => c.Visible)
.Select(c => c.GetBounds(Transform * transform));
.Select(c => c.GetBounds(GetTransform() * transform))
return BoundingBox.GetEnclosingBoundingBox(boundingBoxes);
}
@@ -181,7 +190,7 @@ namespace PckStudio.Rendering
throw new IndexOutOfRangeException();
Vector3 faceCenter = cubes[index] is CubeMesh c ? c.GetCube().GetFaceCenter(face) : Vector3.Zero;
return Vector3.TransformPosition(faceCenter, Transform);
return Vector3.TransformPosition(faceCenter, GetTransform());
}
internal void SetVisible(int index, bool visible)

View File

@@ -29,7 +29,6 @@ namespace PckStudio.Rendering
internal VertexBufferLayout VertexLayout { get; }
internal bool Visible { get; }
public abstract Matrix4 Transform { get; }
protected GenericMesh(string name, bool visible, PrimitiveType type, VertexBufferLayout vertexLayout)
{
@@ -41,6 +40,7 @@ namespace PckStudio.Rendering
public abstract GenericMesh<T> SetVisible(bool visible);
public abstract BoundingBox GetBounds(Matrix4 transform);
public abstract Matrix4 GetTransform();
internal abstract IEnumerable<T> GetVertices();
internal abstract IEnumerable<int> GetIndices();

View File

@@ -217,7 +217,7 @@ namespace PckStudio.Rendering
foreach (CubeMeshCollection item in _rootCollection)
{
DrawMesh(item, shader, item.Transform * Matrix4.CreateScale(1f, -1f, -1f));
DrawMesh(item, shader, item.GetTransform() * Matrix4.CreateScale(1f, -1f, -1f));
}
_modelRenderTexture.Unbind();
}

View File

@@ -1055,7 +1055,7 @@ namespace PckStudio.Rendering
float inflate = autoInflateOverlayParts && box.IsOverlayPart() ? box.Type == "HEADWEAR" ? OverlayScale * 2 : OverlayScale : 0f;
Cube cube = box.ToCube(inflate);
CubeMeshCollection cubeMesh = meshStorage[box.Type];
yield return cube.GetBoundingBox(cubeMesh.Transform);
yield return cube.GetBoundingBox(cubeMesh.GetTransform());
}
yield break;
}
@@ -1072,7 +1072,7 @@ namespace PckStudio.Rendering
private void RenderPart<T>(ShaderProgram shader, GenericMesh<T> mesh, Matrix4 partMatrix, Matrix4 globalMatrix) where T : struct
{
Matrix4 transform = partMatrix * mesh.Transform * globalMatrix;
Matrix4 transform = partMatrix * mesh.GetTransform() * globalMatrix;
DrawMesh(mesh, shader, transform);
}