private void writeFaces(BufferedWriter writer, Element cuboid) throws IOException { writer.write(space(3) + "\"faces\": {"); writer.newLine(); for (Face face : cuboid.getAllFaces()) { if (face.isEnabled()) { writer.write(space(4) + "\"" + Face.getFaceName(face.getSide()) + "\": { "); writer.write( "\"texture\": \"#" + textureList.indexOf(face.getTextureLocation() + face.getTextureName()) + "\""); writer.write( ", \"uv\": [ " + numToString(face.getStartU()) + ", " + numToString(face.getStartV()) + ", " + numToString(face.getEndU()) + ", " + numToString(face.getEndV()) + " ]"); if (face.getRotation() > 0) writer.write(", \"rotation\": " + numToString(face.getRotation() * 90)); if (face.isCullfaced()) writer.write(", \"cullface\": \"" + Face.getFaceName(face.getSide()) + "\""); writer.write(" }"); if (face.getSide() != cuboid.getLastValidFace()) { writer.write(","); writer.newLine(); } } } writer.newLine(); writer.write(space(3) + "}"); }
private void compileTextureList() { for (Element cuboid : manager.getAllElements()) { for (Face face : cuboid.getAllFaces()) { System.out.println(face.getTextureLocation() + " " + face.getTextureName()); if (face.getTextureName() != null && !face.getTextureName().equals("null")) { if (!textureList.contains(face.getTextureLocation() + face.getTextureName())) { textureList.add(face.getTextureLocation() + face.getTextureName()); } } } } }
private void writeElement(BufferedWriter writer, Element cuboid) throws IOException { writer.write(space(3) + "\"name\": \"" + cuboid.toString() + "\","); writer.newLine(); writeBounds(writer, cuboid); writer.newLine(); if (!cuboid.isShaded()) { writeShade(writer, cuboid); writer.newLine(); } if (cuboid.getRotation() != 0) { writeRotation(writer, cuboid); writer.newLine(); } writeFaces(writer, cuboid); }
private void writeRotation(BufferedWriter writer, Element cuboid) throws IOException { writer.write(space(3) + "\"rotation\": { "); writer.write( "\"origin\": [ " + numToString(cuboid.getOriginX()) + ", " + numToString(cuboid.getOriginY()) + ", " + numToString(cuboid.getOriginZ()) + " ], "); writer.write("\"axis\": \"" + Element.parseAxis(cuboid.getPrevAxis()) + "\", "); writer.write("\"angle\": " + numToString(cuboid.getRotation())); if (cuboid.shouldRescale()) { writer.write(", \"rescale\": " + cuboid.shouldRescale()); } writer.write(" },"); }
private void writeBounds(BufferedWriter writer, Element cuboid) throws IOException { writer.write( space(3) + "\"from\": [ " + numToString(cuboid.getStartX()) + ", " + numToString(cuboid.getStartY()) + ", " + numToString(cuboid.getStartZ()) + " ], "); writer.newLine(); writer.write( space(3) + "\"to\": [ " + numToString((cuboid.getStartX() + cuboid.getWidth())) + ", " + numToString((cuboid.getStartY() + cuboid.getHeight())) + ", " + numToString((cuboid.getStartZ() + cuboid.getDepth())) + " ], "); }
private void writeShade(BufferedWriter writer, Element cuboid) throws IOException { writer.write(space(3) + "\"shade\": " + cuboid.isShaded() + ","); }