Class TextureSampler

java.lang.Object
com.hypixel.hytale.builtin.buildertools.objimport.TextureSampler

public final class TextureSampler extends Object
Samples colors from texture images, supporting both average color and UV-based sampling.
  • Method Details

    • loadTexture

      @Nullable public static BufferedImage loadTexture(@Nonnull Path path)
      Loads a texture from disk, using a cache to avoid reloading.
      Parameters:
      path - path to the image file
      Returns:
      the loaded image, or null if it cannot be read
    • sampleAt

      @Nonnull public static int[] sampleAt(@Nonnull BufferedImage texture, float u, float v)
      Samples a texture at the given UV coordinates. Handles UV wrapping (values outside 0-1) and flips V coordinate since OBJ uses bottom-left origin while images use top-left.
      Parameters:
      texture - the texture image
      u - horizontal texture coordinate
      v - vertical texture coordinate
      Returns:
      RGB color array [r, g, b] (0-255)
    • sampleAlphaAt

      public static int sampleAlphaAt(@Nonnull BufferedImage texture, float u, float v)
      Samples a texture at the given UV coordinates and returns the alpha value. Returns 255 (fully opaque) for images without an alpha channel.
      Parameters:
      texture - the texture image
      u - horizontal texture coordinate
      v - vertical texture coordinate
      Returns:
      alpha value (0-255)
    • clearCache

      public static void clearCache()
      Clears the texture cache to free memory.
    • getAverageColor

      @Nullable public static int[] getAverageColor(@Nonnull Path path)
      Calculates the average RGB color of an image. Ignores fully transparent pixels (only for images with alpha channel).
      Parameters:
      path - path to the image file
      Returns:
      RGB color array [r, g, b] (0-255), or null if image cannot be read