Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-3d

Source of release 0.9.5

0.9.5 / src / materials / basic.lucb

import interop
import errors
from core.material import Material, Color, check_color

pub struct MeshBasicMaterial: Material:
    var tint: Color
    ## See Material.fade: 0 opaque, up to 1 a see-through grey.
    var fading: f64

    pub func init(color: Color = Color(1.0, 1.0, 1.0)) -> !:
        try check_color(color)
        self.tint = color
        self.fading = 0.0

    pub func color() -> Color:
        return self.tint

    pub func set_color(color: Color) -> !:
        try check_color(color)
        self.tint = color

    pub func is_lit() -> bool:
        return false

    pub func fade() -> f64:
        return self.fading

    ## Fade the surface toward a see-through grey (0 opaque, 1 most faded).
    pub func set_fade(amount: f64) -> !:
        if not (amount >= 0.0 and amount <= 1.0): error(errors.invalid, "a material fade lies in 0..1")
        self.fading = amount

    pub func close():
        # Color is inline; the shared owner enforces closure across mesh aliases.
        _ = self.tint

pub let basic_material_type: interop.Type[MeshBasicMaterial] = interop.Type[MeshBasicMaterial]("MeshBasicMaterial", MeshBasicMaterial.close, closeable = true, main_thread = true)