Nodes and Nodegraphs in Lua.

Forums: Nodes and Nodegraphs in Lua.
Forum for OctaneRender Lua scripting examples, discussion and support.

Re: Nodes and Nodegraphs in Lua.

Postby stratified » Fri Dec 13, 2013 8:08 pm

stratified Fri Dec 13, 2013 8:08 pm
hi beppe,

bepeg4d wrote:i have tried to go a bit further but i get an error at line 29 :roll:


inColor5Node:setAttribute(octane.A_VALUE, { 1 }) needs to be modified to inColor5Node:setAttribute(octane.A_VALUE, 1)

The node is of type NT_TEX_FLOAT which takes only 1 number (AT_FLOAT). See below for the full docmentation (copy/paste from API browser).

Code: Select all
NT_TEX_FLOAT

 • Output Type    : PT_TEXTURE
 • Category       : Textures|Greyscale Color
 • Default Name   : Greyscale Color
 • #Attributes    : 1
 • #Static Pins   : 0


  Attributes
    A_VALUE
         • Description    : The value of the float texture node. Needs to be in the rage [0 .. 1].
         • Type           : AT_FLOAT
         • Array          : false
         • Default Value  : 0.700000


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

Re: Nodes and Nodegraphs in Lua.

Postby stratified » Fri Dec 13, 2013 8:16 pm

stratified Fri Dec 13, 2013 8:16 pm
r-username wrote:Very nice script.

Would it be possible to enter hex values or 0-255 values? I looked thru the API without success.

I understand the whole linear workflow but all my clients use hex or 0-255 to define colors. if not please add for a future release, I would really like to use the script method.

Thanks in advance


Hi there,

Nope, the colours are floating point numbers in the range [0..1]. But it's just code so you could just use a helper function that converts hex to floating point.

Code: Select all
-- hex number to floating point
function fromHex(hex)
    float = hex / 255
    -- clamp the value
    if float > 1 then return 1 end
    if float < 0 then return 0 end
    return float
end

print(fromHex(0xf3))
print(fromHex(0xff)) -- returns 1
print(fromHex(0xfff)) -- clampled to 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: Nodes and Nodegraphs in Lua.

Postby r-username » Fri Dec 13, 2013 8:24 pm

r-username Fri Dec 13, 2013 8:24 pm
[quote="stratified"]
Nope, the colours are floating point numbers in the range [0..1]. But it's just code so you could just use a helper function that converts hex to floating point.

Code: Select all
-- hex number to floating point
function fromHex(hex)
    float = hex / 255
    -- clamp the value
    if float > 1 then return 1 end
    if float < 0 then return 0 end
    return float
end

print(fromHex(0xf3))
print(fromHex(0xff)) -- returns 1
print(fromHex(0xfff)) -- clampled to 1


Great, this scripting is a real time saver.
i7 960 - W7x64 - 12 GB - 2x GTX 780ti
http://www.startsimple.com/ - http://www.gigavr.com/
r-username
Licensed Customer
Licensed Customer
 
Posts: 217
Joined: Thu Nov 24, 2011 3:39 pm

Re: Nodes and Nodegraphs in Lua.

Postby bepeg4d » Fri Dec 13, 2013 11:40 pm

bepeg4d Fri Dec 13, 2013 11:40 pm
stratified wrote:
inColor5Node:setAttribute(octane.A_VALUE, { 1 }) needs to be modified to inColor5Node:setAttribute(octane.A_VALUE, 1)

i see, only one value, no need for braces :)
thanks, i will correct it tomorrow ;)
ciao beppe
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 9954
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: Nodes and Nodegraphs in Lua.

Postby roeland » Sun Dec 15, 2013 7:38 pm

roeland Sun Dec 15, 2013 7:38 pm
There is an issue with this hex to float conversion described here: viewtopic.php?f=21&t=33214, more specifically this image:

Image

If you aren't bothered by this difference in color, then you are wasting your time converting numbers.

To input a hex color in Octane, click the color swatch, and fill in the hex color in the text field at the bottom like this: "ff8000". It also works if you input three numbers like this: "255 128 0". For scripts you don't need to take this into account since users can always open the color picker.

--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1810
Joined: Wed Mar 09, 2011 10:09 pm

Re: Nodes and Nodegraphs in Lua.

Postby radiant » Mon Dec 16, 2013 7:47 am

radiant Mon Dec 16, 2013 7:47 am
Ok so i have been doing some trail and error with the ones created here,
with this:

Code: Select all
inColor1 = octane.node.create{type=octane.NT_IN_TEXTURE, name="Diffuse-Color", graphOwner=root, position={250, 100}}
inColor1Node = octane.node.create{type=octane.NT_TEX_RGB, pinOwnerNode=inColor1, pinOwnerId=octane.P_INPUT}


Is the following "incolor1" and "incolor1node" a inbuilt naming convention, i thought i was just a variable name you can randomly make up but i replace the "in" the whole script stuffs up, does the "in" have significance?

Also is there a better sort of wiki for the api as for someone like me the browse API doesnt help in the slightest :oops: :|
Win8 Pro 64bit ULT|Intel Core i7 3930K|3.20 GHz|32 GB RAM|GTX 590|UD5 2011 socket||2x TB HD||Master Cooler HAF X||Blender 2.6||Maya 2012||Octane|
User avatar
radiant
Licensed Customer
Licensed Customer
 
Posts: 699
Joined: Mon Apr 05, 2010 12:00 pm
Location: Adelaide, Australia

Re: Nodes and Nodegraphs in Lua.

Postby roeland » Mon Dec 16, 2013 7:51 pm

roeland Mon Dec 16, 2013 7:51 pm
"inColor1" and "inColor1Node" are just the names of variables, there is no naming scheme. Maybe you are replacing it in some other places (the octane.NT_IN_TEXTURE constant, or the pinOwnerId property comes to mind) where it is important.

--
Roeland
User avatar
roeland
OctaneRender Team
OctaneRender Team
 
Posts: 1810
Joined: Wed Mar 09, 2011 10:09 pm

Re: Nodes and Nodegraphs in Lua.

Postby stratified » Mon Dec 16, 2013 8:55 pm

stratified Mon Dec 16, 2013 8:55 pm
radiant wrote:Also is there a better sort of wiki for the api as for someone like me the browse API doesnt help in the slightest :oops: :|


Hi radiant,

You're right just by going through the API browser isn't enough, it's a cross reference. It's like trying to learn english by picking up a dictionary. That's why we have to forum here to help out and post tutorials. So please do ask lot's of questions if something is not clear, because we (the devs) have sort of a tunnel vision on this thing :)

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

Re: Nodes and Nodegraphs in Lua.

Postby phdubrov » Tue Dec 17, 2013 8:47 pm

phdubrov Tue Dec 17, 2013 8:47 pm
How to manipulate static pins attributes inside nodes?
For example how to set camera aperture inside render target without creating camera node?
phdubrov
Licensed Customer
Licensed Customer
 
Posts: 15
Joined: Sun Mar 03, 2013 1:47 pm

Re: Nodes and Nodegraphs in Lua.

Postby stratified » Tue Dec 17, 2013 8:50 pm

stratified Tue Dec 17, 2013 8:50 pm
phdubrov wrote:How to manipulate static pins attributes inside nodes?
For example how to set camera aperture inside render target without creating camera node?


Hi there,

Pins don't have attributes. What you should do is get the get the camera from the render target, and then set the value of the node connected to the aperture pin on the camera.

renderTargetNode:getConnectedNode(P_CAMERA):setPinValue(P_APERTURE, 1)

This will set the value "through" the pin. Technically this means setting the A_VALUE attribute of float node connected to the aperture pin but clamping the value in the range of the aperture pin.

An alternative is renderTargetNode:getConnectedNode(P_CAMERA):getConnectedNode(P_APERTURE):setAttribute(A_VALUE, 1) but this doesn't give you the nice clamping in the pin range.

cheers,
Thomas
Last edited by stratified on Tue Dec 17, 2013 8:53 pm, edited 1 time in total.
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand
PreviousNext

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 15 guests

Fri Apr 19, 2024 11:55 pm [ UTC ]