@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
132 lines (131 loc) • 6.22 kB
TypeScript
/**
* TexturedRectangleGenerator
*
* Generates textured rectangles (filled areas) for Minecraft-style pixel art.
* Produces SVG output with rect elements for blocky/pixelated aesthetics,
* or direct RGBA pixel data for efficient texture generation.
*
* Uses NoiseGenerationUtilities for the core noise algorithms.
*
* Supports both the new IMcpTexturedRectangle format and legacy IMcpNoiseConfig for backwards compatibility.
*/
import { IMcpNoiseConfig, IMcpPixelArt, IMcpPixelColor, IMcpTexturedRectangle } from "./IMcpModelDesign";
import NoiseGenerationUtilities, { SeededRandom } from "./NoiseGenerationUtilities";
import type { ParsedColor } from "./NoiseGenerationUtilities";
/**
* Textured rectangle generator for Minecraft-style procedural textures.
*/
export default class TexturedRectangleGenerator {
/**
* Maps new TexturedRectangleType to legacy NoisePatternType for internal processing.
*/
private static texturedRectangleTypeToPattern;
/**
* Generate an SVG string from a textured rectangle configuration.
* This is the primary API for the new unified texture format.
*
* @param config Textured rectangle configuration
* @param width Width of the texture in pixels
* @param height Height of the texture in pixels
* @param contextString Optional context string for seed generation
* @returns SVG string with the texture pattern
*/
static generateTexturedRectangleSvg(config: IMcpTexturedRectangle, width: number, height: number, contextString?: string): string;
/**
* Generate an SVG string containing the noise texture.
* @deprecated Use generateTexturedRectangleSvg with IMcpTexturedRectangle instead.
*
* @param config Noise configuration with colors, pattern, and parameters
* @param width Width of the texture in pixels
* @param height Height of the texture in pixels
* @param contextString Optional context string for seed generation (e.g., "textureId:wood")
* @returns SVG string with rect elements forming the noise pattern
*/
static generateNoiseSvg(config: IMcpNoiseConfig, width: number, height: number, contextString?: string): string;
/**
* Convert color grid to SVG with rect elements
*/
private static gridToSvg;
/**
* Combine noise SVG with optional overlay SVG.
* The noise forms the background, and the overlay is drawn on top.
*
* @param noiseSvg The noise pattern SVG
* @param overlaySvg Optional SVG to draw on top of the noise
* @param width Texture width
* @param height Texture height
* @returns Combined SVG string
*/
static combineWithOverlay(noiseSvg: string, overlaySvg: string | undefined, width: number, height: number): string;
/**
* Extract inner content from SVG string (removing outer svg tags)
*/
private static extractSvgInner;
/**
* Generate noise texture as RGBA pixel data (Uint8Array).
* This bypasses SVG generation entirely for better performance.
* @deprecated Use generateTexturedRectanglePixels with IMcpTexturedRectangle instead.
*
* @param config Noise configuration with colors, pattern, and parameters
* @param width Width of the texture in pixels
* @param height Height of the texture in pixels
* @param contextString Optional context string for seed generation
* @returns RGBA pixel data as Uint8Array (width * height * 4 bytes)
*/
static generateNoisePixels(config: IMcpNoiseConfig, width: number, height: number, contextString?: string): Uint8Array;
/**
* Generate RGBA pixel data from a textured rectangle configuration.
* This is the primary API for the new unified texture format.
*
* @param config Textured rectangle configuration
* @param width Width of the texture in pixels
* @param height Height of the texture in pixels
* @param contextString Optional context string for seed generation
* @returns RGBA pixel data as Uint8Array (width * height * 4 bytes)
*/
static generatePixels(config: IMcpTexturedRectangle, width: number, height: number, contextString?: string): Uint8Array;
/**
* Convert color grid to RGBA pixel data
*/
private static gridToPixels;
/**
* Parse an IMcpPixelColor to a ParsedColor (RGBA 0-255).
*/
static parsePixelColor(color: IMcpPixelColor): ParsedColor;
/**
* Apply pixel art overlay to an existing RGBA pixel buffer.
* This is the core pixel art rendering method - operates directly on pixel data
* for maximum performance (no SVG generation).
*
* @param pixels Existing RGBA pixel buffer to modify in-place
* @param width Width of the pixel buffer (face texture width in pixels)
* @param height Height of the pixel buffer (face texture height in pixels)
* @param pixelArt Pixel art configuration to apply
* @param pixelsPerUnit Pixels per Minecraft unit (for "unit" scaleMode). Default: 2
*/
static applyPixelArt(pixels: Uint8Array, width: number, height: number, pixelArt: IMcpPixelArt, pixelsPerUnit?: number): void;
/**
* Apply multiple pixel art overlays in order.
* Each layer is rendered on top of the previous.
*
* @param pixels Existing RGBA pixel buffer to modify in-place
* @param width Width of the pixel buffer
* @param height Height of the pixel buffer
* @param pixelArtLayers Array of pixel art configurations to apply
* @param pixelsPerUnit Pixels per Minecraft unit (for "unit" scaleMode). Default: 2
*/
static applyPixelArtLayers(pixels: Uint8Array, width: number, height: number, pixelArtLayers: IMcpPixelArt[], pixelsPerUnit?: number): void;
/**
* Generate pixel art as standalone RGBA pixel data.
* Creates a transparent buffer and applies the pixel art to it.
*
* @param pixelArt Pixel art configuration
* @returns Object with pixels (RGBA Uint8Array), width, and height
*/
static generatePixelArtPixels(pixelArt: IMcpPixelArt): {
pixels: Uint8Array;
width: number;
height: number;
};
}
export { NoiseGenerationUtilities, SeededRandom, ParsedColor };