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

feat: modified meshT file to receive material info instead of texture #45

Open
wants to merge 2 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 MeshDecimatorCore/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void RecalculateTangents()
return;

int vertexCount = vertices.Length;

var tangents = new Vector4[vertexCount];
var tan1 = new Vector3[vertexCount];
var tan2 = new Vector3[vertexCount];
Expand Down Expand Up @@ -429,7 +429,7 @@ public void RecalculateTangents()
t1 = w1.y - w0.y;
t2 = w2.y - w0.y;
}


float x1 = (float)(v1.x - v0.x);
float x2 = (float)(v2.x - v0.x);
Expand Down
44 changes: 22 additions & 22 deletions Obj2Tiles.Library.Test/Mesh3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ public void WriteObj_Square_RemoveUnused()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Square_RemoveUnused));

var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "square-unused.obj"));
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "square-unused.obj"), "");

mesh.WriteObj(Path.Combine(testPath, "square.obj"));
}

[Test]
public void WriteObj_Cube2_Repacking()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Cube2_Repacking));

var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"));
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"), "");

mesh.TexturesStrategy = TexturesStrategy.Repack;

Expand All @@ -66,7 +66,7 @@ public void WriteObj_Cube2_PreserveOriginalTextures()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Cube2_PreserveOriginalTextures));

var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"));
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"), "");
mesh.TexturesStrategy = TexturesStrategy.KeepOriginal;

mesh.WriteObj(Path.Combine(testPath, "mesh.obj"));
Expand All @@ -77,7 +77,7 @@ public void WriteObj_Cube_Repacking()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Cube_Repacking));

var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"));
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"), "");

mesh.TexturesStrategy = TexturesStrategy.Repack;

Expand All @@ -89,7 +89,7 @@ public void WriteObj_Cube_PreserveOriginalTextures()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Cube_PreserveOriginalTextures));

var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"));
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"), "");
mesh.TexturesStrategy = TexturesStrategy.KeepOriginal;

mesh.WriteObj(Path.Combine(testPath, "mesh.obj"));
Expand All @@ -100,7 +100,7 @@ public void WriteObj_Brighton_Repacking()
{
using var fs = new TestFS(BrightonTexturingTestUrl, nameof(Mesh3Tests));

var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(fs.TestFolder, "odm_textured_model_geo.obj"));
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(fs.TestFolder, "odm_textured_model_geo.obj"), "");

mesh.TexturesStrategy = TexturesStrategy.Repack;
var outputPath = Path.Combine(fs.TestFolder, "output");
Expand All @@ -116,7 +116,7 @@ public void WriteObj_Canyon_Repacking()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Canyon_Repacking));

var mesh = (MeshT)MeshUtils.LoadMesh(@"C:\datasets\canyon\odm_texturing\odm_textured_model_geo.obj");
var mesh = (MeshT)MeshUtils.LoadMesh(@"C:\datasets\canyon\odm_texturing\odm_textured_model_geo.obj", "");

mesh.TexturesStrategy = TexturesStrategy.Repack;

Expand All @@ -128,7 +128,7 @@ public void WriteObj_Splitted_Cube_PreserveOriginalTextures()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Splitted_Cube_PreserveOriginalTextures));

var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"));
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"), "");

var center = mesh.GetVertexBaricenter();

Expand All @@ -146,7 +146,7 @@ public void WriteObj_SplittedX_Cube_Repacking()
{
var testPath = GetTestOutputPath(nameof(WriteObj_SplittedX_Cube_Repacking));

var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"));
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"), "");

var center = mesh.GetVertexBaricenter();

Expand All @@ -164,7 +164,7 @@ public void WriteObj_SplittedX_Cube_PreserveOriginalTextures()
{
var testPath = GetTestOutputPath(nameof(WriteObj_SplittedX_Cube_PreserveOriginalTextures));

var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"));
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube/cube.obj"), "");

var center = mesh.GetVertexBaricenter();

Expand All @@ -182,7 +182,7 @@ public void WriteObj_Splitted_Cube2_PreserveOriginalTextures()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Splitted_Cube2_PreserveOriginalTextures));

var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"));
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"), "");

var center = mesh.GetVertexBaricenter();

Expand All @@ -200,7 +200,7 @@ public void WriteObj_Splitted_Cube2_Repacking()
{
var testPath = GetTestOutputPath(nameof(WriteObj_Splitted_Cube2_Repacking));

var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"));
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"), "");

var center = mesh.GetVertexBaricenter();

Expand Down Expand Up @@ -259,22 +259,22 @@ public void Orientation_TestOk()
var v1 = new Vertex3(0, 0, 0);
var v2 = new Vertex3(1, 0, 0);
var v3 = new Vertex3(0, 1, 0);

var o = Common.Orientation(v1, v2, v3);

o.Z.Should().Be(1);
o.X.Should().Be(0);
o.Y.Should().Be(0);
}


[Test]
public void Orientation_TestZero()
{
var v1 = new Vertex3(0, 0, 0);
var v2 = new Vertex3(0, 0, 0);
var v3 = new Vertex3(0, 0, 0);

var o = Common.Orientation(v1, v2, v3);

o.Z.Should().Be(0);
Expand All @@ -285,22 +285,22 @@ public void Orientation_TestZero()
[Test]
public void Orientation_TestCubeMesh()
{
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"));
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube2/cube.obj"), "");

var orientation = mesh.GetAverageOrientation();

orientation.X.Should().Be(0);
orientation.Y.Should().Be(0);
orientation.Z.Should().Be(0);
}

[Test]
public void Orientation_TestBrighton()
{

using var fs = new TestFS(BrightonTexturingTestUrl, nameof(Mesh3Tests));

var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(fs.TestFolder, "odm_textured_model_geo.obj"));
var mesh = (MeshT)MeshUtils.LoadMesh(Path.Combine(fs.TestFolder, "odm_textured_model_geo.obj"), "");

var orientation = mesh.GetAverageOrientation();

Expand Down
30 changes: 30 additions & 0 deletions Obj2Tiles.Library/Geometry/FaceB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Obj2Tiles.Library.Geometry;

public class FaceB
{

public int IndexA;
public int IndexB;
public int IndexC;

public int MaterialIndex;

public override string ToString()
{
return $"{IndexA} {IndexB} {IndexC} {MaterialIndex}";
}

public FaceB(int indexA, int indexB, int indexC, int materialIndex)
{
IndexA = indexA;
IndexB = indexB;
IndexC = indexC;

MaterialIndex = materialIndex;
}

public virtual string ToObj()
{
return $"f {IndexA + 1} {IndexB + 1} {IndexC + 1}";
}
}
22 changes: 11 additions & 11 deletions Obj2Tiles.Library/Geometry/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Mesh(IEnumerable<Vertex3> vertices, IEnumerable<Face> faces)
_vertices = new List<Vertex3>(vertices);
_faces = new List<Face>(faces);
}

public int Split(IVertexUtils utils, double q, out IMesh left,
out IMesh right)
{
Expand All @@ -42,7 +42,7 @@ public int Split(IVertexUtils utils, double q, out IMesh left,
var vA = _vertices[face.IndexA];
var vB = _vertices[face.IndexB];
var vC = _vertices[face.IndexC];

var aSide = utils.GetDimension(vA) < q;
var bSide = utils.GetDimension(vB) < q;
var cSide = utils.GetDimension(vC) < q;
Expand Down Expand Up @@ -288,9 +288,9 @@ public void WriteObj(string path, bool removeUnused = true)
{

if (removeUnused) RemoveUnusedVertices();

using var writer = new FormattingStreamWriter(path, CultureInfo.InvariantCulture);

writer.Write("o ");
writer.WriteLine(string.IsNullOrWhiteSpace(Name) ? DefaultName : Name);

Expand Down Expand Up @@ -327,19 +327,19 @@ private void RemoveUnusedVertices()

if (!newVertexes.TryGetValue(vA, out var newVA))
newVA = newVertexes.AddIndex(vA);

face.IndexA = newVA;

if (!newVertexes.TryGetValue(vB, out var newVB))
newVB = newVertexes.AddIndex(vB);

face.IndexB = newVB;

if (!newVertexes.TryGetValue(vC, out var newVC))
newVC = newVertexes.AddIndex(vC);

face.IndexC = newVC;

}

_vertices = newVertexes.Keys.ToList();
Expand All @@ -352,4 +352,4 @@ private void RemoveUnusedVertices()
#endregion


}
}
Loading