Page 2 of 6
Re: Nodes and Nodegraphs in Lua.
Posted: Fri Dec 13, 2013 8:08 pm
by stratified
hi beppe,
bepeg4d wrote:i have tried to go a bit further but i get an error at line 29
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
Re: Nodes and Nodegraphs in Lua.
Posted: Fri Dec 13, 2013 8:16 pm
by stratified
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
Re: Nodes and Nodegraphs in Lua.
Posted: Fri Dec 13, 2013 8:24 pm
by r-username
[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.
Re: Nodes and Nodegraphs in Lua.
Posted: Fri Dec 13, 2013 11:40 pm
by bepeg4d
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
Re: Nodes and Nodegraphs in Lua.
Posted: Sun Dec 15, 2013 7:38 pm
by roeland
There is an issue with this hex to float conversion described here:
http://render.otoy.com/forum/viewtopic.php?f=21&t=33214, more specifically this 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
Re: Nodes and Nodegraphs in Lua.
Posted: Mon Dec 16, 2013 7:47 am
by radiant
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

Re: Nodes and Nodegraphs in Lua.
Posted: Mon Dec 16, 2013 7:51 pm
by roeland
"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
Re: Nodes and Nodegraphs in Lua.
Posted: Mon Dec 16, 2013 8:55 pm
by stratified
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

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
Re: Nodes and Nodegraphs in Lua.
Posted: Tue Dec 17, 2013 8:47 pm
by phdubrov
How to manipulate static pins attributes inside nodes?
For example how to set camera aperture inside render target without creating camera node?
Re: Nodes and Nodegraphs in Lua.
Posted: Tue Dec 17, 2013 8:50 pm
by stratified
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