Script request to refresh scatter nodes

Forum for OctaneRender Lua scripting examples, discussion and support.
manalokos
Licensed Customer
Posts: 441
Joined: Fri Nov 18, 2011 4:43 pm

Hello

I have absolutelly no experience in scripting, but would like to request a probably easy task that would be helpful to most in our community.

A small script that would automatically refresh all the scatter nodes in a scene. Would this be difficult to achieve through scripting?

Thanks
Best regards
Filipe
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

hi there,

Sure that's possible. Here's a small code snippet for the users who want to try and tackle this problem (getSelection is new in 1.23). It shouldn't be too hard:

Code: Select all

-- gets the selected scatter node
scatter = octane.project.getSelection()[1]

-- 3x4 matrices (actually, they are standard 4x4 transform matrices in disguise but we ommit the last (0, 0, 0, 1) row)
transforms = 
{
    -- unit matrix
    { 
        { 1, 0, 0, 0 },
        { 0, 1, 0, 0 },
        { 0, 0, 1, 0 }
    },

    -- transformed matrix ( 2x scaling + translation)
    {
        { 2, 0, 0, 5 },
        { 0, 2, 0, 5 },
        { 0, 0, 2, 5 },
    }
}

-- set the array of transformations in the scatter node
scatter:setAttribute(octane.A_TRANSFORMS, transforms)
cheers,
Thomas
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Hi there,

Here's something more complete. This script will reload the file in each scatter node. For the interested users, there's a generic update function here which will call a predicate function on each node of a specific type in the project. This might come in handy in other scripts.

Code: Select all

-- Calls the predicate function on each item of the given type.
-- This will recursive in each graph to find nodes of the given type.
--
-- @param   graph (Graph)
-- @param   nodeType (Type of node we're looking for)
-- @param   pred (Predicate function that takes a scatter node)
function updateItem(g, nodeType, pred)
    for i, item in ipairs(g:getOwnedItems()) do
        if item:getProperties().type == nodeType then
            pred(item)
        elseif item:getProperties().isGraph then
            updateItem(item, nodeType, pred)
        end
    end
end

-- reloads a scatter node
function reloadScatter(node)
    print("reloading ", node)
    node:setAttribute(octane.A_RELOAD, true)
end

updateItem(octane.nodegraph.getRootGraph(), octane.NT_GEO_SCATTER, reloadScatter)
cheers,
Thomas
phdubrov
Licensed Customer
Posts: 15
Joined: Sun Mar 03, 2013 1:47 pm

getSelection() is really needed.
Will be another ways to run scripts not from menu only? Non-modal windows, additional buttons, shortcuts...
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

getSelection() (and other selection stuff) will be there in the next release candidate (1.23)

What do you mean by other ways? You can run a script from the command line as well (octane.exe --script myscript.lua) if you want to fully integrate Octane in some other tools.

Non-modal windows might be there in Octane 2.x but not for this 1.5 release. We need to think about this a bit more because with non-modal windows you could actually modify a lot of stuff in the standalone while your script is running (and make Octane crash). That's why the GUI is fully blocked while running a script.

not sure what you mean with additional buttons & shortcuts, could you elaborate a bit.

cheers,
Thomas
phdubrov
Licensed Customer
Posts: 15
Joined: Sun Mar 03, 2013 1:47 pm

I just want a way to run scripts fast. For me the best solution would be a keyboard shortcuts or one shortcut to open window with scripts list.
Buttons mean buttons for toolbars, shortcuts - keyboard shortcuts.
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

okay, I understand we'll put something on our TODO list to assign shortcuts to scripts.

cheers,
Thomas
manalokos
Licensed Customer
Posts: 441
Joined: Fri Nov 18, 2011 4:43 pm

Hello Thomas

This is great! Thank you!

Maybe even being able to assign custom buttons to scripts would be a good idea.

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

We're going to try and come up with a solution that fits more nicely in the workflow in one of the next releases.

cheers,
Thomas
Tugpsx
Licensed Customer
Posts: 1150
Joined: Thu Feb 04, 2010 8:04 pm
Location: Chicago, IL
Contact:

What is this scripting thing! :twisted:
Why is it catching fire even with the non-programmers :twisted:
Why is it making this thing called Octane popular :oops:
To find these answers, we will need to scan through these pages to discover the hidden treasures. :D
Win 11 64GB | NVIDIA RTX3060 12GB
Post Reply

Return to “Lua Scripting”