/** * UnifiedPBRSchema.ts * * Unified PBR material schema that both MaterialEditor.ts and MaterialLibrary.ts * should converge on. Defines the single canonical `PBRMaterialProperties` * interface covering ALL physical properties with proper defaults and validation. * * Background (from MEMORY.md W.040): * HoloScript's trait system supports advanced PBR (SSS, iridescence, * 16 texture channels, custom shaders, 78 material presets) but the R3F * renderer only outputs basic meshPhysicalMaterial with color/metalness/roughness. * This schema is the single source of truth for what PBR properties exist * and what their valid ranges are. * * Relationship to existing types: * - `MaterialDef` (MaterialLibrary.ts) covers core PBR + rendering flags * - `MaterialEditor` (MaterialEditor.ts) re-exports MaterialDef * - This file EXTENDS the schema with advanced physical properties * (transmission, subsurface, iridescence, clearcoat, sheen, anisotropy) * that the existing MaterialDef lacks but the trait system supports * * Usage: * ```typescript * import { createDefaultPBRProperties, validatePBRProperties } from './UnifiedPBRSchema'; * * const props = createDefaultPBRProperties('my-material'); * props.transmission = 0.95; // Glass-like * props.subsurface.weight = 0.8; // Skin-like SSS * * const errors = validatePBRProperties(props); * if (errors.length > 0) console.error('Validation failed:', errors); * ``` * * @module rendering * @see packages/core/src/rendering/MaterialLibrary.ts * @see packages/core/src/tools/MaterialEditor.ts * @version 1.0.0 * @package @holoscript/examples */ /** Blend mode for rendering */ export type BlendMode = 'opaque' | 'transparent' | 'additive' | 'multiply' | 'premultiplied-alpha'; /** Face culling mode */ export type CullMode = 'none' | 'front' | 'back'; /** Material type classification */ export type MaterialType = 'standard' | 'physical' | 'basic' | 'emissive' | 'toon' | 'glass' | 'metal' | 'subsurface' | 'cloth' | 'hair' | 'eye' | 'custom'; /** Alpha mode per glTF 2.0 spec */ export type AlphaMode = 'OPAQUE' | 'MASK' | 'BLEND'; /** Linear RGBA color (0-1 per channel) */ export interface LinearColor { r: number; g: number; b: number; a: number; } /** Linear RGB color (0-1 per channel, no alpha) */ export interface LinearRGB { r: number; g: number; b: number; } /** UV tiling and offset for texture mapping */ export interface UVTransform { tiling: { x: number; y: number; }; offset: { x: number; y: number; }; rotation: number; } /** * Texture reference with full UV configuration. * Texture IDs reference assets managed by the asset pipeline. */ export interface TextureReference { /** Asset ID of the texture */ textureId: string; /** UV channel index (0-3) */ uvChannel: number; /** UV transform (tiling, offset, rotation) */ uvTransform: UVTransform; /** Texture intensity/strength multiplier (0-1) */ intensity: number; /** sRGB color space flag (true for albedo/emissive, false for data textures) */ sRGB: boolean; } /** * Subsurface scattering (SSS) properties. * Used for skin, wax, marble, jade, milk, etc. */ export interface SubsurfaceProperties { /** SSS weight / intensity (0-1) */ weight: number; /** Scattering color (light color after subsurface transport) */ color: LinearRGB; /** Scattering radius per RGB channel (in scene units) */ radius: { r: number; g: number; b: number; }; /** Thin-walled mode (for leaves, paper, etc.) */ thinWalled: boolean; /** Subsurface texture map */ map?: TextureReference; } /** * Transmission properties for glass, water, and transparent materials. * Implements KHR_materials_transmission + KHR_materials_volume. */ export interface TransmissionProperties { /** Transmission factor (0=opaque, 1=fully transmissive) */ factor: number; /** Index of refraction (1.0=air, 1.33=water, 1.5=glass, 2.42=diamond) */ ior: number; /** Volume thickness for absorption (scene units) */ thickness: number; /** Absorption color (color of transmitted light after distance) */ attenuationColor: LinearRGB; /** Absorption distance (scene units before full absorption) */ attenuationDistance: number; /** Dispersion amount (chromatic aberration, 0=none) */ dispersion: number; /** Transmission texture map */ map?: TextureReference; /** Thickness texture map */ thicknessMap?: TextureReference; } /** * Iridescence properties (thin-film interference). * Implements KHR_materials_iridescence. * Used for soap bubbles, oil slicks, beetle shells, etc. */ export interface IridescenceProperties { /** Iridescence intensity (0-1) */ factor: number; /** Index of refraction of the thin film */ ior: number; /** Thin film thickness range in nanometers */ thicknessRange: { min: number; max: number; }; /** Iridescence intensity map */ map?: TextureReference; /** Iridescence thickness map (remaps to thicknessRange) */ thicknessMap?: TextureReference; } /** * Clearcoat properties (automotive paint, lacquered wood). * Implements KHR_materials_clearcoat. */ export interface ClearcoatProperties { /** Clearcoat intensity (0-1) */ factor: number; /** Clearcoat roughness (0-1) */ roughness: number; /** Clearcoat intensity map */ map?: TextureReference; /** Clearcoat roughness map */ roughnessMap?: TextureReference; /** Clearcoat normal map (independent from base normal) */ normalMap?: TextureReference; /** Clearcoat normal scale */ normalScale: number; } /** * Sheen properties (cloth, velvet, microfiber). * Implements KHR_materials_sheen. */ export interface SheenProperties { /** Sheen color */ color: LinearRGB; /** Sheen roughness (0-1) */ roughness: number; /** Sheen color map */ colorMap?: TextureReference; /** Sheen roughness map */ roughnessMap?: TextureReference; } /** * Anisotropy properties (brushed metal, hair, silk). * Implements KHR_materials_anisotropy. */ export interface AnisotropyProperties { /** Anisotropy strength (-1 to 1, 0=isotropic) */ strength: number; /** Anisotropy rotation in radians (direction of anisotropy) */ rotation: number; /** Anisotropy direction/strength map */ map?: TextureReference; } /** * Specular properties (allows decoupling specular from metallic). * Implements KHR_materials_specular. */ export interface SpecularProperties { /** Specular intensity factor (0-1, default 1.0) */ factor: number; /** Specular color tint */ color: LinearRGB; /** Specular intensity map */ map?: TextureReference; /** Specular color map */ colorMap?: TextureReference; } /** * Complete PBR material properties interface. * * This is the single canonical schema for ALL PBR material properties * across HoloScript. Every rendering backend (R3F, Babylon, Three.js, * Unity, Unreal, Godot, WebGPU) maps FROM this schema to their * native material representations. * * Property groups follow the glTF 2.0 PBR metallic-roughness model * with KHR extensions for advanced features. */ export interface PBRMaterialProperties { /** Unique material identifier */ id: string; /** Human-readable material name */ name: string; /** Material type classification for editor UI */ materialType: MaterialType; /** Material version for change tracking */ version: number; /** Tags for categorization and search */ tags: string[]; /** Base color in linear RGBA */ baseColor: LinearColor; /** Base color / albedo texture map */ baseColorMap?: TextureReference; /** Metalness factor (0=dielectric, 1=metal) */ metalness: number; /** Roughness factor (0=mirror, 1=diffuse) */ roughness: number; /** Combined metallic-roughness map (G=roughness, B=metallic per glTF) */ metallicRoughnessMap?: TextureReference; /** Normal map */ normalMap?: TextureReference; /** Normal map scale / intensity */ normalScale: number; /** Ambient occlusion map */ aoMap?: TextureReference; /** AO intensity (0-1) */ aoIntensity: number; /** Emissive color (linear RGB) */ emissive: LinearRGB; /** Emissive intensity multiplier */ emissiveIntensity: number; /** Emissive texture map */ emissiveMap?: TextureReference; /** Displacement / height map */ displacementMap?: TextureReference; /** Displacement scale */ displacementScale: number; /** Displacement bias */ displacementBias: number; /** Baked light map */ lightMap?: TextureReference; /** Light map intensity */ lightMapIntensity: number; /** Subsurface scattering (skin, wax, marble) */ subsurface: SubsurfaceProperties; /** Transmission (glass, water, gems) */ transmission: TransmissionProperties; /** Iridescence (thin-film interference) */ iridescence: IridescenceProperties; /** Clearcoat (automotive paint, lacquer) */ clearcoat: ClearcoatProperties; /** Sheen (cloth, velvet) */ sheen: SheenProperties; /** Anisotropy (brushed metal, hair) */ anisotropy: AnisotropyProperties; /** Specular (decoupled from metallic) */ specular: SpecularProperties; /** Blend mode */ blendMode: BlendMode; /** Alpha mode per glTF spec */ alphaMode: AlphaMode; /** Alpha cutoff for MASK mode (0-1) */ alphaCutoff: number; /** Face culling mode */ cullMode: CullMode; /** Enable depth writing */ depthWrite: boolean; /** Enable depth testing */ depthTest: boolean; /** Double-sided rendering */ doubleSided: boolean; /** Cast shadows */ castShadow: boolean; /** Receive shadows */ receiveShadow: boolean; /** Flat shading (no smooth interpolation) */ flatShading: boolean; /** Wireframe rendering */ wireframe: boolean; /** Shader graph ID (for custom node-based shaders) */ shaderGraphId?: string; /** Custom uniform values for shader graph */ customUniforms?: Record; /** Arbitrary extension properties */ extensions?: Record; } /** Default subsurface properties (disabled) */ export declare const DEFAULT_SUBSURFACE: SubsurfaceProperties; /** Default transmission properties (opaque) */ export declare const DEFAULT_TRANSMISSION: TransmissionProperties; /** Default iridescence properties (disabled) */ export declare const DEFAULT_IRIDESCENCE: IridescenceProperties; /** Default clearcoat properties (disabled) */ export declare const DEFAULT_CLEARCOAT: ClearcoatProperties; /** Default sheen properties (disabled) */ export declare const DEFAULT_SHEEN: SheenProperties; /** Default anisotropy properties (isotropic) */ export declare const DEFAULT_ANISOTROPY: AnisotropyProperties; /** Default specular properties (standard dielectric) */ export declare const DEFAULT_SPECULAR: SpecularProperties; /** * Create a PBRMaterialProperties object with sensible defaults. * All advanced property groups start disabled (zero intensity). */ export declare function createDefaultPBRProperties(id: string, name?: string, materialType?: MaterialType): PBRMaterialProperties; /** A single validation error with field path and message. */ export interface ValidationError { field: string; message: string; value: unknown; } /** * Validate complete PBR material properties. * Returns an array of validation errors (empty = valid). */ export declare function validatePBRProperties(props: PBRMaterialProperties): ValidationError[]; /** * Material preset with overrides to apply on top of defaults. */ export interface PBRPreset { /** Preset name */ name: string; /** Category for UI grouping */ category: string; /** Property overrides */ overrides: Partial; } /** * Built-in PBR material presets. * These match the 78 presets referenced in W.040. */ export declare const PBR_PRESETS: PBRPreset[]; /** * Apply a preset's overrides onto default PBR properties. * Returns a complete PBRMaterialProperties object. */ export declare function applyPreset(preset: PBRPreset, id?: string): PBRMaterialProperties; /** * Convert PBRMaterialProperties to the existing MaterialDef format * used by MaterialLibrary.ts for backward compatibility. * * Note: Advanced properties (subsurface, iridescence, etc.) are stored * in the `properties` extension field of MaterialDef. */ export declare function toMaterialDef(props: PBRMaterialProperties): { id: string; name: string; materialType: MaterialType; albedo: LinearColor; metallic: number; roughness: number; emission: LinearRGB; emissionStrength: number; normalScale: number; aoStrength: number; blendMode: BlendMode; cullMode: CullMode; depthWrite: boolean; depthTest: boolean; doubleSided: boolean; shaderGraphId?: string; customUniforms?: Record; properties?: Record; }; /** * Convert from the existing MaterialDef format to PBRMaterialProperties. * Advanced properties are extracted from the `properties` extension field. */ export declare function fromMaterialDef(def: { id: string; name: string; materialType?: MaterialType; albedo: LinearColor; metallic: number; roughness: number; emission: LinearRGB; emissionStrength: number; normalScale: number; aoStrength: number; blendMode: BlendMode; cullMode: CullMode; depthWrite: boolean; depthTest: boolean; doubleSided: boolean; shaderGraphId?: string; customUniforms?: Record; properties?: Record; }): PBRMaterialProperties; //# sourceMappingURL=UnifiedPBRSchema.d.ts.map