Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.6

0.11.6 / tests / editor / edit_mesh_draw_tests.luc

## Edit Mesh's PolyMirror, Spin, Crease and PolyDraw tools on a 4 by 4 grid
## over -1..1 (point z*5+x, face z*4+x): each offered on its level only,
## each a step, and each also a node in the catalog.
from workspace import Workspace
from luce_geocore.geocore import Selection
import node_catalog
import modeling_commands
import node_commands
import selection_commands

## The Edit node's last step (the node is looked up again: undo restores
## copies).
func last_verb(w: Workspace) -> str!:
    let node = w.selected() else trap("node")
    return node.edits[-1].verb

func faces(w: Workspace) -> int!:
    return (w.geometry else trap("geometry")).face_count()

## A workspace showing an Edit Mesh on the grid.
func edited_grid() -> Workspace!:
    let w = Workspace()
    node_commands.delete_selected(w)
    node_commands.add_node(w, "Grid", 0.0, 0.0)
    node_commands.add_node(w, "Edit Mesh", 0.0, 100.0)
    return w

pub func edit_mesh_draw_tests() -> unit!:
    for kind in ["PolyMirror", "Spin", "Crease", "PolyDraw"]:
        assert(kind in node_catalog.kinds())
    let w = edited_grid()
    # PolyMirror is a Polygons tool: face 0 mirrored across X, welded.
    selection_commands.set_mode(w, 2)
    assert(not w.tool_available("PolyMirror") and w.tool_available("Spin") and w.tool_available("Crease"))
    selection_commands.set_mode(w, 3)
    selection_commands.choose_component(w, 0, false)
    modeling_commands.model(w, "PolyMirror")
    assert(faces(w) == 17 and w.selected_count() == 1 and last_verb(w) == "PolyMirror")
    w.undo()
    # Spin, on Edges: the edge from point 0 to 1 swept a full turn in 12
    # steps.
    selection_commands.set_mode(w, 2)
    let grid = w.geometry else trap("grid")
    w.selection = Selection.of(grid, "p0-1", 4)
    modeling_commands.model(w, "Spin")
    assert(faces(w) == 16 + 12 and last_verb(w) == "Spin")
    w.undo()
    # Crease, on Edges: its sharpness set on the tool bar after.
    w.selection = Selection.of(w.geometry else trap("grid"), "p0-1", 4)
    modeling_commands.model(w, "Crease")
    modeling_commands.set_last_step(w, 0, 4.0, 0.0, 10.0)
    let creased = w.geometry else trap("creased")
    let crease = creased.find_attribute("crease", 4)
    assert(creased.attribute_value(crease, creased.find_edge(0, 1)) == 4.0 and creased.attribute_value(crease, creased.find_edge(1, 2)) == 0.0)
    w.undo()
    # PolyDraw, on Vertices: a face through four selected points.
    selection_commands.set_mode(w, 1)
    assert(w.tool_available("PolyDraw") and not w.tool_available("PolyMirror"))
    # (Elsewhere, with nothing selected, PolyDraw draws: placing_tests.)
    selection_commands.choose_component(w, 0, false)
    for point in [1, 6, 5]:
        selection_commands.choose_component(w, point, true)
    modeling_commands.model(w, "PolyDraw")
    assert(faces(w) == 17 and last_verb(w) == "PolyDraw" and w.domain() == 2 and w.selected_count() == 1)
    print("PASS Edit Mesh draw tools: PolyMirror on Polygons, Spin and Crease on Edges, PolyDraw on Vertices, each also a node")