Add test case to ensure terrain layers use swatch colors when no texture is found

This commit is contained in:
2026-05-18 16:29:34 +02:00
parent df6f52464e
commit 31a337da6a
2 changed files with 23 additions and 9 deletions

View File

@@ -100,7 +100,10 @@ export function getTerrainLayerTexture(
return getFallbackTerrainLayerTexture();
}
return textureLookup(material) ?? getSolidColorTerrainLayerTexture(material.swatchColorHex);
return (
textureLookup(material) ??
getSolidColorTerrainLayerTexture(material.swatchColorHex)
);
}
export function getTerrainLayerPreviewColor(

View File

@@ -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);
});
});