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,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;
@@ -66,16 +68,20 @@ public class MeshingTest4 {
} );
System.out.println( "Took a total of " + ( System.currentTimeMillis() - allStart ) );
// for ( int i = 0; i < CHUNK_DIR.listFiles().length; ++i ) {
// 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() ) );
// long time = System.currentTimeMillis() - start;
//
// System.out.println( "\tTook " + time + "ms" );
// }
// for ( int i = 0; i < CHUNK_DIR.listFiles().length; ++i ) {
// final File file = CHUNK_DIR.listFiles()[ i ];
// System.out.println( ( i + 1 ) + "/" + CHUNK_DIR.listFiles().length + ":\tMeshing " + file );
// final long start = System.currentTimeMillis();
// 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 {
System.err.println( "No such directory exists: " + CHUNK_DIR );
}
@@ -184,6 +190,30 @@ public class MeshingTest4 {
e.printStackTrace();
}
}
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 >();
@@ -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;