|
@@ -15,8 +15,8 @@ namespace SharpGLTF.Geometry
|
|
|
|
|
|
|
|
int VertexCount { get; }
|
|
int VertexCount { get; }
|
|
|
|
|
|
|
|
- VertexBuilder<TvPP, TvMM, TvSS> GetVertex<TvPP, TvMM, TvSS>(int index)
|
|
|
|
|
- where TvPP : struct, IVertexGeometry
|
|
|
|
|
|
|
+ VertexBuilder<TvGG, TvMM, TvSS> GetVertex<TvGG, TvMM, TvSS>(int index)
|
|
|
|
|
+ where TvGG : struct, IVertexGeometry
|
|
|
where TvMM : struct, IVertexMaterial
|
|
where TvMM : struct, IVertexMaterial
|
|
|
where TvSS : struct, IVertexSkinning;
|
|
where TvSS : struct, IVertexSkinning;
|
|
|
|
|
|
|
@@ -31,13 +31,13 @@ namespace SharpGLTF.Geometry
|
|
|
|
|
|
|
|
public interface IPrimitiveBuilder
|
|
public interface IPrimitiveBuilder
|
|
|
{
|
|
{
|
|
|
- void AddTriangle<TvPP, TvMM, TvSS>
|
|
|
|
|
|
|
+ void AddTriangle<TvGG, TvMM, TvSS>
|
|
|
(
|
|
(
|
|
|
- VertexBuilder<TvPP, TvMM, TvSS> a,
|
|
|
|
|
- VertexBuilder<TvPP, TvMM, TvSS> b,
|
|
|
|
|
- VertexBuilder<TvPP, TvMM, TvSS> c
|
|
|
|
|
|
|
+ VertexBuilder<TvGG, TvMM, TvSS> a,
|
|
|
|
|
+ VertexBuilder<TvGG, TvMM, TvSS> b,
|
|
|
|
|
+ VertexBuilder<TvGG, TvMM, TvSS> c
|
|
|
)
|
|
)
|
|
|
- where TvPP : struct, IVertexGeometry
|
|
|
|
|
|
|
+ where TvGG : struct, IVertexGeometry
|
|
|
where TvMM : struct, IVertexMaterial
|
|
where TvMM : struct, IVertexMaterial
|
|
|
where TvSS : struct, IVertexSkinning;
|
|
where TvSS : struct, IVertexSkinning;
|
|
|
}
|
|
}
|
|
@@ -46,7 +46,7 @@ namespace SharpGLTF.Geometry
|
|
|
/// Represents an utility class to help build mesh primitives by adding triangles
|
|
/// Represents an utility class to help build mesh primitives by adding triangles
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <typeparam name="TMaterial">The material type used by this <see cref="PrimitiveBuilder{TMaterial, TvP, TvM, TvS}"/> instance.</typeparam>
|
|
/// <typeparam name="TMaterial">The material type used by this <see cref="PrimitiveBuilder{TMaterial, TvP, TvM, TvS}"/> instance.</typeparam>
|
|
|
- /// <typeparam name="TvP">
|
|
|
|
|
|
|
+ /// <typeparam name="TvG">
|
|
|
/// The vertex fragment type with Position, Normal and Tangent.
|
|
/// The vertex fragment type with Position, Normal and Tangent.
|
|
|
/// Valid types are:
|
|
/// Valid types are:
|
|
|
/// <see cref="VertexPosition"/>,
|
|
/// <see cref="VertexPosition"/>,
|
|
@@ -71,14 +71,14 @@ namespace SharpGLTF.Geometry
|
|
|
/// <see cref="VertexJoints16x8"/>.
|
|
/// <see cref="VertexJoints16x8"/>.
|
|
|
/// </typeparam>
|
|
/// </typeparam>
|
|
|
[System.Diagnostics.DebuggerDisplay("Primitive {_Material}")]
|
|
[System.Diagnostics.DebuggerDisplay("Primitive {_Material}")]
|
|
|
- public class PrimitiveBuilder<TMaterial, TvP, TvM, TvS> : IPrimitiveBuilder, IPrimitive<TMaterial>
|
|
|
|
|
- where TvP : struct, IVertexGeometry
|
|
|
|
|
|
|
+ public class PrimitiveBuilder<TMaterial, TvG, TvM, TvS> : IPrimitiveBuilder, IPrimitive<TMaterial>
|
|
|
|
|
+ where TvG : struct, IVertexGeometry
|
|
|
where TvM : struct, IVertexMaterial
|
|
where TvM : struct, IVertexMaterial
|
|
|
where TvS : struct, IVertexSkinning
|
|
where TvS : struct, IVertexSkinning
|
|
|
{
|
|
{
|
|
|
#region lifecycle
|
|
#region lifecycle
|
|
|
|
|
|
|
|
- internal PrimitiveBuilder(MeshBuilder<TMaterial, TvP, TvM, TvS> mesh, TMaterial material, int primitiveVertexCount, bool strict)
|
|
|
|
|
|
|
+ internal PrimitiveBuilder(MeshBuilder<TMaterial, TvG, TvM, TvS> mesh, TMaterial material, int primitiveVertexCount, bool strict)
|
|
|
{
|
|
{
|
|
|
this._Scrict = strict;
|
|
this._Scrict = strict;
|
|
|
this._Mesh = mesh;
|
|
this._Mesh = mesh;
|
|
@@ -92,20 +92,20 @@ namespace SharpGLTF.Geometry
|
|
|
|
|
|
|
|
private readonly bool _Scrict;
|
|
private readonly bool _Scrict;
|
|
|
|
|
|
|
|
- private readonly MeshBuilder<TMaterial, TvP, TvM, TvS> _Mesh;
|
|
|
|
|
|
|
+ private readonly MeshBuilder<TMaterial, TvG, TvM, TvS> _Mesh;
|
|
|
|
|
|
|
|
private readonly TMaterial _Material;
|
|
private readonly TMaterial _Material;
|
|
|
|
|
|
|
|
private readonly int _PrimitiveVertexCount;
|
|
private readonly int _PrimitiveVertexCount;
|
|
|
|
|
|
|
|
- private readonly VertexList<VertexBuilder<TvP, TvM, TvS>> _Vertices = new VertexList<VertexBuilder<TvP, TvM, TvS>>();
|
|
|
|
|
|
|
+ private readonly VertexList<VertexBuilder<TvG, TvM, TvS>> _Vertices = new VertexList<VertexBuilder<TvG, TvM, TvS>>();
|
|
|
private readonly List<int> _Indices = new List<int>();
|
|
private readonly List<int> _Indices = new List<int>();
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region properties
|
|
#region properties
|
|
|
|
|
|
|
|
- public MeshBuilder<TMaterial, TvP, TvM, TvS> Mesh => _Mesh;
|
|
|
|
|
|
|
+ public MeshBuilder<TMaterial, TvG, TvM, TvS> Mesh => _Mesh;
|
|
|
|
|
|
|
|
public TMaterial Material => _Material;
|
|
public TMaterial Material => _Material;
|
|
|
|
|
|
|
@@ -119,7 +119,7 @@ namespace SharpGLTF.Geometry
|
|
|
|
|
|
|
|
public int VertexCount => Vertices.Count;
|
|
public int VertexCount => Vertices.Count;
|
|
|
|
|
|
|
|
- public IReadOnlyList<VertexBuilder<TvP, TvM, TvS>> Vertices => _Vertices;
|
|
|
|
|
|
|
+ public IReadOnlyList<VertexBuilder<TvG, TvM, TvS>> Vertices => _Vertices;
|
|
|
|
|
|
|
|
public IReadOnlyList<int> Indices => _Indices;
|
|
public IReadOnlyList<int> Indices => _Indices;
|
|
|
|
|
|
|
@@ -138,12 +138,12 @@ namespace SharpGLTF.Geometry
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="vertex">
|
|
/// <param name="vertex">
|
|
|
/// A vertex formed by
|
|
/// A vertex formed by
|
|
|
- /// <typeparamref name="TvP"/>,
|
|
|
|
|
|
|
+ /// <typeparamref name="TvG"/>,
|
|
|
/// <typeparamref name="TvM"/> and
|
|
/// <typeparamref name="TvM"/> and
|
|
|
/// <typeparamref name="TvS"/> fragments.
|
|
/// <typeparamref name="TvS"/> fragments.
|
|
|
/// </param>
|
|
/// </param>
|
|
|
/// <returns>The index of the vertex.</returns>
|
|
/// <returns>The index of the vertex.</returns>
|
|
|
- public int UseVertex(VertexBuilder<TvP, TvM, TvS> vertex)
|
|
|
|
|
|
|
+ public int UseVertex(VertexBuilder<TvG, TvM, TvS> vertex)
|
|
|
{
|
|
{
|
|
|
if (_Scrict) vertex.Validate();
|
|
if (_Scrict) vertex.Validate();
|
|
|
|
|
|
|
@@ -154,7 +154,7 @@ namespace SharpGLTF.Geometry
|
|
|
/// Adds a point.
|
|
/// Adds a point.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="a">vertex for this point.</param>
|
|
/// <param name="a">vertex for this point.</param>
|
|
|
- public void AddPoint(VertexBuilder<TvP, TvM, TvS> a)
|
|
|
|
|
|
|
+ public void AddPoint(VertexBuilder<TvG, TvM, TvS> a)
|
|
|
{
|
|
{
|
|
|
Guard.IsTrue(_PrimitiveVertexCount == 1, nameof(VerticesPerPrimitive), "Points are not supported for this primitive");
|
|
Guard.IsTrue(_PrimitiveVertexCount == 1, nameof(VerticesPerPrimitive), "Points are not supported for this primitive");
|
|
|
|
|
|
|
@@ -166,7 +166,7 @@ namespace SharpGLTF.Geometry
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="a">First corner of the line.</param>
|
|
/// <param name="a">First corner of the line.</param>
|
|
|
/// <param name="b">Second corner of the line.</param>
|
|
/// <param name="b">Second corner of the line.</param>
|
|
|
- public void AddLine(VertexBuilder<TvP, TvM, TvS> a, VertexBuilder<TvP, TvM, TvS> b)
|
|
|
|
|
|
|
+ public void AddLine(VertexBuilder<TvG, TvM, TvS> a, VertexBuilder<TvG, TvM, TvS> b)
|
|
|
{
|
|
{
|
|
|
Guard.IsTrue(_PrimitiveVertexCount == 2, nameof(VerticesPerPrimitive), "Lines are not supported for this primitive");
|
|
Guard.IsTrue(_PrimitiveVertexCount == 2, nameof(VerticesPerPrimitive), "Lines are not supported for this primitive");
|
|
|
|
|
|
|
@@ -192,7 +192,7 @@ namespace SharpGLTF.Geometry
|
|
|
/// <param name="a">First corner of the triangle.</param>
|
|
/// <param name="a">First corner of the triangle.</param>
|
|
|
/// <param name="b">Second corner of the triangle.</param>
|
|
/// <param name="b">Second corner of the triangle.</param>
|
|
|
/// <param name="c">Third corner of the triangle.</param>
|
|
/// <param name="c">Third corner of the triangle.</param>
|
|
|
- public void AddTriangle(VertexBuilder<TvP, TvM, TvS> a, VertexBuilder<TvP, TvM, TvS> b, VertexBuilder<TvP, TvM, TvS> c)
|
|
|
|
|
|
|
+ public void AddTriangle(VertexBuilder<TvG, TvM, TvS> a, VertexBuilder<TvG, TvM, TvS> b, VertexBuilder<TvG, TvM, TvS> c)
|
|
|
{
|
|
{
|
|
|
Guard.IsTrue(_PrimitiveVertexCount == 3, nameof(VerticesPerPrimitive), "Triangles are not supported for this primitive");
|
|
Guard.IsTrue(_PrimitiveVertexCount == 3, nameof(VerticesPerPrimitive), "Triangles are not supported for this primitive");
|
|
|
|
|
|
|
@@ -222,7 +222,7 @@ namespace SharpGLTF.Geometry
|
|
|
/// Polygon triangulation is performed by a <see cref="IPolygonTriangulator"/>
|
|
/// Polygon triangulation is performed by a <see cref="IPolygonTriangulator"/>
|
|
|
/// instance defined in <see cref="MeshBuilder{TMaterial, TvP, TvM, TvS}.Triangulator"/>
|
|
/// instance defined in <see cref="MeshBuilder{TMaterial, TvP, TvM, TvS}.Triangulator"/>
|
|
|
/// </remarks>
|
|
/// </remarks>
|
|
|
- public void AddPolygon(params VertexBuilder<TvP, TvM, TvS>[] points)
|
|
|
|
|
|
|
+ public void AddPolygon(params VertexBuilder<TvG, TvM, TvS>[] points)
|
|
|
{
|
|
{
|
|
|
Span<Vector3> vertices = stackalloc Vector3[points.Length];
|
|
Span<Vector3> vertices = stackalloc Vector3[points.Length];
|
|
|
|
|
|
|
@@ -249,7 +249,7 @@ namespace SharpGLTF.Geometry
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- internal void AddPrimitive(PrimitiveBuilder<TMaterial, TvP, TvM, TvS> primitive, Func<VertexBuilder<TvP, TvM, TvS>, VertexBuilder<TvP, TvM, TvS>> vertexTransform)
|
|
|
|
|
|
|
+ internal void AddPrimitive(PrimitiveBuilder<TMaterial, TvG, TvM, TvS> primitive, Func<VertexBuilder<TvG, TvM, TvS>, VertexBuilder<TvG, TvM, TvS>> vertexTransform)
|
|
|
{
|
|
{
|
|
|
if (primitive == null) throw new ArgumentNullException(nameof(primitive));
|
|
if (primitive == null) throw new ArgumentNullException(nameof(primitive));
|
|
|
|
|
|
|
@@ -306,9 +306,9 @@ namespace SharpGLTF.Geometry
|
|
|
where TvMM : struct, IVertexMaterial
|
|
where TvMM : struct, IVertexMaterial
|
|
|
where TvSS : struct, IVertexSkinning
|
|
where TvSS : struct, IVertexSkinning
|
|
|
{
|
|
{
|
|
|
- var aa = a.ConvertTo<TvP, TvM, TvS>();
|
|
|
|
|
- var bb = b.ConvertTo<TvP, TvM, TvS>();
|
|
|
|
|
- var cc = c.ConvertTo<TvP, TvM, TvS>();
|
|
|
|
|
|
|
+ var aa = a.ConvertTo<TvG, TvM, TvS>();
|
|
|
|
|
+ var bb = b.ConvertTo<TvG, TvM, TvS>();
|
|
|
|
|
+ var cc = c.ConvertTo<TvG, TvM, TvS>();
|
|
|
|
|
|
|
|
AddTriangle(aa, bb, cc);
|
|
AddTriangle(aa, bb, cc);
|
|
|
}
|
|
}
|
|
@@ -344,7 +344,7 @@ namespace SharpGLTF.Geometry
|
|
|
return Schema2.PrimitiveType.TRIANGLES.GetTrianglesIndices(_Indices.Select(item => (uint)item));
|
|
return Schema2.PrimitiveType.TRIANGLES.GetTrianglesIndices(_Indices.Select(item => (uint)item));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void TransformVertices(Func<VertexBuilder<TvP, TvM, TvS>, VertexBuilder<TvP, TvM, TvS>> transformFunc)
|
|
|
|
|
|
|
+ public void TransformVertices(Func<VertexBuilder<TvG, TvM, TvS>, VertexBuilder<TvG, TvM, TvS>> transformFunc)
|
|
|
{
|
|
{
|
|
|
_Vertices.TransformVertices(transformFunc);
|
|
_Vertices.TransformVertices(transformFunc);
|
|
|
}
|
|
}
|