Get transformation from alembic?

Forum for OctaneRender Lua scripting examples, discussion and support.
doca
Licensed Customer
Posts: 90
Joined: Sat Mar 13, 2010 12:12 pm

Hello guys, maybe title speaks for itself, but let me explain a little. I do not know how to do scripting, so I am asking for help.
I have a light rig, lets say, some kind of custom reflector, with zeroed transformations and saved in local DB. As I'm working in external application and rendering in Standalone, I export everything with alembic, but somehow lights are always the pain, especially if I want to tweak transformations of them a little.
So, what I need is to alembic export some guide object (I believe that camera is the best suited for that) and extract its transformations and transform my light rig with it. In short: extract transformations from alembic object, and plug that transformation in the transformation pin of Placement node.
I tried to do that with "FromABC2Thin" script that I downloaded here, and I am getting correct position, but there is not correct rotation output.
Thank in advance,
Doca
doca
Licensed Customer
Posts: 90
Joined: Sat Mar 13, 2010 12:12 pm

Not possible?
calus
Licensed Customer
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

yes it's possible but I think you have to convert the pos, target and up camera vector to a matrix and apply this matrix in an output Transform_Value node.
Pascal ANDRE
calus
Licensed Customer
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Here it is,
I took some parts from the explodeCamera script node and the camera map script.
cameraTransform.orbx
script Node
(2.82 KiB) Downloaded 885 times
Seems to work nicely. :)
usage
usage

Code: Select all

-- Take an ABC camera as input and extract its transformation
-- the output tranform can be plugged in a placement node for example.

local CamTransform = {}
-- edit this to change the name of the graph
local graphName = "cameraTransform"

local inputs  = {}
local outputs = {}
local transform = nil

function CamTransform.onInit(self, graph)
    -- camera input pin
    local inputInfos =
    {
        { type = octane.PT_CAMERA, label = "Camera In", defaultNodeType = octane.NT_CAM_THINLENS },
    }
    -- transform output pin
    local outputInfos =
    {
        { type = octane.PT_TRANSFORM, label = "Transform Out"  },
    }
    -- register the pins
    inputs  = graph:setInputLinkers(inputInfos)
    outputs = graph:setOutputLinkers(outputInfos)
    -- create the transform_value node
    transform = octane.node.create{ type = octane.NT_TRANSFORM_VALUE, name = "Transform Value" }
    outputs[1]:connectToIx(1, transform)

    self:setEvaluateTimeChanges(true)

    graph.name = graphName
    graph:unfold()
end

-- extract camera matrix
function convertInputs()
    local cameraNode = inputs[1]:getInputNodeIx(1)
    if cameraNode ~= nil then
        local pos	 	= cameraNode:getPinValue(octane.P_POSITION)
        local target    = cameraNode:getPinValue(octane.P_TARGET)
        local up	 	= octane.vec.normalized(cameraNode:getPinValue(octane.P_UP))

        local Z = octane.vec.normalized(octane.vec.sub(target, pos))
        local X = octane.vec.normalized(octane.vec.cross(up, Z))
        local Y = octane.vec.normalized(octane.vec.cross(Z, X))

        matrix = {
        {X[1], Y[1], Z[1], pos[1]},
        {X[2], Y[2], Z[2], pos[2]},
        {X[3], Y[3], Z[3], pos[3]},
        }

        transform:setAttribute(octane.A_TRANSFORM, matrix)
    end
end

function CamTransform.onEvaluate(self, graph)
    convertInputs()
end

return CamTransform
Pascal ANDRE
doca
Licensed Customer
Posts: 90
Joined: Sat Mar 13, 2010 12:12 pm

GREAT!!! It works! Thank you very much!
treddie
Licensed Customer
Posts: 739
Joined: Fri Mar 23, 2012 5:44 am

Yes. Many THANKS!

One question. Does Octane use it's own variant of LUA, or is it generic LUA?
Win7 | Geforce TitanX w/ 12Gb | Geforce GTX-560 w/ 2Gb | 6-Core 3.5GHz | 32Gb | Cinema4D w RipTide Importer and OctaneExporter Plugs.
User avatar
roeland
OctaneRender Team
Posts: 1822
Joined: Wed Mar 09, 2011 10:09 pm

It's standard Lua 5.1, with a group of modules added to interact with Octane.

--
Roeland
treddie
Licensed Customer
Posts: 739
Joined: Fri Mar 23, 2012 5:44 am

Thanks, Roeland!
Win7 | Geforce TitanX w/ 12Gb | Geforce GTX-560 w/ 2Gb | 6-Core 3.5GHz | 32Gb | Cinema4D w RipTide Importer and OctaneExporter Plugs.
gardeler
Licensed Customer
Posts: 121
Joined: Fri Feb 22, 2013 5:10 pm

This is actually one of the things I have missed the most in octane!! BUT it does not work with motionblur? Can that be solved? Also, the Z axis of my object got inverted, but I could work around that with a negative scale on a different place node.
User avatar
roeland
OctaneRender Team
Posts: 1822
Joined: Wed Mar 09, 2011 10:09 pm

If you want animated data, you can copy any node to a private root node graph in your script, and vary the time of that root node graph to evaluate that node at arbitrary time stamps. In case of nodes inside an alembic archive, these values will be loaded from the Alembic file.

--
Roeland
Post Reply

Return to “Lua Scripting”