Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.9

0.11.9 / src / combine_target.luc

## Combine's target lit while its tool bodies are picked, as Fusion shows
## the Target Body chosen while the Tool Bodies field waits: the target's
## edges drawn thick in the sketch blue over the body picked on. For the
## Combine node and Edit CAD's Combine step alike (tool_picks.luc).
from luce_gpu.gpu import RenderTarget
from luce_geocore.geocore import Mesh
from workspace import Workspace
from overlay_lines import OverlayLines
import cad_names
import cad_picks
import theme

pub class CombineTarget:
    let w: Workspace
    ## The target's edges, and what they were gathered for.
    var lines: OverlayLines? = none
    var made_for: str = ""

    pub func init(self, w: Workspace):
        self.w = w

    ## The target model on the pick geometry shown (-1: no Combine waits).
    func target(self, mesh: Mesh) -> int!:
        let prompt = self.w.prompt else return -1
        if prompt.tool != "Combine" or prompt.pick != 1:
            return -1
        let node = self.w.network.find(prompt.node) else return -1
        if not prompt.step:
            let name = node.texts[0].trim()
            return cad_names.model_named(mesh, name) if name != "" else 0
        if node.edits.length > 0:
            # The step keeps its target as a body (cad_picks.luc).
            let group = cad_picks.group_on(mesh, node.edits[-1].group) catch failure:
                recover "!*"
            return cad_names.group_model(mesh, group)
        return -1

    pub func draw(self, target: RenderTarget) -> unit!:
        let mesh = self.w.geometry else return
        let model = self.target(mesh)
        if model < 0:
            return
        let key = f"{self.w.revision}|{model}"
        if key != self.made_for or self.lines == none:
            let made = OverlayLines.make()
            made.add_edges_where(mesh, "cad_edge_model", model)
            self.lines = made
            self.made_for = key
        if let lines = self.lines:
            lines.draw(self.w.view.camera, target, theme.sketch_free(), 3.0)