Ejemplo n.º 1
0
  /**
   * Writes a triangle in ASCII.
   *
   * @param writer The file we want to write in.
   * @param triangle The triangle to write.
   */
  private static void writeASCIITriangle(final BufferedWriter writer, final Triangle triangle) {
    try {
      // Write facet normal : to begin a triangle with writing its normal.
      String s1 = "\nfacet normal";

      s1 +=
          " "
              + triangle.getNormal().x
              + " "
              + triangle.getNormal().y
              + " "
              + triangle.getNormal().z;

      // Write outer loop : to begin to write the three points.
      writer.write(s1 + "\nouter loop");
      // Write the three points.
      for (final Point p : triangle.getPoints()) {
        writer.write("\nvertex" + " " + p.getX() + " " + p.getY() + " " + p.getZ());
      }

      // Write the end of the facet.
      writer.write("\nendloop\nendfacet");
    } catch (final java.io.IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  /**
   * Writes a triangle in the binary format.
   *
   * @param writer the writer which writes in the file
   * @param triangle the triangle to write
   * @throws IOException if the writer throws an error
   */
  private static void writeBinaryTriangle(final OutputStream writer, final Triangle triangle)
      throws IOException {

    // Write first the normal.
    WriterSTL.writeInGoodOrder(writer, triangle.getNormal().getX());
    WriterSTL.writeInGoodOrder(writer, triangle.getNormal().getY());
    WriterSTL.writeInGoodOrder(writer, triangle.getNormal().getZ());

    // And the three points after.
    WriterSTL.writeInGoodOrder(writer, triangle.getP1().getX());
    WriterSTL.writeInGoodOrder(writer, triangle.getP1().getY());
    WriterSTL.writeInGoodOrder(writer, triangle.getP1().getZ());

    WriterSTL.writeInGoodOrder(writer, triangle.getP2().getX());
    WriterSTL.writeInGoodOrder(writer, triangle.getP2().getY());
    WriterSTL.writeInGoodOrder(writer, triangle.getP2().getZ());

    WriterSTL.writeInGoodOrder(writer, triangle.getP3().getX());
    WriterSTL.writeInGoodOrder(writer, triangle.getP3().getY());
    WriterSTL.writeInGoodOrder(writer, triangle.getP3().getZ());

    writer.write(new byte[2]);
  }