dymokomi/luced-3d
Source of release 0.11.3
## Viewport tools as verb runs: what a tool does to the selection, whichever
## way it lands (a step of the active Edit node, or a new node after the
## displayed one), with its starting numbers; the tool bar (or the node's
## parameters) changes them after.
from luce_geocore.geocore import Verbs
from luce_window.input import Key
## A tool's verb and its parameter values (every slot, defaults filled).
pub class ToolRun:
pub let verb: str
pub let numbers: list[float]
pub func init(self, verb: str, numbers: list[float]):
self.verb = verb
self.numbers = numbers
## The viewport's transform tools (Q, W, E, R, T): Select, Move, Rotate
## and Scale with the gizmo, and the selected node's own handles.
pub func transform_tools() -> list[str]:
return ["Select", "Move", "Rotate", "Scale", "Manipulator"]
## Their keys, Maya's (in transform_tools' order).
pub func transform_keys() -> list[Key]:
return [Key.q, Key.w, Key.e, Key.r, Key.t]
## Their keys' names, as tooltips show them.
pub func transform_key_names() -> list[str]:
return ["Q", "W", "E", "R", "T"]
## Whether `tool` moves, rotates or scales with the gizmo.
pub func gizmo_tool(tool: str) -> bool:
return tool in ["Move", "Rotate", "Scale"]
## The run of viewport tool `tool` (its verb and starting numbers; the
## tool bar changes them after), or none.
pub func tool_run(tool: str) -> ToolRun?:
if tool == "Noise":
return made("Mountain", [(0, 0.5)])
if tool in ["Extrude", "PolyExtrude"]:
return made("PolyExtrude", [(0, 0.5)])
if tool in ["Inset", "Duplicate", "Smooth", "Peak", "Snap", "Fuse"]:
return made(tool, [(0, 0.5)])
if tool in ["Merge Points", "Bridge", "Loop Cut"]:
return made(tool, [])
# A knife cut across the selection: Clip keeping both sides, through
# its centroid, across X.
if tool == "Knife":
return made("Clip", [(0, 0.0), (2, 1.0), (3, 2.0)])
# Connect's new points halfway along their edges; Edge Slide halfway.
if tool in ["Connect", "Edge Slide"]:
return made(tool, [(0, 0.5)])
# PolyMirror and Spin with their defaults (across X through the origin;
# a full turn about Y in 12 steps); PolyDraw makes a face through the
# selected points.
if tool in ["PolyMirror", "Spin", "PolyDraw"]:
return made(tool, [])
if tool == "Crease":
return made("Crease", [(0, 0.5)])
if tool in ["Bevel", "PolyBevel"]:
return made("PolyBevel", [(0, 0.5)])
if tool in ["Reverse", "Triangulate", "Split", "Fill", "Dissolve", "Flatten", "Delete", "Subdivide", "Clean"]:
return made(tool, [])
return none
func made(verb: str, overrides: list[(int, float)]) -> ToolRun:
let numbers = verb_defaults(verb)
for (slot, value) in overrides:
if slot < numbers.length: numbers[slot] = value
return ToolRun(verb, numbers)
## A verb's initial parameter values, in slot order (vectors per component).
pub func verb_defaults(verb: str) -> list[float]:
let index = Verbs.index_of(verb)
let result: list[float] = []
if index < 0: return result
for parm in 0..<Verbs.parm_count(index):
for component in 0..<Verbs.parm_components(index, parm):
result.append(Verbs.parm_initial(index, parm))
return result