Fix each test and added READMEs

This commit is contained in:
2026-03-15 18:56:59 -04:00
parent c2aa41fe58
commit 14b1647c47
14 changed files with 171 additions and 22 deletions

View File

@@ -0,0 +1,9 @@
# Test 1
This test requires a directory called `chunks` in the current working directory,
filled with mAABB file that follow the naming convention: `<string>,<int>,<int>`.
The mAABB file format contains an arbitrary number of AABBs, with one line per each:
`<min-x> <min-y> <min-z> <max-x> <max-y> <max-z>`
This program should be ran via the command line with `java -jar`. It will process the
first file it finds and print out each plane and the associated properties with each one.

View File

@@ -182,7 +182,7 @@ public class MeshTest {
AABB( double xmin, double ymin, double zmin, double xmax, double ymax, double zmax ) {
this.xmin = xmin;
this.ymax = ymin;
this.ymin = ymin;
this.zmin = zmin;
this.xmax = xmax;

View File

@@ -0,0 +1,15 @@
# Test 2
This test requires a directory called `chunks` in the current working directory,
filled with mAABB files that follow the naming convention: `<string>,<int>,<int>`.
The mAABB file format contains an arbitrary number of AABBs, with one line per each:
`<min-x> <min-y> <min-z> <max-x> <max-y> <max-z>`
This program is a visual application. It will process the first file it finds, and
convert the group of AABBs to planes. It will then mesh each individual plane and
allow the user to browse:
- The final tesselated plane
- A wireframe of the tesselated plane
- A wireframe of the tesselated plane with chain calculation
- Each triangle of the final product
- The tesselation by-product values

View File

@@ -150,7 +150,7 @@ public class MeshingTest2 extends JPanel {
}
}
// final List< Plane > planes = mesh( new File( CHUNK_DIR, "world,-10,-10" ) );
// final List< Plane > planes = mesh( new File( CHUNK_DIR, "world,10,-6" ) );
// masterPlanes.add( planes.get( 27 ) );
// masterPlanes.addAll( planes );

View File

@@ -0,0 +1,9 @@
# Test 1
This test requires a directory called `chunks` in the current working directory,
filled with mAABB files that follow the naming convention: `<string>,<int>,<int>`.
The mAABB file format contains an arbitrary number of AABBs, with one line per each:
`<min-x> <min-y> <min-z> <max-x> <max-y> <max-z>`
This program should be ran via the command line with `java -jar`. It will tesselate all
the files it can find as fast as possible, then output the time results.

View File

@@ -237,7 +237,7 @@ public class MeshingTest3 {
AABB( double xmin, double ymin, double zmin, double xmax, double ymax, double zmax ) {
this.xmin = xmin;
this.ymax = ymin;
this.ymin = ymin;
this.zmin = zmin;
this.xmax = xmax;

View File

@@ -0,0 +1,10 @@
# Test 1
This test requires a directory called `chunks` in the current working directory,
filled with mAABB file that follow the naming convention: `<string>,<int>,<int>`.
This test will create a directory called `chunk_models` containing `ply2` files.
The mAABB file format contains an arbitrary number of AABBs, with one line per each:
`<min-x> <min-y> <min-z> <max-x> <max-y> <max-z>`
This program should be ran via the command line with `java -jar`. It will tesselate each
file and save them in `ply2` format in the `chunk_models` directory. This will take a while.

View File

@@ -43,7 +43,7 @@ public class MeshingTest4 {
System.out.println( "Found " + CHUNK_DIR.list().length + " files" );
// Omega mesh time
// omegaMesh( CHUNK_DIR, new File( MODEL_DIR, "omega.ply" ) );
// omegaMesh( CHUNK_DIR, new File( MODEL_DIR, "omega" ) );
final long allStart = System.currentTimeMillis();
final AtomicInteger index = new AtomicInteger( 0 );
@@ -55,7 +55,9 @@ public class MeshingTest4 {
final long start = System.currentTimeMillis();
final List< Plane > planes = mesh( f, builder );
savePly2( new File( MODEL_DIR, f.getName() + ".ply" ), planes.parallelStream().flatMap( p -> process( p ).parallelStream().map( p::convert ) ).collect( Collectors.toSet() ) );
Collection< Facet > facets = planes.parallelStream().flatMap( p -> process( p ).parallelStream().map( p::convert ) ).collect( Collectors.toSet() );
savePly2( new File( MODEL_DIR, f.getName() + ".ply" ), facets );
saveStl( new File( MODEL_DIR, f.getName() + ".stl" ), facets );
final long time = System.currentTimeMillis() - start;
@@ -70,10 +72,14 @@ public class MeshingTest4 {
// final File file = CHUNK_DIR.listFiles()[ i ];
// System.out.println( ( i + 1 ) + "/" + CHUNK_DIR.listFiles().length + ":\tMeshing " + file );
// final long start = System.currentTimeMillis();
// final List< Plane > planes = mesh( file );
// savePly2( new File( MODEL_DIR, file.getName() + ".ply" ), planes.parallelStream().flatMap( p -> process( p ).parallelStream().map( p::convert ) ).collect( Collectors.toSet() ) );
// final StringBuilder builder = new StringBuilder();
// final List< Plane > planes = mesh( file, builder );
// System.out.println( builder.toString() );
// Collection< Facet > facets = planes.parallelStream().flatMap( p -> process( p ).parallelStream().map( p::convert ) ).collect( Collectors.toSet() );
// savePly2( new File( MODEL_DIR, file.getName() + ".ply" ), facets );
// saveStl( new File( MODEL_DIR, file.getName() + ".stl" ), facets );
// long time = System.currentTimeMillis() - start;
//
// System.out.println( "\tTook " + time + "ms" );
// }
} else {
@@ -185,6 +191,30 @@ public class MeshingTest4 {
}
}
private static void saveStl( final File file, Collection< Facet > facets ) {
file.getParentFile().mkdirs();
if ( file.exists() ) {
file.delete();
}
try ( PrintWriter writer = new PrintWriter( file ) ) {
writer.println( "solid test" );
for ( Facet f : facets ) {
writer.println( "facet normal " + f.normal.getX() + " " + f.normal.getY() + " " + f.normal.getZ() );
writer.println( "outer loop" );
for ( Vector3d p : f.points ) {
writer.println( "vertex " + p.getX() + " " + p.getY() + " " + p.getZ() );
}
writer.println( "endloop" );
writer.println( "endfacet" );
}
writer.println( "endsolid test");
} catch ( FileNotFoundException e ) {
e.printStackTrace();
}
}
private static void omegaMesh( final File directory, final File output ) {
final List< AABB > allBoxes = new ArrayList< AABB >();
for ( int i = 0; i < directory.listFiles().length; ++i ) {
@@ -206,11 +236,13 @@ public class MeshingTest4 {
System.out.println( "Starting to mesh " + builder.planes.size() + " planes" );
final long start = System.currentTimeMillis();
final AtomicInteger counter = new AtomicInteger();
savePly2( output, builder.planes.parallelStream().flatMap( p -> {
Collection< Facet > resultFacets = builder.planes.parallelStream().flatMap( p -> {
final Stream< Facet > facets = process( p ).parallelStream().map( p::convert );
System.out.println( "Finished " + counter.incrementAndGet() + "/" + builder.planes.size() );
return facets;
} ).collect( Collectors.toSet() ) );
} ).collect( Collectors.toSet() );
savePly2( new File( output.getAbsolutePath() + ".ply" ), resultFacets );
saveStl( new File( output.getAbsolutePath() + ".stl" ), resultFacets );
System.out.println( "\tTook " + ( System.currentTimeMillis() - start ) + "ms" );
}
@@ -393,7 +425,7 @@ public class MeshingTest4 {
AABB( double xmin, double ymin, double zmin, double xmax, double ymax, double zmax ) {
this.xmin = xmin;
this.ymax = ymin;
this.ymin = ymin;
this.zmin = zmin;
this.xmax = xmax;

View File

@@ -0,0 +1,16 @@
# Test 1
This test requires a directory called `facets` in the current working directory,
filled with facet files that follow the naming convention: `<string>,<int>,<int>`.
The facet file format contains an arbitrary number of facets, with each facet following
the given format:
```
<vertex-count> <normal-x> <normal-y> <normal-z>
<vertex-x> <vertex-y> <vertex-z>
...
```
The intial line of the vertex count and normals are followed by an extra line for each
vertex, containing the x, y and z coordinates of that vertex.
This program should be ran via the command line with `java -jar`. It will tesselate all
the files it can find as fast as possible, then output the time results.

View File

@@ -0,0 +1,22 @@
# Test 1
This test requires a directory called `facets` in the current working directory,
filled with facet files that follow the naming convention: `<string>,<int>,<int>`.
The facet file format contains an arbitrary number of facets, with each facet following
the given format:
```
<vertex-count> <normal-x> <normal-y> <normal-z>
<vertex-x> <vertex-y> <vertex-z>
...
```
The intial line of the vertex count and normals are followed by an extra line for each
vertex, containing the x, y and z coordinates of that vertex.
This program is a visual application. It will process the first file it finds, and
convert the group of AABBs to planes. It will then mesh each individual plane and
allow the user to browse:
- The final tesselated plane
- A wireframe of the tesselated plane
- A wireframe of the tesselated plane with chain calculation
- Each triangle of the final product
- The tesselation by-product values

View File

@@ -0,0 +1,16 @@
# Test 1
This test requires a directory called `polygons` in the current working directory,
filled with polygon files that follow the naming convention: `<string>,<int>,<int>`.
The polygon file format contains an arbitrary number of 2d polygons, with each polygon
following the given format:
```
<vertex-count>
<vertex-x> <vertex-y>
...
```
The intial line of the vertex count are followed by an extra line for each
vertex, containing the x and y coordinates of that vertex.
This program should be ran via the command line with `java -jar`. It will tesselate all
the files it can find as fast as possible, then output the time results.

View File

@@ -66,7 +66,7 @@ public class Plane {
}
public boolean matches( Vector3d normal, Vector3d point ) {
return Math.abs( this.normal.dot( normal ) ) > 0.99 && Math.abs( new Vector3d( this.point ).subtract( point ).dot( normal ) ) < 0.01;
return Math.abs( this.normal.dot( normal ) ) > 0.999 && Math.abs( new Vector3d( this.point ).subtract( point ).dot( normal ) ) < 0.00001;
}
private Matrix3d getProjectionMatrix() {

View File

@@ -131,6 +131,24 @@ public class Vector3d {
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Vector3d other = (Vector3d) obj;
if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
return false;
if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
return false;
if (Double.doubleToLongBits(z) != Double.doubleToLongBits(other.z))
return false;
return true;
}
@Override
public String toString() {
return "Vector3d{x=" + x + ",y=" + y + ",z=" + z + "}";

View File

@@ -481,6 +481,8 @@ public class Mesh< T extends Region > {
for ( final HalfEdge edge : vertex ) {
// Resolve any intersections belonging to this edge which are still
// being scanned, but only if it's a new edge
// This is incredibly slow the more edges that are available at the current position...
// TODO Need to speed this up
if ( !scannedEdges.contains( edge ) && !scannedVertices.contains( edge.getDest() ) ) {
resolveEdgeIntersections( vertexSet, scannedEdges, edge );
}