package org.artisanlogiciel.games.stl; import org.artisanlogiciel.games.Brick; import org.artisanlogiciel.games.LabyModel; import java.io.IOException; import java.io.OutputStream; public class Wall3dStream { public final static Wall3d South = new Wall3d(10, 1, 10, 0, 0, 0); public final static Wall3d West = new Wall3d(1, 10, 10, 0, 0, 0); public final static Wall3d North = new Wall3d(10, 1, 10, 0, 10, 0); public final static Wall3d East = new Wall3d(1, 10, 10, 10, 0, 0); public final static Wall3d HighGround = new Wall3d(10, 10, 3, 0, 0, 0); public final static Wall3d LowGround = new Wall3d(10, 10, 2, 0, 0, 0); String name; LabyModel provider; OutputStream stream; boolean reverse; /** * reverse : means that resolved path will be HighGround actual making maze more difficult to play with * * @param name * @param provider * @param stream * @param reverse */ public Wall3dStream(String name, LabyModel provider, OutputStream stream, boolean reverse) { this.name = name; this.provider = provider; this.stream = stream; this.reverse = reverse; } public static void prepare() { System.out.println(South.toString()); System.out.println(East.toString()); System.out.println(North.toString()); System.out.println(West.toString()); } private void writeWall3D(Wall3d wall3d) throws IOException { stream.write(wall3d.toString().getBytes()); } public void stream(int xl, int yl, int zl) throws IOException { int width = provider.getWidth(); int height = provider.getHeight(); // WARNING DOWN - UP reversed ( in 2D Y is oriented to lower, in 3D it // is to upper ). stream.write(("solid " + name + "\n").getBytes()); for (int x = 0; x < width; x++) { short walls = provider.getWalls(x, 0); if ((walls & Brick.UP) != 0) { writeWall3D(new Wall3d(South, x * xl, 0, 0)); } if ((walls & Brick.LEFT) != 0) { writeWall3D(new Wall3d(West, x * xl, 0, 0)); } } for (int y = 0; y < height; y++) { short walls = provider.getWalls(0, y); if ((walls & Brick.LEFT) != 0) { writeWall3D(new Wall3d(West, 0, y * yl, 0)); } for (int x = 0; x < width; x++) { // south and east walls = provider.getWalls(x, y); if ((walls & Brick.DOWN) != 0) { writeWall3D(new Wall3d(North, x * xl, y * yl, 0)); } if ((walls & Brick.RIGHT) != 0) { writeWall3D(new Wall3d(East, x * xl, y * yl, 0)); } short path = provider.getPath(x, y); // where resolved path is leaked to stl model. Wall3d ground = reverse ? LowGround : HighGround; if ((path & LabyModel.SOLVED) == LabyModel.SOLVED) // if ( (walls & ( Brick.GOAL | Brick.ENTRY ) ) == 0 ) { // if ( ( (x+y) % 2) == 0 ) ground = reverse ? HighGround : LowGround; } writeWall3D(new Wall3d(ground, x * xl, y * yl, 0)); } } stream.write("endsolid wall\n\n".getBytes()); stream.flush(); } }