I am making a script that will get all the render targets in the scene graph that contain panoramic cameras, and then collect data (position, etc), and save it to a json file.
The gui makes a set of buttons for each pano camera found. One will select the render target node and then update the render viewport.
I am looping through an array (of render target nodes) to create my gui elements. The problem arises when I want to pass index data into the button callback.
The callback function can see global variables, but is not able to retain the value of my index variable (c).
How can I get my callback function to reference an item in an array?
If this cannot work, is there a better way to approach this?
Thanks
Thomas
- Code: Select all
-- Make an array of all cameras and their render node names
panoCams = {};
renderTarget = {}; -- render target that contains the pano camera
p=1;
-- Get all the render target nodes in the scene
nodes = octane.nodegraph.findNodes( octane.project.getSceneGraph(), octane.NT_RENDERTARGET, true );
-- Refine the render targets to only those with pano cameras
for i, entry in ipairs(nodes) do
-- print(entry)
cam = octane.node.getConnectedNodeIx( entry, 1 );
-- print(cam, cam.nodeType, octane.node.getNodeInfo(cam))
if cam.nodeType == 62 then -- CAM_PANORAMIC
panoCams[p] = cam;
renderTarget[p] = entry;
-- print(p, panoCams[p], entry.name);
p=p+1;
end
end
-----------------------------------------------------------------------------------------
panoGroups = {};
panoCaptions = {};
panoOpen = {};
renButtonProps = {};
gTest = "test";
c = 1;
for index, value in ipairs(panoCams) do
local i = (index-1) * 4
print(index, i, ':', panoCams[index], ':', renderTarget[index].name);
local camlabel = createLabel("Pano Camera ".. index);
local renlabel = createLabel("Render Target "..renderTarget[index].name);
print('render target: ', c, renderTarget[c].name);
-- create a button to show a file chooser
local renderTargetButton = octane.gui.create
{
type = octane.gui.componentType.BUTTON,
text = "Render View",
width = 80,
height = 20,
callback =
-- Select the render target
function(component, event)
print('component: ', component);
print('select render target: ', renderTarget[1].name); -- *** HERE is where I'd like the index variable c to go, but it returns nil.
octane.project.clearSelection();
octane.project.select(renderTarget[1]);
--octane.render.restart();
-- octane.render.start { renderTargetNode = renderTarget[1] };
end
}
-- create a button to show a file chooser
local loadImageButton = octane.gui.create
{
type = octane.gui.componentType.BUTTON,
text = "Image Path",
width = 80,
height = 20,
}
-- panoGroups[index] = { camlabel, renlabel, fileChooseButton, loadImageButton };
panoGroups[i+1] = camlabel;
panoGroups[i+2] = renlabel;
panoGroups[i+3] = renderTargetButton;
panoGroups[i+4] = loadImageButton;
c=c+1
end