dymokomi/luced-3d
Source of release 0.11.4
0.11.4 / src / take_commands.luc
## Commands on takes (takes.luc), each one undo step through
## Workspace.perform: switching, adding, removing and renaming takes, and the
## active take's camera and lights.
from workspace import Workspace
import takes
pub func switch_take(w: Workspace, index: int) -> unit!:
if index == w.network.take:
return
w.perform("Switch take", func () -> unit!:
takes.switch_to(w.network, index)
w.rebuild())
pub func add_take(w: Workspace) -> unit!:
w.perform("New take", func () -> unit!:
takes.add_take(w.network))
pub func remove_take(w: Workspace) -> unit!:
if w.network.take == 0:
return
w.perform("Delete take", func () -> unit!:
takes.remove_take(w.network, w.network.take)
w.rebuild())
pub func rename_take(w: Workspace, name: str) -> unit!:
let trimmed = name.trim()
let active = w.network.takes[w.network.take]
if trimmed == "" or trimmed == active.name:
return
w.perform("Rename take", func () -> unit!:
active.name = trimmed)
## Every Render node looks through the camera at `path` ("" the first).
pub func set_camera(w: Workspace, path: str) -> unit!:
w.perform("Change take camera", func () -> unit!:
for node in takes.scene_nodes(w.network, "Render"):
node.texts[0] = path
w.network.invalidate(node.id)
w.rebuild())
## Turn Light node `id` on or off (its bypass).
pub func toggle_light(w: Workspace, id: int) -> unit!:
w.perform("Toggle light", func () -> unit!:
let node = w.network.require(id)
node.enabled = not node.enabled
w.network.invalidate(id)
w.rebuild())
## Show or hide node `id`.
pub func toggle_visible(w: Workspace, id: int) -> unit!:
w.perform("Toggle visibility", func () -> unit!:
let node = w.network.require(id)
node.visible = not node.visible
w.network.visibility_changed(node)
w.rebuild())
## Show or hide the object at `path` in node `id`'s result.
pub func toggle_path(w: Workspace, id: int, path: str) -> unit!:
w.perform("Toggle object visibility", func () -> unit!:
let node = w.network.require(id)
if let at = node.hidden.index_of(path):
_ = node.hidden.remove_at(at)
else:
node.hidden.append(path)
w.network.invalidate(id)
w.rebuild())