dymokomi/luced-3d
Source of release 0.11.1
0.11.1 / src / placing_commands.luc
## Placing on surfaces (place_prompt.luc): a face primitive waits for a
## picked face to sit on, and a drawing tool collects corners in the
## viewport until Enter makes them one step of the displayed Edit node.
from luce_3d.graphics import Vector3
from workspace import Workspace
from place_prompt import PlacePrompt, placed_on_face
## Wait for the face primitive or drawing tool `name` to be placed.
pub func start_placing(w: Workspace, name: str, drawing: bool) -> unit!:
let placing = PlacePrompt(name, drawing)
w.placing = placing
w.notice = placing.hint()
w.revision += 1
## A face was picked for the waiting face primitive: its step, with the
## face's point and normal, goes on the recipe.
pub func place_on_face(w: Workspace, point: Vector3, normal: Vector3) -> unit!:
let placing = w.placing else return
let kind = w.active_kind() else return w.cancel_placing()
let node = w.selected() else return w.cancel_placing()
let step = kind.create(placing.name) else return w.cancel_placing()
w.placing = none
w.notice = ""
w.perform("Create " + placing.name, func () -> unit!:
node.edits.append(placed_on_face(step, point, normal))
w.network.invalidate(node.id)
w.adopt_output = true
w.pending_level = 0
w.rebuild())
## One more drawn corner.
pub func add_corner(w: Workspace, point: Vector3) -> unit!:
let placing = w.placing else return
placing.corners.append(point)
w.revision += 1
## Enter (or the first corner again): the drawing becomes one step.
pub func finish_placing(w: Workspace) -> unit!:
let placing = w.placing else return
let kind = w.active_kind() else return w.cancel_placing()
let node = w.selected() else return w.cancel_placing()
let draw = kind.drawn else return w.cancel_placing()
w.placing = none
w.notice = ""
w.revision += 1
let made = draw(placing.name, placing.corners)
let step = made else return
w.perform(placing.name, func () -> unit!:
node.edits.append(step)
w.network.invalidate(node.id)
w.adopt_output = true
w.rebuild())