diff --git a/application/visualizer/Test1/README.md b/application/visualizer/Test1/README.md new file mode 100644 index 0000000..abe68e7 --- /dev/null +++ b/application/visualizer/Test1/README.md @@ -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: `,,`. + +The mAABB file format contains an arbitrary number of AABBs, with one line per each: +` ` + +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. \ No newline at end of file diff --git a/application/visualizer/Test1/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshTest.java b/application/visualizer/Test1/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshTest.java index b50a7c2..eedb614 100644 --- a/application/visualizer/Test1/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshTest.java +++ b/application/visualizer/Test1/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshTest.java @@ -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; diff --git a/application/visualizer/Test2/README.md b/application/visualizer/Test2/README.md new file mode 100644 index 0000000..8a93712 --- /dev/null +++ b/application/visualizer/Test2/README.md @@ -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: `,,`. + +The mAABB file format contains an arbitrary number of AABBs, with one line per each: +` ` + +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 \ No newline at end of file diff --git a/application/visualizer/Test2/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest2.java b/application/visualizer/Test2/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest2.java index 7e37ea2..06961bb 100644 --- a/application/visualizer/Test2/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest2.java +++ b/application/visualizer/Test2/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest2.java @@ -150,9 +150,9 @@ public class MeshingTest2 extends JPanel { } } -// final List< Plane > planes = mesh( new File( CHUNK_DIR, "world,-10,-10" ) ); -// masterPlanes.add( planes.get( 27 ) ); -// masterPlanes.addAll( planes ); + // final List< Plane > planes = mesh( new File( CHUNK_DIR, "world,10,-6" ) ); + // masterPlanes.add( planes.get( 27 ) ); + // masterPlanes.addAll( planes ); SwingUtilities.invokeLater( new Runnable() { @Override diff --git a/application/visualizer/Test3/README.md b/application/visualizer/Test3/README.md new file mode 100644 index 0000000..7404f30 --- /dev/null +++ b/application/visualizer/Test3/README.md @@ -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: `,,`. + +The mAABB file format contains an arbitrary number of AABBs, with one line per each: +` ` + +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. \ No newline at end of file diff --git a/application/visualizer/Test3/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest3.java b/application/visualizer/Test3/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest3.java index a7411ba..5499ace 100644 --- a/application/visualizer/Test3/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest3.java +++ b/application/visualizer/Test3/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest3.java @@ -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; diff --git a/application/visualizer/Test4/README.md b/application/visualizer/Test4/README.md new file mode 100644 index 0000000..68a36ad --- /dev/null +++ b/application/visualizer/Test4/README.md @@ -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: `,,`. +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: +` ` + +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. \ No newline at end of file diff --git a/application/visualizer/Test4/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest4.java b/application/visualizer/Test4/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest4.java index dfcca9d..80eeeec 100644 --- a/application/visualizer/Test4/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest4.java +++ b/application/visualizer/Test4/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/test/MeshingTest4.java @@ -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; diff --git a/application/visualizer/Test5/README.md b/application/visualizer/Test5/README.md new file mode 100644 index 0000000..9f4b9e1 --- /dev/null +++ b/application/visualizer/Test5/README.md @@ -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: `,,`. + +The facet file format contains an arbitrary number of facets, with each facet following +the given format: +``` + + +... +``` +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. \ No newline at end of file diff --git a/application/visualizer/Test6/README.md b/application/visualizer/Test6/README.md new file mode 100644 index 0000000..985a582 --- /dev/null +++ b/application/visualizer/Test6/README.md @@ -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: `,,`. + +The facet file format contains an arbitrary number of facets, with each facet following +the given format: +``` + + +... +``` +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 \ No newline at end of file diff --git a/application/visualizer/Test7/README.md b/application/visualizer/Test7/README.md new file mode 100644 index 0000000..86e2443 --- /dev/null +++ b/application/visualizer/Test7/README.md @@ -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: `,,`. + +The polygon file format contains an arbitrary number of 2d polygons, with each polygon +following the given format: +``` + + +... +``` +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. \ No newline at end of file diff --git a/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Plane.java b/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Plane.java index 1265d61..e9d95b1 100644 --- a/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Plane.java +++ b/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Plane.java @@ -32,7 +32,7 @@ public class Plane { if ( !set ) { distance = r.getZ(); - + set = true; } else if ( Math.abs( r.getZ() - distance ) > 1e-7 ) { throw new IllegalStateException( "Bad point in facet!" ); @@ -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() { diff --git a/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Vector3d.java b/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Vector3d.java index 95ca948..b0d2f31 100644 --- a/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Vector3d.java +++ b/base/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/base/Vector3d.java @@ -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 + "}"; diff --git a/core/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/Mesh.java b/core/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/Mesh.java index 999f930..0762719 100644 --- a/core/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/Mesh.java +++ b/core/src/main/java/com/aaaaahhhhhhh/bananapuncher714/mesh/Mesh.java @@ -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 ); }