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