dymokomi/luced-3d
Source of release 0.11.1
0.11.1 / tests / edit_engine_tests.luc
## The Edit node as a modeling engine: tools append verb steps with the
## node's symmetry, soft radius and Keep selection; each tool is one undo;
## the output selection (or the kept one) carries on to the next tool.
from workspace import Workspace
from luce_3d.graphics import Vector3, EditOverlay
from luce_std import math
import modeling_commands
import node_commands
import selection_commands
## Steps of the selected Edit node (undo replaces node objects).
func steps(w: Workspace) -> int!:
return (w.selected() else trap("Edit Mesh")).edits.length
func near(a: float, b: float):
assert(math.abs(a - b) < 0.00001)
pub func edit_engine_tests() -> unit!:
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)
assert(w.editing())
# Symmetry across X: moving a point moves its mirror.
node_commands.set_parameter(w, 3, 1.0)
selection_commands.set_mode(w, 3)
selection_commands.choose_component(w, 0, false)
modeling_commands.move_selection(w, Vector3(0.0, 0.5, 0.0))
let mesh = w.geometry else trap("mesh")
near(mesh.point(0).y, 0.5)
near(mesh.point(4).y, 0.5)
near(mesh.point(2).y, 0.0)
assert(steps(w) == 1 and (w.selected() else trap("Edit Mesh")).edits[0].symmetry == 1)
w.undo()
near((w.geometry else trap("undo")).point(4).y, 0.0)
# Soft selection: neighbours follow, less the farther they are.
node_commands.set_parameter(w, 3, 0.0)
node_commands.set_parameter(w, 1, 0.8)
selection_commands.choose_component(w, 12, false)
modeling_commands.move_selection(w, Vector3(0.0, 1.0, 0.0))
let soft = w.geometry else trap("soft")
near(soft.point(12).y, 1.0)
assert(soft.point(7).y > 0.0 and soft.point(7).y < 1.0 and soft.point(0).y == 0.0)
# The viewport tints the reach: the radius, Smooth falloff, no symmetry.
# On the moved mesh point 12 is 1 up, so its neighbours are 1.12 away:
# a 1.5 radius reaches them, not the corner.
assert(w.soft_selection() == [0.8, 3.0, 0.0])
let overlay = EditOverlay()
overlay.set_soft(1.5, 3, 0)
overlay.show(soft, 0, w.selection, -1)
assert(overlay.soft_weight(12) == 1.0 and overlay.soft_weight(7) > 0.0 and overlay.soft_weight(0) == 0.0)
node_commands.set_parameter(w, 1, 0.0)
assert(w.soft_selection()[0] == 0.0)
# Topology tools hand their output selection on: extrude, then inset the
# front face.
selection_commands.set_mode(w, 1)
selection_commands.choose_component(w, 5, false)
node_commands.set_parameter(w, 0, 0.4)
modeling_commands.extrude(w)
assert(w.selected_ids() == [5])
let before = steps(w)
modeling_commands.model(w, "Inset")
assert(steps(w) == before + 1 and w.selected_ids() == [5])
# Keep selection carries the selection through instead (the walls of an
# extruded face descend from it, so they stay selected too).
node_commands.set_parameter(w, 4, 1.0)
selection_commands.choose_component(w, 0, false)
modeling_commands.extrude(w)
assert(w.selected_ids().length == 5 and 0 in w.selected_ids())
# Each tool is one undo step, and the recipe is the truth.
w.undo()
w.undo()
assert(steps(w) == before + 1)
print("PASS Edit engine: verb steps with symmetry, soft falloff, output and kept selections, one undo per tool")