Skip to content

Commit 40d3b5e

Browse files
committed
basic reprojection for Remesher. Works OK, however edges w/ 2 fixed verts cannot be collapsed, which causes some weirdness w/ no normal-flip check...
1 parent 86af85d commit 40d3b5e

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

geometry3Sharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@
146146
<Compile Include="intersection\IntrSegment3Box3.cs" />
147147
<Compile Include="intersection\IntrRay3Box3.cs" />
148148
<Compile Include="spatial\DMeshAABBTree.cs" />
149+
<Compile Include="spatial\MeshProjectionTarget.cs" />
150+
<Compile Include="spatial\SpatialInterfaces.cs" />
149151
</ItemGroup>
150152
<ItemGroup>
151153
<Folder Include="interfaces\" />

mesh/Remesher.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Remesher {
77

88
DMesh3 mesh;
99
MeshConstraints constraints = null;
10-
10+
IProjectionTarget target = null;
1111

1212
public bool EnableFlips = true;
1313
public bool EnableCollapses = true;
@@ -37,6 +37,11 @@ public void SetExternalConstraints(MeshConstraints cons)
3737
}
3838

3939

40+
public void SetProjectionTarget(IProjectionTarget target)
41+
{
42+
this.target = target;
43+
}
44+
4045

4146
public void BasicRemeshPass() {
4247

@@ -51,6 +56,9 @@ public void BasicRemeshPass() {
5156

5257
if ( EnableSmoothing && SmoothSpeedT > 0)
5358
FullSmoothPass_InPlace();
59+
60+
if (target != null)
61+
FullProjectionPass();
5462
}
5563

5664

@@ -240,10 +248,22 @@ void FullSmoothPass_InPlace() {
240248
Vector3d vSmoothed = smoothFunc(mesh, vID, SmoothSpeedT);
241249
mesh.SetVertex( vID, vSmoothed);
242250
}
243-
244251
}
245252

246253

247254

255+
void FullProjectionPass()
256+
{
257+
foreach ( int vID in mesh.VertexIndices() ) {
258+
if (vertex_is_fixed(vID))
259+
continue;
260+
Vector3d curpos = mesh.GetVertex(vID);
261+
Vector3d projected = target.Project(curpos);
262+
mesh.SetVertex(vID, projected);
263+
}
264+
}
265+
266+
267+
248268
}
249269
}

spatial/DMeshAABBTree.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
namespace g3
66
{
7-
public class DMeshAABBTree3
7+
public class DMeshAABBTree3 : ISpatial
88
{
99
DMesh3 mesh;
10+
int mesh_timestamp;
1011

1112
public DMeshAABBTree3(DMesh3 m)
1213
{
@@ -19,13 +20,17 @@ public DMeshAABBTree3(DMesh3 m)
1920
public void Build()
2021
{
2122
build_by_one_rings();
23+
mesh_timestamp = mesh.Timestamp;
2224
}
2325

2426

2527

26-
28+
public bool SupportsNearestTriangle { get { return true; } }
2729
public int FindNearestTriangle(Vector3d p)
2830
{
31+
if (mesh_timestamp != mesh.Timestamp)
32+
throw new Exception("DMeshAABBTree3.FindNearestTriangle: mesh has been modified since tree construction");
33+
2934
double fNearestSqr = double.MaxValue;
3035
int tNearID = -1;
3136
find_nearest_tri(root_index, p, ref fNearestSqr, ref tNearID);
@@ -97,6 +102,9 @@ public class TreeTraversal
97102
// walk over tree, calling functions in TreeTraversal object for internal nodes and triangles
98103
public void DoTraversal(TreeTraversal traversal)
99104
{
105+
if (mesh_timestamp != mesh.Timestamp)
106+
throw new Exception("DMeshAABBTree3.DoTraversal: mesh has been modified since tree construction");
107+
100108
tree_traversal(root_index, traversal);
101109
}
102110

spatial/MeshProjectionTarget.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace g3
5+
{
6+
public class MeshProjectionTarget : IProjectionTarget
7+
{
8+
public DMesh3 Mesh { get; set; }
9+
public ISpatial Spatial { get; set; }
10+
11+
public Vector3d Project(Vector3d vPoint, int identifier = -1)
12+
{
13+
int tNearestID = Spatial.FindNearestTriangle(vPoint);
14+
DistPoint3Triangle3 q = MeshQueries.TriangleDistance(Mesh, tNearestID, vPoint);
15+
return q.TriangleClosest;
16+
}
17+
}
18+
}

spatial/SpatialInterfaces.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace g3
5+
{
6+
public interface ISpatial
7+
{
8+
bool SupportsNearestTriangle { get; }
9+
int FindNearestTriangle(Vector3d p);
10+
}
11+
12+
13+
public interface IProjectionTarget
14+
{
15+
Vector3d Project(Vector3d vPoint, int identifier = -1);
16+
}
17+
}

0 commit comments

Comments
 (0)