dymokomi/luced-3d
Source of release 0.11.1
0.11.1 / src / place_prompt.luc
## Placing on surfaces in the viewport: a create entry waiting for a face
## (Edit Sketch's Plane from Face), or a drawing tool collecting corners
## (Edit Mesh's PolyDraw). The viewport turns clicks into world points
## (snapped to the edited mesh's points, else on the surface under the
## cursor, else on the ground; luce-3d SurfaceHits) and the workspace turns
## the finished placement into one recipe step.
from luce_3d.graphics import Vector3
from edit_operations import EditStep
pub class PlacePrompt:
## The create entry or tool.
pub let name: str
## Drawing corners (else waiting for one face).
pub let drawing: bool
pub var corners: list[Vector3]
## Where the cursor would place the next corner (the rubber band's end).
pub var cursor: Vector3? = none
pub func init(self, name: str, drawing: bool):
self.name = name
self.drawing = drawing
self.corners = []
## What the viewport's notice line says while placing.
pub func hint(self) -> str:
if not self.drawing:
return f"{self.name}: click a face; Esc cancels"
return f"{self.name}: click to place corners (points snap), Enter or the first corner finishes, Esc cancels"
## `step` (a face primitive's default step) with the picked face's point
## and normal as its first six numbers.
pub func placed_on_face(step: EditStep, point: Vector3, normal: Vector3) -> EditStep:
let numbers = step.numbers.copy()
let face = [point.x, point.y, point.z, normal.x, normal.y, normal.z]
for at in 0..<6:
if at < numbers.length:
numbers[at] = face[at]
else:
numbers.append(face[at])
return step.with_numbers(numbers)