Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-geocore

Source of release 0.7.2

0.7.2 / src / fields / api.lucb

## Luce's view of fields: the preview surface the viewport draws for a set's
## SDF and level sets (fog grids are ray-marched instead).

pub struct Fields:
    let reserved: u8 = 0

    ## The surface preview of the set's own SDF and level sets (not its
    ## instances'), one mesh; none when it has neither (fog grids have no
    ## surface). Built once per component and kept with it.
    ## `quick` asks for a coarse SDF surface (a drag's frames); a full
    ## request later builds the full one.
    pub static func preview(geometry: interop.Reference[GeometrySet], quick: bool = false) -> interop.Reference[Mesh]?!:
        let set = try geometry.get()
        var first: const Mesh*? = none
        var second: const Mesh*? = none
        if let sdf = set_sdf(set): first = try sdf_preview(sdf, quick)
        if let volume = set_volume(set): second = try volume_preview(volume)
        if first == none:
            let b = second else return none
            return try mesh_adopt(try mesh_share(b))
        let a = first else return none
        let b = second else return try mesh_adopt(try mesh_share(a))
        let parts: MeshPart[2] = [MeshPart(a, Matrix4()), MeshPart(b, Matrix4())]
        return try concatenated(parts)

    ## Whether the set has an SDF or a volume of its own.
    pub static func present(geometry: interop.Reference[GeometrySet]) -> bool!:
        let set = try geometry.get()
        return set_sdf(set) != none or set_volume(set) != none