Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-geocore

Source of release 0.7.9

0.7.9 / src / code / modes.lucb

# Run Over modes: Houdini's menu order, what each one's entry function declares, the
# domain its lanes are elements of, and the word its messages name an element with.

## What a Code node runs over.
pub enum RunOver as u8:
    ## Once, for the detail.
    detail = 0
    ## Once per point.
    points = 1
    ## Once per vertex (a face's corner).
    vertices = 2
    ## Once per primitive (face).
    primitives = 3
    ## `count` times, numbered.
    numbers = 4
    ## Once per active voxel of a volume grid (Houdini's Volume Wrangle).
    voxels = 5

extend RunOver:
    ## The mode a menu value names.
    static func of(value: i64) -> RunOver!:
        if value < 0 or value > 5:
            error(errors.invalid, "Run Over is 0 (detail), 1 (points), 2 (vertices), 3 (primitives), 4 (numbers) or 5 (voxels)")
        return (RunOver)(u8)value

    ## The entry function the snippet's body goes into; the `gsplat` helpers are imported
    ## when the text uses them (an unused import is an error).
    func wrapper(gsplat: bool = false) -> lower.RunOver:
        let imports = "from luce_geocore.code import Point, Prim, Vertex, Voxel, Kernel\nfrom luce_geocore import gsplat" if gsplat else "from luce_geocore.code import Point, Prim, Vertex, Voxel, Kernel"
        return match self:
            .detail => lower.RunOver(entry = "detail", parameters = "k: Kernel*", imports = imports)
            .points => lower.RunOver(entry = "point", parameters = "p: Point*, k: const Kernel*", imports = imports)
            .vertices => lower.RunOver(entry = "vertex", parameters = "v: Vertex*, k: const Kernel*", imports = imports)
            .primitives => lower.RunOver(entry = "prim", parameters = "f: Prim*, k: const Kernel*", imports = imports)
            .voxels => lower.RunOver(entry = "voxel", parameters = "x: Voxel*, k: const Kernel*", imports = imports)
            _ => lower.RunOver(entry = "number", parameters = "n: i64, k: Kernel*", imports = imports)

    ## The mesh domain its lanes are elements of (detail for Detail and Numbers).
    func domain() -> Domain:
        return match self:
            .points => Domain.point
            .vertices => Domain.corner
            .primitives => Domain.face
            _ => Domain.detail

    ## The word a fault message names an element with.
    func element() -> str:
        return match self:
            .points => "point"
            .vertices => "vertex"
            .primitives => "prim"
            .numbers => "number"
            .voxels => "voxel"
            _ => "detail"

    ## The stub type a mode's element is.
    func owner() -> str:
        return match self:
            .points => "Point"
            .vertices => "Vertex"
            .primitives => "Prim"
            .voxels => "Voxel"
            _ => "Kernel"

## Whether a snippet's text names the `gsplat` helpers.
func uses_gsplat(header: str, body: str) -> bool:
    return strings.contains(header, "gsplat.") or strings.contains(body, "gsplat.")