Changing a Single Scatter Transform From a Script

Forums: Changing a Single Scatter Transform From a Script
Forum for OctaneRender Lua scripting examples, discussion and support.

Changing a Single Scatter Transform From a Script

Postby cnewswanger » Mon Jul 06, 2015 10:55 pm

cnewswanger Mon Jul 06, 2015 10:55 pm
I am evaluating Octane currently for a new project.

I need to create a script to change the shear coefficients in a Scatter node in a very precise way.

I will be producing a large number of frames for the production of light field holograms.
My script will need to change the shear elements for each rendered frame.

I can manually change the X and Y shear elements "1 0 X 0 0 1 Y 0 0 0 1 0" in a scatter node and the shear works the way it should.

Each scene (created in Maya) can have a single scatter node named "myTransform" or some such name just before the render target node.

I would expect that I would copy the scenegraph, as in the turntable demo, before modifying the scatter matrix.

Can I reference this uniquely named node from a Lua script?
Can I then change the scatter matrix elements? There will only be a single matrix transform in the node.


I can see that I will likely need to use items NT_GEO_SCATTER and A_TRANSFORMS to access the node.
I would seem that I should be able to do that, but with only the api browser and a few Lua script examples I have been struggling to get this to work. Of course I am new to Lua, so I am on the steep part of the learning curve.

Thanks for any help!
Craig
http://www.zebraimaging.com
cnewswanger
 
Posts: 9
Joined: Mon Jun 22, 2015 9:16 pm

Re: Changing a Single Scatter Transform From a Script

Postby stratified » Tue Jul 07, 2015 12:27 am

stratified Tue Jul 07, 2015 12:27 am
Hi Craig,

Strictly speaking, you don't need to take a copy of the scene graph but we consider it bad form if scripts unexpectedly modify the Octane project (unless specified otherwise).

You can find an item (node or graph) in a graph by calling findItemsByName(). If the name of your node is unique, the list contains a single item.

The scatter node is a node of type NT_GEO_SCATTER. It has an attribute called A_TRANSFORMS which takes an array of transform matrices (3x4 since the last 0 0 0 1 row is omitted). You can set this by calling for example:

Code: Select all
local matrix = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 } }
myScatterNode:setAttribute(octane.A_TRANSFORMS, { matrix })


I hope this steers you in the right direction.

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

Re: Changing a Single Scatter Transform From a Script

Postby cnewswanger » Tue Jul 07, 2015 3:28 pm

cnewswanger Tue Jul 07, 2015 3:28 pm
Thanks for your quick response.


I've tried this:

Code: Select all
local myScatterNode = octane.nodegraph.findItemsByName(SCENE_GRAPH,"myScatter",false)
local matrix = { { 1, 0, 0.33, 0 }, { 0, 1, 0.66, 0 }, { 0, 0, 1, 0 } }

myScatterNode:setAttribute(octane.A_TRANSFORMS,{matrix})


I get this error on the last line:
[string "scatternode.lua"]:58: attempt to call method 'setAttribute' (a nil value)

I'm still a babe in the woods. I'm planning on handing this over to a real programmer but I would like to have this working in a simple demo script before he arrives.

Thanks,
Craig
cnewswanger
 
Posts: 9
Joined: Mon Jun 22, 2015 9:16 pm

Re: Changing a Single Scatter Transform From a Script

Postby stratified » Tue Jul 07, 2015 8:56 pm

stratified Tue Jul 07, 2015 8:56 pm
cnewswanger wrote:Thanks for your quick response.


I've tried this:

Code: Select all
local myScatterNode = octane.nodegraph.findItemsByName(SCENE_GRAPH,"myScatter",false)
local matrix = { { 1, 0, 0.33, 0 }, { 0, 1, 0.66, 0 }, { 0, 0, 1, 0 } }

myScatterNode:setAttribute(octane.A_TRANSFORMS,{matrix})


I get this error on the last line:
[string "scatternode.lua"]:58: attempt to call method 'setAttribute' (a nil value)

I'm still a babe in the woods. I'm planning on handing this over to a real programmer but I would like to have this working in a simple demo script before he arrives.

Thanks,
Craig


octane.nodegraph.findItemsByName returns a table of items. If you have only one scatter node like in your case, you should change

Code: Select all
local myScatterNode = octane.nodegraph.findItemsByName(SCENE_GRAPH,"myScatter",false)


to

Code: Select all
local myScatterNode = octane.nodegraph.findItemsByName(SCENE_GRAPH,"myScatter",false)[1]


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

Re: Changing a Single Scatter Transform From a Script

Postby cnewswanger » Mon Aug 17, 2015 2:01 am

cnewswanger Mon Aug 17, 2015 2:01 am
Hello again,
The prototype script shown below seems to work fine... some of the time.
It runs to completion on another machine with a single titan X card.

We built a new machine with 4 Titan X cards.
The script renders from 5000-9000 frames and it crashes the machine.
images are roughly 512 square. This takes a few hours.
In our initial tests each frame takes about 1 second.
I have not found any trace of the crash in the system logs.
The system appears as though it was reset after the crash.
The last image rendered is complete.
It is not related to the script as far as the number of frames rendered.
It does not seem to be related to

Initially the cards ran rather hot until I found the EVGA app to rev up the fans.
I've turned off all power saving features of windows and auto system update.

Any other ideas?

Cheers,
Craig

Code: Select all
----------------------------------------------------------------------------------------------------
-- Shear animation using Octane Scatter node
-- animates the shear elements of a single scatter transform
-- @description renders an array of ortho views for holograms
-- @author      Craig Newswanger & Ariel James
-- @version     0.3  August 4, 2015
-- @script-id   Octane Shear Animation


------------------------------------------------------------------------------
-- Returns copies of the original scene graph, the camera node and the rendertarget.
-- This prevents us from modifying the original scene.
local function getSceneCopy()

    -- get the selected render target
    local selectedRt = octane.project.getSelection()[1]
    if not selectedRt or selectedRt.type ~= octane.NT_RENDERTARGET then
        octane.gui.showError{ text = "No render target selected" }
        return nil
    end

    -- Create a full copy of the whole project so we don't modify the original project.
    local copyScene = octane.nodegraph.createRootGraph("Project Copy")
    local copyRt    = copyScene:copyFromGraph(octane.project.getSceneGraph(), { selectedRt })[1]

    -- check if the copied node is a render target with a thinlens camera connected to it
    if not copyRt or copyRt.type ~= octane.NT_RENDERTARGET then
        octane.gui.showError("No render target selected")
        return nil
    end

    -- check if a thin lens camera is connected to the render target
    local copyCam = copyRt:getInputNode(octane.P_CAMERA)
    if not copyCam or copyCam .type ~= octane.NT_CAM_THINLENS then
        octane.gui.showError("No thinlens camera connected to the render target")
        return nil
    end

    return copyScene, copyRt, copyCam
end

local function saveRender(cScene, fName)

   --Find parent direcotry of current project
   local filePath = octane.project.getCurrentProject()
   fileName = octane.file.getParentDirectory(filePath)
   --Define new render folder and check if it exists
   --renderFolder = fileName .. '/RenderFolder'
    renderFolder = 'E:\\Death_Star_8-15-15'
   exists = octane.file.exists(renderFolder)
   --If the render folder does not exist create it
   if not exists then
      local result = octane.file.createDirectory(renderFolder)
   end
   
    renderFile = renderFolder .. '/' .. fName
    print('FILE-NAME')
    print(fName)
    print('RENDER-FOLDER')
    print(renderFile)
   octane.render.start
   {
      renderTargetNode = cScene,
      maxSamples       = 10,
   }
   octane.render.saveImage(renderFile, octane.render.imageType.PNG8)
end

--
--Main
--
-- Get the render target and camera in global variables
SCENE_GRAPH, RT_NODE, CAM_NODE = getSceneCopy()

-- if getSceneCopy failed, halt the script
if SCENE_GRAPH == nil then return end

basename = "Death_Star_Battle"
for x = 255,0,-1 do
    xshear = x/128 -1
        for y = 255,0,-1 do
          yshear = y/128 -1
          xstr=string.format("%04d",255-x)
          ystr=string.format("%04d",255-y)
            filename= basename .. "_" .. ystr .. "_" .. xstr .. ".png"
          print(filename,xshear,yshear)
         local myScatterNode = octane.nodegraph.findItemsByName(SCENE_GRAPH,"myScatter",false)[1]
         local matrix = { { 1, 0, xshear, 0 }, { 0, 1, yshear, 0 }, { 0, 0, 1, 0 } }
         myScatterNode:setAttribute(octane.A_TRANSFORMS,{matrix})
         saveRender(RT_NODE, filename)
        end
end


-- reset the render engine
octane.render.reset()
cnewswanger
 
Posts: 9
Joined: Mon Jun 22, 2015 9:16 pm

Re: Changing a Single Scatter Transform From a Script

Postby cnewswanger » Mon Aug 17, 2015 4:34 pm

cnewswanger Mon Aug 17, 2015 4:34 pm
Still experiencing random crashes of Octane when running our render script. Errors occur at random times.
Last run ran ~47,000 frames out of 65,536 before it crashed.
After crash Octane and script show "Not Responding" and are greyed out.
Windows has no coincidental log event.

My current system is:
Windows 7 Pro
Gigabyte GA-X99-UD4 motherboard.
Intel core i7-5930K, 6 core 3.5 GHz
Memory 64 Gigs G.Skill Ripjaws 4, DDR4 2133 (PC4-17000)
Samsung 850 Pro-Series 512GB Internal SSD
Quad EVGA GeForce GTX TITAN X Video Cards, with EVGA SLI bridge
Corsair AX1500i - Digital ATX 1500 Watt Power Supply, operating at ~850 watts at full render load.

All is running cool, all fans at maximum.
Do I need the SLI bridge at all for Octane?
Is there a log that records Octane events? I can't find one.
Is there a config file that limits memory for Octane?

Thanks for any help.
Craig
cnewswanger
 
Posts: 9
Joined: Mon Jun 22, 2015 9:16 pm

Re: Changing a Single Scatter Transform From a Script

Postby cnewswanger » Mon Aug 17, 2015 7:42 pm

cnewswanger Mon Aug 17, 2015 7:42 pm
Octane crash info;
just crashed again. Grrrr!

Cpu dropped from 25% to 0%

GPUs all cooled down.

Octane and Lua Windows indicated "not responding"

Windows log did not record anything coincidental with failure.

Craig
cnewswanger
 
Posts: 9
Joined: Mon Jun 22, 2015 9:16 pm

Re: Changing a Single Scatter Transform From a Script

Postby grimm » Mon Aug 17, 2015 11:11 pm

grimm Mon Aug 17, 2015 11:11 pm
If it ran ok on the other system then I would suspect the new system. I would check everything in the new system and see if you can find the problem. It could be any number of things from hardware to software. One thing you could do to start with is to remove redundant components from the computer, one by one, until the problem goes away. It could be a bad memory stick that only fails when that memory is used, etc. Sorry I'm not more specific, but there are far too many variables to give you a specific thing to try. By removing pieces and parts from the computer you can narrow the number of issues it could be.
Linux Mint 20 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 460.56
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1321
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 9 guests

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