Contents
Class TextureSampler
java.lang.Object
com.hypixel.hytale.builtin.buildertools.objimport.TextureSampler
Samples colors from texture images, supporting both average color and UV-based sampling.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears the texture cache to free memory.static int[]getAverageColor(Path path) Calculates the average RGB color of an image.static BufferedImageloadTexture(Path path) Loads a texture from disk, using a cache to avoid reloading.static intsampleAlphaAt(BufferedImage texture, float u, float v) Samples a texture at the given UV coordinates and returns the alpha value.static int[]sampleAt(BufferedImage texture, float u, float v) Samples a texture at the given UV coordinates.
-
Method Details
-
loadTexture
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
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 imageu- horizontal texture coordinatev- vertical texture coordinate- Returns:
- RGB color array [r, g, b] (0-255)
-
sampleAlphaAt
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 imageu- horizontal texture coordinatev- vertical texture coordinate- Returns:
- alpha value (0-255)
-
clearCache
public static void clearCache()Clears the texture cache to free memory. -
getAverageColor
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
-