Class StlUtils


  • final class StlUtils
    extends java.lang.Object
    Utility methods for the STL format.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StlUtils()
      Utility class; no instantiation.
    • Constructor Detail

      • StlUtils

        private StlUtils()
        Utility class; no instantiation.
    • Method Detail

      • byteBuffer

        static java.nio.ByteBuffer byteBuffer​(int capacity)
        Create a ByteBuffer with the given size and the byte order appropriate for binary STL content.
        Parameters:
        capacity - buffer capacity
        Returns:
        byte buffer
      • determineNormal

        static Vector3D determineNormal​(Vector3D p1,
                                        Vector3D p2,
                                        Vector3D p3,
                                        Vector3D normal)
        Determine the normal that should be used for the given STL triangle vertices. If normal is present and can be normalized, it is returned. Otherwise, a normal is attempted to be computed using the given triangle vertices. If normal computation fails, the zero vector is returned.
        Parameters:
        p1 - first point
        p2 - second point
        p3 - third point
        normal - defined triangle normal; may be null
        Returns:
        STL normal for the triangle
      • pointsAreCounterClockwise

        static boolean pointsAreCounterClockwise​(Vector3D p1,
                                                 Vector3D p2,
                                                 Vector3D p3,
                                                 Vector3D normal)
        Return true if the given points are arranged counter-clockwise relative to the given normal. Returns true if normal is null.
        Parameters:
        p1 - first point
        p2 - second point
        p3 - third point
        normal - normal; may be null, in which case the zero vector is used
        Returns:
        true if normal is null or if the given points are arranged counter-clockwise relative to normal
      • computeTriangleNormal

        private static Vector3D computeTriangleNormal​(Vector3D p1,
                                                      Vector3D p2,
                                                      Vector3D p3)
        Get the normal using the right-hand rule for the given triangle vertices. Null is returned if the normal could not be computed.
        Parameters:
        p1 - first point
        p2 - second point
        p3 - third point
        Returns:
        the normal for the given triangle vertices or null if one could not be computed