dymokomi/luced-3d
Source of release 0.11.1
0.11.1 / tests / placing_tests.luc
## Placing in the viewport: Edit Sketch's Plane from Face takes a face
## clicked on displayed geometry (its point and normal become the plane
## step); Edit Mesh's PolyDraw with nothing selected draws corners and
## records one step; Esc and undo cancel a placement.
from workspace import Workspace
from luce_geocore.geocore import Sketches
from luce_3d.graphics import Vector3
from luce_std import math
import modeling_commands
import node_commands
import placing_commands
import selection_commands
func near(a: float, b: float):
assert(math.abs(a - b) < 0.00001)
func last_step(w: Workspace) -> list[float]!:
let node = w.selected() else trap("node")
assert(node.edits.length > 0)
return node.edits[-1].numbers
pub func placing_tests() -> unit!:
# A cube (0..2 in Y) into an Edit Sketch; its top face is the plane.
let w = Workspace()
node_commands.delete_selected(w)
node_commands.add_node(w, "Cube", 0.0, 0.0)
node_commands.add_node(w, "Edit Sketch", 0.0, 100.0)
modeling_commands.create(w, "Plane from Face")
let waiting = w.placing else trap("placing")
assert(not waiting.drawing and w.notice != "")
let hit = w.surface_at(Vector3(0.25, 10.0, 0.5), Vector3(0.0, -1.0, 0.0))
assert(hit.found)
near(hit.point.y, 2.0)
placing_commands.place_on_face(w, hit.point, hit.normal)
assert(w.placing == none)
let node = w.selected() else trap("node")
let data = w.network.evaluate_data(node.id)
near(Sketches.plane_origin(data.geometry).y, 2.0)
near(Sketches.plane_origin(data.geometry).x, 0.25)
near(Sketches.plane_normal(data.geometry).y, 1.0)
# A missed click leaves it waiting; Esc cancels.
modeling_commands.create(w, "Plane from Face")
assert(not w.surface_at(Vector3(50.0, 10.0, 0.0), Vector3(0.0, -1.0, 0.0)).found)
w.cancel_placing()
assert(w.placing == none and node.edits.length == 1)
# PolyDraw with nothing selected draws: three corners, one on grid
# point 24 (1, 0, 1), then Enter.
let g = Workspace()
node_commands.delete_selected(g)
node_commands.add_node(g, "Grid", 0.0, 0.0)
node_commands.add_node(g, "Edit Mesh", 0.0, 100.0)
selection_commands.set_mode(g, 1)
modeling_commands.model(g, "PolyDraw")
let drawing = g.placing else trap("drawing")
assert(drawing.drawing)
placing_commands.add_corner(g, Vector3(1.0, 0.0, 1.0))
placing_commands.add_corner(g, Vector3(2.0, 0.0, 1.0))
placing_commands.add_corner(g, Vector3(2.0, 0.0, 0.0))
placing_commands.finish_placing(g)
assert(g.placing == none)
let numbers = last_step(g)
assert(numbers[1] == 3.0 and (g.geometry else trap("drawn")).face_count() == 17 and (g.geometry else trap("drawn")).point_count() == 27)
# Undo while drawing cancels the drawing, not the step before it.
modeling_commands.model(g, "PolyDraw")
placing_commands.add_corner(g, Vector3(0.0, 1.0, 0.0))
g.undo()
assert(g.placing == none and (g.geometry else trap("kept")).face_count() == 17)
print("PASS placing: Plane from Face on a displayed face, PolyDraw drawn corner by corner, Esc and undo cancel")