Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.3

0.11.3 / tests / editor / placing_tests.luc

## Drawing in the viewport: a ray finds the displayed surface under the
## cursor (where a corner lands off the edited mesh's points); Edit Mesh's
## PolyDraw with nothing selected draws corners and records one step; undo
## cancels a drawing.
from workspace import Workspace
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): a ray down hits its top; one beside it misses.
    let w = Workspace()
    node_commands.delete_selected(w)
    node_commands.add_node(w, "Cube", 0.0, 0.0)
    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)
    near(hit.normal.y, 1.0)
    assert(not w.surface_at(Vector3(50.0, 10.0, 0.0), Vector3(0.0, -1.0, 0.0)).found)
    # 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, 3)
    modeling_commands.model(g, "PolyDraw")
    assert(g.placing != none)
    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: surfaces under the cursor, PolyDraw drawn corner by corner, undo cancels")