Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.1

0.11.1 / tests / copy_node_tests.luc

## Copies have no budget: CopyTransform makes 32 copies of a 4,096-quad
## grid and CopyToPoints puts a sphere on each of a grid's 441 points (both
## once past the old 256-copy / 16,384-point limit), every copy in place.
from network import Network
from luce_std import math

pub func copy_node_tests() -> unit!:
    let graph = Network(false)
    let grid = graph.add("Grid", 0.0, 0.0)
    grid.values[1] = 64.0
    let copies = graph.add("CopyTransform", 0.0, 60.0)
    copies.values[0] = 32.0
    copies.values[1] = 3.0
    copies.values[2] = 0.0
    copies.values[3] = 0.0
    graph.connect(grid.id, copies.id, 0)
    let single = graph.evaluate_data(grid.id).mesh else trap("grid")
    let row = graph.evaluate_data(copies.id).mesh else trap("copies")
    assert(row.face_count() == 32 * single.face_count() and row.point_count() == 32 * single.point_count())
    # Copy k sits k steps along x; the last copy's first point is 31 steps on.
    assert(math.abs(row.point((32 - 1) * single.point_count()).x - single.point(0).x - 31.0 * 3.0) < 0.00001)
    let ball = graph.add("Sphere", 100.0, 0.0)
    ball.values[0] = 0.1
    let targets = graph.add("Grid", 200.0, 0.0)
    targets.values[0] = 20.0
    targets.values[1] = 20.0
    let placed = graph.add("CopyToPoints", 100.0, 60.0)
    graph.connect(ball.id, placed.id, 0)
    graph.connect(targets.id, placed.id, 1)
    let sphere = graph.evaluate_data(ball.id).mesh else trap("sphere")
    let points = graph.evaluate_data(targets.id).mesh else trap("targets")
    assert(points.point_count() == 441)
    let scattered = graph.evaluate_data(placed.id).mesh else trap("placed")
    assert(scattered.face_count() == 441 * sphere.face_count() and scattered.point_count() == 441 * sphere.point_count())
    let last = points.point(440)
    let moved = scattered.point(440 * sphere.point_count())
    let first = sphere.point(0)
    assert(math.abs(moved.x - first.x - last.x) < 0.00001 and math.abs(moved.z - first.z - last.z) < 0.00001)
    print("PASS copies without a budget: 32 grid copies, a sphere on 441 points")