Settings for stl export
- set cells size and wall thickness - set reverse for path : when reverse is set then resolved path is higher ground else (default) it is lower ground.
This commit is contained in:
@@ -32,6 +32,7 @@ import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.artisanlogiciel.games.*;
|
||||
import org.artisanlogiciel.games.stl.Maze3dParams;
|
||||
import org.artisanlogiciel.games.stl.Wall3d;
|
||||
import org.artisanlogiciel.games.stl.Wall3dStream;
|
||||
import org.artisanlogiciel.util.UTF8Control;
|
||||
@@ -57,6 +58,8 @@ public class Display extends JFrame {
|
||||
|
||||
MazeParams params = null;
|
||||
|
||||
Maze3dSettings stlsettings;
|
||||
|
||||
Display(LabyModel model, int W, int H, MazeParams params) {
|
||||
super(labels.getString("title"));
|
||||
if (params != null) {
|
||||
@@ -367,17 +370,19 @@ public class Display extends JFrame {
|
||||
System.out.println("save stl");
|
||||
setMazeName(saveName.getText());
|
||||
MazeParamsFixed p = (MazeParamsFixed) params;
|
||||
saveStl(p, model);
|
||||
saveStl(p, model,stlsettings.createParams());
|
||||
}
|
||||
};
|
||||
saveStlButton.addActionListener(saveStlAction);
|
||||
|
||||
stlsettings = new Maze3dSettings(new Maze3dParams());
|
||||
|
||||
JMenu saveMenu = new JMenu("Save");
|
||||
saveMenu.add(saveName);
|
||||
saveMenu.add(saveSvgButton);
|
||||
saveMenu.add(savePngButton);
|
||||
saveMenu.add(saveButton);
|
||||
saveMenu.add(stlsettings);
|
||||
saveMenu.add(saveStlButton);
|
||||
saveMenu.add(saveImcButton);
|
||||
|
||||
@@ -1011,13 +1016,13 @@ public class Display extends JFrame {
|
||||
Display display = new Display(model, W, H, params);
|
||||
}
|
||||
|
||||
public static void saveStl(MazeParamsFixed params, LabyModel model) {
|
||||
public static void saveStl(MazeParamsFixed params, LabyModel model, Maze3dParams wallparams) {
|
||||
File outfile = new File(params.getSaveDir(), params.getName() + ".stl");
|
||||
if (!outfile.exists()) {
|
||||
System.out.println("Saving to " + outfile + " ...");
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(outfile);
|
||||
new Wall3dStream(params.getName(), model, out, false).stream(10,10,10);
|
||||
new Wall3dStream(params.getName(), model, out, wallparams).stream();
|
||||
out.close();
|
||||
System.out.println("... Done.");
|
||||
} catch (IOException io) {
|
||||
|
||||
72
java/org/artisanlogiciel/games/maze/gui/Maze3dSettings.java
Normal file
72
java/org/artisanlogiciel/games/maze/gui/Maze3dSettings.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package org.artisanlogiciel.games.maze.gui;
|
||||
|
||||
import org.artisanlogiciel.games.MazeParams;
|
||||
import org.artisanlogiciel.games.stl.Maze3dParams;
|
||||
import org.artisanlogiciel.games.stl.Wall3d;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Maze3dSettings
|
||||
extends JPanel
|
||||
{
|
||||
// grid size
|
||||
JTextField xl;
|
||||
JTextField yl;
|
||||
JTextField zl;
|
||||
|
||||
JTextField w;
|
||||
JTextField lg;
|
||||
JTextField hg;
|
||||
|
||||
JCheckBox reverse;
|
||||
|
||||
Maze3dParams params;
|
||||
|
||||
public Maze3dSettings(Maze3dParams params) {
|
||||
super();
|
||||
this.params = params;
|
||||
createSettingsGui();
|
||||
}
|
||||
|
||||
void createSettingsGui() {
|
||||
if (params != null) {
|
||||
JLabel widthLabel = new JLabel(Display.labels.getString("width"));
|
||||
xl = new JTextField("0" + params.getXl());
|
||||
add(widthLabel);
|
||||
add(xl);
|
||||
JLabel heightLabel = new JLabel(Display.labels.getString("height"));
|
||||
zl = new JTextField("0" + params.getZl());
|
||||
add(heightLabel);
|
||||
add(zl);
|
||||
JLabel depthLabel = new JLabel(Display.labels.getString("depth"));
|
||||
yl = new JTextField("0" + params.getYl());
|
||||
add(depthLabel);
|
||||
add(yl);
|
||||
|
||||
reverse = new JCheckBox("reverse",params.isReverse());
|
||||
add(reverse);
|
||||
|
||||
w = new JTextField("0" + params.getW());
|
||||
add(w);
|
||||
|
||||
// lowground hightground
|
||||
lg = new JTextField("0" + params.getLg());
|
||||
add(lg);
|
||||
hg = new JTextField("0" + params.getHg());
|
||||
add(hg);
|
||||
}
|
||||
}
|
||||
|
||||
Maze3dParams createParams()
|
||||
{
|
||||
return new Maze3dParams(
|
||||
Integer.parseInt(xl.getText()),
|
||||
Integer.parseInt(yl.getText()),
|
||||
Integer.parseInt(zl.getText()),
|
||||
Integer.parseInt(w.getText()),
|
||||
Integer.parseInt(lg.getText()),
|
||||
Integer.parseInt(hg.getText()),
|
||||
reverse.isSelected());
|
||||
}
|
||||
|
||||
}
|
||||
104
java/org/artisanlogiciel/games/stl/Maze3dParams.java
Normal file
104
java/org/artisanlogiciel/games/stl/Maze3dParams.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package org.artisanlogiciel.games.stl;
|
||||
|
||||
public class Maze3dParams {
|
||||
|
||||
// grid size
|
||||
int xl;
|
||||
int yl;
|
||||
int zl;
|
||||
|
||||
int w;
|
||||
int lg;
|
||||
int hg;
|
||||
|
||||
Wall3d south;
|
||||
Wall3d west;
|
||||
Wall3d north;
|
||||
Wall3d east;
|
||||
Wall3d highGround;
|
||||
Wall3d lowGround;
|
||||
|
||||
// reverse : means that resolved path will be HighGround actual making maze more difficult to play with
|
||||
boolean reverse;
|
||||
|
||||
// default
|
||||
public Maze3dParams()
|
||||
{
|
||||
this(10,10,10, 1 , 1, 3, false);
|
||||
}
|
||||
|
||||
// w width is wall thickness
|
||||
public Maze3dParams(int xl, int yl, int zl, int w, int lg, int hg, boolean reverse)
|
||||
{
|
||||
this.xl = xl;
|
||||
this.yl = yl;
|
||||
this.zl = zl;
|
||||
this.reverse = reverse;
|
||||
int h = zl;
|
||||
|
||||
this.w = w;
|
||||
this.lg = lg;
|
||||
this.hg = hg;
|
||||
|
||||
south = new Wall3d(xl, w, h, 0, 0, 0);
|
||||
west = new Wall3d(w, yl, h, 0, 0, 0);
|
||||
north = new Wall3d(xl, w, h, 0, yl, 0);
|
||||
east = new Wall3d(w, yl, h, xl, 0, 0);
|
||||
highGround = new Wall3d(xl, yl, hg, 0, 0, 0);
|
||||
lowGround = new Wall3d(xl, yl, lg, 0, 0, 0);
|
||||
}
|
||||
|
||||
public boolean isReverse() {
|
||||
return reverse;
|
||||
}
|
||||
|
||||
public int getXl() {
|
||||
return xl;
|
||||
}
|
||||
|
||||
public int getYl() {
|
||||
return yl;
|
||||
}
|
||||
|
||||
public int getZl() {
|
||||
return zl;
|
||||
}
|
||||
|
||||
public Wall3d getSouth() {
|
||||
return south;
|
||||
}
|
||||
|
||||
public Wall3d getWest() {
|
||||
return west;
|
||||
}
|
||||
|
||||
public Wall3d getNorth() {
|
||||
return north;
|
||||
}
|
||||
|
||||
public Wall3d getEast() {
|
||||
return east;
|
||||
}
|
||||
|
||||
public Wall3d getHighGround() {
|
||||
return highGround;
|
||||
}
|
||||
|
||||
public Wall3d getLowGround() {
|
||||
return lowGround;
|
||||
}
|
||||
|
||||
public int getLg() {
|
||||
return lg;
|
||||
}
|
||||
|
||||
public int getHg() {
|
||||
return hg;
|
||||
}
|
||||
|
||||
public int getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,39 +9,25 @@ 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;
|
||||
|
||||
Maze3dParams params;
|
||||
|
||||
/**
|
||||
* reverse : means that resolved path will be HighGround actual making maze more difficult to play with
|
||||
*
|
||||
* @param name
|
||||
* @param provider
|
||||
* @param stream
|
||||
* @param reverse
|
||||
* @param params
|
||||
*/
|
||||
public Wall3dStream(String name, LabyModel provider, OutputStream stream, boolean reverse)
|
||||
public Wall3dStream(String name, LabyModel provider, OutputStream stream, Maze3dParams params)
|
||||
{
|
||||
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());
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
private void writeWall3D(Wall3d wall3d)
|
||||
@@ -50,46 +36,51 @@ public class Wall3dStream
|
||||
stream.write(wall3d.toString().getBytes());
|
||||
}
|
||||
|
||||
public void stream(int xl, int yl, int zl) throws IOException {
|
||||
public void stream() throws IOException {
|
||||
int width = provider.getWidth();
|
||||
int height = provider.getHeight();
|
||||
|
||||
int xl = params.getXl();
|
||||
int yl = params.getYl();
|
||||
int zl = params.getZl();
|
||||
boolean reverse = params.isReverse();
|
||||
|
||||
// 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));
|
||||
writeWall3D(new Wall3d(params.getSouth(), x * xl, 0, 0));
|
||||
}
|
||||
if ((walls & Brick.LEFT) != 0) {
|
||||
writeWall3D(new Wall3d(West, x * xl, 0, 0));
|
||||
writeWall3D(new Wall3d(params.getWest(), 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));
|
||||
writeWall3D(new Wall3d(params.getWest(), 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));
|
||||
writeWall3D(new Wall3d(params.getNorth(), x * xl, y * yl, 0));
|
||||
}
|
||||
if ((walls & Brick.RIGHT) != 0) {
|
||||
writeWall3D(new Wall3d(East, x * xl, y * yl, 0));
|
||||
writeWall3D(new Wall3d(params.getEast(), x * xl, y * yl, 0));
|
||||
}
|
||||
short path = provider.getPath(x, y);
|
||||
|
||||
// where resolved path is leaked to stl model.
|
||||
Wall3d ground = reverse ? LowGround : HighGround;
|
||||
Wall3d ground = reverse ? params.getLowGround() : params.getHighGround();
|
||||
if ((path & LabyModel.SOLVED) == LabyModel.SOLVED)
|
||||
// if ( (walls & ( Brick.GOAL | Brick.ENTRY ) ) == 0 )
|
||||
{
|
||||
// if ( ( (x+y) % 2) == 0 )
|
||||
ground = reverse ? HighGround : LowGround;
|
||||
ground = reverse ? params.getHighGround() : params.getLowGround();
|
||||
}
|
||||
writeWall3D(new Wall3d(ground, x * xl, y * yl, 0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user