From 0ab21b5199755fcd55aa628d31f8856ec7dabfaf Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 00:45:22 +0200 Subject: [PATCH] Update terrain layer material options to use dynamic arrays and implement padding utilities --- src/rendering/terrain-layer-material.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/rendering/terrain-layer-material.ts b/src/rendering/terrain-layer-material.ts index 60ee3748..088e4ea6 100644 --- a/src/rendering/terrain-layer-material.ts +++ b/src/rendering/terrain-layer-material.ts @@ -13,9 +13,10 @@ import { } from "three"; import type { MaterialDef } from "../materials/starter-material-library"; +import { TERRAIN_SHADER_LAYER_COUNT } from "../document/terrains"; interface TerrainLayerBlendMaterialOptions { - layerTextures: readonly [Texture, Texture, Texture, Texture]; + layerTextures: readonly Texture[]; emissiveHex?: number; emissiveIntensity?: number; foliageMaskPreviewColorHex?: number; @@ -24,7 +25,7 @@ interface TerrainLayerBlendMaterialOptions { } interface TerrainLayerColorBlendMaterialOptions { - layerColors: readonly [number, number, number, number]; + layerColors: readonly number[]; emissiveHex?: number; emissiveIntensity?: number; foliageMaskPreviewColorHex?: number; @@ -74,6 +75,26 @@ export function getTerrainLayerPreviewColor(material: MaterialDef | null): numbe : new Color(material.swatchColorHex).getHex(); } +function createPaddedTerrainLayerTextures( + textures: readonly Texture[] +): Texture[] { + const fallbackTexture = getFallbackTerrainLayerTexture(); + + return Array.from( + { length: TERRAIN_SHADER_LAYER_COUNT }, + (_, index) => textures[index] ?? fallbackTexture + ); +} + +function createPaddedTerrainLayerColors(layerColors: readonly number[]): Color[] { + const fallbackColor = getTerrainLayerPreviewColor(null); + + return Array.from( + { length: TERRAIN_SHADER_LAYER_COUNT }, + (_, index) => new Color(layerColors[index] ?? fallbackColor) + ); +} + export function createTerrainLayerBlendMaterial( options: TerrainLayerBlendMaterialOptions ): Material {