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
Scripted node graph to extract camera position
Thomas made one for me. I can look for it and post it here once I locate it...
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...
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
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
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
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
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
- prehabitat
- Posts: 495
- Joined: Fri Aug 16, 2013 10:30 am
- Location: Victoria, Australia
Did Thomas' script ever turn up?
Win10/3770/16gb/K600(display)/GTX780(Octane)/GTX590/372.70
Octane 3.x: GH Lands VARQ Rhino5 -Rhino.io- C4D R16 / Revit17
Octane 3.x: GH Lands VARQ Rhino5 -Rhino.io- C4D R16 / Revit17
- stratified
- Posts: 945
- Joined: Wed Aug 15, 2012 6:32 am
- Location: Auckland, New Zealand
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
cheers,
Thomas
- prehabitat
- Posts: 495
- Joined: Fri Aug 16, 2013 10:30 am
- Location: Victoria, Australia
Cheers 

Win10/3770/16gb/K600(display)/GTX780(Octane)/GTX590/372.70
Octane 3.x: GH Lands VARQ Rhino5 -Rhino.io- C4D R16 / Revit17
Octane 3.x: GH Lands VARQ Rhino5 -Rhino.io- C4D R16 / Revit17