-------------------------------------------- -- Lookat (position, target, up) to Transform. -- @author OTOY -- @version 0.1 -- @script-id fa54a91a-22be-4ba7-9075-5a5d232c3e34 -------------------------------------------- local inputLinkers = {} local outputLinkers = {} local nodeOutputValue = nil local function setInputLinkers(graph) local liPosition = { key = "pos", label = "Position", description = "The position of the camera.", type = octane.pinType.PT_FLOAT, defaultNodeType = octane.nodeType.NT_FLOAT, defaultValue = {0, 0.5, 1.0}, } local liTarget = { key = "target", label = "Target", description = "The target position, i.e. the point the camera looks at.", type = octane.pinType.PT_FLOAT, defaultNodeType = octane.nodeType.NT_FLOAT, defaultValue = {0, 0, 0}, } local liUp = { key = "up", label = "Up-vector", description = "The up-vector, i.e. the vector that defines where is up.", type = octane.pinType.PT_FLOAT, defaultNodeType = octane.nodeType.NT_FLOAT, defaultValue = {0, 1, 0}, } local linkersInfo = { liPosition, liTarget, liUp } local inputs = graph:setInputLinkers(linkersInfo) for i, info in ipairs(linkersInfo) do inputLinkers[info.key] = inputs[i] end end local function setOutputLinkers(graph) local liOutput = { key = "outputValue", label = "Output value", type = octane.pinType.PT_TRANSFORM, defaultValue = octane.matrix.getIdentity() } local linkersInfo = { liOutput } local outputs = graph:setOutputLinkers(linkersInfo) for i, info in ipairs(linkersInfo) do outputLinkers[info.key] = outputs[i] end end local function update(script) local pos = script:getInputValue(inputLinkers.pos) local target = script:getInputValue(inputLinkers.target) local up = script:getInputValue(inputLinkers.up) local zaxis = octane.vec.normalized(octane.vec.sub(pos, target)) local xaxis = octane.vec.normalized(octane.vec.cross(up, zaxis)) local yaxis = octane.vec.cross(zaxis, xaxis) local m = { {xaxis[1], yaxis[1], zaxis[1], pos[1]}, {xaxis[2], yaxis[2], zaxis[2], pos[2]}, {xaxis[3], yaxis[3], zaxis[3], pos[3]}, } nodeOutputValue:setAttribute(octane.attributeId.A_TRANSFORM, m) end local function prepareGraph(graph) nodeOutputValue = octane.node.create { type = octane.nodeType.NT_TRANSFORM_VALUE, name = "Value", graphOwner = graph } outputLinkers.outputValue:connectTo(octane.pinId.P_INPUT, nodeOutputValue) end -------------------------------------------- local node = {} node._name = "Lookat to Transform" node._icon = octane.image.fromBase64("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz".. "AAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAK/SURB".. "VDiNbVNbSNNxFP7O9p/zgrepBaXT0mjijLRh+lAokmENb8PRSxhoUE891GPDEnrUlAgD6aFwblIo".. "IT5kF3uypL+zUnFp/vE6+nsZ023e9fTSZK5+cB5+h/Od853vnEPMDAAgIm1auu7Fzs6WPD8jXUPI".. "I6IqAFkh7jH8TaAtNVaMeNZ8XG4yjzEzQg2Axe12s9/vZ7/fz263mwFYBCLSlhorejttHXppYRkr".. "Hp86Ni6hY23VPQrgJ4BBZp4H8EWj0fSLolgUTEE4X3Cxw26z6qWFZXx3zsFubU8nQvqvadfu5JS0".. "3tP92kVELSaTqaK5ublIluVDPQj7zBgQx7G4ugUA6BsYw/4eQ0EskCo6xnz9Zsz4yNenNptNIUkS".. "AMBgMBwwIQBanT6n+/bdh7lx8Qloe/JI2thY96ak6mJTMvRJb189ixr94YAkSfD5fDAYDC8BtAPI".. "PySiTp8z1NTWxTp9zhCASABnS0ouT25vb7PT6WRRFDkuPnEXwK1D4gaprE1L1/Uf156wMzOqq6t7".. "DoETjvKDlk6+UFw+BiD5nwTBFgoG6FvdvUa/5bGd79xvWgFgCsQqQhfGbDb3WK1WY1DPzwG+8Xtu".. "YlklqJB05FgUgNOBeAURVRGRhYjO/Q/MzHUAJlwzEx61OgzxmkR1TKxGfzBGAFmLi4sNtbW1pVar".. "tSAUnJx60q7T55yKiIqMjohQIyxMwBlDfl5mdu6Qd80zSQAsHo+nwev1wuVyQalUBlfGiYzM/r53".. "HwoFVRg+Do5DUCpQmKfD9tYWSi4VfzrQQJblALgXQGvAPz3lrCkrMzp63n+GSlCCiPCmbwBlZUbH".. "9JSzRgEAe3t7ByKKongVwJXAn5lnnaPDla2N9Y6VJRkrSzJaG+sdztHhSmaeJQBV4eHh2Zubm/vB".. "Z8rMXcHTCZx7gBUzzwLAH61qoROxh1pDAAAAAElFTkSuQmCC", 3) node.evaluateAllChanges = true -- Callback called after initializing the scripted graph with the code. function node.onInit(self, graph) graph:setAttribute(octane.attributeId.A_COLOR, { 0.20, 0.35, 0.55 }, true) setInputLinkers(graph) setOutputLinkers(graph) prepareGraph(graph) update(self) octane.nodegraph.unfold(graph, true) end -- Callback called when the connected value of one of the input linker nodes changes. function node.onEvaluate(self, graph) update(self) end return node