Scripted node graph to extract camera position

Forums: Scripted node graph to extract camera position
Forum for OctaneRender Lua scripting examples, discussion and support.

Scripted node graph to extract camera position

Postby manalokos » Sun Aug 23, 2015 3:24 am

manalokos Sun Aug 23, 2015 3:24 am
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
manalokos
Licensed Customer
Licensed Customer
 
Posts: 438
Joined: Fri Nov 18, 2011 4:43 pm

Re: Scripted node graph to extract camera position

Postby Goldorak » Sun Aug 23, 2015 5:15 am

Goldorak Sun Aug 23, 2015 5:15 am
Thomas made one for me. I can look for it and post it here once I locate it...
User avatar
Goldorak
OctaneRender Team
OctaneRender Team
 
Posts: 2321
Joined: Sun Apr 22, 2012 8:09 pm

Re: Scripted node graph to extract camera position

Postby manalokos » Sun Aug 23, 2015 5:28 pm

manalokos Sun Aug 23, 2015 5:28 pm
Thanks Goldorak

Meanwhile I'll keep trying.
manalokos
Licensed Customer
Licensed Customer
 
Posts: 438
Joined: Fri Nov 18, 2011 4:43 pm

Re: Scripted node graph to extract camera position

Postby manalokos » Sun Aug 23, 2015 8:36 pm

manalokos Sun Aug 23, 2015 8:36 pm
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
manalokos
Licensed Customer
Licensed Customer
 
Posts: 438
Joined: Fri Nov 18, 2011 4:43 pm

Re: Scripted node graph to extract camera position

Postby bepeg4d » Mon Aug 24, 2015 9:18 am

bepeg4d Mon Aug 24, 2015 9:18 am
Hi,
here is my attempt but with just one input abc node:
FromABC2Thin.orbx
(4.21 KiB) Downloaded 1251 times

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
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 9940
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: Scripted node graph to extract camera position

Postby manalokos » Mon Aug 24, 2015 10:14 am

manalokos Mon Aug 24, 2015 10:14 am
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.
manalokos
Licensed Customer
Licensed Customer
 
Posts: 438
Joined: Fri Nov 18, 2011 4:43 pm

Re: Scripted node graph to extract camera position

Postby bepeg4d » Mon Aug 24, 2015 12:37 pm

bepeg4d Mon Aug 24, 2015 12:37 pm
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
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 9940
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: Scripted node graph to extract camera position

Postby prehabitat » Wed Dec 09, 2015 2:57 am

prehabitat Wed Dec 09, 2015 2:57 am
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
prehabitat
Licensed Customer
Licensed Customer
 
Posts: 495
Joined: Fri Aug 16, 2013 10:30 am
Location: Victoria, Australia

Re: Scripted node graph to extract camera position

Postby stratified » Wed Dec 09, 2015 3:13 am

stratified Wed Dec 09, 2015 3:13 am
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.

camera-explode.orbx
(100.3 KiB) Downloaded 1220 times


cheers,
Thomas
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Scripted node graph to extract camera position

Postby prehabitat » Thu Dec 10, 2015 6:43 am

prehabitat Thu Dec 10, 2015 6:43 am
Cheers :D
Win10/3770/16gb/K600(display)/GTX780(Octane)/GTX590/372.70
Octane 3.x: GH Lands VARQ Rhino5 -Rhino.io- C4D R16 / Revit17
prehabitat
Licensed Customer
Licensed Customer
 
Posts: 495
Joined: Fri Aug 16, 2013 10:30 am
Location: Victoria, Australia
Next

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 4 guests

Thu Mar 28, 2024 10:41 am [ UTC ]