Refactor: Update material definition types to use a base interface and separate starter/custom definitions

This commit is contained in:
2026-05-18 15:57:06 +02:00
parent ee5cb3023e
commit a029a99d80

View File

@@ -1,28 +1,65 @@
import { createOpaqueId } from "../core/ids";
export type MaterialWorkflow =
| "roughness-only"
| "metallic-roughness"
| "specular-roughness";
export type MaterialPreviewImageName = "preview.webp" | "preview_sphere.webp";
export const MATERIAL_TEXTURE_SLOTS = [
"albedo",
"normal",
"roughness",
"metallic"
] as const;
export type MaterialKind = "starter" | "custom";
export type MaterialTextureSlot = (typeof MATERIAL_TEXTURE_SLOTS)[number];
export interface MaterialSizeCm {
width: number;
height: number;
}
export interface MaterialDef {
interface MaterialDefBase {
id: string;
kind: MaterialKind;
name: string;
assetFolder: string;
workflow: MaterialWorkflow;
previewImageName: MaterialPreviewImageName;
sizeCm: MaterialSizeCm;
swatchColorHex: string;
tags: string[];
}
export interface StarterMaterialDef extends MaterialDefBase {
kind: "starter";
assetFolder: string;
workflow: MaterialWorkflow;
previewImageName: MaterialPreviewImageName;
sizeCm: MaterialSizeCm;
}
export interface MaterialTextureRef {
assetId: string;
}
export type CustomMaterialTextureRefs = Record<
MaterialTextureSlot,
MaterialTextureRef | null
>;
export interface CustomMaterialDef extends MaterialDefBase {
kind: "custom";
albedoColorHex: string;
opacity: number;
roughness: number;
metallic: number;
normalStrength: number;
textures: CustomMaterialTextureRefs;
}
export type MaterialDef = StarterMaterialDef | CustomMaterialDef;
interface MaterialCatalogEntry
extends Omit<MaterialDef, "tags"> {}
extends Omit<StarterMaterialDef, "kind" | "tags"> {}
const STARTER_MATERIAL_ASSET_ROOT = "/starter-materials";