Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move MathNet.Numerics out of RvmSharp #157

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CadRevealComposer.Tests/Utils/MeshTools/MeshToolsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MeshToolsTests
public void Test_DeduplicateVertices()
{
// Sample data is not a valid mesh, but tests logic
var mesh = new Mesh(new[] { Vector3.One, Vector3.Zero, Vector3.One }, new uint[] { 0, 1, 2, 1, 0, 2 }, 0);
var mesh = new Mesh(new[] { Vector3.One, Vector3.Zero, Vector3.One }, new int[] { 0, 1, 2, 1, 0, 2 }, 0);
var newMesh = MeshTools.DeduplicateVertices(mesh);
Assert.That(newMesh.Vertices, Is.EquivalentTo(new[] { Vector3.One, Vector3.Zero }));

Expand All @@ -23,7 +23,7 @@ public void Test_DeduplicateVertices()
public void EnsureDeduplicateVertices_DoesNothing_WhenNoVertsAreDuplicates()
{
// Sample data is not a valid mesh, but tests logic
var inputMesh = new Mesh(new[] { Vector3.One, Vector3.Zero, -Vector3.One }, new uint[] { 0, 1, 2, 1, 0, 2 }, 0);
var inputMesh = new Mesh(new[] { Vector3.One, Vector3.Zero, -Vector3.One }, new int[] { 0, 1, 2, 1, 0, 2 }, 0);
var newMesh = MeshTools.DeduplicateVertices(inputMesh);
Assert.That(newMesh, Is.Not.SameAs(inputMesh), "Expected not to be reference equal");
Assert.That(newMesh, Is.EqualTo(inputMesh), "Expected to be deep equal");
Expand Down
8 changes: 4 additions & 4 deletions CadRevealComposer/Tessellation/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public class Mesh : IEquatable<Mesh>
/// </summary>
public Vector3[] Vertices => _vertices;

public uint[] Indices => _indices;
public int[] Indices => _indices;

public int TriangleCount => _indices.Length / 3;

private readonly Vector3[] _vertices;
private readonly uint[] _indices;
private readonly int[] _indices;

public Mesh(IReadOnlyList<float> vertexes, int[] indexes, float error)
{
Expand All @@ -33,7 +33,7 @@ public Mesh(IReadOnlyList<float> vertexes, int[] indexes, float error)
_vertices[i] = new Vector3(vertexes[i * 3], vertexes[i * 3 + 1], vertexes[i * 3 + 2]);
}

_indices = new uint[indexes.Length];
_indices = new int[indexes.Length];
Array.Copy(indexes, _indices, indexes.Length);
}

Expand All @@ -44,7 +44,7 @@ public Mesh(IReadOnlyList<float> vertexes, int[] indexes, float error)
/// <param name="vertices"></param>
/// <param name="indices"></param>
/// <param name="error"></param>
public Mesh(Vector3[] vertices, uint[] indices, float error)
public Mesh(Vector3[] vertices, int[] indices, float error)
{
Error = error;
_vertices = vertices;
Expand Down
8 changes: 4 additions & 4 deletions CadRevealComposer/Utils/MeshTools/MeshTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public static class MeshTools
public static Mesh DeduplicateVertices(Mesh input)
{
var comparer = new XyzVector3EqualityComparer();
var alreadyFoundVerticesToIndexMap = new Dictionary<Vector3, uint>(comparer);
var alreadyFoundVerticesToIndexMap = new Dictionary<Vector3, int>(comparer);

var newVertices = new List<Vector3>();
var indicesCopy = input.Indices.ToArray();

// The index in the oldVertexIndexToNewIndexRemap array is the old index, and the value is the new index. (Think of it as a dict)
var oldVertexIndexToNewIndexRemap = new uint[input.Vertices.Count()];
var oldVertexIndexToNewIndexRemap = new int[input.Vertices.Count()];

for (uint i = 0; i < input.Vertices.Count(); i++)
{
var vertex = input.Vertices[(int)i];
if (!alreadyFoundVerticesToIndexMap.TryGetValue(vertex, out uint newIndex))
if (!alreadyFoundVerticesToIndexMap.TryGetValue(vertex, out int newIndex))
{
newIndex = (uint)newVertices.Count;
newIndex = newVertices.Count;
newVertices.Add(vertex);
alreadyFoundVerticesToIndexMap.Add(vertex, newIndex);
}
Expand Down
6 changes: 3 additions & 3 deletions CadRevealComposer/Writers/GltfWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static void WriteInstancedMeshes(InstancedMesh[] meshes, ModelRoot model
);

// write indices
var indexBufferInt = MemoryMarshal.Cast<byte, uint>(indexBuffer.Content.AsSpan());
var indexBufferInt = MemoryMarshal.Cast<byte, int>(indexBuffer.Content.AsSpan());
sourceMesh.Indices.CopyTo(indexBufferInt);

// write vertices
Expand Down Expand Up @@ -227,11 +227,11 @@ private static void WriteTriangleMeshes(TriangleMesh[] triangleMeshes, ModelRoot
// write indices
var indices = sourceMesh.Indices;
var indexBufferSpan = MemoryMarshal
.Cast<byte, uint>(indexBuffer.Content.AsSpan())
.Cast<byte, int>(indexBuffer.Content.AsSpan())
.Slice(indexOffset, indices.Length);
for (var i = 0; i < indices.Length; i++)
{
indexBufferSpan[i] = (uint)vertexOffset + indices[i];
indexBufferSpan[i] = vertexOffset + indices[i];
}

// write vertices
Expand Down
1 change: 1 addition & 0 deletions CadRevealFbxProvider/BatchUtils/FbxWorkload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CadRevealComposer.IdProviders;
using CadRevealComposer.Operations;
using Commons;
using StringInternPool;
using System.Text.RegularExpressions;

public static class FbxWorkload
Expand Down
2 changes: 1 addition & 1 deletion CadRevealFbxProvider/FbxMeshWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static (Mesh Mesh, IntPtr MeshPtr)? GetGeometricData(FbxNode node)
nn[i] = new Vector3(normals[3 * i], normals[3 * i + 1], normals[3 * i + 2]);
}

var ii = indices.Select(a => (uint)a).ToArray();
var ii = indices.ToArray();

const float error = 0f; // We have no tessellation error info for FBX files.

Expand Down
6 changes: 3 additions & 3 deletions CadRevealObjProvider/ObjProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ InstanceIdGenerator instanceIdGenerator
public record ObjMesh
{
public string Name { get; init; } = "";
public uint[] Triangles { get; init; } = Array.Empty<uint>();
public int[] Triangles { get; init; } = Array.Empty<int>();
public Vector3[] Vertices { get; init; } = Array.Empty<Vector3>();

public Vector3[] Normals { get; init; } = Array.Empty<Vector3>();
Expand All @@ -110,9 +110,9 @@ private record VertexData(Vector3 Vertex, Vector3 Normal);

private static ObjMesh? ReadMeshFromGroup(Group group, LoadResult result)
{
var index = 0u;
var index = 0;
var vertexData = new List<VertexData>();
var triangles = new List<uint>();
var triangles = new List<int>();
foreach (Face groupFace in group.Faces)
{
Vector3? generatedNormal = null;
Expand Down
Loading