Source code for simvx.graphics.materials.material

"""Material definition with feature bitmask."""


from __future__ import annotations

import logging

import numpy as np

from .._types import MATERIAL_DTYPE, Feature

log = logging.getLogger(__name__)

__all__ = ["MaterialBuffer"]


[docs] class MaterialBuffer: """Flat array of materials for GPU upload via SSBO.""" def __init__(self, max_materials: int = 4096) -> None: self.data = np.zeros(max_materials, dtype=MATERIAL_DTYPE) self.count = 0
[docs] def add( self, albedo: tuple[float, float, float, float] = (1.0, 1.0, 1.0, 1.0), metallic: float = 0.0, roughness: float = 0.5, features: Feature = Feature.NONE, albedo_tex: int = -1, normal_tex: int = -1, ) -> int: """Add a material. Returns its index.""" idx = self.count m = self.data[idx] m["albedo"] = albedo m["metallic"] = metallic m["roughness"] = roughness m["features"] = int(features) m["albedo_tex"] = albedo_tex m["normal_tex"] = normal_tex m["metallic_roughness_tex"] = -1 m["emissive_tex"] = -1 m["ao_tex"] = -1 self.count += 1 return idx