Script request to refresh scatter nodes

Forums: Script request to refresh scatter nodes
Forum for OctaneRender Lua scripting examples, discussion and support.

Script request to refresh scatter nodes

Postby manalokos » Thu Dec 19, 2013 1:38 pm

manalokos Thu Dec 19, 2013 1:38 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
manalokos
Licensed Customer
Licensed Customer
 
Posts: 438
Joined: Fri Nov 18, 2011 4:43 pm

Re: Script request to refresh scatter nodes

Postby stratified » Thu Dec 19, 2013 7:39 pm

stratified Thu Dec 19, 2013 7:39 pm
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
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Script request to refresh scatter nodes

Postby stratified » Thu Dec 19, 2013 8:10 pm

stratified Thu Dec 19, 2013 8:10 pm
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
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Script request to refresh scatter nodes

Postby phdubrov » Thu Dec 19, 2013 8:22 pm

phdubrov Thu Dec 19, 2013 8:22 pm
getSelection() is really needed.
Will be another ways to run scripts not from menu only? Non-modal windows, additional buttons, shortcuts...
phdubrov
Licensed Customer
Licensed Customer
 
Posts: 15
Joined: Sun Mar 03, 2013 1:47 pm

Re: Script request to refresh scatter nodes

Postby stratified » Thu Dec 19, 2013 8:35 pm

stratified Thu Dec 19, 2013 8:35 pm
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
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Script request to refresh scatter nodes

Postby phdubrov » Thu Dec 19, 2013 9:04 pm

phdubrov Thu Dec 19, 2013 9:04 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.
phdubrov
Licensed Customer
Licensed Customer
 
Posts: 15
Joined: Sun Mar 03, 2013 1:47 pm

Re: Script request to refresh scatter nodes

Postby stratified » Thu Dec 19, 2013 9:26 pm

stratified Thu Dec 19, 2013 9:26 pm
okay, I understand we'll put something on our TODO list to assign shortcuts to scripts.

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

Re: Script request to refresh scatter nodes

Postby manalokos » Fri Dec 20, 2013 12:39 pm

manalokos Fri Dec 20, 2013 12:39 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
manalokos
Licensed Customer
Licensed Customer
 
Posts: 438
Joined: Fri Nov 18, 2011 4:43 pm

Re: Script request to refresh scatter nodes

Postby stratified » Fri Dec 20, 2013 8:52 pm

stratified Fri Dec 20, 2013 8:52 pm
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
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Script request to refresh scatter nodes

Postby Tugpsx » Sat Dec 21, 2013 4:16 am

Tugpsx Sat Dec 21, 2013 4:16 am
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
Dell Win Vista 32 | NVIDIA Quadro NVS135M | Core2 Duo T7500 2.20GHz | 4GB
CyberPowerPC Win 7 64| NVIDIA GTX660Ti (3G) GTX480(1.5G) | 16GB
Tugpsx
Licensed Customer
Licensed Customer
 
Posts: 1145
Joined: Thu Feb 04, 2010 8:04 pm
Location: Chicago, IL
Next

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 5 guests

Thu Mar 28, 2024 8:34 pm [ UTC ]