Page 1 of 2
Scripted node graph to extract camera position
Posted: Sun Aug 23, 2015 3:24 am
by manalokos
Hello
I've been trying to make a scripted node graph to extract camera position and target position or other values as outputs.
This way I can connect an alembic camera to this scripted operator and connect the output nodes to a new camera where I can control the aperture.
But as I have no experience in programming in LUA for octane, I was only able to create an input and output for the nodes, but the connections I wasn't able to make.
Could someone show me how to do this?
Thanks
Kind regards
Filipe
Re: Scripted node graph to extract camera position
Posted: Sun Aug 23, 2015 5:15 am
by Goldorak
Thomas made one for me. I can look for it and post it here once I locate it...
Re: Scripted node graph to extract camera position
Posted: Sun Aug 23, 2015 5:28 pm
by manalokos
Thanks Goldorak
Meanwhile I'll keep trying.
Re: Scripted node graph to extract camera position
Posted: Sun Aug 23, 2015 8:36 pm
by manalokos
I spent the whole afternoon trying to make this work, finally I was able to get the results I was expecting...
The output shoud be a camera node but meanwhile I can connect the position, target, and focus distance to a secondary camera...
It has 2 inputs, one for the alembic camera, and another for another alembic camera to work as a focus point. It would be great if alembic import would get position of nulls into float output...
Code: Select all
local Aextract = {}
local inputs, tex
-- onInit function, this is called once in the beginning.
function Aextract.onInit(self, graph)
-- input and output infos
local inputInfos = {
{type=octane.PT_CAMERA, label="camara", defaultNodeType=octane.NT_IN_CAMERA},
{type=octane.PT_CAMERA, label="foco", defaultNodeType=octane.NT_IN_CAMERA}
}
local outputInfos = {
{type=octane.PT_FLOAT, label="pos"},
{type=octane.PT_FLOAT, label="target"},
{type=octane.PT_FLOAT, label="focusdistance"}
}
-- use these functions to set up input and output linkers. This will keep
-- existing linkers so existing connections in the parent graph are kept.
inputs = graph:setInputLinkers(inputInfos)
local outputs = graph:setOutputLinkers(outputInfos)
-- set up a node to give the graph some output value
posnode = octane.node.create{ type=octane.NT_FLOAT, name="posicaocamara", graphOwner=graph }
targetnode = octane.node.create{ type=octane.NT_FLOAT, name="posicaotarget", graphOwner=graph }
targetvector = octane.node.create{ type=octane.NT_FLOAT, name="pontodefoco", graphOwner=graph }
focusdistance = octane.node.create{ type=octane.NT_FLOAT, name="distanciadefoco", graphOwner=graph }
outputs[1]:connectTo("input", posnode)
outputs[2]:connectTo("input", targetnode)
outputs[3]:connectTo("input", focusdistance)
self:setEvaluateTimeChanges(true)
end
function Aextract.onEvaluate(self, graph)
local camara = inputs[1]:getInputNode("input")
local posicao = camara:getPinValue("pos")
local foco = inputs[2]:getInputNode("input")
local target = foco:getPinValue("pos")
print(posicao[1], posicao[2], posicao[3])
posnode:setAttribute("value", posicao)
targetnode:setAttribute("value", target)
targetvector:setAttribute("value", {target[1]-posicao[1], target[2]-posicao[2], target[3]-posicao[3]})
focusdistance:setAttribute("value",{ math.sqrt(math.pow((target[1]-posicao[1]),2)+math.pow((target[2]-posicao[2]),2)+math.pow((target[3]-posicao[3]),2)),0,0})
print(math.sqrt(math.pow((target[1]-posicao[1]),2)+math.pow((target[2]-posicao[2]),2)+math.pow((target[3]-posicao[3]),2)))
return true
end
return Aextract
Re: Scripted node graph to extract camera position
Posted: Mon Aug 24, 2015 9:18 am
by bepeg4d
Hi,
here is my attempt but with just one input abc node:
It takes the focal distance from the abc node and I had to add also the focal length for correctly matching between the two cameras.
It should work also with animated camera

ciao beppe
Code: Select all
local ABC2ThinScript = {}
local mInput
local mOutputF
local mOutputD
local mOutputP
local mOutputT
function ABC2ThinScript.onInit(self, graph)
-- create input linkers
local inputs = graph:setInputLinkers
{
{
type = octane.PT_CAMERA,
label = "ABCcam",
fromNodeType = octane.NT_OUT_CAMERA,
fromPinId = octane.P_INPUT
}
}
mInput = inputs[1]
-- create output linkers
local outputs = graph:setOutputLinkers
{
{
type = octane.PT_FLOAT,
label = "ABCfocal_length"
},
{
type = octane.PT_FLOAT,
label = "ABCfocal_depth"
},
{
type = octane.PT_FLOAT,
label = "ABCposition"
},
{
type = octane.PT_FLOAT,
label = "ABCtarget"
},
}
-- create float value node that will provide the ABC Camera value
mOutputF = octane.node.create
{
type = octane.NT_FLOAT,
name = outputs[1].name,
pinOwnerNode = outputs[1],
pinOwnerIx = 1
}
mOutputD = octane.node.create
{
type = octane.NT_FLOAT,
name = outputs[2].name,
pinOwnerNode = outputs[2],
pinOwnerIx = 1
}
mOutputP = octane.node.create
{
type = octane.NT_FLOAT,
name = outputs[3].name,
pinOwnerNode = outputs[3],
pinOwnerIx = 1
}
mOutputT = octane.node.create
{
type = octane.NT_FLOAT,
name = outputs[4].name,
pinOwnerNode = outputs[4],
pinOwnerIx = 1
}
end
function ABC2ThinScript.onEvaluate(self, graph)
local inCam = mInput:getConnectedNode(octane.P_INPUT)
if inCam == nil then
local inABC = nil
local inFov = nil
local inDpt = nil
local inPos = nil
local inTarg = nil
elseif inCam ~= nil then
local inABC = inCam:getConnectedNode(octane.P_INPUT)
local inFov = inABC:getPinValue(octane.P_FOCAL_LENGTH)
local inDpt = inABC:getPinValue(octane.P_FOCAL_DEPTH)
local inPos = inABC:getPinValue(octane.P_POSITION)
local inTarg = inABC:getPinValue(octane.P_TARGET)
mOutputF:setAttribute(octane.A_VALUE, inFov)
mOutputD:setAttribute(octane.A_VALUE, inDpt)
mOutputP:setAttribute(octane.A_VALUE, inPos)
mOutputT:setAttribute(octane.A_VALUE, inTarg)
ABC2ThinScript:setEvaluateTimeChanges(true)
end
end
return ABC2ThinScript
Re: Scripted node graph to extract camera position
Posted: Mon Aug 24, 2015 10:14 am
by manalokos
Wow, so much different way to write the code...
There are so few examples of Lua scripted graphs that is difficult to learn.
This is good, but the software I use won't export the focus distance so I had to make the double camera hack.
Re: Scripted node graph to extract camera position
Posted: Mon Aug 24, 2015 12:37 pm
by bepeg4d
hi,
this is my second scripted graph and probably my approach is not the best, better to wait for the Thomas' example for a correct reference

ciao beppe
Re: Scripted node graph to extract camera position
Posted: Wed Dec 09, 2015 2:57 am
by prehabitat
Did Thomas' script ever turn up?
Re: Scripted node graph to extract camera position
Posted: Wed Dec 09, 2015 3:13 am
by stratified
I think it's this one. If you want to inspect/modify the script you need to enable "Scripted graph development" in the application preferences.
cheers,
Thomas
Re: Scripted node graph to extract camera position
Posted: Thu Dec 10, 2015 6:43 am
by prehabitat
Cheers
