/**
* Export to OBJ in a separate class to be able to run HomePane without Java 3D classes.
*/
private static class OBJExporter {
public static void exportHomeToFile(Home home, String objFile, String header) throws RecorderException {
OBJWriter writer = null;
boolean exportInterrupted = false;
try {
writer = new OBJWriter(objFile, header, -1);
List<Selectable> emptySelection = Collections.emptyList();
home.setSelectedItems(emptySelection);
if (home.getWalls().size() > 0) {
// Create a not alive new ground to be able to explore its coordinates without setting capabilities
Rectangle2D homeBounds = getExportedHomeBounds(home);
Ground3D groundNode = new Ground3D(home,
(float)homeBounds.getX(), (float)homeBounds.getY(),
(float)homeBounds.getWidth(), (float)homeBounds.getHeight(), true);
writer.writeNode(groundNode, "ground");
}
// Write 3D walls
int i = 0;
for (Wall wall : home.getWalls()) {
// Create a not alive new wall to be able to explore its coordinates without setting capabilities
Wall3D wallNode = new Wall3D(wall, home, true, true);
writer.writeNode(wallNode, "wall_" + ++i);
}
// Write 3D furniture
i = 0;
for (HomePieceOfFurniture piece : home.getFurniture()) {
if (piece.isVisible()) {
// Create a not alive new piece to be able to explore its coordinates without setting capabilities
HomePieceOfFurniture3D pieceNode = new HomePieceOfFurniture3D(piece, home, true, true);
writer.writeNode(pieceNode);
}
}
// Write 3D rooms
i = 0;
for (Room room : home.getRooms()) {
// Create a not alive new room to be able to explore its coordinates without setting capabilities
Room3D roomNode = new Room3D(room, home, false, true, true);
writer.writeNode(roomNode, "room_" + ++i);
}
} catch (InterruptedIOException ex) {
exportInterrupted = true;
throw new InterruptedRecorderException("Export to " + objFile + " interrupted");
} catch (IOException ex) {
throw new RecorderException("Couldn't export to OBJ in " + objFile, ex);
} finally {
if (writer != null) {
try {
writer.close();
// Delete the file if exporting is interrupted
if (exportInterrupted) {
new File(objFile).delete();
}
} catch (IOException ex) {