Files
parkan-playground/NResUI/Rendering/Viewport/ViewportPiece.cs
T

85 lines
2.3 KiB
C#
Raw Normal View History

2026-06-05 20:33:21 +03:00
using System.Numerics;
using NResUI.Rendering.Viewport.Meshes;
namespace NResUI.Rendering.Viewport;
2026-06-12 02:06:32 +03:00
public sealed class ViewportPiece : IDisposable
2026-06-05 20:33:21 +03:00
{
public int Id { get; }
public string Name { get; }
2026-06-06 21:26:56 +03:00
public IReadOnlyList<GpuMesh> Meshes { get; }
public GpuMesh Mesh => Meshes[0];
2026-06-05 20:33:21 +03:00
public Matrix4x4 LocalTransform { get; set; }
public Vector3 BoundsMin { get; }
public Vector3 BoundsMax { get; }
2026-06-05 21:12:25 +03:00
public ViewportPieceDebugInfo? DebugInfo { get; }
2026-06-09 01:46:57 +03:00
public IReadOnlyList<int> SourceBatchIndices { get; }
2026-06-05 21:12:25 +03:00
2026-06-05 20:33:21 +03:00
public ViewportPiece(
int id,
string name,
GpuMesh mesh,
Matrix4x4 localTransform,
Vector3 boundsMin,
2026-06-05 21:12:25 +03:00
Vector3 boundsMax,
2026-06-09 01:46:57 +03:00
ViewportPieceDebugInfo? debugInfo = null,
IReadOnlyList<int>? sourceBatchIndices = null)
: this(id, name, new[] { mesh }, localTransform, boundsMin, boundsMax, debugInfo, sourceBatchIndices)
2026-06-06 21:26:56 +03:00
{
}
public ViewportPiece(
int id,
string name,
IReadOnlyList<GpuMesh> meshes,
Matrix4x4 localTransform,
Vector3 boundsMin,
Vector3 boundsMax,
2026-06-09 01:46:57 +03:00
ViewportPieceDebugInfo? debugInfo = null,
IReadOnlyList<int>? sourceBatchIndices = null)
2026-06-05 20:33:21 +03:00
{
2026-06-06 21:26:56 +03:00
if (meshes.Count == 0)
throw new ArgumentException("A viewport piece must contain at least one mesh.", nameof(meshes));
2026-06-05 20:33:21 +03:00
Id = id;
Name = name;
2026-06-06 21:26:56 +03:00
Meshes = meshes;
2026-06-05 20:33:21 +03:00
LocalTransform = localTransform;
BoundsMin = boundsMin;
BoundsMax = boundsMax;
2026-06-05 21:12:25 +03:00
DebugInfo = debugInfo;
2026-06-09 01:46:57 +03:00
SourceBatchIndices = sourceBatchIndices ?? [];
2026-06-05 20:33:21 +03:00
}
public static ViewportPiece CreateUnitCube(int id, string name, GpuMesh mesh)
{
return new ViewportPiece(
id,
name,
mesh,
Matrix4x4.Identity,
new Vector3(-1.0f, -1.0f, -1.0f),
2026-06-05 21:12:25 +03:00
new Vector3(1.0f, 1.0f, 1.0f),
new ViewportPieceDebugInfo
{
SourceKind = "Debug primitive",
SourcePieceIndex = id,
SourceParentIndex = -1,
GeometrySlotIndex = 0,
Msh01Flags = 0,
BatchCount = 1,
TriangleCount = 12
});
2026-06-05 20:33:21 +03:00
}
2026-06-12 02:06:32 +03:00
public void Dispose()
{
foreach (var mesh in Meshes)
mesh.Dispose();
}
2026-06-05 20:33:21 +03:00
}