From 31a337da6aa40426afff14fdbfc2721c4dbbd71b Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 18 May 2026 16:29:34 +0200 Subject: [PATCH] Add test case to ensure terrain layers use swatch colors when no texture is found --- src/rendering/terrain-layer-material.ts | 5 ++++- tests/domain/material-rendering.test.ts | 27 +++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/rendering/terrain-layer-material.ts b/src/rendering/terrain-layer-material.ts index 5f96185f..3adfeade 100644 --- a/src/rendering/terrain-layer-material.ts +++ b/src/rendering/terrain-layer-material.ts @@ -100,7 +100,10 @@ export function getTerrainLayerTexture( return getFallbackTerrainLayerTexture(); } - return textureLookup(material) ?? getSolidColorTerrainLayerTexture(material.swatchColorHex); + return ( + textureLookup(material) ?? + getSolidColorTerrainLayerTexture(material.swatchColorHex) + ); } export function getTerrainLayerPreviewColor( diff --git a/tests/domain/material-rendering.test.ts b/tests/domain/material-rendering.test.ts index 8568c695..23f5ae04 100644 --- a/tests/domain/material-rendering.test.ts +++ b/tests/domain/material-rendering.test.ts @@ -8,6 +8,10 @@ import { disposeMaterialTextureSet } from "../../src/materials/material-rendering"; import { createCustomMaterialDef } from "../../src/materials/starter-material-library"; +import { + getFallbackTerrainLayerTexture, + getTerrainLayerTexture +} from "../../src/rendering/terrain-layer-material"; function createLoadedImageAsset( assetId: string, @@ -74,14 +78,10 @@ describe("material rendering", () => { } }); - const textureSet = createMaterialTextureSet( - material, - new TextureLoader(), - { - [albedoAsset.assetId]: albedoAsset, - [normalAsset.assetId]: normalAsset - } - ); + const textureSet = createMaterialTextureSet(material, new TextureLoader(), { + [albedoAsset.assetId]: albedoAsset, + [normalAsset.assetId]: normalAsset + }); expect(textureSet.baseColor).not.toBeNull(); expect(textureSet.normal).not.toBeNull(); @@ -96,4 +96,15 @@ describe("material rendering", () => { albedoAsset.texture.dispose(); normalAsset.texture.dispose(); }); + + it("uses custom material swatch colors for scalar-only terrain layers", () => { + const material = createCustomMaterialDef({ + id: "material-terrain-swatch", + albedoColorHex: "#335577" + }); + const texture = getTerrainLayerTexture(material, () => null); + + expect(texture).not.toBe(getFallbackTerrainLayerTexture()); + expect(getTerrainLayerTexture(material, () => null)).toBe(texture); + }); });