dymokomi/luced-3d
Source of release 0.11.6
0.11.6 / tests / editor / take_tests.luc
## Takes: a take records visibility (of nodes and of objects inside their
## results), transforms, which lights are on and the Render camera; switching swaps them in and out of the nodes, undoes, and projects
## keep every take.
from workspace import Workspace
from network import Network
from luce_prism.prism import Document
from project_graph import write_graph, read_graph
import take_commands
import takes
import node_paths
import scene_nodes
from outliner import object_rows
## The Render node's scene: its lights and the camera it renders through.
func rendered(graph: Network, id: int) -> (int, str)!:
let scene = graph.evaluate_data(id).geometry.scene()
let wanted = graph.render_camera(graph.require(id))
var lights = 0
var camera = ""
for index in 0..<scene.count():
if not scene.is_camera(index):
lights += 1
elif camera == "" and (wanted == "" or scene.path(index) == wanted):
camera = scene.path(index)
return (lights, camera)
## Camera node `id`'s camera's path in the scene.
func scene_path(graph: Network, id: int) -> str!:
return scene_nodes.camera_path(id, graph.require(id).texts)
pub func take_tests() -> unit!:
let w = Workspace()
let graph = w.network
# At the root, objects none wired: the Geo, two Cameras, a key and a
# fill Light, a rim Light, and a Render node (it renders the root's
# flagged objects).
graph.scope = -1
let chain: list[int] = []
for kind in ["Camera", "Camera", "Light", "Light"]:
chain.append(graph.add(kind, 0.0, 0.0).id)
let rim = graph.add("Light", 300.0, 0.0).id
let render = graph.add("Render", 0.0, 300.0).id
graph.selected = render
graph.display = render
let (first_camera, second_camera, key, fill) = (chain[0], chain[1], chain[2], chain[3])
let second_path = scene_path(graph, second_camera)
assert(graph.takes.length == 1 and graph.takes[0].name == "Main")
assert(rendered(graph, render) == (3, scene_path(graph, first_camera)))
# A take of its own: the fill off, the second camera, the rim hidden.
take_commands.add_take(w)
assert(w.network.takes.length == 2 and w.network.take == 1 and w.network.takes[1].name == "Take 1")
take_commands.toggle_light(w, fill)
take_commands.set_camera(w, second_camera)
take_commands.toggle_visible(w, rim)
take_commands.rename_take(w, "Close-up")
assert(rendered(w.network, render) == (1, second_path) and not w.network.require(rim).visible)
# The key light's object hidden in the key's result: no light renders;
# the outliner still lists it, hidden.
let key_path = f"light{key}"
take_commands.toggle_path(w, key, key_path)
assert(rendered(w.network, render) == (0, second_path))
var listed = false
for row in object_rows(w.network, [], []):
if row.id == key and row.path == key_path:
listed = row.hidden and not row.visible
assert(listed)
# The first camera moved.
w.perform("Move camera", func () -> unit!:
w.network.require(first_camera).values[2] = 7.5
w.network.invalidate(first_camera))
# Main as it was; the take's state again on the way back.
take_commands.switch_take(w, 0)
assert(rendered(w.network, render) == (3, scene_path(w.network, first_camera)))
assert(w.network.require(fill).enabled and w.network.require(rim).visible)
assert(w.network.require(first_camera).values[2] != 7.5 and w.network.require(key).hidden.length == 0)
take_commands.switch_take(w, 1)
assert(rendered(w.network, render) == (0, second_path) and not w.network.require(rim).visible)
assert(w.network.require(first_camera).values[2] == 7.5)
w.undo()
assert(w.network.take == 0 and w.network.require(fill).enabled)
w.redo()
assert(w.network.take == 1 and not w.network.require(fill).enabled)
# Projects keep every take, the active one as its nodes hold it.
let doc = Document()
write_graph(doc, w.network)
let opened = read_graph(doc)
assert(opened.take == 1 and takes.names(opened) == ["Main", "Close-up"])
assert(not opened.require(fill).enabled and opened.require(render).texts[0] == node_paths.absolute(opened.nodes, opened.require(second_camera)))
assert(opened.require(key).hidden == [key_path] and opened.require(first_camera).values[2] == 7.5)
takes.switch_to(opened, 0)
assert(opened.require(fill).enabled and opened.require(render).texts[0] == "" and opened.require(rim).visible)
assert(opened.require(key).hidden.length == 0 and opened.require(first_camera).values[2] != 7.5)
# Deleting the active take returns to Main; Main stays.
take_commands.remove_take(w)
assert(w.network.takes.length == 1 and w.network.take == 0 and w.network.require(fill).enabled)
take_commands.remove_take(w)
assert(w.network.takes.length == 1)
print("PASS takes: visibility of nodes and objects, transforms, lights and camera per take, switching, undo, projects, deleting")