OXa^octane_versionf11000013?e-------------------------------------------- -- 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?@ 2 0 1 0 0 1 0 0 0 0 0 0 0 24 0 36 0 0 50 0 0 2.8 0 0 39.597752 0 0 0.80498445 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1e+10 0 0 1 1.118034 0 0 0.89285719 0 0 1 0 0 1 0 0 6 0 0 0 0 0 1 0 0 0 0.5 1 0 0 0 0 1 0 0 1 0.064999998 0 0 0 1 0 0.81199998 0 1 0.18799999 1 1 1 0.64999998 0 0 1 1 0 0 1023 1024 512 0 10000 0 0 0 0 65536 65536 0 3 0.2 0 0 0 0 0 1 0 0 500 0 0 3 5 0 0 2 0 0 2 0 0 4 0 0 9.9999997e-05 0 0 1.2 0 0 3 0 0 1 1 0 10 0 0 0 0 0 1 1 0 0 0.30000001 0 0 0 0 0 0 16 0 0 32 0 0 1 0 0.02 0 0 512 0 0 2 0 0 0 1 0 0 0 8 0 0 0.050000001 0 0 0.5 0.5 0.5 0 1 0 0 0 0 0 1 0 6 0 0 10 0 0 128 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 10 0 0 1 0 0 0 0 0 0 0 0 401 0 1 0 0 0 0 1 10 0 0 20 0 0 0 0 0 1 1 1 10 0 0 10 0 0 0 0 0 0 1 0 0 1 0 0 3 0 0 15 0 0 0.001 0 0 0 0 0 2 0 0 0 36 0 0 50.000004 0 0 1000 0 0 39.597752 0 0 3.6701193 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1e+10 0 0 1 1.118034 0 0 0 0 0 1 0 0 1 0 0 6 0 0 0 0 0 1 0 0 0 1 0.064999998 0 0 0 1 0 0.81199998 0 1 0.18799999 0.2 0.34999999 0.55000001 assets\lookatToTransform.lua 1 The position of the camera. The target position, i.e. the point the camera looks at. The up-vector, i.e. the vector that defines where is up. <?xml version='1.0' encoding='utf-8'?> <storage> <table name="params"><table name="Sphere"><number name="radius">0.5</number> <number name="subdivLevel">0</number> </table> <table name="Plane"><number name="width">10</number> <number name="subdivLevel">2</number> <number name="height">10</number> </table> <table name="Box"><number name="width">1</number> <number name="depth">1</number> <number name="subdivLevel">0</number> <number name="height">1</number> </table> </table> <string name="primitive">Plane</string> </storage> 15 0.32354137 0.57914394 0.73759747 1 0 0.063199997 0 0 0 0 0.5 0 0 0 1.45 0 0 0 0 0 0.2 1.3 0 0 1 0 0 1 0 0 0 1 0 0 8 0 0 0 255 0 0 4096 0 0 1 0 0 1 0 0 1 1 1 1023 0 0 0 0 0 0 4096 0 1 0 0 2 -0 0 0 1 1 1 0 0 0 2 -0 0 0 1 1 1 0 0 0 10 0 0 10 0 0 2 0 0 <?xml version='1.0' encoding='utf-8'?> <storage> <table name="params"><table name="Box"><number name="height">0.1</number> <number name="width">0.1</number> <number name="depth">0.1</number> <number name="subdivLevel">0</number> </table> </table> <string name="primitive">Box</string> </storage> 1 0.16850869 0.41252759 0.7678709 0 1 1 0 1 0 0 0 1 0 0 8 0 0 0 0 0 0 0 4096 0 0 1 0 0 1 0 0 1 1 1 1023 0 0 0 0 0 0 4096 0 1 0 0 2 -0 0 0 1 1 1 0 0 0 2 -0 0 0 1 1 1 0 0 0 0.1 0 0 0.1 0 0 0.1 0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1023 0 0 0 1280 720 0 403 0 0 0 0 65536 65536 0 3 0.2 0 0 0 0 0 1 0 0 5000 0 0 3 5 0 0 2 0 0 2 0 0 4 0 0 9.9999997e-05 0 0 1.2 0 0 3 0 0 1 0 0 10 0 0 0 0 0 1 1 0 0 0.30000001 0 0 0 0 0 0 8 0 0 16 0 0 1 0 0.02 0 0 512 0 0 2 1 0 0 0 1 0 0 8 0 0 0.050000001 0 0 0.5 0.5 0.5 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 10 0 0 0 0 0 128 0 0 0 1 1 0 0 1 0 1 0 0 5 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 3 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0.30000001 0 0 1 1 1 1 0 0 0 0 0 1 0 0 20 0 0 1 0 0 0 0 0 0 0 0 105 0 1 0 0 0 0 1 10 0 0 20 0 0 0 0 0 1 1 1 10 0 0 10 0 0 0 0 0 0 1 0 0 1 0 0 3 0 0 15 0 0 0.001 0 0 0 0 0 2 0 0 3 -1 -1.700842 1.5271701 4.6715484 -0.11601732 0.25175276 -0.0023159729 0 1 0 -1 0.1 0.1 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0 8 0 0 0 0 0 0 0.23649968 0.041355539 0.041355539 100 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 1 1 0 4096 0 0 1 0 0 1 0 0 1 1 1 1023 0 0 0 0 0 0 4096 0 1 0 0 2 -0 0 0 1 1 1 0 0 0 2 -0 0 0 1 1 1 0 0 0 <?xml version='1.0' encoding='utf-8'?> <storage> <table name="params"><table name="Box"><number name="height">1</number> <number name="subdivLevel">0</number> <number name="depth">0.1</number> <number name="width">0.1</number> </table> </table> <string name="primitive">Box</string> </storage> 1 0.69999999 0.69999999 0.69999999 0 1 1 0 1 0 0 0 1 0 0 8 0 0 0 0 0 0 0 4096 0 0 1 0 0 1 0 0 1 1 1 1023 0 0 0 0 0 0 4096 0 1 0 0 2 -0 0 0 1 1 1 0 0 0 2 -0 0 0 1 1 1 0 0.5 0 0.1 0 0 1 0 0 0.1 0 0 0 0 0 To fix the object/light in relation to the camera, use a placement node or transformation *before* the camera transformation is applied. 0.5 0.5 0.5 200 23 -1 -1 2 24.6 180 0 1 1 1 0.5 0 -2 yyfile;CRqq3Se3hS@ii#3e>assets/lookatToTransform.lua#3@> project.ocsZZyyfile;CRqq3Se3hS@ii#3e>assets/lookatToTransform.lua#3@> project.ocsZZ