Files
stgsharp/源代码/StgSharp/Graphics/PlainGeometryMesh.cs
T

59 lines
1.5 KiB
C#

using StgSharp.Geometries;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StgSharp.Graphics
{
public class PlainGeometryMesh
{
private IGeometry _shape;
private Image _texture;
private vec2d[] textureCoord;
public PlainGeometryMesh(
IGeometry shape, Image texture, IEnumerable<vec2d> texCoord
)
{
if (shape==null)
{
throw new ArgumentNullException(nameof(shape));
}
if (texCoord == null)
{
throw new ArgumentNullException(nameof(texCoord));
}
_shape = shape;
textureCoord = new vec2d[shape.VertexCount];
_texture = texture;
if (texCoord is not vec2d[] source)
{
source = texCoord.ToArray();
}
if (textureCoord.Length > source.Length)
{
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
}
Array.Copy(sourceArray: source, textureCoord, textureCoord.Length);
return;
}
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
public vec4d[] VertexArray => _shape.VertexStream;
public Image Texture
{
get => _texture;
internal set => _texture = value;
}
public vec2d[] TextureCoord => textureCoord;
}
}