// ----------------------------------------------------------------------------- // file="PlainGeometryMesh" // Project: StgSharp // Copyright (c) Nitload. // SPDX-License-Identifier: MIT // ----------------------------------------------------------------------------- using Nitload.Geometries; using Nitload.Mathematics; using Nitload.Mathematics.Numeric.Graphics; using System; using System.Runtime.InteropServices; namespace Nitload.Graphics { public class PlainGeometryMesh { private readonly Vec2[] _textureCoordinates; private readonly Image _textureImage; private readonly PlainGeometry _shape; public PlainGeometryMesh( PlainGeometry shape, Image texture, Vec2[] texCoord ) { ArgumentNullException.ThrowIfNull(shape); ArgumentNullException.ThrowIfNull(texture); ArgumentNullException.ThrowIfNull(texCoord); if (shape.VertexCount > texCoord.Length) { throw new ArgumentException( paramName:nameof(texCoord), message:"Amount of texture coordination is too less"); } _shape = shape; _textureImage = texture; _textureCoordinates = texCoord; } public Vec3[] VertexArray => _shape.VertexStream; public Image TextureImage => _textureImage; public ReadOnlySpan MeshIndices => _shape.VertexIndices; public ReadOnlySpan> TextureCoord => _textureCoordinates; public PlainGeometryMesh Resize( PlainGeometry newShape ) { return new PlainGeometryMesh(newShape, _textureImage, _textureCoordinates); } } }