Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
710b949
commit d1d3b17
Showing
10 changed files
with
215 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using DemoContentLoader; | ||
using ObjLoader.Loader.Loaders; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Numerics; | ||
|
||
namespace DemoContentBuilder | ||
{ | ||
public static class MeshBuilder | ||
{ | ||
public unsafe static MeshContent Build(Stream dataStream) | ||
{ | ||
var result = new ObjLoaderFactory().Create().Load(dataStream); | ||
var triangles = new List<TriangleContent>(); | ||
for (int i = 0; i < result.Groups.Count; ++i) | ||
{ | ||
var group = result.Groups[i]; | ||
for (int j = 0; j < group.Faces.Count; ++j) | ||
{ | ||
var face = group.Faces[j]; | ||
var a = result.Vertices[face[0].VertexIndex]; | ||
for (int k = 1; k < face.Count - 1; ++k) | ||
{ | ||
var b = result.Vertices[face[k].VertexIndex]; | ||
var c = result.Vertices[face[k + 1].VertexIndex]; | ||
triangles.Add(new TriangleContent | ||
{ | ||
A = new Vector3(a.X, a.Y, a.Z), | ||
B = new Vector3(b.X, b.Y, b.Z), | ||
C = new Vector3(c.X, c.Y, c.Z) | ||
}); | ||
} | ||
} | ||
} | ||
return new MeshContent(triangles.ToArray()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using BepuUtilities; | ||
using DemoContentLoader; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Numerics; | ||
|
||
namespace DemoContentLoader | ||
{ | ||
public struct TriangleContent | ||
{ | ||
public Vector3 A; | ||
public Vector3 B; | ||
public Vector3 C; | ||
} | ||
|
||
public class MeshContent : IContent | ||
{ | ||
public TriangleContent[] Triangles; | ||
|
||
public ContentType ContentType { get { return ContentType.Mesh; } } | ||
|
||
public MeshContent(TriangleContent[] triangles) | ||
{ | ||
Triangles = triangles; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Numerics; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
|
||
namespace DemoContentLoader | ||
{ | ||
public class MeshIO | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void ReadVector3(BinaryReader reader, out Vector3 v) | ||
{ | ||
v = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); | ||
} | ||
|
||
public static MeshContent Load(BinaryReader reader) | ||
{ | ||
var triangleCount = reader.ReadInt32(); | ||
var triangles = new TriangleContent[triangleCount]; | ||
for (int i = 0; i < triangleCount; ++i) | ||
{ | ||
ref var triangle = ref triangles[i]; | ||
ReadVector3(reader, out triangle.A); | ||
ReadVector3(reader, out triangle.B); | ||
ReadVector3(reader, out triangle.C); | ||
} | ||
return new MeshContent(triangles); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void Write(BinaryWriter writer, in Vector3 v) | ||
{ | ||
writer.Write(v.X); | ||
writer.Write(v.Y); | ||
writer.Write(v.Z); | ||
} | ||
|
||
public static void Save(MeshContent content, BinaryWriter writer) | ||
{ | ||
writer.Write(content.Triangles.Length); | ||
for (int i = 0; i < content.Triangles.Length; ++i) | ||
{ | ||
ref var triangle = ref content.Triangles[i]; | ||
Write(writer, triangle.A); | ||
Write(writer, triangle.B); | ||
Write(writer, triangle.C); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.