9f1387fe68
- Added undo
157 lines
4.5 KiB
Python
157 lines
4.5 KiB
Python
"""Material presets for the render backend.
|
|
|
|
Each preset is a RenderMaterial with physically-plausible values.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Dict, List
|
|
|
|
from .render_backend import RenderMaterial
|
|
|
|
# ── Preset library ──────────────────────────────────────────────────────
|
|
# Note: Mitsuba pip installs don't include spectral metal data files,
|
|
# so metal_preset is not used. Instead, metals use material="none" with
|
|
# specular_reflectance set to the metal color.
|
|
|
|
PRESETS: Dict[str, RenderMaterial] = {
|
|
# ── Metals ──────────────────────────────────────────────────────
|
|
"Brushed Steel": RenderMaterial(
|
|
name="Brushed Steel",
|
|
color=(0.65, 0.67, 0.72),
|
|
metallic=0.9,
|
|
roughness=0.35,
|
|
bsdf_type="roughconductor",
|
|
),
|
|
"Polished Chrome": RenderMaterial(
|
|
name="Polished Chrome",
|
|
color=(0.8, 0.8, 0.8),
|
|
metallic=1.0,
|
|
roughness=0.05,
|
|
bsdf_type="roughconductor",
|
|
),
|
|
"Brushed Aluminum": RenderMaterial(
|
|
name="Brushed Aluminum",
|
|
color=(0.75, 0.75, 0.75),
|
|
metallic=0.85,
|
|
roughness=0.25,
|
|
bsdf_type="roughconductor",
|
|
),
|
|
"Copper": RenderMaterial(
|
|
name="Copper",
|
|
color=(0.95, 0.64, 0.54),
|
|
metallic=0.95,
|
|
roughness=0.15,
|
|
bsdf_type="roughconductor",
|
|
),
|
|
"Gold": RenderMaterial(
|
|
name="Gold",
|
|
color=(1.0, 0.76, 0.33),
|
|
metallic=1.0,
|
|
roughness=0.1,
|
|
bsdf_type="roughconductor",
|
|
),
|
|
"Blackened Steel": RenderMaterial(
|
|
name="Blackened Steel",
|
|
color=(0.15, 0.15, 0.17),
|
|
metallic=0.8,
|
|
roughness=0.4,
|
|
bsdf_type="roughconductor",
|
|
),
|
|
# ── Plastics ────────────────────────────────────────────────────
|
|
"Matte Plastic": RenderMaterial(
|
|
name="Matte Plastic",
|
|
color=(0.2, 0.5, 0.8),
|
|
metallic=0.0,
|
|
roughness=0.6,
|
|
bsdf_type="plastic",
|
|
int_ior=1.5,
|
|
),
|
|
"Glossy Plastic": RenderMaterial(
|
|
name="Glossy Plastic",
|
|
color=(0.2, 0.5, 0.8),
|
|
metallic=0.0,
|
|
roughness=0.1,
|
|
bsdf_type="plastic",
|
|
int_ior=1.5,
|
|
),
|
|
"White Nylon": RenderMaterial(
|
|
name="White Nylon",
|
|
color=(0.85, 0.85, 0.83),
|
|
metallic=0.0,
|
|
roughness=0.45,
|
|
bsdf_type="plastic",
|
|
int_ior=1.53,
|
|
),
|
|
"Black ABS": RenderMaterial(
|
|
name="Black ABS",
|
|
color=(0.05, 0.05, 0.05),
|
|
metallic=0.0,
|
|
roughness=0.35,
|
|
bsdf_type="plastic",
|
|
int_ior=1.54,
|
|
),
|
|
"Red PA12": RenderMaterial(
|
|
name="Red PA12",
|
|
color=(0.75, 0.08, 0.08),
|
|
metallic=0.0,
|
|
roughness=0.4,
|
|
bsdf_type="plastic",
|
|
int_ior=1.53,
|
|
),
|
|
# ── Other ───────────────────────────────────────────────────────
|
|
"Rubber": RenderMaterial(
|
|
name="Rubber",
|
|
color=(0.1, 0.1, 0.1),
|
|
metallic=0.0,
|
|
roughness=0.9,
|
|
bsdf_type="diffuse",
|
|
),
|
|
"Ceramic White": RenderMaterial(
|
|
name="Ceramic White",
|
|
color=(0.92, 0.91, 0.88),
|
|
metallic=0.0,
|
|
roughness=0.15,
|
|
bsdf_type="dielectric",
|
|
int_ior=1.55,
|
|
),
|
|
"Glass": RenderMaterial(
|
|
name="Glass",
|
|
color=(0.95, 0.95, 0.95),
|
|
metallic=0.0,
|
|
roughness=0.0,
|
|
bsdf_type="dielectric",
|
|
int_ior=1.52,
|
|
),
|
|
"Wood": RenderMaterial(
|
|
name="Wood",
|
|
color=(0.6, 0.4, 0.2),
|
|
metallic=0.0,
|
|
roughness=0.7,
|
|
bsdf_type="diffuse",
|
|
),
|
|
}
|
|
|
|
|
|
def get_preset(name: str) -> RenderMaterial:
|
|
"""Get a material preset by name. Falls back to default if not found."""
|
|
if name in PRESETS:
|
|
return PRESETS[name]
|
|
return default_material()
|
|
|
|
|
|
def default_material() -> RenderMaterial:
|
|
"""Return the default grey material."""
|
|
return RenderMaterial(
|
|
name="Default",
|
|
color=(0.7, 0.7, 0.7),
|
|
metallic=0.0,
|
|
roughness=0.5,
|
|
bsdf_type="diffuse",
|
|
)
|
|
|
|
|
|
def preset_names() -> List[str]:
|
|
"""Return sorted list of available preset names."""
|
|
return sorted(PRESETS.keys())
|