Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.7

0.11.7 / src / edit_kinds.luc

## The Edit node kinds. A kind is registered by two lines here: its node
## kind in `edit_kind_names`, and its module's kind() in edit_kind. The
## framework (the recipe, the viewport and the inspector) finds a node's
## kind here; edit_types.luc has what a kind plugs in.
from edit_types import EditKind
import edit_mesh
import edit_cad
import edit_sdf
import edit_gsplats

## The node kinds of the Edit kinds, in node menu order.
pub func edit_kind_names() -> list[str]:
    return [edit_mesh.kind_name, edit_cad.kind_name, edit_sdf.kind_name, edit_gsplats.kind_name]

## The kind of node kind `name` (built on each call: callers keep it), or
## none when it is not an Edit node.
pub func edit_kind(name: str) -> EditKind?:
    if name == edit_mesh.kind_name:
        return edit_mesh.kind()
    if name == edit_cad.kind_name:
        return edit_cad.kind()
    if name == edit_sdf.kind_name:
        return edit_sdf.kind()
    if name == edit_gsplats.kind_name:
        return edit_gsplats.kind()
    return none

## Edit kinds by node kind, each made once. Making one builds its tool
## registry (every tool's rows), far too slow for each cook, read or pick,
## so a graph and the workspace keep theirs here.
pub class EditKinds:
    let made: map[str, EditKind]

    pub func init(self) -> unit:
        self.made = {}

    ## The Edit kind of node kind `name`, or none when it is not an Edit node.
    pub func of(self, name: str) -> EditKind?:
        if let known = self.made[name]:
            return known
        let kind = edit_kind(name) else return none
        self.made[name] = kind
        return kind

pub func is_edit(name: str) -> bool:
    return name in edit_kind_names()

## Every kind's tools, then every kind's primitives, each name once in
## registry order: the commands the viewport's tool strip offers.
pub func edit_tool_names() -> list[str]:
    let result: list[str] = []
    for name in edit_kind_names():
        let kind = edit_kind(name) else continue
        for tool in kind.tools:
            if not (tool.name in result): result.append(tool.name)
    return result

pub func edit_primitive_names() -> list[str]:
    let result: list[str] = []
    for name in edit_kind_names():
        let kind = edit_kind(name) else continue
        for primitive in kind.primitives:
            if not (primitive in result): result.append(primitive)
    return result

## Component selection follows the enclosing authoring context, including
## plain feature nodes and Groups. Scene/material/volume contexts pick nodes.
pub func context_kind(context: str) -> str:
    if context == "geometry": return edit_mesh.kind_name
    if context == "cad": return edit_cad.kind_name
    if context == "sdf": return edit_sdf.kind_name
    if context == "gsplats": return edit_gsplats.kind_name
    return ""