Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.9

0.11.9 / src / view_grid.luc

## A sketch plane's grid, built in Base (OverlayLines.add_grid), at the
## snapping step (snapping.grid_step) round where the camera looks, a
## brighter line every fifth (the ground's is luce-3d's GroundGrid, drawn
## to the horizon in view.luc). It is depth
## tested but writes no depth: a mesh in front hides it, and Gaussian
## splats and fog, which are drawn after it and write no depth either,
## cover it where they are dense, as they cover anything behind them.
## The lines are made and sent again only when the grid moves (its center,
## plane or step); a frame draws them from the GPU.
from luce_gpu.gpu import RenderTarget, Color
from luce_3d.graphics import Camera, Vector3
from overlay_lines import OverlayLines

pub class GridLines:
    var key: str = ""
    var fine: OverlayLines? = none
    var bold: OverlayLines? = none

    ## A grid on the plane through `center` spanned by unit axes `u` and `v`:
    ## 60 cells of `step` across in `minor`, every fifth line in `major`.
    pub func draw(self, camera: Camera, target: RenderTarget, center: Vector3, u: Vector3, v: Vector3, step: float, minor: Color, major: Color) -> unit!:
        let key = f"{center.x} {center.y} {center.z} {u.x} {u.y} {u.z} {v.x} {v.y} {v.z} {step}"
        if key != self.key:
            let fine = OverlayLines.make()
            fine.add_grid(center, u, v, step * 30.0, 60)
            let bold = OverlayLines.make()
            bold.add_grid(center, u, v, step * 30.0, 12)
            self.fine = fine
            self.bold = bold
            self.key = key
        if let fine = self.fine:
            fine.batch().draw(camera, target, minor, writes_depth = false)
        if let bold = self.bold:
            bold.batch().draw(camera, target, major, writes_depth = false)