-- current render target and camera local rendertarget = octane.render.getRenderTargetNode() local camera = rendertarget:getInputNode(octane.P_CAMERA) -- camera transform local pos = camera:getPinValue(octane.P_POSITION) local target = camera:getPinValue(octane.P_TARGET) local up = octane.vec.normalized(camera: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]}, } -- field of view, lens shift and resolution local fov = camera:getPinValue(octane.P_FOV) local shift = camera:getPinValue(octane.P_LENS_SHIFT) local resolution = rendertarget:getPinValue(octane.P_RESOLUTION) local w = 2 * math.tan(math.rad(fov / 2)) local h = w * resolution[2] / resolution[1] local matrix = octane.matrix.mul(matrix, octane.matrix.makeScale{-w, h, 1}) local uvmatrix = octane.matrix.makeTranslation{-.5 + shift[1], -.5 + shift[2], 0} -- get selected texture or material node, and apply transform function project(tex) proj = octane.node.create{ type = octane.NT_PROJ_PERSPECTIVE, pinOwnerNode = tex, pinOwnerId = octane.P_PROJECTION, } octane.node.create{ type = octane.NT_TRANSFORM_VALUE, pinOwnerNode = tex, pinOwnerId = octane.P_TRANSFORM, } tex:setPinValue(octane.P_TRANSFORM, uvmatrix) proj:setPinValue(octane.P_TRANSFORM, matrix) end -- node.getPinInfo raises an error when the pin doesn't exist. function hasPin(n, pin) local r = pcall(n.getPinInfo, n, pin) return r end function hasProjection(n) return hasPin(n, octane.P_PROJECTION) and hasPin(n, octane.P_TRANSFORM) end local foundtex = false for _, n in ipairs(octane.project.getSelection()) do if hasProjection(n) then foundtex = true project(n) elseif n:getProperties().outputType == octane.PT_MATERIAL then for i = 1, n:getPinCount() do local m = nil pcall(function() m = n:getInputNodeIx(i) end) if m ~= nil and hasProjection(m) then foundtex = true project(m) end end end end if foundtex then octane.changemanager.update() else error("You have to select an image texture node or material node.") end